1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
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 \
jump
# 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)
|