-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
199 lines (192 loc) · 9.77 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
###############
# DIRECTORIES #
###############
BASEDIR = $(shell pwd)
JFlex_DIR = ${BASEDIR}/jflex
CUP_DIR = ${BASEDIR}/cup
SRC_DIR = ${BASEDIR}/src
BIN_DIR = ${BASEDIR}/bin
INPUT_DIR = ${BASEDIR}/input
OUTPUT_DIR = ${BASEDIR}/output
EXTERNAL_JARS_DIR = ${BASEDIR}/external_jars
MANIFEST_DIR = ${BASEDIR}/manifest
#########
# FILES #
#########
JFlex_GENERATED_FILE = ${SRC_DIR}/Lexer.java
CUP_GENERATED_FILES = ${SRC_DIR}/Parser.java ${SRC_DIR}/TokenNames.java
JFlex_CUP_GENERATED_FILES = ${JFlex_GENERATED_FILE} ${CUP_GENERATED_FILES}
SRC_FILES = ${SRC_DIR}/*.java \
${SRC_DIR}/IR/*.java \
${SRC_DIR}/AST/*.java \
${SRC_DIR}/TEMP/*.java \
${SRC_DIR}/MIPS/*.java \
${SRC_DIR}/TYPES/*.java \
${SRC_DIR}/SYMBOL_TABLE/*.java
EXTERNAL_JAR_FILES = ${EXTERNAL_JARS_DIR}/java-cup-11b-runtime.jar
MANIFEST_FILE = ${MANIFEST_DIR}/MANIFEST.MF
########################
# DEFINITIONS :: JFlex #
########################
JFlex_PROGRAM = jflex
JFlex_FLAGS = -q
JFlex_DEST_DIR = ${SRC_DIR}
JFlex_FILE = ${JFlex_DIR}/LEX_FILE.lex
######################
# DEFINITIONS :: CUP #
######################
CUP_PROGRAM = java -jar ${EXTERNAL_JARS_DIR}/java-cup-11b.jar
CUP_FILE = ${CUP_DIR}/CUP_FILE.cup
CUP_GENERATED_PARSER_NAME = Parser
CUP_GENERATED_SYMBOLS_FILENAME = TokenNames
######################
# DEFINITIONS :: CUP #
######################
CUP_FLAGS = \
-nowarn \
-parser ${CUP_GENERATED_PARSER_NAME} \
-symbols ${CUP_GENERATED_SYMBOLS_FILENAME}
#########################
# DEFINITIONS :: PARSER #
#########################
INPUT = ${INPUT_DIR}/Input.txt
OUTPUT = ${OUTPUT_DIR}/SemanticStatus.txt
##########
# TARGET #
##########
compile:
clear
@echo "*******************************"
@echo "* *"
@echo "* *"
@echo "* [0] Remove COMPILER program *"
@echo "* *"
@echo "* *"
@echo "*******************************"
rm -rf COMPILER
@echo "\n"
@echo "************************************************************"
@echo "* *"
@echo "* *"
@echo "* [1] Remove *.class files and JFlex-CUP generated files: *"
@echo "* *"
@echo "* Lexer.java *"
@echo "* Parser.java *"
@echo "* TokenNames.java *"
@echo "* *"
@echo "************************************************************"
rm -rf ${JFlex_CUP_GENERATED_FILES} ${BIN_DIR}/*.class ${BIN_DIR}/AST/*.class
@echo "\n"
@echo "************************************************************"
@echo "* *"
@echo "* *"
@echo "* [2] Use JFlex to synthesize Lexer.java from LEX_FILE.lex *"
@echo "* *"
@echo "* *"
@echo "************************************************************"
$(JFlex_PROGRAM) ${JFlex_FLAGS} -d ${JFlex_DEST_DIR} ${JFlex_FILE}
@echo "\n"
@echo "*******************************************************************************"
@echo "* *"
@echo "* *"
@echo "* [3] Use CUP to synthesize Parser.java and TokenNames.java from CUP_FILE.cup *"
@echo "* *"
@echo "* *"
@echo "*******************************************************************************"
$(CUP_PROGRAM) ${CUP_FLAGS} -destdir ${SRC_DIR} ${CUP_FILE}
@echo "\n"
@echo "********************************************************"
@echo "* *"
@echo "* *"
@echo "* [4] Create *.class files from *.java files + CUP JAR *"
@echo "* *"
@echo "* *"
@echo "********************************************************"
javac -cp ${EXTERNAL_JAR_FILES} -d ${BIN_DIR} ${SRC_FILES}
@echo "\n"
@echo "***********************************************************"
@echo "* *"
@echo "* *"
@echo "* [5] Create a JAR file from from *.class files + CUP JAR *"
@echo "* *"
@echo "* *"
@echo "***********************************************************"
jar cfm COMPILER ${MANIFEST_FILE} -C ${BIN_DIR} .
everything:
clear
@echo "******************************"
@echo "* *"
@echo "* *"
@echo "* [0] Remove COMPIER program *"
@echo "* *"
@echo "* *"
@echo "******************************"
rm -rf COMPILER
@echo "\n"
@echo "************************************************************"
@echo "* *"
@echo "* *"
@echo "* [1] Remove *.class files and JFlex-CUP generated files: *"
@echo "* *"
@echo "* Lexer.java *"
@echo "* Parser.java *"
@echo "* TokenNames.java *"
@echo "* *"
@echo "************************************************************"
rm -rf ${JFlex_CUP_GENERATED_FILES} ${BIN_DIR}/*.class ${BIN_DIR}/AST/*.class
@echo "\n"
@echo "************************************************************"
@echo "* *"
@echo "* *"
@echo "* [2] Use JFlex to synthesize Lexer.java from LEX_FILE.lex *"
@echo "* *"
@echo "* *"
@echo "************************************************************"
$(JFlex_PROGRAM) ${JFlex_FLAGS} -d ${JFlex_DEST_DIR} ${JFlex_FILE}
@echo "\n"
@echo "*******************************************************************************"
@echo "* *"
@echo "* *"
@echo "* [3] Use CUP to synthesize Parser.java and TokenNames.java from CUP_FILE.cup *"
@echo "* *"
@echo "* *"
@echo "*******************************************************************************"
$(CUP_PROGRAM) ${CUP_FLAGS} -destdir ${SRC_DIR} ${CUP_FILE}
@echo "\n"
@echo "********************************************************"
@echo "* *"
@echo "* *"
@echo "* [4] Create *.class files from *.java files + CUP JAR *"
@echo "* *"
@echo "* *"
@echo "********************************************************"
javac -cp ${EXTERNAL_JAR_FILES} -d ${BIN_DIR} ${SRC_FILES}
@echo "\n"
@echo "***********************************************************"
@echo "* *"
@echo "* *"
@echo "* [5] Create a JAR file from from *.class files + CUP JAR *"
@echo "* *"
@echo "* *"
@echo "***********************************************************"
jar cfm COMPILER ${MANIFEST_FILE} -C ${BIN_DIR} .
@echo "\n"
@echo "*****************************"
@echo "* *"
@echo "* *"
@echo "* [6] Run resulting program *"
@echo "* *"
@echo "* *"
@echo "*****************************"
java -jar COMPILER ${INPUT} ${OUTPUT}
@echo "\n"
@echo "***********************************************************"
@echo "* *"
@echo "* *"
@echo "* [10] Allocate registers (just for this running example) *"
@echo "* *"
@echo "* *"
@echo "***********************************************************"
@echo "\n"
# [11] Run spim and redirect its output (un-comment after codegen + register allocation is implemented)
spim -f ${OUTPUT_DIR}/MIPS.txt > ${OUTPUT_DIR}/MIPS_OUTPUT.txt