Converted many of the TokenAtEquals calls in gs_meta to TokenAtHashEquals

This commit is contained in:
Peter Slattery 2020-05-12 19:07:09 -07:00
parent 142fc72357
commit 287d305137
8 changed files with 300 additions and 123 deletions

View File

@ -1,37 +1,7 @@
enum gsm_meta_tag_type enum gsm_meta_tag_type
{ {
MetaTag_panel_type_file_view,
MetaTag_panel_type_node_graph,
MetaTag_node_output,
MetaTag_node_struct,
MetaTag_panel_cleanup,
MetaTag_node_input,
MetaTag_panel_init,
MetaTag_panel_type_animation_timeline,
MetaTag_panel_commands,
MetaTag_panel_type_sculpture_view,
MetaTag_node_proc,
MetaTag_panel_type_hierarchy,
MetaTag_panel_type_profiler,
MetaTag_panel_render,
MetaTag_panel_type_dmx_view,
}; };
gsm_meta_tag MetaTagStrings[] = { gsm_meta_tag MetaTagStrings[] = {
{ "panel_type_file_view", 20 },
{ "panel_type_node_graph", 21 },
{ "node_output", 11 },
{ "node_struct", 11 },
{ "panel_cleanup", 13 },
{ "node_input", 10 },
{ "panel_init", 10 },
{ "panel_type_animation_timeline", 29 },
{ "panel_commands", 14 },
{ "panel_type_sculpture_view", 25 },
{ "node_proc", 9 },
{ "panel_type_hierarchy", 20 },
{ "panel_type_profiler", 19 },
{ "panel_render", 12 },
{ "panel_type_dmx_view", 19 },
}; };
enum gsm_struct_type enum gsm_struct_type
{ {

View File

@ -66,6 +66,7 @@ struct debug_services
{ {
memory_arena Arena; memory_arena Arena;
memory_arena Transient; memory_arena Transient;
bool ShouldProfile;
u32 CollatedScopesCount; u32 CollatedScopesCount;
collated_scopes_hash_table* CollatedScopes; collated_scopes_hash_table* CollatedScopes;
@ -161,22 +162,33 @@ PushScopeOnList(debug_services* Services, char* ScopeName, s64 Start, s64 End)
NewRecord->EndTime = End; NewRecord->EndTime = End;
} }
#define DEBUG_TRACK_FUNCTION scope_tracker ScopeTracker ((char*)__func__) #define DEBUG_TRACK_FUNCTION scope_tracker ScopeTracker ((char*)__func__, &GlobalDebugServices)
struct scope_tracker struct scope_tracker
{ {
s64 ScopeStart; s64 ScopeStart;
char* ScopeName; char* ScopeName;
debug_services* Services;
scope_tracker(char* ScopeName) scope_tracker(char* ScopeName, debug_services* Services)
{ {
this->ScopeName = ScopeName; if (Services && Services->ShouldProfile)
this->ScopeStart = GetWallClock(); {
this->ScopeName = ScopeName;
this->ScopeStart = GetWallClock();
this->Services = Services;
}
else
{
this->Services = 0;
}
} }
~scope_tracker() ~scope_tracker()
{ {
s64 ScopeEnd = GetWallClock(); if (this->Services != 0)
PushScopeOnList(&GlobalDebugServices, this->ScopeName, this->ScopeStart, ScopeEnd); {
s64 ScopeEnd = GetWallClock();
PushScopeOnList(&GlobalDebugServices, this->ScopeName, this->ScopeStart, ScopeEnd);
}
} }
}; };
@ -243,14 +255,19 @@ CollateFrame(debug_services* Services)
RadixSortInPlace(SortList, SortListCount); RadixSortInPlace(SortList, SortListCount);
for (u32 i = 0; i < SortListCount; i++) for (s32 i = SortListCount - 1; i >= 0; i--)
{ {
u64 Hash = SortList[i].ID; u64 Hash = SortList[i].ID;
collated_scope_record* ScopeData = GetCollatedRecordForScope(Services, Hash); collated_scope_record* ScopeData = GetCollatedRecordForScope(Services, Hash);
u64 AverageDuration = ScopeData->TotalCycles / ScopeData->CallCount;
printf("Scope: %s\n", ScopeData->Identifier); printf("Scope: %s\n", ScopeData->Identifier);
printf(" Call Count: %lld\n", ScopeData->CallCount); printf(" %d / %d\n", SortListCount - i, SortListCount);
printf(" Total Cycles: %lld\n", ScopeData->TotalCycles); printf(" Total Cycles: %lld\n", ScopeData->TotalCycles);
printf(" Call Count: %lld\n", ScopeData->CallCount);
printf(" Longest Duration: %lld\n", ScopeData->LongestDuration); printf(" Longest Duration: %lld\n", ScopeData->LongestDuration);
printf(" Average Duration: %lld\n", AverageDuration);
} }
} }

View File

