def visit_Tuple(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid type: tuple')
def visit_DictComp(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid operation: dict comprehension')
def visit_TryFinally(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid operation: try-finally')
def visit_Exec(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid operation: exec')
def visit_Delete(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid operation: delete')
def visit_Raise(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid operation: raise')
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!' )
def visit_Str(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid operation: str')
def visit_Continue(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid operation: continue')
def visit_ExtSlice(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid operation: extslice')
def visit_Break(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid operation: break')
def visit_Pass(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid operation: pass')
def visit_Global(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid operation: global')
def visit_GeneratorExp(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid operation: generator expression')
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__}!')
def visit_Yield(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid operation: yield')
def visit_Lambda(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid operation: lambda function')
def visit_ClassDef(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid operation: classdef')
def visit_Dict(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid type: dict')
def visit_With(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid operation: with')
def visit_Set(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid type: set')
def visit_TryExcept(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid operation: try-except')
def visit_List(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid type: list')
def visit_Import(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid operation: import')
def visit_AugAssign(s, node): raise PyMTLSyntaxError(s.blk, node, 'invalid operation: augmented assignment')