Created gs_profiler, began using it in gs_meta

This commit is contained in:
Peter Slattery 2020-05-12 18:23:54 -07:00
parent 3418f1417a
commit 142fc72357
16 changed files with 704 additions and 397 deletions

View File

@ -4,9 +4,8 @@ SET MyPath=%~dp0
SET MyPath=%MyPath:~0,-1% SET MyPath=%MyPath:~0,-1%
call %MyPath%\_prebuild_win32.bat app debug msvc call %MyPath%\_prebuild_win32.bat app debug msvc
set CommonCompilerFlags=-nologo -DDEBUG=1 -DPLATFORM_WINDOWS -FC -WX -W4 -Z7 -Oi -GR- -EHsc -EHa- -MTd -fp:fast -fp:except- -IC:\programs-dev\gs_libs\src set CommonCompilerFlags=-nologo -DDEBUG=1 -DPLATFORM_WINDOWS -FC -WX -W4 -Z7 -Oi -GR- -EHsc -EHa- -MTd -fp:fast -fp:except-
set CommonCompilerFlags=-wd4127 -wd4702 -wd4101 -wd4505 -wd4100 -wd4189 -wd4244 -wd4201 -wd4996 -I%CommonLibs% -O2 %CommonCompilerFlags% set CommonCompilerFlags=-wd4127 -wd4702 -wd4101 -wd4505 -wd4100 -wd4189 -wd4244 -wd4201 -wd4996 -O2 %CommonCompilerFlags%
set CommonLinkerFlags= -opt:ref -incremental:no set CommonLinkerFlags= -opt:ref -incremental:no
set DLLExports=/EXPORT:InitializeApplication /EXPORT:UpdateAndRender /EXPORT:CleanupApplication /EXPORT:ReloadStaticData set DLLExports=/EXPORT:InitializeApplication /EXPORT:UpdateAndRender /EXPORT:CleanupApplication /EXPORT:ReloadStaticData

View File

@ -5,8 +5,8 @@ SET MyPath=%MyPath:~0,-1%
call %MyPath%\_prebuild_win32.bat meta debug msvc call %MyPath%\_prebuild_win32.bat meta debug msvc
set CommonCompilerFlags=-nologo -DDEBUG=1 -DPLATFORM_WINDOWS -FC -WX -W4 -Z7 -Oi -GR- -EHsc -EHa- -MTd -fp:fast -fp:except- set CommonCompilerFlags=-nologo -DDEBUG=1 -DPLATFORM_WINDOWS -FC -WX -W4 -Z7 -Oi -GR- -EHsc -EHa- -MTd -fp:fast -fp:except-
set CommonCompilerFlags=-wd4127 -wd4702 -wd4101 -wd4505 -wd4100 -wd4189 -wd4244 -wd4201 -wd4996 -I%CommonLibs% -O2 %CommonCompilerFlags% set CommonCompilerFlags=-wd4127 -wd4702 -wd4101 -wd4505 -wd4100 -wd4189 -wd4244 -wd4201 -wd4996 -Od %CommonCompilerFlags%
set CommonLinkerFlags= -opt:ref set CommonLinkerFlags= -opt:ref -incremental:no
pushd %BuildPath% pushd %BuildPath%

View File

@ -1,32 +1,14 @@
enum node_type enum node_type
{ {
NodeType_SolidColorProc,
NodeType_RevolvingDiscs,
NodeType_VerticalColorFadeProc,
NodeType_Count, NodeType_Count,
}; };
static node_specification_ NodeSpecifications[] = { static node_specification_ NodeSpecifications[] = {
{ NodeType_SolidColorProc, {"SolidColorProc", 14}, gsm_StructType_solid_color_data },
{ NodeType_RevolvingDiscs, {"RevolvingDiscs", 14}, gsm_StructType_revolving_discs_data },
{ NodeType_VerticalColorFadeProc, {"VerticalColorFadeProc", 21}, gsm_StructType_vertical_color_fade_data },
}; };
void CallNodeProc(node_type Type, u8* NodeData) void CallNodeProc(node_type Type, u8* NodeData)
{ {
switch(Type) { switch(Type) {
case NodeType_SolidColorProc:
{
SolidColorProc((solid_color_data*)NodeData);
} break;
case NodeType_RevolvingDiscs:
{
RevolvingDiscs((revolving_discs_data*)NodeData);
} break;
case NodeType_VerticalColorFadeProc:
{
VerticalColorFadeProc((vertical_color_fade_data*)NodeData);
} break;
} }
} }

View File

@ -1,19 +1,5 @@
enum panel_type { enum panel_type {
PanelType_FileView,
PanelType_SculptureView,
PanelType_AnimationTimeline,
PanelType_DMXView,
PanelType_HierarchyView,
PanelType_NodeGraph,
PanelType_ProfilerView,
}; };
global_variable s32 GlobalPanelDefsCount = 7; global_variable s32 GlobalPanelDefsCount = 0;
global_variable panel_definition GlobalPanelDefs[] = { global_variable panel_definition GlobalPanelDefs[] = {
{ "File View", 9, FileView_Init, FileView_Cleanup, FileView_Render, FileView_Commands, FileView_CommandsCount },
{ "Sculpture View", 14, SculptureView_Init, SculptureView_Cleanup, SculptureView_Render, SculptureView_Commands, SculptureView_CommandsCount },
{ "Animation Timeline", 18, AnimationTimeline_Init, AnimationTimeline_Cleanup, AnimationTimeline_Render, AnimationTimeline_Commands, AnimationTimeline_CommandsCount },
{ "Dmx View", 8, DMXView_Init, DMXView_Cleanup, DMXView_Render, DMXView_Commands, DMXView_CommandsCount },
{ "Hierarchy", 9, HierarchyView_Init, HierarchyView_Cleanup, HierarchyView_Render, HierarchyView_Commands, HierarchyView_CommandsCount },
{ "Node Graph", 10, NodeGraph_Init, NodeGraph_Cleanup, NodeGraph_Render, NodeGraph_Commands, NodeGraph_CommandsCount },
{ "Profiler", 8, ProfilerView_Init, ProfilerView_Cleanup, ProfilerView_Render, ProfilerView_Commands, ProfilerView_CommandsCount },
}; };

View File

@ -35,94 +35,10 @@ gsm_meta_tag MetaTagStrings[] = {
}; };
enum gsm_struct_type enum gsm_struct_type
{ {
gsm_StructType_solid_color_data,
gsm_StructType_v4,
gsm_StructType_float,
gsm_StructType_color_buffer,
gsm_StructType_led,
gsm_StructType_s32,
gsm_StructType_pixel,
gsm_StructType_u8,
gsm_StructType_sin_wave_data,
gsm_StructType_r32,
gsm_StructType_revolving_discs_data,
gsm_StructType_vertical_color_fade_data,
gsm_StructType_multiply_patterns_data,
gsm_StructType_Count, gsm_StructType_Count,
}; };
static gsm_struct_member_type_info StructMembers_v4[] = {
{ "x", 1, (u64)&((v4*)0)->x, {}, 0},
{ "y", 1, (u64)&((v4*)0)->y, {}, 0},
{ "z", 1, (u64)&((v4*)0)->z, {}, 0},
{ "w", 1, (u64)&((v4*)0)->w, {}, 0},
{ "r", 1, (u64)&((v4*)0)->r, {}, 0},
{ "g", 1, (u64)&((v4*)0)->g, {}, 0},
{ "b", 1, (u64)&((v4*)0)->b, {}, 0},
{ "a", 1, (u64)&((v4*)0)->a, {}, 0},
{ "E", 1, (u64)&((v4*)0)->E, {}, 0},
};
static gsm_struct_member_type_info StructMembers_led[] = {
{ "Index", 5, (u64)&((led*)0)->Index, {}, 0},
{ "Position", 8, (u64)&((led*)0)->Position, {}, 0},
};
static gsm_struct_member_type_info StructMembers_pixel[] = {
{ "R", 1, (u64)&((pixel*)0)->R, {}, 0},
{ "G", 1, (u64)&((pixel*)0)->G, {}, 0},
{ "B", 1, (u64)&((pixel*)0)->B, {}, 0},
{ "Channels", 8, (u64)&((pixel*)0)->Channels, {}, 0},
};
static gsm_struct_member_type_info StructMembers_color_buffer[] = {
{ "LEDs", 4, (u64)&((color_buffer*)0)->LEDs, {}, 0},
{ "Colors", 6, (u64)&((color_buffer*)0)->Colors, {}, 0},
{ "LEDCount", 8, (u64)&((color_buffer*)0)->LEDCount, {}, 0},
};
static gsm_struct_member_type_info StructMembers_solid_color_data[] = {
{ "Color", 5, (u64)&((solid_color_data*)0)->Color, {MetaTag_node_input, }, 1},
{ "Result", 6, (u64)&((solid_color_data*)0)->Result, {MetaTag_node_output, }, 1},
};
static gsm_struct_member_type_info StructMembers_sin_wave_data[] = {
{ "Period", 6, (u64)&((sin_wave_data*)0)->Period, {MetaTag_node_input, }, 1},
{ "Min", 3, (u64)&((sin_wave_data*)0)->Min, {MetaTag_node_input, }, 1},
{ "Max", 3, (u64)&((sin_wave_data*)0)->Max, {MetaTag_node_input, }, 1},
{ "Result", 6, (u64)&((sin_wave_data*)0)->Result, {MetaTag_node_input, }, 1},
{ "Accumulator", 11, (u64)&((sin_wave_data*)0)->Accumulator, {}, 0},
};
static gsm_struct_member_type_info StructMembers_revolving_discs_data[] = {
{ "Rotation", 8, (u64)&((revolving_discs_data*)0)->Rotation, {MetaTag_node_input, }, 1},
{ "ThetaZ", 6, (u64)&((revolving_discs_data*)0)->ThetaZ, {MetaTag_node_input, }, 1},
{ "ThetaY", 6, (u64)&((revolving_discs_data*)0)->ThetaY, {MetaTag_node_input, }, 1},
{ "DiscWidth", 9, (u64)&((revolving_discs_data*)0)->DiscWidth, {MetaTag_node_input, }, 1},
{ "InnerRadius", 11, (u64)&((revolving_discs_data*)0)->InnerRadius, {MetaTag_node_input, }, 1},
{ "OuterRadius", 11, (u64)&((revolving_discs_data*)0)->OuterRadius, {MetaTag_node_input, }, 1},
{ "Color", 5, (u64)&((revolving_discs_data*)0)->Color, {MetaTag_node_input, }, 1},
{ "Result", 6, (u64)&((revolving_discs_data*)0)->Result, {MetaTag_node_output, }, 1},
};
static gsm_struct_member_type_info StructMembers_vertical_color_fade_data[] = {
{ "Color", 5, (u64)&((vertical_color_fade_data*)0)->Color, {MetaTag_node_input, }, 1},
{ "Min", 3, (u64)&((vertical_color_fade_data*)0)->Min, {MetaTag_node_input, }, 1},
{ "Max", 3, (u64)&((vertical_color_fade_data*)0)->Max, {MetaTag_node_input, }, 1},
{ "Result", 6, (u64)&((vertical_color_fade_data*)0)->Result, {MetaTag_node_output, }, 1},
};
static gsm_struct_member_type_info StructMembers_multiply_patterns_data[] = {
{ "A", 1, (u64)&((multiply_patterns_data*)0)->A, {MetaTag_node_input, }, 1},
{ "B", 1, (u64)&((multiply_patterns_data*)0)->B, {MetaTag_node_input, }, 1},
{ "Result", 6, (u64)&((multiply_patterns_data*)0)->Result, {MetaTag_node_output, }, 1},
};
static gsm_struct_type_info StructTypes[] = { static gsm_struct_type_info StructTypes[] = {
{ gsm_StructType_solid_color_data, "solid_color_data", 16, 36, 0, 0, StructMembers_solid_color_data, 2 },
{ gsm_StructType_v4, "v4", 2, 16, 0, 0, StructMembers_v4, 3 },
{ gsm_StructType_float, "float", 5, 4, 0, 0, 0, 0 },
{ gsm_StructType_color_buffer, "color_buffer", 12, 20, 0, 0, StructMembers_color_buffer, 3 },
{ gsm_StructType_led, "led", 3, 20, 0, 0, StructMembers_led, 2 },
{ gsm_StructType_s32, "s32", 3, 4, 0, 0, 0, 0 },
{ gsm_StructType_pixel, "pixel", 5, 3, 0, 0, StructMembers_pixel, 2 },
{ gsm_StructType_u8, "u8", 2, 1, 0, 0, 0, 0 },
{ gsm_StructType_sin_wave_data, "sin_wave_data", 13, 20, 0, 0, StructMembers_sin_wave_data, 5 },
{ gsm_StructType_r32, "r32", 3, 4, 0, 0, 0, 0 },
{ gsm_StructType_revolving_discs_data, "revolving_discs_data", 20, 60, 0, 0, StructMembers_revolving_discs_data, 8 },
{ gsm_StructType_vertical_color_fade_data, "vertical_color_fade_data", 24, 44, 0, 0, StructMembers_vertical_color_fade_data, 4 },
{ gsm_StructType_multiply_patterns_data, "multiply_patterns_data", 22, 60, 0, 0, StructMembers_multiply_patterns_data, 3 },
}; };
static gsm_u32 StructTypesCount = 13; static gsm_u32 StructTypesCount = 0;

