def contents_as_module_without_require(lib, other_imports, export=False, **kwargs): import_all_directories = not absolutize_has_all_constants( kwargs['absolutize']) if import_all_directories and not export: transform_base = lambda x: (escape_lib(x) + '.' + x if is_local_import(x, **kwargs) else x) else: transform_base = lambda x: x v_name = filename_of_lib(lib, ext='.v', **kwargs) contents = get_file(v_name, transform_base=transform_base, **kwargs) contents = strip_requires(contents) if kwargs['verbose'] > 2: kwargs['log'](contents) module_name = escape_lib(lib) # import the top-level wrappers if len(other_imports) > 0 and not export: # we need to import the contents in the correct order. Namely, if we have a module whose name is also the name of a directory (in the same folder), we want to import the file first. for imp in reversed( construct_import_list( other_imports, import_all_directories=import_all_directories)): contents = 'Import %s.\n%s' % (imp, contents) # wrap the contents in directory modules lib_parts = list(map(escape_lib, lib.split('.'))) maybe_export = 'Export ' if export else '' contents = 'Module %s.\n%s\nEnd %s.\n' % (lib_parts[-1], contents, lib_parts[-1]) for name in reversed(lib_parts[:-1]): contents = 'Module %s%s.\n%s\nEnd %s.\n' % ( maybe_export, name, contents, name) # or Module Export? contents = 'Module %s%s.\n%s\nEnd %s.\n' % (maybe_export, module_name, contents, module_name) return contents
def contents_without_imports(lib, **kwargs): v_file = filename_of_lib(lib, ext='.v', **kwargs) contents = get_file(v_file, **kwargs) if '(*' in ' '.join(IMPORT_LINE_REG.findall(contents)): print( 'Warning: There are comments in your Require/Import/Export lines in %s.' % v_file) return IMPORT_LINE_REG.sub('', contents)
def normalize_requires(filename, **kwargs): """Return the contents of filename, with all [Require]s split out and ordered at the top.""" if filename[-2:] != '.v': filename += '.v' kwargs = fill_kwargs(kwargs) lib = lib_of_filename(filename, libnames=tuple(kwargs['libnames'])) all_imports = run_recursively_get_imports(lib, **kwargs) v_name = filename_of_lib(lib, ext='.v', **kwargs) contents = get_file(v_name, **kwargs) contents = strip_requires(contents) contents = ''.join('Require %s.\n' % i for i in all_imports[:-1]) + '\n' + contents.strip() + '\n' return contents
def normalize_requires(filename, **kwargs): """Return the contents of filename, with all [Require]s split out and ordered at the top. Preserve any leading whitespace/comments. """ if filename[-2:] != '.v': filename += '.v' kwargs = fill_kwargs(kwargs) lib = lib_of_filename(filename, **kwargs) all_imports = run_recursively_get_imports(lib, **kwargs) v_name = filename_of_lib(lib, ext='.v', **kwargs) contents = get_file(v_name, **kwargs) header, contents = split_leading_comments_and_whitespace(contents) contents = strip_requires(contents) contents = ''.join('Require %s.\n' % i for i in all_imports[:-1]) + '\n' + contents.strip() + '\n' return header + contents
def contents_as_module_without_require(lib, other_imports, export=False, **kwargs): import_all_directories = not absolutize_has_all_constants(kwargs['absolutize']) if import_all_directories and not export: transform_base = lambda x: (escape_lib(x) + '.' + x if is_local_import(x, **kwargs) else x) else: transform_base = lambda x: x v_name = filename_of_lib(lib, ext='.v', **kwargs) contents = get_file(v_name, transform_base=transform_base, **kwargs) contents = strip_requires(contents) if kwargs['verbose'] > 2: kwargs['log'](contents) module_name = escape_lib(lib) # import the top-level wrappers if len(other_imports) > 0 and not export: # we need to import the contents in the correct order. Namely, if we have a module whose name is also the name of a directory (in the same folder), we want to import the file first. for imp in reversed(construct_import_list(other_imports, import_all_directories=import_all_directories)): contents = 'Import %s.\n%s' % (imp, contents) # wrap the contents in directory modules lib_parts = list(map(escape_lib, lib.split('.'))) maybe_export = 'Export ' if export else '' contents = 'Module %s.\n%s\nEnd %s.\n' % (lib_parts[-1], contents, lib_parts[-1]) for name in reversed(lib_parts[:-1]): contents = 'Module %s%s.\n%s\nEnd %s.\n' % (maybe_export, name, contents, name) # or Module Export? contents = 'Module %s%s.\n%s\nEnd %s.\n' % (maybe_export, module_name, contents, module_name) return contents
def contents_without_imports(lib, **kwargs): v_file = filename_of_lib(lib, ext='.v', **kwargs) contents = get_file(v_file, **kwargs) if '(*' in ' '.join(IMPORT_LINE_REG.findall(contents)): print('Warning: There are comments in your Require/Import/Export lines in %s.' % filename) return IMPORT_LINE_REG.sub('', contents)