Cleanup iterators, remove logging, add message queue

This commit is contained in:
Krzosa Karol
2023-01-01 19:18:42 +01:00
parent 3de813212a
commit ec66f02e46
8 changed files with 214 additions and 217 deletions

View File

@@ -344,74 +344,3 @@ compile_file_to_string(Allocator *allocator, String filename) {
String result = compile_to_c_code();
return result;
}
const U32 COMPILE_NULL = 0x0;
const U32 COMPILE_PRINT_STATS = 0x1;
const U32 COMPILE_PRINT_ALLOCATOR_STATS_BEFORE_DESTROY = 0x2;
const U32 COMPILE_AND_RUN = 0x4;
const U32 COMPILE_TESTING = 0x8;
CORE_Static void
compile_file(Allocator *allocator, String filename, U32 compile_flags = COMPILE_NULL) {
String result = compile_file_to_string(allocator, filename);
if (is_flag_set(compile_flags, COMPILE_AND_RUN)) {
log_info_no_nl("%Q - ", filename);
}
B32 r = os_write_file("program.c"_s, result);
assert(r);
F64 total_compiler_time = os_time() - pctx->total_time;
log_info_no_nl("%f - ", total_compiler_time);
Scratch_Arena *scratch = pctx->scratch;
Scratch_Scope _scope(scratch);
F64 begin = os_time();
String_Builder builder = {scratch};
builder.addf("clang program.c -Wall -Wno-unused-function -Wno-parentheses-equality -g -o a" OS_EXE " ");
For(pctx->files_to_link) {
builder.addf("-l%Q ", it->intern_val);
}
String compiler_call = string_flatten(scratch, &builder);
log_trace("%Q", compiler_call);
system((const char *)compiler_call.str);
F64 end = os_time();
if (is_flag_set(compile_flags, COMPILE_PRINT_STATS)) {
log_info("total = %f", os_time() - pctx->total_time);
log_info("clang = %f", end - begin);
log_info("parsing = %f", pctx->parsing_time_end - pctx->parsing_time_begin);
log_info("resolving = %f", pctx->resolving_time_end - pctx->resolving_time_begin);
log_info("generatin = %f", pctx->generating_time_end - pctx->generating_time_begin);
}
if (is_flag_set(compile_flags, COMPILE_PRINT_ALLOCATOR_STATS_BEFORE_DESTROY)) {
// @! allocator stats
//Arena *p = (Arena *)pctx->perm;
//Arena *stage = (Arena *)&pctx->stage_arena;
//log_info("Pernament arena len: %llu commit: %llu", pct, p->memory.commit);
//log_info("Stage arena len: %llu commit: %llu", stage->len, stage->memory.commit);
//log_info("Scratch1 len: %llu commit: %llu", thread_ctx.scratch[0].len, thread_ctx.scratch[0].memory.commit);
//log_info("Scratch2 len: %llu commit: %llu", thread_ctx.scratch[1].len, thread_ctx.scratch[1].memory.commit);
}
if (is_flag_set(compile_flags, COMPILE_AND_RUN)) {
String testing = compile_flags & COMPILE_TESTING ? "testing"_s : ""_s;
#if OS_WINDOWS
String sys = string_fmt(scratch, "a.exe %Q", testing);
#else
String sys = string_fmt(scratch, "./a.out %Q", testing);
#endif
int result = system((char *)sys.str);
assert(result != -1);
if (result == 0) {
log_info_no_nl(PRINTF_GREEN "OK!" PRINTF_RESET);
}
if (result != 0) {
log_info_no_nl(PRINTF_RED "ERROR!" PRINTF_RESET);
}
log_info("");
}
}