import re import os import sys # The generated .f lists live next to this script, not under the caller's cwd -- # the flow runs the tools from outputs//, so relative paths would escape. LISTS_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'lists') synopsys = True # global variables search_dirs = [] file_path_list = {} modules = {} module_names = [] # if you're reading this code stop before its too late # it will ruin you like it ruined me . .. . define_module_regex = re.compile(r'^(? ", file=sys.stderr) print("Example: python3.12 get_rtl.py execute_stage /path/to/SJapr/tapeouts/to2/src /path/to/SJapr/tapeouts/to2/packages") sys.exit(1) # ingest toplevel module name and codebase path toplevel_module_name = sys.argv[1] del sys.argv[0] del sys.argv[0] search_dirs = sys.argv # modules is a dict with : modules = find_modules() module_names = list(modules.keys()) print(modules) try: toplevel_module_path = modules[toplevel_module_name] except: print(f"ERROR: RTL module {toplevel_module_name} not found in RTL search paths.") sys.exit(1) hierarchy = collect_hierarchy(toplevel_module_path) if modules[toplevel_module_name] not in hierarchy: hierarchy.append(modules[toplevel_module_name]) assumed_headers = [] for filepath in hierarchy: if not has_defines(filepath): assumed_headers.append(filepath) hierarchy.remove(filepath) headers = [] for path in hierarchy: if ".svh" in path: headers.append(path) hierarchy.remove(path) assumed_headers.extend(hierarchy) headers.extend(assumed_headers) hierarchy = headers os.makedirs(LISTS_DIR, exist_ok=True) # synopsys finds headers itself for some reason if (synopsys): try: with open(os.path.join(LISTS_DIR, 'header_directory_list.f'), 'w') as header_directory_list: with open(os.path.join(LISTS_DIR, 'header_list.f'), 'w') as header_list: headers = [] for filepath in hierarchy[:]: if filepath.endswith('.svh'): piece_list = filepath.split('/') path = filepath.replace(piece_list[len(piece_list)-1], '', 1) header_list.write(f"{filepath}\n") if path not in headers: headers.append(path) header_directory_list.write(f"{path}\n") hierarchy.remove(filepath) except Exception: pass with open(os.path.join(LISTS_DIR, 'file_list.f'), 'w') as file_list: for filepath in hierarchy: file_list.write(f"{filepath}\n")