Jelajahi Sumber

Add `runtime._cleanup_runtime` internal call

gingerBill 4 tahun lalu
induk
melakukan
7aac8df2f2
3 mengubah file dengan 11 tambahan dan 3 penghapusan
  1. 6 1
      core/runtime/core.odin
  2. 1 1
      src/checker.cpp
  3. 4 1
      src/llvm_backend.cpp

+ 6 - 1
core/runtime/core.odin

@@ -384,7 +384,12 @@ Raw_Cstring :: struct {
 // This is probably only useful for freestanding targets
 foreign {
 	@(link_name="__$startup_runtime")
-	_startup_runtime :: proc "contextless" () ---
+	_startup_runtime :: proc() ---
+}
+
+@(link_name="__$cleanup_runtime")
+_cleanup_runtime :: proc() {
+	default_temp_allocator_destroy(&global_default_temp_allocator_data)
 }
 
 

+ 1 - 1
src/checker.cpp

@@ -1967,6 +1967,7 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) {
 		str_lit("__init_context"),
 		str_lit("__type_info_of"),
 		str_lit("cstring_to_string"),
+		str_lit("_cleanup_runtime"), 
 
 		// Pseudo-CRT required procedures
 		str_lit("memset"),
@@ -1993,7 +1994,6 @@ void generate_minimum_dependency_set(Checker *c, Entity *start) {
 		str_lit("gnu_h2f_ieee"),
 		str_lit("gnu_f2h_ieee"),
 		str_lit("extendhfsf2"),
-
 	};
 	for (isize i = 0; i < gb_count_of(required_runtime_entities); i++) {
 		force_add_dependency_entity(c, c->info.runtime_package->scope, required_runtime_entities[i]);

+ 4 - 1
src/llvm_backend.cpp

@@ -879,7 +879,10 @@ lbProcedure *lb_create_main_procedure(lbModule *m, lbProcedure *startup_runtime)
 		}
 	}
 
-
+	
+	lbValue cleanup_runtime_value = lb_find_runtime_value(m, str_lit("_cleanup_runtime"));
+	lb_emit_call(p, cleanup_runtime_value, {}, ProcInlining_none, false);
+	
 
 	if (is_dll_main) {
 		LLVMBuildRet(p->builder, LLVMConstInt(lb_type(m, t_i32), 1, false));