From 3ce044f84f24b096156d6b4ce527c93a15f19147 Mon Sep 17 00:00:00 2001 From: Ginger Bill Date: Mon, 14 Nov 2016 21:37:37 +0000 Subject: [PATCH] Add general timings for sections of the compiler --- build.bat | 2 +- compile_time_execution_problems.md | 55 ++++++++++++++++++++++++++++++ roadmap.md | 13 +++++++ src/main.cpp | 18 +++++----- 4 files changed, 78 insertions(+), 10 deletions(-) create mode 100644 compile_time_execution_problems.md create mode 100644 roadmap.md diff --git a/build.bat b/build.bat index 065057a63..ed4442851 100644 --- a/build.bat +++ b/build.bat @@ -4,7 +4,7 @@ set exe_name=odin.exe :: Debug = 0, Release = 1 -set release_mode=0 +set release_mode=1 set compiler_flags= -nologo -Oi -TP -W4 -fp:fast -fp:except- -Gm- -MP -FC -GS- -EHsc- -GR- diff --git a/compile_time_execution_problems.md b/compile_time_execution_problems.md new file mode 100644 index 000000000..8cfeca4e4 --- /dev/null +++ b/compile_time_execution_problems.md @@ -0,0 +1,55 @@ +# Compile Time Execution Problems (Metaprogramming) +2016-11-02 + +## Memory and Types + +Compile time execution (CTE) is a stage of the compiler which runs any Odin code the +user requests before the creation of the executable. The data modified and generated +by this stage will be used as the initialization data for the _compiled_ code. + +The CTE stage is an interpreter running the generated _single static assignment_ (SSA) +tree for the requested code. When using the memory generated by the interpreter for the +compiled code, there are a few problems. The main problem being: pointers will point +to invalid memory addresses. This is becaused the memory space of the interpreter is +completely different to the memory space of the executable (compiled code). + +The table below presents which data types are safe for transferal and which are not. + +Key: + +* Y - Yes +* N - No +* D - Dependent on elements +* ? - Highly depends on a lot of factors (most likely no) + +| Type | Safe? | +|-----------|------------------------------------------------------------------------| +| boolean | Y | +| integer | Y | +| float | Y | +| pointer | N - Maybe safe if never changed | +| string | Y - Even though (ptr+int) interally, still safe to convert to constant | +| any | N - (ptr+ptr) | +| array | D | +| vector | Y - Elements can only be boolean, integer, or float (thus safe) | +| slice | N - Internally (ptr+int+int) | +| maybe | D | +| struct | D | +| enum | Y | +| union | N - (blob+int) | +| raw_union | N - ^^^ | +| tuple | D | +| proc | ? - Need to solve the next problem | + + +## Calling procedures (external and internal) + +If all the procedures are only from within the code itself, i.e. not a loaded pointer, +then it is "safe". However, calling external procedures and passing procedures from the +interpreter to external programs _will_ cause problems as many of the procedures are not +stored in _real_ memory. This causes numerous problems. + +**TODO:** + +* Look at how other languages solve this problem (e.g. LUA) +* ??? diff --git a/roadmap.md b/roadmap.md new file mode 100644 index 000000000..378be6ee6 --- /dev/null +++ b/roadmap.md @@ -0,0 +1,13 @@ +# Odin Roadmap + +Not in any particular order + +* Compile Time Execution (CTE) + - More metaprogramming madness + - Compiler as a library + - AST inspection and modification +* CTE-based build system +* Replace LLVM backend with my own custom backend +* Improve SSA design to accommodate for lowering to a "bytecode" +* SSA optimizations +* Parametric Polymorphism diff --git a/src/main.cpp b/src/main.cpp index 856f9e253..0c6ab2c25 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -17,7 +17,7 @@ i32 win32_exec_command_line_app(char *name, char *fmt, ...) { STARTUPINFOW start_info = {gb_size_of(STARTUPINFOW)}; PROCESS_INFORMATION pi = {}; - char cmd_line[2048] = {}; + char cmd_line[4096] = {}; isize cmd_len; va_list va; gbTempArenaMemory tmp; @@ -142,7 +142,7 @@ int main(int argc, char **argv) { Parser parser = {0}; - timings_start_section(&timings, make_string("Parser")); + timings_start_section(&timings, make_string("parse files")); if (!init_parser(&parser)) { return 1; @@ -155,7 +155,7 @@ int main(int argc, char **argv) { #if 1 - timings_start_section(&timings, make_string("Checker")); + timings_start_section(&timings, make_string("type check")); Checker checker = {}; ArchData arch_data = make_arch_data(ArchKind_x64); @@ -175,13 +175,13 @@ int main(int argc, char **argv) { } // defer (ssa_gen_destroy(&ssa)); - timings_start_section(&timings, make_string("SSA gen")); + timings_start_section(&timings, make_string("ssa gen")); ssa_gen_tree(&ssa); - timings_start_section(&timings, make_string("SSA opt")); + timings_start_section(&timings, make_string("ssa opt")); ssa_opt_tree(&ssa); - timings_start_section(&timings, make_string("SSA print")); + timings_start_section(&timings, make_string("ssa print")); ssa_print_llvm_ir(&ssa); // prof_print_all(); @@ -252,12 +252,12 @@ int main(int argc, char **argv) { if (exit_code != 0) { return exit_code; } - // prof_print_all(); - timings_print_all(&timings); + // timings_print_all(&timings); if (run_output) { - win32_exec_command_line_app("odin run", "%.*s.exe", cast(int)base_name_len, output_name); + win32_exec_command_line_app("odin run", + "%.*s.exe", cast(int)base_name_len, output_name); } #endif #endif