示例#1
0
    def tocode(self):
        flatname = util.toFlatname(self.name)
        scope = self.getScope(self.name)
        code = ''
        if self.isTopmodule(scope):
            if signaltype.isInput(self.termtype): code += 'input '
            elif signaltype.isInout(self.termtype): code += 'inout '
            elif signaltype.isOutput(self.termtype): code += 'output '
        else:
            if signaltype.isInput(self.termtype): code += 'wire '
            elif signaltype.isInout(self.termtype): code += 'wire '
            elif signaltype.isOutput(self.termtype) and not signaltype.isReg(self.termtype): code += 'wire '

        if signaltype.isReg(self.termtype): code += 'reg '
        if signaltype.isRegArray(self.termtype): code += 'reg '
        if signaltype.isWire(self.termtype): code += 'wire '
        if signaltype.isWireArray(self.termtype): code += 'wire '
        if signaltype.isInteger(self.termtype): code += 'integer '
        if signaltype.isFunction(self.termtype): code += 'wire '
        if signaltype.isRename(self.termtype): code += 'wire '

        if (not signaltype.isInteger(self.termtype) and
            self.msb is not None and self.lsb is not None):
            code += '[' + self.msb.tocode(None) + ':' + self.lsb.tocode(None) + '] '
        code += flatname # signal name
        if self.lenmsb is not None and self.lenlsb is not None:
            code += ' [' + self.lenmsb.tocode() + ':' + self.lenlsb.tocode(flatname) + ']'
        code += ';\n'
        return code
示例#2
0
文件: merge.py 项目: ewelex/Pyverilog
 def getAssignType(self, termname, bind):
     termtype = self.getTermtype(termname)
     if signaltype.isWire(termtype):
         return 'assign'
     if signaltype.isWireArray(termtype):
         return 'assign'
     if signaltype.isReg(termtype):
         if bind.isClockEdge(): return 'clockedge'
         return 'combination'
     if signaltype.isRegArray(termtype):
         if bind.isClockEdge(): return 'clockedge'
         return 'combination'
     if signaltype.isInteger(termtype):
         if bind.isClockEdge(): return 'clockedge'
         return 'combination'
     if signaltype.isParameter(termtype):
         return 'parameter'
     if signaltype.isLocalparam(termtype):
         return 'localparam'
     if signaltype.isOutput(termtype):
         return 'assign'
     if signaltype.isInput(termtype):
         return 'assign'
     if signaltype.isFunction(termtype):
         return 'assign'
     if signaltype.isRename(termtype):
         return 'assign'
     if signaltype.isGenvar(termtype):
         return 'genvar'
     raise verror.DefinitionError('Unexpected Assignment Type: %s : %s' % (str(termname), str(termtype)))
示例#3
0
 def getAssignType(self, termname, bind):
     termtype = self.getTermtype(termname)
     if signaltype.isWire(termtype):
         return 'assign'
     if signaltype.isWireArray(termtype):
         return 'assign'
     if signaltype.isReg(termtype):
         if bind.isClockEdge(): return 'clockedge'
         return 'combination'
     if signaltype.isRegArray(termtype):
         if bind.isClockEdge(): return 'clockedge'
         return 'combination'
     if signaltype.isInteger(termtype):
         if bind.isClockEdge(): return 'clockedge'
         return 'combination'
     if signaltype.isParameter(termtype):
         return 'parameter'
     if signaltype.isLocalparam(termtype):
         return 'localparam'
     if signaltype.isOutput(termtype):
         return 'assign'
     if signaltype.isInput(termtype):
         return 'assign'
     if signaltype.isFunction(termtype):
         return 'assign'
     if signaltype.isRename(termtype):
         return 'assign'
     if signaltype.isGenvar(termtype):
         return 'genvar'
     raise verror.DefinitionError('Unexpected Assignment Type: %s : %s' %
                                  (str(termname), str(termtype)))
