from argg_hdl.ast.ast_classes.ast_base import add_class def body_unfold_Break(astParser, args, keywords=None): return "exit" add_class('Break', body_unfold_Break)
lhs = astParser.Unfold_body(Node.left) if issubclass(type(lhs), argg_hdl_base): lhs = hdl.impl_reasign_type(lhs) if issubclass(type(rhs), argg_hdl_base): rhs = hdl.impl_get_value(rhs, lhs, astParser) else: rhs = rhs.impl_get_value(lhs, astParser) if astParser.ContextName[-1] == 'process': lhs.__Driver__ = 'process' elif astParser.ContextName[-1] == 'function': lhs.__Driver__ = 'function' else: lhs << rhs return v_re_assigne(lhs, rhs, context=astParser.ContextName[-1], astParser=astParser) var = astParser.get_variable(lhs.Value, Node) #print(str(lhs) + " << " + str(rhs)) return v_re_assigne(var, rhs, context=astParser.ContextName[-1], astParser=astParser) add_class("LShift", body_LShift)
from argg_hdl.ast.ast_classes.ast_base import add_class def body_expr(astParser,Node): return astParser.Unfold_body(Node.value) add_class("Expr", body_expr)
from argg_hdl.ast.ast_classes.ast_base import add_class def body_list(astParser,Node): localContext = astParser.Context ret = list() astParser.Context = ret for x in Node: l = astParser.Unfold_body(x) ret.append(l) astParser.Context =localContext return ret add_class("list", body_list)
def get_type(self): return "integer" def impl_get_value(self,ReturnToObj=None,astParser=None): if ReturnToObj._type =="std_logic": return "'" + str(self.value)+ "'" if "std_logic_vector" in ReturnToObj._type: if str(self) == '0': return " (others => '0')" return """std_logic_vector(to_unsigned({src}, {dest}'length))""".format( dest=str(ReturnToObj), src = str(self.value) ) if ReturnToObj._type =="integer": return str(self.value) if str(self) == '0': ret = v_copy(ReturnToObj) ret.__hdl_name__ = ReturnToObj._type + "_null" return ret return "convert2"+ ReturnToObj.get_type().replace(" ","") + "(" + str(self) +")" def body_unfold_Num(astParser,Node): return v_Num(Node.n) add_class("Num", body_unfold_Num)
for x in Node.iter.args: l = astParser.Unfold_body(x) args.append(l) #obj=astParser.getInstantByName(Node.iter.id) itt = "i"+str(v_for.range_counter) v_for.range_counter += 1 arg = itt + " in 0 to " + str(args[0]) +" -1" vhdl_name = str(Node.target.id) buff = astParser.try_get_variable(vhdl_name) if buff is None: buff = v_int() buff.__hdl_name__ = itt buff._varSigConst = varSig.reference_t astParser.FuncArgs.append({'ScopeType':"", 'name' : vhdl_name,'symbol': buff}) else: raise Exception("name already used") body = for_body(astParser,Node.body) astParser.FuncArgs = [ x for x in astParser.FuncArgs if x['name'] != vhdl_name ] return v_for(arg,body) add_class("For", body_unfold_for)
else: obj = val if issubclass(type(obj), v_enum): return v_enum(getattr(obj._type, Node.attr)) att = getattr(obj, Node.attr) if type(type(att)).__name__ == "EnumMeta": return v_enum(att) parend = astParser.get_parant(obj) set_v_classType(obj, parend) n = hdl.impl_get_attribute(obj, Node.attr, parend) if type(att).__name__ == "str": att = to_v_object(att) att.set_vhdl_name(n, True) att._add_used() astParser.add_child(obj, att) # att._Inout = obj._Inout astParser.FuncArgs.append({ "name": att.__hdl_name__, "symbol": att, "ScopeType": obj._Inout }) return att add_class("Attribute", body_unfold_Attribute)
def __str__(self): op = type(self.op).__name__ if op == "And": op = " and " elif op == "Or": op = " or " ret = "( " start = "" for x in self.elements: ret += start + str(x) start = op ret += ") " return ret def get_type(self): return "boolean" def body_BoolOp(astParser, Node): elements = list() for x in Node.values: e = astParser.Unfold_body(x) e = v_type_to_bool(astParser, e) elements.append(e) op = Node.op return v_boolOp(elements, op) add_class("BoolOp", body_BoolOp)
from argg_hdl.ast.ast_classes.ast_base import add_class def body_BinOP(astParser, Node): optype = type(Node.op).__name__ return astParser._Unfold_body[optype](astParser, Node) add_class("BinOp", body_BinOP)
if Node.targets[0].id in x.__hdl_name__: raise Exception( Node_line_col_2_str(astParser, Node) + " Target already exist. Use << operate to assigne new value to existing object." ) for x in astParser.FuncArgs: if Node.targets[0].id == x["name"]: raise Exception( Node_line_col_2_str(astParser, Node) + " Target already exist. Use << operate to assigne new value to existing object." ) if type(Node.targets[0]).__name__ != "Name": raise Exception(Node_line_col_2_str(astParser, Node) + " unknown type") if not astParser.get_scope_name(): raise Exception( Node_line_col_2_str(astParser, Node) + " Symbol is not defined. use end_architecture() function at the end of the archetecture " ) lhs = v_name(Node.targets[0].id) rhs = astParser.Unfold_body(Node.value) rhs = to_v_object(rhs) rhs.set_vhdl_name(lhs.Value, True) astParser.LocalVar.append(rhs) ret = v_variable_cration(lhs, rhs) return ret add_class("Assign", body_unfold_assign)
""".format(sensitivity_list=sensitivity_list, combinatorial_pull=combinatorial_pull, process_decorator=process_decorator, process_header=process_header, body=body, combinatorial_push=combinatorial_push) return ret def body_unfold_porcess_body(astParser, Node): if astParser.get_scope_name() != "process": return body_unfold_porcess(astParser, Node=Node, Body=Node) localContext = astParser.Context dummy_DefaultVarSig = getDefaultVarSig() setDefaultVarSig(varSig.variable_t) decorator_l = astParser.Unfold_body(Node.decorator_list) ret = list() astParser.Context = ret for x in Node.body: ret.append(astParser.Unfold_body(x)) astParser.Context = localContext setDefaultVarSig(dummy_DefaultVarSig) return v_process_body_Def(ret, Node.name, astParser.LocalVar, decorator_l) add_class("rising_edge", body_unfold_porcess_body)
self.sourceOBJ = sourceOBJ def __str__(self): if self.upper is None: upper = str(hdl.length(self.sourceOBJ)) + " -1 " else: upper = str(self.upper) if upper.lstrip('-').isnumeric(): upper = int(upper) if upper < 0 : upper = str(hdl.length(self.sourceOBJ)) + " - " + str( abs(upper - 1)) else: upper = str(int(upper) - 1 ) else: upper += " - 1 " if self.reversed: return str(self.lower) + " to " + upper return upper + " downto " + str(self.lower) def body_unfold_slice(astParser,Node,keywords=None): lower = astParser.Unfold_body( Node.lower) if Node.lower else None upper = astParser.Unfold_body( Node.upper) if Node.upper else None step = astParser.Unfold_body( Node.step) if Node.step else None ret = v_slice(lower, upper, step) return ret add_class( "Slice",body_unfold_slice)
else: for x in self.oreEsle: x.isElse = True oreelse += str(x) ret += oreelse gIndent.deinc() if self.isElse: ret += "" else: ret += "\n" + str(gIndent) + "end if" return ret def body_if(astParser, Node): ifEsleIfElse = "if" test = v_type_to_bool(astParser, astParser.Unfold_body(Node.test)) body = astParser.Unfold_body(Node.body) localContext = astParser.Context oreEsle = list() astParser.Context = oreEsle for x in Node.orelse: oreEsle.append(astParser.Unfold_body(x)) astParser.Context = localContext return v_if(ifEsleIfElse, test, body, oreEsle) add_class("If", body_if)
class index_handler(v_ast_base): def __init__(self, index) -> None: self.index = index self.Source = None def set_source(self, source): self.Source = source def __str__(self): sl = self.index if issubclass(type(sl), argg_hdl_base0): sl = hdl.impl_get_value(sl, ReturnToObj=v_int(), astParser=None) return str(sl) def body_subscript(astParser, Node): value = astParser.Unfold_body(Node.value) sl = astParser.Unfold_body(Node.slice) sl.set_source(value) return hdl.impl_slice(value, sl, astParser) def body_index(astParser, Node): sl = astParser.Unfold_body(Node.value) return index_handler(sl) add_class("Subscript", body_subscript) add_class("Index", body_index)
ret += x_str + ";\n " ret += push return ret def body_unfold_porcess_body_timed(astParser, Node): if astParser.get_scope_name() != "process": return body_unfold_porcess(astParser, Node=Node, Body=Node) localContext = astParser.Context dummy_DefaultVarSig = getDefaultVarSig() setDefaultVarSig(varSig.variable_t) decorator_l = astParser.Unfold_body(Node.decorator_list) ret = list() astParser.Context = ret for x in Node.body: ret.append(astParser.Unfold_body(x)) astParser.Context = localContext setDefaultVarSig(dummy_DefaultVarSig) return v_process_body_timed_Def(ret, Node.name, astParser.LocalVar, decorator_l) add_class("timed", body_unfold_porcess_body_timed)
def __str__(self): if issubclass(type(self.lhs), argg_hdl_base): return hdl.impl_reasign_rshift_(self.lhs, self.rhs, astParser=self.astParser, context_str=self.context) return str(self.lhs) + " := " + str(self.rhs) 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) add_class("RShift", body_RShift)
from argg_hdl.ast.ast_classes.ast_base import v_ast_base, add_class from argg_hdl.argg_hdl_base import argg_hdl_base from argg_hdl.argg_hdl_lib_enums import varSig class v_USubOP(v_ast_base): def __init__(self, obj): self.obj = obj self._type = obj._type def __str__(self): return " -(" + str(self.obj) + ")" def body_unfol_USub(astParser, Node): arg = astParser.Unfold_body(Node.operand) if issubclass(type(arg), argg_hdl_base) and arg._varSigConst == varSig.unnamed_const: arg.nextValue = -arg.nextValue arg.set_vhdl_name(str(arg.nextValue), True) return arg return v_USubOP(arg) add_class('USub', body_unfol_USub)
from argg_hdl.ast.ast_classes.ast_base import v_ast_base, add_class import argg_hdl.argg_hdl_hdl_converter as hdl from argg_hdl.argg_hdl_base import argg_hdl_base class v_sub(v_ast_base): def __init__(self, lhs, rhs): self.lhs = lhs self.rhs = rhs self._type = lhs._type def __str__(self): if issubclass(type(self.lhs), argg_hdl_base): return hdl.impl_sub(self.lhs, self.rhs) return str(self.lhs) + " - " + str(self.rhs) def body_sub(astParser, Node): rhs = astParser.Unfold_body(Node.right) lhs = astParser.Unfold_body(Node.left) if issubclass(type(lhs), argg_hdl_base): return v_sub(lhs, rhs) var = astParser.get_variable(lhs.Value, Node) return v_sub(var, rhs) add_class("Sub", body_sub)
if issubclass(type(self.lhs),v_symbol): return hdl.impl_compare( self.lhs, self.ops , self.rhs, astParser ) if issubclass(type(self.lhs),v_enum): return hdl.impl_compare( self.lhs, self.ops , self.rhs, astParser ) raise Exception("unknown type",type(self.lhs).__name__ ) def body_unfold_Compare(astParser,Node): if len (Node.ops)>1: raise Exception("unexpected number of operators") return v_compare( astParser.Unfold_body(Node.left), type(Node.ops[0]).__name__, astParser.Unfold_body(Node.comparators[0]), astParser ) add_class("Compare", body_unfold_Compare)
class v_return(v_ast_base): def __init__(self, Value): self.value = Value def __str__(self): if self.value is None: return "return" return "return " + str(self.value) def get_type(self): if self.value is None: return "None" ty = get_symbol(self.value) if ty is not None and type( ty).__name__ != "str" and ty.primitive_type != "base": return ty.primitive_type ty = get_type(self.value) return ty def body_unfold_return(astParser, Node): if Node.value is None: #procedure return v_return(None) return v_return(astParser.Unfold_body(Node.value)) add_class("Return", body_unfold_return)
class v_UnaryOP(v_ast_base): def __init__(self, obj, op): self.obj = obj self.op = op self._type = "boolean" def __str__(self): op = type(self.op).__name__ if op == "Not": op = " not " return op + " ( " + str(self.obj) + " ) " def get_symbol(self): return self.obj def get_type(self): return "boolean" def body_unfol_Not(astParser, Node): arg = astParser.Unfold_body(Node.operand) arg = v_type_to_bool(astParser, arg) #print_cnvt(arg) return v_UnaryOP(arg, Node.op) add_class('Not', body_unfol_Not)
from argg_hdl.ast.ast_classes.ast_base import add_class def body_unfold_Continue(astParser, args, keywords=None): return "next" add_class('Continue', body_unfold_Continue)
from argg_hdl.ast.ast_classes.ast_base import v_ast_base, add_class import argg_hdl.argg_hdl_hdl_converter as hdl class v_yield(v_ast_base): def __init__(self, Arg): self.arg = Arg def __str__(self): return "wait for " + str(self.arg.symbol) def body_unfold_yield(astParser, Node): arg = astParser.Unfold_body(Node.value) return v_yield(arg) add_class("Yield", body_unfold_yield)
from argg_hdl.ast.ast_classes.ast_base import add_class import argg_hdl.argg_hdl_hdl_converter as hdl def body_unfold_BitAnd(astParser, Node, keywords=None): rhs = astParser.Unfold_body(Node.right) lhs = astParser.Unfold_body(Node.left) ret = hdl.impl_bit_and(lhs, rhs, astParser) return ret add_class("BitAnd", body_unfold_BitAnd)
from argg_hdl.ast.ast_classes.ast_base import v_ast_base, add_class def body_bitOr(astParser,Node): rhs = astParser.Unfold_body(Node.right) lhs = astParser.Unfold_body(Node.left) ret = lhs | rhs ret.astParser = astParser return ret add_class("BitOr", body_bitOr)
ret += ";" ret += "\n " ret += "end process" return ret def body_unfold_porcess(astParser, Node, Body=None): localContext = astParser.Context astParser.push_scope("process") dummy_DefaultVarSig = getDefaultVarSig() setDefaultVarSig(varSig.variable_t) ret = list() astParser.Context = ret if Body is None: for x in Node.body: ret.append(astParser.Unfold_body(x)) else: ret.append(astParser.Unfold_body(Body)) astParser.Context = localContext setDefaultVarSig(dummy_DefaultVarSig) astParser.pop_scope() return v_process_Def(ret, Node.name) add_class("process", body_unfold_porcess)
from argg_hdl.ast.ast_classes.ast_base import v_ast_base, add_class from argg_hdl.argg_hdl_v_symbol import v_int class v_named_C(v_ast_base): def __init__(self,Value): self.Value = Value self.__hdl_name__ =str(Value) def get_symbol(self): ret = v_int(self.Value) ret.set_vhdl_name(str(self.Value), True) return ret def __str__(self): return str(self.Value) def body_Named_constant(astParser,Node): return v_named_C(Node.value) add_class("NameConstant",body_Named_constant)
if isDecoratorName(Node.decorator_list, "rising_edge"): return astParser._Unfold_body["rising_edge"](astParser, Node) if isDecoratorName(Node.decorator_list, "timed"): return astParser._Unfold_body["timed"](astParser, Node) if isDecoratorName(Node.decorator_list, "combinational"): return astParser._Unfold_body["combinational"](astParser, Node) if isDecoratorName(Node.decorator_list, "architecture"): return astParser._Unfold_body["architecture"](astParser, Node) if isDecoratorName(Node.decorator_list, "hdl_export"): decorator_l = [] else: decorator_l = astParser.Unfold_body(Node.decorator_list) localContext = astParser.Context ret = list() astParser.Context = ret for x in Node.body: ret.append(astParser.Unfold_body(x)) astParser.Context = localContext return v_funDef(ret, decorator_l) add_class("FunctionDef", body_unfold_functionDef)
from argg_hdl.ast.ast_classes.ast_base import add_class def body_UnaryOP(astParser, Node): ftype = type(Node.op).__name__ return astParser._Unfold_body[ftype](astParser, Node) add_class("UnaryOp", body_UnaryOP)
from argg_hdl.ast.ast_classes.ast_base import add_class, v_ast_base class v_Str(v_ast_base): def __init__(self, Value): self.value = Value def __str__(self): return str(self.value) def get_type(self): return "str" def body_unfold_str(astParser, Node): return v_Str(Node.s) add_class("Str", body_unfold_str)