コード例 #1
0
ファイル: _analyze.py プロジェクト: hgomersall/myhdl
def _analyzeGens(top, absnames):
    genlist = []
    for g in top:
        if isinstance(g, _UserCode):
            tree = g
        elif isinstance(g, (_AlwaysComb, _AlwaysSeq, _Always)):
            f = g.func
            tree = g.ast
            tree.symdict = f.__globals__.copy()
            tree.callstack = []
            # handle free variables
            tree.nonlocaldict = {}
            if f.__code__.co_freevars:
                for n, c in zip(f.__code__.co_freevars, f.__closure__):
                    obj = c.cell_contents
                    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 = _AttrRefTransformer(tree)
            v.visit(tree)
            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
            tree = g.ast
            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 = _AttrRefTransformer(tree)
            v.visit(tree)
            v = _FirstPassVisitor(tree)
            v.visit(tree)
            v = _AnalyzeBlockVisitor(tree)
            v.visit(tree)
        genlist.append(tree)
    return genlist
コード例 #2
0
ファイル: _instance.py プロジェクト: arhik/myhdl
    def __init__(self, genfunc):
        self.genfunc = genfunc
        self.gen = genfunc()
        # infer symdict
        f = self.funcobj
        varnames = f.__code__.co_varnames
        symdict = {}
        for n, v in f.__globals__.items():
            if n not in varnames:
                symdict[n] = v
        # handle free variables
        freevars = f.__code__.co_freevars
        if freevars:
            closure = (c.cell_contents for c in f.__closure__)
            symdict.update(zip(freevars, closure))
        self.symdict = symdict

        tree = self.ast
        # print ast.dump(tree)
        v = _AttrRefTransformer(self)
        v.visit(tree)
        v = _SigNameVisitor(self.symdict)
        v.visit(tree)
        self.inputs = v.inputs
        self.outputs = v.outputs
        self.inouts = v.inouts
        self.embedded_func = v.embedded_func
コード例 #3
0
ファイル: _always_comb.py プロジェクト: Thomasb81/myhdl
    def __init__(self, func, symdict):
        self.symdict = symdict
        s = inspect.getsource(func)
        s = _dedent(s)
        tree = ast.parse(s)
        # print ast.dump(tree)
        v = _AttrRefTransformer(self)
        v.visit(tree)
        v = _SigNameVisitor(self.symdict)
        v.visit(tree)
        self.inputs = v.results["input"]
        self.outputs = v.results["output"]

        inouts = v.results["inout"] | self.inputs.intersection(self.outputs)
        if inouts:
            raise AlwaysCombError(_error.SignalAsInout % inouts)

        if v.results["embedded_func"]:
            raise AlwaysCombError(_error.EmbeddedFunction)

        senslist = []
        for n in self.inputs:
            s = self.symdict[n]
            if isinstance(s, _Signal):
                senslist.append(s)
            elif _isListOfSigs(s):
                senslist.extend(s)
        self.senslist = tuple(senslist)
        if len(self.senslist) == 0:
            raise AlwaysCombError(_error.EmptySensitivityList)

        super(_AlwaysComb, self).__init__(func, senslist)
コード例 #4
0
ファイル: _instance.py プロジェクト: unornate/myhdl
    def __init__(self, genfunc, callinfo):
        self.callinfo = callinfo
        self.callername = callinfo.name
        self.modctxt = callinfo.modctxt
        self.genfunc = genfunc
        self.gen = genfunc()
        # infer symdict
        f = self.funcobj
        varnames = f.__code__.co_varnames
        symdict = {}
        for n, v in callinfo.symdict.items():
            if n not in varnames:
                symdict[n] = v
        self.symdict = symdict

        # print modname, genfunc.__name__
        tree = self.ast
        # print ast.dump(tree)
        v = _AttrRefTransformer(self)
        v.visit(tree)
        v = _SigNameVisitor(self.symdict)
        v.visit(tree)
        self.inputs = v.inputs
        self.outputs = v.outputs
        self.inouts = v.inouts
        self.embedded_func = v.embedded_func
        self.sigdict = v.sigdict
        self.losdict = v.losdict
