aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorWojciech Kosior <kwojtus@protonmail.com>2020-09-01 10:54:59 +0200
committerWojciech Kosior <kwojtus@protonmail.com>2020-09-01 11:04:22 +0200
commitee1f6c47e1eff920068f4bceaf604f9535a2e8a9 (patch)
tree580eb001a72601d254bb29cc348a529490f84808 /Makefile
parentcd02ddff8886aa1db29f80d3cc5cf99a349d8258 (diff)
downloadAGH-engineering-thesis-ee1f6c47e1eff920068f4bceaf604f9535a2e8a9.tar.gz
AGH-engineering-thesis-ee1f6c47e1eff920068f4bceaf604f9535a2e8a9.zip
start anew
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile127
1 files changed, 127 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..21346c7
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,127 @@
+CC = gcc
+CFLAGS = -std=c89 -pedantic -Wall -Werror -O2
+
+IV = iverilog
+
+IVFLAGS = -Iinclude/ -DSIMULATION
+# The macroassembly header file is somewhat different thing, but I don't know
+# what place would be more suitable for it than include/ dir
+MACROASM_FLAGS := -Iinclude/ -E
+
+# It made sense to just list all of those in this variable
+# and then prepend stack_machine_ to each element
+STACK_MACHINE_TESTS := \
+ store \
+ load_store \
+ multiinstructions_load_store \
+ add \
+ sub \
+ div \
+ mul
+
+# Add other tests here if You need
+TESTS := \
+ self \
+ intercon \
+ div \
+ vga \
+ $(addprefix stack_machine_,$(STACK_MACHINE_TESTS))
+
+# For each of these Makefile will attempt to generate VGAdump.ppm
+# and compare it to VGAdump_expected.ppm inside that test's directory
+TESTS_WITH_VGA := vga
+
+# Short C programs
+TOOLS := VGAdump2ppm
+
+ifdef DEBUG
+IVFLAGS += -DDEBUG
+DBG&SAVE = tee "$(1)"
+else
+DBG&SAVE = cat > "$(1)" # putting cat through pipe - what an animal cruelty!
+endif
+
+TEST_TARGETS := $(addprefix test_,$(TESTS))
+VGA_TEST_TARGETS := $(addprefix test_,$(TESTS_WITH_VGA))
+
+TEST_LOGS := $(foreach TEST,$(TESTS),tests/$(TEST)/report.log)
+
+TOOLS_TARGETS := $(addprefix tools/,$(TOOLS))
+
+GENERATED_MEM_FILES := $(shell find tests/ -name "*.s.tcl")
+GENERATED_MEM_FILES := $(basename $(basename $(GENERATED_MEM_FILES)))
+GENERATED_MEM_FILES += $(basename $(shell find tests/ -name "*.memv"))
+GENERATED_MEM_FILES := $(addsuffix .mem,$(GENERATED_MEM_FILES))
+
+# TODO: check if this function can be changed to use $(shell grep ...)
+FILE_LINES = `grep -E '^[[:space:]]*[^[:space:]/]' -c $(1)`
+
+test : $(TEST_TARGETS)
+
+tests/%.mem : tests/%.memv
+ $(IV) $(MACROASM_FLAGS) $^ -o $@
+
+tests/%.mem : tests/%.s.tcl tclasm.tcl
+ $< > $@
+
+tests/self/test.vvp : tests/self/operations.mem tests/self/test.v \
+ models/slave.v models/master.v include/messages.vh
+ $(IV) $(IVFLAGS) -s self_test \
+ -DMASTER_OPERATIONS_COUNT=$(call FILE_LINES,$<) \
+ $(filter %.v,$^) -o $@
+
+tests/intercon/test.vvp : tests/intercon/operations.mem tests/intercon/test.v \
+ models/slave.v models/master.v design/intercon.v \
+ include/messages.vh
+ $(IV) $(IVFLAGS) -s intercon_test \
+ -DMASTER_OPERATIONS_COUNT=$(call FILE_LINES,$<) \
+ $(filter %.v,$^) -o $@
+
+tests/div/test.vvp : tests/div/test.v design/div.v include/messages.vh
+ $(IV) $(IVFLAGS) -s div_test $(filter %.v,$^) -o $@
+
+tests/vga/test.vvp : tests/vga/test.v design/vga.v models/vga_display.v \
+ include/messages.vh
+ $(IV) $(IVFLAGS) -s vga_test $^ -o $@
+
+tests/stack_machine_%/test.vvp : tests/stack_machine_%/instructions.mem \
+ tests/stack_machine_%/words_to_verify.mem \
+ tests/stack_machine_%/test.v models/slave.v \
+ design/stack_machine.v design/div.v include/messages.vh
+ $(IV) $(IVFLAGS) -s stack_machine_test \
+ -DINSTRUCTIONS_COUNT=$(call FILE_LINES,$<) \
+ -DWORDS_TO_VERIFY_COUNT=$(call FILE_LINES,$(filter %fy.mem,$^)) \
+ $(filter %.v,$^) -o $@
+
+
+$(foreach TEST,$(TESTS_WITH_VGA),tests/$(TEST)/report.log) \
+$(foreach TEST,$(TESTS_WITH_VGA),tests/$(TEST)/VGAdump.ppm) : design/font.mem
+
+tests/%/VGAdump.mem tests/%/report.log : tests/%/test.vvp
+ cd $(dir $<) && vvp $(notdir $<) | $(call DBG&SAVE,report.log)
+
+tests/%/VGAdump.ppm : tests/%/VGAdump.mem tools/VGAdump2ppm
+ grep -v // < $< | ./tools/VGAdump2ppm > $@
+
+$(VGA_TEST_TARGETS) : test_% : tests/%/VGAdump_expected.ppm tests/%/VGAdump.ppm
+$(TEST_TARGETS) : test_% : tests/%/report.log
+ if grep error $<; then false; fi
+ if [ "$(filter $@,$(VGA_TEST_TARGETS))" != "" ]; then \
+ diff $(dir $<)VGAdump.ppm $(dir $<)VGAdump_expected.ppm; \
+ fi
+
+tools : $(TOOLS_TARGETS)
+
+$(TOOLS_TARGETS) : tools/% : tools/%.c
+ $(CC) $(CFLAGS) $^ -o $@
+
+clean :
+ -find tests/ -name "*.vvp" -delete
+ -find tests/ -name "*.log" -delete
+ -find tests/ -name "VGAdump.mem" -delete
+ -find tests/ -name "VGAdump.ppm" -delete
+ -rm $(GENERATED_MEM_FILES)
+ -rm tests
+ -rm $(TOOLS_TARGETS)
+
+.PHONY : tools test $(TEST_TARGETS)