示例#4
0
def createSignalList(analyzer, designterm_list, idx, sigdiffScope_Ref0,
                     sigStr_Type):

    instances = analyzer.getInstances()

    print('Instance: ')
    for module, instname in sorted(instances, key=lambda x: str(x[1])):
        print((module, instname))

    term = analyzer.getTerms()
    #designterm_list[idx] = term
    designterm_list.append(term)

    #calculate the bitnum
    for tk, tv in term.items():
        tv.bitwidth = tv.msb.eval() - tv.lsb.eval() + 1
        #print(tv.bitwidth, tk)

    if idx > 0:
        #check the diff in port no. between signals, the bitwidth in design0 is set as ref :D
        for tk, tv in term.items():

            preterm = designterm_list[idx - 1][tk]

            #if the bitwidth is the same, you still need to check if any of the previous signal is diff
            if preterm.bitwidth == tv.bitwidth:
                if tk in sigdiffScope_Ref0:
                    sigdiffScope_Ref0[tk][idx] = sigdiffScope_Ref0[tk][idx - 1]
            else:
                if tk in sigdiffScope_Ref0:
                    sigdiffScope_Ref0[tk][idx] = tv.bitwidth - (
                        preterm.bitwidth - sigdiffScope_Ref0[tk][idx - 1])
                else:
                    for i in xrange(0, idx):
                        if i == 0:
                            sigdiffScope_Ref0[tk] = []
                            #sigdiffScope_Ref0[tk][i] = preterm.bitwidth
                            sigdiffScope_Ref0[tk].append(preterm.bitwidth)
                        else:
                            #sigdiffScope_Ref0[tk][i] = 0
                            sigdiffScope_Ref0[tk].append(0)

                    sigdiffScope_Ref0[tk].append(tv.bitwidth -
                                                 preterm.bitwidth)

                    sigStr_Type[str(tk)] = copy.deepcopy(tv.termtype)
                    if signaltype.isReg(sigStr_Type[str(tk)]):
                        sigStr_Type[str(tk)].remove('Reg')

    print('Term:')
    for tk, tv in term.items():
        print(tk, tv.tostr())

    print(' ')
示例#5
0
    def walkTree(self,
                 tree,
                 visited=set([]),
                 step=0,
                 delay=False,
                 msb=None,
                 lsb=None,
                 ptr=None):
        if tree is None:
            return DFUndefined(32)

        if isinstance(tree, DFUndefined):
            return tree

        if isinstance(tree, DFHighImpedance):
            return tree

        if isinstance(tree, DFConstant):
            return tree

        if isinstance(tree, DFEvalValue):
            return tree

        if isinstance(tree, DFTerminal):
            scope = util.getScope(tree.name)
            termname = tree.name
            if termname in visited: return tree

            termtype = self.getTermtype(termname)
            if util.isTopmodule(scope) and signaltype.isInput(termtype):
                return tree

            nptr = None
            if signaltype.isRegArray(termtype) or signaltype.isWireArray(
                    termtype):
                if ptr is None:
                    raise verror.FormatError(
                        'Array variable requires an pointer.')
                if msb is not None and lsb is not None: return tree
                nptr = ptr

            nextstep = step
            if signaltype.isReg(termtype) or signaltype.isRegArray(termtype):
                if (not self.isCombination(termname)
                        and not signaltype.isRename(termtype)
                        and nextstep == 0):
                    return tree
                if (not self.isCombination(termname)
                        and not signaltype.isRename(termtype)):
                    nextstep -= 1

            return self.walkTree(self.getTree(termname, nptr), visited | set([
                termname,
            ]), nextstep, delay)

        if isinstance(tree, DFBranch):
            condnode = self.walkTree(tree.condnode, visited, step, delay)
            truenode = self.walkTree(tree.truenode, visited, step, delay)
            falsenode = self.walkTree(tree.falsenode, visited, step, delay)
            return DFBranch(condnode, truenode, falsenode)

        if isinstance(tree, DFOperator):
            nextnodes = []
            for n in tree.nextnodes:
                nextnodes.append(self.walkTree(n, visited, step, delay))
            return DFOperator(tuple(nextnodes), tree.operator)

        if isinstance(tree, DFPartselect):
            msb = self.walkTree(tree.msb, visited, step, delay)
            lsb = self.walkTree(tree.lsb, visited, step, delay)
            var = self.walkTree(tree.var,
                                visited,
                                step,
                                delay,
                                msb=msb,
                                lsb=lsb)
            return DFPartselect(var, msb, lsb)

        if isinstance(tree, DFPointer):
            ptr = self.walkTree(tree.ptr, visited, step, delay)
            var = self.walkTree(tree.var, visited, step, delay, ptr=ptr)
            if isinstance(tree.var, DFTerminal):
                termtype = self.getTermtype(tree.var.name)
                if ((signaltype.isRegArray(termtype)
                     or signaltype.isWireArray(termtype))
                        and not (isinstance(var, DFTerminal)
                                 and var.name == tree.var.name)):
                    return var
            return DFPointer(var, ptr)

        if isinstance(tree, DFConcat):
            nextnodes = []
            for n in tree.nextnodes:
                nextnodes.append(self.walkTree(n, visited, step, delay))
            return DFConcat(tuple(nextnodes))

        raise verror.DefinitionError('Undefined Node Type: %s : %s' %
                                     (str(type(tree)), str(tree)))
