1 ; file: gnet-spice-dmn.scm
  2 ; copyright (c) 2019-2020 dmn <graahnul.grom@gmail.com>
  3 ; license: GPLv2+
  4 ;
  5 ; simple SPICE lepton-netlist backend
  6 ; usage: lepton-netlist -o - -f gnet-spice-dmn.scm some_schematic.sch
  7 ;
  8 
  9 ( use-modules ( netlist schematic ) )
 10 ( use-modules ( netlist schematic toplevel ) )
 11 ( use-modules ( netlist package ) )
 12 
 13 
 14 ( define ( nets_in_pinseq_order refdes pins_nets )
 15 ( let
 16     (
 17     ( len     (length pins_nets) )
 18     ( pinseq  1   )
 19     ( pinnum  #f  )
 20     ( netname #f  )
 21     ( res     '() )
 22     )
 23 
 24     ( while ( <= pinseq len )
 25 
 26         ( set! pinnum
 27             ( gnetlist:get-attribute-by-pinseq
 28                 refdes
 29                 ( number->string pinseq )
 30                 "pinnumber"
 31             )
 32         )
 33 
 34         ( set! netname ( package-pin-netname refdes pinnum ) )
 35         ( set! res ( append res (list netname) ) )
 36 
 37         ( set! pinseq ( 1+ pinseq ) )
 38 
 39     ) ; while
 40 
 41     ; return:
 42     res
 43 
 44 ) ; let
 45 ) ; nets_in_pinseq_order()
 46 
 47 
 48 
 49 ; backend's entry point:
 50 ;
 51 ( define ( spice-dmn output-filename )
 52 ( let
 53     (
 54     ( pkgs ( schematic-package-names (toplevel-schematic) ) ) ; list of refdes's
 55     ( nets ( schematic-nets          (toplevel-schematic) ) )
 56     ( pinnum    #f )
 57     ( netnames  #f )
 58     ( attr      #f )
 59     ( pins_nets '() )
 60     )
 61 
 62     ( format #t "* spice-dmn lepton-netlist backend:~%" )
 63     ( format #t "*~%" )
 64 
 65     ( for-each
 66     ( lambda( refdes )
 67 
 68         ( set! pins_nets ( get-pins-nets refdes ) )
 69 
 70         ( if ( > (length pins_nets) 0 ) ; pkg has pins
 71         ( begin
 72 
 73             ( set! netnames ( nets_in_pinseq_order refdes pins_nets ) )
 74             ( set! attr (gnetlist:get-package-attribute refdes "value") )
 75 
 76             ( format #t "~a~{~,15t~a~}~,15t~a" refdes netnames attr )
 77             ( format #t "~%" )
 78 
 79         )
 80         ) ; if
 81 
 82     )
 83     pkgs
 84     )
 85 
 86     ( format #t ".end~%" )
 87 
 88 ) ; let
 89 ) ; spice-dmn()
 90 
 91 
 92 
 93 ; instruct the netlister to use the 'spice mode
 94 ; (this function is called by lepton-netlist):
 95 ;
 96 ( define ( request-netlist-mode )
 97     ; return:
 98     'spice
 99 )
100