diff --git a/core_codegen_c_language.cpp b/core_codegen_c_language.cpp index 2050dd5..03f36f2 100644 --- a/core_codegen_c_language.cpp +++ b/core_codegen_c_language.cpp @@ -771,7 +771,7 @@ gen_ast(Ast *ast){ CORE_Static String compile_to_c_code(){ - pctx->generating_time_begin = os_time(); + pctx->time.code_generation = os_time(); prefixed_string_type = string_fmt(pctx->perm, "%QString", pctx->symbol_prefix); if(pctx->single_header_library_mode){ @@ -977,6 +977,6 @@ typedef struct String{ String string_result = string_flatten(pctx->perm, &pctx->gen); - pctx->generating_time_end = os_time(); + pctx->time.code_generation = os_time() - pctx->time.code_generation; return string_result; } diff --git a/core_compiler.cpp b/core_compiler.cpp index 0f7d212..ca48b63 100644 --- a/core_compiler.cpp +++ b/core_compiler.cpp @@ -1,7 +1,7 @@ CORE_Static void core_init_compiler(Core_Ctx *ctx, Allocator *allocator) { - ctx->init_ctx_time_begin = os_time(); + ctx->time.init_context = os_time(); pctx = ctx; ctx->emit_type_info = true; @@ -155,7 +155,7 @@ pctx->op_info_table[19] = {pctx->intern("!"_s), "NOT"_s, TK_Not, 0, 1}; String main_module = string_fmt(ctx->perm, "%Q/modules", ctx->exe_folder); add(ctx->perm, &ctx->module_folders, main_module); - ctx->init_ctx_time_end = os_time(); + ctx->time.init_context = os_time() - ctx->time.init_context; } CORE_Static void @@ -177,7 +177,7 @@ insert_builtin_type_into_scope(Ast_Scope *p, String name, Ast_Type *type) { CORE_Static void parse_all_modules() { - pctx->parsing_time_begin = os_time(); + pctx->time.parsing = os_time(); For_Named(pctx->modules, module) { if (module->state != MODULE_REGISTERED) @@ -194,7 +194,7 @@ parse_all_modules() { module->state = MODULE_PARSED; } - pctx->parsing_time_end = os_time(); + pctx->time.parsing = os_time() - pctx->time.parsing; } CORE_Static Ast_Module * @@ -260,7 +260,7 @@ CORE_Static void resolve_everything_in_module(Ast_Module *module) { if (module->state == MODULE_RESOLVED) return; - pctx->resolving_time_begin = os_time(); + pctx->time.typechecking = os_time(); For_Named(module->all_loaded_files, file) { For_Named(file->decls, decl) { resolve_name(file, decl->pos, decl->name); @@ -271,14 +271,15 @@ resolve_everything_in_module(Ast_Module *module) { } } module->state = MODULE_RESOLVED; - pctx->resolving_time_end = os_time(); + pctx->time.typechecking = os_time() - pctx->time.typechecking; } CORE_Static String compile_file_to_string(Allocator *allocator, String filename) { F64 total_time = os_time(); core_bootstrap_compiler(allocator); - pctx->total_time = total_time; + pctx->time.total = total_time; + pctx->time.start = total_time; { Ast_Module *module = add_module(0, pctx->intern("Language.core"_s)); { @@ -343,5 +344,7 @@ compile_file_to_string(Allocator *allocator, String filename) { pctx->stage_arena->len = 0; String result = compile_to_c_code(); + + pctx->time.total = os_time() - pctx->time.total; return result; } diff --git a/core_compiler.h b/core_compiler.h index dcb8aa3..d208240 100644 --- a/core_compiler.h +++ b/core_compiler.h @@ -14,8 +14,6 @@ @! Bring the Table<> @! Look into List, check if that's neccessary - @! Compute time statistics inside context and expose them properly - Probably want to implement a Red Black Tree then probably I wouldn't need any sort of heap based data structure. @@ -79,15 +77,15 @@ struct Core_Ctx{ String working_folder; List files_to_link; - F64 generating_time_begin; - F64 generating_time_end; - F64 resolving_time_begin; - F64 resolving_time_end; - F64 total_time; - F64 init_ctx_time_begin; - F64 init_ctx_time_end; - F64 parsing_time_begin; - F64 parsing_time_end; + struct { + F64 typechecking; + F64 code_generation; + F64 total; + F64 init_context; + F64 parsing; + + F64 start; + } time; bool color_codes_enabled; bool debugger_break_on_compiler_error; diff --git a/core_main.cpp b/core_main.cpp index a15aa73..ec31732 100644 --- a/core_main.cpp +++ b/core_main.cpp @@ -273,7 +273,7 @@ static void compile_file(Allocator *allocator, String filename, U32 compile_flag B32 r = os_write_file("program.c"_s, result); assert(r); - F64 total_compiler_time = os_time() - pctx->total_time; + F64 total_compiler_time = os_time() - pctx->time.start; printf("%f - ", total_compiler_time); Scratch_Arena *scratch = pctx->scratch; @@ -291,11 +291,12 @@ static void compile_file(Allocator *allocator, String filename, U32 compile_flag F64 end = os_time(); if (is_flag_set(compile_flags, COMPILE_PRINT_STATS)) { - printf("total = %f\n", os_time() - pctx->total_time); - printf("clang = %f\n", end - begin); - printf("parsing = %f\n", pctx->parsing_time_end - pctx->parsing_time_begin); - printf("resolving = %f\n", pctx->resolving_time_end - pctx->resolving_time_begin); - printf("generatin = %f\n", pctx->generating_time_end - pctx->generating_time_begin); + printf("total = %f\n", os_time() - pctx->time.start); + printf("core_total = %f\n", pctx->time.total); + printf("clang = %f\n", end - begin); + printf("parsing = %f\n", pctx->time.parsing); + printf("typecheck = %f\n", pctx->time.typechecking); + printf("generatin = %f\n", pctx->time.code_generation); } if (is_flag_set(compile_flags, COMPILE_PRINT_ALLOCATOR_STATS_BEFORE_DESTROY)) {