Merge fixes from branch 'xorn'
[geda-gaf.git] / xorn / src / backend / gnet_spice.py
blob6e9ce0bac771394953c03491e121633611721a61
1 # gaf.netlist - gEDA Netlist Extraction and Generation
2 # Copyright (C) 1998-2010 Ales Hvezda
3 # Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
4 # Copyright (C) 2013-2020 Roland Lutz
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software Foundation,
18 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 # SPICE netlist backend written by S. Gieltjes
22 # Common functions for the `spice' and `spice-sdb' backends
23 from spice_common import *
25 # write mos transistor
27 def write_mos_transistor(f, package):
28 write_one_component(f, package)
29 # create list of attributes which can be attached to a mosfet
30 attrib_list = ['l', 'w', 'as', 'ad', 'pd', 'ps', 'nrd', 'nrs', 'temp', 'ic']
31 write_list_of_attributes(f, package, attrib_list)
32 # write the off attribute separately
33 off_value = package.get_attribute('off', 'unknown')
34 if off_value in ['#t', '1']:
35 f.write(' off')
36 f.write('\n')
38 # Include a file
40 def write_include(f, package):
41 f.write('%s %s\n' % (package.refdes, component_value(package)))
43 # write the refdes, the net name connected to pin# and the
44 # component value. No extra attributes.
46 def write_one_component(f, package):
47 f.write(package.refdes + ' ')
48 # write net names, slotted components not implemented
49 write_net_names_on_component(f, package)
50 # write component value, if components have a label "value=<hash>"
51 # what if a component has no value label, currently unknown is written
52 f.write(component_value(package))
54 # Spice netlist generation
56 def run(f, netlist):
57 f.write('* Spice netlister for gnetlist\n')
58 # search for specific device labels
59 for package in reversed(netlist.packages):
60 # write the refdes, to the pin# connected net and component
61 # value and optional extra attributes
62 # check if the component is a special spice component
63 device = package.get_attribute('device', 'unknown')
64 if device == 'SPICE-ccvs':
65 write_ccvs(f, package)
66 elif device == 'SPICE-cccs':
67 write_cccs(f, package)
68 elif device == 'SPICE-vcvs':
69 write_vcvs(f, package)
70 elif device == 'SPICE-vccs':
71 write_vccs(f, package)
72 elif device == 'SPICE-nullor':
73 write_nullor(f, package)
74 elif device == 'PMOS_TRANSISTOR':
75 write_mos_transistor(f, package)
76 elif device == 'NMOS_TRANSISTOR':
77 write_mos_transistor(f, package)
78 elif device == 'include':
79 write_include(f, package)
80 else:
81 write_one_component(f, package)
82 f.write('\n')
84 f.write('.END\n')