def visit_HdlOp(self, op): """ :type o: HdlOp """ w = self.out.write o = op.fn if o == HdlOpType.RISING: self._visit_operand(op.ops[0], 0, op, False, False) w(".pos()") elif o == HdlOpType.FALLING: self._visit_operand(op.ops[0], 0, op, False, False) w(".neg()") elif o == HdlOpType.PARAMETRIZATION: self._visit_operand(op.ops[0], 0, op, False, False) w("<") for last, _o in iter_with_last(op.ops[1:]): self.visit_iHdlExpr(_o) if not last: w(", ") w(">") else: ToHdlCommon.visit_HdlOp(self, op) return True
def visit_HdlOp(self, o): """ :type o: HdlOp """ fn = o.ops[0] if fn == HdlValueId("assert"): self.visit_assert(o.ops[1:]) return elif fn == HdlValueId("report"): self.visit_report(o.ops[1:]) return w = self.out.write op = o.fn if op == HdlOpType.RISING: w("RISING_EDGE(") self.visit_iHdlExpr(o.ops[0]) w(")") elif op == HdlOpType.FALLING: w("FALLING_EDGE(") self.visit_iHdlExpr(o.ops[0]) w(")") elif op == HdlOpType.INDEX or op == HdlOpType.CALL: self._visit_operand(o.ops[0], 0, o, False, False) w("(") for isLast, (o_i, _o) in iter_with_last(enumerate(o.ops[1:])): self._visit_operand(_o, o_i + 1, o, False, True) if not isLast: w(", ") w(")") elif op == HdlOpType.TERNARY: has_3_ops = len(o.ops) == 3 if has_3_ops: cond, o0, o1 = o.ops else: cond, o0 = o.ops self._visit_operand(o0, 1, o, True, False) w(" WHEN ") self._visit_operand(cond, 0, o, True, False) if has_3_ops: if isinstance(o1, HdlOp) and o1.fn == HdlOpType.TERNARY: w(" ELSE\n") self.visit_iHdlExpr(o1) # must not have parenthesis else: w(" ELSE ") self._visit_operand(o1, 2, o, False, False) elif op == HdlOpType.APOSTROPHE: self._visit_operand(o.ops[0], 0, o, True, False) w("'") args = o.ops[1] if isinstance(args, list): self.visit_iHdlExpr(args) elif isinstance(args, HdlValueId): # normal attribute self.visit_iHdlExpr(args) else: w("(") self._visit_operand(args, 0, o, False, True) w(")") elif op == HdlOpType.ABS: w("ABS(") self.visit_iHdlExpr(o.ops[0]) w(")") elif op == HdlOpType.DEFINE_RESOLVER: assert self.in_typedef self.visit_iHdlExpr(o.ops[0]) w(" ") self.visit_iHdlExpr(o.ops[1]) else: return ToHdlCommon.visit_HdlOp(self, o)