Merge fixes from branch 'xorn'
[geda-gaf.git] / xorn / src / backend / gnet_gossip.py
blob3d0e26a9f51b4142fb849639938d29611df236fc
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 # Netlister for GOSSIP system simulation system
21 # For more info see http://gossip.sourceforge.net
23 def run(f, netlist):
24 f.write(';; Gossip Netlist Created by gNetlist\n')
25 f.write('\n')
26 f.write(';; Created By Matt Ettus <matt@ettus.com>\n')
27 f.write(';; Libraries:\n')
28 f.write('\n')
30 done = set()
31 for package in reversed(netlist.packages):
32 lib = package.get_attribute('library', 'unknown')
33 if lib == 'unknown':
34 package.warn("does not have a library attribute")
35 if lib in done:
36 continue
38 f.write('(use-library %s *)\n' % lib)
39 done.add(lib)
41 blockname = netlist.get_toplevel_attribute('blockname', 'not found')
42 f.write('(define-block (%s (\n' % blockname)
43 f.write('(signals (%s))\n' % ' '.join(
44 net.name for net in reversed(netlist.nets)))
46 for package in reversed(netlist.packages):
47 f.write(' (')
48 f.write(package.refdes)
50 i = 1
51 while True:
52 if str(i) not in package.pins_by_number:
53 break
54 pin = package.pins_by_number[str(i)]
55 pinname = pin.get_attribute('label', None)
56 if pinname is None:
57 break
59 f.write(' :%s ' % pinname)
61 if not pin.net.is_unconnected_pin:
62 f.write(pin.net.name)
63 else:
64 f.write('Not Connected')
66 i += 1
68 f.write(')\n')