@ -114,6 +114,7 @@ struct token
{ {
token_type Type; token_type Type;
u32 LineNumber; u32 LineNumber;
u64 TextHash;
string Text; string Text;
token* Next; // TODO(Peter): Get rid of this token* Next; // TODO(Peter): Get rid of this
}; };
@ -376,6 +377,7 @@ GSPow (float N, s32 Power)
static void static void
InitializeEmptyString (string* String, char* Data, s32 DataSize) InitializeEmptyString (string* String, char* Data, s32 DataSize)
{ {
DEBUG_TRACK_FUNCTION;
String->Memory = Data; String->Memory = Data;
String->Max = DataSize; String->Max = DataSize;
String->Length = 0; String->Length = 0;
@ -384,6 +386,7 @@ InitializeEmptyString (string* String, char* Data, s32 DataSize)
static void static void
InitializeString(string* String, char* Data, s32 Used, s32 Max) InitializeString(string* String, char* Data, s32 Used, s32 Max)
{ {
DEBUG_TRACK_FUNCTION;
String->Memory = Data; String->Memory = Data;
String->Max = Max; String->Max = Max;
String->Length = Used; String->Length = Used;
@ -392,6 +395,7 @@ InitializeString(string* String, char* Data, s32 Used, s32 Max)
static string static string
InitializeEmptyString (char* Data, s32 DataSize) InitializeEmptyString (char* Data, s32 DataSize)
{ {
DEBUG_TRACK_FUNCTION;
string Result = {}; string Result = {};
Result.Memory = Data; Result.Memory = Data;
Result.Max = DataSize; Result.Max = DataSize;
@ -402,6 +406,7 @@ InitializeEmptyString (char* Data, s32 DataSize)
static string static string
InitializeString (char* Data, s32 Used, s32 Max) InitializeString (char* Data, s32 Used, s32 Max)
{ {
DEBUG_TRACK_FUNCTION;
string Result = {}; string Result = {};
Result.Memory = Data; Result.Memory = Data;
Result.Max = Max; Result.Max = Max;
@ -412,6 +417,7 @@ InitializeString (char* Data, s32 Used, s32 Max)
static void static void
ClearString (string* String) ClearString (string* String)
{ {
DEBUG_TRACK_FUNCTION;
String->Memory = 0; String->Memory = 0;
String->Max = 0; String->Max = 0;
String->Length = 0; String->Length = 0;
@ -427,31 +433,38 @@ static bool IsWhitespace (char C) { return (C == ' ') || (C == '\t'); }
static bool IsNewlineOrWhitespace (char C) { return (IsWhitespace(C) || IsNewline(C)); } static bool IsNewlineOrWhitespace (char C) { return (IsWhitespace(C) || IsNewline(C)); }
static bool IsAlpha (char C) static bool IsAlpha (char C)
{ {
DEBUG_TRACK_FUNCTION;
// TODO(Peter): support UTF8 chars // TODO(Peter): support UTF8 chars
return ((C >= 'A') && (C <= 'Z')) || ((C >= 'a') && (C <= 'z')) || (C == '_'); return ((C >= 'A') && (C <= 'Z')) || ((C >= 'a') && (C <= 'z')) || (C == '_');
} }
static bool IsUpper (char C) static bool IsUpper (char C)
{ {
DEBUG_TRACK_FUNCTION;
return ((C >= 'A') && (C <= 'Z')); return ((C >= 'A') && (C <= 'Z'));
} }
static bool IsLower (char C) static bool IsLower (char C)
{ {
DEBUG_TRACK_FUNCTION;
return ((C >= 'a') && (C <= 'z')); return ((C >= 'a') && (C <= 'z'));
} }
static bool IsNumeric (char C) static bool IsNumeric (char C)
{ {
DEBUG_TRACK_FUNCTION;
return (C >= '0') && (C <= '9'); return (C >= '0') && (C <= '9');
} }
static bool IsNumericExtended (char C) static bool IsNumericExtended (char C)
{ {
DEBUG_TRACK_FUNCTION;
return (IsNumeric(C) || (C == 'x') || (C == 'f') || (C == '.')); return (IsNumeric(C) || (C == 'x') || (C == 'f') || (C == '.'));
} }
static bool IsAlphaNumeric (char C) static bool IsAlphaNumeric (char C)
{ {
DEBUG_TRACK_FUNCTION;
return IsAlpha(C) || IsNumeric(C); return IsAlpha(C) || IsNumeric(C);
} }
static bool IsOperator (char C) static bool IsOperator (char C)
{ {
DEBUG_TRACK_FUNCTION;
return ((C == '+') || return ((C == '+') ||
(C == '-') || (C == '-') ||
(C == '*') || (C == '*') ||
@ -463,6 +476,7 @@ static bool IsOperator (char C)
} }
static char ToUpper (char A) static char ToUpper (char A)
{ {
DEBUG_TRACK_FUNCTION;
char Result = A; char Result = A;
if (IsLower(A)) if (IsLower(A))
{ {
@ -472,6 +486,7 @@ static char ToUpper (char A)
} }
static char ToLower (char A) static char ToLower (char A)
{ {
DEBUG_TRACK_FUNCTION;
char Result = A; char Result = A;
if (IsUpper(A)) if (IsUpper(A))
{ {
@ -481,6 +496,7 @@ static char ToLower (char A)
} }
static bool CharsEqualCaseInsensitive (char A, char B) static bool CharsEqualCaseInsensitive (char A, char B)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = (ToLower(A) == ToLower(B)); b32 Result = (ToLower(A) == ToLower(B));
return Result; return Result;
} }
@ -492,6 +508,7 @@ static bool CharsEqualCaseInsensitive (char A, char B)
static void static void
EatChar (tokenizer* T) EatChar (tokenizer* T)
{ {
DEBUG_TRACK_FUNCTION;
if (AtValidPosition(*T)) if (AtValidPosition(*T))
{ {
if (IsNewline(*T->At)) if (IsNewline(*T->At))
@ -510,6 +527,7 @@ EatChar (tokenizer* T)
static b32 static b32
AtValidPosition (tokenizer Tokenizer) AtValidPosition (tokenizer Tokenizer)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = (Tokenizer.At - Tokenizer.Memory) <= Tokenizer.MemoryLength; b32 Result = (Tokenizer.At - Tokenizer.Memory) <= Tokenizer.MemoryLength;
return Result; return Result;
} }
@ -517,6 +535,7 @@ AtValidPosition (tokenizer Tokenizer)
static b32 static b32
AtValidToken(tokenizer Tokenizer) AtValidToken(tokenizer Tokenizer)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = *Tokenizer.At && Tokenizer.At < (Tokenizer.Memory + Tokenizer.MemoryLength); b32 Result = *Tokenizer.At && Tokenizer.At < (Tokenizer.Memory + Tokenizer.MemoryLength);
return Result; return Result;
} }
@ -524,6 +543,7 @@ AtValidToken(tokenizer Tokenizer)
static char* static char*
EatToNewLine(char* C) EatToNewLine(char* C)
{ {
DEBUG_TRACK_FUNCTION;
char* Result = C; char* Result = C;
while (*Result && !IsNewline(*Result)) while (*Result && !IsNewline(*Result))
{ {
@ -535,6 +555,7 @@ EatToNewLine(char* C)
static s32 static s32
EatToNewLine(tokenizer* T) EatToNewLine(tokenizer* T)
{ {
DEBUG_TRACK_FUNCTION;
char* TStart = T->At; char* TStart = T->At;
while (AtValidPosition(*T) && !IsNewline(*T->At)) while (AtValidPosition(*T) && !IsNewline(*T->At))
{ {
@ -546,6 +567,7 @@ EatToNewLine(tokenizer* T)
static char* static char*
EatPastNewLine(char* C) EatPastNewLine(char* C)
{ {
DEBUG_TRACK_FUNCTION;
char* Result = EatToNewLine(C); char* Result = EatToNewLine(C);
while(*Result && IsNewline(*Result)) while(*Result && IsNewline(*Result))
{ {
@ -557,6 +579,7 @@ EatPastNewLine(char* C)
static s32 static s32
EatPastNewLine(tokenizer* T) EatPastNewLine(tokenizer* T)
{ {
DEBUG_TRACK_FUNCTION;
char* TStart = T->At; char* TStart = T->At;
EatToNewLine(T); EatToNewLine(T);
@ -571,6 +594,7 @@ EatPastNewLine(tokenizer* T)
static char* static char*
EatWhitespace(char* C) EatWhitespace(char* C)
{ {
DEBUG_TRACK_FUNCTION;
char* Result = C; char* Result = C;
while (*Result && IsNewlineOrWhitespace(*Result)) { Result++; } while (*Result && IsNewlineOrWhitespace(*Result)) { Result++; }
return Result; return Result;
@ -579,6 +603,7 @@ EatWhitespace(char* C)
static s32 static s32
EatWhitespace(tokenizer* T) EatWhitespace(tokenizer* T)
{ {
DEBUG_TRACK_FUNCTION;
char* TStart = T->At; char* TStart = T->At;
while (AtValidPosition(*T) && IsNewlineOrWhitespace(*T->At)) { EatChar(T); } while (AtValidPosition(*T) && IsNewlineOrWhitespace(*T->At)) { EatChar(T); }
return T->At - TStart; return T->At - TStart;
@ -587,6 +612,7 @@ EatWhitespace(tokenizer* T)
static char* static char*
EatToNonWhitespaceOrNewline(char* C) EatToNonWhitespaceOrNewline(char* C)
{ {
DEBUG_TRACK_FUNCTION;
char* Result = C; char* Result = C;
while (*Result && IsWhitespace(*Result)) { Result++; } while (*Result && IsWhitespace(*Result)) { Result++; }
return Result; return Result;
@ -595,6 +621,7 @@ EatToNonWhitespaceOrNewline(char* C)
static s32 static s32
EatToNonWhitespaceOrNewline(tokenizer* T) EatToNonWhitespaceOrNewline(tokenizer* T)
{ {
DEBUG_TRACK_FUNCTION;
char* TStart = T->At; char* TStart = T->At;
while (AtValidPosition(*T) && IsWhitespace(*T->At)) { EatChar(T); } while (AtValidPosition(*T) && IsWhitespace(*T->At)) { EatChar(T); }
return T->At - TStart; return T->At - TStart;
@ -603,6 +630,7 @@ EatToNonWhitespaceOrNewline(tokenizer* T)
static char* static char*
EatToWhitespace(char* C) EatToWhitespace(char* C)
{ {
DEBUG_TRACK_FUNCTION;
char* Result = C; char* Result = C;
while (*Result && !IsWhitespace(*Result)) { Result++; } while (*Result && !IsWhitespace(*Result)) { Result++; }
return Result; return Result;
@ -611,6 +639,7 @@ EatToWhitespace(char* C)
static s32 static s32
EatToWhitespace(tokenizer* T) EatToWhitespace(tokenizer* T)
{ {
DEBUG_TRACK_FUNCTION;
char* TStart = T->At; char* TStart = T->At;
while (AtValidPosition(*T) && !IsWhitespace(*T->At)) { EatChar(T); } while (AtValidPosition(*T) && !IsWhitespace(*T->At)) { EatChar(T); }
return T->At - TStart; return T->At - TStart;
@ -619,6 +648,7 @@ EatToWhitespace(tokenizer* T)
static char* static char*
EatToCharacter(char* C, char Char) EatToCharacter(char* C, char Char)
{ {
DEBUG_TRACK_FUNCTION;
char* Result = C; char* Result = C;
while (*Result && *Result != Char) { Result++; } while (*Result && *Result != Char) { Result++; }
return Result; return Result;
@ -627,6 +657,7 @@ EatToCharacter(char* C, char Char)
static s32 static s32
EatToCharacter(tokenizer* T, char Char) EatToCharacter(tokenizer* T, char Char)
{ {
DEBUG_TRACK_FUNCTION;
char* TStart = T->At; char* TStart = T->At;
while (AtValidPosition(*T) && *T->At != Char) { EatChar(T); } while (AtValidPosition(*T) && *T->At != Char) { EatChar(T); }
return T->At - TStart; return T->At - TStart;
@ -635,6 +666,7 @@ EatToCharacter(tokenizer* T, char Char)
static char* static char*
EatPastCharacter(char* C, char Char) EatPastCharacter(char* C, char Char)
{ {
DEBUG_TRACK_FUNCTION;
char* Result = EatToCharacter(C, Char); char* Result = EatToCharacter(C, Char);
if (*Result && *Result == Char) { Result++; } if (*Result && *Result == Char) { Result++; }
return Result; return Result;
@ -643,6 +675,7 @@ EatPastCharacter(char* C, char Char)
static s32 static s32
EatPastCharacter(tokenizer* T, char Char) EatPastCharacter(tokenizer* T, char Char)
{ {
DEBUG_TRACK_FUNCTION;
char* TStart = T->At; char* TStart = T->At;
EatToCharacter(T, Char); EatToCharacter(T, Char);
if (AtValidPosition(*T) && *T->At == Char) { EatChar(T); } if (AtValidPosition(*T) && *T->At == Char) { EatChar(T); }
@ -652,6 +685,7 @@ EatPastCharacter(tokenizer* T, char Char)
static char* static char*
EatNumber(char* C) EatNumber(char* C)
{ {
DEBUG_TRACK_FUNCTION;
char* Result = C; char* Result = C;
while (*Result && IsNumericExtended(*Result)) { Result++; } while (*Result && IsNumericExtended(*Result)) { Result++; }
return Result; return Result;
@ -660,6 +694,7 @@ EatNumber(char* C)
static s32 static s32
EatNumber(tokenizer* T) EatNumber(tokenizer* T)
{ {
DEBUG_TRACK_FUNCTION;
char* TStart = T->At; char* TStart = T->At;
while (AtValidPosition(*T) && IsNumericExtended(*T->At)) { EatChar(T); } while (AtValidPosition(*T) && IsNumericExtended(*T->At)) { EatChar(T); }
return T->At - TStart; return T->At - TStart;
@ -669,7 +704,9 @@ EatNumber(tokenizer* T)
// Basic Char Operations // Basic Char Operations
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
static u32 CharToUInt (char C) { static u32 CharToUInt (char C)
{
DEBUG_TRACK_FUNCTION;
u32 Result = (C - '0'); u32 Result = (C - '0');
return Result; return Result;
} }
@ -677,6 +714,7 @@ static u32 CharToUInt (char C) {
static s32 static s32
CharArrayLength (char* Array) CharArrayLength (char* Array)
{ {
DEBUG_TRACK_FUNCTION;
char* C = Array; char* C = Array;
s32 Result = 0; s32 Result = 0;
while (*C) while (*C)
@ -690,6 +728,7 @@ CharArrayLength (char* Array)
static s32 static s32
NullTerminatedCharArrayLength (char* CharArray) NullTerminatedCharArrayLength (char* CharArray)
{ {
DEBUG_TRACK_FUNCTION;
char* Iter = CharArray; char* Iter = CharArray;
while (*Iter) while (*Iter)
{ {
@ -701,6 +740,7 @@ NullTerminatedCharArrayLength (char* CharArray)
static bool static bool
CharArraysEqual (char* A, s32 ALength, char* B, s32 BLength) CharArraysEqual (char* A, s32 ALength, char* B, s32 BLength)
{ {
DEBUG_TRACK_FUNCTION;
bool Result = false; bool Result = false;
if (ALength == BLength) if (ALength == BLength)
{ {
@ -722,6 +762,7 @@ CharArraysEqual (char* A, s32 ALength, char* B, s32 BLength)
static bool static bool
CharArraysEqualUnsafe (char* A, char* B) CharArraysEqualUnsafe (char* A, char* B)
{ {
DEBUG_TRACK_FUNCTION;
bool Result = true; bool Result = true;
char* AIter = A; char* AIter = A;
@ -746,6 +787,7 @@ CharArraysEqualUnsafe (char* A, char* B)
static bool static bool
CharArraysEqualUpToLength (char* A, char* B, s32 Length) CharArraysEqualUpToLength (char* A, char* B, s32 Length)
{ {
DEBUG_TRACK_FUNCTION;
bool Result = true; bool Result = true;
char* AIter = A; char* AIter = A;
@ -765,6 +807,7 @@ CharArraysEqualUpToLength (char* A, char* B, s32 Length)
static void static void
ReverseCharArray (char* Array, s32 Length) ReverseCharArray (char* Array, s32 Length)
{ {
DEBUG_TRACK_FUNCTION;
char* ForwardIter = Array; char* ForwardIter = Array;
char* BackwardIter = Array + Length - 1; char* BackwardIter = Array + Length - 1;
for (s32 i = 0; i < (Length / 2); i++) for (s32 i = 0; i < (Length / 2); i++)
@ -779,6 +822,7 @@ ReverseCharArray (char* Array, s32 Length)
static s32 static s32
IndexOfChar (char* Array, s32 After, char Find) IndexOfChar (char* Array, s32 After, char Find)
{ {
DEBUG_TRACK_FUNCTION;
s32 Result = -1; s32 Result = -1;
s32 Counter = After; s32 Counter = After;
@ -800,6 +844,7 @@ IndexOfChar (char* Array, s32 After, char Find)
static s32 static s32
FastReverseIndexOfChar (char* Array, s32 Length, s32 OffsetFromEnd, char Find) FastReverseIndexOfChar (char* Array, s32 Length, s32 OffsetFromEnd, char Find)
{ {
DEBUG_TRACK_FUNCTION;
s32 Result = -1; s32 Result = -1;
s32 Counter = Length - OffsetFromEnd; s32 Counter = Length - OffsetFromEnd;
@ -822,6 +867,7 @@ FastReverseIndexOfChar (char* Array, s32 Length, s32 OffsetFromEnd, char Find)
static s32 static s32
ReverseIndexOfChar (char* Array, s32 OffsetFromEnd, char Find) ReverseIndexOfChar (char* Array, s32 OffsetFromEnd, char Find)
{ {
DEBUG_TRACK_FUNCTION;
s32 StringLength = NullTerminatedCharArrayLength(Array); s32 StringLength = NullTerminatedCharArrayLength(Array);
return FastReverseIndexOfChar(Array, StringLength, OffsetFromEnd, Find); return FastReverseIndexOfChar(Array, StringLength, OffsetFromEnd, Find);
} }
@ -829,6 +875,7 @@ ReverseIndexOfChar (char* Array, s32 OffsetFromEnd, char Find)
static b32 static b32
CharArrayContains(char* Array, char* CheckFor) CharArrayContains(char* Array, char* CheckFor)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
char* Src = Array; char* Src = Array;
@ -859,6 +906,7 @@ CharArrayContains(char* Array, char* CheckFor)
static b32 static b32
CharArrayContainsSafe(char* Array, s32 ArrayLength, char* CheckFor, s32 CheckForLength) CharArrayContainsSafe(char* Array, s32 ArrayLength, char* CheckFor, s32 CheckForLength)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
if (ArrayLength >= CheckForLength) if (ArrayLength >= CheckForLength)
@ -897,6 +945,7 @@ CharArrayContainsSafe(char* Array, s32 ArrayLength, char* CheckFor, s32 CheckFor
static bool static bool
StringsEqual (string A, string B) StringsEqual (string A, string B)
{ {
DEBUG_TRACK_FUNCTION;
bool Result = false; bool Result = false;
if (A.Length == B.Length) if (A.Length == B.Length)
@ -920,6 +969,7 @@ StringsEqual (string A, string B)
static string static string
MakeString (char* Array, s32 Length, s32 Max) MakeString (char* Array, s32 Length, s32 Max)
{ {
DEBUG_TRACK_FUNCTION;
string Result = {}; string Result = {};
Result.Memory = Array; Result.Memory = Array;
Result.Length = Length; Result.Length = Length;
@ -930,6 +980,7 @@ MakeString (char* Array, s32 Length, s32 Max)
static string static string
MakeString (char* Array, s32 Length) MakeString (char* Array, s32 Length)
{ {
DEBUG_TRACK_FUNCTION;
string Result = {}; string Result = {};
Result.Memory = Array; Result.Memory = Array;
Result.Length = Length; Result.Length = Length;
@ -940,6 +991,7 @@ MakeString (char* Array, s32 Length)
static string static string
MakeString (char* Array) MakeString (char* Array)
{ {
DEBUG_TRACK_FUNCTION;
s32 Length = CharArrayLength (Array); s32 Length = CharArrayLength (Array);
return MakeString(Array, Length); return MakeString(Array, Length);
} }
@ -947,6 +999,7 @@ MakeString (char* Array)
static string static string
MakeStringLiteral (char* String) MakeStringLiteral (char* String)
{ {
DEBUG_TRACK_FUNCTION;
string Result = {}; string Result = {};
Result.Memory = String; Result.Memory = String;
Result.Max = CharArrayLength(String); Result.Max = CharArrayLength(String);
@ -957,6 +1010,7 @@ MakeStringLiteral (char* String)
static bool static bool
StringEqualsCharArray (string String, char* CharArray, s32 CharArrayLength) StringEqualsCharArray (string String, char* CharArray, s32 CharArrayLength)
{ {
DEBUG_TRACK_FUNCTION;
bool Result = false; bool Result = false;
if (CharArrayLength == String.Length) if (CharArrayLength == String.Length)
@ -981,6 +1035,7 @@ StringEqualsCharArray (string String, char* CharArray, s32 CharArrayLength)
static bool static bool
StringEqualsCharArray (string String, char* CharArray) StringEqualsCharArray (string String, char* CharArray)
{ {
DEBUG_TRACK_FUNCTION;
s32 CLength = CharArrayLength(CharArray); s32 CLength = CharArrayLength(CharArray);
return StringEqualsCharArray(String, CharArray, CLength); return StringEqualsCharArray(String, CharArray, CLength);
} }
@ -988,6 +1043,7 @@ StringEqualsCharArray (string String, char* CharArray)
static s32 static s32
FindFirstChar (string String, char C) FindFirstChar (string String, char C)
{ {
DEBUG_TRACK_FUNCTION;
s32 Result = -1; s32 Result = -1;
char* Iter = String.Memory; char* Iter = String.Memory;
@ -1006,6 +1062,7 @@ FindFirstChar (string String, char C)
static void static void
SetStringToChar (string* Dest, char C, s32 Count) SetStringToChar (string* Dest, char C, s32 Count)
{ {
DEBUG_TRACK_FUNCTION;
Assert(Count <= Dest->Max); Assert(Count <= Dest->Max);
char* Iter = Dest->Memory; char* Iter = Dest->Memory;
@ -1019,6 +1076,7 @@ SetStringToChar (string* Dest, char C, s32 Count)
static void static void
SetStringToCharArray (string* Dest, char* Source) SetStringToCharArray (string* Dest, char* Source)
{ {
DEBUG_TRACK_FUNCTION;
Dest->Length = 0; Dest->Length = 0;
char* Src = Source; char* Src = Source;
@ -1033,6 +1091,7 @@ SetStringToCharArray (string* Dest, char* Source)
static void static void
ConcatString (string Source, string* Dest) ConcatString (string Source, string* Dest)
{ {
DEBUG_TRACK_FUNCTION;
Assert((Dest->Length + Source.Length) <= Dest->Max); Assert((Dest->Length + Source.Length) <= Dest->Max);
char* Dst = Dest->Memory + Dest->Length; char* Dst = Dest->Memory + Dest->Length;
@ -1047,6 +1106,7 @@ ConcatString (string Source, string* Dest)
static void static void
ConcatString (string Source, s32 Length, string* Dest) ConcatString (string Source, s32 Length, string* Dest)
{ {
DEBUG_TRACK_FUNCTION;
Assert(Length <= Source.Length); Assert(Length <= Source.Length);
Assert((Dest->Length + Length) <= Dest->Max); Assert((Dest->Length + Length) <= Dest->Max);
@ -1062,6 +1122,7 @@ ConcatString (string Source, s32 Length, string* Dest)
static void static void
ConcatCharToString (string* Dest, char C) ConcatCharToString (string* Dest, char C)
{ {
DEBUG_TRACK_FUNCTION;
Assert(Dest->Length + 1 <= Dest->Max); Assert(Dest->Length + 1 <= Dest->Max);
char* Dst = Dest->Memory + Dest->Length; char* Dst = Dest->Memory + Dest->Length;
@ -1072,6 +1133,7 @@ ConcatCharToString (string* Dest, char C)
static void static void
ConcatCharArrayToString (char* Source, string* Dest) ConcatCharArrayToString (char* Source, string* Dest)
{ {
DEBUG_TRACK_FUNCTION;
Assert(CharArrayLength(Source) + Dest->Length <= Dest->Max); Assert(CharArrayLength(Source) + Dest->Length <= Dest->Max);
char* Dst = Dest->Memory + Dest->Length; char* Dst = Dest->Memory + Dest->Length;
@ -1087,6 +1149,7 @@ ConcatCharArrayToString (char* Source, string* Dest)
static void static void
ConcatCharArrayToString (char* Source, s32 SourceLength, string* Dest) ConcatCharArrayToString (char* Source, s32 SourceLength, string* Dest)
{ {
DEBUG_TRACK_FUNCTION;
Assert(SourceLength + Dest->Length <= Dest->Max); Assert(SourceLength + Dest->Length <= Dest->Max);
char* Dst = Dest->Memory + Dest->Length; char* Dst = Dest->Memory + Dest->Length;
@ -1101,6 +1164,7 @@ ConcatCharArrayToString (char* Source, s32 SourceLength, string* Dest)
static void static void
CopyStringTo (string Source, string* Dest) CopyStringTo (string Source, string* Dest)
{ {
DEBUG_TRACK_FUNCTION;
char* Src = Source.Memory; char* Src = Source.Memory;
char* Dst = Dest->Memory; char* Dst = Dest->Memory;
s32 CopyLength = GSMin(Source.Length, Dest->Max); s32 CopyLength = GSMin(Source.Length, Dest->Max);
@ -1114,6 +1178,7 @@ CopyStringTo (string Source, string* Dest)
static s32 static s32
CopyStringToCharArray (string Source, char* Dest, s32 DestLength) CopyStringToCharArray (string Source, char* Dest, s32 DestLength)
{ {
DEBUG_TRACK_FUNCTION;
char* Src = Source.Memory; char* Src = Source.Memory;
char* Dst = Dest; char* Dst = Dest;
s32 CopyLength = GSMin(Source.Length, DestLength); s32 CopyLength = GSMin(Source.Length, DestLength);
@ -1127,6 +1192,7 @@ CopyStringToCharArray (string Source, char* Dest, s32 DestLength)
static void static void
CopyCharArrayToString (char* Source, string* Dest) CopyCharArrayToString (char* Source, string* Dest)
{ {
DEBUG_TRACK_FUNCTION;
char* Src = Source; char* Src = Source;
char* Dst = Dest->Memory; char* Dst = Dest->Memory;
s32 Copied = 0; s32 Copied = 0;
@ -1142,6 +1208,7 @@ CopyCharArrayToString (char* Source, string* Dest)
static void static void
CopyCharArrayToString (char* Source, s32 SourceLength, string* Dest) CopyCharArrayToString (char* Source, s32 SourceLength, string* Dest)
{ {
DEBUG_TRACK_FUNCTION;
Assert(SourceLength <= Dest->Max); Assert(SourceLength <= Dest->Max);
char* Src = Source; char* Src = Source;
@ -1157,6 +1224,7 @@ CopyCharArrayToString (char* Source, s32 SourceLength, string* Dest)
static s32 static s32
CopyCharArray (char* Source, char* Dest, s32 DestLength) CopyCharArray (char* Source, char* Dest, s32 DestLength)
{ {
DEBUG_TRACK_FUNCTION;
char* Src = Source; char* Src = Source;
char* Dst = Dest; char* Dst = Dest;
s32 i = 0; s32 i = 0;
@ -1171,6 +1239,7 @@ CopyCharArray (char* Source, char* Dest, s32 DestLength)
static s32 static s32
CopyCharArrayAt (char* Source, char* Dest, s32 DestLength, s32 Offset) CopyCharArrayAt (char* Source, char* Dest, s32 DestLength, s32 Offset)
{ {
DEBUG_TRACK_FUNCTION;
Assert(Offset < DestLength); Assert(Offset < DestLength);
char* Src = Source; char* Src = Source;
@ -1187,6 +1256,7 @@ CopyCharArrayAt (char* Source, char* Dest, s32 DestLength, s32 Offset)
static void static void
InsertChar (string* String, char Char, s32 Index) InsertChar (string* String, char Char, s32 Index)
{ {
DEBUG_TRACK_FUNCTION;
Assert(Index >= 0 && Index < String->Max); Assert(Index >= 0 && Index < String->Max);
Assert(String->Length < String->Max); Assert(String->Length < String->Max);
@ -1204,6 +1274,7 @@ InsertChar (string* String, char Char, s32 Index)
static void static void
RemoveCharAt (string* String, s32 Index) RemoveCharAt (string* String, s32 Index)
{ {
DEBUG_TRACK_FUNCTION;
Assert(Index >= 0 && Index < String->Max); Assert(Index >= 0 && Index < String->Max);
char* Dst = String->Memory + Index; char* Dst = String->Memory + Index;
@ -1219,6 +1290,7 @@ RemoveCharAt (string* String, s32 Index)
static s32 static s32
IndexOfChar(string String, char C) IndexOfChar(string String, char C)
{ {
DEBUG_TRACK_FUNCTION;
s32 Result = -1; s32 Result = -1;
char* At = String.Memory; char* At = String.Memory;
for (s32 i = 0; i < String.Length; i++) for (s32 i = 0; i < String.Length; i++)
@ -1236,6 +1308,7 @@ IndexOfChar(string String, char C)
static s32 static s32
LastIndexOfChar(string String, char C) LastIndexOfChar(string String, char C)
{ {
DEBUG_TRACK_FUNCTION;
s32 Result = -1; s32 Result = -1;
char* At = String.Memory + String.Length - 1; char* At = String.Memory + String.Length - 1;
for (s32 i = 0; i < String.Length; i++) for (s32 i = 0; i < String.Length; i++)
@ -1253,6 +1326,7 @@ LastIndexOfChar(string String, char C)
static s32 static s32
SearchForCharInSet(string String, char* Set) SearchForCharInSet(string String, char* Set)
{ {
DEBUG_TRACK_FUNCTION;
s32 Index = -1; s32 Index = -1;
char* At = String.Memory; char* At = String.Memory;
@ -1284,6 +1358,7 @@ SearchForCharInSet(string String, char* Set)
static s32 static s32
ReverseSearchForCharInSet(string String, char* Set) ReverseSearchForCharInSet(string String, char* Set)
{ {
DEBUG_TRACK_FUNCTION;
s32 Index = -1; s32 Index = -1;
for (s32 i = String.Length - 1; i >= 0; i--) for (s32 i = String.Length - 1; i >= 0; i--)
@ -1312,6 +1387,7 @@ ReverseSearchForCharInSet(string String, char* Set)
static string static string
Substring (string String, s32 Start, s32 End) Substring (string String, s32 Start, s32 End)
{ {
DEBUG_TRACK_FUNCTION;
Assert(Start >= 0 && End > Start && End <= String.Length); Assert(Start >= 0 && End > Start && End <= String.Length);
string Result = {}; string Result = {};
@ -1323,6 +1399,7 @@ Substring (string String, s32 Start, s32 End)
static string static string
Substring (string String, s32 Start) Substring (string String, s32 Start)
{ {
DEBUG_TRACK_FUNCTION;
Assert(Start >= 0 && Start < String.Length); Assert(Start >= 0 && Start < String.Length);
string Result = {}; string Result = {};
@ -1334,6 +1411,7 @@ Substring (string String, s32 Start)
static b32 static b32
StringContainsCharArray(string SearchIn, char* SearchFor, s32 SearchForLength) StringContainsCharArray(string SearchIn, char* SearchFor, s32 SearchForLength)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
char* SearchInAt = SearchIn.Memory; char* SearchInAt = SearchIn.Memory;
@ -1362,12 +1440,14 @@ StringContainsCharArray(string SearchIn, char* SearchFor, s32 SearchForLength)
static b32 static b32
StringContainsString(string SearchIn, string SearchFor) StringContainsString(string SearchIn, string SearchFor)
{ {
DEBUG_TRACK_FUNCTION;
return StringContainsCharArray(SearchIn, SearchFor.Memory, SearchFor.Length); return StringContainsCharArray(SearchIn, SearchFor.Memory, SearchFor.Length);
} }
static b32 static b32
StringContainsCharArrayCaseInsensitive(string SearchIn, char* SearchFor, s32 SearchForLength) StringContainsCharArrayCaseInsensitive(string SearchIn, char* SearchFor, s32 SearchForLength)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
char* SearchInAt = SearchIn.Memory; char* SearchInAt = SearchIn.Memory;
@ -1396,12 +1476,14 @@ StringContainsCharArrayCaseInsensitive(string SearchIn, char* SearchFor, s32 Sea
static b32 static b32
StringContainsStringCaseInsensitive(string SearchIn, string SearchFor) StringContainsStringCaseInsensitive(string SearchIn, string SearchFor)
{ {
DEBUG_TRACK_FUNCTION;
return StringContainsCharArrayCaseInsensitive(SearchIn, SearchFor.Memory, SearchFor.Length); return StringContainsCharArrayCaseInsensitive(SearchIn, SearchFor.Memory, SearchFor.Length);
} }
static void static void
NullTerminate (string* String) NullTerminate (string* String)
{ {
DEBUG_TRACK_FUNCTION;
Assert(String->Length + 1 <= String->Max); Assert(String->Length + 1 <= String->Max);
*(String->Memory + String->Length) = 0; *(String->Memory + String->Length) = 0;
String->Length++; String->Length++;
@ -1412,6 +1494,7 @@ NullTerminate (string* String)
static u32 static u32
HashString(string String) HashString(string String)
{ {
DEBUG_TRACK_FUNCTION;
u32 Hash = 5381; u32 Hash = 5381;
for (s32 i = 0; i < String.Length; i++) for (s32 i = 0; i < String.Length; i++)
{ {
@ -1423,6 +1506,7 @@ HashString(string String)
static void static void
InsertStringAt (string* Dest, string Source, s32 At) InsertStringAt (string* Dest, string Source, s32 At)
{ {
DEBUG_TRACK_FUNCTION;
Assert(At + Source.Length < Dest->Max); Assert(At + Source.Length < Dest->Max);
Assert(At < Dest->Length); Assert(At < Dest->Length);
@ -1455,6 +1539,7 @@ InsertStringAt (string* Dest, string Source, s32 At)
static parse_result static parse_result
ParseUnsignedInt (s32 Length, char* String) ParseUnsignedInt (s32 Length, char* String)
{ {
DEBUG_TRACK_FUNCTION;
Assert(IsNumeric(*String)); Assert(IsNumeric(*String));
parse_result Result = {}; parse_result Result = {};
Result.Type = ParseType_UnsignedInt; Result.Type = ParseType_UnsignedInt;
@ -1475,6 +1560,7 @@ ParseUnsignedInt (s32 Length, char* String)
static parse_result static parse_result
ParseUnsignedIntUnsafe (char* String) ParseUnsignedIntUnsafe (char* String)
{ {
DEBUG_TRACK_FUNCTION;
char* Start = String; char* Start = String;
char* End = EatNumber(String + 1); char* End = EatNumber(String + 1);
return ParseUnsignedInt(End - Start, String); return ParseUnsignedInt(End - Start, String);
@ -1484,6 +1570,7 @@ ParseUnsignedIntUnsafe (char* String)
static parse_result static parse_result
ParseSignedInt (s32 Length, char* String) ParseSignedInt (s32 Length, char* String)
{ {
DEBUG_TRACK_FUNCTION;
Assert(Length > 0); Assert(Length > 0);
parse_result Result = {}; parse_result Result = {};
Result.Type = ParseType_SignedInt; Result.Type = ParseType_SignedInt;
@ -1515,6 +1602,7 @@ ParseSignedInt (s32 Length, char* String)
static parse_result static parse_result
ParseSignedIntUnsafe (char* String) ParseSignedIntUnsafe (char* String)
{ {
DEBUG_TRACK_FUNCTION;
char* Start = String; char* Start = String;
char* End = EatNumber(String + 1); char* End = EatNumber(String + 1);
return ParseSignedInt(End - Start, String); return ParseSignedInt(End - Start, String);
@ -1524,6 +1612,7 @@ ParseSignedIntUnsafe (char* String)
static parse_result static parse_result
ParseFloat (s32 Length, char* String) ParseFloat (s32 Length, char* String)
{ {
DEBUG_TRACK_FUNCTION;
parse_result Result = {}; parse_result Result = {};
Result.Type = ParseType_Float; Result.Type = ParseType_Float;
@ -1585,6 +1674,7 @@ ParseFloat (s32 Length, char* String)
static parse_result static parse_result
ParseFloatUnsafe (char* String) ParseFloatUnsafe (char* String)
{ {
DEBUG_TRACK_FUNCTION;
char* Start = String; char* Start = String;
char* End = EatNumber(String + 1); char* End = EatNumber(String + 1);
return ParseFloat(End - Start, String); return ParseFloat(End - Start, String);
@ -1593,6 +1683,7 @@ ParseFloatUnsafe (char* String)
static s32 static s32
UIntToString (u32 Int, char* String, s32 MaxLength, b32 FormatFlags = 0, s32 MinimumLength = 0) UIntToString (u32 Int, char* String, s32 MaxLength, b32 FormatFlags = 0, s32 MinimumLength = 0)
{ {
DEBUG_TRACK_FUNCTION;
s32 Remaining = Int; s32 Remaining = Int;
char* Iter = String; char* Iter = String;
while (Remaining > 0 && (Iter - String) < MaxLength) while (Remaining > 0 && (Iter - String) < MaxLength)
@ -1608,6 +1699,7 @@ UIntToString (u32 Int, char* String, s32 MaxLength, b32 FormatFlags = 0, s32 Min
static s32 static s32
IntToString (s32 Int, char* String, s32 MaxLength, b32 FormatFlags = 0, s32 MinimumLength = 0) IntToString (s32 Int, char* String, s32 MaxLength, b32 FormatFlags = 0, s32 MinimumLength = 0)
{ {
DEBUG_TRACK_FUNCTION;
s32 Remaining = Int; s32 Remaining = Int;
s32 CharsCopied = 0; s32 CharsCopied = 0;
@ -1643,6 +1735,7 @@ IntToString (s32 Int, char* String, s32 MaxLength, b32 FormatFlags = 0, s32 Mini
static s32 static s32
IntToString (s32 Int, char* String, s32 MaxLength, s32 Offset, b32 FormatFlags = 0, s32 MinimumWidth = 0) IntToString (s32 Int, char* String, s32 MaxLength, s32 Offset, b32 FormatFlags = 0, s32 MinimumWidth = 0)
{ {
DEBUG_TRACK_FUNCTION;
char* StringStart = String + Offset; char* StringStart = String + Offset;
s32 LengthWritten = IntToString(Int, StringStart, MaxLength - Offset); s32 LengthWritten = IntToString(Int, StringStart, MaxLength - Offset);
return LengthWritten; return LengthWritten;
@ -1651,6 +1744,7 @@ IntToString (s32 Int, char* String, s32 MaxLength, s32 Offset, b32 FormatFlags =
static s32 static s32
FloatToString(float Float, char *String, s32 MaxLength, s32 AfterPoint = 0, b32 FormatFlags = 0, s32 MinimumWidth = 0) FloatToString(float Float, char *String, s32 MaxLength, s32 AfterPoint = 0, b32 FormatFlags = 0, s32 MinimumWidth = 0)
{ {
DEBUG_TRACK_FUNCTION;
s32 IPart = (s32)Float; s32 IPart = (s32)Float;
float FPart = GSAbs(Float - (float)IPart); float FPart = GSAbs(Float - (float)IPart);
@ -1674,6 +1768,7 @@ FloatToString(float Float, char *String, s32 MaxLength, s32 AfterPoint = 0, b32
static void static void
OutChar (string* String, char C) OutChar (string* String, char C)
{ {
DEBUG_TRACK_FUNCTION;
if (String->Length < String->Max) if (String->Length < String->Max)
{ {
String->Memory[String->Length] = C; String->Memory[String->Length] = C;
@ -1688,6 +1783,7 @@ char HexDigits[] = "0123456789ABCDEF";
static void static void
U64ToASCII (string* String, u64 Value, s32 Base, char* Digits) U64ToASCII (string* String, u64 Value, s32 Base, char* Digits)
{ {
DEBUG_TRACK_FUNCTION;
u64 ValueRemaining = Value; u64 ValueRemaining = Value;
char* Start = String->Memory + String->Length; char* Start = String->Memory + String->Length;
do { do {
@ -1711,6 +1807,7 @@ U64ToASCII (string* String, u64 Value, s32 Base, char* Digits)
static void static void
F64ToASCII (string* String, r64 Value, s32 Precision) F64ToASCII (string* String, r64 Value, s32 Precision)
{ {
DEBUG_TRACK_FUNCTION;
if (Value < 0) if (Value < 0)
{ {
OutChar(String, '-'); OutChar(String, '-');
@ -1736,6 +1833,7 @@ F64ToASCII (string* String, r64 Value, s32 Precision)
internal s64 internal s64
ReadVarArgsSignedInteger (s32 Width, va_list* Args) ReadVarArgsSignedInteger (s32 Width, va_list* Args)
{ {
DEBUG_TRACK_FUNCTION;
s64 Result = 0; s64 Result = 0;
switch (Width) switch (Width)
{ {
@ -1751,6 +1849,7 @@ ReadVarArgsSignedInteger (s32 Width, va_list* Args)
internal r64 internal r64
ReadVarArgsUnsignedInteger (s32 Width, va_list* Args) ReadVarArgsUnsignedInteger (s32 Width, va_list* Args)
{ {
DEBUG_TRACK_FUNCTION;
u64 Result = 0; u64 Result = 0;
switch (Width) switch (Width)
{ {
@ -1766,6 +1865,7 @@ ReadVarArgsUnsignedInteger (s32 Width, va_list* Args)
internal r64 internal r64
ReadVarArgsFloat (s32 Width, va_list* Args) ReadVarArgsFloat (s32 Width, va_list* Args)
{ {
DEBUG_TRACK_FUNCTION;
r64 Result = 0; r64 Result = 0;
switch (Width) switch (Width)
{ {
@ -1779,6 +1879,7 @@ ReadVarArgsFloat (s32 Width, va_list* Args)
internal s32 internal s32
PrintFArgsList (char* Dest, s32 DestMax, char* Format, va_list Args) PrintFArgsList (char* Dest, s32 DestMax, char* Format, va_list Args)
{ {
DEBUG_TRACK_FUNCTION;
char* DestAt = Dest; char* DestAt = Dest;
char* FormatAt = Format; char* FormatAt = Format;
@ -2005,6 +2106,7 @@ PrintFArgsList (char* Dest, s32 DestMax, char* Format, va_list Args)
static void static void
PrintF (string* String, char* Format, ...) PrintF (string* String, char* Format, ...)
{ {
DEBUG_TRACK_FUNCTION;
va_list Args; va_list Args;
va_start(Args, Format); va_start(Args, Format);
String->Length = 0; String->Length = 0;
@ -2015,6 +2117,7 @@ PrintF (string* String, char* Format, ...)
static void static void
AppendPrintF (string* String, char* Format, ...) AppendPrintF (string* String, char* Format, ...)
{ {
DEBUG_TRACK_FUNCTION;
va_list Args; va_list Args;
va_start(Args, Format); va_start(Args, Format);
String->Length += PrintFArgsList(String->Memory + String->Length, String->Max - String->Length, Format, Args); String->Length += PrintFArgsList(String->Memory + String->Length, String->Max - String->Length, Format, Args);
@ -2025,6 +2128,7 @@ AppendPrintF (string* String, char* Format, ...)
static u32 static u32
GetU32NumberOfCharactersNeeded(u32 Value, u32 Base) GetU32NumberOfCharactersNeeded(u32 Value, u32 Base)
{ {
DEBUG_TRACK_FUNCTION;
u32 Result = 0; u32 Result = 0;
u32 ValueLeft = Value; u32 ValueLeft = Value;
// NOTE(Peter): This is in a do while loop because even if the number is 0, // NOTE(Peter): This is in a do while loop because even if the number is 0,
@ -2040,6 +2144,7 @@ GetU32NumberOfCharactersNeeded(u32 Value, u32 Base)
static u32 static u32
GetS32NumberOfCharactersNeeded(s32 Value, s32 Base) GetS32NumberOfCharactersNeeded(s32 Value, s32 Base)
{ {
DEBUG_TRACK_FUNCTION;
u32 Result = 0; u32 Result = 0;
s32 ValueLeft = Value; s32 ValueLeft = Value;
if (Value < 0) if (Value < 0)
@ -2064,6 +2169,7 @@ GetS32NumberOfCharactersNeeded(s32 Value, s32 Base)
static s32 static s32
CalculateSlotCountFromSize (s32 RequestedSize, s32 SlotSize) CalculateSlotCountFromSize (s32 RequestedSize, s32 SlotSize)
{ {
DEBUG_TRACK_FUNCTION;
s32 SlotCount = RequestedSize / SlotSize; s32 SlotCount = RequestedSize / SlotSize;
if (SlotCount * SlotSize < RequestedSize) if (SlotCount * SlotSize < RequestedSize)
{ {
@ -2075,6 +2181,7 @@ CalculateSlotCountFromSize (s32 RequestedSize, s32 SlotSize)
static bool static bool
SlotsAreContiguous (slot_header* First, slot_header* Second) SlotsAreContiguous (slot_header* First, slot_header* Second)
{ {
DEBUG_TRACK_FUNCTION;
bool Result = false; bool Result = false;
u8* FirstSlotNextAddress = (u8*)First + First->Size; u8* FirstSlotNextAddress = (u8*)First + First->Size;
u8* SecondAddress = (u8*)Second; u8* SecondAddress = (u8*)Second;
@ -2085,6 +2192,7 @@ SlotsAreContiguous (slot_header* First, slot_header* Second)
static contiguous_slot_count_result static contiguous_slot_count_result
CountContiguousSlots (slot_header* First) CountContiguousSlots (slot_header* First)
{ {
DEBUG_TRACK_FUNCTION;
Assert(First != 0); Assert(First != 0);
contiguous_slot_count_result Result = {}; contiguous_slot_count_result Result = {};
@ -2106,6 +2214,7 @@ CountContiguousSlots (slot_header* First)
static slot_header* static slot_header*
GetSlotAtOffset(slot_header* First, s32 Offset) GetSlotAtOffset(slot_header* First, s32 Offset)
{ {
DEBUG_TRACK_FUNCTION;
slot_header* Iter = First; slot_header* Iter = First;
s32 Count = 0; s32 Count = 0;
while (Count < Offset && Iter) while (Count < Offset && Iter)
@ -2119,6 +2228,7 @@ GetSlotAtOffset(slot_header* First, s32 Offset)
static slot_header* static slot_header*
InsertSlotIntoList (slot_header* NewSlot, slot_header* ListStart) InsertSlotIntoList (slot_header* NewSlot, slot_header* ListStart)
{ {
DEBUG_TRACK_FUNCTION;
slot_header* List = ListStart; slot_header* List = ListStart;
if (NewSlot < List) if (NewSlot < List)
{ {
@ -2152,6 +2262,7 @@ InsertSlotIntoList (slot_header* NewSlot, slot_header* ListStart)
static void static void
AllocStringFromStringArena (string* String, s32 Size, slot_arena* Storage) AllocStringFromStringArena (string* String, s32 Size, slot_arena* Storage)
{ {
DEBUG_TRACK_FUNCTION;
s32 SlotCount = CalculateSlotCountFromSize(Size, Storage->SlotSize); s32 SlotCount = CalculateSlotCountFromSize(Size, Storage->SlotSize);
slot_header* Slot = Storage->FreeList; slot_header* Slot = Storage->FreeList;
slot_header* PrevSlot = 0; slot_header* PrevSlot = 0;
@ -2190,6 +2301,7 @@ AllocStringFromStringArena (string* String, s32 Size, slot_arena* Storage)
static string static string
AllocStringFromStringArena (s32 Size, slot_arena* Storage) AllocStringFromStringArena (s32 Size, slot_arena* Storage)
{ {
DEBUG_TRACK_FUNCTION;
string Result = {0}; string Result = {0};
AllocStringFromStringArena(&Result, Size, Storage); AllocStringFromStringArena(&Result, Size, Storage);
return Result; return Result;
@ -2198,6 +2310,7 @@ AllocStringFromStringArena (s32 Size, slot_arena* Storage)
static void static void
FreeToStringArena (string* String, slot_arena* Storage) FreeToStringArena (string* String, slot_arena* Storage)
{ {
DEBUG_TRACK_FUNCTION;
u8* Base = (u8*)(String->Memory); u8* Base = (u8*)(String->Memory);
u8* End = Base + String->Max - 1; u8* End = Base + String->Max - 1;
u8* MemoryEnd = Storage->Memory + (Storage->SlotSize * Storage->SlotCount); u8* MemoryEnd = Storage->Memory + (Storage->SlotSize * Storage->SlotCount);
@ -2222,6 +2335,7 @@ FreeToStringArena (string* String, slot_arena* Storage)
static void static void
ReallocFromStringArena (string* String, s32 NewSize, slot_arena* Storage) ReallocFromStringArena (string* String, s32 NewSize, slot_arena* Storage)
{ {
DEBUG_TRACK_FUNCTION;
string NewString = AllocStringFromStringArena(NewSize, Storage); string NewString = AllocStringFromStringArena(NewSize, Storage);
CopyStringTo(*String, &NewString); CopyStringTo(*String, &NewString);
FreeToStringArena(String, Storage); FreeToStringArena(String, Storage);
@ -2232,6 +2346,7 @@ ReallocFromStringArena (string* String, s32 NewSize, slot_arena* Storage)
void DEBUGPrintChars (string* String, s32 Count) void DEBUGPrintChars (string* String, s32 Count)
{ {
DEBUG_TRACK_FUNCTION;
char* Iter = String->Memory; char* Iter = String->Memory;
for (int i = 0; i < Count; i++) for (int i = 0; i < Count; i++)
{ {
@ -2248,6 +2363,7 @@ static void
TestStrings() TestStrings()
{ {
slot_arena StringArena = {}; slot_arena StringArena = {};
s32 TestCount = 0; s32 TestCount = 0;

View File

@ -303,6 +303,9 @@ int main(int ArgCount, char* Args[])
Allocator.Alloc = (allocator_alloc*)PlatformAlloc; Allocator.Alloc = (allocator_alloc*)PlatformAlloc;
Allocator.Free = (allocator_free*)PlatformFree; Allocator.Free = (allocator_free*)PlatformFree;
GlobalDebugServices.Arena = CreateMemoryArena(Allocator);
GlobalDebugServices.Transient = CreateMemoryArena(Allocator);
GlobalDebugServices.ShouldProfile = true;
string RootFile = MakeString(Args[1]); string RootFile = MakeString(Args[1]);
s32 IndexOfLastSlash = ReverseSearchForCharInSet(RootFile, "\\/"); s32 IndexOfLastSlash = ReverseSearchForCharInSet(RootFile, "\\/");

View File

@ -28,6 +28,34 @@
#include "..\gs_libs\gs_profiler.h" #include "..\gs_libs\gs_profiler.h"
#include "..\gs_libs\gs_string.h" #include "..\gs_libs\gs_string.h"
global_variable u64 TokenHash_GSMetaTag = HashDJB2ToU64("GSMetaTag");
global_variable u64 TokenHash_OpenParen = HashDJB2ToU64("(");
global_variable u64 TokenHash_CloseParen = HashDJB2ToU64(")");
global_variable u64 TokenHash_Semicolon = HashDJB2ToU64(";");
global_variable u64 TokenHash_Unsigned = HashDJB2ToU64("unsigned");
global_variable u64 TokenHash_Signed = HashDJB2ToU64("signed");
global_variable u64 TokenHash_Short = HashDJB2ToU64("short");
global_variable u64 TokenHash_Int = HashDJB2ToU64("int");
global_variable u64 TokenHash_Long = HashDJB2ToU64("long");
global_variable u64 TokenHash_Char = HashDJB2ToU64("char");
global_variable u64 TokenHash_WCharT = HashDJB2ToU64("wchar_t");
global_variable u64 TokenHash_Bool = HashDJB2ToU64("bool");
global_variable u64 TokenHash_Float = HashDJB2ToU64("float");
global_variable u64 TokenHash_Double = HashDJB2ToU64("double");
global_variable u64 TokenHash_Star = HashDJB2ToU64("*");
global_variable u64 TokenHash_Volatile = HashDJB2ToU64("volatile");
global_variable u64 TokenHash_Const = HashDJB2ToU64("const");
global_variable u64 TokenHash_OpenSquareBracket = HashDJB2ToU64("[");
global_variable u64 TokenHash_CloseSquareBracket = HashDJB2ToU64("]");
global_variable u64 TokenHash_Comma = HashDJB2ToU64(",");
global_variable u64 TokenHash_Struct = HashDJB2ToU64("struct");
global_variable u64 TokenHash_Union = HashDJB2ToU64("union");
global_variable u64 TokenHash_OpenCurlyBracket = HashDJB2ToU64("{");
global_variable u64 TokenHash_CloseCurlyBracket = HashDJB2ToU64("}");
global_variable u64 TokenHash_Typedef = HashDJB2ToU64("typedef");
global_variable u64 TokenHash_Enum = HashDJB2ToU64("enum");
global_variable u64 TokenHash_Equals = HashDJB2ToU64("=");
struct gsm_profiler_scope struct gsm_profiler_scope
{ {
s64 StartTime; s64 StartTime;
@ -311,6 +339,19 @@ TokenAtEquals(token_iter* Iter, char* String)
return Result; return Result;
} }
internal b32
TokenAtHashEquals(token_iter* Iter, u64 Hash)
{
DEBUG_TRACK_FUNCTION;
b32 Result = false;
if (Hash == Iter->TokenAt->TextHash)
{
Result = true;
NextToken(Iter);
}
return Result;
}
internal b32 internal b32
TokenAtEquals(token_iter* Iter, token_type Type) TokenAtEquals(token_iter* Iter, token_type Type)
{ {
@ -545,14 +586,14 @@ ParseMetaTag(token_iter* Iter, gs_meta_preprocessor* Meta)
b32 Result = false; b32 Result = false;
PushSnapshot(Iter); PushSnapshot(Iter);
if (TokenAtEquals(Iter, "GSMetaTag") && if (TokenAtHashEquals(Iter, TokenHash_GSMetaTag) &&
TokenAtEquals(Iter, "(")) TokenAtHashEquals(Iter, TokenHash_OpenParen))
{ {
token MetaIdentifier = {0}; token MetaIdentifier = {0};
if (TokenAtEquals(Iter, Token_Identifier, &MetaIdentifier)) if (TokenAtEquals(Iter, Token_Identifier, &MetaIdentifier))
{ {
if (TokenAtEquals(Iter, ")") && if (TokenAtHashEquals(Iter, TokenHash_OpenParen) &&
TokenAtEquals(Iter, ";")) TokenAtHashEquals(Iter, TokenHash_Semicolon))
{ {
Result = true; Result = true;
type_table_handle MetaTagHandle = GetMetaTagHandle(MetaIdentifier.Text, Meta->TypeTable); type_table_handle MetaTagHandle = GetMetaTagHandle(MetaIdentifier.Text, Meta->TypeTable);
@ -592,8 +633,8 @@ ParseSignedness (token_iter* Iter)
b32 Result = false; b32 Result = false;
if (TokenAtEquals(Iter, "unsigned") || if (TokenAtHashEquals(Iter, TokenHash_Unsigned) ||
TokenAtEquals(Iter, "signed")) TokenAtHashEquals(Iter, TokenHash_Signed))
{ {
Result = true; Result = true;
} }
@ -609,10 +650,10 @@ ShortInt (token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTab
PushSnapshot(Iter); PushSnapshot(Iter);
ParseSignedness(Iter); ParseSignedness(Iter);
if (TokenAtEquals(Iter, "short")) if (TokenAtHashEquals(Iter, TokenHash_Short))
{ {
Result = true; Result = true;
if (TokenAtEquals(Iter, "int")) if (TokenAtHashEquals(Iter, TokenHash_Int))
{ {
Result = true; Result = true;
} }
@ -634,7 +675,7 @@ Int (token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTable)
PushSnapshot(Iter); PushSnapshot(Iter);
ParseSignedness(Iter); ParseSignedness(Iter);
if (TokenAtEquals(Iter, "int")) if (TokenAtHashEquals(Iter, TokenHash_Int))
{ {
Result = true; Result = true;
} }
@ -655,10 +696,10 @@ LongInt (token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTabl
PushSnapshot(Iter); PushSnapshot(Iter);
ParseSignedness(Iter); ParseSignedness(Iter);
if (TokenAtEquals(Iter, "long")) if (TokenAtHashEquals(Iter, TokenHash_Long))
{ {
Result = true; Result = true;
if (TokenAtEquals(Iter, "int")) if (TokenAtHashEquals(Iter, TokenHash_Int))
{ {
Result = true; Result = true;
} }
@ -680,12 +721,12 @@ LongLongInt (token_iter* Iter, type_table_handle* TypeHandleOut, type_table Type
PushSnapshot(Iter); PushSnapshot(Iter);
ParseSignedness(Iter); ParseSignedness(Iter);
if (TokenAtEquals(Iter, "long")) if (TokenAtHashEquals(Iter, TokenHash_Long))
{ {
if (TokenAtEquals(Iter, "long")) if (TokenAtHashEquals(Iter, TokenHash_Long))
{ {
Result = true; Result = true;
if (TokenAtEquals(Iter, "int")) if (TokenAtHashEquals(Iter, TokenHash_Int))
{ {
Result = true; Result = true;
} }
@ -708,12 +749,12 @@ ParseChar(token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTab
PushSnapshot(Iter); PushSnapshot(Iter);
ParseSignedness(Iter); ParseSignedness(Iter);
if (TokenAtEquals(Iter, "char")) if (TokenAtHashEquals(Iter, TokenHash_Char))
{ {
Result = true; Result = true;
*TypeHandleOut = GetTypeHandle(MakeStringLiteral("char"), TypeTable); *TypeHandleOut = GetTypeHandle(MakeStringLiteral("char"), TypeTable);
} }
else if (TokenAtEquals(Iter, "wchar_t")) else if (TokenAtHashEquals(Iter, TokenHash_WCharT))
{ {
Result = true; Result = true;
*TypeHandleOut = GetTypeHandle(MakeStringLiteral("wchar_t"), TypeTable); *TypeHandleOut = GetTypeHandle(MakeStringLiteral("wchar_t"), TypeTable);
@ -730,7 +771,7 @@ ParseBool(token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTab
b32 Result = false; b32 Result = false;
PushSnapshot(Iter); PushSnapshot(Iter);
if (TokenAtEquals(Iter, "bool")) if (TokenAtHashEquals(Iter, TokenHash_Bool))
{ {
Result = true; Result = true;
*TypeHandleOut = GetTypeHandle(MakeStringLiteral("bool"), TypeTable); *TypeHandleOut = GetTypeHandle(MakeStringLiteral("bool"), TypeTable);
@ -747,7 +788,7 @@ ParseFloat(token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeTa
b32 Result = false; b32 Result = false;
PushSnapshot(Iter); PushSnapshot(Iter);
if (TokenAtEquals(Iter, "float")) if (TokenAtHashEquals(Iter, TokenHash_Float))
{ {
Result = true; Result = true;
*TypeHandleOut = GetTypeHandle(MakeStringLiteral("float"), TypeTable); *TypeHandleOut = GetTypeHandle(MakeStringLiteral("float"), TypeTable);
@ -764,7 +805,7 @@ ParseDouble(token_iter* Iter, type_table_handle* TypeHandleOut, type_table TypeT
b32 Result = false; b32 Result = false;
PushSnapshot(Iter); PushSnapshot(Iter);
if (TokenAtEquals(Iter, "double")) if (TokenAtHashEquals(Iter, TokenHash_Double))
{ {
Result = true; Result = true;
*TypeHandleOut = GetTypeHandle(MakeStringLiteral("double"), TypeTable); *TypeHandleOut = GetTypeHandle(MakeStringLiteral("double"), TypeTable);
@ -843,7 +884,7 @@ ParsePointer (token_iter* Iter)
{ {
DEBUG_TRACK_FUNCTION; DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
if (TokenAtEquals(Iter, "*")) if (TokenAtHashEquals(Iter, TokenHash_Star))
{ {
Result = true; Result = true;
} }
@ -857,8 +898,8 @@ ParseConstVolatile (token_iter* Iter)
b32 Result = false; b32 Result = false;
PushSnapshot(Iter); PushSnapshot(Iter);
if (TokenAtEquals(Iter, "volatile") || if (TokenAtHashEquals(Iter, TokenHash_Volatile) ||
TokenAtEquals(Iter, "const")) TokenAtHashEquals(Iter, TokenHash_Const))
{ {
Result = true; Result = true;
} }
@ -910,7 +951,7 @@ ParseVariableDecl(token_iter* Iter, gs_bucket<variable_decl>* VariableList, gs_m
// are still ok to proceed // are still ok to proceed
b32 ArrayParseSuccess = true; b32 ArrayParseSuccess = true;
u32 ArrayCount = 0; u32 ArrayCount = 0;
if (TokenAtEquals(Iter, "[")) if (TokenAtHashEquals(Iter, TokenHash_OpenSquareBracket))
{ {
// NOTE(Peter): Once we get to this point, we have to complete the entire // NOTE(Peter): Once we get to this point, we have to complete the entire
// array notation before we have successfully parsed, hence setting // array notation before we have successfully parsed, hence setting
@ -931,7 +972,7 @@ ParseVariableDecl(token_iter* Iter, gs_bucket<variable_decl>* VariableList, gs_m
} }
} }
if (TokenAtEquals(Iter, "]")) if (TokenAtHashEquals(Iter, TokenHash_CloseSquareBracket))
{ {
ArrayParseSuccess = true; ArrayParseSuccess = true;
} }
@ -969,7 +1010,7 @@ ParseVariableDecl(token_iter* Iter, gs_bucket<variable_decl>* VariableList, gs_m
PushSnapshot(Iter); PushSnapshot(Iter);
if (TokenAtEquals(Iter, Token_Identifier) && if (TokenAtEquals(Iter, Token_Identifier) &&
(TokenAtEquals(Iter, ",") || TokenAtEquals(Iter, ";"))) (TokenAtHashEquals(Iter, TokenHash_Comma) || TokenAtHashEquals(Iter, TokenHash_Semicolon)))
{ {
// We are in a declaration list (case 1) // We are in a declaration list (case 1)
ApplySnapshotIfNotParsedAndPop(false, Iter); ApplySnapshotIfNotParsedAndPop(false, Iter);
@ -1000,12 +1041,12 @@ StructOrUnion(token_iter* Iter, type_definition_type* Type)
{ {
DEBUG_TRACK_FUNCTION; DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
if (TokenAtEquals(Iter, "struct")) if (TokenAtHashEquals(Iter, TokenHash_Struct))
{ {
Result = true; Result = true;
*Type = TypeDef_Struct; *Type = TypeDef_Struct;
} }
else if (TokenAtEquals(Iter, "union")) else if (TokenAtHashEquals(Iter, TokenHash_Union))
{ {
Result = true; Result = true;
*Type = TypeDef_Union; *Type = TypeDef_Union;
@ -1035,7 +1076,7 @@ ParseStruct(token_iter* Iter, type_table_handle* StructTypeHandleOut, gs_meta_pr
if (TokenAtEquals(Iter, Token_Identifier, &IdentifierToken)) {} if (TokenAtEquals(Iter, Token_Identifier, &IdentifierToken)) {}
// TODO(Peter): Handle name coming after the struct // TODO(Peter): Handle name coming after the struct
if (TokenAtEquals(Iter, "{")) if (TokenAtHashEquals(Iter, TokenHash_OpenCurlyBracket))
{ {
type_definition StructDecl = {}; type_definition StructDecl = {};
if (IdentifierToken.Text.Length > 0) if (IdentifierToken.Text.Length > 0)
@ -1065,7 +1106,7 @@ ParseStruct(token_iter* Iter, type_table_handle* StructTypeHandleOut, gs_meta_pr
StructDecl.Type = DeclType; StructDecl.Type = DeclType;
CopyMetaTagsAndClear(&Meta->TagList, &StructDecl.MetaTags); CopyMetaTagsAndClear(&Meta->TagList, &StructDecl.MetaTags);
while (!TokenAtEquals(Iter, "}")) while (!TokenAtHashEquals(Iter, TokenHash_CloseCurlyBracket))
{ {
type_table_handle MemberStructTypeHandle = InvalidTypeTableHandle; type_table_handle MemberStructTypeHandle = InvalidTypeTableHandle;
variable_decl MemberDecl = {}; variable_decl MemberDecl = {};
@ -1075,7 +1116,7 @@ ParseStruct(token_iter* Iter, type_table_handle* StructTypeHandleOut, gs_meta_pr
} }
else if (ParseVariableDecl(Iter, &StructDecl.Struct.MemberDecls, Meta)) else if (ParseVariableDecl(Iter, &StructDecl.Struct.MemberDecls, Meta))
{ {
if (!TokenAtEquals(Iter, ";")) if (!TokenAtHashEquals(Iter, TokenHash_Semicolon))
{ {
PushFError(Iter->Errors, "No semicolon after struct member variable declaration. %S", StructDecl.Identifier); PushFError(Iter->Errors, "No semicolon after struct member variable declaration. %S", StructDecl.Identifier);
} }
@ -1102,7 +1143,7 @@ ParseStruct(token_iter* Iter, type_table_handle* StructTypeHandleOut, gs_meta_pr
} }
} }
if (TokenAtEquals(Iter, ";")) if (TokenAtHashEquals(Iter, TokenHash_Semicolon))
{ {
Result = true; Result = true;
*StructTypeHandleOut = PushTypeDefOnTypeTable(StructDecl, &Meta->TypeTable); *StructTypeHandleOut = PushTypeDefOnTypeTable(StructDecl, &Meta->TypeTable);
@ -1123,7 +1164,7 @@ ParseFunctionParameterList (token_iter* Iter, type_definition* FunctionPtrDecl,
b32 Result = false; b32 Result = false;
PushSnapshot(Iter); PushSnapshot(Iter);
if (TokenAtEquals(Iter, "(")) if (TokenAtHashEquals(Iter, TokenHash_OpenParen))
{ {
Result = true; Result = true;
@ -1142,7 +1183,7 @@ ParseFunctionParameterList (token_iter* Iter, type_definition* FunctionPtrDecl,
} }
} }
if (TokenAtEquals(Iter, ")")) if (TokenAtHashEquals(Iter, TokenHash_CloseParen))
{ {
Result = true; Result = true;
} }
@ -1183,7 +1224,7 @@ ParseFunctionDeclaration (token_iter* Iter, token* Identifier, gs_meta_preproces
if (ParseFunctionParameterList(Iter, &FunctionPtr, Meta)) if (ParseFunctionParameterList(Iter, &FunctionPtr, Meta))
{ {
if (TokenAtEquals(Iter, ";")) if (TokenAtHashEquals(Iter, TokenHash_Semicolon))
{ {
Result = true; Result = true;
PushTypeDefOnTypeTable(FunctionPtr, &Meta->TypeTable); PushTypeDefOnTypeTable(FunctionPtr, &Meta->TypeTable);
@ -1214,7 +1255,7 @@ ParseTypedef(token_iter* Iter, gs_meta_preprocessor* Meta)
{ {
token TypeToken = {0}; token TypeToken = {0};
type_table_handle TypeHandle = InvalidTypeTableHandle; type_table_handle TypeHandle = InvalidTypeTableHandle;
if (TokenAtEquals(Iter, "struct") && if (TokenAtHashEquals(Iter, TokenHash_Struct) &&
ParseStruct(Iter, &TypeHandle, Meta)) ParseStruct(Iter, &TypeHandle, Meta))
{ {
Result = true; Result = true;
@ -1258,7 +1299,7 @@ ParseTypedef(token_iter* Iter, gs_meta_preprocessor* Meta)
{ {
string* Error = TakeError(Iter->Errors); string* Error = TakeError(Iter->Errors);
PrintF(Error, "unhandled typedef "); PrintF(Error, "unhandled typedef ");
while (!TokenAtEquals(Iter, ";")) while (!TokenAtHashEquals(Iter, TokenHash_Semicolon))
{ {
PrintF(Error, "%S ", Iter->TokenAt->Text); PrintF(Error, "%S ", Iter->TokenAt->Text);
NextToken(Iter); NextToken(Iter);
@ -1283,7 +1324,7 @@ ParseEnum (token_iter* Iter, gs_meta_preprocessor* Meta)
b32 Result = false; b32 Result = false;
PushSnapshot(Iter); PushSnapshot(Iter);
if (TokenAtEquals(Iter, "enum")) if (TokenAtHashEquals(Iter, TokenHash_Enum))
{ {
token IdentifierToken = {}; token IdentifierToken = {};
if (TokenAtEquals(Iter, Token_Identifier, &IdentifierToken)) if (TokenAtEquals(Iter, Token_Identifier, &IdentifierToken))
@ -1294,7 +1335,7 @@ ParseEnum (token_iter* Iter, gs_meta_preprocessor* Meta)
CopyMetaTagsAndClear(&Meta->TagList, &EnumDecl.MetaTags); CopyMetaTagsAndClear(&Meta->TagList, &EnumDecl.MetaTags);
EnumDecl.Type = TypeDef_Enum; EnumDecl.Type = TypeDef_Enum;
if (TokenAtEquals(Iter, "{")) if (TokenAtHashEquals(Iter, TokenHash_OpenCurlyBracket))
{ {
u32 EnumAcc = 0; u32 EnumAcc = 0;
@ -1303,7 +1344,7 @@ ParseEnum (token_iter* Iter, gs_meta_preprocessor* Meta)
token EnumIdentifierToken = {}; token EnumIdentifierToken = {};
if (TokenAtEquals(Iter, Token_Identifier, &EnumIdentifierToken)) if (TokenAtEquals(Iter, Token_Identifier, &EnumIdentifierToken))
{ {
if (TokenAtEquals(Iter, "=")) if (TokenAtHashEquals(Iter, TokenHash_Equals))
{ {
// TODO(Peter): TempValue is just here until we handle all // TODO(Peter): TempValue is just here until we handle all
// const expr that could define an enum value. Its there so // const expr that could define an enum value. Its there so
@ -1331,7 +1372,7 @@ ParseEnum (token_iter* Iter, gs_meta_preprocessor* Meta)
} }
s32 EnumValue = EnumAcc++; s32 EnumValue = EnumAcc++;
if (TokenAtEquals(Iter, ",") || if (TokenAtHashEquals(Iter, TokenHash_Comma) ||
StringsEqual(Iter->TokenAt->Text, MakeStringLiteral("}"))) StringsEqual(Iter->TokenAt->Text, MakeStringLiteral("}")))
{ {
EnumDecl.Enum.Identifiers.PushElementOnBucket(EnumIdentifierToken.Text); EnumDecl.Enum.Identifiers.PushElementOnBucket(EnumIdentifierToken.Text);
@ -1345,8 +1386,8 @@ ParseEnum (token_iter* Iter, gs_meta_preprocessor* Meta)
} }
} }
if (TokenAtEquals(Iter, "}") && if (TokenAtHashEquals(Iter, TokenHash_OpenCurlyBracket) &&
TokenAtEquals(Iter, ";")) TokenAtHashEquals(Iter, TokenHash_Semicolon))
{ {
PushTypeDefOnTypeTable(EnumDecl, &Meta->TypeTable); PushTypeDefOnTypeTable(EnumDecl, &Meta->TypeTable);
Result = true; Result = true;
@ -1365,9 +1406,6 @@ ParseFunction (token_iter* Iter, gs_meta_preprocessor* Meta)
{ {
DEBUG_TRACK_FUNCTION; DEBUG_TRACK_FUNCTION;
gsm_profiler_scope* ProfilerScope = BeginScope(&Meta->Profiler,
MakeStringLiteral("parse"),
MakeStringLiteral("ParseFunction"));
b32 Result = false; b32 Result = false;
PushSnapshot(Iter); PushSnapshot(Iter);
@ -1376,11 +1414,8 @@ ParseFunction (token_iter* Iter, gs_meta_preprocessor* Meta)
{ {
token IdentifierToken = {}; token IdentifierToken = {};
if (TokenAtEquals(Iter, Token_Identifier, &IdentifierToken) && if (TokenAtEquals(Iter, Token_Identifier, &IdentifierToken) &&
TokenAtEquals(Iter, "(")) TokenAtHashEquals(Iter, TokenHash_OpenParen))
{ {
gsm_profiler_scope* ProfilerInnerScope = BeginScope(&Meta->Profiler,
MakeStringLiteral("parse"),
MakeStringLiteral("ParseFunctionInner"));
type_definition FunctionDecl = {}; type_definition FunctionDecl = {};
FunctionDecl.Identifier = IdentifierToken.Text; FunctionDecl.Identifier = IdentifierToken.Text;
FunctionDecl.Function.ReturnTypeHandle = ReturnTypeHandle; FunctionDecl.Function.ReturnTypeHandle = ReturnTypeHandle;
@ -1395,23 +1430,21 @@ ParseFunction (token_iter* Iter, gs_meta_preprocessor* Meta)
} }
if(!TokenAtEquals(Iter, ",")) if(!TokenAtHashEquals(Iter, TokenHash_Comma))
{ {
break; break;
} }
} }
if (TokenAtEquals(Iter, ")")) if (TokenAtHashEquals(Iter, TokenHash_OpenParen))
{ {
Result = true; Result = true;
PushTypeDefOnTypeTable(FunctionDecl, &Meta->TypeTable); PushTypeDefOnTypeTable(FunctionDecl, &Meta->TypeTable);
} }
EndScope(ProfilerInnerScope);
} }
} }
ApplySnapshotIfNotParsedAndPop(Result, Iter); ApplySnapshotIfNotParsedAndPop(Result, Iter);
EndScope(ProfilerScope);
return Result; return Result;
} }
@ -1524,9 +1557,6 @@ PrintFunctionPtrDecl (type_definition* FnPtrDecl, type_table TypeTable)
internal gs_meta_preprocessor internal gs_meta_preprocessor
PreprocessProgram (base_allocator Allocator, char* SourceFile) PreprocessProgram (base_allocator Allocator, char* SourceFile)
{ {
GlobalDebugServices.Arena = CreateMemoryArena(Allocator);
GlobalDebugServices.Transient = CreateMemoryArena(Allocator);
DEBUG_TRACK_FUNCTION; DEBUG_TRACK_FUNCTION;
gs_meta_preprocessor Meta = {}; gs_meta_preprocessor Meta = {};

View File

@ -59,7 +59,7 @@ EatIdentifier (tokenizer* Tokenizer)
{ {
s32 Length = 0; s32 Length = 0;
while (Tokenizer->At[0] && while (Tokenizer->At[0] &&
(IsAlpha(Tokenizer->At[0]) || IsNumericExtended(Tokenizer->At[0]))) (IsAlpha(Tokenizer->At[0]) || IsNumericExtended(Tokenizer->At[0])))
{ {
++Tokenizer->At; ++Tokenizer->At;
@ -135,7 +135,7 @@ GetNextToken (tokenizer* Tokenizer)
char C = Tokenizer->At[0]; char C = Tokenizer->At[0];
++Tokenizer->At; ++Tokenizer->At;
if (C == 0) { Result.Type = Token_EndOfStream; } if (C == 0) { Result.Type = Token_EndOfStream; }
else if (C == '(') { Result.Type = Token_LeftParen; } else if (C == '(') { Result.Type = Token_LeftParen; }
else if (C == ')') { Result.Type = Token_RightParen; } else if (C == ')') { Result.Type = Token_RightParen; }
else if (C == '[') { Result.Type = Token_LeftSquareBracket; } else if (C == '[') { Result.Type = Token_LeftSquareBracket; }
@ -145,9 +145,9 @@ GetNextToken (tokenizer* Tokenizer)
else if (C == ';') { Result.Type = Token_Semicolon; } else if (C == ';') { Result.Type = Token_Semicolon; }
else if (C == ',') { Result.Type = Token_Comma; } else if (C == ',') { Result.Type = Token_Comma; }
else if (C == '.') { Result.Type = Token_Period; } else if (C == '.') { Result.Type = Token_Period; }
else if (C == '-' && Tokenizer->At[0] && Tokenizer->At[0] == '>') else if (C == '-' && Tokenizer->At[0] && Tokenizer->At[0] == '>')
{ {
Result.Type = Token_PointerReference; Result.Type = Token_PointerReference;
Result.Text.Length = 2; Result.Text.Length = 2;
++Tokenizer->At; ++Tokenizer->At;
} }
@ -157,67 +157,67 @@ GetNextToken (tokenizer* Tokenizer)
EatWhitespace(Tokenizer); EatWhitespace(Tokenizer);
if (TokenAtEquals(Tokenizer, "define")) if (TokenAtEquals(Tokenizer, "define"))
{ {
Result.Type = Token_PoundDefine; Result.Type = Token_PoundDefine;
EatPreprocessor(Tokenizer); EatPreprocessor(Tokenizer);
Result.Text.Length = Tokenizer->At - Result.Text.Memory; Result.Text.Length = Tokenizer->At - Result.Text.Memory;
} }
else if (TokenAtEquals(Tokenizer, "undef")) else if (TokenAtEquals(Tokenizer, "undef"))
{ {
Result.Type = Token_PoundUndef; Result.Type = Token_PoundUndef;
EatToNewLine(Tokenizer); EatToNewLine(Tokenizer);
Result.Text.Length = Tokenizer->At - Result.Text.Memory; Result.Text.Length = Tokenizer->At - Result.Text.Memory;
} }
else if (TokenAtEquals(Tokenizer, "include")) else if (TokenAtEquals(Tokenizer, "include"))
{ {
Result.Type = Token_PoundInclude; Result.Type = Token_PoundInclude;
Result.Text.Length = Tokenizer->At - Result.Text.Memory; Result.Text.Length = Tokenizer->At - Result.Text.Memory;
} }
else if (TokenAtEquals(Tokenizer, "ifdef")) else if (TokenAtEquals(Tokenizer, "ifdef"))
{ {
Result.Type = Token_PoundIfDef; Result.Type = Token_PoundIfDef;
EatToNewLine(Tokenizer); EatToNewLine(Tokenizer);
Result.Text.Length = Tokenizer->At - Result.Text.Memory; Result.Text.Length = Tokenizer->At - Result.Text.Memory;
} }
else if (TokenAtEquals(Tokenizer, "ifndef")) else if (TokenAtEquals(Tokenizer, "ifndef"))
{ {
Result.Type = Token_PoundIfNDef; Result.Type = Token_PoundIfNDef;
EatToNewLine(Tokenizer); EatToNewLine(Tokenizer);
Result.Text.Length = Tokenizer->At - Result.Text.Memory; Result.Text.Length = Tokenizer->At - Result.Text.Memory;
} }
else if (TokenAtEquals(Tokenizer, "if")) else if (TokenAtEquals(Tokenizer, "if"))
{ {
Result.Type = Token_PoundIf; Result.Type = Token_PoundIf;
EatToNewLine(Tokenizer); EatToNewLine(Tokenizer);
Result.Text.Length = Tokenizer->At - Result.Text.Memory; Result.Text.Length = Tokenizer->At - Result.Text.Memory;
} }
else if (TokenAtEquals(Tokenizer, "elif")) else if (TokenAtEquals(Tokenizer, "elif"))
{ {
Result.Type = Token_PoundElif; Result.Type = Token_PoundElif;
EatToNewLine(Tokenizer); EatToNewLine(Tokenizer);
Result.Text.Length = Tokenizer->At - Result.Text.Memory; Result.Text.Length = Tokenizer->At - Result.Text.Memory;
} }
else if (TokenAtEquals(Tokenizer, "else")) else if (TokenAtEquals(Tokenizer, "else"))
{ {
Result.Type = Token_PoundElse; Result.Type = Token_PoundElse;
EatToNewLine(Tokenizer); EatToNewLine(Tokenizer);
Result.Text.Length = Tokenizer->At - Result.Text.Memory; Result.Text.Length = Tokenizer->At - Result.Text.Memory;
} }
else if (TokenAtEquals(Tokenizer, "endif")) else if (TokenAtEquals(Tokenizer, "endif"))
{ {
Result.Type = Token_PoundEndif; Result.Type = Token_PoundEndif;
EatToNewLine(Tokenizer); EatToNewLine(Tokenizer);
Result.Text.Length = Tokenizer->At - Result.Text.Memory; Result.Text.Length = Tokenizer->At - Result.Text.Memory;
} }
else if (TokenAtEquals(Tokenizer, "error")) else if (TokenAtEquals(Tokenizer, "error"))
{ {
Result.Type = Token_PoundError; Result.Type = Token_PoundError;
EatToNewLine(Tokenizer); EatToNewLine(Tokenizer);
Result.Text.Length = Tokenizer->At - Result.Text.Memory; Result.Text.Length = Tokenizer->At - Result.Text.Memory;
} }
else if (TokenAtEquals(Tokenizer, "pragma")) else if (TokenAtEquals(Tokenizer, "pragma"))
{ {
Result.Type = Token_PoundPragma; Result.Type = Token_PoundPragma;
EatToNewLine(Tokenizer); EatToNewLine(Tokenizer);
Result.Text.Length = Tokenizer->At - Result.Text.Memory; Result.Text.Length = Tokenizer->At - Result.Text.Memory;
} }
@ -257,5 +257,6 @@ GetNextToken (tokenizer* Tokenizer)
Result.Text.Length += EatIdentifier(Tokenizer); Result.Text.Length += EatIdentifier(Tokenizer);
} }
Result.TextHash = HashDJB2ToU64(Result.Text.Memory);
return Result; return Result;
} }

View File

@ -44,6 +44,7 @@ struct type_table_handle
// #define TypeHandleIsValid(handle) (!((handle).BucketIndex == 0) && ((handle).IndexInBucket == 0)) // #define TypeHandleIsValid(handle) (!((handle).BucketIndex == 0) && ((handle).IndexInBucket == 0))
inline b32 TypeHandleIsValid(type_table_handle A) inline b32 TypeHandleIsValid(type_table_handle A)
{ {
DEBUG_TRACK_FUNCTION;
b32 FirstBucket = (A.BucketIndex == 0); b32 FirstBucket = (A.BucketIndex == 0);
b32 FirstIndex = (A.IndexInBucket == 0); b32 FirstIndex = (A.IndexInBucket == 0);
b32 Both = FirstBucket && FirstIndex; b32 Both = FirstBucket && FirstIndex;
@ -153,6 +154,7 @@ struct type_table
internal b32 internal b32
HandlesAreEqual(type_table_handle A, type_table_handle B) HandlesAreEqual(type_table_handle A, type_table_handle B)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = ((A.BucketIndex == B.BucketIndex) && (A.IndexInBucket == B.IndexInBucket)); b32 Result = ((A.BucketIndex == B.BucketIndex) && (A.IndexInBucket == B.IndexInBucket));
return Result; return Result;
} }
@ -160,6 +162,7 @@ HandlesAreEqual(type_table_handle A, type_table_handle B)
internal u32 internal u32
HashIdentifier(string Identifier) HashIdentifier(string Identifier)
{ {
DEBUG_TRACK_FUNCTION;
u32 IdentHash = HashString(Identifier); u32 IdentHash = HashString(Identifier);
if (IdentHash == 0) if (IdentHash == 0)
{ {
@ -174,6 +177,7 @@ HashIdentifier(string Identifier)
internal type_table_handle internal type_table_handle
GetTypeHandle (string Identifier, type_table TypeTable) GetTypeHandle (string Identifier, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
type_table_handle Result = InvalidTypeTableHandle; type_table_handle Result = InvalidTypeTableHandle;
u32 IdentHash = HashIdentifier(Identifier); u32 IdentHash = HashIdentifier(Identifier);
@ -196,6 +200,7 @@ GetTypeHandle (string Identifier, type_table TypeTable)
internal type_table_handle internal type_table_handle
GetMetaTagHandle(string Identifier, type_table TypeTable) GetMetaTagHandle(string Identifier, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
type_table_handle Result = InvalidTypeTableHandle; type_table_handle Result = InvalidTypeTableHandle;
u32 IdentHash = HashIdentifier(Identifier); u32 IdentHash = HashIdentifier(Identifier);
@ -218,6 +223,7 @@ GetMetaTagHandle(string Identifier, type_table TypeTable)
internal type_table_handle internal type_table_handle
GetMetaTagHandleWithIdentifier(string Identifier, type_table TypeTable) GetMetaTagHandleWithIdentifier(string Identifier, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
type_table_handle Result = InvalidTypeTableHandle; type_table_handle Result = InvalidTypeTableHandle;
u32 IdentHash = HashIdentifier(Identifier); u32 IdentHash = HashIdentifier(Identifier);
@ -239,6 +245,7 @@ GetMetaTagHandleWithIdentifier(string Identifier, type_table TypeTable)
internal b32 internal b32
HasTag(string Needle, gs_bucket<type_table_handle> Tags, type_table TypeTable) HasTag(string Needle, gs_bucket<type_table_handle> Tags, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
type_table_handle NeedleTagHandle = GetMetaTagHandleWithIdentifier(Needle, TypeTable); type_table_handle NeedleTagHandle = GetMetaTagHandleWithIdentifier(Needle, TypeTable);
@ -261,6 +268,7 @@ HasTag(string Needle, gs_bucket<type_table_handle> Tags, type_table TypeTable)
internal void internal void
CopyMetaTagsAndClear(gs_bucket<type_table_handle>* Source, gs_bucket<type_table_handle>* Dest) CopyMetaTagsAndClear(gs_bucket<type_table_handle>* Source, gs_bucket<type_table_handle>* Dest)
{ {
DEBUG_TRACK_FUNCTION;
for (u32 i = 0; i < Source->Used; i++) for (u32 i = 0; i < Source->Used; i++)
{ {
type_table_handle* TagToken = Source->GetElementAtIndex(i); type_table_handle* TagToken = Source->GetElementAtIndex(i);
@ -272,6 +280,7 @@ CopyMetaTagsAndClear(gs_bucket<type_table_handle>* Source, gs_bucket<type_table_
internal type_table_handle internal type_table_handle
FindSlotForTypeIdentifier(u32 IdentHash, type_table* TypeTable) FindSlotForTypeIdentifier(u32 IdentHash, type_table* TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
type_table_handle Result = InvalidTypeTableHandle; type_table_handle Result = InvalidTypeTableHandle;
u32 Index = IdentHash % TYPE_TABLE_BUCKET_MAX; u32 Index = IdentHash % TYPE_TABLE_BUCKET_MAX;
@ -312,6 +321,7 @@ FindSlotForTypeIdentifier(u32 IdentHash, type_table* TypeTable)
internal type_table_handle internal type_table_handle
FindSlotForMetaTag(u32 IdentHash, type_table* TypeTable) FindSlotForMetaTag(u32 IdentHash, type_table* TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
type_table_handle Result = InvalidTypeTableHandle; type_table_handle Result = InvalidTypeTableHandle;
u32 Index = IdentHash % TYPE_TABLE_BUCKET_MAX; u32 Index = IdentHash % TYPE_TABLE_BUCKET_MAX;
@ -348,6 +358,7 @@ FindSlotForMetaTag(u32 IdentHash, type_table* TypeTable)
internal type_table_handle internal type_table_handle
PushTypeOnHashTable(type_definition TypeDef, type_table* TypeTable) PushTypeOnHashTable(type_definition TypeDef, type_table* TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
u32 IdentHash = HashIdentifier(TypeDef.Identifier); u32 IdentHash = HashIdentifier(TypeDef.Identifier);
type_table_handle Result = FindSlotForTypeIdentifier(IdentHash, TypeTable); type_table_handle Result = FindSlotForTypeIdentifier(IdentHash, TypeTable);
@ -367,6 +378,7 @@ PushTypeOnHashTable(type_definition TypeDef, type_table* TypeTable)
internal type_table_handle internal type_table_handle
PushUndeclaredType (string Identifier, type_table* TypeTable) PushUndeclaredType (string Identifier, type_table* TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
type_definition UndeclaredTypeDef = {}; type_definition UndeclaredTypeDef = {};
UndeclaredTypeDef.Identifier = Identifier; UndeclaredTypeDef.Identifier = Identifier;
UndeclaredTypeDef.Type = TypeDef_Unknown; UndeclaredTypeDef.Type = TypeDef_Unknown;
@ -377,6 +389,7 @@ PushUndeclaredType (string Identifier, type_table* TypeTable)
internal type_table_handle internal type_table_handle
PushMetaTagOnTable(meta_tag Tag, type_table* TypeTable) PushMetaTagOnTable(meta_tag Tag, type_table* TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
u32 TagIdentifierHash = HashIdentifier(Tag.Identifier); u32 TagIdentifierHash = HashIdentifier(Tag.Identifier);
type_table_handle Result = FindSlotForMetaTag(TagIdentifierHash, TypeTable); type_table_handle Result = FindSlotForMetaTag(TagIdentifierHash, TypeTable);
@ -396,6 +409,7 @@ PushMetaTagOnTable(meta_tag Tag, type_table* TypeTable)
internal type_definition* internal type_definition*
GetTypeDefinition(type_table_handle Handle, type_table TypeTable) GetTypeDefinition(type_table_handle Handle, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
Assert(TypeHandleIsValid(Handle)); Assert(TypeHandleIsValid(Handle));
type_definition* Result = 0; type_definition* Result = 0;
if (TypeTable.Types[Handle.BucketIndex].Keys != 0) if (TypeTable.Types[Handle.BucketIndex].Keys != 0)
@ -409,6 +423,7 @@ GetTypeDefinition(type_table_handle Handle, type_table TypeTable)
internal type_definition* internal type_definition*
GetTypeDefinitionUnsafe(type_table_handle Handle, type_table TypeTable) GetTypeDefinitionUnsafe(type_table_handle Handle, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
type_definition* Result = 0; type_definition* Result = 0;
if (TypeTable.Types[Handle.BucketIndex].Keys != 0) if (TypeTable.Types[Handle.BucketIndex].Keys != 0)
{ {
@ -420,6 +435,7 @@ GetTypeDefinitionUnsafe(type_table_handle Handle, type_table TypeTable)
internal meta_tag* internal meta_tag*
GetMetaTag(type_table_handle Handle, type_table TypeTable) GetMetaTag(type_table_handle Handle, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
meta_tag* Result = 0; meta_tag* Result = 0;
if (TypeTable.MetaTags[Handle.BucketIndex].Keys != 0) if (TypeTable.MetaTags[Handle.BucketIndex].Keys != 0)
{ {
@ -431,6 +447,7 @@ GetMetaTag(type_table_handle Handle, type_table TypeTable)
internal type_definition* internal type_definition*
GetTypeDefinition(string Identifier, type_table TypeTable) GetTypeDefinition(string Identifier, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
type_definition* Result = 0; type_definition* Result = 0;
u32 IdentHash = HashIdentifier(Identifier); u32 IdentHash = HashIdentifier(Identifier);
u32 Index = IdentHash % TYPE_TABLE_BUCKET_MAX; u32 Index = IdentHash % TYPE_TABLE_BUCKET_MAX;
@ -449,6 +466,7 @@ GetTypeDefinition(string Identifier, type_table TypeTable)
internal type_table_handle internal type_table_handle
PushTypeDefOnTypeTable(type_definition TypeDef, type_table* TypeTable) PushTypeDefOnTypeTable(type_definition TypeDef, type_table* TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
// NOTE(Peter): We don't accept type definitions with empty identifiers. // NOTE(Peter): We don't accept type definitions with empty identifiers.
// If a struct or union is anonymous, it should be assigned a name of the form // If a struct or union is anonymous, it should be assigned a name of the form
// parent_struct_name_# where # is the member index // parent_struct_name_# where # is the member index
@ -478,6 +496,7 @@ PushTypeDefOnTypeTable(type_definition TypeDef, type_table* TypeTable)
internal s32 internal s32
GetSizeOfType (type_table_handle TypeHandle, type_table TypeTable) GetSizeOfType (type_table_handle TypeHandle, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
s32 Result = -1; s32 Result = -1;
type_definition* TypeDef = GetTypeDefinition(TypeHandle, TypeTable); type_definition* TypeDef = GetTypeDefinition(TypeHandle, TypeTable);
if (TypeDef) if (TypeDef)
@ -490,6 +509,7 @@ GetSizeOfType (type_table_handle TypeHandle, type_table TypeTable)
internal s32 internal s32
GetSizeOfType (string Identifier, type_table TypeTable) GetSizeOfType (string Identifier, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
s32 Result = -1; s32 Result = -1;
type_definition* TypeDef = GetTypeDefinition(Identifier, TypeTable); type_definition* TypeDef = GetTypeDefinition(Identifier, TypeTable);
if (TypeDef) if (TypeDef)
@ -502,6 +522,7 @@ GetSizeOfType (string Identifier, type_table TypeTable)
internal b32 internal b32
VariableDeclsEqual (variable_decl A, variable_decl B) VariableDeclsEqual (variable_decl A, variable_decl B)
{ {
DEBUG_TRACK_FUNCTION;
b32 Result = false; b32 Result = false;
if (TypeHandlesEqual(A.TypeHandle, B.TypeHandle) && if (TypeHandlesEqual(A.TypeHandle, B.TypeHandle) &&
A.ArrayCount == B.ArrayCount && A.ArrayCount == B.ArrayCount &&
@ -515,6 +536,7 @@ VariableDeclsEqual (variable_decl A, variable_decl B)
internal b32 internal b32
StructOrUnionsEqual (type_definition A, type_definition B) StructOrUnionsEqual (type_definition A, type_definition B)
{ {
DEBUG_TRACK_FUNCTION;
// NOTE(Peter): Fairly certain the only places this is used are when we // NOTE(Peter): Fairly certain the only places this is used are when we
// already know the identifiers match // already know the identifiers match
Assert(StringsEqual(A.Identifier, B.Identifier)); Assert(StringsEqual(A.Identifier, B.Identifier));
@ -543,6 +565,7 @@ StructOrUnionsEqual (type_definition A, type_definition B)
internal type_table_handle internal type_table_handle
FindHandleOfMatchingType (type_definition Match, type_table TypeTable) FindHandleOfMatchingType (type_definition Match, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
type_table_handle Result = InvalidTypeTableHandle; type_table_handle Result = InvalidTypeTableHandle;
type_table_handle Handle = GetTypeHandle(Match.Identifier, TypeTable); type_table_handle Handle = GetTypeHandle(Match.Identifier, TypeTable);
if (TypeHandleIsValid(Handle)) if (TypeHandleIsValid(Handle))
@ -558,6 +581,7 @@ internal void FixUpUnionSize (type_table_handle TypeHandle, type_table TypeTable
internal void internal void
FixupMemberType (variable_decl* Member, type_table TypeTable) FixupMemberType (variable_decl* Member, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
if (!TypeHandleIsValid(Member->TypeHandle)) if (!TypeHandleIsValid(Member->TypeHandle))
{ {
Member->TypeHandle = GetTypeHandle(Member->Identifier, TypeTable); Member->TypeHandle = GetTypeHandle(Member->Identifier, TypeTable);
@ -568,6 +592,7 @@ FixupMemberType (variable_decl* Member, type_table TypeTable)
internal s32 internal s32
CalculateStructMemberSize (variable_decl Member, type_definition MemberType) CalculateStructMemberSize (variable_decl Member, type_definition MemberType)
{ {
DEBUG_TRACK_FUNCTION;
Assert(TypeHandleIsValid(Member.TypeHandle)); Assert(TypeHandleIsValid(Member.TypeHandle));
// NOTE(Peter): At one point we were Asserting on struct sizes of zero, but // NOTE(Peter): At one point we were Asserting on struct sizes of zero, but
// that's actually incorrect. It is valid to have an empty struct. // that's actually incorrect. It is valid to have an empty struct.
@ -589,6 +614,7 @@ CalculateStructMemberSize (variable_decl Member, type_definition MemberType)
internal void internal void
FixupStructMember (variable_decl* Member, type_definition* MemberTypeDef, type_table TypeTable, errors* Errors) FixupStructMember (variable_decl* Member, type_definition* MemberTypeDef, type_table TypeTable, errors* Errors)
{ {
DEBUG_TRACK_FUNCTION;
// NOTE(Peter): There are a lot of cases where struct members which are pointers // NOTE(Peter): There are a lot of cases where struct members which are pointers
// to other structs cause interesting behavior here. // to other structs cause interesting behavior here.
// For example: // For example:
@ -643,6 +669,7 @@ FixupStructMember (variable_decl* Member, type_definition* MemberTypeDef, type_t
internal void internal void
FixUpStructSize (type_table_handle TypeHandle, type_table TypeTable, errors* Errors) FixUpStructSize (type_table_handle TypeHandle, type_table TypeTable, errors* Errors)
{ {
DEBUG_TRACK_FUNCTION;
type_definition* Struct = GetTypeDefinition(TypeHandle, TypeTable); type_definition* Struct = GetTypeDefinition(TypeHandle, TypeTable);
Assert(Struct->Type == TypeDef_Struct); Assert(Struct->Type == TypeDef_Struct);
@ -688,6 +715,7 @@ FixUpStructSize (type_table_handle TypeHandle, type_table TypeTable, errors* Err
internal void internal void
FixUpUnionSize (type_table_handle TypeHandle, type_table TypeTable, errors* Errors) FixUpUnionSize (type_table_handle TypeHandle, type_table TypeTable, errors* Errors)
{ {
DEBUG_TRACK_FUNCTION;
type_definition* Union = GetTypeDefinition(TypeHandle, TypeTable); type_definition* Union = GetTypeDefinition(TypeHandle, TypeTable);
Assert(Union->Type == TypeDef_Union); Assert(Union->Type == TypeDef_Union);
@ -745,6 +773,7 @@ type_definition CPPBasicTypes[] = {
internal void internal void
PopulateTableWithDefaultCPPTypes(type_table* TypeTable) PopulateTableWithDefaultCPPTypes(type_table* TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
for (u32 i = 0; i < GSArrayLength(CPPBasicTypes); i++) for (u32 i = 0; i < GSArrayLength(CPPBasicTypes); i++)
{ {
PushTypeDefOnTypeTable(CPPBasicTypes[i], TypeTable); PushTypeDefOnTypeTable(CPPBasicTypes[i], TypeTable);
@ -754,6 +783,7 @@ PopulateTableWithDefaultCPPTypes(type_table* TypeTable)
internal void internal void
PrintTypeDefinition(type_definition TypeDef, type_table TypeTable) PrintTypeDefinition(type_definition TypeDef, type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
printf("Type: %.*s\n", StringExpand(TypeDef.Identifier)); printf("Type: %.*s\n", StringExpand(TypeDef.Identifier));
printf(" Size: %d\n", TypeDef.Size); printf(" Size: %d\n", TypeDef.Size);
@ -819,6 +849,7 @@ PrintTypeDefinition(type_definition TypeDef, type_table TypeTable)
internal void internal void
PrintTypeTable(type_table TypeTable) PrintTypeTable(type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
for (u32 b = 0; b < TypeTable.TypeBucketsCount; b++) for (u32 b = 0; b < TypeTable.TypeBucketsCount; b++)
{ {
type_table_hash_bucket Bucket = TypeTable.Types[b]; type_table_hash_bucket Bucket = TypeTable.Types[b];
@ -835,6 +866,7 @@ PrintTypeTable(type_table TypeTable)
internal void internal void
DEBUGPrintTypeTableMembership(type_table TypeTable) DEBUGPrintTypeTableMembership(type_table TypeTable)
{ {
DEBUG_TRACK_FUNCTION;
printf("\n--- Type Table Membership --\n"); printf("\n--- Type Table Membership --\n");
u32 SlotsAvailable = 0; u32 SlotsAvailable = 0;
u32 SlotsFilled = 0; u32 SlotsFilled = 0;

View File

@ -15,6 +15,14 @@ Profile 1:
Total Allocated Space: 1217890 bytes, or 1.161470 MB Total Allocated Space: 1217890 bytes, or 1.161470 MB
Total Time: 0.061852 seconds Total Time: 0.061852 seconds
Profile 2:
Profile 3:
Converted many of the TokenAtEquals to TokenAtHashEquals
Total Allocated Space: 912143773 bytes, or 869.888089 MB
Total Time: 4.915469