Ejemplo n.º 1
0
 def visit_Tuple(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid type: tuple')
Ejemplo n.º 2
0
 def visit_DictComp(s, node):
     raise PyMTLSyntaxError(s.blk, node,
                            'invalid operation: dict comprehension')
Ejemplo n.º 3
0
 def visit_TryFinally(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: try-finally')
Ejemplo n.º 4
0
 def visit_Exec(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: exec')
Ejemplo n.º 5
0
 def visit_Delete(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: delete')
Ejemplo n.º 6
0
 def visit_Raise(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: raise')
Ejemplo n.º 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!'
     )
Ejemplo n.º 8
0
 def visit_Str(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: str')
Ejemplo n.º 9
0
 def visit_Continue(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: continue')
Ejemplo n.º 10
0
 def visit_ExtSlice(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: extslice')
Ejemplo n.º 11
0
 def visit_Break(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: break')
Ejemplo n.º 12
0
 def visit_Pass(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: pass')
Ejemplo n.º 13
0
 def visit_Global(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: global')
Ejemplo n.º 14
0
 def visit_GeneratorExp(s, node):
     raise PyMTLSyntaxError(s.blk, node,
                            'invalid operation: generator expression')
Ejemplo n.º 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__}!')
Ejemplo n.º 16
0
 def visit_Yield(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: yield')
Ejemplo n.º 17
0
 def visit_Lambda(s, node):
     raise PyMTLSyntaxError(s.blk, node,
                            'invalid operation: lambda function')
Ejemplo n.º 18
0
 def visit_ClassDef(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: classdef')
Ejemplo n.º 19
0
 def visit_Dict(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid type: dict')
Ejemplo n.º 20
0
 def visit_With(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: with')
Ejemplo n.º 21
0
 def visit_Set(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid type: set')
Ejemplo n.º 22
0
 def visit_TryExcept(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: try-except')
Ejemplo n.º 23
0
 def visit_List(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid type: list')
Ejemplo n.º 24
0
 def visit_Import(s, node):
     raise PyMTLSyntaxError(s.blk, node, 'invalid operation: import')
Ejemplo n.º 25
0
 def visit_AugAssign(s, node):
     raise PyMTLSyntaxError(s.blk, node,
                            'invalid operation: augmented assignment')