2023-09-08 12:14:09 -07:00
|
|
|
#if GEN_TIME
|
|
|
|
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
|
|
|
#define GEN_IMPLEMENTATION
|
|
|
|
#define GEN_BENCHMARK
|
|
|
|
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
2023-09-28 18:21:05 -07:00
|
|
|
#include "dependencies/gen.hpp"
|
2023-12-30 12:25:58 -08:00
|
|
|
#undef min
|
|
|
|
#undef max
|
2024-12-14 05:02:47 -08:00
|
|
|
#undef cast
|
2023-09-08 12:14:09 -07:00
|
|
|
|
2023-10-01 17:17:14 -07:00
|
|
|
#define path_gen "./gen/"
|
|
|
|
|
2024-12-14 05:02:47 -08:00
|
|
|
using namespace gen;
|
|
|
|
using GStr = gen::Str;
|
2023-10-01 17:17:14 -07:00
|
|
|
|
2023-09-08 12:14:09 -07:00
|
|
|
int gen_main()
|
|
|
|
{
|
2024-12-14 05:02:47 -08:00
|
|
|
gen::Context ctx {};
|
|
|
|
gen::init( & ctx);
|
2023-09-28 18:21:05 -07:00
|
|
|
log_fmt("Generating code for Handmade Hero: Platform Module\n");
|
2023-10-01 17:17:14 -07:00
|
|
|
|
|
|
|
CodeComment generation_notice = def_comment( txt("This was generated by project/codegen/platform_gen.cpp") );
|
|
|
|
|
|
|
|
Builder builder = Builder::open( path_gen "context.gen.hpp");
|
|
|
|
builder.print( generation_notice );
|
|
|
|
builder.print( fmt_newline );
|
|
|
|
|
2024-12-14 05:02:47 -08:00
|
|
|
FileContents h_context = file_read_contents(ctx.Allocator_Temp, true, "context.hpp");
|
|
|
|
CodeBody code_context = parse_global_body( { rcast( char const*, h_context.data ), h_context.size } );
|
2023-10-01 17:17:14 -07:00
|
|
|
|
|
|
|
CodeStruct context_struct = {};
|
|
|
|
for ( Code code : code_context )
|
|
|
|
{
|
2024-12-14 05:02:47 -08:00
|
|
|
if ( code->Type == CT_Struct )
|
2023-10-01 17:17:14 -07:00
|
|
|
{
|
2024-12-14 05:02:47 -08:00
|
|
|
if ( code->Name.is_equal(txt("Context")) )
|
2023-10-01 17:17:14 -07:00
|
|
|
{
|
|
|
|
context_struct = code;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-14 05:02:47 -08:00
|
|
|
Array<Code> context_data_members = Array<Code>::init_reserve( ctx.Allocator_Temp, kilobytes( 1 ) );
|
2023-10-01 17:17:14 -07:00
|
|
|
for ( Code code : context_struct->Body )
|
|
|
|
{
|
2024-12-14 05:02:47 -08:00
|
|
|
if ( code->Type == CT_Variable )
|
2023-10-01 17:17:14 -07:00
|
|
|
{
|
|
|
|
context_data_members.append( code );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeDefine using_context;
|
|
|
|
{
|
2024-12-14 05:02:47 -08:00
|
|
|
StrBuilder using_context_content = StrBuilder::make_reserve( ctx.Allocator_Temp, kilobytes( 1 ) );
|
2023-10-01 17:17:14 -07:00
|
|
|
{
|
2024-12-14 05:02:47 -08:00
|
|
|
StrBuilder
|
2023-10-01 17:17:14 -07:00
|
|
|
content = using_context_content;
|
|
|
|
content.append( "\\\n" );
|
|
|
|
|
|
|
|
for ( s32 id = 0; id < context_data_members.num() - 1; ++id )
|
|
|
|
{
|
|
|
|
Code code = context_data_members[ id ];
|
2024-12-14 05:02:47 -08:00
|
|
|
content.append( code.to_strbuilder() );
|
2023-10-01 17:17:14 -07:00
|
|
|
|
|
|
|
// Default serializer inserts a newline at the end of the string, we need to insert a line continuation
|
|
|
|
content[ content.length() - 1 ] = '\\';
|
|
|
|
content.append( "\n" );
|
|
|
|
}
|
2024-12-14 05:02:47 -08:00
|
|
|
content.append( context_data_members[ context_data_members.num() - 1 ].to_strbuilder() );
|
2023-10-01 17:17:14 -07:00
|
|
|
}
|
2024-12-15 07:43:47 -08:00
|
|
|
|
|
|
|
using_context = def_define( txt("using_context()"), MT_Statement, { {}, using_context_content } );
|
2023-10-01 17:17:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
builder.print( using_context );
|
|
|
|
builder.write();
|
|
|
|
|
|
|
|
log_fmt("Generaton finished for Handmade Hero: Platform Module\n\n");
|
2023-09-08 21:01:53 -07:00
|
|
|
// gen::deinit();
|
2023-09-08 12:14:09 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|