示例#6
0
    def walkTree(self, tree, visited=set([]), step=0, delay=False, msb=None, lsb=None, ptr=None):
        if tree is None:
            return DFUndefined(32)

        if isinstance(tree, DFUndefined):
            return tree

        if isinstance(tree, DFHighImpedance):
            return tree

        if isinstance(tree, DFConstant):
            return tree

        if isinstance(tree, DFEvalValue):
            return tree

        if isinstance(tree, DFTerminal):
            scope = util.getScope(tree.name)
            termname = tree.name
            if termname in visited:
                return tree

            termtype = self.getTermtype(termname)
            if util.isTopmodule(scope) and signaltype.isInput(termtype):
                return tree

            nptr = None
            if signaltype.isRegArray(termtype) or signaltype.isWireArray(termtype):
                if ptr is None:
                    raise verror.FormatError("Array variable requires an pointer.")
                if msb is not None and lsb is not None:
                    return tree
                nptr = ptr

            nextstep = step
            if signaltype.isReg(termtype) or signaltype.isRegArray(termtype):
                if not self.isCombination(termname) and not signaltype.isRename(termtype) and nextstep == 0:
                    return tree
                if not self.isCombination(termname) and not signaltype.isRename(termtype):
                    nextstep -= 1

            return self.walkTree(self.getTree(termname, nptr), visited | set([termname]), nextstep, delay)

        if isinstance(tree, DFBranch):
            condnode = self.walkTree(tree.condnode, visited, step, delay)
            truenode = self.walkTree(tree.truenode, visited, step, delay)
            falsenode = self.walkTree(tree.falsenode, visited, step, delay)
            return DFBranch(condnode, truenode, falsenode)

        if isinstance(tree, DFOperator):
            nextnodes = []
            for n in tree.nextnodes:
                nextnodes.append(self.walkTree(n, visited, step, delay))
            return DFOperator(tuple(nextnodes), tree.operator)

        if isinstance(tree, DFPartselect):
            msb = self.walkTree(tree.msb, visited, step, delay)
            lsb = self.walkTree(tree.lsb, visited, step, delay)
            var = self.walkTree(tree.var, visited, step, delay, msb=msb, lsb=lsb)
            if isinstance(var, DFPartselect):
                child_lsb = self.getTerm(str(tree.var)).lsb.eval()
                return DFPartselect(
                    var.var,
                    DFIntConst(str(msb.eval() + var.lsb.eval() - child_lsb)),
                    DFIntConst(str(lsb.eval() + var.lsb.eval() - child_lsb)),
                )
            return DFPartselect(var, msb, lsb)

        if isinstance(tree, DFPointer):
            ptr = self.walkTree(tree.ptr, visited, step, delay)
            var = self.walkTree(tree.var, visited, step, delay, ptr=ptr)
            if isinstance(tree.var, DFTerminal):
                termtype = self.getTermtype(tree.var.name)
                if (signaltype.isRegArray(termtype) or signaltype.isWireArray(termtype)) and not (
                    isinstance(var, DFTerminal) and var.name == tree.var.name
                ):
                    return var
            return DFPointer(var, ptr)

        if isinstance(tree, DFConcat):
            nextnodes = []
            for n in tree.nextnodes:
                nextnodes.append(self.walkTree(n, visited, step, delay))
            return DFConcat(tuple(nextnodes))

        raise verror.DefinitionError("Undefined Node Type: %s : %s" % (str(type(tree)), str(tree)))