diff options
author | IIITM-Jay <jaydev.neuroscitech@gmail.com> | 2024-10-25 01:43:58 +0530 |
---|---|---|
committer | IIITM-Jay <jaydev.neuroscitech@gmail.com> | 2024-10-25 01:43:58 +0530 |
commit | d57a94cf8eb07917a2084b6d502b9225fc9ce210 (patch) | |
tree | ef59527e0beba91314303c5732354fd88e582dcd /c_utils.py | |
parent | 0b7f6180f893ec7cddaa6fcf55c7a7e3969ccd17 (diff) | |
download | riscv-opcodes-d57a94cf8eb07917a2084b6d502b9225fc9ce210.zip riscv-opcodes-d57a94cf8eb07917a2084b6d502b9225fc9ce210.tar.gz riscv-opcodes-d57a94cf8eb07917a2084b6d502b9225fc9ce210.tar.bz2 |
clean up codes for refactoring parsing logic
Diffstat (limited to 'c_utils.py')
-rw-r--r-- | c_utils.py | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -43,18 +43,19 @@ def make_c(instr_dict): arg_str = "" for name, rng in arg_lut.items(): + sanitized_name = name.replace(" ", "_").replace("=", "_eq_") begin = rng[1] end = rng[0] mask = ((1 << (end - begin + 1)) - 1) << begin - arg_str += f"#define INSN_FIELD_{name.upper().replace(' ', '_')} {hex(mask)}\n" + arg_str += f"#define INSN_FIELD_{sanitized_name.upper()} {hex(mask)}\n" with open(f"{os.path.dirname(__file__)}/encoding.h", "r") as file: enc_header = file.read() commit = os.popen('git log -1 --format="format:%h"').read() - enc_file = open("encoding.out.h", "w") - enc_file.write( - f"""/* SPDX-License-Identifier: BSD-3-Clause */ + + # Generate the output as a string + output_str = f"""/* SPDX-License-Identifier: BSD-3-Clause */ /* Copyright (c) 2023 RISC-V International */ @@ -78,5 +79,7 @@ def make_c(instr_dict): #ifdef DECLARE_CAUSE {declare_cause_str}#endif """ - ) - enc_file.close() + + # Write the modified output to the file + with open("encoding.out.h", "w") as enc_file: + enc_file.write(output_str) |