-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.lua
186 lines (167 loc) · 5.18 KB
/
build.lua
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
#!/usr/bin/env lua
COMMON_FLAGS = '-collection:disasm=src'
DISASM_CLI_SRC_PATH = 'src/disasm-cli'
TABLE_GEN_SRC_PATH = 'src/table-gen'
TABLE_INSPECT_SRC_PATH = 'src/table-inspect'
TABLE_CHECK_SRC_PATH = 'src/table-check'
TABLE_PATH = './tables/encodings.txt'
function table.slice(tbl, first, last, step)
local sliced = {}
for i = first or 1, last or #tbl, step or 1 do
sliced[#sliced+1] = tbl[i]
end
return sliced
end
function is_windows()
return package.config:sub(1,1) == '\\'
end
function run_command(command)
print('> ' .. command)
local ok = os.execute(command)
if not ok then
print("!!! command failed")
os.exit(1)
end
end
function odin_build(out, dir, options)
if is_windows() then
out = out .. '.exe'
end
run_command("odin build " .. dir .. " -out:"..out .. ' ' .. COMMON_FLAGS .. ' ' .. options)
end
function assemble(file)
local in_file = 'test/asm/' .. file .. '.asm'
local out_file = 'tmp/bin/' .. file
run_command('nasm ' .. in_file .. ' -o '..out_file)
end
function build_disasm(flags)
flags = flags .. ' -define:X86_USE_STUB=false'
return odin_build('x86-disasm', DISASM_CLI_SRC_PATH, flags)
end
function run_disasm(file, options)
local disasm_path
if is_windows() then
disasm_path = 'x86-disasm'
else
disasm_path = './x86-disasm'
end
run_command(disasm_path .. " " .. file .. ' ' .. options)
end
function build_tablegen(options)
return odin_build('table-gen', TABLE_GEN_SRC_PATH, options)
end
function run_tablegen(table, options)
local tablegen_path
if is_windows() then
tablegen_path = 'table-gen'
else
tablegen_path = './table-gen'
end
run_command(tablegen_path .. ' ' .. table .. ' src/disasm/table_gen.odin ' .. options)
end
function build_table_inspect(options)
return odin_build('table-inspect', TABLE_INSPECT_SRC_PATH, options)
end
function run_table_inspect(table, options)
local tablegen_path
if is_windows() then
tablegen_path = 'table-inspect'
else
tablegen_path = './table-inspect'
end
run_command(tablegen_path .. ' ' .. table .. options)
end
function build_table_check(options)
return odin_build('table-check', TABLE_CHECK_SRC_PATH, options)
end
function run_table_check(table)
local table_check_path
if is_windows() then
table_check_path = 'table-check'
else
table_check_path = './table-check'
end
run_command(table_check_path .. ' ' .. table)
end
-------------------------------------------------------------------------------
local command = 'build'
local build_mode = 'debug'
if #arg == 0 then
print('No arguments specified.')
print('Assuming `./build.lua build -debug`')
else
command = arg[1]
end
if command == 'build' then
for i, flag in pairs(table.slice(arg, 2, #arg)) do
if flag == '-release' then
build_mode = 'release'
elseif flag == '-debug' then
build_mode = 'debug'
end
end
local odin_flags = ''
if build_mode == 'release' then
odin_flags = odin_flags .. ' -o:aggressive -no-bounds-check'
else
odin_flags = odin_flags .. ' -debug'
end
build_tablegen(odin_flags)
run_tablegen(TABLE_PATH, '')
build_disasm(odin_flags)
elseif command == 'test' then
local odin_flags = ''
odin_flags = odin_flags .. ' -debug'
build_tablegen(odin_flags)
run_tablegen(TABLE_PATH, '')
build_disasm(odin_flags)
assemble('mov16')
run_disasm('tmp/bin/mov16', '-cpu:16')
elseif command == 'test-inst' then
local odin_flags = ''
odin_flags = odin_flags .. ' -debug'
build_tablegen(odin_flags)
run_tablegen(TABLE_PATH, '')
build_disasm(odin_flags)
assemble('inst')
run_disasm('tmp/bin/inst', '-cpu:16')
elseif command == 'inspect' then
build_table_inspect('-debug')
local tablegen_flags = ''
for i, flag in pairs(table.slice(arg, 2, #arg)) do
tablegen_flags = tablegen_flags .. ' ' .. flag
end
run_table_inspect(TABLE_PATH, tablegen_flags)
elseif command == 'inspect-inst' then
build_table_inspect('-debug')
local tablegen_flags = ''
for i, flag in pairs(table.slice(arg, 2, #arg)) do
tablegen_flags = tablegen_flags .. ' ' .. flag
end
run_table_inspect('./tables/entry.txt', tablegen_flags)
elseif command == 'test-table' then
local odin_flags = ''
odin_flags = odin_flags .. ' -debug'
build_table_check(odin_flags)
run_table_check(TABLE_PATH, '')
elseif command == 'build-test-nasm' then
local odin_flags = ''
odin_flags = odin_flags .. ' -debug'
build_tablegen(odin_flags)
run_tablegen(TABLE_PATH, '')
odin_build('test-nasm', 'test/nasm-test', ' -define:X86_USE_STUB=false -debug')
elseif command == 'test-nasm' then
local odin_flags = ''
odin_flags = odin_flags .. ' -debug'
build_tablegen(odin_flags)
run_tablegen(TABLE_PATH, '')
odin_build('test-nasm', 'test/nasm-test', ' -define:X86_USE_STUB=false -debug')
local path = 'test-nasm'
if not is_windows() then
path = './test-nasm'
end
run_command(path .. ' ' .. arg[2])
else
print('== INVALID COMMAND: "' .. command .. '"')
end
print('== DONE == ')