示例#1
0
def _analyzeGens(top, absnames):
    genlist = []
    for g in top:
        if isinstance(g, _UserCode):
            tree = g
        elif isinstance(g, (_AlwaysComb, _AlwaysSeq, _Always)):
            f = g.func
            s = inspect.getsource(f)
            s = _dedent(s)
            tree = ast.parse(s)
            #print ast.dump(tree)
            tree.sourcefile  = inspect.getsourcefile(f)
            tree.lineoffset = inspect.getsourcelines(f)[1]-1
            tree.symdict = f.func_globals.copy()
            tree.callstack = []
            # handle free variables
            tree.nonlocaldict = {}
            if f.func_code.co_freevars:
                for n, c in zip(f.func_code.co_freevars, f.func_closure):
                    obj = _cell_deref(c)
                    if isinstance(g, _AlwaysComb):
                        if not ( isinstance(obj, (int, long, EnumType,_Signal)) or \
                                 _isMem(obj) or _isTupleOfInts(obj)
                               ):
                            info =  "File %s, line %s: " % (tree.sourcefile, tree.lineoffset)
                            print type(obj)
                            raise ConversionError(_error.UnsupportedType, n, info)
                    tree.symdict[n] = obj
                    # currently, only intbv as automatic nonlocals (until Python 3.0)
                    if isinstance(obj, intbv):
                        tree.nonlocaldict[n] = obj
            tree.name = absnames.get(id(g), str(_Label("BLOCK"))).upper()
            v = _FirstPassVisitor(tree)
            v.visit(tree)
            if isinstance(g, _AlwaysComb):
                v = _AnalyzeAlwaysCombVisitor(tree, g.senslist)
            elif isinstance(g, _AlwaysSeq):
                v = _AnalyzeAlwaysSeqVisitor(tree, g.senslist, g.reset, g.sigregs, g.varregs)
            else:
                v = _AnalyzeAlwaysDecoVisitor(tree, g.senslist)
            v.visit(tree)
        else: # @instance
            f = g.gen.gi_frame
            s = inspect.getsource(f)
            s = _dedent(s)
            tree = ast.parse(s)
            # print ast.dump(tree)
            tree.sourcefile = inspect.getsourcefile(f)
            tree.lineoffset = inspect.getsourcelines(f)[1]-1
            tree.symdict = f.f_globals.copy()
            tree.symdict.update(f.f_locals)
            tree.nonlocaldict = {}
            tree.callstack = []
            tree.name = absnames.get(id(g), str(_Label("BLOCK"))).upper()
            v = _FirstPassVisitor(tree)
            v.visit(tree)
            v = _AnalyzeBlockVisitor(tree)
            v.visit(tree)
        genlist.append(tree)
    return genlist
示例#2
0
def _analyzeGens(top, absnames):
    genlist = []
    for g in top:
        if isinstance(g, _UserCode):
            ast = g
        elif isinstance(g, (_AlwaysComb, _Always)):
            f = g.func
            s = inspect.getsource(f)
            # remove decorators
            s = re.sub(r"@.*", "", s)
            s = s.lstrip()
            ast = compiler.parse(s)
            # print ast
            ast.sourcefile = inspect.getsourcefile(f)
            ast.lineoffset = inspect.getsourcelines(f)[1]-1
            ast.symdict = f.func_globals.copy()
            ast.callstack = []
            # handle free variables
            if f.func_code.co_freevars:
                for n, c in zip(f.func_code.co_freevars, f.func_closure):
                    obj = _cell_deref(c)
                    if isinstance(g, _AlwaysComb):
                        # print type(obj)
                        assert isinstance(obj, (int, long, Signal)) or \
                               _isMem(obj) or _isTupleOfInts(obj)
                    ast.symdict[n] = obj
            ast.name = absnames.get(id(g), str(_Label("BLOCK"))).upper()
            v = _NotSupportedVisitor(ast)
            compiler.walk(ast, v)
            if isinstance(g, _AlwaysComb):
                v = _AnalyzeAlwaysCombVisitor(ast, g.senslist)
            else:
                v = _AnalyzeAlwaysDecoVisitor(ast, g.senslist)
            compiler.walk(ast, v)
        else: # @instance
            f = g.gen.gi_frame
            s = inspect.getsource(f)
            # remove decorators
            s = re.sub(r"@.*", "", s)
            s = s.lstrip()
            ast = compiler.parse(s)
            # print ast
            ast.sourcefile = inspect.getsourcefile(f)
            ast.lineoffset = inspect.getsourcelines(f)[1]-1
            ast.symdict = f.f_globals.copy()
            ast.symdict.update(f.f_locals)
            ast.callstack = []
            ast.name = absnames.get(id(g), str(_Label("BLOCK"))).upper()
            v = _NotSupportedVisitor(ast)
            compiler.walk(ast, v)
            v = _AnalyzeBlockVisitor(ast)
            compiler.walk(ast, v)
        genlist.append(ast)
    return genlist
