11-2: The Lisp Interface


This section explains the Lisp interpretive language interface in the Electric VLSI design system. This interface is built on top of ELK Lisp 3.0, a Scheme dialect (see

Throughout this section, examples of Lisp code will appear underlined. For example, the "getarcproto" predicate takes the name of an arc prototype and returns a pointer to that object. This is coded as (getarcproto 'Metal-1) which evaluates to the pointer of the form #[arcproto Metal-1].

This section assumes that the reader is very familiar with the use of Electric, and somewhat familiar with the internals of the system. The Internals Manual (a document that is available from Static Free Software) provides a broad, C-oriented view of the information described here. For users of Lisp, however, this section summarizes the relevant aspects of the Internals Manual. In general, the best way to understand this section is to try each command as it is explained.

Session Control

To invoke the Lisp interpreter, use the LISP... subcommand of the Language Interpreter command of the Tools menu. On some systems it may be necessary to move the cursor into the messages window (the text window) in order for the interpreter to "hear" you.

If you have a disk file with Lisp code in it, you can read it into the interpreter by typing:
  (load 'FILENAME)

To get back to Electric from Lisp, type ^D (hold the Control key and type a "D"). On Windows, you must type the ESC key instead.

Database Structure

The entire Electric database is a collection of objects, each of which has an arbitrary number of attributes. This section briefly outlines the object types and shows how they are related. Further detail can be found in the Internals Manual. See Section 11-5 for a list of attributes on these objects.

Individual components inside of circuits are described with NODEINST objects (instances of nodes), and individual wires are described with ARCINST objects (instances of arcs). Connections between components and wires are described with PORTARCINST objects (instances of ports that connect to arcs). Because both components and wires have geometry, each one also has an associated GEOM object, and all of the GEOM objects in a cell are organized spatially into an R-tree with a collection of RTNODE objects.

Class objects also exist to describe all individuals of a given type. The NODEPROTO object describes the prototypical component, which may have many individual NODEINST objects associated with it. For example, the CMOS P-Transistor is described with a single NODEPROTO object, and many NODEINST objects for each instance of such a transistor in any circuit. Hierarchy is implemented by having complex components, better known as cells, represented in the same way as the primitive components such as transistors. For example, the ALU circuit is described with a single NODEPROTO object, and each instance of that circuit higher up the hierarchy is described with a NODEINST object.

The CELL object aggregates different views and versions of a circuit. Each of these is called a "cell" (represented with a NODEPROTO object) and a cell has both a VIEW pointer and a version number.

In addition to component prototypes, the ARCPROTO describes classes of wires and the PORTPROTO describes classes of component-wire connections. An additional object, the PORTEXPINST, exists for exports. The NETWORK object describes electrically connected ARCINST and PORTPROTO objects within a CELL.

As a further aggregation of objects, the LIBRARY is a collection of cells and cells. The TECHNOLOGY is a collection of primitive components (NODEPROTOs) and all wire classes (ARCPROTOs).

In addition to the above object pointers, there are some standard types of values that can be accessed through getval:

integer32-bit integer
address32-bit integer
char8-bit byte
stringnull-terminated string of bytes
float32-bit floating point number
double64-bit floating point number
fractfractional integer number that is multiplied by 120
short16-bit integer
windowwindow partition object
window-framedisplay window object
constraintconstraint system object
graphicsgraphical attributes object

Also, there is the ability to have displayable variables (those whose values appear on the object) with the keyword: displayable.

Database Examination

To begin a search through the database, it is important to know the current library. This is done with:
which returns a pointer to a LIBRARY object (for example #[library noname]). From here, the current cell can be obtained with:
  (getval (curlib) 'firstnodeproto)

Essentially, any attribute can be examined with getval, and new attributes can be created with setval. Getval has the following format:
where OBJECT is the object being accessed and ATTRIBUTE is the attribute being requested. A list of all existing attributes on the Electric objects is given at the end of this document.

New attributes can be created on any object with setval. In general, many of the existing attributes that are described at the end of this document cannot be set with setval, but rather are controlled with special database modification predicates. The format for setval is:
Where the OPTIONS are either 0 or 'displayable to show this attribute when displaying the object. For example, to add a new attribute called "power-consumption" to the transistor component "t1", and give it the value 75, use:
  (setval t1 'power-consumption 75 0)
To add a displayed name to node "t1", use:
  (setval t1 'NODE_name "Q1" 'displayable)
To set an array of values, use vectors. For example, to set the shape of pure-layer node "metal" to be a diamond, use:
  (setval metal 'trace (vector -1000 0 0 1000 1000 0 0 -1000) 0)

Single entries in array attributes can be set, with:
where INDEX is the 0-based entry in the array.

Finally, attributes can be deleted with:
However, only those attributes that have been created with setval can be deleted in this way. The other attributes are protected.

Basic Synthesis

To create a new cell in the current library, use:
  (newnodeproto 'CELLNAME (curlib))
which returns a NODEPROTO pointer that can be used in subsequent calls which place components and wires in that cell.

To get the address of an existing NODEPROTO, use:
  (getnodeproto 'CELLNAME)
which returns the same type of value as newnodeproto. Thus, the code:
  (define mycell (newnodeproto 'adder{lay} (curlib)))
is the same as the code:
  (newnodeproto 'adder{lay} (curlib))
  (define mycell (getnodeproto 'adder{lay}))
and both deal with the "layout" view of the cell called "adder".

To create a component in a cell, use:
where PROTO is a NODEPROTO of the component that is to be created, LOWX, HIGHX, LOWY, and HIGHY are the bounds of the component, ANGLE is the number of tenth-degrees of rotation for the component, TRANSPOSE is nonzero to transpose the component's orientation (after rotation), and CELL is the NODEPROTO in which to place the component.

The four bounds values are somewhat confusing to compute. For primitive components (such as Transistors), any value is acceptable and the component will scale. However, it is still nice to know the default value, which can be obtained from the NODEPROTO with getval as follows:
  (define tran (getnodeproto 'P-Transistor))
  (define lowx (getval tran 'lowx))
  (define highx (getval tran 'highx))
  (define lowy (getval tran 'lowy))
  (define highy (getval tran 'highy))
When complex components (cells) are placed, the bounds MUST be exactly the same as the bounding box of the cell's contents. This information is available in the above manner. As an example of newnodeinst, and given the above bounds calculations, a default size P-Transistor is created in cell "adder" with:
  (define t1 (newnodeinst tran lowx highx lowy highy 0 0 mycell))
The returned pointer to the transistor component will be used later when wiring.

To wire two components, it is necessary to know these four things:

Connection sites are called PORTPROTOs and are associated with NODEPROTOs. To get the address, use:
  (getportproto NODEPROTO 'PORTNAME)
For example, to get the polysilicon port on the left side of the MOSIS CMOS P-Transistor, use:
  (define polyleft (getportproto tran 'p-trans-poly-left))
Unfortunately, there is no good way to get a list of port names on the primitive components. There are, however, some simplifications. For example, if there is only one port (as is the case with most contacts and pins) then its name is not necessary:
  (define port (getval tran 'firstportproto))
This will obtain the first port on the P-Transistor component. To obtain the coordinates of a port for wiring, use:
  (portposition NODE PORT)
This returns a vector with the coordinates. For example:
  (define portpos (portposition t1 polyleft))
will obtain the coordinate of the "p-trans-poly-left" port on the newly created P-Transistor, t1. The X value will be (vector-ref portpos 0) and the Y value will be (vector-ref portpos 1).

The final piece of information necessary is the type of arc and the width of the arc. Given an arc name, the type can be obtained with:
  (getarcproto 'ARCNAME)
Given an ARCPROTO, its default width can be obtained with:
  (getval ARCTYPE 'nominalwidth)
When all of the information is ready, the call:
places the wire. You can ignore the value of BITS and set it to zero.

Here is a complete example of placing a transistor, a contact, and running a wire between them (the result is shown here).

  ; create a cell called "tran-contact" in the current library
  (define mycell (newnodeproto 'tran-contact (curlib)))

  ; get pointers to primitives
  (define tran (getnodeproto 'P-Transistor))
  (define contact (getnodeproto 'Metal-1-Polysilicon-1-Con))

  ; get default sizes of these primitives
  (define tlowx (getval tran 'lowx))
  (define thighx (getval tran 'highx))
  (define tlowy (getval tran 'lowy))
  (define thighy (getval tran 'highy))
  (define clowx (getval contact 'lowx))
  (define chighx (getval contact 'highx))
  (define clowy (getval contact 'lowy))
  (define chighy (getval contact 'highy))

  ; get pointer to Polysilicon arc and its default width
  (define arctype (getarcproto 'Polysilicon-1))
  (define width (getval arctype 'nominalwidth))

  ; create the transistor and the contact to its left
  (define c1 (newnodeinst contact clowx chighx clowy chighy
    0 0 mycell))
  (define t1 (newnodeinst tran (+ tlowx 8000) (+ thighx 8000)
    tlowy thighy 0 0 mycell))

  ; get the transistor's left port coordinates
  (define tport (getportproto tran 'p-trans-poly-left))
  (define tpos (portposition t1 tport))

  ; get the contacts's only port coordinates
  (define cport (getval contact 'firstportproto))
  (define cpos (portposition c1 cport))

  ; run a wire between the primitives
  (newarcinst arctype width 0
    t1 tport (vector-ref tpos 0) (vector-ref tpos 1)
    c1 cport (vector-ref cpos 0) (vector-ref cpos 1) mycell)

Figure 11.1


Cells, as created by newnodeproto, can be placed in other cells with newnodeinst. The instances simply use complex NODEPROTO fields rather than primitive NODEPROTOs as in the above example. For example, the following code creates a new cell called "two-trans" and places two instances of the above "tran-contact" cell, one above the other.

  ; create a cell called "two-trans"
  (define highercell (newnodeproto 'two-trans (curlib)))

  ; get pointer to the "tran-contact" cell
  (define t-c (getnodeproto 'tran-contact))

  ; get size of this cell
  (define lowx (getval t-c 'lowx))
  (define highx (getval t-c 'highx))
  (define lowy (getval t-c 'lowy))
  (define highy (getval t-c 'highy))

  ; create the two cell instances, one above the other
  (define o1 (newnodeinst t-c lowx highx lowy highy
    0 0 highercell))
  (define o2 (newnodeinst t-c lowx highx
    (+ lowy 10000) (+ highy 10000) 0 0 highercell))

Figure 11.2

Another necessary feature, when making hierarchy, is the ability to place wires between connection sites on cell instances. To do this, it is necessary to create exports. This takes a port on a primitive component (for example, the transistor or contact in the "tran-contact" cell) and makes it into an export on the current cell. This is done with:
where CELL is the cell containing the component whose port is being exported, NODE-IN-CELL is that component, and PORT-ON-NODE is the particular port on that node being exported. For example, to export the top and bottom diffusion ports in the "tran-contact" cell (as shown here), the following code can be added:

  (newportproto mycell t1
    (getportproto tran 'p-trans-diff-top) 'topdiff)
  (newportproto mycell t1
    (getportproto tran 'p-trans-diff-bottom) 'botdiff)
Figure 11.3

And then, the components "o1" and "o2" in the cell "two-trans" can be wired, using the ports called "topdiff" and "botdiff":

  ; get pointer to P-Active arc and its default width
  (define darctype (getarcproto 'P-Active))
  (define dwidth (getval darctype 'nominalwidth))

  ; get the bottom cell's top port
  (define lowport (getportproto mycell 'topdiff))
  (define lowpos (portposition o1 lowport))

  ; get the top cell's bottom port
  (define highport (getportproto mycell 'botdiff))
  (define highpos (portposition o2 highport))

  ; run a wire between the primitives
  (newarcinst darctype dwidth 0
    o1 lowport (vector-ref lowpos 0) (vector-ref lowpos 1)
    o2 highport (vector-ref highpos 0)
      (vector-ref highpos 1) highercell)

Figure 11.4


Two types of modification can be done to existing objects: deletion and change. To delete a cell, use:
  (killnodeproto CELL)

To make a copy of a cell (within the same library or from one library to another), use:
where FROM-CELL is the original cell (NODEPROTO) and TO-LIBRARY is the destination library. Use (curlib) to copy to the same library. The new cell name is the last parameter. The predicate returns the address of the new cell (NODEPROTO).

To delete a component, use:
  (killnodeinst NODE)
Before a component can be deleted, all wires and exports must be removed.

To change the size or orientation of a component, use:
where DLOWX, DLOWY, DHIGHX, and DHIGHY are the changes to position and size. DROTATION and DTRN are changes to the orientation.

To change the prototype of a component, use:
  (replacenodeinst OLD-NODE NEW-PROTOTYPE)
where the old component is OLD-NODE, and the new NODEPROTO that should be in its place is NEW-PROTOTYPE. This new prototype must be able to connect to all existing arcs. The predicate returns the address of the new component.

To delete a wire, use:
  (killarcinst ARC)

To change the width or position of a wire, use:
  (modifyarcinst ARC DWIDTH DX1 DY1 DX2 DY2)
where DWIDTH, DX1, DY1, DX2, and DY2 are the changes to the width, X/Y position of end 1, and X/Y position of end 2. Note that position changes cannot cause the connecting nodes to move, so the changes may only be small ones that work within the ports.

To change the prototype of a wire, use:
  (replacearcinst OLD-ARC NEW-PROTOTYPE)
where OLD-ARC is the former wire and NEW-PROTOTYPE is the new ARCPROTO to use. The nodes on either end must be able to accept this new type of wire. The predicate returns the address of the new wire.

To delete an export, use:
  (killportproto CELL PORT)
which will remove port PORT on cell CELL.

To move an export from one component to another (keeping connected wires), use:
where the old port is OLD-PORT in cell CELL, and it is now moved to component NEW-NODE (which is also in cell CELL), port PORT-ON-NEW-NODE of that component.


A common operation is a search of all components in a cell. The following code prints the name of all components in the cell "mycell":

      (node (getval mycell 'firstnodeinst)
        (getval node 'nextnodeinst))
    ((null? node))

    (format #t "Found ~s node~%" (describenode node))

Where describenode is defined as follows (the name of a node is found in different places depending on whether it is a primitive or complex NODEPROTO):

  (define describenode
    (lambda (node)
      (define proto (getval node 'proto))
      (if (= (getval proto 'primindex) 0)
        (getval (getval proto 'cell) 'cellname)
          (getval proto 'primname)

And the following code prints the name of all wires in the cell "mycell":

      (arc (getval mycell 'firstarcinst)
        (getval arc 'nextarcinst))
    ((null? arc))

    (format #t "Found ~s arc~%"
      (getval (getval arc 'proto) 'protoname))

To do a search of all nodes and arcs in a rectangular area of a cell, first call:
where LOWX, HIGHX, LOWY, and HIGHY are the coordinates to search in cell CELL (a NODEPROTO). This predicate will return a search key that can then be passed repeatedly to:
  (nextobject SEARCHKEY)
which will return GEOM objects of each node and arc in the search area. When this predicate returns Null, the search is complete. GEOM objects can point to either nodes or arcs, depending on their "entryisnode" attribute. Then, the "entryaddr" attribute will point to the actual NODEINST or ARCINST. Here is an example of code that prints the names of all nodes and arcs in the area (2000 <= X <= 10000, -3000 <= Y <= 3000). The selected area is shown as a black box here.

  (define key (initsearch 2000 10000 -3000 3000 mycell))
      (object (nextobject key) (nextobject key))
    ((null? object))

    (define isnode (getval object 'entryisnode))
    (if (= isnode 0)
      (format t "Found ~s arc~%"
            (getval object 'entryaddr)
      (format t "Found ~s node~%"
        (describenode (getval object 'entryaddr))

Figure 11.5


A view is an object that describes a cell. There are many standard views: Layout, Schematic, Icon, Simulation-snapshot, Skeleton, VHDL, Verilog, Document, Unknown, and many flavors of Netlist. In addition, new views can be created with "newview":
and views can be deleted with killview (the standard views cannot be deleted):
  (killview VIEW)
To get a view object, use getview on its name.

To associate different views of a cell, the predicates iconview and contentsview obtain different cells. For example:
  (iconview mycell)
finds the associated icon cell of the cell in which "mycell" resides.


In the above examples, the current library was always used. This is determined by calling:
However, there can be other libraries. To get a specific named library, use:
  (getlibrary 'LIBNAME)

To create a new library, use:
where LIBRARYNAME is the name to use, and LIBRARYFILE is the path name where this library will be saved. This predicate returns the address of a new library object that can then be used when creating cells.

Only one library is the current one, and to switch, you must use:
  (selectlibrary LIBRARY)

A library can be deleted with:
  (killlibrary LIBRARY)

A library can be erased (its cells deleted, but not the library) with:
  (eraselibrary LIBRARY)


A technology is an environment of design that includes primitive components and wire prototypes. The current technology can be obtained with:

A specific technology can be obtained from its name with:
  (gettechnology 'TECHNAME)

All technologies can be found by traversing a linked list, the head of which is a technology named "Generic".


A tool is a piece of synthesis or analysis code that can operate upon the database. A particular tool object can be obtained with:
  (gettool 'TOOLNAME)
where the possible names of tools are:

compactioncircuit compaction
compensationgeometry compensation
drcdesign-rule checking
ercelectrical-rule checking
ioinput/output control
logeffortlogical effort analysis
networknetwork maintenance
plaprogrammable logic array generator
projectproject management
routingautomatic wire routing
silicon-compilernetlist-to-layout silicon assembler
userthe user interface
vhdl-compilerVHDL-to-netlist compiler
The number of tools is available with:
And a particular tool, indexed from 0 to (maxtool)-1 can be obtained with:
  (indextool INDEX)

A tool can be switched on with:
  (toolturnon TOOL)
where TOOL is a tool object.

A tool can be turned off with:
  (toolturnoff TOOL)

A tool can be given a specific instruction with:
  (telltool TOOL PARAMETERS)
For example, to list all technologies, use this code:
  (telltool (gettool 'user) 'show 'technologies)
These commands are from the low-level command interpreter, which is documented fully in the Internals Manual.


Every change to the database is queued internally in a "batch" which includes the change and any constrained side-effects of that change. A new batch is created for each Lisp session with the interpreter (also for each Electric command that is issued from the keyboard/mouse). To reverse the last batch of changes, use:

Multiple calls to this predicate in a single batch will undo multiple batches. To erase the list of change batches, use:

If you are creating a wire that makes many bends, it is necessary to create special nodes called "pins" at each bend. To find out what kind of pin to use for a given wire type, use:
  (getpinproto ARC-PROTO)
where ARC-PROTO is the wire type, and the predicate returns the component type (NODEPROTO) of the pin.

Network objects can be obtained by name with the predicate getnetwork which takes a name and a cell in which to search. For example, the code:
  (getnetwork 'insig mycell)
obtains the address of the network called "insig" in cell mycell.

The generic function of a node instance can be determined with:
  (nodefunction NODE)
which returns a value from the list of constants in the C header file "efunction.h". This value is essentially the same one as would be obtained by looking at the "userbits" field of the node's prototype. However, certain components that have generic prototypes will be made more specific by this predicate.

To get an attribute value from an instance above this in the hierarchy, use:
  (getparentval 'name DEFAULT HEIGHT)
where name is the attribute name, DEFAULT is the default value to return if the attribute is not found, and HEIGHT is the number of levels of hierarchy to climb when looking for the attribute (0 for infinite). As a shortcut for finding parameter values, there are four macros which use this routine:

Prev Previous     Contents Table of Contents     Next Next