def visit_FunctionDef(self, node): self.name = node.name self.argnames = _get_argnames(node) if isboundmethod(self.func): if not self.argnames[0] == 'self': self.raiseError(node, _error.NotSupported, "first method argument name other than 'self'") # skip self self.argnames = self.argnames[1:] i = -1 for i, arg in enumerate(self.args): n = self.argnames[i] self.fullargdict[n] = arg if isinstance(arg, _Signal): self.argdict[n] = arg if _isMem(arg): self.raiseError(node, _error.ListAsPort, n) for n in self.argnames[i + 1:]: if n in self.kwargs: arg = self.kwargs[n] self.fullargdict[n] = arg if isinstance(arg, _Signal): self.argdict[n] = arg if _isMem(arg): self.raiseError(node, _error.ListAsPort, n) self.argnames = [n for n in self.argnames if n in self.argdict]
def visit_FunctionDef(self, node): self.refStack.push() argnames = _get_argnames(node) for i, arg in enumerate(self.args): n = argnames[i] self.tree.symdict[n] = self.getObj(arg) self.tree.argnames.append(n) for kw in self.keywords: n = kw.arg self.tree.symdict[n] = self.getObj(kw.value) self.tree.argnames.append(n) for n, v in self.tree.symdict.items(): if isinstance(v, (_Signal, intbv)): self.tree.sigdict[n] = v for stmt in node.body: self.visit(stmt) self.refStack.pop() if self.tree.hasYield: self.raiseError(node, _error.NotSupported, "call to a generator function") if self.tree.kind == _kind.TASK: if self.tree.returnObj is not None: self.raiseError(node, _error.NotSupported, "function with side effects and return value") else: if self.tree.returnObj is None: self.raiseError(node, _error.NotSupported, "pure function without return value")
def visit_FunctionDef(self, node): self.name = node.name self.argnames = _get_argnames(node) if isboundmethod(self.func): if not self.argnames[0] == 'self': self.raiseError( node, _error.NotSupported, "first method argument name other than 'self'") # skip self self.argnames = self.argnames[1:] i = -1 for i, arg in enumerate(self.args): n = self.argnames[i] self.fullargdict[n] = arg if isinstance(arg, _Signal): self.argdict[n] = arg if _isMem(arg): self.raiseError(node, _error.ListAsPort, n) for n in self.argnames[i + 1:]: if n in self.kwargs: arg = self.kwargs[n] self.fullargdict[n] = arg if isinstance(arg, _Signal): self.argdict[n] = arg if _isMem(arg): self.raiseError(node, _error.ListAsPort, n) self.argnames = [n for n in self.argnames if n in self.argdict]
def visit_FunctionDef(self, node): if node.args.vararg or node.args.kwarg: self.raiseError(node, _error.NotSupported, "extra positional or named arguments") if not self.toplevel: self.raiseError(node, _error.NotSupported, "embedded function definition") self.toplevel = False node.argnames = _get_argnames(node) # don't visit decorator lists - they can support more than other calls # put official docstrings aside for separate processing node.doc = None if node.body and isinstance(node.body[0], ast.Expr) and \ isinstance(node.body[0].value, ast.Str): node.doc = node.body[0].value.s node.body = node.body[1:] self.visitList(node.body)
def visit_Call(self, node): self.visit(node.func) f = self.getObj(node.func) node.obj = None if f is print: self.visit_Print(node) return self.access = _access.UNKNOWN for arg in node.args: self.visit(arg) for kw in node.keywords: self.visit(kw) self.access = _access.INPUT argsAreInputs = True if type(f) is type and issubclass(f, intbv): node.obj = self.getVal(node) elif f is concat: node.obj = self.getVal(node) elif f is len: self.access = _access.UNKNOWN node.obj = int(0) # XXX elif f is bool: node.obj = bool() elif f in _flatten(integer_types): node.obj = int(-1) # elif f in (posedge , negedge): ## node.obj = _EdgeDetector() elif f is ord: node.obj = int(-1) if not (isinstance(node.args[0], ast.Str) and (len(node.args[0].s) == 1)): self.raiseError(node, _error.NotSupported, "ord: expect string argument with length 1") elif f is delay: node.obj = delay(0) # suprize: identity comparison on unbound methods doesn't work in python 2.5?? elif f == intbv.signed: obj = node.func.value.obj if len(obj): M = 2 ** (len(obj) - 1) node.obj = intbv(-1, min=-M, max=M) else: node.obj = intbv(-1) elif f in myhdlObjects: pass elif f in builtinObjects: pass elif type(f) is FunctionType: argsAreInputs = False tree = _makeAST(f) fname = f.__name__ tree.name = _Label(fname) tree.symdict = f.__globals__.copy() tree.nonlocaldict = {} if fname in self.tree.callstack: self.raiseError(node, _error.NotSupported, "Recursive call") tree.callstack = self.tree.callstack[:] tree.callstack.append(fname) # handle free variables if f.__code__.co_freevars: for n, c in zip(f.__code__.co_freevars, f.__closure__): obj = c.cell_contents if not isinstance(obj, (integer_types, _Signal)): self.raiseError(node, _error.FreeVarTypeError, n) tree.symdict[n] = obj v = _FirstPassVisitor(tree) v.visit(tree) v = _AnalyzeFuncVisitor(tree, node.args, node.keywords) v.visit(tree) node.obj = tree.returnObj node.tree = tree tree.argnames = argnames = _get_argnames(tree.body[0]) # extend argument list with keyword arguments on the correct position node.args.extend([None] * len(node.keywords)) for kw in node.keywords: node.args[argnames.index(kw.arg)] = kw.value for n, arg in zip(argnames, node.args): if n in tree.outputs: self.access = _access.OUTPUT self.visit(arg) self.access = _access.INPUT if n in tree.inputs: self.visit(arg) elif type(f) is MethodType: self.raiseError(node, _error.NotSupported, "method call: '%s'" % f.__name__) else: debug_info = [e for e in ast.iter_fields(node.func)] raise AssertionError("Unexpected callable %s" % str(debug_info)) if argsAreInputs: for arg in node.args: self.visit(arg)
def visit_Call(self, node): self.visit(node.func) f = self.getObj(node.func) node.obj = None if f is print: self.visit_Print(node) return self.access = _access.UNKNOWN for arg in node.args: self.visit(arg) for kw in node.keywords: self.visit(kw) self.access = _access.INPUT argsAreInputs = True if type(f) is type and issubclass(f, intbv): node.obj = self.getVal(node) elif f is concat: node.obj = self.getVal(node) elif f is len: self.access = _access.UNKNOWN node.obj = int(0) # XXX elif f is bool: node.obj = bool() elif f in _flatten(integer_types): node.obj = int(-1) # elif f in (posedge , negedge): # # node.obj = _EdgeDetector() elif f is ord: node.obj = int(-1) if not (isinstance(node.args[0], ast.Str) and (len(node.args[0].s) == 1)): self.raiseError(node, _error.NotSupported, "ord: expect string argument with length 1") elif f is delay: node.obj = delay(0) # suprize: identity comparison on unbound methods doesn't work in python 2.5?? elif f == intbv.signed: obj = node.func.value.obj if len(obj): M = 2**(len(obj) - 1) node.obj = intbv(-1, min=-M, max=M) else: node.obj = intbv(-1) elif f in myhdlObjects: pass elif f in builtinObjects: pass elif type(f) is FunctionType: argsAreInputs = False tree = _makeAST(f) fname = f.__name__ tree.name = _Label(fname) tree.symdict = f.__globals__.copy() tree.nonlocaldict = {} if fname in self.tree.callstack: self.raiseError(node, _error.NotSupported, "Recursive call") tree.callstack = self.tree.callstack[:] tree.callstack.append(fname) # handle free variables if f.__code__.co_freevars: for n, c in zip(f.__code__.co_freevars, f.__closure__): obj = c.cell_contents if not isinstance(obj, (integer_types, _Signal)): self.raiseError(node, _error.FreeVarTypeError, n) tree.symdict[n] = obj v = _FirstPassVisitor(tree) v.visit(tree) v = _AnalyzeFuncVisitor(tree, node.args, node.keywords) v.visit(tree) node.obj = tree.returnObj node.tree = tree tree.argnames = argnames = _get_argnames(tree.body[0]) # extend argument list with keyword arguments on the correct position node.args.extend([None] * len(node.keywords)) for kw in node.keywords: node.args[argnames.index(kw.arg)] = kw.value for n, arg in zip(argnames, node.args): if n in tree.outputs: self.access = _access.OUTPUT self.visit(arg) self.access = _access.INPUT if n in tree.inputs: self.visit(arg) elif type(f) is MethodType: self.raiseError(node, _error.NotSupported, "method call: '%s'" % f.__name__) else: debug_info = [e for e in ast.iter_fields(node.func)] raise AssertionError("Unexpected callable %s" % str(debug_info)) if argsAreInputs: for arg in node.args: self.visit(arg)