示例#3
0
 def visitName(self, node, access=_access.INPUT, *args):
     n = node.name
     node.obj = None
     if n not in self.refStack:
         if n in self.ast.vardict:
             self.raiseError(node, _error.UnboundLocal, n)
         self.globalRefs.add(n)
     if n in self.ast.sigdict:
         node.obj = sig = self.ast.sigdict[n]
         if not isinstance(sig, Signal):
             # print "not a signal: %s" % n
             pass 
         else:
             if sig._type is bool:
                 node.edge = sig.posedge
         if access == _access.INPUT:
             self.ast.inputs.add(n)
         elif access == _access.OUTPUT:
             self.ast.kind = _kind.TASK
             if n in self.ast.outputs:
                 node.kind = _kind.REG
             self.ast.outputs.add(n)
         elif access == _access.UNKNOWN:
             pass
         else: 
             raise AssertionError
     if n in self.ast.vardict:
         obj = self.ast.vardict[n]
         if access == _access.INOUT:
             # upgrade bool to int for augmented assignments
             if isinstance(obj, bool):
                 obj = int(0)
                 self.ast.vardict[n] = obj
         node.obj = obj
     elif n in self.ast.symdict:
         node.obj = self.ast.symdict[n]
         if _isTupleOfInts(node.obj):
             node.obj = _Rom(node.obj)
             self.ast.hasRom = True
         elif isinstance(node.obj, int):
             node.value = node.obj
     elif n in __builtin__.__dict__:
         node.obj = __builtin__.__dict__[n]
     else:
         pass
     node.signed = _maybeNegative(node.obj)
示例#4
0
 def getName(self, node):
     n = node.id
     node.obj = None
     if n not in self.refStack:
         if (n in self.tree.vardict) and (n not in self.tree.nonlocaldict):
             self.raiseError(node, _error.UnboundLocal, n)
         self.globalRefs.add(n)
     if n in self.tree.sigdict:
         node.obj = sig = self.tree.sigdict[n]
         # mark shadow signal as driven only when they are seen somewhere
         if isinstance(sig, _ShadowSignal):
             sig._driven = 'wire'
         # mark tristate signal as driven if its driver is seen somewhere
         if isinstance(sig, _TristateDriver):
             sig._sig._driven = 'wire'
         if not isinstance(sig, _Signal):
             # print "not a signal: %s" % n
             pass
         else:
             if sig._type is bool:
                 node.edge = sig.posedge
         if self.access == _access.INPUT:
             self.tree.inputs.add(n)
         elif self.access == _access.OUTPUT:
             self.tree.kind = _kind.TASK
             if n in self.tree.outputs:
                 node.kind = _kind.REG
             self.tree.outputs.add(n)
         elif self.access == _access.UNKNOWN:
             pass
         else:
             self.raiseError(node, _error.NotSupported, "Augmented signal assignment")
     if n in self.tree.vardict:
         obj = self.tree.vardict[n]
         if self.access == _access.INOUT:  # probably dead code
             # upgrade bool to int for augmented assignments
             if isinstance(obj, bool):
                 obj = int(-1)
                 self.tree.vardict[n] = obj
         node.obj = obj
     elif n in self.tree.symdict:
         node.obj = self.tree.symdict[n]
         if _isTupleOfInts(node.obj):
             node.obj = _Rom(node.obj)
             self.tree.hasRom = True
         elif _isMem(node.obj):
             m = _getMemInfo(node.obj)
             if self.access == _access.INPUT:
                 m._read = True
             elif self.access == _access.OUTPUT:
                 m._driven = 'reg'
                 self.tree.outmems.add(n)
             elif self.access == _access.UNKNOWN:
                 pass
             else:
                 assert False, "unexpected mem access %s %s" % (n, self.access)
             self.tree.hasLos = True
         elif isinstance(node.obj, int):
             node.value = node.obj
         if n in self.tree.nonlocaldict:
             # hack: put nonlocal intbv's in the vardict
             self.tree.vardict[n] = v = node.obj
     elif n in builtins.__dict__:
         node.obj = builtins.__dict__[n]
     else:
         self.raiseError(node, _error.UnboundLocal, n)