コード例 #5
0
 def __init__(self, func, symdict):
     self.func = func
     self.symdict = symdict
     s = inspect.getsource(func)
     s = _dedent(s)
     tree = ast.parse(s)
     # print ast.dump(tree)
     v = _AttrRefTransformer(self)
     v.visit(tree)
     v = _SigNameVisitor(self.symdict)
     v.visit(tree)
     self.inputs = v.inputs
     self.outputs = v.outputs
     senslist = []
     for n in self.inputs:
         s = self.symdict[n]
         if isinstance(s, _Signal):
             senslist.append(s)
         else:  # list of sigs
             senslist.extend(s)
     self.senslist = tuple(senslist)
     self.gen = self.genfunc()
     if len(self.senslist) == 0:
         raise AlwaysCombError(_error.EmptySensitivityList)
     if len(self.senslist) == 1:
         W = _SignalWaiter
     else:
         W = _SignalTupleWaiter
     self.waiter = W(self.gen)
コード例 #6
0
ファイル: _instance.py プロジェクト: Aravind-Suresh/myhdl
    def __init__(self, genfunc):
        self.genfunc = genfunc
        self.gen = genfunc()
        # infer symdict
        f = self.funcobj
        varnames = f.__code__.co_varnames
        symdict = {}
        for n, v in f.__globals__.items():
            if n not in varnames:
                symdict[n] = v
        # handle free variables
        freevars = f.__code__.co_freevars
        if freevars:
            closure = (c.cell_contents for c in f.__closure__)
            symdict.update(zip(freevars, closure))
        self.symdict = symdict

        tree = self.ast
        # print ast.dump(tree)
        v = _AttrRefTransformer(self)
        v.visit(tree)
        v = _SigNameVisitor(self.symdict)
        v.visit(tree)
        self.inputs = v.inputs
        self.outputs = v.outputs
        self.inouts = v.inouts
        self.embedded_func = v.embedded_func
コード例 #7
0
    def __init__(self, func):
        senslist = []
        super(_AlwaysComb, self).__init__(func, senslist)

        s = inspect.getsource(func)
        s = _dedent(s)
        tree = ast.parse(s)
        # print ast.dump(tree)
        v = _AttrRefTransformer(self)
        v.visit(tree)
        v = _SigNameVisitor(self.symdict)
        v.visit(tree)
        self.inputs = v.results['input']
        self.outputs = v.results['output']

        inouts = v.results['inout'] | self.inputs.intersection(self.outputs)
        if inouts:
            raise AlwaysCombError(_error.SignalAsInout % inouts)

        if v.results['embedded_func']:
            raise AlwaysCombError(_error.EmbeddedFunction)

        for n in self.inputs:
            s = self.symdict[n]
            if isinstance(s, _Signal):
                senslist.append(s)
            elif _isListOfSigs(s):
                senslist.extend(s)
        self.senslist = tuple(senslist)
        if len(self.senslist) == 0:
            raise AlwaysCombError(_error.EmptySensitivityList)
コード例 #8
0
ファイル: _instance.py プロジェクト: StudentESE/myhdl
    def __init__(self, genfunc, callinfo):
        self.callinfo = callinfo
        self.callername = callinfo.name
        self.modctxt = callinfo.modctxt
        self.genfunc = genfunc
        self.gen = genfunc()
        # infer symdict
        f = self.funcobj
        varnames = f.__code__.co_varnames
        symdict = {}
        for n, v in callinfo.symdict.items():
            if n not in varnames:
                symdict[n] = v
        self.symdict = symdict

        # print modname, genfunc.__name__
        tree = self.ast
        # print ast.dump(tree)
        v = _AttrRefTransformer(self)
        v.visit(tree)
        v = _SigNameVisitor(self.symdict)
        v.visit(tree)
        self.inputs = v.inputs
        self.outputs = v.outputs
        self.inouts = v.inouts
        self.embedded_func = v.embedded_func
        self.sigdict = v.sigdict
        self.losdict = v.losdict
