forked from Obijuan/open-fpga-verilog-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
214 lines (171 loc) · 6.74 KB
/
Makefile
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
SHELL=/bin/bash -o pipefail
SRC = src
BUILD = build
NAME = wasmachine
DEPS = $(SRC)/genrom.v $(SRC)/$(NAME).v
VENDOR_DEPS = -y vendor/fpu/double_to_float \
-y vendor/fpu/float_to_double \
-y vendor/LEB128
IVERILOG = iverilog -g2005-sv -I $(SRC) -y $(SRC) $(VENDOR_DEPS) $(parameters)
GTKWAVE = gtkwave
VVP = vvp -N
RED=\033[0;31m
GREEN=\033[0;32m
NC=\033[0m
ECHO = echo -e
all: test $(NAME).bin
clean:
rm -rf *.bin *.txt *.blif $(BUILD) *~
update-dependencies:
git submodule update --remote
.PHONY: all clean update-dependencies
ifndef VERBOSE
.SILENT:
endif
#
# General test objectives
#
test : test/stack test/SuperStack test/genrom test/cpu
test/genrom : $(BUILD)/genrom_tb.vcd
test/stack : $(BUILD)/stack_tb.vcd
test/SuperStack: $(BUILD)/SuperStack_tb.vcd
test/% : $(BUILD)/%_tb.vcd
$(BUILD)/%_tb.vcd: $(BUILD)/%_tb
( \
cd $(BUILD) && $(VVP) ../$< | \
(grep -v -e "opened for output" \
-e "Not enough words in the file for the requested range" \
|| true) \
) \
&& $(ECHO) "$(GREEN)ok$(NC)" \
|| ($(ECHO) "$(RED)FAIL$(NC)" && exit 1)
$(BUILD)/%_tb: test/%_tb.v $(SRC)/%.v test/assert.vh
$(ECHO) -n $<"... "
mkdir -p $(@D)
$(IVERILOG) -I test $< -o $@
view/%: test/%
$(GTKWAVE) $(BUILD)/$(@F)_tb.vcd test/$(@F)_tb.gtkw
# cpu
test/cpu: test/cpu/control_flow_operators test/cpu/call_operators \
test/cpu/parametric_operators test/cpu/variable_access \
test/cpu/constants test/cpu/comparison_operators \
test/cpu/numeric_operators test/cpu/conversions \
test/cpu/reinterpretations
test/cpu/control_flow_operators: test/cpu/block test/cpu/loop test/cpu/if \
test/cpu/else test/cpu/br test/cpu/br_if \
test/cpu/br_table test/cpu/return
test/cpu/block: $(BUILD)/cpu/block_tb.vcd
test/cpu/loop: $(BUILD)/cpu/loop_tb.vcd
test/cpu/if: test/cpu/if1 test/cpu/if2
test/cpu/if1: $(BUILD)/cpu/if1_tb.vcd
test/cpu/if2: $(BUILD)/cpu/if2_tb.vcd
test/cpu/else: test/cpu/else1 test/cpu/else2
test/cpu/else1: $(BUILD)/cpu/else1_tb.vcd
test/cpu/else2: $(BUILD)/cpu/else2_tb.vcd
test/cpu/br: $(BUILD)/cpu/br_tb.vcd
test/cpu/br_if: $(BUILD)/cpu/br_if_tb.vcd
test/cpu/br_table: test/cpu/br_table1 test/cpu/br_table2 test/cpu/br_table3
test/cpu/br_table1: $(BUILD)/cpu/br_table1_tb.vcd
test/cpu/br_table2: $(BUILD)/cpu/br_table2_tb.vcd
test/cpu/br_table3: $(BUILD)/cpu/br_table3_tb.vcd
test/cpu/return: $(BUILD)/cpu/return_tb.vcd
test/cpu/call_operators: test/cpu/call
test/cpu/call : test/cpu/call1 test/cpu/call2
test/cpu/call1: $(BUILD)/cpu/call1_tb.vcd
test/cpu/call2: $(BUILD)/cpu/call2_tb.vcd
test/cpu/parametric_operators: test/cpu/drop test/cpu/select
test/cpu/drop : $(BUILD)/cpu/drop_tb.vcd
test/cpu/select : test/cpu/select1 test/cpu/select2 test/cpu/select3
test/cpu/select1: $(BUILD)/cpu/select1_tb.vcd
test/cpu/select2: $(BUILD)/cpu/select2_tb.vcd
test/cpu/select3: $(BUILD)/cpu/select3_tb.vcd
test/cpu/variable_access: test/cpu/get_local1 test/cpu/get_local2 \
test/cpu/set_local test/cpu/tee_local
test/cpu/get_local1: $(BUILD)/cpu/get_local1_tb.vcd
test/cpu/get_local2: $(BUILD)/cpu/get_local2_tb.vcd
test/cpu/set_local: $(BUILD)/cpu/set_local_tb.vcd
test/cpu/tee_local: $(BUILD)/cpu/tee_local_tb.vcd
test/cpu/constants: test/cpu/f32.const test/cpu/f64.const test/cpu/i32.const \
test/cpu/i64.const
test/cpu/f32.const: $(BUILD)/cpu/f32.const_tb.vcd
test/cpu/f64.const: $(BUILD)/cpu/f64.const_tb.vcd
test/cpu/i32.const: $(BUILD)/cpu/i32.const_tb.vcd
test/cpu/i64.const: $(BUILD)/cpu/i64.const_tb.vcd
test/cpu/comparison_operators: test/cpu/i32.eqz test/cpu/i32.eq \
test/cpu/i32.ne test/cpu/i64.eqz \
test/cpu/i64.eq test/cpu/i64.ne
test/cpu/i32.eqz : test/cpu/i32.eqz1 test/cpu/i32.eqz2
test/cpu/i32.eqz1: $(BUILD)/cpu/i32.eqz1_tb.vcd
test/cpu/i32.eqz2: $(BUILD)/cpu/i32.eqz2_tb.vcd
test/cpu/i32.eq : test/cpu/i32.eq1 test/cpu/i32.eq2
test/cpu/i32.eq1: $(BUILD)/cpu/i32.eq1_tb.vcd
test/cpu/i32.eq2: $(BUILD)/cpu/i32.eq2_tb.vcd
test/cpu/i32.ne : test/cpu/i32.ne1 test/cpu/i32.ne2
test/cpu/i32.ne1: $(BUILD)/cpu/i32.ne1_tb.vcd
test/cpu/i32.ne2: $(BUILD)/cpu/i32.ne2_tb.vcd
test/cpu/i64.eqz : test/cpu/i64.eqz1 test/cpu/i64.eqz2
test/cpu/i64.eqz1: $(BUILD)/cpu/i64.eqz1_tb.vcd
test/cpu/i64.eqz2: $(BUILD)/cpu/i64.eqz2_tb.vcd
test/cpu/i64.eq : test/cpu/i64.eq1 test/cpu/i64.eq2
test/cpu/i64.eq1: $(BUILD)/cpu/i64.eq1_tb.vcd
test/cpu/i64.eq2: $(BUILD)/cpu/i64.eq2_tb.vcd
test/cpu/i64.ne : test/cpu/i64.ne1 test/cpu/i64.ne2
test/cpu/i64.ne1: $(BUILD)/cpu/i64.ne1_tb.vcd
test/cpu/i64.ne2: $(BUILD)/cpu/i64.ne2_tb.vcd
test/cpu/numeric_operators: test/cpu/i32.add test/cpu/i32.sub test/cpu/i64.add \
test/cpu/i64.sub
test/cpu/i32.add: $(BUILD)/cpu/i32.add_tb.vcd
test/cpu/i32.sub: $(BUILD)/cpu/i32.sub_tb.vcd
test/cpu/i64.add: $(BUILD)/cpu/i64.add_tb.vcd
test/cpu/i64.sub: $(BUILD)/cpu/i64.sub_tb.vcd
test/cpu/conversions: test/cpu/f32.demote-f64
test/cpu/f32.demote-f64: $(BUILD)/cpu/f32.demote-f64_tb.vcd
test/cpu/conversions: test/cpu/i32.wrap-i64
test/cpu/i32.wrap-i64: $(BUILD)/cpu/i32.wrap-i64_tb.vcd
test/cpu/reinterpretations: test/cpu/i32.reinterpret-f32 \
test/cpu/i64.reinterpret-f64 \
test/cpu/f32.reinterpret-i32 \
test/cpu/f64.reinterpret-i64
test/cpu/i32.reinterpret-f32: $(BUILD)/cpu/i32.reinterpret-f32_tb.vcd
test/cpu/i64.reinterpret-f64: $(BUILD)/cpu/i64.reinterpret-f64_tb.vcd
test/cpu/f32.reinterpret-i32: $(BUILD)/cpu/f32.reinterpret-i32_tb.vcd
test/cpu/f64.reinterpret-i64: $(BUILD)/cpu/f64.reinterpret-i64_tb.vcd
$(BUILD)/cpu/%_tb.vcd: $(BUILD)/cpu/%_tb $(BUILD)/cpu/%.hex
( \
cd $(BUILD)/cpu && $(VVP) ../../$< | \
(grep -v -e "opened for output" \
-e "Not enough words in the file for the requested range" \
|| true) \
) \
&& $(ECHO) "$(GREEN)ok$(NC)" \
|| ($(ECHO) "$(RED)FAIL$(NC)" && exit 1)
$(BUILD)/cpu/%.hex:
mkdir -p $(@D)
cp test/cpu/$(@F) $(BUILD)/cpu
$(BUILD)/cpu/%_tb: test/cpu/%_tb.v $(SRC)/cpu.v test/assert.vh
$(ECHO) -n $<"... "
mkdir -p $(@D)
$(IVERILOG) -I test $< -o $@
view/cpu/%: test/cpu/%
$(GTKWAVE) $(BUILD)/cpu/$(@F)_tb.vcd test/cpu/cpu_tb.gtkw
# genrom
$(BUILD)/genrom_tb.vcd: $(BUILD)/genrom_tb
cp test/genrom.hex $(BUILD)
( \
cd $(BUILD) && $(VVP) ../$< | \
(grep -v -e "opened for output" \
-e "Not enough words in the file for the requested range" \
|| true) \
) \
&& $(ECHO) "$(GREEN)ok$(NC)" \
|| ($(ECHO) "$(RED)FAIL$(NC)" && exit 1)
#------------------------------
#-- Sintesis completa
#------------------------------
$(NAME).bin: resources/$(NAME).pcf $(DEPS) test/prog.list
#-- Sintesis
yosys -p "synth_ice40 -blif $(NAME).blif" $(DEPS)
#-- Place & route
arachne-pnr -d 1k -p resources/$(NAME).pcf $(NAME).blif -o $(NAME).txt
#-- Generar binario final, listo para descargar en fgpa
icepack $(NAME).txt $(NAME).bin