示例#5
0
 def getName(self, node):
     n = node.id
     node.obj = None
     if n not in self.refStack:
         if (n in self.tree.vardict) and (n not in self.tree.nonlocaldict):
             self.raiseError(node, _error.UnboundLocal, n)
         self.globalRefs.add(n)
     if n in self.tree.sigdict:
         node.obj = sig = self.tree.sigdict[n]
         # mark shadow signal as driven only when they are seen somewhere
         if isinstance(sig, _ShadowSignal):
             sig._driven = 'wire'
         if not isinstance(sig, _Signal):
             # print "not a signal: %s" % n
             pass
         else:
             if sig._type is bool:
                 node.edge = sig.posedge
             ws = getattr(sig._val, 'lenStr', False)
             ext = getattr(sig._val, 'external', False)
             if ws and ws in self.tree.symdict:
                 _constDict[ws] = self.tree.symdict[ws]
                 if ext:
                     _extConstDict[ws] = self.tree.symdict[ws]
         if self.access == _access.INPUT:
             self.tree.inputs.add(n)
         elif self.access == _access.OUTPUT:
             self.tree.kind = _kind.TASK
             if n in self.tree.outputs:
                 node.kind = _kind.REG
             self.tree.outputs.add(n)
         elif self.access == _access.UNKNOWN:
             pass
         else:
             self.raiseError(node, _error.NotSupported, "Augmented signal assignment")
     if n in self.tree.vardict:
         obj = self.tree.vardict[n]
         if self.access == _access.INOUT: # probably dead code
             # upgrade bool to int for augmented assignments
             if isinstance(obj, bool):
                 obj = int(-1)
                 self.tree.vardict[n] = obj
         node.obj = obj
     elif n in self.tree.symdict:
         node.obj = self.tree.symdict[n]
         if _isTupleOfInts(node.obj):
             node.obj = _Rom(node.obj)
             self.tree.hasRom = True
         elif _isMem(node.obj):
             m = _getMemInfo(node.obj)
             if self.access == _access.INPUT:
                 m._read = True
             elif self.access == _access.OUTPUT:
                 m._driven = 'reg'
                 self.tree.outmems.add(n)
             elif self.access == _access.UNKNOWN:
                 pass
             else:
                 assert False, "unexpected mem access %s %s" % (n, self.access)
             self.tree.hasLos = True
             ws = getattr(m.elObj._val, 'lenStr', False)
             ext = getattr(m.elObj._val, 'external', False)
             if ws and ws in self.tree.symdict:
                 _constDict[ws] = self.tree.symdict[ws]
                 if ext:
                     _extConstDict[ws] = self.tree.symdict[ws]
         elif isinstance(node.obj, int):
             node.value = node.obj
             # put VHDL compliant integer constants in global dict
             if n not in _constDict and abs(node.obj) < 2**31:
                 _constDict[n] = node.obj
         if n in self.tree.nonlocaldict:
             # hack: put nonlocal intbv's in the vardict
             self.tree.vardict[n] = v = node.obj
             # typedef string for nonlocal intbv's
             ws = getattr(v, 'lenStr', False)
             ext = getattr(v, 'external', False)
             if ws and ws in self.tree.symdict:
                 _constDict[ws] = self.tree.symdict[ws]
                 if ext:
                     _extConstDict[ws] = self.tree.symdict[ws]
     elif n in __builtin__.__dict__:
         node.obj = __builtin__.__dict__[n]
     else:
         self.raiseError(node, _error.UnboundLocal, n)
