Slight refactoring

This commit is contained in:
Flawed
2023-11-05 21:07:04 -08:00
parent e48db26870
commit 07e6e6cf26
2 changed files with 50 additions and 36 deletions
+26 -17
View File
@@ -31,22 +31,11 @@ desired_names = {
}
@click.command()
@click.argument("opcodes_file", type=click.File("r"))
def generate_act_format(opcodes_file):
"""
Parses an OPCODES_FILE and outputs opcodes in a format expected by ACT.
This is also just a bunch of regexes slapped together.
Outputs to stdout.
Example:
python generate_act_format.py Ipcs.h
"""
def write_act_format(opcodes_lines):
output_lines = []
opcode_mapping = dict()
for line in opcodes_file.readlines():
for line in opcodes_lines:
match_groups = re.findall(r"^\s*([^\/].*)=\s*(.*),\s*\/\/.*$", line)
if len(match_groups) != 1:
continue
@@ -66,11 +55,31 @@ def generate_act_format(opcodes_file):
desired = name
opcodes = opcode_mapping[name]
if len(opcodes) == 1:
print(f"{desired}|{opcodes[0]:x}")
output_lines.append(f"{desired}|{opcodes[0]:x}")
elif len(opcodes) > 1:
print(f'{desired}|{[f"{opcode:x}" for opcode in opcodes]}')
output_lines.append(f'{desired}|{[f"{opcode:x}" for opcode in opcodes]}')
else:
print(f"{desired}|???")
output_lines.append(f"{desired}|???")
return output_lines
@click.command()
@click.argument("opcodes_file", type=click.File("r"))
def generate_act_format(opcodes_file):
"""
Parses an OPCODES_FILE and outputs opcodes in a format expected by ACT.
This is also just a bunch of regexes slapped together.
Outputs to stdout.
Example:
python generate_act_format.py Ipcs.h
"""
lines = write_act_format(opcodes_file.readlines())
for line in lines:
print(line)
if __name__ == "__main__":