Last active
November 5, 2020 12:14
-
-
Save Myriad-Dreamin/a327441440c451946ea4a8630f195515 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| import os | |
| import json | |
| from collections import deque | |
| if __name__ == '__main__': | |
| with open('build/fake-include/fuzzer-fake-include-all.inc', 'r', encoding='utf8') as f: | |
| wif = False | |
| the_wif = '' | |
| pre_decls = [] | |
| for line in f.readlines(): | |
| if wif: | |
| wif = False | |
| if line.startswith('//'): | |
| pre_decls.append((the_wif.strip(), line[2:])) | |
| if line.startswith('// in file '): | |
| wif = True | |
| the_wif = line[len('// in file '):] | |
| with open('build/no_ref', 'r', encoding='utf8') as f: | |
| urt = 'undefined reference to ' | |
| in_func = 'In function' | |
| mur = 'more undefined references to' | |
| undefined_references = set() | |
| for line in f.readlines(): | |
| line = line.strip() | |
| if len(line) == 0: | |
| continue | |
| if urt in line: | |
| undefined_references.add(re.search(r"`(.*)'", line).group(1)) | |
| elif in_func in line or mur in line: | |
| pass | |
| else: | |
| print(line) | |
| with open('fps.parsed.json') as f: | |
| res = json.load(f) | |
| serial_vars = res['serial_var_decls'] | |
| func_refs = dict() | |
| for func in serial_vars: | |
| func_refs[func['name']] = func | |
| completion = ['#include <fuzzer-fake-include-all.inc>'] | |
| for fd in serial_vars: | |
| if fd['name'] in undefined_references: | |
| undefined_references.remove(fd['name']) | |
| completion.append(fd['decl'].replace('extern', '') + ';') | |
| dirs = deque() | |
| dirs.append('build/fake-drivers/drivers/gpu/arm_gpu') | |
| while len(dirs): | |
| the_dir = dirs.pop() | |
| for file_name in os.listdir(the_dir): | |
| if file_name.endswith('.h'): | |
| joined = os.path.join(the_dir, file_name) | |
| with open(joined) as f: | |
| for line in f.readlines(): | |
| founded = None | |
| for ur in undefined_references: | |
| if ur in line: | |
| founded = (ur, line) | |
| if founded: | |
| if founded[1].startswith('extern'): | |
| completion.append(founded[1].replace('extern', '')) | |
| else: | |
| # macro = os.path.abspath(joined) | |
| # macro = macro.replace('/', '_').replace('-', '_').upper() | |
| # completion.append(f'#ifndef {macro}') | |
| # completion.append(f'#define {macro}') | |
| # completion.append(f'#include "{os.path.abspath(joined)}"') | |
| # completion.append(f'#endif // {macro}') | |
| completion.append(founded[1].replace('} ', '').replace(' ;', ' {}')) | |
| undefined_references.remove(founded[0]) | |
| elif file_name.endswith('.d') or file_name.endswith('.c'): | |
| pass | |
| else: | |
| joined = os.path.join(the_dir, file_name) | |
| if os.path.isdir(joined): | |
| dirs.append(joined) | |
| else: | |
| print('gg', joined) | |
| with open('build/auto-completion.c', 'w', encoding='utf8') as f: | |
| f.write('\n'.join(completion)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment