26 from gettext
import gettext
as _
87 def __init__(self, toplevel_filenames,
90 prefer_netname_attribute =
False,
91 flat_package_namespace =
False,
92 flat_netname_namespace =
False,
93 flat_netattrib_namespace =
False,
94 refdes_mangle_func = NotImplemented,
95 netname_mangle_func = NotImplemented,
96 default_net_name =
'unnamed_net',
97 default_bus_name =
'unnamed_bus'):
130 def load_schematic(filename):
137 sys.stderr.write(_(
"Loading schematic [%s]\n") % filename)
141 except Exception
as e:
142 sys.stderr.write(_(
"ERROR: Failed to load '%s': %s\n")
149 self.schematics.append(schematic)
155 for component
in schematic.components:
156 component.composite_sources = []
158 for value
in component.get_attributes(
'source'):
159 for filename
in value.split(
','):
160 if filename.startswith(
' '):
161 warn(_(
"leading spaces in source names "
163 filename = filename.lstrip(
' ')
168 if full_filename
is None:
170 _(
"failed to load subcircuit '%s': "
171 "schematic not found in source library")
177 _(
"Going to traverse source [%s]\n")
179 load_schematic(full_filename)
180 component.composite_sources.append(
183 for filename
in toplevel_filenames:
184 load_schematic(filename)
194 def s_traverse_sheet1(sheet):
195 for component
in sheet.components:
201 for subschematic
in component.blueprint.composite_sources:
205 component.sheet.netlist, subschematic, component)
206 s_traverse_sheet1(subsheet)
208 for filename
in toplevel_filenames:
211 self.toplevel_sheets.append(sheet)
212 if traverse_hierarchy:
213 s_traverse_sheet1(sheet)
220 def collect_components(sheet):
221 for component
in sheet.components:
222 sheet.netlist.components.append(component)
223 for subsheet
in component.subsheets:
224 collect_components(subsheet)
227 collect_components(sheet)
231 self, {
False: flat_netname_namespace,
232 True: flat_netattrib_namespace },
233 prefer_netname_attribute,
234 default_net_name, default_bus_name)
237 for net
in self.
nets:
238 net.name = netname_mangle_func(
239 net.unmangled_name, net.namespace)
243 for cpin
in component.cpins:
244 if (component.sheet, cpin.blueprint.net) \
245 not in cpin.local_net.net.sheets_and_net_blueprints:
246 cpin.local_net.net.sheets_and_net_blueprints.append(
247 (component.sheet, cpin.blueprint.net))
249 for net
in self.
nets:
250 for sheet, net_blueprint
in net.sheets_and_net_blueprints:
251 for cpin_blueprint
in net_blueprint.pins:
252 if cpin_blueprint.ob
is not None:
253 assert cpin_blueprint.ob.data().is_pin
256 .components_by_blueprint[cpin_blueprint.component] \
257 .cpins_by_blueprint[cpin_blueprint]
259 assert cpin
not in net.component_pins
260 net.component_pins.append(cpin)
269 self, flat_package_namespace)
272 self.
nets = [net
for net
in self.
nets if not net.is_unconnected_pin]
277 if component.blueprint.refdes
is not None:
278 if component.sheet.instantiating_component
is not None:
279 namespace = component.sheet
282 component.refdes = refdes_mangle_func(
283 component.blueprint.refdes, namespace)
287 if package.namespace
is not None:
288 package.refdes = refdes_mangle_func(
289 package.unmangled_refdes, package.namespace)
293 package.refdes = package.unmangled_refdes
300 self.
error(_(
"refdes conflict across hierarchy: "
301 "refdes `%s' is used by package `%s' on page "
302 "`%s' and by package `%s' on page `%s'") % (
304 other_package.unmangled_refdes,
305 refdes_mangle_func(
'', other_package.namespace),
306 package.unmangled_refdes,
307 refdes_mangle_func(
'', package.namespace)))
311 for net
in self.
nets:
314 self.
error(_(
"net name conflict across hierarchy: "
315 "net name `%s' is used by net `%s' on page "
316 "`%s' and by net `%s' on page `%s'") % (
318 other_net.unmangled_name,
319 netname_mangle_func(
'', other_net.namespace),
321 netname_mangle_func(
'', net.namespace)))
337 if not isinstance(name, basestring):
343 sheet.blueprint.rev, name)
346 for value
in values[1:]:
347 if value != values[0]:
349 _(
"inconsistent values for toplevel attribute "
351 name, _(
" vs. ").join(_(
"\"%s\"") % value
352 for value
in values)))
356 if default
is not KeyError:
363 sys.stderr.write(_(
"error: %s\n" % msg))
369 sys.stderr.write(_(
"warning: %s\n" % msg))
components
Aggregated list of all components in the netlist.
Post-processing: Slotting mechanism.
Attribute parsing and lookup.
toplevel_sheets
List of sheets for the schematics named on the command line.
Reading schematic/symbol files.
Post-processing: Artificial pins.
def search_floating
Search the floating attributes in a revision for an attribute name and return matching values...
Grouping local nets with the same name into a net.
def get_toplevel_attribute
Return the value of a toplevel attribute.
def __init__
Create a netlist.
Netlists for individual schematic files.
Building one hierarchical netlist from instantiated sheet blueprints.
packages
List of packages.
def error
Print an error message and mark the netlist as failed.
Post-processing: Graphical components.
def read
Read a symbol or schematic file.
failed
Whether an error has occurred.
schematics_by_filename
Dictionary mapping filenames to schematic blueprints.
Instantiation of a schematic page.
Global netlist object representing the result of a netlister run.
A netlist for a single schematic.
Post-processing: Hierarchy traversal.
Grouping components with the same refdes into a package.
nets_by_name
Convenience dictionary for looking up nets by their name.
def postproc_instances
Connect subsheet I/O ports to the instantiating component's pins.
def warn
Print a warning message.
def s_slib_search_single
Search the source library for a particular file name substring.
packages_by_refdes
Convenience dictionary for looking up packages by their refdes.
schematics
List of schematic blueprints.