diff --git a/core/runtime/default_allocators.odin b/core/runtime/default_allocators.odin index 7e616d043..a132b7a4f 100644 --- a/core/runtime/default_allocators.odin +++ b/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, diff --git a/src/build_settings.cpp b/src/build_settings.cpp index 39deb4063..0d5352347 100644 --- a/src/build_settings.cpp +++ b/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; diff --git a/src/checker.cpp b/src/checker.cpp index 7659a42ff..5c93e12b6 100644 --- a/src/checker.cpp +++ b/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)); diff --git a/src/main.cpp b/src/main.cpp index 13d9e53bf..ed90095ef 100644 --- a/src/main.cpp +++ b/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 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 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 {