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)))