示例#6
0
 def getName(self, node):
     n = node.id
     node.obj = None
     if n not in self.refStack:
         if (n in self.tree.vardict) and (n not in self.tree.nonlocaldict):
             self.raiseError(node, _error.UnboundLocal, n)
         self.globalRefs.add(n)
     if n in self.tree.sigdict:
         node.obj = sig = self.tree.sigdict[n]
         # mark shadow signal as driven only when they are seen somewhere
         if isinstance(sig, _ShadowSignal):
             sig._driven = 'wire'
         if not isinstance(sig, _Signal):
             # print "not a signal: %s" % n
             pass 
         else:
             if sig._type is bool:
                 node.edge = sig.posedge
             ws = getattr(sig._val, 'lenStr', False)
             ext = getattr(sig._val, 'external', False)
             if ws and ws in self.tree.symdict:
                 _constDict[ws] = self.tree.symdict[ws]
                 if ext:
                     _extConstDict[ws] = self.tree.symdict[ws]
         if self.access == _access.INPUT:
             self.tree.inputs.add(n)
         elif self.access == _access.OUTPUT:
             self.tree.kind = _kind.TASK
             if n in self.tree.outputs:
                 node.kind = _kind.REG
             self.tree.outputs.add(n)
         elif self.access == _access.UNKNOWN:
             pass
         else: 
             self.raiseError(node, _error.NotSupported, "Augmented signal assignment")
     if n in self.tree.vardict:
         obj = self.tree.vardict[n]
         if self.access == _access.INOUT: # probably dead code
             # upgrade bool to int for augmented assignments
             if isinstance(obj, bool):
                 obj = int(-1)
                 self.tree.vardict[n] = obj
         node.obj = obj
     elif n in self.tree.symdict:
         node.obj = self.tree.symdict[n]
         if _isTupleOfInts(node.obj):
             node.obj = _Rom(node.obj)
             self.tree.hasRom = True
         elif _isMem(node.obj):
             m = _getMemInfo(node.obj)
             if self.access == _access.INPUT:
                 m._read = True
             elif self.access == _access.OUTPUT:
                 m._driven = 'reg'
                 self.tree.outmems.add(n)
             elif self.access == _access.UNKNOWN:
                 pass
             else:
                 assert False, "unexpected mem access %s %s" % (n, self.access)
             self.tree.hasLos = True
             ws = getattr(m.elObj._val, 'lenStr', False)
             ext = getattr(m.elObj._val, 'external', False)
             if ws and ws in self.tree.symdict:
                 _constDict[ws] = self.tree.symdict[ws]
                 if ext:
                     _extConstDict[ws] = self.tree.symdict[ws]
         elif isinstance(node.obj, int):
             node.value = node.obj
             # put VHDL compliant integer constants in global dict
             if n not in _constDict and abs(node.obj) < 2**31:
                 _constDict[n] = node.obj
         if n in self.tree.nonlocaldict:
             # hack: put nonlocal intbv's in the vardict
             self.tree.vardict[n] = v = node.obj
             # typedef string for nonlocal intbv's
             ws = getattr(v, 'lenStr', False)
             ext = getattr(v, 'external', False)
             if ws and ws in self.tree.symdict:
                 _constDict[ws] = self.tree.symdict[ws]
                 if ext:
                     _extConstDict[ws] = self.tree.symdict[ws]
     elif n in __builtin__.__dict__:
         node.obj = __builtin__.__dict__[n]
     else:
         self.raiseError(node, _error.UnboundLocal, n)
示例#7
0
 def getName(self, node):
     n = node.id
     node.obj = None
     if n not in self.refStack:
         if (n in self.tree.vardict) and (n not in self.tree.nonlocaldict):
             self.raiseError(node, _error.UnboundLocal, n)
         self.globalRefs.add(n)
     if n in self.tree.sigdict:
         node.obj = sig = self.tree.sigdict[n]
         # mark shadow signal as driven only when they are seen somewhere
         if isinstance(sig, _ShadowSignal):
             sig._driven = 'wire'
         # mark tristate signal as driven if its driver is seen somewhere
         if isinstance(sig, _TristateDriver):
             sig._sig._driven = 'wire'
         if not isinstance(sig, _Signal):
             # print "not a signal: %s" % n
             pass
         else:
             if sig._type is bool:
                 node.edge = sig.posedge
         if self.access == _access.INPUT:
             self.tree.inputs.add(n)
         elif self.access == _access.OUTPUT:
             self.tree.kind = _kind.TASK
             if n in self.tree.outputs:
                 node.kind = _kind.REG
             self.tree.outputs.add(n)
         elif self.access == _access.UNKNOWN:
             pass
         else:
             self.raiseError(node, _error.NotSupported,
                             "Augmented signal assignment")
     if n in self.tree.vardict:
         obj = self.tree.vardict[n]
         if self.access == _access.INOUT:  # probably dead code
             # upgrade bool to int for augmented assignments
             if isinstance(obj, bool):
                 obj = int(-1)
                 self.tree.vardict[n] = obj
         node.obj = obj
     elif n in self.tree.symdict:
         node.obj = self.tree.symdict[n]
         if _isTupleOfInts(node.obj):
             node.obj = _Rom(node.obj)
             self.tree.hasRom = True
         elif _isMem(node.obj):
             m = _getMemInfo(node.obj)
             if self.access == _access.INPUT:
                 m._read = True
             elif self.access == _access.OUTPUT:
                 m._driven = 'reg'
                 self.tree.outmems.add(n)
             elif self.access == _access.UNKNOWN:
                 pass
             else:
                 assert False, "unexpected mem access %s %s" % (n,
                                                                self.access)
             self.tree.hasLos = True
         elif isinstance(node.obj, int):
             node.value = node.obj
         if n in self.tree.nonlocaldict:
             # hack: put nonlocal intbv's in the vardict
             self.tree.vardict[n] = v = node.obj
     elif n in builtins.__dict__:
         node.obj = builtins.__dict__[n]
     else:
         self.raiseError(node, _error.UnboundLocal, n)