-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathnobuild.c
More file actions
93 lines (76 loc) · 2.72 KB
/
nobuild.c
File metadata and controls
93 lines (76 loc) · 2.72 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
#include <stdbool.h>
#define NOBUILD_IMPLEMENTATION
#include "../nobuild.h"
#include "../nobuild.global.h"
#define CFLAGS COMMON_FLAGS
#define INCLUDES INCLUDE_FLAG(PATH("..", "common")), \
INCLUDE_FLAG(PATH("..", "bm", "src"))
#define COMMON_UNITS PATH("..", "common", "sv.c"), \
PATH("..", "common", "arena.c"), \
PATH("..", "common", "path.c")
#define BM_UNITS PATH("..", "bm", "src", "types.c"), \
PATH("..", "bm", "src", "bm.c")
#define BASM_UNITS PATH("src", "compiler.c"), \
PATH("src", "expr.c"), \
PATH("src", "fl.c"), \
PATH("src", "gas_arm64.c"), \
PATH("src", "linizer.c"), \
PATH("src", "nasm_sysv_x86_64.c"), \
PATH("src", "statement.c"), \
PATH("src", "target.c"), \
PATH("src", "tokenizer.c"), \
PATH("src", "verifier.c")
#define UNITS COMMON_UNITS, BM_UNITS, BASM_UNITS
#define LIBS "-lm"
void build_all_bins(void)
{
MKDIRS("bin");
CC("bin", "basm", PATH("src", "basm.c"));
CC("bin", "basm2dot", PATH("src", "basm2dot.c"));
CC("bin", "expr2dot", PATH("src", "expr2dot.c"));
}
void basm_test(bool record)
{
build_all_bins();
#ifdef _WIN32
const char *bmr_path = PATH("..", "bm", "bin", "bmr.exe");
#else
const char *bmr_path = PATH("..", "bm", "bin", "bmr");
#endif
if (!PATH_EXISTS(bmr_path)) {
PANIC("Could not find `%s` please go to the bm subproject and build it",
bmr_path);
}
MKDIRS("bin", "test", "cases");
FOREACH_FILE_IN_DIR(example, PATH("test", "cases"), {
if (ENDS_WITH(example, ".basm"))
{
const char *expected_output_path = PATH("test", "outputs", CONCAT(NOEXT(example), ".expected.out"));
const char *bm_path = PATH("bin", "test", "cases", CONCAT(NOEXT(example), ".bm"));
CMD(PATH("bin", "basm"),
"-I", PATH("lib"),
"-o", bm_path,
PATH("test", "cases", example));
CMD(bmr_path,
"-p", bm_path,
record ? "-ao" : "-eo", expected_output_path);
}
});
}
int main(int argc, char **argv)
{
if (argc >= 2) {
if (strcmp(argv[1], "test") == 0) {
basm_test(false);
} else if (strcmp(argv[1], "record") == 0) {
basm_test(true);
} else if (strcmp(argv[1], "help") == 0) {
PANIC("TODO(#461): help subcommand for basm subproject is not implemented");
} else {
PANIC("unknown subcommand `%s`", argv[1]);
}
} else {
build_all_bins();
}
return 0;
}