aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTommy Thorn <tommy-github-email@thorn.ws>2019-08-03 17:36:25 -0700
committerAndrew Waterman <andrew@sifive.com>2019-08-03 17:36:25 -0700
commite2ebbf53340bd856cde5eabfaa6b15831c791478 (patch)
tree9878d823e299b24ed5c0d1b2d8a161aa42f13c44
parenta52c518b8d2dc36051e1cbc61c519967deeaf60f (diff)
downloadriscv-opcodes-e2ebbf53340bd856cde5eabfaa6b15831c791478.zip
riscv-opcodes-e2ebbf53340bd856cde5eabfaa6b15831c791478.tar.gz
riscv-opcodes-e2ebbf53340bd856cde5eabfaa6b15831c791478.tar.bz2
(Partially) fix #30 (#31)
* (Partially) fix #30 With this change (and a renamed parse-opcodes) it's possible to as a Python module without having to patch the repo. Example: from parse_opcodes import parse_inputs if __name__ == "__main__": (namelist, pseudos, mask, match, arguments) = parse_inputs(["opcodes", "opcodes-rvc"]) * Fix #30: Rename parse-opcode to parse_opcode to enable module use
-rw-r--r--Makefile24
-rw-r--r--opcodes-rvc-pseudo2
-rwxr-xr-xparse_opcodes (renamed from parse-opcodes)63
3 files changed, 47 insertions, 42 deletions
diff --git a/Makefile b/Makefile
index 7982501..c630cef 100644
--- a/Makefile
+++ b/Makefile
@@ -10,23 +10,23 @@ ALL_OPCODES := opcodes-pseudo opcodes opcodes-rvc opcodes-rvc-pseudo opcodes-cus
install: $(ISASIM_H) $(PK_H) $(FESVR_H) $(ENV_H) $(OPENOCD_H) inst.chisel instr-table.tex priv-instr-table.tex
-$(ISASIM_H) $(PK_H) $(FESVR_H) $(ENV_H) $(OPENOCD_H): $(ALL_OPCODES) parse-opcodes encoding.h
+$(ISASIM_H) $(PK_H) $(FESVR_H) $(ENV_H) $(OPENOCD_H): $(ALL_OPCODES) parse_opcodes encoding.h
cp encoding.h $@
- cat opcodes opcodes-rvc-pseudo opcodes-rvc opcodes-custom opcodes-rvv | python ./parse-opcodes -c >> $@
+ cat opcodes opcodes-rvc-pseudo opcodes-rvc opcodes-custom opcodes-rvv | python ./parse_opcodes -c >> $@
-inst.chisel: $(ALL_OPCODES) parse-opcodes
- cat opcodes opcodes-rvc opcodes-rvc-pseudo opcodes-custom opcodes-rvv opcodes-rvv-pseudo opcodes-pseudo | ./parse-opcodes -chisel > $@
+inst.chisel: $(ALL_OPCODES) parse_opcodes
+ cat opcodes opcodes-rvc opcodes-rvc-pseudo opcodes-custom opcodes-rvv opcodes-rvv-pseudo opcodes-pseudo | ./parse_opcodes -chisel > $@
-inst.go: opcodes opcodes-pseudo parse-opcodes
- cat opcodes opcodes-pseudo | ./parse-opcodes -go > $@
+inst.go: opcodes opcodes-pseudo parse_opcodes
+ cat opcodes opcodes-pseudo | ./parse_opcodes -go > $@
-inst.sverilog: opcodes opcodes-pseudo parse-opcodes
- cat opcodes opcodes-rvc opcodes-rvc-pseudo opcodes-custom opcodes-pseudo | ./parse-opcodes -sverilog > $@
+inst.sverilog: opcodes opcodes-pseudo parse_opcodes
+ cat opcodes opcodes-rvc opcodes-rvc-pseudo opcodes-custom opcodes-pseudo | ./parse_opcodes -sverilog > $@
-instr-table.tex: $(ALL_OPCODES) parse-opcodes
- cat opcodes opcodes-pseudo | ./parse-opcodes -tex > $@
+instr-table.tex: $(ALL_OPCODES) parse_opcodes
+ cat opcodes opcodes-pseudo | ./parse_opcodes -tex > $@
-priv-instr-table.tex: $(ALL_OPCODES) parse-opcodes
- cat opcodes opcodes-pseudo | ./parse-opcodes -privtex > $@
+priv-instr-table.tex: $(ALL_OPCODES) parse_opcodes
+ cat opcodes opcodes-pseudo | ./parse_opcodes -privtex > $@
.PHONY : install
diff --git a/opcodes-rvc-pseudo b/opcodes-rvc-pseudo
index dd3d929..57ed05c 100644
--- a/opcodes-rvc-pseudo
+++ b/opcodes-rvc-pseudo
@@ -1,5 +1,5 @@
# these aren't really pseudo-ops, but they overlay other encodings,
-# so they are here to prevent parse-opcodes from barfing
+# so they are here to prevent parse_opcodes from barfing
@c.nop 1..0=1 15..13=0 12=0 11..7=0 6..2=0
@c.addi16sp 1..0=1 15..13=3 12=ignore 11..7=2 6..2=ignore
diff --git a/parse-opcodes b/parse_opcodes
index ddb5b9f..c9822d5 100755
--- a/parse-opcodes
+++ b/parse_opcodes
@@ -351,7 +351,7 @@ def binary(n, digits=0):
return rep if digits == 0 else ('0' * (digits - len(rep))) + rep
def make_c(match,mask):
- print('/* Automatically generated by parse-opcodes. */')
+ print('/* Automatically generated by parse_opcodes. */')
print('#ifndef RISCV_ENCODING_H')
print('#define RISCV_ENCODING_H')
for name in namelist:
@@ -900,7 +900,7 @@ def print_chisel_insn(name):
print(s + "\")")
def make_chisel():
- print('/* Automatically generated by parse-opcodes */')
+ print('/* Automatically generated by parse_opcodes */')
print('object Instructions {')
for name in namelist:
print_chisel_insn(name)
@@ -942,7 +942,7 @@ def print_sverilog_insn(name):
print(s + ";")
def make_sverilog():
- print('/* Automatically generated by parse-opcodes */')
+ print('/* Automatically generated by parse_opcodes */')
print('package riscv_instr;')
for name in namelist:
print_sverilog_insn(name)
@@ -968,7 +968,7 @@ def print_go_insn(name):
print('\t\treturn &inst{0x%x, 0x%x, 0x%x, %d, 0x%x}, true' % (opcode, funct3, rs2, signed(csr, 12), funct7))
def make_go():
- print('// Code generated by parse-opcodes; DO NOT EDIT.')
+ print('// Code generated by parse_opcodes; DO NOT EDIT.')
print()
print('package riscv')
print()
@@ -990,16 +990,17 @@ def make_go():
print('\treturn nil, false')
print('}')
-inputs = []
-for index in range(2, len(sys.argv)):
- try:
- inputs.append(open(sys.argv[index]))
- except:
- assert(0)
-if not inputs:
- inputs.append(sys.stdin)
-
-for f in inputs:
+def parse_inputs(args):
+ inputs = []
+ for fn in args:
+ try:
+ inputs.append(open(fn))
+ except:
+ assert(0)
+ if not inputs:
+ inputs.append(sys.stdin)
+
+ for f in inputs:
for line in f:
line = line.partition('#')
tokens = line[0].split()
@@ -1067,18 +1068,22 @@ for f in inputs:
if f is not sys.stdin:
f.close()
-
-if sys.argv[1] == '-tex':
- make_latex_table()
-elif sys.argv[1] == '-privtex':
- make_supervisor_latex_table()
-elif sys.argv[1] == '-chisel':
- make_chisel()
-elif sys.argv[1] == '-sverilog':
- make_sverilog()
-elif sys.argv[1] == '-c':
- make_c(match,mask)
-elif sys.argv[1] == '-go':
- make_go()
-else:
- assert 0
+ return (namelist, pseudos, mask, match, arguments)
+
+if __name__ == "__main__":
+ parse_inputs(sys.argv[1:])
+
+ if sys.argv[1] == '-tex':
+ make_latex_table()
+ elif sys.argv[1] == '-privtex':
+ make_supervisor_latex_table()
+ elif sys.argv[1] == '-chisel':
+ make_chisel()
+ elif sys.argv[1] == '-sverilog':
+ make_sverilog()
+ elif sys.argv[1] == '-c':
+ make_c(match,mask)
+ elif sys.argv[1] == '-go':
+ make_go()
+ else:
+ assert 0