Made the meta system put generated files relative to the root file rather than at an absolute path

This commit is contained in:
Peter Slattery 2020-02-29 14:43:07 -08:00
parent 67d3dd1e26
commit b103ede28c
3 changed files with 72 additions and 4 deletions

View File

@ -254,6 +254,19 @@ GeneratePanelMetaInfo(gs_meta_preprocessor Meta, string_builder* PanelCodeGen)
WriteF(PanelCodeGen, "};\n");
}
internal string
AllocAndConcatStrings(string First, string Second)
{
string Result = {0};
Result.Max = First.Length + Second.Length + 1;
Result.Memory = (char*)malloc(sizeof(char) * Result.Max);
ConcatString(First, &Result);
ConcatString(Second, &Result);
NullTerminate(&Result);
Result.Length -= 1;
return Result;
}
int main(int ArgCount, char* Args[])
{
if (ArgCount <= 1)
@ -262,6 +275,13 @@ int main(int ArgCount, char* Args[])
return 0;
}
string RootFile = MakeString(Args[1]);
s32 IndexOfLastSlash = ReverseSearchForCharInSet(RootFile, "\\/");
string WorkingDirectory = Substring(RootFile, 0, IndexOfLastSlash + 1);
string GeneratedDirectoryName = MakeStringLiteral("generated\\");
string GeneratedFilesDirectory = AllocAndConcatStrings(WorkingDirectory, GeneratedDirectoryName);
printf("Putting Generated Files In %s\n", GeneratedFilesDirectory.Memory);
gs_meta_preprocessor Meta = PreprocessProgram(Args[1]);
typeinfo_generator TypeGenerator = InitTypeInfoGenerator(Meta.TypeTable);
@ -278,7 +298,8 @@ int main(int ArgCount, char* Args[])
string_builder PanelCodeGen = {0};
GeneratePanelMetaInfo(Meta, &PanelCodeGen);
FILE* TypeInfoH = fopen("C:\\projects\\foldhaus\\src\\generated\\gs_meta_generated_typeinfo.h", "w");
string TypeInfoHFilePath = AllocAndConcatStrings(GeneratedFilesDirectory, MakeStringLiteral("gs_meta_genreated_typeinfo.h"));
FILE* TypeInfoH = fopen(TypeInfoHFilePath.Memory, "w");
if (TypeInfoH)
{
WriteStringBuilderToFile(TypeGenerator.MetaTagEnum, TypeInfoH);
@ -288,8 +309,13 @@ int main(int ArgCount, char* Args[])
WriteStringBuilderToFile(TypeGenerator.TypeDefinitions, TypeInfoH);
fclose(TypeInfoH);
}
else
{
printf("Error: Unable to open file at %.*s\n", StringExpand(TypeInfoHFilePath));
}
FILE* NodeInfoH = fopen("C:\\projects\\foldhaus\\src\\generated\\foldhaus_nodes_generated.h", "w");
string NodeInfoHFilePath = AllocAndConcatStrings(GeneratedFilesDirectory, MakeStringLiteral("foldhaus_nodes_generated.h"));
FILE* NodeInfoH = fopen(TypeInfoHFilePath.Memory, "w");
if (NodeInfoH)
{
WriteStringBuilderToFile(*NodeTypeGen.Builder, NodeInfoH);
@ -297,13 +323,22 @@ int main(int ArgCount, char* Args[])
WriteStringBuilderToFile(CallNodeProcGen, NodeInfoH);
fclose(NodeInfoH);
}
else
{
printf("Error: Unable to open file at %.*s\n", StringExpand(NodeInfoHFilePath));
}
FILE* PanelInfoH = fopen("C:\\projects\\foldhaus\\src\\generated\\foldhaus_panels_generated.h", "w");
string PanelInfoHFilePath = AllocAndConcatStrings(GeneratedFilesDirectory, MakeStringLiteral("foldhaus_panels_generated.h"));
FILE* PanelInfoH = fopen(PanelInfoHFilePath.Memory, "w");
if (PanelInfoH)
{
WriteStringBuilderToFile(PanelCodeGen, PanelInfoH);
fclose(PanelInfoH);
}
else
{
printf("Error: Unable to open file at %.*s\n", StringExpand(PanelInfoHFilePath));
}
FinishMetaprogram(&Meta);

View File

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

View File

@ -2,8 +2,9 @@ TODO FOLDHAUS
Ground Up Reengineering
- Metaprogramming
- panels metaprogramming
x panels metaprogramming
- fix memory layout (remeber to profile before and after)
x get the meta program to generate code in the codebase's directory, no matter where it is
- Make the DLL truly platform agnostic
- math.h: present for trig functions