diff options
author | Ngo Iok Ui (Wu Yu Wei) <wusyong9104@gmail.com> | 2020-11-09 06:18:22 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-08 14:18:22 -0800 |
commit | 130fcfb252c02c32f3d2f12e22df546239188813 (patch) | |
tree | f77526952d2b7f3fed51be5771cd9134f069664a | |
parent | e4f71addaa112f7890e5d9f89c3a088a2017731a (diff) | |
download | riscv-opcodes-130fcfb252c02c32f3d2f12e22df546239188813.zip riscv-opcodes-130fcfb252c02c32f3d2f12e22df546239188813.tar.gz riscv-opcodes-130fcfb252c02c32f3d2f12e22df546239188813.tar.bz2 |
Support generating Rust code (#52)
-rw-r--r-- | Makefile | 3 | ||||
-rwxr-xr-x | parse_opcodes | 13 |
2 files changed, 16 insertions, 0 deletions
@@ -27,6 +27,9 @@ inst.chisel: $(ALL_OPCODES) parse_opcodes inst.go: $(ALL_REAL_ILEN32_OPCODES) parse_opcodes cat $(ALL_REAL_ILEN32_OPCODES) | ./parse_opcodes -go > $@ +inst.rs: $(ALL_OPCODES) parse_opcodes + cat $(ALL_OPCODES) | ./parse_opcodes -rust > $@ + inst.sverilog: $(ALL_OPCODES) parse_opcodes cat $(ALL_OPCODES) | ./parse_opcodes -sverilog > $@ diff --git a/parse_opcodes b/parse_opcodes index 3c2b84b..6002b01 100755 --- a/parse_opcodes +++ b/parse_opcodes @@ -1019,6 +1019,17 @@ def make_go(): print('\treturn nil, false') print('}') +def make_rust(): + print('/* Automatically generated by parse_opcodes. */') + for name in namelist: + name2 = name.upper().replace('.','_') + print('const MATCH_%s: u32 = %s;' % (name2, hex(match[name]))) + print('const MASK_%s: u32 = %s;' % (name2, hex(mask[name]))) + for num, name in csrs+csrs32: + print('const CSR_%s: u16 = %s;' % (name.upper(), hex(num))) + for num, name in causes: + print('const CAUSE_%s: u8 = %s;' % (name.upper().replace(' ', '_'), hex(num))) + def parse_inputs(args): inputs = [] for fn in args: @@ -1114,5 +1125,7 @@ if __name__ == "__main__": make_c(match,mask) elif sys.argv[1] == '-go': make_go() + elif sys.argv[1] == '-rust': + make_rust() else: assert 0 |