Beispiel #1
0
 def visit_Tuple(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid type: tuple')
Beispiel #2
0
 def visit_DictComp(s, node):
     raise PyMTLSyntaxError(s.blk, node,
                            'invalid operation: dict comprehension')
Beispiel #3
0
 def visit_TryFinally(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: try-finally')
Beispiel #4
0
 def visit_Exec(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: exec')
Beispiel #5
0
 def visit_Delete(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: delete')
Beispiel #6
0
 def visit_Raise(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: raise')
Beispiel #7
0
 def visit_BoolOp(s, node):
     raise PyMTLSyntaxError(
         s.blk, node,
         'Boolean operations are not translatable due to inconsistent semantics '
         'between Python and PyMTL. Please consider using bitwise &, |, and ~ instead!'
     )
Beispiel #8
0
 def visit_Str(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: str')
Beispiel #9
0
 def visit_Continue(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: continue')
Beispiel #10
0
 def visit_ExtSlice(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: extslice')
Beispiel #11
0
 def visit_Break(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: break')
Beispiel #12
0
 def visit_Pass(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: pass')
Beispiel #13
0
 def visit_Global(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: global')
Beispiel #14
0
 def visit_GeneratorExp(s, node):
     raise PyMTLSyntaxError(s.blk, node,
                            'invalid operation: generator expression')
Beispiel #15
0
    def visit_Call(s, node):
        """Return the behavioral RTLIR of method calls.

    Some data types are interpreted as function calls in the Python AST.
    Example: Bits4(2)
    These are converted to different RTLIR nodes in different contexts.
    """
        obj = s.get_call_obj(node)
        if (obj == copy.copy) or (obj == copy.deepcopy):
            if len(node.args) != 1:
                raise PyMTLSyntaxError(
                    s.blk, node,
                    f'copy method {obj} takes exactly 1 argument!')
            ret = s.visit(node.args[0])
            ret.ast = node
            return ret

        # Now that we have the live Python object, there are a few cases that
        # we need to treat separately:
        # 1. Instantiation: Bits16( 10 ) where obj is an instance of Bits
        # Bits16( 1+2 ), Bits16( s.STATE_A )?
        # 2. concat()
        # 3. zext(), sext()
        # TODO: support the following
        # 4. reduce_and(), reduce_or(), reduce_xor()
        # 5. Real function call: not supported yet

        # Deal with Bits type cast
        if isinstance(obj, type) and issubclass(obj, Bits):
            nbits = obj.nbits
            if len(node.args) != 1:
                raise PyMTLSyntaxError(
                    s.blk, node,
                    'exactly one argument should be given to Bits!')
            value = s.visit(node.args[0])
            ret = bir.SizeCast(nbits, value)
            ret.ast = node
            return ret

        # concat method
        elif obj is concat:
            if len(node.args) < 1:
                raise PyMTLSyntaxError(
                    s.blk, node,
                    'at least one argument should be given to concat!')
            values = [s.visit(c) for c in node.args]
            ret = bir.Concat(values)
            ret.ast = node
            return ret

        # zext method
        elif obj is zext:
            if len(node.args) != 2:
                raise PyMTLSyntaxError(
                    s.blk, node,
                    'exactly two arguments should be given to zext!')
            nbits = s.visit(node.args[1])
            value = s.visit(node.args[0])
            ret = bir.ZeroExt(nbits, value)
            ret.ast = node
            return ret

        # sext method
        elif obj is sext:
            if len(node.args) != 2:
                raise PyMTLSyntaxError(
                    s.blk, node,
                    'exactly two arguments should be given to sext!')
            nbits = s.visit(node.args[1])
            value = s.visit(node.args[0])
            ret = bir.SignExt(nbits, value)
            ret.ast = node
            return ret

        # reduce methods
        elif obj is reduce_and or obj is reduce_or or obj is reduce_xor:
            if obj is reduce_and:
                op = bir.BitAnd()
            elif obj is reduce_or:
                op = bir.BitOr()
            elif obj is reduce_xor:
                op = bir.BitXor()
            if len(node.args) != 1:
                raise PyMTLSyntaxError(
                    s.blk, node,
                    f'exactly two arguments should be given to reduce {op} methods!'
                )
            value = s.visit(node.args[0])
            ret = bir.Reduce(op, value)
            ret.ast = node
            return ret

        else:
            # Only Bits class instantiation is supported at L1
            raise PyMTLSyntaxError(
                s.blk, node, f'Unrecognized method call {obj.__name__}!')
Beispiel #16
0
 def visit_Yield(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: yield')
Beispiel #17
0
 def visit_Lambda(s, node):
     raise PyMTLSyntaxError(s.blk, node,
                            'invalid operation: lambda function')
Beispiel #18
0
 def visit_ClassDef(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: classdef')
Beispiel #19
0
 def visit_Dict(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid type: dict')
Beispiel #20
0
 def visit_With(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: with')
Beispiel #21
0
 def visit_Set(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid type: set')
Beispiel #22
0
 def visit_TryExcept(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: try-except')
Beispiel #23
0
 def visit_List(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid type: list')
Beispiel #24
0
 def visit_Import(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: import')
Beispiel #25
0
 def visit_AugAssign(s, node):
     raise PyMTLSyntaxError(s.blk, node,
                            'invalid operation: augmented assignment')