コード例 #9
0
ファイル: _always_comb.py プロジェクト: Cadavis8/myhdl
 def __init__(self, func, symdict):
     self.func = func
     self.symdict = symdict
     s = inspect.getsource(func)
     s = _dedent(s)
     tree = ast.parse(s)
     # print ast.dump(tree)
     v = _AttrRefTransformer(self)
     v.visit(tree)
     v = _SigNameVisitor(self.symdict)
     v.visit(tree)
     self.inputs = v.inputs
     self.outputs = v.outputs
     senslist = []
     for n in self.inputs:
         s = self.symdict[n]
         if isinstance(s, _Signal):
             senslist.append(s)
         else: # list of sigs
             senslist.extend(s)
     self.senslist = tuple(senslist)
     self.gen = self.genfunc()
     if len(self.senslist) == 0:
         raise AlwaysCombError(_error.EmptySensitivityList)
     if len(self.senslist) == 1:
         W = _SignalWaiter
     else:
         W = _SignalTupleWaiter
     self.waiter = W(self.gen)
コード例 #10
0
ファイル: _analyze.py プロジェクト: cpeppenster/myhdl
def _analyzeGens(top, absnames):
    genlist = []
    for g in top:
        if isinstance(g, _UserCode):
            tree = g
        elif isinstance(g, (_AlwaysComb, _AlwaysSeq, _Always)):
            f = g.func
            tree = g.ast
            tree.symdict = f.__globals__.copy()
            tree.callstack = []
            # handle free variables
            tree.nonlocaldict = {}
            if f.__code__.co_freevars:
                for n, c in zip(f.__code__.co_freevars, f.__closure__):
                    obj = c.cell_contents
                    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 = _AttrRefTransformer(tree)
            v.visit(tree)
            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
            tree = g.ast
            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 = _AttrRefTransformer(tree)
            v.visit(tree)
            v = _FirstPassVisitor(tree)
            v.visit(tree)
            v = _AnalyzeBlockVisitor(tree)
            v.visit(tree)
        genlist.append(tree)
    return genlist
コード例 #11
0
ファイル: _always_seq.py プロジェクト: forrestv/myhdl
        # handle free variables
        if func.func_code.co_freevars:
            for n, c in zip(func.func_code.co_freevars, func.func_closure):
                try:
                    obj = _cell_deref(c)
                    symdict[n] = obj
                except NameError:
                    raise NameError(n)
        self.symdict = symdict

        # now infer outputs to be reset
        s = inspect.getsource(func)
        s = _dedent(s)
        tree = ast.parse(s)
        # print ast.dump(tree)
        v = _AttrRefTransformer(self)
        v.visit(tree)
        v = _SigNameVisitor(self.symdict)
        v.visit(tree)
        sigregs = self.sigregs = []
        varregs = self.varregs = []
        for n in v.outputs:
            reg = self.symdict[n]
            if isinstance(reg, _Signal):
                sigregs.append(reg)
            elif isinstance(reg, intbv):
                varregs.append((n, reg, int(reg)))
            else:
                assert _isListOfSigs(reg)
                for e in reg:
                    sigregs.append(e)
コード例 #12
0
ファイル: _always_seq.py プロジェクト: Thomasb81/myhdl
        # handle free variables
        if func.__code__.co_freevars:
            for n, c in zip(func.__code__.co_freevars, func.__closure__):
                try:
                    obj = _cell_deref(c)
                    symdict[n] = obj
                except NameError:
                    raise NameError(n)
        self.symdict = symdict

        # now infer outputs to be reset
        s = inspect.getsource(func)
        s = _dedent(s)
        tree = ast.parse(s)
        # print ast.dump(tree)
        v = _AttrRefTransformer(self)
        v.visit(tree)
        v = _SigNameVisitor(self.symdict)
        v.visit(tree)

        if v.results['inout']:
            raise AlwaysSeqError(_error.SigAugAssign, v.results['inout'])

        if v.results['embedded_func']:
            raise AlwaysSeqError(_error.EmbeddedFunction)

        sigregs = self.sigregs = []
        varregs = self.varregs = []
        for n in v.results['output']:
            reg = self.symdict[n]
            if isinstance(reg, _Signal):
