def extractFunctionsForEntity(astParser, ClassInstance, parent): ClassName = type(ClassInstance).__name__ cl = astParser.getClassByName(ClassName) for f in cl.body: if f.name in astParser.functionNameVetoList: continue astParser.parent = parent astParser.reset_buffers() astParser.FuncArgs.append({ "name": "self", "symbol": ClassInstance, "ScopeType": InOut_t.InOut_tt }) #p=ClassInstance._process1() #self.local_function = p.__globals__ astParser.local_function = ClassInstance.__init__.__globals__ try: body = astParser.Unfold_body(f) ## get local vars except Exception as inst: err_msg = argg_hdl_error( astParser.sourceFileName, f.lineno, f.col_offset, ClassName, "Function Name: " + f.name + ", Unable to Convert AST to String, Error In extractFunctionsForEntity: body = self.Unfold_body(f)" ) raise Exception(err_msg, ClassInstance, inst) header = "" for x in astParser.LocalVar: if x._type == "undef": continue header += x.__hdl_converter__._vhdl__DefineSymbol(x, "variable") pull = "" for x in astParser.LocalVar: if x._type == "undef": continue pull += x._vhdl__Pull() push = "" for x in astParser.LocalVar: if x._type == "undef": continue push += x._vhdl__push() for x in f.body: if type(x).__name__ == "FunctionDef": b = astParser.Unfold_body(x) body = str(b) ## unfold function of intressed break body = pull + "\n" + body + "\n" + push proc = v_process(body=body, SensitivityList=b.dec[0].get_sensitivity_list(), prefix=b.dec[0].get_prefix(), VariableList=header) ClassInstance.__processList__.append(proc)
def unfold_architecture(self, Arc): try: body = self.astParser.Unfold_body(Arc) ## get local vars return body except Exception as inst: err_msg = argg_hdl_error( self.astParser.sourceFileName, Arc.lineno, Arc.col_offset, type(self.ClassInstance).__name__, "FileName: " + Arc.name + ", Unable to Unfold AST, Error In extractArchetectureForClass: body = self.Unfold_body(Arc)" ) raise Exception(err_msg, ClassInstance, inst)
def Unfold_body(self,FuncDef): try: ftype = type(FuncDef).__name__ return self._Unfold_body[ftype](self,FuncDef) except Exception as inst: flat_list = flatten_list([FuncDef]) er = [] for x in flat_list: er.append(argg_hdl_error(self.sourceFileName,x.lineno, x.col_offset,type(x).__name__, "Error In unfolding")) raise Exception(er,FuncDef, inst)
def get_architechtures(self): ClassInstance = self.ClassInstance parent = self.parent setDefaultVarSig(varSig.signal_t) ClassName = type(ClassInstance).__name__ cl = self.astParser.getClassByName(ClassName) for f in cl.body: if f.name in self.astParser.functionNameVetoList: continue self.astParser.Missing_template = False ClassInstance.__hdl_converter__.reset_TemplateMissing( ClassInstance) self.astParser.reset_buffers() self.astParser.parent = parent self.astParser.FuncArgs.append({ "name": "self", "symbol": ClassInstance, "ScopeType": InOut_t.InOut_tt }) self.astParser.local_function = ClassInstance.__init__.__globals__ if sort_archetecture(): self.astParser.Archetecture_vars = sorted( ClassInstance.__local_symbols__, key=lambda element_: element_["type_name"]) else: self.astParser.Archetecture_vars = ClassInstance.__local_symbols__ try: body = self.astParser.Unfold_body(f) ## get local vars except Exception as inst: err_msg = argg_hdl_error( self.astParser.sourceFileName, f.lineno, f.col_offset, ClassName, "Function Name: " + f.name + ", Unable to Unfold AST, Error In extractArchetectureForEntity: body = self.Unfold_body(f)" ) raise Exception(err_msg, ClassInstance, inst) if self.astParser.Missing_template: ClassInstance.__hdl_converter__.FlagFor_TemplateMissing( ClassInstance) ClassInstance.__hdl_converter__.MissingTemplate = True else: proc = v_Arch(body=body, Symbols=self.astParser.LocalVar, Arch_vars=self.astParser.Archetecture_vars, ports=ClassInstance.getMember()) ClassInstance.__processList__.append(proc)
def convert_to_string(self, body): try: bodystr= str(body) return bodystr except Exception as inst: err_msg = argg_hdl_error( self.astParser.sourceFileName, self.Function_Node.lineno, self.Function_Node.col_offset, type(self.freeFunction).__name__, "Function Name: " + self.Function_Node.name +", Unable to Convert AST to String, Error In extractFunctionsForClass_impl: bodystr= str(body)" ) raise Exception(err_msg,self.package,inst)
def body_unfold(self): try: body = self.astParser.Unfold_body(self.Function_Node) return body except Exception as inst: err_msg = argg_hdl_error( self.astParser.sourceFileName, self.Function_Node.lineno, self.Function_Node.col_offset, type(self.freeFunction).__name__, "Function Name: " + self.Function_Node.name +", Unable to Unfold AST. Error In extractFunctionsForClass_impl: body = self.Unfold_body(funcDef)" ) raise Exception(err_msg,self.package,inst)
def body_RShift(astParser,Node): rhs = astParser.Unfold_body(Node.right) lhs = astParser.Unfold_body(Node.left) if issubclass( type(lhs),argg_hdl_base) and issubclass( type(rhs),argg_hdl_base): rhs.__Driver__ = astParser.ContextName[-1] return v_re_assigne_rhsift(lhs, rhs,context=astParser.ContextName[-1],astParser=astParser) err_msg = argg_hdl_error( astParser.sourceFileName, Node.lineno, Node.col_offset, type(lhs).__name__, "right shift is only supported for argg_hdl objects" ) raise Exception(err_msg,lhs)
def convert_to_string(self, body): dummy_DefaultVarSig = getDefaultVarSig() setDefaultVarSig(varSig.variable_t) try: bodystr = str(body) return bodystr except Exception as inst: err_msg = argg_hdl_error( self.astParser.sourceFileName, funcDef.lineno, funcDef.col_offset, type(ClassInstance).__name__, "Function Name: " + funcDef.name + ", Unable to Convert AST to String, Error In extractFunctionsForClass_impl: bodystr= str(body)" ) raise Exception(err_msg, ClassInstance, inst) finally: setDefaultVarSig(dummy_DefaultVarSig)
def unfold_body(self, Function_node): dummy_DefaultVarSig = getDefaultVarSig() setDefaultVarSig(varSig.variable_t) try: body = self.astParser.Unfold_body(Function_node) return body except Exception as inst: err_msg = argg_hdl_error( self.astParser.sourceFileName, Function_node.lineno, Function_node.col_offset, type(self.ClassInstance).__name__, "Function Name: " + Function_node.name + ", Unable to Unfold AST. Error In extractFunctionsForClass_impl: body = self.Unfold_body(funcDef)" ) raise Exception(err_msg, ClassInstance, inst) finally: setDefaultVarSig(dummy_DefaultVarSig)