| #!/usr/bin/env python |
| |
| # |
| # Generated Thu Dec 17 10:14:08 2009 by generateDS.py version 1.20b. |
| # |
| |
| import sys |
| import getopt |
| from string import lower as str_lower |
| from xml.dom import minidom |
| from xml.dom import Node |
| |
| # |
| # User methods |
| # |
| # Calls to the methods in these classes are generated by generateDS.py. |
| # You can replace these methods by re-implementing the following class |
| # in a module named generatedssuper.py. |
| |
| try: |
| from generatedssuper import GeneratedsSuper |
| except ImportError, exp: |
| |
| class GeneratedsSuper(object): |
| def format_string(self, input_data, input_name=''): |
| return input_data |
| def format_integer(self, input_data, input_name=''): |
| return '%d' % input_data |
| def format_float(self, input_data, input_name=''): |
| return '%f' % input_data |
| def format_double(self, input_data, input_name=''): |
| return '%e' % input_data |
| def format_boolean(self, input_data, input_name=''): |
| return '%s' % input_data |
| |
| |
| # |
| # If you have installed IPython you can uncomment and use the following. |
| # IPython is available from http://ipython.scipy.org/. |
| # |
| |
| ## from IPython.Shell import IPShellEmbed |
| ## args = '' |
| ## ipshell = IPShellEmbed(args, |
| ## banner = 'Dropping into IPython', |
| ## exit_msg = 'Leaving Interpreter, back to program.') |
| |
| # Then use the following line where and when you want to drop into the |
| # IPython shell: |
| # ipshell('<some message> -- Entering ipshell.\nHit Ctrl-D to exit') |
| |
| # |
| # Globals |
| # |
| |
| ExternalEncoding = 'ascii' |
| |
| # |
| # Support/utility functions. |
| # |
| |
| def showIndent(outfile, level): |
| for idx in range(level): |
| outfile.write(' ') |
| |
| def quote_xml(inStr): |
| s1 = (isinstance(inStr, basestring) and inStr or |
| '%s' % inStr) |
| s1 = s1.replace('&', '&') |
| s1 = s1.replace('<', '<') |
| s1 = s1.replace('>', '>') |
| return s1 |
| |
| def quote_attrib(inStr): |
| s1 = (isinstance(inStr, basestring) and inStr or |
| '%s' % inStr) |
| s1 = s1.replace('&', '&') |
| s1 = s1.replace('<', '<') |
| s1 = s1.replace('>', '>') |
| if '"' in s1: |
| if "'" in s1: |
| s1 = '"%s"' % s1.replace('"', """) |
| else: |
| s1 = "'%s'" % s1 |
| else: |
| s1 = '"%s"' % s1 |
| return s1 |
| |
| def quote_python(inStr): |
| s1 = inStr |
| if s1.find("'") == -1: |
| if s1.find('\n') == -1: |
| return "'%s'" % s1 |
| else: |
| return "'''%s'''" % s1 |
| else: |
| if s1.find('"') != -1: |
| s1 = s1.replace('"', '\\"') |
| if s1.find('\n') == -1: |
| return '"%s"' % s1 |
| else: |
| return '"""%s"""' % s1 |
| |
| |
| class MixedContainer: |
| # Constants for category: |
| CategoryNone = 0 |
| CategoryText = 1 |
| CategorySimple = 2 |
| CategoryComplex = 3 |
| # Constants for content_type: |
| TypeNone = 0 |
| TypeText = 1 |
| TypeString = 2 |
| TypeInteger = 3 |
| TypeFloat = 4 |
| TypeDecimal = 5 |
| TypeDouble = 6 |
| TypeBoolean = 7 |
| def __init__(self, category, content_type, name, value): |
| self.category = category |
| self.content_type = content_type |
| self.name = name |
| self.value = value |
| def getCategory(self): |
| return self.category |
| def getContenttype(self, content_type): |
| return self.content_type |
| def getValue(self): |
| return self.value |
| def getName(self): |
| return self.name |
| def export(self, outfile, level, name, namespace): |
| if self.category == MixedContainer.CategoryText: |
| outfile.write(self.value) |
| elif self.category == MixedContainer.CategorySimple: |
| self.exportSimple(outfile, level, name) |
| else: # category == MixedContainer.CategoryComplex |
| self.value.export(outfile, level, namespace,name) |
| def exportSimple(self, outfile, level, name): |
| if self.content_type == MixedContainer.TypeString: |
| outfile.write('<%s>%s</%s>' % (self.name, self.value, self.name)) |
| elif self.content_type == MixedContainer.TypeInteger or \ |
| self.content_type == MixedContainer.TypeBoolean: |
| outfile.write('<%s>%d</%s>' % (self.name, self.value, self.name)) |
| elif self.content_type == MixedContainer.TypeFloat or \ |
| self.content_type == MixedContainer.TypeDecimal: |
| outfile.write('<%s>%f</%s>' % (self.name, self.value, self.name)) |
| elif self.content_type == MixedContainer.TypeDouble: |
| outfile.write('<%s>%g</%s>' % (self.name, self.value, self.name)) |
| def exportLiteral(self, outfile, level, name): |
| if self.category == MixedContainer.CategoryText: |
| showIndent(outfile, level) |
| outfile.write('model_.MixedContainer(%d, %d, "%s", "%s"),\n' % \ |
| (self.category, self.content_type, self.name, self.value)) |
| elif self.category == MixedContainer.CategorySimple: |
| showIndent(outfile, level) |
| outfile.write('model_.MixedContainer(%d, %d, "%s", "%s"),\n' % \ |
| (self.category, self.content_type, self.name, self.value)) |
| else: # category == MixedContainer.CategoryComplex |
| showIndent(outfile, level) |
| outfile.write('model_.MixedContainer(%d, %d, "%s",\n' % \ |
| (self.category, self.content_type, self.name,)) |
| self.value.exportLiteral(outfile, level + 1) |
| showIndent(outfile, level) |
| outfile.write(')\n') |
| |
| |
| class MemberSpec_(object): |
| def __init__(self, name='', data_type='', container=0): |
| self.name = name |
| self.data_type = data_type |
| self.container = container |
| def set_name(self, name): self.name = name |
| def get_name(self): return self.name |
| def set_data_type(self, data_type): self.data_type = data_type |
| def get_data_type_chain(self): return self.data_type |
| def get_data_type(self): |
| if isinstance(self.data_type, list): |
| if len(self.data_type) > 0: |
| return self.data_type[-1] |
| else: |
| return 'xs:string' |
| else: |
| return self.data_type |
| def set_container(self, container): self.container = container |
| def get_container(self): return self.container |
| |
| def _cast(typ, value): |
| if typ is None or value is None: |
| return value |
| return typ(value) |
| |
| # |
| # Data representation classes. |
| # |
| |
| class config(GeneratedsSuper): |
| subclass = None |
| superclass = None |
| def __init__(self, verilog_files=None, output=None, optimizations=None, debug_outputs=None): |
| self.verilog_files = verilog_files |
| self.output = output |
| self.optimizations = optimizations |
| self.debug_outputs = debug_outputs |
| def factory(*args_, **kwargs_): |
| if config.subclass: |
| return config.subclass(*args_, **kwargs_) |
| else: |
| return config(*args_, **kwargs_) |
| factory = staticmethod(factory) |
| def get_verilog_files(self): return self.verilog_files |
| def set_verilog_files(self, verilog_files): self.verilog_files = verilog_files |
| def get_output(self): return self.output |
| def set_output(self, output): self.output = output |
| def get_optimizations(self): return self.optimizations |
| def set_optimizations(self, optimizations): self.optimizations = optimizations |
| def get_debug_outputs(self): return self.debug_outputs |
| def set_debug_outputs(self, debug_outputs): self.debug_outputs = debug_outputs |
| def export(self, outfile, level, namespace_='', name_='config', namespacedef_=''): |
| showIndent(outfile, level) |
| outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) |
| self.exportAttributes(outfile, level, namespace_, name_='config') |
| if self.hasContent_(): |
| outfile.write('>\n') |
| self.exportChildren(outfile, level + 1, namespace_, name_) |
| showIndent(outfile, level) |
| outfile.write('</%s%s>\n' % (namespace_, name_)) |
| else: |
| outfile.write('/>\n') |
| def exportAttributes(self, outfile, level, namespace_='', name_='config'): |
| pass |
| def exportChildren(self, outfile, level, namespace_='', name_='config'): |
| if self.verilog_files: |
| self.verilog_files.export(outfile, level, namespace_, name_='verilog_files', ) |
| if self.output: |
| self.output.export(outfile, level, namespace_, name_='output', ) |
| if self.optimizations: |
| self.optimizations.export(outfile, level, namespace_, name_='optimizations', ) |
| if self.debug_outputs: |
| self.debug_outputs.export(outfile, level, namespace_, name_='debug_outputs', ) |
| def hasContent_(self): |
| if ( |
| self.verilog_files is not None or |
| self.output is not None or |
| self.optimizations is not None or |
| self.debug_outputs is not None |
| ): |
| return True |
| else: |
| return False |
| def exportLiteral(self, outfile, level, name_='config'): |
| level += 1 |
| self.exportLiteralAttributes(outfile, level, name_) |
| if self.hasContent_(): |
| self.exportLiteralChildren(outfile, level, name_) |
| def exportLiteralAttributes(self, outfile, level, name_): |
| pass |
| def exportLiteralChildren(self, outfile, level, name_): |
| if self.verilog_files is not None: |
| showIndent(outfile, level) |
| outfile.write('verilog_files=model_.verilog_files(\n') |
| self.verilog_files.exportLiteral(outfile, level) |
| showIndent(outfile, level) |
| outfile.write('),\n') |
| if self.output is not None: |
| showIndent(outfile, level) |
| outfile.write('output=model_.output(\n') |
| self.output.exportLiteral(outfile, level) |
| showIndent(outfile, level) |
| outfile.write('),\n') |
| if self.optimizations is not None: |
| showIndent(outfile, level) |
| outfile.write('optimizations=model_.optimizations(\n') |
| self.optimizations.exportLiteral(outfile, level) |
| showIndent(outfile, level) |
| outfile.write('),\n') |
| if self.debug_outputs is not None: |
| showIndent(outfile, level) |
| outfile.write('debug_outputs=model_.debug_outputs(\n') |
| self.debug_outputs.exportLiteral(outfile, level) |
| showIndent(outfile, level) |
| outfile.write('),\n') |
| def build(self, node_): |
| attrs = node_.attributes |
| self.buildAttributes(attrs) |
| for child_ in node_.childNodes: |
| nodeName_ = child_.nodeName.split(':')[-1] |
| self.buildChildren(child_, nodeName_) |
| def buildAttributes(self, attrs): |
| pass |
| def buildChildren(self, child_, nodeName_): |
| if child_.nodeType == Node.ELEMENT_NODE and \ |
| nodeName_ == 'verilog_files': |
| obj_ = verilog_files.factory() |
| obj_.build(child_) |
| self.set_verilog_files(obj_) |
| elif child_.nodeType == Node.ELEMENT_NODE and \ |
| nodeName_ == 'output': |
| obj_ = output.factory() |
| obj_.build(child_) |
| self.set_output(obj_) |
| elif child_.nodeType == Node.ELEMENT_NODE and \ |
| nodeName_ == 'optimizations': |
| obj_ = optimizations.factory() |
| obj_.build(child_) |
| self.set_optimizations(obj_) |
| elif child_.nodeType == Node.ELEMENT_NODE and \ |
| nodeName_ == 'debug_outputs': |
| obj_ = debug_outputs.factory() |
| obj_.build(child_) |
| self.set_debug_outputs(obj_) |
| # end class config |
| |
| |
| class verilog_files(GeneratedsSuper): |
| subclass = None |
| superclass = None |
| def __init__(self, verilog_file=None): |
| if verilog_file is None: |
| self.verilog_file = [] |
| else: |
| self.verilog_file = verilog_file |
| def factory(*args_, **kwargs_): |
| if verilog_files.subclass: |
| return verilog_files.subclass(*args_, **kwargs_) |
| else: |
| return verilog_files(*args_, **kwargs_) |
| factory = staticmethod(factory) |
| def get_verilog_file(self): return self.verilog_file |
| def set_verilog_file(self, verilog_file): self.verilog_file = verilog_file |
| def add_verilog_file(self, value): self.verilog_file.append(value) |
| def insert_verilog_file(self, index, value): self.verilog_file[index] = value |
| def export(self, outfile, level, namespace_='', name_='verilog_files', namespacedef_=''): |
| showIndent(outfile, level) |
| outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) |
| self.exportAttributes(outfile, level, namespace_, name_='verilog_files') |
| if self.hasContent_(): |
| outfile.write('>\n') |
| self.exportChildren(outfile, level + 1, namespace_, name_) |
| showIndent(outfile, level) |
| outfile.write('</%s%s>\n' % (namespace_, name_)) |
| else: |
| outfile.write('/>\n') |
| def exportAttributes(self, outfile, level, namespace_='', name_='verilog_files'): |
| pass |
| def exportChildren(self, outfile, level, namespace_='', name_='verilog_files'): |
| for verilog_file_ in self.verilog_file: |
| showIndent(outfile, level) |
| outfile.write('<%sverilog_file>%s</%sverilog_file>\n' % (namespace_, self.format_string(quote_xml(verilog_file_).encode(ExternalEncoding), input_name='verilog_file'), namespace_)) |
| def hasContent_(self): |
| if ( |
| self.verilog_file |
| ): |
| return True |
| else: |
| return False |
| def exportLiteral(self, outfile, level, name_='verilog_files'): |
| level += 1 |
| self.exportLiteralAttributes(outfile, level, name_) |
| if self.hasContent_(): |
| self.exportLiteralChildren(outfile, level, name_) |
| def exportLiteralAttributes(self, outfile, level, name_): |
| pass |
| def exportLiteralChildren(self, outfile, level, name_): |
| showIndent(outfile, level) |
| outfile.write('verilog_file=[\n') |
| level += 1 |
| for verilog_file_ in self.verilog_file: |
| showIndent(outfile, level) |
| outfile.write('%s,\n' % quote_python(verilog_file_).encode(ExternalEncoding)) |
| level -= 1 |
| showIndent(outfile, level) |
| outfile.write('],\n') |
| def build(self, node_): |
| attrs = node_.attributes |
| self.buildAttributes(attrs) |
| for child_ in node_.childNodes: |
| nodeName_ = child_.nodeName.split(':')[-1] |
| self.buildChildren(child_, nodeName_) |
| def buildAttributes(self, attrs): |
| pass |
| def buildChildren(self, child_, nodeName_): |
| if child_.nodeType == Node.ELEMENT_NODE and \ |
| nodeName_ == 'verilog_file': |
| verilog_file_ = '' |
| for text__content_ in child_.childNodes: |
| verilog_file_ += text__content_.nodeValue |
| self.verilog_file.append(verilog_file_) |
| # end class verilog_files |
| |
| |
| class output(GeneratedsSuper): |
| subclass = None |
| superclass = None |
| def __init__(self, output_type='blif', output_path_and_name=None, target=None): |
| self.output_type = output_type |
| self.output_path_and_name = output_path_and_name |
| self.target = target |
| def factory(*args_, **kwargs_): |
| if output.subclass: |
| return output.subclass(*args_, **kwargs_) |
| else: |
| return output(*args_, **kwargs_) |
| factory = staticmethod(factory) |
| def get_output_type(self): return self.output_type |
| def set_output_type(self, output_type): self.output_type = output_type |
| def get_output_path_and_name(self): return self.output_path_and_name |
| def set_output_path_and_name(self, output_path_and_name): self.output_path_and_name = output_path_and_name |
| def get_target(self): return self.target |
| def set_target(self, target): self.target = target |
| def export(self, outfile, level, namespace_='', name_='output', namespacedef_=''): |
| showIndent(outfile, level) |
| outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) |
| self.exportAttributes(outfile, level, namespace_, name_='output') |
| if self.hasContent_(): |
| outfile.write('>\n') |
| self.exportChildren(outfile, level + 1, namespace_, name_) |
| showIndent(outfile, level) |
| outfile.write('</%s%s>\n' % (namespace_, name_)) |
| else: |
| outfile.write('/>\n') |
| def exportAttributes(self, outfile, level, namespace_='', name_='output'): |
| pass |
| def exportChildren(self, outfile, level, namespace_='', name_='output'): |
| if self.output_type is not None: |
| showIndent(outfile, level) |
| outfile.write('<%soutput_type>%s</%soutput_type>\n' % (namespace_, self.format_string(quote_xml(self.output_type).encode(ExternalEncoding), input_name='output_type'), namespace_)) |
| if self.output_path_and_name is not None: |
| showIndent(outfile, level) |
| outfile.write('<%soutput_path_and_name>%s</%soutput_path_and_name>\n' % (namespace_, self.format_string(quote_xml(self.output_path_and_name).encode(ExternalEncoding), input_name='output_path_and_name'), namespace_)) |
| if self.target: |
| self.target.export(outfile, level, namespace_, name_='target', ) |
| def hasContent_(self): |
| if ( |
| self.output_type is not None or |
| self.output_path_and_name is not None or |
| self.target is not None |
| ): |
| return True |
| else: |
| return False |
| def exportLiteral(self, outfile, level, name_='output'): |
| level += 1 |
| self.exportLiteralAttributes(outfile, level, name_) |
| if self.hasContent_(): |
| self.exportLiteralChildren(outfile, level, name_) |
| def exportLiteralAttributes(self, outfile, level, name_): |
| pass |
| def exportLiteralChildren(self, outfile, level, name_): |
| if self.output_type is not None: |
| showIndent(outfile, level) |
| outfile.write('output_type=%s,\n' % quote_python(self.output_type).encode(ExternalEncoding)) |
| if self.output_path_and_name is not None: |
| showIndent(outfile, level) |
| outfile.write('output_path_and_name=%s,\n' % quote_python(self.output_path_and_name).encode(ExternalEncoding)) |
| if self.target is not None: |
| showIndent(outfile, level) |
| outfile.write('target=model_.target(\n') |
| self.target.exportLiteral(outfile, level) |
| showIndent(outfile, level) |
| outfile.write('),\n') |
| def build(self, node_): |
| attrs = node_.attributes |
| self.buildAttributes(attrs) |
| for child_ in node_.childNodes: |
| nodeName_ = child_.nodeName.split(':')[-1] |
| self.buildChildren(child_, nodeName_) |
| def buildAttributes(self, attrs): |
| pass |
| def buildChildren(self, child_, nodeName_): |
| if child_.nodeType == Node.ELEMENT_NODE and \ |
| nodeName_ == 'output_type': |
| output_type_ = '' |
| for text__content_ in child_.childNodes: |
| output_type_ += text__content_.nodeValue |
| self.output_type = output_type_ |
| elif child_.nodeType == Node.ELEMENT_NODE and \ |
| nodeName_ == 'output_path_and_name': |
| output_path_and_name_ = '' |
| for text__content_ in child_.childNodes: |
| output_path_and_name_ += text__content_.nodeValue |
| self.output_path_and_name = output_path_and_name_ |
| elif child_.nodeType == Node.ELEMENT_NODE and \ |
| nodeName_ == 'target': |
| obj_ = target.factory() |
| obj_.build(child_) |
| self.set_target(obj_) |
| # end class output |
| |
| |
| class target(GeneratedsSuper): |
| subclass = None |
| superclass = None |
| def __init__(self, arch_file=None): |
| self.arch_file = arch_file |
| def factory(*args_, **kwargs_): |
| if target.subclass: |
| return target.subclass(*args_, **kwargs_) |
| else: |
| return target(*args_, **kwargs_) |
| factory = staticmethod(factory) |
| def get_arch_file(self): return self.arch_file |
| def set_arch_file(self, arch_file): self.arch_file = arch_file |
| def export(self, outfile, level, namespace_='', name_='target', namespacedef_=''): |
| showIndent(outfile, level) |
| outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) |
| self.exportAttributes(outfile, level, namespace_, name_='target') |
| if self.hasContent_(): |
| outfile.write('>\n') |
| self.exportChildren(outfile, level + 1, namespace_, name_) |
| showIndent(outfile, level) |
| outfile.write('</%s%s>\n' % (namespace_, name_)) |
| else: |
| outfile.write('/>\n') |
| def exportAttributes(self, outfile, level, namespace_='', name_='target'): |
| pass |
| def exportChildren(self, outfile, level, namespace_='', name_='target'): |
| if self.arch_file is not None: |
| showIndent(outfile, level) |
| outfile.write('<%sarch_file>%s</%sarch_file>\n' % (namespace_, self.format_string(quote_xml(self.arch_file).encode(ExternalEncoding), input_name='arch_file'), namespace_)) |
| def hasContent_(self): |
| if ( |
| self.arch_file is not None |
| ): |
| return True |
| else: |
| return False |
| def exportLiteral(self, outfile, level, name_='target'): |
| level += 1 |
| self.exportLiteralAttributes(outfile, level, name_) |
| if self.hasContent_(): |
| self.exportLiteralChildren(outfile, level, name_) |
| def exportLiteralAttributes(self, outfile, level, name_): |
| pass |
| def exportLiteralChildren(self, outfile, level, name_): |
| if self.arch_file is not None: |
| showIndent(outfile, level) |
| outfile.write('arch_file=%s,\n' % quote_python(self.arch_file).encode(ExternalEncoding)) |
| def build(self, node_): |
| attrs = node_.attributes |
| self.buildAttributes(attrs) |
| for child_ in node_.childNodes: |
| nodeName_ = child_.nodeName.split(':')[-1] |
| self.buildChildren(child_, nodeName_) |
| def buildAttributes(self, attrs): |
| pass |
| def buildChildren(self, child_, nodeName_): |
| if child_.nodeType == Node.ELEMENT_NODE and \ |
| nodeName_ == 'arch_file': |
| arch_file_ = '' |
| for text__content_ in child_.childNodes: |
| arch_file_ += text__content_.nodeValue |
| self.arch_file = arch_file_ |
| # end class target |
| |
| |
| class optimizations(GeneratedsSuper): |
| subclass = None |
| superclass = None |
| def __init__(self, multiply=None, memory=None): |
| self.multiply = multiply |
| self.memory = memory |
| def factory(*args_, **kwargs_): |
| if optimizations.subclass: |
| return optimizations.subclass(*args_, **kwargs_) |
| else: |
| return optimizations(*args_, **kwargs_) |
| factory = staticmethod(factory) |
| def get_multiply(self): return self.multiply |
| def set_multiply(self, multiply): self.multiply = multiply |
| def get_memory(self): return self.memory |
| def set_memory(self, memory): self.memory = memory |
| def export(self, outfile, level, namespace_='', name_='optimizations', namespacedef_=''): |
| showIndent(outfile, level) |
| outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) |
| self.exportAttributes(outfile, level, namespace_, name_='optimizations') |
| if self.hasContent_(): |
| outfile.write('>\n') |
| self.exportChildren(outfile, level + 1, namespace_, name_) |
| showIndent(outfile, level) |
| outfile.write('</%s%s>\n' % (namespace_, name_)) |
| else: |
| outfile.write('/>\n') |
| def exportAttributes(self, outfile, level, namespace_='', name_='optimizations'): |
| pass |
| def exportChildren(self, outfile, level, namespace_='', name_='optimizations'): |
| if self.multiply: |
| self.multiply.export(outfile, level, namespace_, name_='multiply', ) |
| if self.memory: |
| self.memory.export(outfile, level, namespace_, name_='memory', ) |
| def hasContent_(self): |
| if ( |
| self.multiply is not None or |
| self.memory is not None |
| ): |
| return True |
| else: |
| return False |
| def exportLiteral(self, outfile, level, name_='optimizations'): |
| level += 1 |
| self.exportLiteralAttributes(outfile, level, name_) |
| if self.hasContent_(): |
| self.exportLiteralChildren(outfile, level, name_) |
| def exportLiteralAttributes(self, outfile, level, name_): |
| pass |
| def exportLiteralChildren(self, outfile, level, name_): |
| if self.multiply is not None: |
| showIndent(outfile, level) |
| outfile.write('multiply=model_.multiply(\n') |
| self.multiply.exportLiteral(outfile, level) |
| showIndent(outfile, level) |
| outfile.write('),\n') |
| if self.memory is not None: |
| showIndent(outfile, level) |
| outfile.write('memory=model_.memory(\n') |
| self.memory.exportLiteral(outfile, level) |
| showIndent(outfile, level) |
| outfile.write('),\n') |
| def build(self, node_): |
| attrs = node_.attributes |
| self.buildAttributes(attrs) |
| for child_ in node_.childNodes: |
| nodeName_ = child_.nodeName.split(':')[-1] |
| self.buildChildren(child_, nodeName_) |
| def buildAttributes(self, attrs): |
| pass |
| def buildChildren(self, child_, nodeName_): |
| if child_.nodeType == Node.ELEMENT_NODE and \ |
| nodeName_ == 'multiply': |
| obj_ = multiply.factory() |
| obj_.build(child_) |
| self.set_multiply(obj_) |
| elif child_.nodeType == Node.ELEMENT_NODE and \ |
| nodeName_ == 'memory': |
| obj_ = memory.factory() |
| obj_.build(child_) |
| self.set_memory(obj_) |
| # end class optimizations |
| |
| |
| class multiply(GeneratedsSuper): |
| subclass = None |
| superclass = None |
| def __init__(self, fixed=None, fracture=None, size=None, valueOf_=''): |
| self.fixed = _cast(int, fixed) |
| self.fracture = _cast(int, fracture) |
| self.size = _cast(int, size) |
| self.valueOf_ = valueOf_ |
| def factory(*args_, **kwargs_): |
| if multiply.subclass: |
| return multiply.subclass(*args_, **kwargs_) |
| else: |
| return multiply(*args_, **kwargs_) |
| factory = staticmethod(factory) |
| def get_fixed(self): return self.fixed |
| def set_fixed(self, fixed): self.fixed = fixed |
| def get_fracture(self): return self.fracture |
| def set_fracture(self, fracture): self.fracture = fracture |
| def get_size(self): return self.size |
| def set_size(self, size): self.size = size |
| def getValueOf_(self): return self.valueOf_ |
| def setValueOf_(self, valueOf_): self.valueOf_ = valueOf_ |
| def export(self, outfile, level, namespace_='', name_='multiply', namespacedef_=''): |
| showIndent(outfile, level) |
| outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) |
| self.exportAttributes(outfile, level, namespace_, name_='multiply') |
| if self.hasContent_(): |
| outfile.write('>') |
| self.exportChildren(outfile, level + 1, namespace_, name_) |
| outfile.write('</%s%s>\n' % (namespace_, name_)) |
| else: |
| outfile.write('/>\n') |
| def exportAttributes(self, outfile, level, namespace_='', name_='multiply'): |
| if self.fixed is not None: |
| outfile.write(' fixed="%s"' % self.format_integer(self.fixed, input_name='fixed')) |
| if self.fracture is not None: |
| outfile.write(' fracture="%s"' % self.format_integer(self.fracture, input_name='fracture')) |
| if self.size is not None: |
| outfile.write(' size="%s"' % self.format_integer(self.size, input_name='size')) |
| def exportChildren(self, outfile, level, namespace_='', name_='multiply'): |
| if self.valueOf_.find('![CDATA') > -1: |
| value=quote_xml('%s' % self.valueOf_) |
| value=value.replace('![CDATA','<![CDATA') |
| value=value.replace(']]',']]>') |
| outfile.write(value) |
| else: |
| outfile.write(quote_xml('%s' % self.valueOf_)) |
| def hasContent_(self): |
| if ( |
| self.valueOf_ |
| ): |
| return True |
| else: |
| return False |
| def exportLiteral(self, outfile, level, name_='multiply'): |
| level += 1 |
| self.exportLiteralAttributes(outfile, level, name_) |
| if self.hasContent_(): |
| self.exportLiteralChildren(outfile, level, name_) |
| def exportLiteralAttributes(self, outfile, level, name_): |
| if self.fixed is not None: |
| showIndent(outfile, level) |
| outfile.write('fixed = %d,\n' % (self.fixed,)) |
| if self.fracture is not None: |
| showIndent(outfile, level) |
| outfile.write('fracture = %d,\n' % (self.fracture,)) |
| if self.size is not None: |
| showIndent(outfile, level) |
| outfile.write('size = %d,\n' % (self.size,)) |
| def exportLiteralChildren(self, outfile, level, name_): |
| showIndent(outfile, level) |
| outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,)) |
| def build(self, node_): |
| attrs = node_.attributes |
| self.buildAttributes(attrs) |
| self.valueOf_ = '' |
| for child_ in node_.childNodes: |
| nodeName_ = child_.nodeName.split(':')[-1] |
| self.buildChildren(child_, nodeName_) |
| def buildAttributes(self, attrs): |
| if attrs.get('fixed'): |
| try: |
| self.fixed = int(attrs.get('fixed').value) |
| except ValueError, exp: |
| raise ValueError('Bad integer attribute (fixed): %s' % exp) |
| if attrs.get('fracture'): |
| try: |
| self.fracture = int(attrs.get('fracture').value) |
| except ValueError, exp: |
| raise ValueError('Bad integer attribute (fracture): %s' % exp) |
| if attrs.get('size'): |
| try: |
| self.size = int(attrs.get('size').value) |
| except ValueError, exp: |
| raise ValueError('Bad integer attribute (size): %s' % exp) |
| def buildChildren(self, child_, nodeName_): |
| if child_.nodeType == Node.TEXT_NODE: |
| self.valueOf_ += child_.nodeValue |
| elif child_.nodeType == Node.CDATA_SECTION_NODE: |
| self.valueOf_ += '![CDATA['+child_.nodeValue+']]' |
| # end class multiply |
| |
| |
| class memory(GeneratedsSuper): |
| subclass = None |
| superclass = None |
| def __init__(self, split_memory_width=None, split_memory_depth=None, valueOf_=''): |
| self.split_memory_width = _cast(int, split_memory_width) |
| self.split_memory_depth = _cast(int, split_memory_depth) |
| self.valueOf_ = valueOf_ |
| def factory(*args_, **kwargs_): |
| if memory.subclass: |
| return memory.subclass(*args_, **kwargs_) |
| else: |
| return memory(*args_, **kwargs_) |
| factory = staticmethod(factory) |
| def get_split_memory_width(self): return self.split_memory_width |
| def set_split_memory_width(self, split_memory_width): self.split_memory_width = split_memory_width |
| def get_split_memory_depth(self): return self.split_memory_depth |
| def set_split_memory_depth(self, split_memory_depth): self.split_memory_depth = split_memory_depth |
| def getValueOf_(self): return self.valueOf_ |
| def setValueOf_(self, valueOf_): self.valueOf_ = valueOf_ |
| def export(self, outfile, level, namespace_='', name_='memory', namespacedef_=''): |
| showIndent(outfile, level) |
| outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) |
| self.exportAttributes(outfile, level, namespace_, name_='memory') |
| if self.hasContent_(): |
| outfile.write('>') |
| self.exportChildren(outfile, level + 1, namespace_, name_) |
| outfile.write('</%s%s>\n' % (namespace_, name_)) |
| else: |
| outfile.write('/>\n') |
| def exportAttributes(self, outfile, level, namespace_='', name_='memory'): |
| if self.split_memory_width is not None: |
| outfile.write(' split_memory_width="%s"' % self.format_integer(self.split_memory_width, input_name='split_memory_width')) |
| if self.split_memory_depth is not None: |
| outfile.write(' split_memory_depth="%s"' % self.format_integer(self.split_memory_depth, input_name='split_memory_depth')) |
| def exportChildren(self, outfile, level, namespace_='', name_='memory'): |
| if self.valueOf_.find('![CDATA') > -1: |
| value=quote_xml('%s' % self.valueOf_) |
| value=value.replace('![CDATA','<![CDATA') |
| value=value.replace(']]',']]>') |
| outfile.write(value) |
| else: |
| outfile.write(quote_xml('%s' % self.valueOf_)) |
| def hasContent_(self): |
| if ( |
| self.valueOf_ |
| ): |
| return True |
| else: |
| return False |
| def exportLiteral(self, outfile, level, name_='memory'): |
| level += 1 |
| self.exportLiteralAttributes(outfile, level, name_) |
| if self.hasContent_(): |
| self.exportLiteralChildren(outfile, level, name_) |
| def exportLiteralAttributes(self, outfile, level, name_): |
| if self.split_memory_width is not None: |
| showIndent(outfile, level) |
| outfile.write('split_memory_width = %d,\n' % (self.split_memory_width,)) |
| if self.split_memory_depth is not None: |
| showIndent(outfile, level) |
| outfile.write('split_memory_depth = %d,\n' % (self.split_memory_depth,)) |
| def exportLiteralChildren(self, outfile, level, name_): |
| showIndent(outfile, level) |
| outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,)) |
| def build(self, node_): |
| attrs = node_.attributes |
| self.buildAttributes(attrs) |
| self.valueOf_ = '' |
| for child_ in node_.childNodes: |
| nodeName_ = child_.nodeName.split(':')[-1] |
| self.buildChildren(child_, nodeName_) |
| def buildAttributes(self, attrs): |
| if attrs.get('split_memory_width'): |
| try: |
| self.split_memory_width = int(attrs.get('split_memory_width').value) |
| except ValueError, exp: |
| raise ValueError('Bad integer attribute (split_memory_width): %s' % exp) |
| if attrs.get('split_memory_depth'): |
| try: |
| self.split_memory_depth = int(attrs.get('split_memory_depth').value) |
| except ValueError, exp: |
| raise ValueError('Bad integer attribute (split_memory_depth): %s' % exp) |
| def buildChildren(self, child_, nodeName_): |
| if child_.nodeType == Node.TEXT_NODE: |
| self.valueOf_ += child_.nodeValue |
| elif child_.nodeType == Node.CDATA_SECTION_NODE: |
| self.valueOf_ += '![CDATA['+child_.nodeValue+']]' |
| # end class memory |
| |
| |
| class debug_outputs(GeneratedsSuper): |
| subclass = None |
| superclass = None |
| def __init__(self, debug_output_path=None, output_ast_graphs=None, output_netlist_graphs=None): |
| self.debug_output_path = debug_output_path |
| self.output_ast_graphs = output_ast_graphs |
| self.output_netlist_graphs = output_netlist_graphs |
| def factory(*args_, **kwargs_): |
| if debug_outputs.subclass: |
| return debug_outputs.subclass(*args_, **kwargs_) |
| else: |
| return debug_outputs(*args_, **kwargs_) |
| factory = staticmethod(factory) |
| def get_debug_output_path(self): return self.debug_output_path |
| def set_debug_output_path(self, debug_output_path): self.debug_output_path = debug_output_path |
| def get_output_ast_graphs(self): return self.output_ast_graphs |
| def set_output_ast_graphs(self, output_ast_graphs): self.output_ast_graphs = output_ast_graphs |
| def validate_output_ast_graphs(self, value): |
| # Validate type output_ast_graphs, a restriction on xs:integer. |
| pass |
| def get_output_netlist_graphs(self): return self.output_netlist_graphs |
| def set_output_netlist_graphs(self, output_netlist_graphs): self.output_netlist_graphs = output_netlist_graphs |
| def validate_output_netlist_graphs(self, value): |
| # Validate type output_netlist_graphs, a restriction on xs:integer. |
| pass |
| def export(self, outfile, level, namespace_='', name_='debug_outputs', namespacedef_=''): |
| showIndent(outfile, level) |
| outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) |
| self.exportAttributes(outfile, level, namespace_, name_='debug_outputs') |
| if self.hasContent_(): |
| outfile.write('>\n') |
| self.exportChildren(outfile, level + 1, namespace_, name_) |
| showIndent(outfile, level) |
| outfile.write('</%s%s>\n' % (namespace_, name_)) |
| else: |
| outfile.write('/>\n') |
| def exportAttributes(self, outfile, level, namespace_='', name_='debug_outputs'): |
| pass |
| def exportChildren(self, outfile, level, namespace_='', name_='debug_outputs'): |
| if self.debug_output_path is not None: |
| showIndent(outfile, level) |
| outfile.write('<%sdebug_output_path>%s</%sdebug_output_path>\n' % (namespace_, self.format_string(quote_xml(self.debug_output_path).encode(ExternalEncoding), input_name='debug_output_path'), namespace_)) |
| if self.output_ast_graphs is not None: |
| showIndent(outfile, level) |
| outfile.write('<%soutput_ast_graphs>%s</%soutput_ast_graphs>\n' % (namespace_, self.format_string(quote_xml(self.output_ast_graphs).encode(ExternalEncoding), input_name='output_ast_graphs'), namespace_)) |
| if self.output_netlist_graphs is not None: |
| showIndent(outfile, level) |
| outfile.write('<%soutput_netlist_graphs>%s</%soutput_netlist_graphs>\n' % (namespace_, self.format_string(quote_xml(self.output_netlist_graphs).encode(ExternalEncoding), input_name='output_netlist_graphs'), namespace_)) |
| def hasContent_(self): |
| if ( |
| self.debug_output_path is not None or |
| self.output_ast_graphs is not None or |
| self.output_netlist_graphs is not None |
| ): |
| return True |
| else: |
| return False |
| def exportLiteral(self, outfile, level, name_='debug_outputs'): |
| level += 1 |
| self.exportLiteralAttributes(outfile, level, name_) |
| if self.hasContent_(): |
| self.exportLiteralChildren(outfile, level, name_) |
| def exportLiteralAttributes(self, outfile, level, name_): |
| pass |
| def exportLiteralChildren(self, outfile, level, name_): |
| if self.debug_output_path is not None: |
| showIndent(outfile, level) |
| outfile.write('debug_output_path=%s,\n' % quote_python(self.debug_output_path).encode(ExternalEncoding)) |
| if self.output_ast_graphs is not None: |
| showIndent(outfile, level) |
| outfile.write('output_ast_graphs=%s,\n' % quote_python(self.output_ast_graphs).encode(ExternalEncoding)) |
| if self.output_netlist_graphs is not None: |
| showIndent(outfile, level) |
| outfile.write('output_netlist_graphs=%s,\n' % quote_python(self.output_netlist_graphs).encode(ExternalEncoding)) |
| def build(self, node_): |
| attrs = node_.attributes |
| self.buildAttributes(attrs) |
| for child_ in node_.childNodes: |
| nodeName_ = child_.nodeName.split(':')[-1] |
| self.buildChildren(child_, nodeName_) |
| def buildAttributes(self, attrs): |
| pass |
| def buildChildren(self, child_, nodeName_): |
| if child_.nodeType == Node.ELEMENT_NODE and \ |
| nodeName_ == 'debug_output_path': |
| debug_output_path_ = '' |
| for text__content_ in child_.childNodes: |
| debug_output_path_ += text__content_.nodeValue |
| self.debug_output_path = debug_output_path_ |
| elif child_.nodeType == Node.ELEMENT_NODE and \ |
| nodeName_ == 'output_ast_graphs': |
| output_ast_graphs_ = '' |
| for text__content_ in child_.childNodes: |
| output_ast_graphs_ += text__content_.nodeValue |
| self.output_ast_graphs = output_ast_graphs_ |
| self.validate_output_ast_graphs(self.output_ast_graphs) # validate type output_ast_graphs |
| elif child_.nodeType == Node.ELEMENT_NODE and \ |
| nodeName_ == 'output_netlist_graphs': |
| output_netlist_graphs_ = '' |
| for text__content_ in child_.childNodes: |
| output_netlist_graphs_ += text__content_.nodeValue |
| self.output_netlist_graphs = output_netlist_graphs_ |
| self.validate_output_netlist_graphs(self.output_netlist_graphs) # validate type output_netlist_graphs |
| # end class debug_outputs |
| |
| |
| class output_ast_graphs(GeneratedsSuper): |
| subclass = None |
| superclass = None |
| def __init__(self, valueOf_=''): |
| self.valueOf_ = valueOf_ |
| def factory(*args_, **kwargs_): |
| if output_ast_graphs.subclass: |
| return output_ast_graphs.subclass(*args_, **kwargs_) |
| else: |
| return output_ast_graphs(*args_, **kwargs_) |
| factory = staticmethod(factory) |
| def getValueOf_(self): return self.valueOf_ |
| def setValueOf_(self, valueOf_): self.valueOf_ = valueOf_ |
| def export(self, outfile, level, namespace_='', name_='output_ast_graphs', namespacedef_=''): |
| showIndent(outfile, level) |
| outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) |
| self.exportAttributes(outfile, level, namespace_, name_='output_ast_graphs') |
| if self.hasContent_(): |
| outfile.write('>') |
| self.exportChildren(outfile, level + 1, namespace_, name_) |
| outfile.write('</%s%s>\n' % (namespace_, name_)) |
| else: |
| outfile.write('/>\n') |
| def exportAttributes(self, outfile, level, namespace_='', name_='output_ast_graphs'): |
| pass |
| def exportChildren(self, outfile, level, namespace_='', name_='output_ast_graphs'): |
| if self.valueOf_.find('![CDATA') > -1: |
| value=quote_xml('%s' % self.valueOf_) |
| value=value.replace('![CDATA','<![CDATA') |
| value=value.replace(']]',']]>') |
| outfile.write(value) |
| else: |
| outfile.write(quote_xml('%s' % self.valueOf_)) |
| def hasContent_(self): |
| if ( |
| self.valueOf_ |
| ): |
| return True |
| else: |
| return False |
| def exportLiteral(self, outfile, level, name_='output_ast_graphs'): |
| level += 1 |
| self.exportLiteralAttributes(outfile, level, name_) |
| if self.hasContent_(): |
| self.exportLiteralChildren(outfile, level, name_) |
| def exportLiteralAttributes(self, outfile, level, name_): |
| pass |
| def exportLiteralChildren(self, outfile, level, name_): |
| showIndent(outfile, level) |
| outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,)) |
| def build(self, node_): |
| attrs = node_.attributes |
| self.buildAttributes(attrs) |
| self.valueOf_ = '' |
| for child_ in node_.childNodes: |
| nodeName_ = child_.nodeName.split(':')[-1] |
| self.buildChildren(child_, nodeName_) |
| def buildAttributes(self, attrs): |
| pass |
| def buildChildren(self, child_, nodeName_): |
| if child_.nodeType == Node.TEXT_NODE: |
| self.valueOf_ += child_.nodeValue |
| elif child_.nodeType == Node.CDATA_SECTION_NODE: |
| self.valueOf_ += '![CDATA['+child_.nodeValue+']]' |
| # end class output_ast_graphs |
| |
| |
| class output_netlist_graphs(GeneratedsSuper): |
| subclass = None |
| superclass = None |
| def __init__(self, valueOf_=''): |
| self.valueOf_ = valueOf_ |
| def factory(*args_, **kwargs_): |
| if output_netlist_graphs.subclass: |
| return output_netlist_graphs.subclass(*args_, **kwargs_) |
| else: |
| return output_netlist_graphs(*args_, **kwargs_) |
| factory = staticmethod(factory) |
| def getValueOf_(self): return self.valueOf_ |
| def setValueOf_(self, valueOf_): self.valueOf_ = valueOf_ |
| def export(self, outfile, level, namespace_='', name_='output_netlist_graphs', namespacedef_=''): |
| showIndent(outfile, level) |
| outfile.write('<%s%s%s' % (namespace_, name_, namespacedef_ and ' ' + namespacedef_ or '', )) |
| self.exportAttributes(outfile, level, namespace_, name_='output_netlist_graphs') |
| if self.hasContent_(): |
| outfile.write('>') |
| self.exportChildren(outfile, level + 1, namespace_, name_) |
| outfile.write('</%s%s>\n' % (namespace_, name_)) |
| else: |
| outfile.write('/>\n') |
| def exportAttributes(self, outfile, level, namespace_='', name_='output_netlist_graphs'): |
| pass |
| def exportChildren(self, outfile, level, namespace_='', name_='output_netlist_graphs'): |
| if self.valueOf_.find('![CDATA') > -1: |
| value=quote_xml('%s' % self.valueOf_) |
| value=value.replace('![CDATA','<![CDATA') |
| value=value.replace(']]',']]>') |
| outfile.write(value) |
| else: |
| outfile.write(quote_xml('%s' % self.valueOf_)) |
| def hasContent_(self): |
| if ( |
| self.valueOf_ |
| ): |
| return True |
| else: |
| return False |
| def exportLiteral(self, outfile, level, name_='output_netlist_graphs'): |
| level += 1 |
| self.exportLiteralAttributes(outfile, level, name_) |
| if self.hasContent_(): |
| self.exportLiteralChildren(outfile, level, name_) |
| def exportLiteralAttributes(self, outfile, level, name_): |
| pass |
| def exportLiteralChildren(self, outfile, level, name_): |
| showIndent(outfile, level) |
| outfile.write('valueOf_ = """%s""",\n' % (self.valueOf_,)) |
| def build(self, node_): |
| attrs = node_.attributes |
| self.buildAttributes(attrs) |
| self.valueOf_ = '' |
| for child_ in node_.childNodes: |
| nodeName_ = child_.nodeName.split(':')[-1] |
| self.buildChildren(child_, nodeName_) |
| def buildAttributes(self, attrs): |
| pass |
| def buildChildren(self, child_, nodeName_): |
| if child_.nodeType == Node.TEXT_NODE: |
| self.valueOf_ += child_.nodeValue |
| elif child_.nodeType == Node.CDATA_SECTION_NODE: |
| self.valueOf_ += '![CDATA['+child_.nodeValue+']]' |
| # end class output_netlist_graphs |
| |
| |
| USAGE_TEXT = """ |
| Usage: python <Parser>.py [ -s ] <in_xml_file> |
| """ |
| |
| def usage(): |
| print USAGE_TEXT |
| sys.exit(1) |
| |
| |
| def parse(inFileName): |
| doc = minidom.parse(inFileName) |
| rootNode = doc.documentElement |
| rootObj = config.factory() |
| rootObj.build(rootNode) |
| # Enable Python to collect the space used by the DOM. |
| doc = None |
| sys.stdout.write('<?xml version="1.0" ?>\n') |
| rootObj.export(sys.stdout, 0, name_="config", |
| namespacedef_='') |
| return rootObj |
| |
| |
| def parseString(inString): |
| doc = minidom.parseString(inString) |
| rootNode = doc.documentElement |
| rootObj = config.factory() |
| rootObj.build(rootNode) |
| # Enable Python to collect the space used by the DOM. |
| doc = None |
| sys.stdout.write('<?xml version="1.0" ?>\n') |
| rootObj.export(sys.stdout, 0, name_="config", |
| namespacedef_='') |
| return rootObj |
| |
| |
| def parseLiteral(inFileName): |
| doc = minidom.parse(inFileName) |
| rootNode = doc.documentElement |
| rootObj = config.factory() |
| rootObj.build(rootNode) |
| # Enable Python to collect the space used by the DOM. |
| doc = None |
| sys.stdout.write('#from ODIN_CONFIG import *\n\n') |
| sys.stdout.write('import ODIN_CONFIG as model_\n\n') |
| sys.stdout.write('rootObj = model_.config(\n') |
| rootObj.exportLiteral(sys.stdout, 0, name_="config") |
| sys.stdout.write(')\n') |
| return rootObj |
| |
| |
| def main(): |
| args = sys.argv[1:] |
| if len(args) == 1: |
| parse(args[0]) |
| else: |
| usage() |
| |
| |
| if __name__ == '__main__': |
| #import pdb; pdb.set_trace() |
| main() |
| |