Beispiel #1
0
def parse_spectre(netlist_string):
    # newlines are part of the grammar, thus redifine the whitespaces without it
    ws = ' \t'
    _p.ParserElement.setDefaultWhitespaceChars(ws)

    # spectre netlist grammar definition
    EOL = _p.LineEnd().suppress()  # end of line
    linebreak = _p.Suppress(
        "\\" + _p.LineEnd())  # breaking a line with backslash newline
    identifier = _p.Word(_p.alphanums + '_!<>-+')  # a name for...
    number = _p.Word(_p.nums + ".")  # a number
    net = identifier  # a net
    nets = _p.Group(_p.OneOrMore(net('net') | linebreak))  # many nets
    cktname = identifier  # name of a subcircuit
    cktname_end = _p.Keyword("ends").suppress()
    comment = _p.Suppress("//" + _p.SkipTo(_p.LineEnd()))
    expression = _p.Word(_p.alphanums + '._*+-/()')
    inst_param_key = identifier + _p.Suppress("=")
    inst_param_value = expression('expression')
    inst_parameter = _p.Group(
        inst_param_key('name') +
        inst_param_value('value')).setResultsName('key')
    parameters = _p.Group(
        _p.ZeroOrMore(inst_parameter | linebreak)).setResultsName('parameters')
    instref = identifier
    instname = identifier
    instance = _p.Group(
        instname('name') + _p.Suppress('(') + nets('nets') + _p.Suppress(')') +
        instref('reference') + parameters + EOL).setResultsName('instance')
    subcircuit_content = _p.Group(
        _p.ZeroOrMore(instance | EOL | comment)).setResultsName('subnetlist')
    subcircuit = _p.Group(
        # matches subckt <name> <nets> <newline>
        _p.Keyword("subckt").suppress() + cktname('name') + nets('nets') + EOL
        # matches the content of the subcircuit
        + subcircuit_content
        # matches ends <name> <newline>
        + cktname_end + _p.matchPreviousExpr(cktname).suppress() +
        EOL).setResultsName('subcircuit')
    topcircuit = _p.Group(
        # matches subckt <name> <nets> <newline>
        _p.Keyword("topckt").suppress() + cktname('name') + nets('nets') + EOL
        # matches the content of the subcircuit
        + subcircuit_content
        # matches ends <name> <newline>
        + cktname_end + _p.matchPreviousExpr(cktname).suppress() +
        EOL).setResultsName('topcircuit')
    netlist_element = subcircuit | topcircuit | EOL | comment('comment')
    netlist = _p.ZeroOrMore(netlist_element) + _p.StringEnd()

    parameters.setParseAction(handle_parameters)
    instance.setParseAction(handle_instance)
    subcircuit.setParseAction(handle_subcircuit)
    topcircuit.setParseAction(handle_topcircuit)

    return netlist.parseString(netlist_string)
def parse_hspice(netlist_string):
    # newlines are part of the grammar, thus redifine the whitespaces without it
    ws = ' \t'
    _p.ParserElement.setDefaultWhitespaceChars(ws)

    # spectre netlist grammar definition
    EOL = _p.LineEnd().suppress() # end of line
    linebreak = _p.Suppress(_p.LineEnd() + "+") # breaking a line with backslash newline
    identifier=_p.Word(_p.alphanums+'_!<>#') # a name for...
    number=_p.Word(_p.nums + ".") # a number
    net = identifier # a net
    nets = _p.Group(_p.OneOrMore(net('net') + ~_p.FollowedBy("=") | linebreak)) # many nets
    cktname = identifier # name of a subcircuit
    cktname_end = _p.CaselessLiteral(".ends").suppress()
    comment = _p.Suppress("//" + _p.SkipTo(_p.LineEnd())) | _p.Suppress("*" + _p.SkipTo(_p.LineEnd()))
    expression = _p.Word(_p.alphanums+'._*+-/()')
    inst_param_key = identifier + _p.Suppress("=")
    inst_param_value = expression('expression')
    inst_parameter = _p.Group(inst_param_key('name') + inst_param_value('value')).setResultsName('key')
    parameters = _p.Group(_p.ZeroOrMore(inst_parameter | linebreak)).setResultsName('parameters')
    instname = identifier
    instnets = _p.Group(_p.OneOrMore(net('net') + ~_p.FollowedBy("=") | linebreak))
    instance = _p.Group(instname('name') + instnets('instnets') + parameters + EOL).setResultsName('instance')
    subcircuit_content = _p.Group(_p.ZeroOrMore(instance | EOL | comment)).setResultsName('subnetlist')
    subcircuit = _p.Group(
        # matches subckt <name> <nets> <newline>
        _p.CaselessLiteral(".subckt").suppress() + cktname('name') + nets('nets') + EOL  
        # matches the content of the subcircuit
        + subcircuit_content
        # matches ends <name> <newline>
        + cktname_end + _p.matchPreviousExpr(cktname).suppress() + EOL).setResultsName('subcircuit')
    netlist_element = subcircuit | instance | EOL | comment('comment')
    netlist = _p.ZeroOrMore(netlist_element) + _p.StringEnd()
    
    parameters.setParseAction(handle_parameters)
    instance.setParseAction(handle_instance)
    subcircuit.setParseAction(handle_subcircuit)

    return netlist.parseString(netlist_string);
