stage1 实现部分ast2ir内容并重构stage0 引入并重构ir2vm 构建系统修改部分
This commit is contained in:
1 parent
3d57260f3f
commit
34df303b56
17 files changed
+636
-1800
No files matched your search
@@ -1,52 +1,28 @@
|
||||
#undef UNICODE
|
||||
#define NOB_IMPLEMENTATION
|
||||
// Redefine nob_cc_flags() to carry the project's debug flags. Keep in sync
|
||||
// with CFLAGS_STR below.
|
||||
|
||||
#define SPL_CFLAGS "-Wall", "-Wextra", "-O0", "-g", "-D_CRT_SECURE_NO_WARNINGS"
|
||||
#define nob_cc_flags(cmd) nob_cmd_append(cmd, SPL_CFLAGS)
|
||||
#include "nob.h"
|
||||
#ifdef _WIN32
|
||||
#include <consoleapi2.h>
|
||||
#endif
|
||||
|
||||
// C-side bootstrap build script. Builds the stage0 VM tools and the splc0
|
||||
// compiler from their C sources. The SPL self-hosting chain (splc1, ...) is
|
||||
// out of scope and is driven by a different mechanism.
|
||||
//
|
||||
// Usage:
|
||||
// cc -o nob nob.c # bootstrap once
|
||||
// ./nob # build all targets
|
||||
// ./nob build <targets...> # build specific targets
|
||||
// ./nob run <target> [..] # build and run
|
||||
// ./nob test # build and run VM unit tests
|
||||
// ./nob clean # remove build artifacts
|
||||
// ./nob list # list all targets
|
||||
// ./nob help # print this help
|
||||
|
||||
#define BUILD_FOLDER "build/"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define EXE_SUFFIX ".exe"
|
||||
#else
|
||||
#define EXE_SUFFIX ""
|
||||
#endif
|
||||
|
||||
// Content of the .cflags stamp file; must match SPL_CFLAGS above.
|
||||
#define CFLAGS_STR "-Wall -Wextra -O0 -g"
|
||||
// Stamp file whose mtime is refreshed whenever the flags change so that all
|
||||
// object files get rebuilt.
|
||||
static const char *CFLAGS_STAMP = BUILD_FOLDER ".cflags";
|
||||
|
||||
// Target descriptions
|
||||
#define VM_SRCS "stage0/spl_mcode.c", "stage0/spl_syscall.c", "stage0/spl_vm.c"
|
||||
#define SPLC0_PART_SRCS \
|
||||
"stage1/spl_ast.c", "stage1/spl_lexer.c", "stage1/spl_dumptree.c", "stage1/spl_type.c", \
|
||||
"stage1/spl_sema.c", "stage1/spl_ir.c", "stage1/spl_ast2ir.c"
|
||||
|
||||
static const char *spl_cli_srcs[] = {"stage0/spl_cli.c", VM_SRCS};
|
||||
static const char *splc0_srcs[] = {"stage1/splc0.c", VM_SRCS, SPLC0_PART_SRCS};
|
||||
static const char *test_srcs[] = {"stage0/test_spl_vm.c", VM_SRCS};
|
||||
static const char *spl_disasm_srcs[] = {"stage0/spl_disasm.c", VM_SRCS};
|
||||
static const char *splc0_srcs[] = {
|
||||
"stage1/splc0.c", "stage0/spl_mcode.c", "stage1/spl_ast.c", "stage1/spl_lexer.c",
|
||||
"stage1/spl_dumptree.c", "stage1/spl_type.c", "stage1/spl_sema.c", "stage1/spl_ir.c",
|
||||
"stage1/spl_ast2ir.c", "stage1/spl_ir2vm.c",
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
@@ -56,9 +32,8 @@ typedef struct {
|
||||
|
||||
static Exe_Target exe_targets[] = {
|
||||
{"spl_cli", spl_cli_srcs, NOB_ARRAY_LEN(spl_cli_srcs)},
|
||||
{"splc0", splc0_srcs, NOB_ARRAY_LEN(splc0_srcs)},
|
||||
{"test", test_srcs, NOB_ARRAY_LEN(test_srcs)},
|
||||
{"spl_disasm", spl_disasm_srcs, NOB_ARRAY_LEN(spl_disasm_srcs)},
|
||||
{"splc0", splc0_srcs, NOB_ARRAY_LEN(splc0_srcs)},
|
||||
};
|
||||
|
||||
static const Exe_Target *find_exe_target(const char *name) {
|
||||
@@ -84,10 +59,6 @@ static const char *obj_path(const char *src) {
|
||||
return out;
|
||||
}
|
||||
|
||||
static const char *exe_path(const char *name) {
|
||||
return nob_temp_sprintf(BUILD_FOLDER "%s" EXE_SUFFIX, name);
|
||||
}
|
||||
|
||||
static bool sync_cflags_stamp(void) {
|
||||
Nob_String_View cflags = nob_sv_from_cstr(CFLAGS_STR);
|
||||
Nob_String_Builder old = {0};
|
||||
@@ -135,7 +106,7 @@ static bool build_object(const char *src) {
|
||||
}
|
||||
|
||||
static bool link_exe(const Exe_Target *target) {
|
||||
const char *exe = exe_path(target->name);
|
||||
const char *exe = nob_temp_sprintf(BUILD_FOLDER "%s", target->name);
|
||||
const char **objs = (const char **)nob_temp_alloc(sizeof(const char *) * target->srcs_count);
|
||||
for (size_t i = 0; i < target->srcs_count; ++i) {
|
||||
objs[i] = obj_path(target->srcs[i]);
|
||||
@@ -246,7 +217,7 @@ int main(int argc, char **argv) {
|
||||
if (!build_target(target_name))
|
||||
return 1;
|
||||
Nob_Cmd cmd = {0};
|
||||
nob_cmd_append(&cmd, exe_path(target_name));
|
||||
nob_cmd_append(&cmd, nob_temp_sprintf(BUILD_FOLDER "%s", target_name));
|
||||
while (argc > 0) {
|
||||
nob_cmd_append(&cmd, nob_shift(argv, argc));
|
||||
}
|
||||
@@ -259,7 +230,7 @@ int main(int argc, char **argv) {
|
||||
if (!build_target("test"))
|
||||
return 1;
|
||||
Nob_Cmd cmd = {0};
|
||||
nob_cmd_append(&cmd, exe_path("test"));
|
||||
nob_cmd_append(&cmd, BUILD_FOLDER "test");
|
||||
return nob_cmd_run(&cmd) ? 0 : 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user