diff options
author | Jay Dev Jha <jaydev.neuroscitech@gmail.com> | 2024-10-27 20:38:10 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-27 20:38:10 +0530 |
commit | 25c09e69c72371d1f72ff22c3359e83a4b3247a7 (patch) | |
tree | 4c9b578a359e371cd4c49175b4abd57e595ca5e6 /rust_utils.py | |
parent | 020470605b661fbffaa0e946cf279fee7c7e6fda (diff) | |
parent | 6900b2aba2ab6e895cf21bcf37c9cea4e97409bf (diff) | |
download | riscv-opcodes-25c09e69c72371d1f72ff22c3359e83a4b3247a7.zip riscv-opcodes-25c09e69c72371d1f72ff22c3359e83a4b3247a7.tar.gz riscv-opcodes-25c09e69c72371d1f72ff22c3359e83a4b3247a7.tar.bz2 |
Merge pull request #283 from riscv/latex-based-output-refactor
Refactored and Optimized Logic:: Parser Logic & Shared Modules
Diffstat (limited to 'rust_utils.py')
-rw-r--r-- | rust_utils.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/rust_utils.py b/rust_utils.py new file mode 100644 index 0000000..19a47b9 --- /dev/null +++ b/rust_utils.py @@ -0,0 +1,39 @@ +import collections +import copy +import glob +import logging +import os +import pprint +import re +import sys + +import yaml + +from constants import * + +# from shared_utils import overlaps, overlap_allowed, extension_overlap_allowed, instruction_overlap_allowed, process_enc_line, same_base_isa, add_segmented_vls_insn, expand_nf_field +from shared_utils import * + +pp = pprint.PrettyPrinter(indent=2) +logging.basicConfig(level=logging.INFO, format="%(levelname)s:: %(message)s") + + +def make_rust(instr_dict): + mask_match_str = "" + for i in instr_dict: + mask_match_str += f'const MATCH_{i.upper().replace(".","_")}: u32 = {(instr_dict[i]["match"])};\n' + mask_match_str += f'const MASK_{i.upper().replace(".","_")}: u32 = {(instr_dict[i]["mask"])};\n' + for num, name in csrs + csrs32: + mask_match_str += f"const CSR_{name.upper()}: u16 = {hex(num)};\n" + for num, name in causes: + mask_match_str += ( + f'const CAUSE_{name.upper().replace(" ","_")}: u8 = {hex(num)};\n' + ) + rust_file = open("inst.rs", "w") + rust_file.write( + f""" +/* Automatically generated by parse_opcodes */ +{mask_match_str} +""" + ) + rust_file.close() |