Compiling and testing multiple files

This commit is contained in:
Krzosa Karol
2022-06-27 14:01:22 +02:00
parent 7b343ca642
commit a363a5e982
4 changed files with 62 additions and 31 deletions

View File

@@ -10,7 +10,7 @@ function void
begin_compilation(){
init_ctx_time_begin = os_time();
OS_Heap *heap = exp_alloc_type(&pernament_arena, OS_Heap, AF_ZeroMemory);
*heap = win32_os_heap_create(false, mib(4), 0);
*heap = win32_os_heap_create(false, mib(4), 0, "Compiler heap"_s);
Parse_Ctx *ctx = exp_alloc_type(&pernament_arena, Parse_Ctx, AF_ZeroMemory);
parse_init(ctx, &pernament_arena, heap);
init_ctx_time_end = os_time();
@@ -20,6 +20,7 @@ function void
destroy_compiler(){
exp_destroy(pctx->heap);
exp_free_all(pctx->perm);
exp_destroy(&pctx->stage_arena);
}
function void
@@ -225,11 +226,17 @@ compile_file_to_string(String filename){
return result;
}
const U32 COMPILE_NULL = 0x0;
const U32 COMPILE_PRINT_STATS = 0x1;
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;
function void
compile_file(String filename, U32 compile_flags = COMPILE_NULL){
if(is_flag_set(compile_flags, COMPILE_AND_RUN)){
log_info("\n%Q - ", filename);
}
String result = compile_file_to_string(filename);
assert(os_write_file("program.c"_s, result));
@@ -239,12 +246,33 @@ compile_file(String filename, U32 compile_flags = COMPILE_NULL){
system((const char *)compiler_call.str);
F64 end = os_time();
if(compile_flags & COMPILE_PRINT_STATS){
printf("\ntotal = %f", os_time() - total_time);
printf("\nclang = %f", end - begin);
printf("\nparsing = %f", parsing_time_end - parsing_time_begin);
printf("\nresolving = %f", resolving_time_end - resolving_time_begin);
printf("\ngeneratin = %f", generating_time_end - generating_time_begin);
if(is_flag_set(compile_flags, COMPILE_PRINT_STATS)){
log_info("\ntotal = %f", os_time() - total_time);
log_info("\nclang = %f", end - begin);
log_info("\nparsing = %f", parsing_time_end - parsing_time_begin);
log_info("\nresolving = %f", resolving_time_end - resolving_time_begin);
log_info("\ngeneratin = %f", generating_time_end - generating_time_begin);
}
if(is_flag_set(compile_flags, COMPILE_PRINT_ALLOCATOR_STATS_BEFORE_DESTROY)){
Arena *p = (Arena *)pctx->perm;
Arena *stage = (Arena *)&pctx->stage_arena;
log_info("\nPernament arena len: %llu commit: %llu", p->len, p->memory.commit);
log_info("\nStage arena len: %llu commit: %llu", stage->len, stage->memory.commit);
log_info("\nScratch1 len: %llu commit: %llu", thread_ctx.scratch[0].len, thread_ctx.scratch[0].memory.commit);
log_info("\nScratch2 len: %llu commit: %llu", thread_ctx.scratch[1].len, thread_ctx.scratch[1].memory.commit);
}
if(is_flag_set(compile_flags, COMPILE_AND_RUN)){
int result = system("a.exe");
assert(result != -1);
if(result == 0){
log_info(PRINTF_GREEN "OK!" PRINTF_RESET);
}
if(result != 0){
log_info(PRINTF_RED "ERROR!" PRINTF_RESET);
}
}
destroy_compiler();
}