def get_dotted_items(List): if len(List) == 3: if istoken(List[0]) and istoken(List[2]): return [List[0][0], List[2][0]] More = get_dotted_items(DataBase[List[2]]) return [List[0]] + More elif len(List) == 4: LL = [List[0][0]] if isbusbit(List[3]): LL.append(('subbit', List[2][0], get_busbit(List[3]))) return LL if List[3][0] == 'Width': Wid = get_wid(List[3]) LL.append(('subbus', List[2][0], Wid)) return LL elif len(List) == 6: if istoken(List[0]) and istoken(List[2]) and (isexpr(List[4])): return [ List[0][0], ('functioncall', List[2][0], get_expr(List[4])) ] logs.log_err('dotted ilia! len=%d %s' % (len(List), List)) return []
def add_module(Key): global Current, ModuleStuffs List = DataBase[Key] Module = List[1][0] Current = module_class(Module, 'module') Modules[Module] = Current print 'addmodule %s (%s)' % (Module, Modules.keys()), List[-2] if List[-1][0] == 'Ending': List = List[:-1] if len(List) == 5: Lhead = DataBase[List[2]] Lbody = DataBase[List[3]] Lparams = [] elif len(List) == 6: Lparams = DataBase[List[2]] Lhead = DataBase[List[3]] Lbody = DataBase[List[4]] else: logs.log_err('dont know to deal with %s' % List) return if (len(Lparams) > 0): add_module_params(Lparams) if (len(Lhead) > 1): add_module_header(Lhead) if (len(Lbody) > 0): ModuleStuffs = [Lbody] while (ModuleStuffs != []): add_module_stuff()
def add_function(List): if istoken(List[1]): Func = List[1][0] Wid = 0 Next = 2 elif iswidth(List[1]): Func = List[2][0] Wid = get_wid(List[1]) Next = 3 else: logs.log_err('untreated add_func %s' % (str(List))) return if List[Next][0] == '(': Header = get_header_list(List[Next + 1]) Next += 4 else: Header = [] if List[Next][0] == 'Mem_defs': Memdefs = get_mem_defs(List[Next]) else: Memdefs = [] Statement = get_statement(List[-2]) Header.extend(Memdefs) Current.add_function(Func, Wid, Header, Statement)
def get_curly_items(Item1): List = DataBase[Item1] res = [] for Item in List: if len(Item) == 2: if (Item[0] == 'CurlyItem'): LL = DataBase[Item] if len(LL) == 4: Rep = get_expr(LL[0]) What = get_expr(LL[2]) X = ['repeat', Rep, What] elif (len(LL) == 1): X = get_expr(LL[0]) elif (len(LL) == 2): X = get_expr(LL[0]) Y = curly_list(LL[1]) return ['repeat', X, Y] else: logs.log_err('curly got %s out of %s' % (Item, LL)) X = 'error' if (type(X) == types.ListType) and (len(X) == 1) and (type( X[0]) == types.ListType): res.extend(X) else: res.append(X) elif (Item[0] == 'CurlyItems'): more = get_curly_items(Item) res.extend(more) return res
def get_wid(Item): if len(Item) == 2: List = DataBase[Item] if (len(List) == 5): if List[2][0] == ':': High = get_expr(List[1]) Low = get_expr(List[3]) return High, Low if List[2][1] == 'plus_range': High = get_expr(List[1]) Low = get_expr(List[3]) return ['-', ['+', High, Low], 1], High if List[2][1] == 'minus_range': High = get_expr(List[1]) Low = get_expr(List[3]) return High, ['+', ['-', High, Low], 1] elif (len(List) == 1): if List[0][0] == 'integer': return 31, 0 if List[0][0] == 'Width': return get_wid(List[0]) elif len(List) == 4: if (List[0][0] == '#') and (List[2][0] == 'Prms_list'): LL = get_conns(List[2]) return LL logs.log_err('get_wid got %s %s' % (len(List), List)) elif len(Item) == 1: if Item[0][0] == 'integer': return 31, 0 logs.log_err('get_wid %s' % str(Item)) return 0, 0
def get_busbit(Item): if len(Item) == 2: List = DataBase[Item] if (len(List) == 3): Ind = get_expr(List[1]) return Ind logs.log_err('get_busbit %s %s' % (Item, List))
def add_module(Key): global Current, ModuleStuffs List = DataBase[Key] Module = List[1][0] Current = module_class(Module) Modules[Module] = Current logs.log_info('addmodule %s (%s)' % (Module, Modules.keys())) if len(List) == 5: Lhead = DataBase[List[2]] Lbody = DataBase[List[3]] Lparams = [] elif len(List) == 6: Lparams = DataBase[List[2]] Lhead = DataBase[List[3]] Lbody = DataBase[List[4]] elif len(List) == 3: if (List[0][1] == 'define'): Var = List[1][0] Expr = get_expr(List[2]) add_module_define(Var, Expr) else: logs.log_err('dont know to deal with %d %s' % (len(List), List)) return if (len(Lparams) > 0): add_module_params(Lparams) if (len(Lhead) > 1): add_module_header(Lhead) if (len(Lbody) > 0): ModuleStuffs = [Lbody] while (ModuleStuffs != []): add_module_stuff()
def get_definition(List): if List[1][1] == 'domino': return 'wire', 0, List[3][0] Dir = get_dir(List[0]) if len(List) > 4: if List[-3][0] == '=': List1 = List[:-3] + [(';', ';', 0, 0)] What = get_definition(List1) return What if len(List) == 5: Wid = get_wid(List[1]) Name = get_names(List[2]) Wid2 = get_wid(List[3]) return Dir, Wid, Name, Wid2 if len(List) == 4: Wid = get_wid(List[1]) Names = get_names(List[2]) return Dir, Wid, Names if len(List) == 3: Wid = 0 Names = get_names(List[1]) return Dir, Wid, Names logs.log_err('bad definition %d %s' % (len(List), List)) return 0
def add_header_item(List1): global LastWidDir if (len(List1) == 1): Name = List1[0][0] if LastWidDir: Current.add_sig(Name, LastWidDir[0], LastWidDir[1]) return if (len(List1) == 2) and (List1[0][1] == 'token') and (List1[1][1] == 'token'): # we look at interface Current.add_interface(List1[0][0], List1[1][0], 'ext') return Name = List1[-1][0] Dir = get_dir(List1[0]) if (len(List1) == 3): Wid = get_wid(List1[1]) elif (len(List1) == 2): Wid = 0 elif (len(List1) == 4): Wid0 = get_wid(List1[1]) Wid1 = get_wid(List1[3]) Wid = ('double', Wid0, Wid1) Name = List1[2][0] else: logs.log_err('get_dd_header %s' % str(List1)) if Dir in ['input', 'output', 'inout', 'output reg']: LastWidDir = (Dir, Wid) Current.add_sig(Name, Dir, Wid)
def get_pair(List): if len(List) == 3: Name = List[0][0] Expr = get_expr(List[2]) return (Name, Expr) logs.log_err('get_pair %d %s' % (len(List), List)) return []
def add_module_item(Item): if len(Item) == 2: List = DataBase[Item] if Item[0] == 'Definition': add_definition(List) elif Item[0] == 'Parameter': add_parameter(List[-2]) elif Item[0] == 'Localparam': add_localparam(List[1]) elif Item[0] == 'Assign': add_hard_assign(List) elif Item[0] == 'Instance': add_instance(List) elif Item[0] == 'Always': add_always(List) elif Item[0] == 'Initial': add_initial(List) elif Item[0] == 'Function': add_function(List) elif Item[0] == 'Task': add_task(List) elif Item[0] == 'Define': add_define_item(List) elif Item[0] == 'Generate': add_generate_item(List) else: logs.log_err('untreated(0) "%s" "%s"' % (Item, List)) elif (len(Item) == 4) and (Item[1] == 'pragma'): add_pragma(Item) elif (len(Item) == 4) and (Item[1] == 'newver'): add_newver(Item) else: logs.log_err('untreated(1) len=%d "%s"' % (len(Item), str(Item)))
def add_typedef(List): if len(List) == 9: if (List[1][0] == 'enum') and (List[2][0] == 'logic'): Name = List[-2][0] Wid = get_wid(List[3]) Singles = get_singles(DataBase[List[5]]) Current.add_enum(Name, ('width_singles', Wid, Singles)) return if len(List) == 8: Name = List[-2][0] if List[1][0] == 'struct': Key = List[4] List2 = DataBase[Key] Things = add_typedef_items(List2) Current.add_typedef(Name, Things) return if (List[1][0] == 'enum') and (List[2][0] == 'logic'): Name = List[-2][0] Singles = get_singles(DataBase[List[4]]) Current.add_enum(Name, ('singles', Singles)) return if len(List) == 7: if List[1][0] == 'enum': Name = List[-2][0] Pairs = get_pairs(DataBase[List[3]]) Current.add_enum(Name, Pairs) return logs.log_err('add_typedef %d %s' % (len(List), List))
def add_package_items(Stuffs): if len(Stuffs) == 2: add_package_item(DataBase[Stuffs[0]]) add_package_items(DataBase[Stuffs[1]]) elif len(Stuffs) == 1: add_package_item(DataBase[Stuffs[0]]) else: logs.log_err('add_package_items %d %s' % (len(Stuffs), Stuffs))
def external_dir(Dir): if 'input' in Dir: return True if 'output' in Dir: return True if 'inout' in Dir: return True if Dir in ['wire', 'reg', 'integer', 'signed']: return False logs.log_err('external dir got "%s"' % (Dir)) return False
def add_generate_item(List): if len(List) == 3: Statement = get_statements(List[1]) if (len(Statement) == 1) and (type(Statement) == types.ListType): Statement = Statement[0] Current.add_generate(Statement) else: logs.log_err('dont know to deal with generate %s' % (len(List), str(List)))
def create_always_drive_tables(Current): for Always in Current.alwayses: if len(Always) in [2, 3]: if not is_edged_timing(Always[0]): scan_statements(Current, Always[1], drive_assist1, [[]], []) else: scan_statements(Current, Always[1], drive_assist2, [[]], []) else: logs.log_err('unrecognized always %d' % (len(Always)))
def add_interface_stuffs(Stuffs): if len(Stuffs) == 0: return elif len(Stuffs) == 2: add_interface_stuff(DataBase[Stuffs[0]]) add_interface_stuffs(DataBase[Stuffs[1]]) elif len(Stuffs) == 1: add_interface_stuff(DataBase[Stuffs[0]]) else: logs.log_err('add_interface_stuffs %d %s' % (len(Stuffs), Stuffs))
def is_double_def(Wid): if type(Wid)not in [types.TupleType,types.ListType]: return False if (len(Wid)==3)and(Wid[0] in ['packed','double']): return True if len(Wid)!=2: logs.log_err('bad width definition, ilia! %s '%(str(Wid))) traceback.print_stack(None,None,logs.Flog) return False return False
def get_pairs(List): if len(List) == 3: More = get_pairs(DataBase[List[0]]) Pair = get_pair(DataBase[List[2]]) return More + [Pair] if len(List) == 1: Pair = get_pair(DataBase[List[0]]) return [Pair] logs.log_err('get_pairs %d %s' % (len(List), List)) return []
def is_double_def(Wid): if not isinstance(Wid, (tuple, list)): return False if (len(Wid) == 3) and (Wid[0] in ['packed', 'double']): return True if len(Wid) != 2: logs.log_err('bad width definition, ilia! %s ' % (str(Wid))) traceback.print_stack(None, None, logs.Flog) return False return False
def scan_statements(Current, Root, functiontorun, Params, Stack): if type(Root) is list: if Root[0] == 'list': for Item in Root[1:]: scan_statement(Current, functiontorun, Item, Params, Stack) else: scan_statement(Current, functiontorun, Root, Params, Stack) else: logs.log_err('scan_statements not list %s %s %s' % (type(Root), Root, Stack)) print(traceback.print_stack())
def needed_bits(Int): if type(Int) == types.IntType: Str = bin(Int)[2:] return len(Str) else: try: II = int(Int) return needed_bits(II) except: logs.log_err('needed bits failed in on "%s"' % Int) return 0
def add_typedef_items(Stuffs): if len(Stuffs) == 2: Item = add_typedef_item(DataBase[Stuffs[1]]) More = add_typedef_items(DataBase[Stuffs[0]]) return More + [Item] elif len(Stuffs) == 1: Item = add_typedef_item(DataBase[Stuffs[0]]) return [Item] else: logs.log_err('add_typedef_items %d %s' % (len(Stuffs), Stuffs)) return []
def gather_module_items(Stuffs): if len(Stuffs) == 3: More = gather_module_items(DataBase[Stuffs[0]]) Item = gather_module_item(DataBase[Stuffs[2]]) return More + [Item] elif len(Stuffs) == 1: Item = gather_module_item(DataBase[Stuffs[0]]) return [Item] else: logs.log_err('gather_module_items %d %s' % (len(Stuffs), Stuffs)) return []
def get_strength(Item): List = DataBase[Item] if (len(List) == 5) and (Item[0] == 'StrengthDef'): One = get_strength(List[1]) Two = get_strength(List[3]) return One, Two if (len(List) == 1) and (Item[0] == 'Strength'): return List[0][0] logs.log_err('get_strength %s %s' % (Item, List)) return []
def add_define_item(List): Tok = List[0][1] if Tok == 'backtick_include': Expr = get_expr(List[1]) if Current: Current.add_include(Expr) else: logs.log_err('dont know to deal with %s' % List) return elif Tok == 'backtick_undef': return logs.log_err('dont know to deal with %s' % List)
def add_package(Key): global Current List = DataBase[Key] if len(List) == 7: Name = List[1][0] Current = module_class(Name, 'package') Modules[Name] = Current Stuffs = DataBase[List[3]] add_package_item(DataBase[Stuffs[0]]) add_package_items(DataBase[Stuffs[1]]) else: logs.log_err('add_package %s %d %s' % (Key, len(List), List))
def scan_statement(Current, functiontorun, Item, Params, Stack): if Item[0] == 'ifelse': scan_statements(Current, Item[2], functiontorun, Params, Stack + [('if', Item[1])]) scan_statements(Current, Item[3], functiontorun, Params, Stack + [('else', Item[1])]) elif Item[0] == 'if': functiontorun(Current, Item, Params, Stack) scan_statements(Current, Item[2], functiontorun, Params, Stack + [('if', Item[1])]) elif Item[0] == 'named_begin': scan_statement(Current, functiontorun, Item[2], Params, Stack) elif Item[0] == 'list': for X in Item[1:]: scan_statements(Current, X, functiontorun, Params, Stack) elif Item[0] == 'while': functiontorun(Current, Item, Params, Stack) scan_statements(Current, Item[2], functiontorun, Params, Stack + [('while', Item[1])]) functiontorun(Current, False, Params, Stack) elif Item[0] == 'for': functiontorun(Current, Item, Params, Stack) scan_statements(Current, Item[4], functiontorun, Params, Stack + [('for', Item[1])]) functiontorun(Current, False, Params, Stack) elif Item[0] in ['case', 'casez', 'casex']: for NX in Item[2]: Case = NX[0] Stmnt = NX[1] scan_statements(Current, Stmnt, functiontorun, Params, Stack + [('case', Item[1]), ('item', Case)]) elif Item[0] in [ 'wait', 'when', '#', '$finish', 'force', 'release', 'disable' ]: functiontorun(Current, Item, Params, Stack) elif Item[0] == 'functioncall': functiontorun(Current, Item, Params, Stack) elif Item[0] in ['<=', '=', 'emit']: functiontorun(Current, Item, Params, Stack) elif Item[0] == 'taskcall': Task = Item[1] if Task in Current.tasks: logs.log_info('going into task %s' % Task) Code = Current.tasks[Task] scan_statements(Current, Code[0], functiontorun, Params, Stack) else: logs.log_err('scan_statement: task %s not in tasks %s %s' % (Task, Params, Stack)) elif Item[0] == 'empty_begin_end': pass else: logs.log_err('scan_statement: %s %s stack=%s' % (Item, Params, Stack))
def help_main(Env): if Env.Current == None: logs.log_err('no module to work on') return load_sons(Env) check_integrity(Env, Env.Current) check_instance_connections(Env, Env.Current) create_drive_table(Env.Current) look_for_loops(Env.Current) look_for_short_loops(Env.Current) look_for_pass_throughs(Env.Current) check_cases(Env.Current) logs.report_errx(Env.Current.Module)
def get_dir(Item): if len(Item) == 2: List = DataBase[Item] res = [] for Thing in List: res.append(Thing[0]) res.sort() return string.join(res) if (type(Item) == types.TupleType) and (len(Item) == 4): return Item[0] logs.log_err('get_dir %s' % str(Item)) return Item