GlobalAllocator fixes

- Made a gen script (does full build and test) build just builds gencpp now.
This commit is contained in:
Edward R. Gonzalez 2023-07-19 00:49:54 -04:00
parent 1488aeb188
commit d1c061769c
5 changed files with 107 additions and 62 deletions

View File

@ -1096,13 +1096,13 @@ namespace gen
#pragma region Gen Interface
internal void* Global_Allocator_Proc( void* allocator_data, AllocType type, sw size, sw alignment, void* old_memory, sw old_size, u64 flags )
{
Arena& last = Global_AllocatorBuckets.back();
Arena* last = & Global_AllocatorBuckets.back();
switch ( type )
{
case EAllocation_ALLOC:
{
if ( last.TotalUsed + size > last.TotalSize )
if ( ( last->TotalUsed + size ) > last->TotalSize )
{
Arena bucket = Arena::init_from_allocator( heap(), Global_BucketSize );
@ -1112,10 +1112,10 @@ namespace gen
if ( ! Global_AllocatorBuckets.append( bucket ) )
fatal( "Failed to append bucket to Global_AllocatorBuckets");
last = Global_AllocatorBuckets.back();
last = & Global_AllocatorBuckets.back();
}
return alloc_align( last, size, alignment );
return alloc_align( * last, size, alignment );
}
case EAllocation_FREE:
{
@ -1129,7 +1129,7 @@ namespace gen
break;
case EAllocation_RESIZE:
{
if ( last.TotalUsed + size > last.TotalSize )
if ( last->TotalUsed + size > last->TotalSize )
{
Arena bucket = Arena::init_from_allocator( heap(), Global_BucketSize );
@ -1139,10 +1139,10 @@ namespace gen
if ( ! Global_AllocatorBuckets.append( bucket ) )
fatal( "Failed to append bucket to Global_AllocatorBuckets");
last = Global_AllocatorBuckets.back();
last = & Global_AllocatorBuckets.back();
}
void* result = alloc_align( last.Backing, size, alignment );
void* result = alloc_align( last->Backing, size, alignment );
if ( result != nullptr && old_memory != nullptr )
{
@ -1336,8 +1336,8 @@ namespace gen
void deinit()
{
s32 index = 0;
s32 left = CodePools.num();
uw index = 0;
uw left = CodePools.num();
do
{
Pool* code_pool = & CodePools[index];
@ -1361,9 +1361,7 @@ namespace gen
CodePools.free();
StringArenas.free();
#ifdef GEN_FEATURE_PARSING
LexArena.free();
#endif
index = 0;
left = Global_AllocatorBuckets.num();

View File

@ -43,53 +43,3 @@ Push-Location $path_root
& ninja $args_ninja
Pop-Location
Push-location $path_gen
# Run meta-program
$gencpp = Join-Path $path_gen_build gencpp.exe
Write-Host `nRunning tests...
& $gencpp
# Format generated files
Write-Host `nBeginning format...
$formatParams = @(
'-i' # In-place
'-style=file' # Search for a .clang-format file in the parent directory of the source file.
'-verbose'
)
$include = @('*.gen.hpp', '*.gen.cpp')
$exclude = $null
$targetFiles = @(Get-ChildItem -Recurse -Path $path_gen -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
clang-format $formatParams $targetFiles
Write-Host "`nFormatting complete"
Pop-Location
# Build the program depending on generated files.
if ( -not( Test-Path $path_test_build ) )
{
Push-Location $path_test
$args_meson = @()
$args_meson += "setup"
$args_meson += $path_test_build
# & meson $args_meson
Pop-Location
}
Push-Location $path_root
$args_ninja = @()
$args_ninja += "-C"
$args_ninja += $path_test_build
# ninja $args_ninja
Pop-Location
Push-Location $path_test
$testcpp = Join-Path $path_test_build testcpp.exe
# & $testcpp
Pop-Location

95
scripts/gen.ps1 Normal file
View File

@ -0,0 +1,95 @@
[string] $type = $null
[string] $test = $false
foreach ( $arg in $args )
{
if ( $arg -eq "test" )
{
$test = $true
}
else
{
$type = $arg
}
}
$path_root = git rev-parse --show-toplevel
$path_build = Join-Path $path_root build
$path_scripts = Join-Path $path_root scripts
$path_test = Join-Path $path_root test
$path_gen = Join-Path $path_test gen
$path_test_build = Join-Path $path_test build
$path_gen_build = Join-Path $path_gen build
write-host "`n`nBuilding Test`n"
if ( -not( Test-Path $path_gen_build ) )
{
# Generate build files for meta-program
Push-Location $path_gen
$args_meson = @()
$args_meson += "setup"
$args_meson += $path_gen_build
& meson $args_meson
Pop-Location
}
# Compile meta-program
Push-Location $path_root
$args_ninja = @()
$args_ninja += "-C"
$args_ninja += $path_gen_build
& ninja $args_ninja
Pop-Location
Push-location $path_gen
# Run meta-program
$gencpp = Join-Path $path_gen_build gencpp.exe
Write-Host `nRunning tests...
& $gencpp
# Format generated files
Write-Host `nBeginning format...
$formatParams = @(
'-i' # In-place
'-style=file' # Search for a .clang-format file in the parent directory of the source file.
'-verbose'
)
$include = @('*.gen.hpp', '*.gen.cpp')
$exclude = $null
$targetFiles = @(Get-ChildItem -Recurse -Path $path_gen -Include $include -Exclude $exclude | Select-Object -ExpandProperty FullName)
clang-format $formatParams $targetFiles
Write-Host "`nFormatting complete"
Pop-Location
# Build the program depending on generated files.
if ( -not( Test-Path $path_test_build ) )
{
Push-Location $path_test
$args_meson = @()
$args_meson += "setup"
$args_meson += $path_test_build
# & meson $args_meson
Pop-Location
}
Push-Location $path_root
$args_ninja = @()
$args_ninja += "-C"
$args_ninja += $path_test_build
# ninja $args_ninja
Pop-Location
Push-Location $path_test
$testcpp = Join-Path $path_test_build testcpp.exe
# & $testcpp
Pop-Location

View File

@ -117,6 +117,7 @@ Code gen_SOA( CodeStruct struct_def, s32 num_entries = 0 )
void check_SOA()
{
log_fmt("\ncheck_SOA:");
gen::init();
Builder soa_test; soa_test.open( "SOA.gen.hpp" );
@ -140,5 +141,6 @@ void check_SOA()
soa_test.write();
gen::deinit();
log_fmt(" passed!\n");
}
#endif

View File

@ -87,7 +87,7 @@ void check_sanity()
log_fmt("Num String Cache Arenas : %llu TotalSize: %llu !\n", StringArenas.num(), StringArenas.num() * SizePer_StringArena);
log_fmt("Num String Cache : %llu\n", StringCache.Entries.num(), StringCache);
log_fmt("\nSanity passed!\n");
gen::deinit();
log_fmt("\nSanity passed!\n");
}
#endif