View File

@ -124,7 +124,7 @@ Test(b32 Result, char* Description, s32* Count)
#define DEBUG_TRACK_SCOPE(a) #define DEBUG_TRACK_SCOPE(a)
#endif // DEBUG_TRACK_SCOPE #endif // DEBUG_TRACK_SCOPE
#ifndef DEBUG_TRACK_FUNCTION #ifndef DEBUG_TRACK_FUNCTION
#define DEBUG_TRACK_FUNCTION // #define DEBUG_TRACK_FUNCTION
#endif // DEBUG_TRACK_FUNCTION #endif // DEBUG_TRACK_FUNCTION
#endif // GS_LANGUAGE_NO_PROFILER_DEFINES #endif // GS_LANGUAGE_NO_PROFILER_DEFINES

View File

@ -167,6 +167,21 @@ if((expression)) { \
#define GSMem_Assert(expression) #define GSMem_Assert(expression)
#endif #endif
struct data
{
u8* Memory;
u64 Size;
};
typedef data allocator_alloc(u64 Size);
typedef void allocator_free(u8* Base, u64 Size);
struct base_allocator
{
allocator_alloc* Alloc;
allocator_free* Free;
};
enum gs_memory_expansion_rule enum gs_memory_expansion_rule
{ {
MemoryExpansion_Allowed, // Zero is initialization lets the memory grow on its own MemoryExpansion_Allowed, // Zero is initialization lets the memory grow on its own
@ -229,6 +244,8 @@ struct memory_buffer
struct memory_arena struct memory_arena
{ {
base_allocator Allocator;
memory_buffer* Buffers; memory_buffer* Buffers;
gs_mem_u32 BuffersCount; gs_mem_u32 BuffersCount;
@ -266,6 +283,30 @@ struct arena_snapshot
#endif #endif
}; };
#define AllocatorAllocArray(alloc,type,count) (type*)(AllocatorAlloc((alloc), sizeof(type) * (count)).Memory)
#define AllocatorAllocStruct(alloc,type) (type*)(AllocatorAlloc((alloc), sizeof(type)).Memory)
static data
AllocatorAlloc(base_allocator Allocator, gs_mem_u64 Size)
{
return Allocator.Alloc(Size);
}
static void
AllocatorFree(base_allocator Allocator, gs_mem_u8* Base, gs_mem_u64 Size)
{
Allocator.Free(Base, Size);
}
static memory_arena
CreateMemoryArena(base_allocator Allocator)
{
memory_arena Result = {0};
Result.Allocator = Allocator;
Result.ExpansionRule = MemoryExpansion_Allowed;
Result.FindAddressRule = FindAddress_InLastBufferOnly;
return Result;
}
static void static void
FreeMemoryArena(memory_arena* Arena, gs_memory_free* Free = 0) FreeMemoryArena(memory_arena* Arena, gs_memory_free* Free = 0)
{ {
@ -348,22 +389,8 @@ static gs_mem_u8*
ArenaAlloc(memory_arena* Arena, gs_mem_u32 Size) ArenaAlloc(memory_arena* Arena, gs_mem_u32 Size)
{ {
gs_mem_u8* Result = 0; gs_mem_u8* Result = 0;
data Data = AllocatorAlloc(Arena->Allocator, Size);
if (Arena->Alloc) Result = Data.Memory;
{
Result = (gs_mem_u8*)Arena->Alloc(sizeof(gs_mem_u8) * Size);
}
else
{
#ifdef GS_MEMORY_NO_STD_LIBS
// NOTE(Peter): If you specify no std libs AND don't supply a allocation function
// we should assert as this is an invalid codepath
GSMem_Assert(0);
#else
Result = (gs_mem_u8*)malloc(sizeof(gs_mem_u8) * Size);
#endif
}
return Result; return Result;
} }
@ -372,21 +399,21 @@ ArenaRealloc(memory_arena* Arena, gs_mem_u8* Head, gs_mem_u32 OldSize, gs_mem_u3
{ {
gs_mem_u8* Result = 0; gs_mem_u8* Result = 0;
if (Arena->Realloc != 0) GSMem_Assert(Arena->Allocator.Alloc);
GSMem_Assert(Arena->Allocator.Free);
data Data = AllocatorAlloc(Arena->Allocator, NewSize);
for (gs_mem_u64 i = 0; i < (gs_mem_u64)OldSize; i++)
{ {
Result = (gs_mem_u8*)Arena->Realloc(Head, OldSize, NewSize); Data.Memory[i] = Head[i];
}
else
{
#ifdef GS_MEMORY_NO_STD_LIBS
// NOTE(Peter): If you specify no std libs AND don't supply a reallocation function
// we should assert as this is an invalid codepath
GSMem_Assert(0);
#else
Result = (gs_mem_u8*)realloc(Head, NewSize);
#endif
} }
if (Head != 0)
{
AllocatorFree(Arena->Allocator, Head, OldSize);
}
Result = Data.Memory;
return Result; return Result;
} }
@ -396,7 +423,7 @@ GrowArena(memory_arena* Arena, gs_mem_u32 SizeNeeded)
GSMem_Assert(Arena->ExpansionRule != MemoryExpansion_Disallowed); GSMem_Assert(Arena->ExpansionRule != MemoryExpansion_Disallowed);
if (Arena->ExpansionRule == MemoryExpansion_OnlyIfFunctionsProvided) if (Arena->ExpansionRule == MemoryExpansion_OnlyIfFunctionsProvided)
{ {
GSMem_Assert((Arena->Alloc != 0) && (Arena->Realloc != 0)); GSMem_Assert((Arena->Allocator.Alloc != 0) && (Arena->Allocator.Free != 0));
} }
gs_mem_u32 NewBuffersCount = (Arena->BuffersCount + 1); gs_mem_u32 NewBuffersCount = (Arena->BuffersCount + 1);

258
src/gs_libs/gs_profiler.h Normal file
View File

@ -0,0 +1,258 @@
//
// File: gs_profiler.h
// Author: Peter Slattery
// Creation Date: 2020-05-11
//
#ifndef GS_PROFILER_H
internal s64
GetWallClock()
{
LARGE_INTEGER Time;
if (!QueryPerformanceCounter(&Time))
{
s32 Error = GetLastError();
// TODO(Peter): I'm waiting to see an error actually occur here
// to know what it could possibly be.
InvalidCodePath;
}
return (s64)Time.QuadPart;
}
internal u64
HashDJB2ToU64(char* String)
{
u64 Hash = 5381;
char* C = String;
while(*C)
{
Hash = ((Hash << 5) + Hash) + *C++;
}
return Hash;
}
struct scope_record
{
u64 IdentifierHash;
s64 StartTime;
s64 EndTime;
};
struct scope_record_list
{
scope_record* List;
u32 Count;
u32 MaxCount;
scope_record_list* Next;
};
struct collated_scope_record
{
char* Identifier;
u64 CallCount;
u64 TotalCycles;
u64 LongestDuration;
};
#define COLLATED_SCOPES_HASH_SIZE 1024
struct collated_scopes_hash_table
{
u64* Hashes;
collated_scope_record* Scopes;
collated_scopes_hash_table* Next;
};
struct debug_services
{
memory_arena Arena;
memory_arena Transient;
u32 CollatedScopesCount;
collated_scopes_hash_table* CollatedScopes;
scope_record_list* ScopeRecordsHead;
scope_record_list* ScopeRecordsTail;
};
global_variable debug_services GlobalDebugServices = {0};
internal u64
RegisterScope(debug_services* Services, char* Identifier)
{
u64 Hash = HashDJB2ToU64(Identifier);
u32 Index = (u32)(Hash % COLLATED_SCOPES_HASH_SIZE);
collated_scopes_hash_table* PrevTable = 0;
collated_scopes_hash_table* TableAt = Services->CollatedScopes;
while (TableAt != 0)
{
if (TableAt->Hashes[Index] == Hash || TableAt->Hashes[Index] == 0)
{
break;
}
PrevTable = TableAt;
TableAt = TableAt->Next;
}
if (!TableAt)
{
collated_scopes_hash_table* NewTable = PushStruct(&Services->Arena, collated_scopes_hash_table);
NewTable->Hashes = PushArray(&Services->Arena, u64, COLLATED_SCOPES_HASH_SIZE);
GSZeroMemory(NewTable->Hashes, sizeof(u64) * COLLATED_SCOPES_HASH_SIZE);
NewTable->Scopes = PushArray(&Services->Arena, collated_scope_record, COLLATED_SCOPES_HASH_SIZE);
NewTable->Next = 0;
if (PrevTable)
{
PrevTable->Next = NewTable;
}
else
{
Services->CollatedScopes = NewTable;
}
TableAt = NewTable;
}
if (TableAt->Hashes[Index] == 0)
{
// New Scope Being Registered
TableAt->Hashes[Index] = Hash;
TableAt->Scopes[Index] = {0};
TableAt->Scopes[Index].Identifier = Identifier;
Services->CollatedScopesCount++;
}
else if (TableAt->Hashes[Index] != Hash)
{
InvalidCodePath;
}
return Hash;
}
internal void
PushScopeOnList(debug_services* Services, char* ScopeName, s64 Start, s64 End)
{
if (!Services->ScopeRecordsTail ||
Services->ScopeRecordsTail->Count >= Services->ScopeRecordsTail->MaxCount)
{
scope_record_list* NewTail = PushStruct(&Services->Arena, scope_record_list);
NewTail->MaxCount = 4096;
NewTail->List = PushArray(&Services->Arena, scope_record, NewTail->MaxCount);
NewTail->Count = 0;
NewTail->Next = 0;
if (Services->ScopeRecordsHead)
{
Services->ScopeRecordsTail->Next = NewTail;
}
else
{
Services->ScopeRecordsHead = NewTail;
}
Services->ScopeRecordsTail = NewTail;
}
u32 NewRecordIndex = Services->ScopeRecordsTail->Count++;
scope_record* NewRecord = &Services->ScopeRecordsTail->List[NewRecordIndex];
NewRecord->IdentifierHash = RegisterScope(Services, ScopeName);
NewRecord->StartTime = Start;
NewRecord->EndTime = End;
}
#define DEBUG_TRACK_FUNCTION scope_tracker ScopeTracker ((char*)__func__)
struct scope_tracker
{
s64 ScopeStart;
char* ScopeName;
scope_tracker(char* ScopeName)
{
this->ScopeName = ScopeName;
this->ScopeStart = GetWallClock();
}
~scope_tracker()
{
s64 ScopeEnd = GetWallClock();
PushScopeOnList(&GlobalDebugServices, this->ScopeName, this->ScopeStart, ScopeEnd);
}
};
//
// Reporting
//
internal collated_scope_record*
GetCollatedRecordForScope(debug_services* Services, u64 Hash)
{
Assert(Services->CollatedScopes);
collated_scope_record* Result = 0;
u64 Index = Hash % COLLATED_SCOPES_HASH_SIZE;
collated_scopes_hash_table* TableAt = Services->CollatedScopes;
while (TableAt != 0)
{
if (TableAt->Hashes[Index] == Hash)
{
Result = TableAt->Scopes + Index;
break;
}
TableAt = TableAt->Next;
}
return Result;
}
internal void
CollateFrame(debug_services* Services)
{
scope_record_list* ListAt = Services->ScopeRecordsHead;
while (ListAt != 0)
{
for (u32 i = 0; i < ListAt->Count; i++)
{
scope_record ScopeAt = ListAt->List[i];
u64 ScopeAtDuration = ScopeAt.EndTime - ScopeAt.StartTime;
collated_scope_record* CollatedScopeData = GetCollatedRecordForScope(Services, ScopeAt.IdentifierHash);
Assert(CollatedScopeData != 0);
CollatedScopeData->CallCount++;
CollatedScopeData->TotalCycles += ScopeAtDuration;
CollatedScopeData->LongestDuration = GSMax(ScopeAtDuration, CollatedScopeData->LongestDuration);
}
ListAt = ListAt->Next;
}
u32 SortListCount = Services->CollatedScopesCount;
gs_radix_entry* SortList = PushArray(&Services->Transient, gs_radix_entry, SortListCount);
u32 SortListAt = 0;
collated_scopes_hash_table* TableAt = Services->CollatedScopes;
while (TableAt != 0)
{
for (u32 i = 0; i < COLLATED_SCOPES_HASH_SIZE; i++)
{
if (TableAt->Hashes[i] == 0) { continue; }
SortList[SortListAt].ID = TableAt->Hashes[i];
SortList[SortListAt].Radix = TableAt->Scopes[i].TotalCycles;
SortListAt += 1;
}
TableAt = TableAt->Next;
}
RadixSortInPlace(SortList, SortListCount);
for (u32 i = 0; i < SortListCount; i++)
{
u64 Hash = SortList[i].ID;
collated_scope_record* ScopeData = GetCollatedRecordForScope(Services, Hash);
printf("Scope: %s\n", ScopeData->Identifier);
printf(" Call Count: %lld\n", ScopeData->CallCount);
printf(" Total Cycles: %lld\n", ScopeData->TotalCycles);
printf(" Longest Duration: %lld\n", ScopeData->LongestDuration);
}
}
#define GS_PROFILER_H
#endif // GS_PROFILER_H

View File

@ -15,26 +15,26 @@ if(!(expression)) { \
#endif // !defined(GSRad_Assert) #endif // !defined(GSRad_Assert)
#endif // DEBUG #endif // DEBUG
typedef unsigned int gs_rad_u32; typedef unsigned long long int gs_rad_u64;
typedef unsigned int gs_rad_b32; typedef unsigned int gs_rad_b32;
struct gs_radix_entry struct gs_radix_entry
{ {
gs_rad_u32 Radix; gs_rad_u64 Radix;
gs_rad_u32 ID; gs_rad_u64 ID;
}; };
static void static void
RadixSortInPlace_ (gs_radix_entry* Data, gs_rad_u32 Start, gs_rad_u32 End, gs_rad_u32 Iteration) RadixSortInPlace_ (gs_radix_entry* Data, gs_rad_u64 Start, gs_rad_u64 End, gs_rad_u64 Iteration)
{ {
gs_rad_u32 Shift = Iteration; gs_rad_u64 Shift = Iteration;
gs_rad_u32 ZerosBoundary = Start; gs_rad_u64 ZerosBoundary = Start;
gs_rad_u32 OnesBoundary = End - 1; gs_rad_u64 OnesBoundary = End - 1;
for (gs_rad_u32 d = Start; d < End; d++) for (gs_rad_u64 d = Start; d < End; d++)
{ {
gs_radix_entry Entry = Data[ZerosBoundary]; gs_radix_entry Entry = Data[ZerosBoundary];
gs_rad_u32 Place = (Entry.Radix >> Shift) & 0x1; gs_rad_u64 Place = (Entry.Radix >> Shift) & 0x1;
if (Place) if (Place)
{ {
gs_radix_entry Evicted = Data[OnesBoundary]; gs_radix_entry Evicted = Data[OnesBoundary];
@ -56,10 +56,10 @@ RadixSortInPlace_ (gs_radix_entry* Data, gs_rad_u32 Start, gs_rad_u32 End, gs_ra
} }
static void static void
RadixSortInPlace (gs_radix_entry* Data, gs_rad_u32 Count) RadixSortInPlace (gs_radix_entry* Data, gs_rad_u64 Count)
{ {
gs_rad_u32 Highest = 0; gs_rad_u64 Highest = 0;
for (gs_rad_u32 i = 0; i < Count; i++) for (gs_rad_u64 i = 0; i < Count; i++)
{ {
if (Data[i].Radix > Highest) if (Data[i].Radix > Highest)
{ {
@ -67,7 +67,7 @@ RadixSortInPlace (gs_radix_entry* Data, gs_rad_u32 Count)
} }
} }
gs_rad_u32 Iterations = 0; gs_rad_u64 Iterations = 0;
while (Highest > 1) while (Highest > 1)
{ {
++Iterations; ++Iterations;

View File

@ -225,7 +225,7 @@ GeneratePanelMetaInfo(gs_meta_preprocessor Meta, string_builder* PanelEnumGen, s
panel_elements* Panel = Panels.GetElementAtIndex(i); panel_elements* Panel = Panels.GetElementAtIndex(i);
string PanelIdentifier = {0}; string PanelIdentifier = {0};
PanelIdentifier.Max = Panel->PanelIdentifier.Length; PanelIdentifier.Max = Panel->PanelIdentifier.Length;
PanelIdentifier.Memory = (char*)malloc(sizeof(char) * PanelIdentifier.Max); PanelIdentifier.Memory = PushArray(&Meta.Permanent, char, PanelIdentifier.Max);
CopyStringTo(Substring(Panel->PanelIdentifier, 11), &PanelIdentifier); CopyStringTo(Substring(Panel->PanelIdentifier, 11), &PanelIdentifier);
MakeReadableIdentifier(&PanelIdentifier); MakeReadableIdentifier(&PanelIdentifier);
@ -259,11 +259,11 @@ GeneratePanelMetaInfo(gs_meta_preprocessor Meta, string_builder* PanelEnumGen, s
} }
internal string internal string
AllocAndConcatStrings(string First, string Second) AllocAndConcatStrings(base_allocator Allocator, string First, string Second)
{ {
string Result = {0}; string Result = {0};
Result.Max = First.Length + Second.Length + 1; Result.Max = First.Length + Second.Length + 1;
Result.Memory = (char*)malloc(sizeof(char) * Result.Max); Result.Memory = AllocatorAllocArray(Allocator, char, Result.Max);
ConcatString(First, &Result); ConcatString(First, &Result);
ConcatString(Second, &Result); ConcatString(Second, &Result);
NullTerminate(&Result); NullTerminate(&Result);
@ -271,6 +271,26 @@ AllocAndConcatStrings(string First, string Second)
return Result; return Result;
} }
u64 TotalAllocatedSpace = 0;
internal data
PlatformAlloc(u64 Size)
{
data Result = {0};
Result.Memory = (u8*)malloc(Size);
Result.Size = Size;
TotalAllocatedSpace += Size;
return Result;
}
internal void
PlatformFree(u8* Base, u64 Size)
{
free((void*)Base);
}
int main(int ArgCount, char* Args[]) int main(int ArgCount, char* Args[])
{ {
if (ArgCount <= 1) if (ArgCount <= 1)
@ -279,22 +299,27 @@ int main(int ArgCount, char* Args[])
return 0; return 0;
} }
base_allocator Allocator = {0};
Allocator.Alloc = (allocator_alloc*)PlatformAlloc;
Allocator.Free = (allocator_free*)PlatformFree;
string RootFile = MakeString(Args[1]); string RootFile = MakeString(Args[1]);
s32 IndexOfLastSlash = ReverseSearchForCharInSet(RootFile, "\\/"); s32 IndexOfLastSlash = ReverseSearchForCharInSet(RootFile, "\\/");
string WorkingDirectory = Substring(RootFile, 0, IndexOfLastSlash + 1); string WorkingDirectory = Substring(RootFile, 0, IndexOfLastSlash + 1);
string GeneratedDirectoryName = MakeStringLiteral("generated\\"); string GeneratedDirectoryName = MakeStringLiteral("generated\\");
string GeneratedFilesDirectory = AllocAndConcatStrings(WorkingDirectory, GeneratedDirectoryName); string GeneratedFilesDirectory = AllocAndConcatStrings(Allocator, WorkingDirectory, GeneratedDirectoryName);
printf("Putting Generated Files In %s\n", GeneratedFilesDirectory.Memory); printf("Putting Generated Files In %s\n", GeneratedFilesDirectory.Memory);
gs_meta_preprocessor Meta = PreprocessProgram(Args[1]); gs_meta_preprocessor Meta = PreprocessProgram(Allocator, Args[1]);
typeinfo_generator TypeGenerator = InitTypeInfoGenerator(Meta.TypeTable); typeinfo_generator TypeGenerator = InitTypeInfoGenerator(&Meta.TypeTable);
GenerateMetaTagList(Meta.TypeTable, &TypeGenerator); GenerateMetaTagList(Meta.TypeTable, &TypeGenerator);
GenerateFilteredTypeInfo(MakeStringLiteral("node_struct"), Meta.TypeTable, &TypeGenerator); GenerateFilteredTypeInfo(MakeStringLiteral("node_struct"), Meta.TypeTable, &TypeGenerator);
GenerateFilteredTypeInfo(MakeStringLiteral("gen_type_info"), Meta.TypeTable, &TypeGenerator); GenerateFilteredTypeInfo(MakeStringLiteral("gen_type_info"), Meta.TypeTable, &TypeGenerator);
FinishGeneratingTypes(&TypeGenerator); FinishGeneratingTypes(&TypeGenerator);
gsm_code_generator NodeTypeGen = BeginEnumGeneration("node_type", "NodeType", false, true); gsm_code_generator NodeTypeGen = BeginEnumGeneration(&Meta.TypeTable.Arena, "node_type", "NodeType", false, true);
string_builder NodeSpecificationGen = {0}; string_builder NodeSpecificationGen = {0};
string_builder CallNodeProcGen = {0}; string_builder CallNodeProcGen = {0};
GenerateNodeMetaInfo(&NodeTypeGen, &NodeSpecificationGen, &CallNodeProcGen, Meta); GenerateNodeMetaInfo(&NodeTypeGen, &NodeSpecificationGen, &CallNodeProcGen, Meta);
@ -303,7 +328,7 @@ int main(int ArgCount, char* Args[])
string_builder PanelCodeGen = {0}; string_builder PanelCodeGen = {0};
GeneratePanelMetaInfo(Meta, &PanelEnumGen, &PanelCodeGen); GeneratePanelMetaInfo(Meta, &PanelEnumGen, &PanelCodeGen);
string TypeInfoHFilePath = AllocAndConcatStrings(GeneratedFilesDirectory, MakeStringLiteral("gs_meta_generated_typeinfo.h")); string TypeInfoHFilePath = AllocAndConcatStrings(Allocator, GeneratedFilesDirectory, MakeStringLiteral("gs_meta_generated_typeinfo.h"));
FILE* TypeInfoH = fopen(TypeInfoHFilePath.Memory, "w"); FILE* TypeInfoH = fopen(TypeInfoHFilePath.Memory, "w");
if (TypeInfoH) if (TypeInfoH)
{ {
@ -319,7 +344,7 @@ int main(int ArgCount, char* Args[])
printf("Error: Unable to open file at %.*s\n", StringExpand(TypeInfoHFilePath)); printf("Error: Unable to open file at %.*s\n", StringExpand(TypeInfoHFilePath));
} }
string NodeInfoHFilePath = AllocAndConcatStrings(GeneratedFilesDirectory, MakeStringLiteral("foldhaus_nodes_generated.h")); string NodeInfoHFilePath = AllocAndConcatStrings(Allocator, GeneratedFilesDirectory, MakeStringLiteral("foldhaus_nodes_generated.h"));
FILE* NodeInfoH = fopen(NodeInfoHFilePath.Memory, "w"); FILE* NodeInfoH = fopen(NodeInfoHFilePath.Memory, "w");
if (NodeInfoH) if (NodeInfoH)
{ {
@ -333,7 +358,7 @@ int main(int ArgCount, char* Args[])
printf("Error: Unable to open file at %.*s\n", StringExpand(NodeInfoHFilePath)); printf("Error: Unable to open file at %.*s\n", StringExpand(NodeInfoHFilePath));
} }
string PanelInfoHFilePath = AllocAndConcatStrings(GeneratedFilesDirectory, MakeStringLiteral("foldhaus_panels_generated.h")); string PanelInfoHFilePath = AllocAndConcatStrings(Allocator, GeneratedFilesDirectory, MakeStringLiteral("foldhaus_panels_generated.h"));
FILE* PanelInfoH = fopen(PanelInfoHFilePath.Memory, "w"); FILE* PanelInfoH = fopen(PanelInfoHFilePath.Memory, "w");
if (PanelInfoH) if (PanelInfoH)
{ {
@ -348,6 +373,9 @@ int main(int ArgCount, char* Args[])
FinishMetaprogram(&Meta); FinishMetaprogram(&Meta);
r64 AllocatedMegabytes = (r64)TotalAllocatedSpace / (1024 * 1024);
printf("Total Allocated Space: %lld bytes, or %f MB\n", TotalAllocatedSpace, AllocatedMegabytes);
//__debugbreak(); //__debugbreak();
return 0; return 0;
} }

View File

@ -21,41 +21,13 @@
#include <stdio.h> #include <stdio.h>
#include "..\gs_libs\gs_language.h" #include "..\gs_libs\gs_language.h"
#include "..\gs_libs\gs_radix_sort.h"
#include "..\gs_libs\gs_bucket.h" #include "..\gs_libs\gs_bucket.h"
#include "..\gs_libs\gs_memory_arena.h" #include "..\gs_libs\gs_memory_arena.h"
#include "..\gs_libs\gs_profiler.h"
#include "..\gs_libs\gs_string.h" #include "..\gs_libs\gs_string.h"
#include "gs_meta_lexer.h"
#include "gs_meta_error.h"
#include "gs_meta_type_table.h"
struct source_code_file
{
string Path;
s32 FileSize;
string Contents;
s32 FirstTokenIndex;
s32 LastTokenIndex;
};
struct token_iter
{
gs_bucket<token>* Tokens;
token* TokenAt;
s32 TokenAtIndex;
s32 FirstToken;
s32 LastToken;
#define TOKEN_ITER_SNAPSHOTS_MAX 64
u32 SnapshotsUsed;
u32 Snapshots[TOKEN_ITER_SNAPSHOTS_MAX];
errors* Errors;
};
struct gsm_profiler_scope struct gsm_profiler_scope
{ {
s64 StartTime; s64 StartTime;
@ -81,31 +53,10 @@ struct gsm_profiler
gs_bucket<gsm_profiler_category> Categories; gs_bucket<gsm_profiler_category> Categories;
}; };
struct gs_meta_preprocessor
{
errors Errors;
gs_bucket<source_code_file> SourceFiles;
gs_bucket<token> Tokens;
gs_bucket<type_table_handle> TagList;
type_table TypeTable;
// Performance
s64 PreprocessorStartTime;
s64 TokenizeTime;
s64 PreprocTime;
s64 FixupTime;
s64 PreprocessorEndTime;
gsm_profiler Profiler;
};
// ------------------------ // ------------------------
// Timing / Performance // Timing / Performance
// ------------------------ // ------------------------
#if 0
internal s64 internal s64
GetWallClock () GetWallClock ()
{ {
@ -119,7 +70,7 @@ GetWallClock ()
} }
return (s64)Time.QuadPart; return (s64)Time.QuadPart;
} }
#endif
internal s64 internal s64
GetPerformanceFrequency () GetPerformanceFrequency ()
{ {
@ -274,6 +225,63 @@ PrintAllCategories(gsm_profiler* Profiler)
} }
} }
#include "gs_meta_lexer.h"
#include "gs_meta_error.h"
#include "gs_meta_type_table.h"
struct token_array
{
token* List;
u32 Count;
};
struct source_code_file
{
string Path;
s32 FileSize;
string Contents;
token_array Tokens;
};
struct token_iter
{
token_array Tokens;
token* TokenAt;
u32 TokenAtIndex;
#define TOKEN_ITER_SNAPSHOTS_MAX 64
u32 SnapshotsUsed;
u32 Snapshots[TOKEN_ITER_SNAPSHOTS_MAX];
errors* Errors;
};
struct gs_meta_preprocessor
{
memory_arena Permanent;
memory_arena Transient;
errors Errors;
gs_bucket<source_code_file> SourceFiles;
//gs_bucket<token> Tokens;
gs_bucket<type_table_handle> TagList;
type_table TypeTable;
// Performance
s64 PreprocessorStartTime;
s64 TokenizeTime;
s64 PreprocTime;
s64 FixupTime;
s64 PreprocessorEndTime;
gsm_profiler Profiler;
};
// ------------------------ // ------------------------
// Token Iterator // Token Iterator
// ------------------------ // ------------------------
@ -281,10 +289,10 @@ PrintAllCategories(gsm_profiler* Profiler)
internal token* internal token*
NextToken (token_iter* Iter) NextToken (token_iter* Iter)
{ {
if (Iter->TokenAtIndex < Iter->LastToken) DEBUG_TRACK_FUNCTION;
if (Iter->TokenAtIndex < Iter->Tokens.Count)
{ {
Iter->TokenAtIndex++; Iter->TokenAt = Iter->Tokens.List + Iter->TokenAtIndex++;
Iter->TokenAt = Iter->Tokens->GetElementAtIndex(Iter->TokenAtIndex);
} }
return Iter->TokenAt; return Iter->TokenAt;
@ -293,6 +301,7 @@ NextToken (token_iter* Iter)
internal b32 internal b32
TokenAtEquals(token_iter* Iter, char* String) TokenAtEquals(token_iter* Iter, char* String)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
if (StringEqualsCharArray(Iter->TokenAt->Text, String)) if (StringEqualsCharArray(Iter->TokenAt->Text, String))
{ {
@ -305,6 +314,7 @@ TokenAtEquals(token_iter* Iter, char* String)
internal b32 internal b32
TokenAtEquals(token_iter* Iter, token_type Type) TokenAtEquals(token_iter* Iter, token_type Type)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
if (Iter->TokenAt->Type == Type) if (Iter->TokenAt->Type == Type)
{ {
@ -317,6 +327,7 @@ TokenAtEquals(token_iter* Iter, token_type Type)
internal b32 internal b32
TokenAtEquals(token_iter* Iter, token_type Type, token* Token) TokenAtEquals(token_iter* Iter, token_type Type, token* Token)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
if (Iter->TokenAt->Type == Type) if (Iter->TokenAt->Type == Type)
{ {
@ -330,12 +341,14 @@ TokenAtEquals(token_iter* Iter, token_type Type, token* Token)
internal void internal void
PushSnapshot (token_iter* Iter) PushSnapshot (token_iter* Iter)
{ {
DEBUG_TRACK_FUNCTION;
Iter->Snapshots[Iter->SnapshotsUsed++] = Iter->TokenAtIndex; Iter->Snapshots[Iter->SnapshotsUsed++] = Iter->TokenAtIndex;
} }
internal void internal void
PopSnapshot (token_iter* Iter) PopSnapshot (token_iter* Iter)
{ {
DEBUG_TRACK_FUNCTION;
if (Iter->SnapshotsUsed > 0) if (Iter->SnapshotsUsed > 0)
{ {
Iter->SnapshotsUsed -= 1; Iter->SnapshotsUsed -= 1;
@ -345,15 +358,17 @@ PopSnapshot (token_iter* Iter)
internal void internal void
ApplySnapshot (token_iter* Iter) ApplySnapshot (token_iter* Iter)
{ {
DEBUG_TRACK_FUNCTION;
u32 SnapshotIndex = Iter->SnapshotsUsed; u32 SnapshotIndex = Iter->SnapshotsUsed;
u32 SnapshotPoint = Iter->Snapshots[SnapshotIndex]; u32 SnapshotPoint = Iter->Snapshots[SnapshotIndex];
Iter->TokenAtIndex = SnapshotPoint; Iter->TokenAtIndex = SnapshotPoint;
Iter->TokenAt = Iter->Tokens->GetElementAtIndex(SnapshotPoint); Iter->TokenAt = Iter->Tokens.List + Iter->TokenAtIndex;
} }
internal void internal void
ApplySnapshotIfNotParsedAndPop(b32 ParseSuccess, token_iter* Iter) ApplySnapshotIfNotParsedAndPop(b32 ParseSuccess, token_iter* Iter)
{ {
DEBUG_TRACK_FUNCTION;
PopSnapshot(Iter); PopSnapshot(Iter);
if (!ParseSuccess) if (!ParseSuccess)
{ {
@ -365,6 +380,7 @@ ApplySnapshotIfNotParsedAndPop(b32 ParseSuccess, token_iter* Iter)
internal s32 internal s32
GetFileSize (char* FileName) GetFileSize (char* FileName)
{ {
DEBUG_TRACK_FUNCTION;
s32 Result = 0; s32 Result = 0;
FILE* ReadFile = fopen(FileName, "r"); FILE* ReadFile = fopen(FileName, "r");
@ -386,8 +402,9 @@ GetFileSize (char* FileName)
// ------------------------- // -------------------------
internal s32 internal s32
ReadEntireFileAndNullTerminate (source_code_file* File, errors* Errors) ReadEntireFileAndNullTerminate (memory_arena* Storage, source_code_file* File, errors* Errors)
{ {
DEBUG_TRACK_FUNCTION;
s32 LengthRead = 0; s32 LengthRead = 0;
FILE* ReadFile = fopen(File->Path.Memory, "r"); FILE* ReadFile = fopen(File->Path.Memory, "r");
@ -399,7 +416,7 @@ ReadEntireFileAndNullTerminate (source_code_file* File, errors* Errors)
Assert(File->Contents.Memory == 0); Assert(File->Contents.Memory == 0);
File->Contents.Max = (s32)FileSize + 1; File->Contents.Max = (s32)FileSize + 1;
File->Contents.Memory = (char*)malloc(File->Contents.Max); File->Contents.Memory = (char*)PushSize(Storage, File->Contents.Max);
size_t ReadSize = fread(File->Contents.Memory, 1, FileSize, ReadFile); size_t ReadSize = fread(File->Contents.Memory, 1, FileSize, ReadFile);
File->Contents.Memory[FileSize] = 0; File->Contents.Memory[FileSize] = 0;
@ -415,6 +432,7 @@ ReadEntireFileAndNullTerminate (source_code_file* File, errors* Errors)
internal b32 internal b32
FileAlreadyInSource(string Path, gs_bucket<source_code_file> SourceFiles) FileAlreadyInSource(string Path, gs_bucket<source_code_file> SourceFiles)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
for (u32 i = 0; i < SourceFiles.Used; i++) for (u32 i = 0; i < SourceFiles.Used; i++)
@ -431,19 +449,18 @@ FileAlreadyInSource(string Path, gs_bucket<source_code_file> SourceFiles)
} }
internal void internal void
AddFileToSource(string RelativePath, source_code_file CurrentFile, gs_bucket<source_code_file>* SourceFiles, errors* Errors) AddFileToSource(memory_arena* Storage, string RelativePath, source_code_file CurrentFile, gs_bucket<source_code_file>* SourceFiles, errors* Errors)
{ {
DEBUG_TRACK_FUNCTION;
source_code_file File = {0}; source_code_file File = {0};
File.FirstTokenIndex = -1;
File.LastTokenIndex = -1;
u32 PathLength = RelativePath.Length + 1; u32 PathLength = RelativePath.Length + 1;
File.Path = MakeString((char*)malloc(sizeof(char) * PathLength), 0, PathLength); char* PathData = PushArray(Storage, char, PathLength);
File.Path = MakeString(PathData, 0, PathLength);
CopyStringTo(RelativePath, &File.Path); CopyStringTo(RelativePath, &File.Path);
NullTerminate(&File.Path); NullTerminate(&File.Path);
File.FileSize = ReadEntireFileAndNullTerminate(&File, Errors); File.FileSize = ReadEntireFileAndNullTerminate(Storage, &File, Errors);
if (File.FileSize > 0) if (File.FileSize > 0)
{ {
@ -460,8 +477,21 @@ AddFileToSource(string RelativePath, source_code_file CurrentFile, gs_bucket<sou
} }
internal void internal void
TokenizeFile (source_code_file* File, gs_bucket<token>* Tokens) TokenizeFile (gs_meta_preprocessor* Meta, source_code_file* File)
{ {
DEBUG_TRACK_FUNCTION;
gsm_profiler_scope* Scope = BeginScope(&Meta->Profiler, MakeStringLiteral("tokenize"), File->Path);
struct token_list
{
token Token;
token_list* Next;
};
u32 TokensCount = 0;
token_list* TokensHead = 0;
token_list* TokensTail = 0;
tokenizer Tokenizer = {}; tokenizer Tokenizer = {};
Tokenizer.At = File->Contents.Memory; Tokenizer.At = File->Contents.Memory;
Tokenizer.Memory = File->Contents.Memory; Tokenizer.Memory = File->Contents.Memory;
@ -470,15 +500,35 @@ TokenizeFile (source_code_file* File, gs_bucket<token>* Tokens)
token* LastToken = 0; token* LastToken = 0;
while(AtValidPosition(Tokenizer)) while(AtValidPosition(Tokenizer))
{ {
token NewToken = GetNextToken(&Tokenizer); token_list* NewToken = PushStruct(&Meta->Transient, token_list);
u32 TokenIndex = Tokens->PushElementOnBucket(NewToken); NewToken->Token = GetNextToken(&Tokenizer);
if (File->FirstTokenIndex < 0) NewToken->Next = 0;
TokensCount++;
if (TokensHead != 0)
{ {
File->FirstTokenIndex = (s32)TokenIndex; TokensTail->Next = NewToken;
TokensTail = NewToken;
}
else
{
TokensHead = NewToken;
TokensTail = NewToken;
} }
} }
File->LastTokenIndex = Tokens->Used - 1; File->Tokens = {0};
File->Tokens.Count = TokensCount;
File->Tokens.List = PushArray(&Meta->Permanent, token, File->Tokens.Count);
token_list* At = TokensHead;
for (u32 i = 0; i < TokensCount; i++)
{
Assert(At != 0);
File->Tokens.List[i] = At->Token;
At = At->Next;
}
EndScope(Scope);
} }
// ------------------------ // ------------------------
@ -488,6 +538,7 @@ TokenizeFile (source_code_file* File, gs_bucket<token>* Tokens)
internal b32 internal b32
ParseMetaTag(token_iter* Iter, gs_meta_preprocessor* Meta) ParseMetaTag(token_iter* Iter, gs_meta_preprocessor* Meta)
{ {
DEBUG_TRACK_FUNCTION;
gsm_profiler_scope* ProfilerScope = BeginScope(&Meta->Profiler, gsm_profiler_scope* ProfilerScope = BeginScope(&Meta->Profiler,
MakeStringLiteral("parse"), MakeStringLiteral("parse"),
MakeStringLiteral("ParseMetaTag")); MakeStringLiteral("ParseMetaTag"));
@ -534,6 +585,7 @@ ParseMetaTag(token_iter* Iter, gs_meta_preprocessor* Meta)
internal b32 internal b32
ParseSignedness (token_iter* Iter) ParseSignedness (token_iter* Iter)
{ {
DEBUG_TRACK_FUNCTION;
// NOTE(Peter): This doesn't really do much at the moment, but // NOTE(Peter): This doesn't really do much at the moment, but
// I want all signedness parsing to happen in one place in case // I want all signedness parsing to happen in one place in case
// we ever need to do anything with it. // we ever need to do anything with it.
@ -552,6 +604,7 @@ ParseSignedness (token_iter* Iter)
internal b32 internal b32
ShortInt (token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTable) ShortInt (token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
PushSnapshot(Iter); PushSnapshot(Iter);
@ -576,6 +629,7 @@ ShortInt (token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTab
internal b32 internal b32
Int (token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTable) Int (token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
PushSnapshot(Iter); PushSnapshot(Iter);
@ -596,6 +650,7 @@ Int (token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTable)
internal b32 internal b32
LongInt (token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTable) LongInt (token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
PushSnapshot(Iter); PushSnapshot(Iter);
@ -620,6 +675,7 @@ LongInt (token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTabl
internal b32 internal b32
LongLongInt (token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTable) LongLongInt (token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
PushSnapshot(Iter); PushSnapshot(Iter);
@ -647,6 +703,7 @@ LongLongInt (token_iter* Iter, type_table_handle* TypeHandleOut, type_table Type
internal b32 internal b32
ParseChar(token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTable) ParseChar(token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
PushSnapshot(Iter); PushSnapshot(Iter);
@ -669,6 +726,7 @@ ParseChar(token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTab
internal b32 internal b32
ParseBool(token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTable) ParseBool(token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
PushSnapshot(Iter); PushSnapshot(Iter);
@ -685,6 +743,7 @@ ParseBool(token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTab
internal b32 internal b32
ParseFloat(token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTable) ParseFloat(token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
PushSnapshot(Iter); PushSnapshot(Iter);
@ -701,6 +760,7 @@ ParseFloat(token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTa
internal b32 internal b32
ParseDouble(token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTable) ParseDouble(token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
PushSnapshot(Iter); PushSnapshot(Iter);
@ -720,6 +780,7 @@ ParseDouble(token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeT
internal b32 internal b32
ParseType(token_iter* Iter, gs_meta_preprocessor* Meta, type_table_handle* TypeHandleOut) ParseType(token_iter* Iter, gs_meta_preprocessor* Meta, type_table_handle* TypeHandleOut)
{ {
DEBUG_TRACK_FUNCTION;
gsm_profiler_scope* ProfilerScope = BeginScope(&Meta->Profiler, gsm_profiler_scope* ProfilerScope = BeginScope(&Meta->Profiler,
MakeStringLiteral("parse"), MakeStringLiteral("parse"),
MakeStringLiteral("ParseType")); MakeStringLiteral("ParseType"));
@ -780,6 +841,7 @@ ParseType(token_iter* Iter, gs_meta_preprocessor* Meta, type_table_handle* TypeH
internal b32 internal b32
ParsePointer (token_iter* Iter) ParsePointer (token_iter* Iter)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
if (TokenAtEquals(Iter, "*")) if (TokenAtEquals(Iter, "*"))
{ {
@ -791,6 +853,7 @@ ParsePointer (token_iter* Iter)
internal b32 internal b32
ParseConstVolatile (token_iter* Iter) ParseConstVolatile (token_iter* Iter)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
PushSnapshot(Iter); PushSnapshot(Iter);
@ -807,6 +870,7 @@ ParseConstVolatile (token_iter* Iter)
internal b32 internal b32
ParseVariableDecl(token_iter* Iter, gs_bucket<variable_decl>* VariableList, gs_meta_preprocessor* Meta) ParseVariableDecl(token_iter* Iter, gs_bucket<variable_decl>* VariableList, gs_meta_preprocessor* Meta)
{ {
DEBUG_TRACK_FUNCTION;
gsm_profiler_scope* ProfilerScope = BeginScope(&Meta->Profiler, gsm_profiler_scope* ProfilerScope = BeginScope(&Meta->Profiler,
MakeStringLiteral("parse"), MakeStringLiteral("parse"),
MakeStringLiteral("ParseVariableDecl")); MakeStringLiteral("ParseVariableDecl"));
@ -934,6 +998,7 @@ ParseVariableDecl(token_iter* Iter, gs_bucket<variable_decl>* VariableList, gs_m
internal b32 internal b32
StructOrUnion(token_iter* Iter, type_definition_type* Type) StructOrUnion(token_iter* Iter, type_definition_type* Type)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
if (TokenAtEquals(Iter, "struct")) if (TokenAtEquals(Iter, "struct"))
{ {
@ -954,6 +1019,7 @@ StructOrUnion(token_iter* Iter, type_definition_type* Type)
internal b32 internal b32
ParseStruct(token_iter* Iter, type_table_handle* StructTypeHandleOut, gs_meta_preprocessor* Meta, type_definition* ContainingStruct = 0) ParseStruct(token_iter* Iter, type_table_handle* StructTypeHandleOut, gs_meta_preprocessor* Meta, type_definition* ContainingStruct = 0)
{ {
DEBUG_TRACK_FUNCTION;
gsm_profiler_scope* ProfilerScope = BeginScope(&Meta->Profiler, gsm_profiler_scope* ProfilerScope = BeginScope(&Meta->Profiler,
MakeStringLiteral("parse"), MakeStringLiteral("parse"),
MakeStringLiteral("ParseStruct")); MakeStringLiteral("ParseStruct"));
@ -988,7 +1054,7 @@ ParseStruct(token_iter* Iter, type_table_handle* StructTypeHandleOut, gs_meta_pr
string AnonStructIdentifier = {}; string AnonStructIdentifier = {};
AnonStructIdentifier.Max = 256; AnonStructIdentifier.Max = 256;
AnonStructIdentifier.Memory = (char*)malloc(sizeof(char) * AnonStructIdentifier.Max); AnonStructIdentifier.Memory = PushArray(&Meta->Permanent, char, AnonStructIdentifier.Max);
PrintF(&AnonStructIdentifier, "%S_%d", ContainingStruct->Identifier, ContainingStruct->Struct.MemberDecls.Used); PrintF(&AnonStructIdentifier, "%S_%d", ContainingStruct->Identifier, ContainingStruct->Struct.MemberDecls.Used);
@ -1053,6 +1119,7 @@ ParseStruct(token_iter* Iter, type_table_handle* StructTypeHandleOut, gs_meta_pr
internal b32 internal b32
ParseFunctionParameterList (token_iter* Iter, type_definition* FunctionPtrDecl, gs_meta_preprocessor* Meta) ParseFunctionParameterList (token_iter* Iter, type_definition* FunctionPtrDecl, gs_meta_preprocessor* Meta)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
PushSnapshot(Iter); PushSnapshot(Iter);
@ -1088,6 +1155,7 @@ ParseFunctionParameterList (token_iter* Iter, type_definition* FunctionPtrDecl,
internal b32 internal b32
ParseFunctionDeclaration (token_iter* Iter, token* Identifier, gs_meta_preprocessor* Meta) ParseFunctionDeclaration (token_iter* Iter, token* Identifier, gs_meta_preprocessor* Meta)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
PushSnapshot(Iter); PushSnapshot(Iter);
@ -1135,6 +1203,7 @@ ParseFunctionDeclaration (token_iter* Iter, token* Identifier, gs_meta_preproces
internal b32 internal b32
ParseTypedef(token_iter* Iter, gs_meta_preprocessor* Meta) ParseTypedef(token_iter* Iter, gs_meta_preprocessor* Meta)
{ {
DEBUG_TRACK_FUNCTION;
gsm_profiler_scope* ProfilerScope = BeginScope(&Meta->Profiler, gsm_profiler_scope* ProfilerScope = BeginScope(&Meta->Profiler,
MakeStringLiteral("parse"), MakeStringLiteral("parse"),
MakeStringLiteral("ParseTypedef")); MakeStringLiteral("ParseTypedef"));
@ -1207,6 +1276,7 @@ ParseTypedef(token_iter* Iter, gs_meta_preprocessor* Meta)
internal b32 internal b32
ParseEnum (token_iter* Iter, gs_meta_preprocessor* Meta) ParseEnum (token_iter* Iter, gs_meta_preprocessor* Meta)
{ {
DEBUG_TRACK_FUNCTION;
gsm_profiler_scope* ProfilerScope = BeginScope(&Meta->Profiler, gsm_profiler_scope* ProfilerScope = BeginScope(&Meta->Profiler,
MakeStringLiteral("parse"), MakeStringLiteral("parse"),
MakeStringLiteral("ParseEnum")); MakeStringLiteral("ParseEnum"));
@ -1293,6 +1363,8 @@ ParseEnum (token_iter* Iter, gs_meta_preprocessor* Meta)
internal b32 internal b32
ParseFunction (token_iter* Iter, gs_meta_preprocessor* Meta) ParseFunction (token_iter* Iter, gs_meta_preprocessor* Meta)
{ {
DEBUG_TRACK_FUNCTION;
gsm_profiler_scope* ProfilerScope = BeginScope(&Meta->Profiler, gsm_profiler_scope* ProfilerScope = BeginScope(&Meta->Profiler,
MakeStringLiteral("parse"), MakeStringLiteral("parse"),
MakeStringLiteral("ParseFunction")); MakeStringLiteral("ParseFunction"));
@ -1346,6 +1418,8 @@ ParseFunction (token_iter* Iter, gs_meta_preprocessor* Meta)
internal void internal void
PrintIndent (u32 Indent) PrintIndent (u32 Indent)
{ {
DEBUG_TRACK_FUNCTION;
for (u32 i = 0; i < Indent; i++) for (u32 i = 0; i < Indent; i++)
{ {
printf(" "); printf(" ");
@ -1357,6 +1431,8 @@ internal void PrintStructDecl (type_definition* StructDecl, type_table TypeTable
internal void internal void
PrintVariableDecl (variable_decl Member, type_table TypeTable, u32 Indent = 0) PrintVariableDecl (variable_decl Member, type_table TypeTable, u32 Indent = 0)
{ {
DEBUG_TRACK_FUNCTION;
type_definition* MemberTypeDef = GetTypeDefinition(Member.TypeHandle, TypeTable); type_definition* MemberTypeDef = GetTypeDefinition(Member.TypeHandle, TypeTable);
if ((MemberTypeDef->Type == TypeDef_Struct || MemberTypeDef->Type == TypeDef_Union) if ((MemberTypeDef->Type == TypeDef_Struct || MemberTypeDef->Type == TypeDef_Union)
&& MemberTypeDef->Identifier.Length == 0) && MemberTypeDef->Identifier.Length == 0)
@ -1389,6 +1465,8 @@ PrintVariableDecl (variable_decl Member, type_table TypeTable, u32 Indent = 0)
internal void internal void
PrintStructDecl (type_definition* StructDecl, type_table TypeTable, u32 Indent = 0) PrintStructDecl (type_definition* StructDecl, type_table TypeTable, u32 Indent = 0)
{ {
DEBUG_TRACK_FUNCTION;
Assert(StructDecl->Type == TypeDef_Struct || Assert(StructDecl->Type == TypeDef_Struct ||
StructDecl->Type == TypeDef_Union); StructDecl->Type == TypeDef_Union);
@ -1422,6 +1500,8 @@ PrintStructDecl (type_definition* StructDecl, type_table TypeTable, u32 Indent =
internal void internal void
PrintFunctionPtrDecl (type_definition* FnPtrDecl, type_table TypeTable) PrintFunctionPtrDecl (type_definition* FnPtrDecl, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
type_definition* ReturnType = GetTypeDefinition(FnPtrDecl->FunctionPtr.ReturnTypeHandle, TypeTable); type_definition* ReturnType = GetTypeDefinition(FnPtrDecl->FunctionPtr.ReturnTypeHandle, TypeTable);
printf("%.*s ", StringExpand(ReturnType->Identifier)); printf("%.*s ", StringExpand(ReturnType->Identifier));
@ -1442,9 +1522,19 @@ PrintFunctionPtrDecl (type_definition* FnPtrDecl, type_table TypeTable)
} }
internal gs_meta_preprocessor internal gs_meta_preprocessor
PreprocessProgram (char* SourceFile) PreprocessProgram (base_allocator Allocator, char* SourceFile)
{ {
GlobalDebugServices.Arena = CreateMemoryArena(Allocator);
GlobalDebugServices.Transient = CreateMemoryArena(Allocator);
DEBUG_TRACK_FUNCTION;
gs_meta_preprocessor Meta = {}; gs_meta_preprocessor Meta = {};
Meta.Permanent = CreateMemoryArena(Allocator);
Meta.Transient = CreateMemoryArena(Allocator);
Meta.Errors.Arena = CreateMemoryArena(Allocator);
Meta.TypeTable.Arena = CreateMemoryArena(Allocator);
gsm_profiler_scope* TotalScope = BeginScope(&Meta.Profiler, "total", "total"); gsm_profiler_scope* TotalScope = BeginScope(&Meta.Profiler, "total", "total");
@ -1452,10 +1542,10 @@ PreprocessProgram (char* SourceFile)
PopulateTableWithDefaultCPPTypes(&Meta.TypeTable); PopulateTableWithDefaultCPPTypes(&Meta.TypeTable);
string CurrentWorkingDirectory = MakeString((char*)malloc(1024), 0, 1024); string CurrentWorkingDirectory = MakeString(PushArray(&Meta.Permanent, char, 1024), 0, 1024);
string RootFile = MakeString(SourceFile); string RootFile = MakeString(SourceFile);
AddFileToSource(RootFile, {}, &Meta.SourceFiles, &Meta.Errors); AddFileToSource(&Meta.Permanent, RootFile, {}, &Meta.SourceFiles, &Meta.Errors);
s32 LastSlash = ReverseSearchForCharInSet(RootFile, "\\/"); s32 LastSlash = ReverseSearchForCharInSet(RootFile, "\\/");
if (LastSlash <= 0) if (LastSlash <= 0)
@ -1475,24 +1565,18 @@ PreprocessProgram (char* SourceFile)
MakeStringLiteral("file"), MakeStringLiteral("file"),
File->Path); File->Path);
gsm_profiler_scope* TokenizeScope = BeginScope(&Meta.Profiler, TokenizeFile(&Meta, File);
MakeStringLiteral("tokenize"),
File->Path);
TokenizeFile(File, &Meta.Tokens);
EndScope(TokenizeScope);
gsm_profiler_scope* PreprocScope = BeginScope(&Meta.Profiler, gsm_profiler_scope* PreprocScope = BeginScope(&Meta.Profiler,
MakeStringLiteral("preproc"), MakeStringLiteral("preproc"),
File->Path); File->Path);
token_iter Iter = {}; token_iter Iter = {};
Iter.Tokens = &Meta.Tokens; Iter.Tokens = File->Tokens;
Iter.FirstToken = File->FirstTokenIndex; Iter.TokenAtIndex = 0;
Iter.LastToken = File->LastTokenIndex; Iter.TokenAt = File->Tokens.List + Iter.TokenAtIndex;
Iter.TokenAtIndex = Iter.FirstToken;
Iter.TokenAt = Meta.Tokens.GetElementAtIndex(Iter.TokenAtIndex);
Iter.Errors = &Meta.Errors; Iter.Errors = &Meta.Errors;
while (Iter.TokenAtIndex < Iter.LastToken) while (Iter.TokenAtIndex < Iter.Tokens.Count)
{ {
b32 ParseSuccess = false; b32 ParseSuccess = false;
@ -1527,7 +1611,7 @@ PreprocessProgram (char* SourceFile)
ParseSuccess = true; ParseSuccess = true;
if (!FileAlreadyInSource(TempFilePath, Meta.SourceFiles)) if (!FileAlreadyInSource(TempFilePath, Meta.SourceFiles))
{ {
AddFileToSource(TempFilePath, *File, &Meta.SourceFiles, &Meta.Errors); AddFileToSource(&Meta.Permanent, TempFilePath, *File, &Meta.SourceFiles, &Meta.Errors);
} }
EndScope(IncludeScope); EndScope(IncludeScope);
} }
@ -1600,6 +1684,8 @@ PreprocessProgram (char* SourceFile)
internal void internal void
FinishMetaprogram(gs_meta_preprocessor* Meta) FinishMetaprogram(gs_meta_preprocessor* Meta)
{ {
CollateFrame(&GlobalDebugServices);
FinishProfiler(&Meta->Profiler); FinishProfiler(&Meta->Profiler);
PrintAllErrors(Meta->Errors); PrintAllErrors(Meta->Errors);

View File

@ -37,12 +37,12 @@ struct gsm_code_generator
// --------------- // ---------------
internal gsm_code_generator internal gsm_code_generator
BeginEnumGeneration(string EnumIdentifier, string ValuePrefix, b32 StartsWithInvalid, b32 EndsWithCount) BeginEnumGeneration(memory_arena* Storage, string EnumIdentifier, string ValuePrefix, b32 StartsWithInvalid, b32 EndsWithCount)
{ {
gsm_code_generator Gen = {}; gsm_code_generator Gen = {};
// TODO(Peter): TEMP!! // TODO(Peter): TEMP!!
Gen.Builder = (string_builder*)malloc(sizeof(string_builder)); Gen.Builder = PushStruct(Storage, string_builder);
*Gen.Builder = {}; *Gen.Builder = {};
Gen.Type = gsm_CodeGen_Enum; Gen.Type = gsm_CodeGen_Enum;
@ -60,9 +60,9 @@ BeginEnumGeneration(string EnumIdentifier, string ValuePrefix, b32 StartsWithInv
} }
internal gsm_code_generator internal gsm_code_generator
BeginEnumGeneration(char* EnumIdentifier, char* ValuePrefix, b32 StartsWithInvalid, b32 EndsWithCount) BeginEnumGeneration(memory_arena* Storage, char* EnumIdentifier, char* ValuePrefix, b32 StartsWithInvalid, b32 EndsWithCount)
{ {
return BeginEnumGeneration(MakeStringLiteral(EnumIdentifier), return BeginEnumGeneration(Storage, MakeStringLiteral(EnumIdentifier),
MakeStringLiteral(ValuePrefix), MakeStringLiteral(ValuePrefix),
StartsWithInvalid, StartsWithInvalid,
EndsWithCount); EndsWithCount);

View File

@ -9,6 +9,7 @@ struct error_buffer
#define ERROR_BUFFER_SIZE 256 #define ERROR_BUFFER_SIZE 256
struct errors struct errors
{ {
memory_arena Arena;
error_buffer* Buffers; error_buffer* Buffers;
u32 BuffersCount; u32 BuffersCount;
u32 Used; u32 Used;
@ -23,8 +24,8 @@ PushFError (errors* Errors, char* Format, ...)
Errors->Buffers = (error_buffer*)realloc(Errors->Buffers, sizeof(error_buffer*) * Errors->BuffersCount); Errors->Buffers = (error_buffer*)realloc(Errors->Buffers, sizeof(error_buffer*) * Errors->BuffersCount);
error_buffer* NewBuffer = Errors->Buffers + (Errors->BuffersCount - 1); error_buffer* NewBuffer = Errors->Buffers + (Errors->BuffersCount - 1);
NewBuffer->Backbuffer = (char*)malloc(sizeof(char) * ERROR_MAX_LENGTH * ERROR_BUFFER_SIZE); NewBuffer->Backbuffer = PushArray(&Errors->Arena, char, ERROR_MAX_LENGTH * ERROR_BUFFER_SIZE);
NewBuffer->Contents = (string*)malloc(sizeof(string) * ERROR_BUFFER_SIZE); NewBuffer->Contents = PushArray(&Errors->Arena, string, ERROR_BUFFER_SIZE);
for (u32 i = 0; i < ERROR_BUFFER_SIZE; i++) for (u32 i = 0; i < ERROR_BUFFER_SIZE; i++)
{ {

View File

@ -141,6 +141,8 @@ struct meta_tag_hash_bucket
struct type_table struct type_table
{ {
memory_arena Arena;
type_table_hash_bucket* Types; type_table_hash_bucket* Types;
u32 TypeBucketsCount; u32 TypeBucketsCount;
@ -292,8 +294,8 @@ FindSlotForTypeIdentifier(u32 IdentHash, type_table* TypeTable)
TypeTable->Types = (type_table_hash_bucket*)realloc(TypeTable->Types, NewTypesSize); TypeTable->Types = (type_table_hash_bucket*)realloc(TypeTable->Types, NewTypesSize);
type_table_hash_bucket* NewBucket = TypeTable->Types + NewTypeBucketIndex; type_table_hash_bucket* NewBucket = TypeTable->Types + NewTypeBucketIndex;
NewBucket->Keys = (u32*)malloc(sizeof(u32) * TYPE_TABLE_BUCKET_MAX); NewBucket->Keys = PushArray(&TypeTable->Arena, u32, TYPE_TABLE_BUCKET_MAX);
NewBucket->Values = (type_definition*)malloc(sizeof(type_definition) * TYPE_TABLE_BUCKET_MAX); NewBucket->Values = PushArray(&TypeTable->Arena, type_definition, TYPE_TABLE_BUCKET_MAX);
GSZeroMemory((u8*)NewBucket->Keys, sizeof(u32) * TYPE_TABLE_BUCKET_MAX); GSZeroMemory((u8*)NewBucket->Keys, sizeof(u32) * TYPE_TABLE_BUCKET_MAX);
GSZeroMemory((u8*)NewBucket->Values, sizeof(type_definition) * TYPE_TABLE_BUCKET_MAX); GSZeroMemory((u8*)NewBucket->Values, sizeof(type_definition) * TYPE_TABLE_BUCKET_MAX);
@ -331,8 +333,8 @@ FindSlotForMetaTag(u32 IdentHash, type_table* TypeTable)
TypeTable->MetaTags = (meta_tag_hash_bucket*)realloc(TypeTable->MetaTags, NewMetaBucketListSize); TypeTable->MetaTags = (meta_tag_hash_bucket*)realloc(TypeTable->MetaTags, NewMetaBucketListSize);
meta_tag_hash_bucket* NewBucket = TypeTable->MetaTags + NewMetaBucketIndex; meta_tag_hash_bucket* NewBucket = TypeTable->MetaTags + NewMetaBucketIndex;
NewBucket->Keys = (u32*)malloc(sizeof(u32) * TYPE_TABLE_BUCKET_MAX); NewBucket->Keys = PushArray(&TypeTable->Arena, u32, TYPE_TABLE_BUCKET_MAX);
NewBucket->Values = (meta_tag*)malloc(sizeof(meta_tag) * TYPE_TABLE_BUCKET_MAX); NewBucket->Values = PushArray(&TypeTable->Arena, meta_tag, TYPE_TABLE_BUCKET_MAX);
GSZeroMemory((u8*)NewBucket->Keys, sizeof(u32) * TYPE_TABLE_BUCKET_MAX); GSZeroMemory((u8*)NewBucket->Keys, sizeof(u32) * TYPE_TABLE_BUCKET_MAX);
GSZeroMemory((u8*)NewBucket->Values, sizeof(meta_tag) * TYPE_TABLE_BUCKET_MAX); GSZeroMemory((u8*)NewBucket->Values, sizeof(meta_tag) * TYPE_TABLE_BUCKET_MAX);

View File

@ -31,15 +31,15 @@ struct typeinfo_generator
#define TypeHandleToIndex(handle) ((handle.BucketIndex * TYPE_TABLE_BUCKET_MAX) + handle.IndexInBucket) #define TypeHandleToIndex(handle) ((handle.BucketIndex * TYPE_TABLE_BUCKET_MAX) + handle.IndexInBucket)
internal typeinfo_generator internal typeinfo_generator
InitTypeInfoGenerator(type_table TypeTable) InitTypeInfoGenerator(type_table* TypeTable)
{ {
typeinfo_generator Result = {}; typeinfo_generator Result = {};
Result.TypesMax = TypeTable.TypeBucketsCount * TYPE_TABLE_BUCKET_MAX; Result.TypesMax = TypeTable->TypeBucketsCount * TYPE_TABLE_BUCKET_MAX;
Result.TypesGeneratedMask = (b8*)malloc(sizeof(b8) * Result.TypesMax); Result.TypesGeneratedMask = PushArray(&TypeTable->Arena, b8, Result.TypesMax);
GSZeroMemory((u8*)Result.TypesGeneratedMask, Result.TypesMax); GSZeroMemory((u8*)Result.TypesGeneratedMask, Result.TypesMax);
Result.TypeList = BeginEnumGeneration("gsm_struct_type", "gsm_StructType", false, true); Result.TypeList = BeginEnumGeneration(&TypeTable->Arena, "gsm_struct_type", "gsm_StructType", false, true);
WriteF(&Result.TypeDefinitions, "static gsm_struct_type_info StructTypes[] = {\n"); WriteF(&Result.TypeDefinitions, "static gsm_struct_type_info StructTypes[] = {\n");
return Result; return Result;

View File

@ -3,6 +3,28 @@ TODO FOLDHAUS
STREAM #0: Metaprogramming STREAM #0: Metaprogramming
- Metaprogramming - Metaprogramming
- fix memory layout (remeber to profile before and after) - fix memory layout (remeber to profile before and after)
- use a base_allocator struct to track allocations to begin with
- introduce memory_arenas
- get rid of gs_bucket and gs_list or whatever, just use custom bucket lists
Profile 0:
Total Allocated Space: 1186150 bytes, or 1.131201 MB
Total Time: 0.062665 seconds
Profile 1:
Total Allocated Space: 1217890 bytes, or 1.161470 MB
Total Time: 0.061852 seconds
- convert gs_memory_arena to using 64 bit integers
- investigate centralizing type table type creation in a similar place, rather than scattered all over
- Make everything truly platform agnostic - Make everything truly platform agnostic
- Application DLL - Application DLL
- math.h: present for trig functions (though this is part of the c-std lib, so it should be everywhere) - math.h: present for trig functions (though this is part of the c-std lib, so it should be everywhere)