+get_insn_list = $(shell grep ^DECLARE_INSN $(1) | sed 's/DECLARE_INSN(\(.*\),.*,.*)/\1/')
+get_opcode = $(shell grep ^DECLARE_INSN.*\\\<$(2)\\\> $(1) | sed 's/DECLARE_INSN(.*,\(.*\),.*)/\1/')
+
riscv_subproject_deps = \
- softfloat_riscv \
softfloat \
riscv_install_prog_srcs = \
- spike.cc \
-riscv_hdrs := \
+riscv_hdrs = \
htif.h \
common.h \
decode.h \
processor.h \
sim.h \
trap.h \
- opcodes.h \
- insn_header.h \
+ encoding.h \
cachesim.h \
memtracer.h \
+ extension.h \
+ rocc.h \
+ insn_template.h \
+ mulhi.h \
+
+riscv_precompiled_hdrs = \
+ insn_template.h \
riscv_srcs = \
htif.cc \
cachesim.cc \
mmu.cc \
disasm.cc \
- $(DISPATCH_SRCS) \
+ extension.cc \
+ extensions.cc \
+ rocc.cc \
+ regnames.cc \
+ $(riscv_gen_srcs) \
riscv_test_srcs =
-riscv_gen_hdrs: \
- dispatch.h \
+riscv_gen_hdrs = \
+ icache.h \
+
+riscv_gen_srcs = \
+ $(addsuffix .cc, $(call get_insn_list,$(src_dir)/riscv/encoding.h))
-NDISPATCH := 9
-DISPATCH_SRCS = $(addsuffix .cc,$(addprefix dispatch,$(call range,0,$(NDISPATCH))))
+icache_entries := `grep "ICACHE_ENTRIES =" $(src_dir)/riscv/mmu.h | sed 's/.* = \(.*\);/\1/'`
-$(DISPATCH_SRCS): %.cc: dispatch $(wildcard insns/*.h) opcodes.h
- $< $(subst dispatch,,$(subst .cc,,$@)) $(NDISPATCH) 1024 < $(src_dir)/riscv/opcodes.h > $@
+icache.h: mmu.h
+ $(src_dir)/riscv/gen_icache $(icache_entries) > $@.tmp
+ mv $@.tmp $@
-dispatch.h: %.h: dispatch opcodes.h
- echo $(riscv_srcs)
- $< $(NDISPATCH) 1024 < $(src_dir)/riscv/opcodes.h > $@
+$(riscv_gen_srcs): %.cc: insns/%.h insn_template.cc
+ sed 's/NAME/$(subst .cc,,$@)/' $(src_dir)/riscv/insn_template.cc | sed 's/OPCODE/$(call get_opcode,$(src_dir)/riscv/encoding.h,$(subst .cc,,$@))/' > $@
riscv_junk = \
- dispatch.h \
- $(DISPATCH_SRCS) \
+ $(riscv_gen_srcs) \