fix asm deps
This commit is contained in:
parent
5b9f4c65dd
commit
6b0e1654f6
@ -1,14 +1,15 @@
|
|||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT boot.bin
|
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/boot.bin
|
||||||
DEPENDS asm ${PROJECT_SOURCE_DIR}/boot/boot.vc6asm
|
DEPENDS asm ${CMAKE_CURRENT_SOURCE_DIR}/boot.vc6asm
|
||||||
COMMAND asm ${PROJECT_SOURCE_DIR}/boot/boot.vc6asm -o boot.bin
|
COMMAND asm ${CMAKE_CURRENT_SOURCE_DIR}/boot.vc6asm -o ${CMAKE_CURRENT_BINARY_DIR}/boot.bin -M
|
||||||
|
DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/boot.bin.d
|
||||||
VERBATIM
|
VERBATIM
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target(
|
add_custom_target(
|
||||||
build-boot.bin
|
boot.bin.target
|
||||||
ALL
|
ALL
|
||||||
DEPENDS boot.bin
|
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/boot.bin
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
63
src/asm.c
63
src/asm.c
@ -186,6 +186,21 @@ void *map_get(Map *m, const char *key)
|
|||||||
return found ? found->val : nullptr;
|
return found ? found->val : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t map_size(const Map *m)
|
||||||
|
{
|
||||||
|
return m->entries_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *map_key_at(const Map *m, size_t i)
|
||||||
|
{
|
||||||
|
return m->entries[i].key;
|
||||||
|
}
|
||||||
|
|
||||||
|
void *map_val_at(Map *m, size_t i)
|
||||||
|
{
|
||||||
|
return m->entries[i].val;
|
||||||
|
}
|
||||||
|
|
||||||
static char *alloc_sprintf(const char *format, ...)
|
static char *alloc_sprintf(const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list va0;
|
va_list va0;
|
||||||
@ -655,6 +670,8 @@ typedef struct {
|
|||||||
int expan_ids;
|
int expan_ids;
|
||||||
ARRAY_FIELD(Tok, tok_stack);
|
ARRAY_FIELD(Tok, tok_stack);
|
||||||
Map guard_set;
|
Map guard_set;
|
||||||
|
Map dep_str_map;
|
||||||
|
FILE *dep_file;
|
||||||
int directive_depth;
|
int directive_depth;
|
||||||
bool second_pass;
|
bool second_pass;
|
||||||
bool print;
|
bool print;
|
||||||
@ -680,13 +697,17 @@ void assembler_init(Assembler *a, Lexer *lexer)
|
|||||||
.expan_ids = 0,
|
.expan_ids = 0,
|
||||||
ARRAY_FIELD_INIT(tok_stack),
|
ARRAY_FIELD_INIT(tok_stack),
|
||||||
.guard_set = { },
|
.guard_set = { },
|
||||||
|
.dep_str_map = { },
|
||||||
|
.dep_file = nullptr,
|
||||||
.directive_depth = 0,
|
.directive_depth = 0,
|
||||||
.second_pass = false,
|
.second_pass = false,
|
||||||
|
.print = false,
|
||||||
};
|
};
|
||||||
|
|
||||||
map_init(&a->syms, sizeof(Sym));
|
map_init(&a->syms, sizeof(Sym));
|
||||||
map_init(&a->macro_map, sizeof(size_t));
|
map_init(&a->macro_map, sizeof(size_t));
|
||||||
map_init(&a->guard_set, sizeof(int));
|
map_init(&a->guard_set, sizeof(int));
|
||||||
|
map_init(&a->dep_str_map, sizeof(char *));
|
||||||
}
|
}
|
||||||
|
|
||||||
void assembler_rewind(Assembler *a)
|
void assembler_rewind(Assembler *a)
|
||||||
@ -732,6 +753,9 @@ void assembler_destroy(Assembler *a)
|
|||||||
if (a->tok_stack)
|
if (a->tok_stack)
|
||||||
free(a->tok_stack);
|
free(a->tok_stack);
|
||||||
map_destroy(&a->guard_set);
|
map_destroy(&a->guard_set);
|
||||||
|
for (size_t i = 0; i < map_size(&a->dep_str_map); ++i)
|
||||||
|
free(*(char **)map_val_at(&a->dep_str_map, i));
|
||||||
|
map_destroy(&a->dep_str_map);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Lexer *a_lexer(Assembler *a)
|
static Lexer *a_lexer(Assembler *a)
|
||||||
@ -1114,6 +1138,22 @@ static void a_parse_directive_include(Assembler *a)
|
|||||||
snprintf(
|
snprintf(
|
||||||
filename, included_filename_len + 1, "%s/%s", current_dir, str_val);
|
filename, included_filename_len + 1, "%s/%s", current_dir, str_val);
|
||||||
free(str_val);
|
free(str_val);
|
||||||
|
|
||||||
|
if (a->dep_file) {
|
||||||
|
char **res = map_get(&a->dep_str_map, a_lexer(a)->loc.filename);
|
||||||
|
char *dep_str = res ? *res : nullptr;
|
||||||
|
|
||||||
|
char *dep_filename = realpath(filename, nullptr);
|
||||||
|
if (dep_str) {
|
||||||
|
char *new_dep_str = alloc_sprintf("%s %s", dep_str, dep_filename);
|
||||||
|
free(dep_str);
|
||||||
|
dep_str = new_dep_str;
|
||||||
|
} else {
|
||||||
|
dep_str = alloc_sprintf("%s", dep_filename);
|
||||||
|
}
|
||||||
|
map_set(&a->dep_str_map, a_lexer(a)->loc.filename, &dep_str);
|
||||||
|
free(dep_filename);
|
||||||
|
}
|
||||||
free(current_filename);
|
free(current_filename);
|
||||||
|
|
||||||
char *text = read_text_file(filename);
|
char *text = read_text_file(filename);
|
||||||
@ -1549,12 +1589,15 @@ int main(int argc, char *argv[])
|
|||||||
const char *input_filename = nullptr;
|
const char *input_filename = nullptr;
|
||||||
const char *output_filename = nullptr;
|
const char *output_filename = nullptr;
|
||||||
bool print = false;
|
bool print = false;
|
||||||
|
bool use_dep_file = false;
|
||||||
|
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
if (strcmp(argv[i], "-o") == 0) {
|
if (strcmp(argv[i], "-o") == 0) {
|
||||||
i += 1;
|
i += 1;
|
||||||
assert(i < argc);
|
assert(i < argc);
|
||||||
output_filename = argv[i];
|
output_filename = argv[i];
|
||||||
|
} else if (strcmp(argv[i], "-M") == 0) {
|
||||||
|
use_dep_file = true;
|
||||||
} else if (strcmp(argv[i], "--print") == 0) {
|
} else if (strcmp(argv[i], "--print") == 0) {
|
||||||
print = true;
|
print = true;
|
||||||
} else {
|
} else {
|
||||||
@ -1567,6 +1610,14 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
char *input_text = read_text_file(input_filename);
|
char *input_text = read_text_file(input_filename);
|
||||||
|
|
||||||
|
FILE *dep_file = nullptr;
|
||||||
|
if (use_dep_file) {
|
||||||
|
char *filename = alloc_sprintf("%s.d", output_filename);
|
||||||
|
dep_file = fopen(filename, "w");
|
||||||
|
assert(dep_file);
|
||||||
|
free(filename);
|
||||||
|
}
|
||||||
|
|
||||||
Lexer lexer = {
|
Lexer lexer = {
|
||||||
.text = input_text,
|
.text = input_text,
|
||||||
.loc = { input_filename, 0, 1, 1 },
|
.loc = { input_filename, 0, 1, 1 },
|
||||||
@ -1584,12 +1635,24 @@ int main(int argc, char *argv[])
|
|||||||
print_error_exit(assembler.tok.loc, "expected '@end'");
|
print_error_exit(assembler.tok.loc, "expected '@end'");
|
||||||
|
|
||||||
assembler_rewind(&assembler);
|
assembler_rewind(&assembler);
|
||||||
|
assembler.dep_file = dep_file;
|
||||||
|
|
||||||
while (!assembler_done(&assembler))
|
while (!assembler_done(&assembler))
|
||||||
assembler_parse_line(&assembler);
|
assembler_parse_line(&assembler);
|
||||||
|
|
||||||
free(input_text);
|
free(input_text);
|
||||||
|
|
||||||
|
if (assembler.dep_file) {
|
||||||
|
for (size_t i = 0; i < map_size(&assembler.dep_str_map); ++i) {
|
||||||
|
const char *key = map_key_at(&assembler.dep_str_map, i);
|
||||||
|
char *path = realpath(key, nullptr);
|
||||||
|
char **dep_str = map_val_at(&assembler.dep_str_map, i);
|
||||||
|
fprintf(assembler.dep_file, "%s: %s\n\n", path, *dep_str);
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
|
fclose(assembler.dep_file);
|
||||||
|
}
|
||||||
|
|
||||||
FILE *output_file = fopen(output_filename, "w");
|
FILE *output_file = fopen(output_filename, "w");
|
||||||
assert(output_file);
|
assert(output_file);
|
||||||
size_t words_written
|
size_t words_written
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user