Initialization of the Backend

After opening the output netlist, any specific initializations which must be done for the particular netlist are done. In the switcap example, we must initialize a net name and reference designator (refdes) aliasing database. This is because switcap has more restrictive requirements on its net names than gschem does. In addition, the reference designators in a switcap netlist have special requirements. To deal with this situation, gnetlist provides some general purpose functions which rename nets and reference designators to comply with the target netlist requirements. More details on this later. For now, just note that the switcap backend uses the following code:

      ;; initialize the net-name aliasing
      (gnetlist:build-net-aliases switcap:map-net-names 
          all-unique-nets)

      ;; initialize the refdes aliasing
      (gnetlist:build-refdes-aliases switcap:map-refdes
          packages)

The other initialization which is typically done, although not required by all netlist types, is to output some sort of header. This header may be explicitly contained in the entry point function or it may be contained in its own function for code clarity. In the switcap backend, the call is:

      (switcap:write-top-header port)
Note that the convention is for any backend specific functions to have their names prefixed by the backend name. For example all switcap specific functions begin with ``switcap:''. Functions which are available to all backends and provided by gnetlist are prefixed by ``gnetlist:''.

The definition of ``switcap:write-top-header'' is

;; 
;; Switcap netlist header
;;
(define switcap:write-top-header
  (lambda (port)
    (display 
      "/* Switcap netlist produced by gnetlist (part of gEDA) */\n" 
      port)  
    (display 
      "/* See http://www.geda.seul.org for more information.  */\n"
      port)  
    (display 
      "/* Switcap backend written by Dan McMahill             */\n"
      port)
    (display "\n\n" port)
    )
  )

The entry point function continues by calling functions for each section in the output netlist. The variable ``packages'' is predefined by gnetlist to be a list of all components in the design and ``all-unique-nets'' is a list of all the nets in the design. The various functions used by the backend for each section in the netlist will use these variables. For example, the main part of the switcap netlist which contains the components and their connectivity is written to the output file with

      (switcap:write-netlist port packages)

Ales Hvezda 2005-03-15