def makeDFTree(node): if isinstance(node, fxd._FixedBase): raise TypeError('FixedPoint is not supported.') if isinstance(node, vtypes._Variable): name = node.name v = DFTerminal(name) v.original = node return v if isinstance(node, bool): v = 1 if node else 0 return DFIntConst(str(v)) if isinstance(node, int): return DFIntConst(str(node)) if isinstance(node, float): return DFFloatConst(str(node)) if isinstance(node, str): return DFStringConst(node) if isinstance(node, vtypes.Int): return DFIntConst(str(node.value)) if isinstance(node, vtypes.Float): return DFFloatConst(str(node.value)) if isinstance(node, vtypes.Str): return DFStringConst(node.value) if isinstance(node, vtypes.Cond): true_df = makeDFTree(node.true_value) false_df = makeDFTree(node.false_value) cond_df = makeDFTree(node.cond) if isinstance(cond_df, DFBranch): return reorder.insertCond(cond_df, true_df, false_df) return DFBranch(cond_df, true_df, false_df) if isinstance(node, vtypes._UnaryOperator): right_df = makeDFTree(node.right) if isinstance(right_df, DFBranch): return reorder.insertUnaryOp(right_df, node.__class__.__name__) return DFOperator((right_df, ), node.__class__.__name__) if isinstance(node, vtypes._BinaryOperator): left_df = makeDFTree(node.left) right_df = makeDFTree(node.right) if isinstance(left_df, DFBranch) or isinstance(right_df, DFBranch): return reorder.insertOp(left_df, right_df, node.__class__.__name__) return DFOperator(( left_df, right_df, ), node.__class__.__name__) if isinstance(node, vtypes.SystemTask): return DFSyscall(node.cmd, tuple([makeDFTree(n) for n in node.args])) raise TypeError("unsupported type: %s %s" % (str(type(node)), str(node)))
def makeDFTree(node): if isinstance(node, fxd._FixedBase): raise TypeError('FixedPoint is not supported.') if isinstance(node, vtypes._Variable): name = node.name v = DFTerminal(name) v.original = node return v if isinstance(node, bool): v = 1 if node else 0 return DFIntConst(str(v)) if isinstance(node, int): return DFIntConst(str(node)) if isinstance(node, float): return DFFloatConst(str(node)) if isinstance(node, str): return DFStringConst(node) if isinstance(node, vtypes.Int): return DFIntConst(str(node.value)) if isinstance(node, vtypes.Float): return DFFloatConst(str(node.value)) if isinstance(node, vtypes.Str): return DFStringConst(node.value) if isinstance(node, vtypes.Cond): true_df = makeDFTree(node.true_value) false_df = makeDFTree(node.false_value) cond_df = makeDFTree(node.cond) if isinstance(cond_df, DFBranch): return reorder.insertCond(cond_df, true_df, false_df) return DFBranch(cond_df, true_df, false_df) if isinstance(node, vtypes._UnaryOperator): right_df = makeDFTree(node.right) if isinstance(right_df, DFBranch): return reorder.insertUnaryOp(right_df, node.__class__.__name__) return DFOperator((right_df,), node.__class__.__name__) if isinstance(node, vtypes._BinaryOperator): left_df = makeDFTree(node.left) right_df = makeDFTree(node.right) if isinstance(left_df, DFBranch) or isinstance(right_df, DFBranch): return reorder.insertOp(left_df, right_df, node.__class__.__name__) return DFOperator((left_df, right_df,), node.__class__.__name__) if isinstance(node, vtypes.SystemTask): return DFSyscall(node.cmd, tuple([makeDFTree(n) for n in node.args])) raise TypeError("unsupported type: %s %s" % (str(type(node)), str(node)))
def makeDFTree(node): if isinstance(node, str): name = ScopeChain((ScopeLabel(node), )) return DFTerminal(name) if isinstance(node, Identifier): name = ScopeChain((ScopeLabel(node.name), )) return DFTerminal(name) if isinstance(node, IntConst): return DFIntConst(node.value) if isinstance(node, FloatConst): return DFFloatConst(node.value) if isinstance(node, StringConst): return DFStringConst(node.value) if isinstance(node, Cond): true_df = makeDFTree(node.true_value) false_df = makeDFTree(node.false_value) cond_df = makeDFTree(node.cond) if isinstance(cond_df, DFBranch): return reorder.insertCond(cond_df, true_df, false_df) return DFBranch(cond_df, true_df, false_df) if isinstance(node, UnaryOperator): right_df = makeDFTree(node.right) if isinstance(right_df, DFBranch): return reorder.insertUnaryOp(right_df, node.__class__.__name__) return DFOperator((right_df, ), node.__class__.__name__) if isinstance(node, Operator): left_df = makeDFTree(node.left) right_df = makeDFTree(node.right) if isinstance(left_df, DFBranch) or isinstance(right_df, DFBranch): return reorder.insertOp(left_df, right_df, node.__class__.__name__) return DFOperator(( left_df, right_df, ), node.__class__.__name__) if isinstance(node, SystemCall): #if node.syscall == 'unsigned': # return makeDFTree(node.args[0]) #if node.syscall == 'signed': # return makeDFTree(node.args[0]) #return DFIntConst('0') return DFSyscall(node.syscall, tuple([makeDFTree(n) for n in node.args])) raise TypeError("unsupported AST node type: %s %s" % (str(type(node)), str(node)))
def makeDFTree(node): if isinstance(node, str): name = ScopeChain((ScopeLabel(node),)) return DFTerminal(name) if isinstance(node, Identifier): name = ScopeChain((ScopeLabel(node.name),)) return DFTerminal(name) if isinstance(node, IntConst): return DFIntConst(node.value) if isinstance(node, FloatConst): return DFFloatConst(node.value) if isinstance(node, StringConst): return DFStringConst(node.value) if isinstance(node, Cond): true_df = makeDFTree(node.true_value) false_df = makeDFTree(node.false_value) cond_df = makeDFTree(node.cond) if isinstance(cond_df, DFBranch): return reorder.insertCond(cond_df, true_df, false_df) return DFBranch(cond_df, true_df, false_df) if isinstance(node, UnaryOperator): right_df = makeDFTree(node.right) if isinstance(right_df, DFBranch): return reorder.insertUnaryOp(right_df, node.__class__.__name__) return DFOperator((right_df,), node.__class__.__name__) if isinstance(node, Operator): left_df = makeDFTree(node.left) right_df = makeDFTree(node.right) if isinstance(left_df, DFBranch) or isinstance(right_df, DFBranch): return reorder.insertOp(left_df, right_df, node.__class__.__name__) return DFOperator((left_df, right_df,), node.__class__.__name__) if isinstance(node, SystemCall): #if node.syscall == 'unsigned': # return makeDFTree(node.args[0]) #if node.syscall == 'signed': # return makeDFTree(node.args[0]) #return DFIntConst('0') return DFSyscall(node.syscall, tuple([ makeDFTree(n) for n in node.args ])) raise TypeError("unsupported AST node type: %s %s" % (str(type(node)), str(node)))
def makeDFTree(self, node, scope): if isinstance(node, str): return self.searchConstantValue(scope, node) if isinstance(node, Identifier): if node.scope is not None: const = self.searchScopeConstantValue(node.scope, node.name) return const return self.searchConstantValue(scope, node.name) if isinstance(node, IntConst): return DFIntConst(node.value) if isinstance(node, FloatConst): return DFFloatConst(node.value) if isinstance(node, StringConst): return DFStringConst(node.value) if isinstance(node, Cond): true_df = self.makeDFTree(node.true_value, scope) false_df = self.makeDFTree(node.false_value, scope) cond_df = self.makeDFTree(node.cond, scope) if isinstance(cond_df, DFBranch): return reorder.insertCond(cond_df, true_df, false_df) return DFBranch(cond_df, true_df, false_df) if isinstance(node, UnaryOperator): right_df = self.makeDFTree(node.right, scope) if isinstance(right_df, DFBranch): return reorder.insertUnaryOp(right_df, node.__class__.__name__) return DFOperator((right_df, ), node.__class__.__name__) if isinstance(node, Operator): left_df = self.makeDFTree(node.left, scope) right_df = self.makeDFTree(node.right, scope) if isinstance(left_df, DFBranch) or isinstance(right_df, DFBranch): return reorder.insertOp(left_df, right_df, node.__class__.__name__) return DFOperator(( left_df, right_df, ), node.__class__.__name__) if isinstance(node, Partselect): var_df = self.makeDFTree(node.var, scope) msb_df = self.makeDFTree(node.msb, scope) lsb_df = self.makeDFTree(node.lsb, scope) if isinstance(var_df, DFBranch): return reorder.insertPartselect(var_df, msb_df, lsb_df) return DFPartselect(var_df, msb_df, lsb_df) if isinstance(node, Pointer): var_df = self.makeDFTree(node.var, scope) ptr_df = self.makeDFTree(node.ptr, scope) if (isinstance(var_df, DFTerminal) and (signaltype.isRegArray(self.getTermtype(var_df.name)) or signaltype.isWireArray(self.getTermtype(var_df.name)))): return DFPointer(var_df, ptr_df) return DFPartselect(var_df, ptr_df, copy.deepcopy(ptr_df)) if isinstance(node, Concat): nextnodes = [] for n in node.list: nextnodes.append(self.makeDFTree(n, scope)) for n in nextnodes: if isinstance(n, DFBranch): return reorder.insertConcat(tuple(nextnodes)) return DFConcat(tuple(nextnodes)) if isinstance(node, Repeat): nextnodes = [] times = self.optimize(self.getTree(node.times, scope)).value value = self.makeDFTree(node.value, scope) for i in range(int(times)): nextnodes.append(copy.deepcopy(value)) return DFConcat(tuple(nextnodes)) if isinstance(node, SystemCall): if node.syscall == 'unsigned': return self.makeDFTree(node.args[0]) if node.syscall == 'signed': return self.makeDFTree(node.args[0]) return DFIntConst('0') raise verror.FormatError("unsupported AST node type: %s %s" % (str(type(node)), str(node)))
def makeDFTree(self, node, scope): if isinstance(node, str): return self.searchConstantValue(scope, node) if isinstance(node, Identifier): if node.scope is not None: const = self.searchScopeConstantValue(node.scope, node.name) return const return self.searchConstantValue(scope, node.name) if isinstance(node, IntConst): return DFIntConst(node.value) if isinstance(node, FloatConst): return DFFloatConst(node.value) if isinstance(node, StringConst): return DFStringConst(node.value) if isinstance(node, Cond): true_df = self.makeDFTree(node.true_value, scope) false_df = self.makeDFTree(node.false_value, scope) cond_df = self.makeDFTree(node.cond, scope) if isinstance(cond_df, DFBranch): return reorder.insertCond(cond_df, true_df, false_df) return DFBranch(cond_df, true_df, false_df) if isinstance(node, UnaryOperator): right_df = self.makeDFTree(node.right, scope) if isinstance(right_df, DFBranch): return reorder.insertUnaryOp(right_df, node.__class__.__name__) return DFOperator((right_df,), node.__class__.__name__) if isinstance(node, Operator): left_df = self.makeDFTree(node.left, scope) right_df = self.makeDFTree(node.right, scope) if isinstance(left_df, DFBranch) or isinstance(right_df, DFBranch): return reorder.insertOp(left_df, right_df, node.__class__.__name__) return DFOperator((left_df, right_df,), node.__class__.__name__) if isinstance(node, Partselect): var_df = self.makeDFTree(node.var, scope) msb_df = self.makeDFTree(node.msb, scope) lsb_df = self.makeDFTree(node.lsb, scope) if isinstance(var_df, DFBranch): return reorder.insertPartselect(var_df, msb_df, lsb_df) return DFPartselect(var_df, msb_df, lsb_df) if isinstance(node, Pointer): var_df = self.makeDFTree(node.var, scope) ptr_df = self.makeDFTree(node.ptr, scope) if (isinstance(var_df, DFTerminal) and (signaltype.isRegArray(self.getTermtype(var_df.name)) or signaltype.isWireArray(self.getTermtype(var_df.name)))): return DFPointer(var_df, ptr_df) return DFPartselect(var_df, ptr_df, copy.deepcopy(ptr_df)) if isinstance(node, Concat): nextnodes = [] for n in node.list: nextnodes.append(self.makeDFTree(n, scope)) for n in nextnodes: if isinstance(n, DFBranch): return reorder.insertConcat(tuple(nextnodes)) return DFConcat(tuple(nextnodes)) if isinstance(node, Repeat): nextnodes = [] times = self.optimize(self.getTree(node.times, scope)).value value = self.makeDFTree(node.value, scope) for i in range(int(times)): nextnodes.append(copy.deepcopy(value)) return DFConcat(tuple(nextnodes)) if isinstance(node, SystemCall): if node.syscall == 'unsigned': return self.makeDFTree(node.args[0]) if node.syscall == 'signed': return self.makeDFTree(node.args[0]) return DFIntConst('0') raise verror.FormatError("unsupported AST node type: %s %s" % (str(type(node)), str(node)))