forked from pretis/flexpret
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
162 lines (123 loc) · 5.63 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
# Makefile for FlexPRET processor
# Set configuration in config.mk or pass variable assignments as arguments.
#
# Usage:
# make run: Compile programs located at $(PROG_DIR)/$(PROGS) with
# $(PROG_CONFIG) configuration, then execute on target specified by $(TARGET)
# (either emulator or fpga) FlexPRET core with $(CORE_CONFIG) configuration.
#
# Optional Usage:
# make emulator: Generate and compile C++ emulator for FlexPRET core with
# $(CORE_CONFIG) configuration.
# make fpga: ---
# make all: Same as make $(TARGET)
#
# Michael Zimmer (mzimmer@eecs.berkeley.edu)
# -----------------------------------------------------------------------------
# Standard directory/file locations and naming.
# -----------------------------------------------------------------------------
# Source code location, where subdirectories contain either Chisel
# (used for generating Verilog and C++ emulator) or Verilog code.
SRC_DIR = src
MODULE = Core
# C++ emulator location, where subdirectories contain testbenches, generated C++,
# and build files.
EMULATOR_DIR = emulator
# C or ASM test location, where subdirectories contain sets of tests with
# identical compilation configurations.
TESTS_DIR = tests
# FPGA
FPGA_DIR = fpga
# Simple build tool location, used for generating both C++ and Verilog from
# Chisel source code.
SBT_DIR = sbt
SBT_TO_BASE = ..
SBT = java -Xmx1024M -Xss8M -XX:MaxPermSize=128M -jar sbt-launch.jar
# Compiler options.
CXX = g++
CXXFLAGS = -g -O2
# -----------------------------------------------------------------------------
# Core and target configuration
# -----------------------------------------------------------------------------
# Default configuration of core, programs, and target.
# Override by modifying config.mk or pass varaible assignment as argument.
# See file for description of variables.
include config.mk
# Construct core configuration string (used for directory naming).
# Note: '?=' not used so string is only constructed once.
CORE_CONFIG := $(THREADS)t$(if $(findstring true, $(FLEX)),f)-$(ISPM_KBYTES)i-$(DSPM_KBYTES)d-$(MUL_STAGES)smul$(if $(findstring true, $(STATS)),-stats)$(if $(findstring true, $(EXCEPTIONS)),-exc)$(if $(findstring true, $(GET_TIME)),-gt)$(if $(findstring true, $(DELAY_UNTIL)),-du)$(if $(findstring true, $(EXCEPTION_ON_EXPIRE)),-ee)
# Default will build target and selected programs.
all: $(TARGET)
# -----------------------------------------------------------------------------
# C++ emulator generation and compilation.
# -----------------------------------------------------------------------------
# C++ emulator generation, build, executable locations.
EMULATOR_SRC_DIR = $(EMULATOR_DIR)/generated-src/$(CORE_CONFIG)
EMULATOR_BUILD_DIR = $(EMULATOR_DIR)/build/$(CORE_CONFIG)
EMULATOR = $(EMULATOR_BUILD_DIR)/$(MODULE)
# Must provide rules for generating and compiling C++ emulator $(EMULATOR)
include $(EMULATOR_DIR)/emulator.mk
emulator: $(EMULATOR)
# -----------------------------------------------------------------------------
# FPGA
# -----------------------------------------------------------------------------
# FPGA Verilog generation
FPGA_SRC_DIR = $(FPGA_DIR)/generated-src/$(CORE_CONFIG)
VERILOG = $(FPGA_SRC_DIR)/$(MODULE).v
# Must provide rules for generating verilog file $(VERILOG)
include $(FPGA_DIR)/fpga.mk
fpga: $(VERILOG)
# -----------------------------------------------------------------------------
# Program compilation.
# -----------------------------------------------------------------------------
# Program source code and build locations.
PROG_CONFIG ?= $(TARGET)
PROG_SRC_DIR = $(TESTS_DIR)/$(PROG_DIR)
PROG_BUILD_DIR = $(TESTS_DIR)/$(PROG_DIR)/build/$(PROG_CONFIG)
PROG_RESULTS_DIR = $(TESTS_DIR)/$(PROG_DIR)/results/$(PROG_CONFIG)/$(CORE_CONFIG)
# Default rules and templates for compilation of programs.
#include $(TESTS_DIR)/tests.mk
# Define what programs in selected directory will be compiled and their
# configuration.
# Must provide rules for generating .inst.mem and .data.mem files
include $(TESTS_DIR)/$(PROG_DIR)/test.mk
prog: $(PROG:%=$(PROG_BUILD_DIR)/%.inst.mem) $(PROG:%=$(PROG_BUILD_DIR)/%.data.mem)
# -----------------------------------------------------------------------------
# Running programs on targets.
# -----------------------------------------------------------------------------
ifeq ($(TARGET),emulator)
# TODO: force STATS=true?
# TODO: debug?
#MAX_CYCLES ?= 20000000
MAX_CYCLES ?= 200000
ifeq ($(DEBUG), true)
CONFIG = $(CORE_CONFIG)-debug
SBT_ARGS = --debug --vcd
SIM_DEBUG = --vcd=$(@:%.out=%.vcd)
else
CONFIG = $(CORE_CONFIG)
endif
$(PROG:%=$(PROG_RESULTS_DIR)/%.out): $(PROG_RESULTS_DIR)/%.out: $(PROG_BUILD_DIR)/%.inst.mem $(PROG_BUILD_DIR)/%.data.mem $(EMULATOR)
mkdir -p $(PROG_RESULTS_DIR)
./$(EMULATOR) --maxcycles=$(MAX_CYCLES) --ispm=$(PROG_BUILD_DIR)/$*.inst.mem --dspm=$(PROG_BUILD_DIR)/$*.data.mem --vcd=$(@:.out=.vcd) > $@ 2>&1
echo $@ $^
# Possible targets are emulator and fpga.
run: $(PROG:%=$(PROG_RESULTS_DIR)/%.out)
@echo; perl -ne 'print " [$$1] $$ARGV \t$$2\n" if /\*{3}(.{8})\*{3}(.*)/' \
$^; echo;
CLEAN_TARGET = $(EMULATOR_SRC_DIR) $(EMULATOR_BUILD_DIR) $(PROG_RESULTS_DIR)
endif
# -----------------------------------------------------------------------------
# Cleanup
# -----------------------------------------------------------------------------
clean:
rm -rf $(CLEAN_TARGET)
#rm -rf $(PROG_BUILD_DIR) $(CLEAN_TARGET)
# Clean for all configurations and targets.
cleanall:
rm -rf $(EMULATOR_DIR)/generated-src
rm -rf $(EMULATOR_DIR)/build
rm -rf $(FGPA_DIR)/generated-src
find $(TESTS_DIR) -type d -name "results" -exec rm -rf {} \;
#find $(TESTS_DIR) -type d -name "build" -exec rm -rf {} \;
.PHONY: run emulator fpga prog clean cleanall