Ejemplo n.º 1
0
 def visit_iHdlExpr(self, expr):
     w = self.out.write
     if expr is HdlAll:
         w("ALL")
     elif expr is HdlOthers:
         w("OTHERS")
     elif self.in_typedef and expr is None:
         w("<>")
     elif is_str(expr):
         self.visit_str(expr)
     elif isinstance(expr, list):
         with_nl = len(expr) > 3
         if with_nl:
             w("(\n")
         else:
             w("(")
         with Indent(self.out):
             for is_last, elem in iter_with_last(expr):
                 self.visit_iHdlExpr(elem)
                 if not is_last:
                     if with_nl:
                         w(",\n")
                     else:
                         w(", ")
         w(")")
     else:
         ToHdlCommon.visit_iHdlExpr(self, expr)
Ejemplo n.º 2
0
    def _visit_operand(self, operand, i,
        parent,
        expr_requires_parenthesis,
        cancel_parenthesis):
        if parent.fn in self.EQ_NEQ_OPS and isinstance(operand, HdlOp) and operand.fn in self.EQ_NEQ_OPS:
            # handle the case (a = b) = (c = d) where to boolean conversion is applied during a = b evaluation
            expr_requires_parenthesis = True

        return ToHdlCommon._visit_operand(self, operand, i, parent, expr_requires_parenthesis, cancel_parenthesis)
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
 def __init__(self, out_stream):
     ToHdlCommon.__init__(self, out_stream)
     self.module_path_prefix = None
     self.add_imports = True
     self._is_port = False
     self._is_param = False