Beispiel #3
0
    syntax = (
        Optional(hasLiteral('encapsulated')) +
        Optional(hasLiteral('partial')) + 
        Suppress('operator') + Optional(
            hasLiteral('function') ^ hasLiteral('record')
            ) + ClassSpecifier.name('specification')
        )
    )

class_name = IDENT.name('class_name')
ClassSpecifier.ebnf(
    syntax = Or(
        (
            class_name + StringComment.name('comment') + 
            Composition.name('composition') + 
            Suppress('end') + matchPreviousExpr(class_name)
            ),
        (
            IDENT.name('class_name') + Suppress('=') + 
            BasePrefix.name('base_prefix') + Name.name('base_name') + 
            Optional(ArraySubscripts.name('base_subscripts')) + 
            Optional(ClassModification.name('base_modification')) +
            Comment.name('comment')
            ),
        
        )
    )

### B.2.3 Extends

Beispiel #4
0
                     ClassSpecifier.name('specification')))

Function.ebnf(syntax=(Optional(hasLiteral('encapsulated')) +
                      Optional(hasLiteral('partial')) + Suppress('function') +
                      ClassSpecifier.name('specification')))

Operator.ebnf(syntax=(Optional(hasLiteral('encapsulated')) +
                      Optional(hasLiteral('partial')) + Suppress('operator') +
                      Optional(hasLiteral('function') ^ hasLiteral('record')) +
                      ClassSpecifier.name('specification')))

class_name = IDENT.name('class_name')
ClassSpecifier.ebnf(syntax=Or(
    (class_name + StringComment.name('comment') +
     Composition.name('composition') + Suppress('end') +
     matchPreviousExpr(class_name)),
    (IDENT.name('class_name') + Suppress('=') +
     BasePrefix.name('base_prefix') + Name.name('base_name') +
     Optional(ArraySubscripts.name('base_subscripts')) +
     Optional(ClassModification.name('base_modification')) +
     Comment.name('comment')),
))

### B.2.3 Extends

### B.2.4 Component Clause

### B.2.5 Modification

### B.2.6 Equations
Beispiel #5
0
    def parse_hspice(self, netlist_file):
        """
        @brief parse the input hspice netlist file
        @param .sp file
        """
        with open(netlist_file, 'r') as fin:
            nl = fin.read()
            ws = ' \t'  #newlines are part of the syntax, thus redefine the whitespaces without it
            _p.ParserElement.setDefaultWhitespaceChars(ws)

            # spectre netlist grammar definition
            EOL = _p.LineEnd().suppress()  # end of line
            linebreak = _p.Suppress(
                _p.LineEnd() + "+")  # breaking a line with backslash newline
            identifier = _p.Word(_p.alphanums + '_!<>#-+')  # a name for...
            number = _p.Word(_p.nums + ".")  # a number
            net = identifier  # a net
            nets = _p.Group(
                _p.OneOrMore(net('net') + ~_p.FollowedBy("=")
                             | linebreak))  # many nets
            cktname = identifier  # name of a subcircuit
            cktname_end = _p.CaselessLiteral(".ends").suppress()
            comment = _p.Suppress("//" +
                                  _p.SkipTo(_p.LineEnd())) | _p.Suppress(
                                      "*" + _p.SkipTo(_p.LineEnd()))
            expression = _p.Word(_p.alphanums + '._*+-/()')
            inst_param_key = identifier + _p.Suppress("=")
            inst_param_value = expression('expression')
            inst_parameter = _p.Group(
                inst_param_key('name') +
                inst_param_value('value')).setResultsName('key')
            parameters = _p.Group(
                _p.ZeroOrMore(inst_parameter
                              | linebreak)).setResultsName('parameters')
            instname = identifier
            instnets = _p.Group(
                _p.OneOrMore(net('net') + ~_p.FollowedBy("=") | linebreak))
            instance = _p.Group(
                instname('name') + instnets('instnets') + parameters +
                EOL).setResultsName('instance')
            subcircuit_content = _p.Group(
                _p.ZeroOrMore(instance | EOL
                              | comment)).setResultsName('subnetlist')
            subcircuit = _p.Group(
                # matches subckt <name> <nets> <newline>
                _p.CaselessLiteral(".subckt").suppress() + cktname('name') +
                _p.Optional(nets('nets')) + EOL
                # matches the content of the subcircuit
                + subcircuit_content
                # matches ends <name> <newline>
                + cktname_end + _p.matchPreviousExpr(cktname).suppress() +
                EOL).setResultsName('subcircuit')
            topcircuit = _p.Group(
                # matches subckt <name> <nets> <newline>
                _p.CaselessLiteral(".topckt").suppress() + cktname('name') +
                _p.Optional(nets('nets')) + EOL
                # matches the content of the subcircuit
                + subcircuit_content
                # matches ends <name> <newline>
                + cktname_end + _p.matchPreviousExpr(cktname).suppress() +
                EOL).setResultsName('topcircuit')
            netlist_element = topcircuit | subcircuit | EOL | comment(
                'comment')
            netlist = _p.ZeroOrMore(netlist_element) + _p.StringEnd()

            parameters.setParseAction(handle_parameters)
            instance.setParseAction(handle_instance)
            subcircuit.setParseAction(handle_subcircuit)
            topcircuit.setParseAction(handle_topcircuit)

            self.raw_netlist = netlist.parseString(
                nl
            )  # Parse the file into raw_netlist and then translate into database

            self._finish_raw_parse = True
            self.translate_raw_netlist()