Lumenarium/meta/foldhaus_meta.cpp

83 lines
3.1 KiB
C++
Raw Normal View History

//
2020-01-21 05:11:07 +00:00
// File: foldhaus_meta.cpp
// Author: Peter Slattery
// Creation Date: 2020-01-19
//
2020-01-21 05:11:07 +00:00
#ifndef FOLDHAUS_META_CPP
#include "gs_meta.cpp"
#include "gs_meta_typeinfo_generator.h"
int main(int ArgCount, char* Args[])
{
if (ArgCount <= 1)
{
printf("Please supply at least one source directory to analyze.\n");
return 0;
}
gs_meta_preprocessor Meta = PreprocessProgram(Args[1]);
typeinfo_generator TypeGenerator = InitTypeInfoGenerator(Meta.TypeTable);
GenerateFilteredTypeInfo(MakeStringLiteral("node_struct"), Meta.TypeTable, &TypeGenerator);
GenerateFilteredTypeInfo(MakeStringLiteral("gen_type_info"), Meta.TypeTable, &TypeGenerator);
FinishGeneratingTypes(&TypeGenerator);
2020-01-21 05:11:07 +00:00
gsm_code_generator NodeTypeGen = BeginEnumGeneration("node_type", "NodeType", false, true);
// TODO(Peter): Create a FilterTypesByTag function to create a contiguous array
// of type_definition**
printf("\n\n");
for (u32 b = 0; b < Meta.TypeTable.TypeBucketsCount; b++)
2020-01-21 05:11:07 +00:00
{
type_table_hash_bucket Bucket = Meta.TypeTable.Types[b];
for (u32 i = 0; i < TYPE_TABLE_BUCKET_MAX; i++)
2020-01-21 05:11:07 +00:00
{
if (!Bucket.Keys[i] == 0) { continue; }
2020-01-21 05:11:07 +00:00
type_definition* Decl = Bucket.Values + i;
if (HasTag(MakeStringLiteral("node_proc"), Decl->MetaTags) &&
Decl->Type == TypeDef_Function)
2020-01-21 05:11:07 +00:00
{
AddEnumElement(&NodeTypeGen, Decl->Identifier);
type_table_handle ReturnTypeHandle = Decl->Function.ReturnTypeHandle;
type_definition* ReturnType = GetTypeDefinition(ReturnTypeHandle, Meta.TypeTable);
printf("%.*s %.*s(\n", StringExpand(ReturnType->Identifier), StringExpand(Decl->Identifier));
for (u32 j = 0; j < Decl->Function.Parameters.Used; j++)
{
variable_decl* Param = Decl->Function.Parameters.GetElementAtIndex(j);
type_table_handle ParamTypeHandle = Param->TypeHandle;
type_definition* ParamType = GetTypeDefinition(ParamTypeHandle, Meta.TypeTable);
printf(" %.*s %.*s,\n", StringExpand(ParamType->Identifier), StringExpand(Param->Identifier));
}
printf(");\n\n");
2020-01-21 05:11:07 +00:00
}
}
}
printf("\n\n");
FinishEnumGeneration(&NodeTypeGen);
FILE* TypeInfoH = fopen("C:\\projects\\foldhaus\\src\\generated\\gs_meta_generated_typeinfo.h", "w");
if (TypeInfoH)
{
2020-01-21 05:11:07 +00:00
WriteStringBuilderToFile(*TypeGenerator.TypeList.Builder, TypeInfoH);
WriteStringBuilderToFile(TypeGenerator.StructMembers, TypeInfoH);
WriteStringBuilderToFile(TypeGenerator.TypeDefinitions, TypeInfoH);
2020-01-20 01:03:19 +00:00
fclose(TypeInfoH);
}
2020-01-21 05:11:07 +00:00
FILE* NodeInfoH = fopen("C:\\projects\\foldhaus\\src\\generated\\foldhaus_nodes_generated.h", "w");
if (NodeInfoH)
{
WriteStringBuilderToFile(*NodeTypeGen.Builder, NodeInfoH);
fclose(NodeInfoH);
}
FinishMetaprogram(&Meta);
//__debugbreak();
2019-10-30 14:28:02 +00:00
return 0;
2020-01-21 05:11:07 +00:00
}
#define FOLDHAUS_META_CPP
#endif // FOLDHAUS_META_CPP