Repository navigation
Expand file tree
/
Copy pathxmake.lua
More file actions
303 lines (273 loc) · 10.6 KB
/
Copy pathxmake.lua
File metadata and controls
303 lines (273 loc) · 10.6 KB
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
set_project("Compiler")
set_version("0.1.0")
set_xmakever("2.8.0")
set_languages("c++17")
set_warnings("all")
add_cxxflags("-Wall", "-Wextra")
if is_mode("debug") then
add_cxxflags("-g", "-O0", "-DA_OUT_DEBUG", "-fno-limit-debug-info")
add_defines("A_OUT_DEBUG")
set_symbols("debug")
set_optimize("none")
elseif is_mode("release") then
add_cxxflags("-O3", "-DNDEBUG")
set_symbols("hidden")
set_optimize("fastest")
end
set_policy("build.ccache", true)
set_policy("build.warning", true)
add_rules("plugin.compile_commands.autoupdate", {outputdir = "."})
includes("modules/midend/xmake.lua")
includes("modules/riscv64/xmake.lua")
includes("modules/frontend/xmake.lua")
target("compiler")
set_kind("binary")
set_targetdir("$(builddir)")
add_files("src/*.cpp")
-- add_includedirs("include")
add_deps("riscv64", "midend", "frontend")
add_rpathdirs("@loader_path", "@loader_path/lib")
function resolve(path)
if path.is_absolute(path) then
return path
else
return path.join(os.workingdir(), path)
end
end
task("update-submodules")
on_run(function()
import("core.project.project")
local projectdir = project.directory()
os.cd(projectdir)
cprint("${bright blue}Updating submodules to latest commits...")
os.exec("git submodule update --init --recursive")
local submodules = {
{path = "modules/midend", branch = "main"},
{path = "modules/riscv64", branch = "master"},
{path = "modules/frontend", branch = "main"}
}
for _, submodule in ipairs(submodules) do
cprint("${bright yellow}Updating %s...", submodule.path)
os.cd(path.join(projectdir, submodule.path))
os.exec("git checkout %s", submodule.branch)
os.exec("git pull origin %s", submodule.branch)
end
os.cd(projectdir)
cprint("${color.success}All submodules updated successfully!")
end)
set_menu {
usage = "xmake update-submodules",
description = "Update all submodules to their latest commits"
}
task("format")
set_menu {
usage = "xmake format",
description = "Check code formatting with clang-format",
options = {
{'c', "check", "k", false, "Run clang-format in dry-run mode to check formatting without making changes."},
}
}
on_run(function ()
import("lib.detect.find_tool")
import("core.base.option")
local clang_format = find_tool("clang-format-15") or find_tool("clang-format")
if not clang_format then
raise("clang-format-15 or clang-format is required for formatting")
end
local cmd = "find . -name '*.cpp' -o -name '*.h' | grep -v build | grep -v googletest | grep -v modules | grep -v _deps | xargs " .. clang_format.program
if option.get("check") then
cmd = cmd .. " --dry-run --Werror"
else
cmd = cmd .. " -i"
end
local ok, outdata, errdata = os.iorunv("sh", {"-c", cmd})
if not ok then
cprint("${red}Code formatting check failed:")
if errdata and #errdata > 0 then
print(errdata)
end
os.exit(1)
else
cprint("${green}All files are properly formatted!")
end
end)
task("test")
set_menu {
usage = "xmake test",
description = "Run tests",
options = {
{'t', "target", "v", nil, "测试目标(.sy 文件或测试用例目录)"},
{'o', "optimization", "kv", "0", "优化级别(0 或 1)"},
{'p', "pipeline", "kv", nil, "优化 Pipeline"},
{'s', "hidden", "k", nil, "关闭标准输出"}
}
}
on_run(function ()
import("core.project.project")
import("core.base.task")
import("lib.detect.find_tool")
import("core.base.option")
import("devel.git")
local python3 = find_tool("python3")
if not python3 then
raise("Python3 is required to run tests")
end
task.run("build", {target = "compiler"})
local target = project.target("compiler")
local target_executable = path.absolute(target:targetfile())
local test_script_dir = path.join(target:targetdir(), "test_script")
if not os.isdir(test_script_dir) then
cprint("${blue}test_script not found, cloning from repository...")
git.clone("https://github.com/BUPT-a-out/test-script.git", {outputdir = test_script_dir, branch = "master"})
end
local test_script = path.join(test_script_dir, "test.py")
local test_target = option.get("target")
if test_target == nil then
raise("Please specify a test target")
end
local level = option.get("optimization") or "0"
local pipeline = option.get("pipeline")
if pipeline ~= nil then
pipeline = " -p " .. pipeline
else
pipeline = ""
end
local hidden = option.get("hidden")
if hidden then
hidden = " --no-stdout "
else
hidden = ""
end
if not path.is_absolute(test_target) then
test_target = path.join(os.workingdir(), test_target)
end
local command = python3.program .. " " .. test_script .. " run " .. hidden .. test_target .. " -- " .. target_executable .. " -S -O" .. level .. pipeline
print("Running test command: " .. command)
os.exec(command)
end)
task("debug")
set_menu {
usage = "xmake debug",
description = "Debug a test target",
options = {
{'t', "target", "v", nil, "测试目标(.sy 文件或测试用例目录)"},
{'o', "optimization", "kv", "0", "优化级别(0 或 1)"},
{'p', "pipeline", "kv", nil, "优化 Pipeline"}
}
}
on_run(function ()
import("core.project.project")
import("core.base.task")
import("lib.detect.find_tool")
import("core.base.option")
import("devel.git")
local python3 = find_tool("python3")
if not python3 then
raise("Python3 is required to run tests")
end
task.run("build", {target = "compiler"})
local target = project.target("compiler")
local target_executable = path.absolute(target:targetfile())
local test_script_dir = path.join(target:targetdir(), "test_script")
if not os.isdir(test_script_dir) then
cprint("${blue}test_script not found, cloning from repository...")
git.clone("https://github.com/BUPT-a-out/test-script.git", {outputdir = test_script_dir, branch = "master"})
end
local test_script = path.join(test_script_dir, "test.py")
local test_target = option.get("target")
if test_target == nil then
raise("Please specify a test target")
end
local level = option.get("optimization") or "0"
local pipeline = option.get("pipeline")
if pipeline ~= nil then
pipeline = " -p " .. pipeline
else
pipeline = ""
end
local command = python3.program .. " " .. test_script .. " debug " .. path.join(os.workingdir(), test_target) .. " -- " .. target_executable .. " -S -O" .. level .. pipeline
print("Running test command: " .. command)
os.exec(command)
end)
task("gen")
set_menu {
usage = "xmake gen",
description = "Generate assembly code for a test target",
options = {
{'t', "target", "v", nil, "测试目标(.sy 文件)"},
{'o', "optimization", "kv", "0", "优化级别(0 或 1)"},
{'s', "save", "kv", nil, "保存汇编结果到指定文件"},
{'p', "pipeline", "kv", nil, "优化 Pipeline"},
{'i', "ir", "k", nil, "生成 IR 输出"}
}
}
on_run(function ()
import("core.project.project")
import("core.base.task")
import("lib.detect.find_tool")
import("core.base.option")
import("devel.git")
task.run("build", {target = "compiler"})
local target = project.target("compiler")
local target_executable = path.absolute(target:targetfile())
local test_target = option.get("target")
if test_target == nil then
raise("Please specify a test target")
end
local level = option.get("optimization") or "0"
local pipeline = option.get("pipeline")
if pipeline ~= nil then
pipeline = " -p " .. pipeline
else
pipeline = ""
end
local save_file = option.get("save")
if save_file then
save_file = " -o " .. save_file
else
save_file = ""
end
local output = " -S "
if option.get("ir") then
output = " --emit-ir "
end
if not path.is_absolute(test_target) then
test_target = path.join(os.workingdir(), test_target)
end
local command = target_executable .. " " .. test_target .. output .. "-O" .. level .. pipeline .. save_file
print("Running test command: " .. command)
os.exec(command, {stdin=stdin})
end)
task("clang")
set_menu {
usage = "xmake clang",
description = "Run test with clang",
options = {
{'t', "target", "v", nil, "测试目标(.sy 文件或测试用例目录)"}
}
}
on_run(function ()
import("core.project.project")
import("core.base.task")
import("lib.detect.find_tool")
import("core.base.option")
import("devel.git")
local python3 = find_tool("python3")
if not python3 then
raise("Python3 is required to run tests")
end
local target = project.target("compiler")
local test_script_dir = path.join(target:targetdir(), "test_script")
if not os.isdir(test_script_dir) then
cprint("${blue}test_script not found, cloning from repository...")
git.clone("https://github.com/BUPT-a-out/test-script.git", {outputdir = test_script_dir, branch = "master"})
end
local test_script = path.join(test_script_dir, "test.py")
local test_target = option.get("target")
if test_target == nil then
raise("Please specify a test target")
end
local command = python3.program .. " " .. path.join(os.workingdir(), test_target) .. " clang " .. test_target
print("Running test command: " .. command)
os.exec(command)
end)