Browse Source

Add general timings for sections of the compiler

Ginger Bill 8 years ago
parent
commit
3ce044f84f
4 changed files with 78 additions and 10 deletions
  1. 1 1
      build.bat
  2. 55 0
      compile_time_execution_problems.md
  3. 13 0
      roadmap.md
  4. 9 9
      src/main.cpp

+ 1 - 1
build.bat

@@ -4,7 +4,7 @@
 set exe_name=odin.exe
 set exe_name=odin.exe
 
 
 :: Debug = 0, Release = 1
 :: 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-
 set compiler_flags= -nologo -Oi -TP -W4 -fp:fast -fp:except- -Gm- -MP -FC -GS- -EHsc- -GR-
 
 

+ 55 - 0
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)
+* ???

+ 13 - 0
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

+ 9 - 9
src/main.cpp

@@ -17,7 +17,7 @@
 i32 win32_exec_command_line_app(char *name, char *fmt, ...) {
 i32 win32_exec_command_line_app(char *name, char *fmt, ...) {
 	STARTUPINFOW start_info = {gb_size_of(STARTUPINFOW)};
 	STARTUPINFOW start_info = {gb_size_of(STARTUPINFOW)};
 	PROCESS_INFORMATION pi = {};
 	PROCESS_INFORMATION pi = {};
-	char cmd_line[2048] = {};
+	char cmd_line[4096] = {};
 	isize cmd_len;
 	isize cmd_len;
 	va_list va;
 	va_list va;
 	gbTempArenaMemory tmp;
 	gbTempArenaMemory tmp;
@@ -142,7 +142,7 @@ int main(int argc, char **argv) {
 	Parser parser = {0};
 	Parser parser = {0};
 
 
 
 
-	timings_start_section(&timings, make_string("Parser"));
+	timings_start_section(&timings, make_string("parse files"));
 
 
 	if (!init_parser(&parser)) {
 	if (!init_parser(&parser)) {
 		return 1;
 		return 1;
@@ -155,7 +155,7 @@ int main(int argc, char **argv) {
 
 
 
 
 #if 1
 #if 1
-	timings_start_section(&timings, make_string("Checker"));
+	timings_start_section(&timings, make_string("type check"));
 
 
 	Checker checker = {};
 	Checker checker = {};
 	ArchData arch_data = make_arch_data(ArchKind_x64);
 	ArchData arch_data = make_arch_data(ArchKind_x64);
@@ -175,13 +175,13 @@ int main(int argc, char **argv) {
 	}
 	}
 	// defer (ssa_gen_destroy(&ssa));
 	// 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);
 	ssa_gen_tree(&ssa);
 
 
-	timings_start_section(&timings, make_string("SSA opt"));
+	timings_start_section(&timings, make_string("ssa opt"));
 	ssa_opt_tree(&ssa);
 	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);
 	ssa_print_llvm_ir(&ssa);
 
 
 	// prof_print_all();
 	// prof_print_all();
@@ -252,12 +252,12 @@ int main(int argc, char **argv) {
 	if (exit_code != 0) {
 	if (exit_code != 0) {
 		return exit_code;
 		return exit_code;
 	}
 	}
-	// prof_print_all();
 
 
-	timings_print_all(&timings);
+	// timings_print_all(&timings);
 
 
 	if (run_output) {
 	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
 #endif
 #endif