From 6eb65d5b37cfbb3deb2410069562f5c720f1823f Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Thu, 26 Jan 2023 20:33:37 +0100 Subject: [PATCH] Add memory-env option. --- lib/std/core/env.c3 | 17 +++++++++++++---- lib/std/core/mem.c3 | 11 ++++++++++- src/build/build_options.c | 7 +++++++ src/build/build_options.h | 19 +++++++++++++++++++ src/build/builder.c | 5 +++++ src/build/project.c | 6 ++++++ src/compiler/compiler.c | 10 +++++++--- src/version.h | 2 +- test/test_suite/stdlib/map.c3t | 4 ++-- test/test_suite14/stdlib/map.c3t | 4 ++-- 10 files changed, 72 insertions(+), 13 deletions(-) diff --git a/lib/std/core/env.c3 b/lib/std/core/env.c3 index 32748c8b2..41ae17d41 100644 --- a/lib/std/core/env.c3 +++ b/lib/std/core/env.c3 @@ -11,6 +11,14 @@ enum CompilerOptLevel O3 } +enum MemoryEnvironment +{ + NORMAL, + SMALL, + TINY, + NONE +} + enum OsType { UNKNOWN, @@ -51,9 +59,9 @@ enum OsType EMSCRIPTEN, } -const OsType OS_TYPE = (OsType)($$OS_TYPE); +const OsType OS_TYPE = (OsType)$$OS_TYPE; const bool COMPILER_LIBC_AVAILABLE = $$COMPILER_LIBC_AVAILABLE; -const CompilerOptLevel COMPILER_OPT_LEVEL = (CompilerOptLevel)($$COMPILER_OPT_LEVEL); +const CompilerOptLevel COMPILER_OPT_LEVEL = (CompilerOptLevel)$$COMPILER_OPT_LEVEL; const bool BIG_ENDIAN = $$PLATFORM_BIG_ENDIAN; const bool I128_NATIVE_SUPPORT = $$PLATFORM_I128_SUPPORTED; const bool F16_SUPPORT = $$PLATFORM_F16_SUPPORTED; @@ -62,7 +70,7 @@ const bool COMPILER_SAFE_MODE = $$COMPILER_SAFE_MODE; const usz LLVM_VERSION = $$LLVM_VERSION; const bool BENCHMARKING = $$BENCHMARKING; const bool TESTING = $$TESTING; -const usz TEMP_ALLOCATOR_SIZE = 128 * 1024; +const MemoryEnvironment MEMORY_ENV = (MemoryEnvironment)$$MEMORY_ENVIRONMENT; macro bool os_is_posix() { @@ -86,4 +94,5 @@ macro bool os_is_posix() $echo("Assuming non-Posix environment"); return false; $endswitch; -} \ No newline at end of file +} + diff --git a/lib/std/core/mem.c3 b/lib/std/core/mem.c3 index 363d1117e..1e7f5cee6 100644 --- a/lib/std/core/mem.c3 +++ b/lib/std/core/mem.c3 @@ -275,7 +275,16 @@ macro TempAllocator* temp_allocator() { if (!thread_temp_allocator) { - thread_temp_allocator = allocator::new_temp(env::TEMP_ALLOCATOR_SIZE, allocator::LIBC_ALLOCATOR)!!; + $switch (env::MEMORY_ENV): + $case NORMAL: + thread_temp_allocator = allocator::new_temp(1024 * 256, allocator::LIBC_ALLOCATOR)!!; + $case SMALL: + thread_temp_allocator = allocator::new_temp(1024 * 16, allocator::LIBC_ALLOCATOR)!!; + $case TINY: + thread_temp_allocator = allocator::new_temp(1024 * 4, allocator::LIBC_ALLOCATOR)!!; + $case NONE: + unreachable("Temp allocator must explicitly created when memory-env is set to 'none'."); + $endswitch; } return thread_temp_allocator; } diff --git a/src/build/build_options.c b/src/build/build_options.c index 9c5a04b30..5ad6074ff 100644 --- a/src/build/build_options.c +++ b/src/build/build_options.c @@ -131,6 +131,7 @@ static void usage(void) OUTPUT(""); OUTPUT(" --reloc=