Browse Source

Add -default-to-nil-allocator flag (sets `ODIN_DEFAULT_TO_NIL_ALLOCATOR`)

gingerBill 5 years ago
parent
commit
edbad0709e
4 changed files with 13 additions and 3 deletions
  1. 1 1
      core/runtime/default_allocators.odin
  2. 1 0
      src/build_settings.cpp
  3. 1 0
      src/checker.cpp
  4. 10 2
      src/main.cpp

+ 1 - 1
core/runtime/default_allocators.odin

@@ -1,6 +1,6 @@
 package runtime
 
-when ODIN_OS == "freestanding" {
+when ODIN_DEFAULT_TO_NIL_ALLOCATOR || ODIN_OS == "freestanding" {
 	// mem.nil_allocator reimplementation
 
 	default_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode,

+ 1 - 0
src/build_settings.cpp

@@ -111,6 +111,7 @@ struct BuildContext {
 	String ODIN_ROOT;    // Odin ROOT
 	bool   ODIN_DEBUG;   // Odin in debug mode
 	bool   ODIN_DISABLE_ASSERT; // Whether the default 'assert' et al is disabled in code or not
+	bool   ODIN_DEFAULT_TO_NIL_ALLOCATOR; // Whether the default allocator is a "nil" allocator or not (i.e. it does nothing)
 
 	TargetEndianKind endian_kind;
 

+ 1 - 0
src/checker.cpp

@@ -739,6 +739,7 @@ void init_universal(void) {
 	add_global_string_constant(str_lit("ODIN_ROOT"),    bc->ODIN_ROOT);
 	add_global_constant(str_lit("ODIN_DEBUG"), t_untyped_bool, exact_value_bool(bc->ODIN_DEBUG));
 	add_global_constant(str_lit("ODIN_DISABLE_ASSERT"), t_untyped_bool, exact_value_bool(bc->ODIN_DISABLE_ASSERT));
+	add_global_constant(str_lit("ODIN_DEFAULT_TO_NIL_ALLOCATOR"), t_untyped_bool, exact_value_bool(bc->ODIN_DEFAULT_TO_NIL_ALLOCATOR));
 	add_global_constant(str_lit("ODIN_USE_LLVM_API"), t_untyped_bool, exact_value_bool(bc->use_llvm_api));
 	add_global_constant(str_lit("ODIN_NO_DYNAMIC_LITERALS"), t_untyped_bool, exact_value_bool(bc->no_dynamic_literals));
 

+ 10 - 2
src/main.cpp

@@ -580,6 +580,8 @@ enum BuildFlagKind {
 	BuildFlag_IgnoreUnknownAttributes,
 	BuildFlag_ExtraLinkerFlags,
 
+	BuildFlag_DefaultToNilAllocator,
+
 	BuildFlag_Compact,
 	BuildFlag_GlobalDefinitions,
 	BuildFlag_GoToDefinitions,
@@ -676,6 +678,8 @@ bool parse_build_flags(Array<String> args) {
 	add_flag(&build_flags, BuildFlag_IgnoreUnknownAttributes, str_lit("ignore-unknown-attributes"), BuildFlagParam_None);
 	add_flag(&build_flags, BuildFlag_ExtraLinkerFlags,  str_lit("extra-linker-flags"), BuildFlagParam_String);
 
+	add_flag(&build_flags, BuildFlag_DefaultToNilAllocator, str_lit("default-to-nil-allocator"), BuildFlagParam_None);
+
 	add_flag(&build_flags, BuildFlag_Compact, str_lit("compact"), BuildFlagParam_None);
 	add_flag(&build_flags, BuildFlag_GlobalDefinitions, str_lit("global-definitions"), BuildFlagParam_None);
 	add_flag(&build_flags, BuildFlag_GoToDefinitions, str_lit("go-to-definitions"), BuildFlagParam_None);
@@ -1099,6 +1103,10 @@ bool parse_build_flags(Array<String> args) {
 							build_context.extra_linker_flags = value.value_string;
 							break;
 
+						case BuildFlag_DefaultToNilAllocator:
+							build_context.ODIN_DEFAULT_TO_NIL_ALLOCATOR = true;
+							break;
+
 						case BuildFlag_Compact:
 							if (!build_context.query_data_set_settings.ok) {
 								gb_printf_err("Invalid use of -compact flag, only allowed with 'odin query'\n");
@@ -1685,7 +1693,7 @@ int main(int arg_count, char const **arg_ptr) {
 		#endif
 	} else if (command == "version") {
 		gb_printf("%.*s version %.*s", LIT(args[0]), LIT(ODIN_VERSION));
-		
+
 		#ifdef NIGHTLY
 		gb_printf("-nightly");
 		#endif
@@ -1693,7 +1701,7 @@ int main(int arg_count, char const **arg_ptr) {
 		#ifdef GIT_SHA
 		gb_printf("-%s", GIT_SHA);
 		#endif
-		
+
 		gb_printf("\n");
 		return 0;
 	} else {