コード例 #13
0
ファイル: _analyze.py プロジェクト: forrestv/myhdl
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)
                    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 = _AttrRefTransformer(tree)
            v.visit(tree)
            v = _FirstPassVisitor(tree)
            v.visit(tree)
            if isinstance(g, _AlwaysComb):
                objs = [tree.symdict[objname] for objname in tree.objlist]
                for obj in objs:
                    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)
                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 = _AttrRefTransformer(tree)
            v.visit(tree)
            v = _FirstPassVisitor(tree)
            v.visit(tree)
            v = _AnalyzeBlockVisitor(tree)
            v.visit(tree)
        genlist.append(tree)
    return genlist
コード例 #14
0
ファイル: _always_comb.py プロジェクト: myhdl-jb/myhdl
    def __init__(self, func):
        def senslistexpand(senslist, reg):
            #             print(repr(reg))
            if isinstance(reg, _Signal):
                senslist.append(reg)
            elif isinstance(reg, StructType):
                #                 print('senslistexpand StructType', repr(reg))
                refs = vars(reg)
                #                 print(refs)
                for k in refs:
                    #                     print(refs[k])
                    if isinstance(refs[k], _Signal):
                        senslist.append(refs[k])
                    elif isinstance(refs[k], (list, Array)):
                        if len(refs[k]) != 0:
                            senslistexpand(senslist, refs[k])
                    elif isinstance(refs[k], StructType):
                        senslistexpand(senslist, refs[k])
                    else:
                        #                         print('senslistexpand passing {}?'.format(k))
                        pass
            elif isinstance(reg, (list, Array)):
                if isinstance(reg[0], (list, Array)):
                    for r in reg:
                        senslistexpand(senslist, r)
                else:
                    if isinstance(reg[0], StructType):
                        for rr in reg:
                            senslistexpand(senslist, rr)
                    elif isinstance(reg[0], _Signal):
                        senslist.extend(reg)
#                     elif isinstance(reg, Array):
#                         senslist.extend(reg._array)
#                     elif isinstance(reg, list):
#                         senslist.extend(reg)

#         self.func = func
#         self.symdict = symdict

        senslist = []
        super(_AlwaysComb, self).__init__(func, senslist)
        #         print('_AlwaysComb', senslist)
        s = inspect.getsource(func)
        s = _dedent(s)
        tree = ast.parse(s)
        #         print(ast.dump(tree))
        #         for item in ast.dump(tree).split():
        #             print(item)
        v = _AttrRefTransformer(self)
        v.visit(tree)
        #         print(ast.dump(tree))
        #         for item in ast.dump(tree).split():
        #             print(item)
        v = _SigNameVisitor(self.symdict)
        v.visit(tree)
        #         print(ast.dump(tree))
        #         for item in ast.dump(tree).split():
        #             print(item)
        self.inputs = v.results['input']
        self.outputs = v.results['output']
        #         print(v.results)
        #         print('inputs:', self.inputs)
        #         print('outputs:', self.outputs)
        #         inouts = v.results['inout'] | self.inputs.intersection(self.outputs)
        #         if inouts:
        #             raise AlwaysCombError(_error.SignalAsInout % inouts)

        if v.results['embedded_func']:
            raise AlwaysCombError(_error.EmbeddedFunction)
#         print(self.inputs)
#         print('2', self.senslist)
        for n in self.inputs:
            s = self.symdict[n]
            #             print(n,s)
            #             print(n, s, isinstance(s, StructType), isinstance(s, (list, Array)))
            senslistexpand(senslist, s)
#             if isinstance(s, _Signal):
#                 senslist.append(s)
#             elif isinstance(s, list):
# #                 print(repr(s))
#                 # list or Array of sigs
#                 senslistexpand(senslist, s)
#             elif isinstance(s, Array):
#                 # Array of sigs
#                 if not isinstance(s.element, intbv):
#                     senslistexpand(senslist, s)
#             elif isinstance(s, StructType):
#                 senslistexpand(senslist, s)
#             elif _isListOfSigs(s):
#                 senslist.extend(s)
#             else :
# #                 print('_always_comb', n)
#                 pass
#         print('3', self.senslist)
        self.senslist = tuple(senslist)
        #         print('4', self.senslist)
        self.gen = self.genfunc()
        #         for item in self.senslist:
        #             print(item._name, repr(item))
        #         print()
        if len(self.senslist) == 0:
            raise AlwaysCombError(_error.EmptySensitivityList)