mirror of
https://github.com/Ed94/HandmadeHero.git
synced 2024-12-22 14:24:43 -08:00
85 lines
2.2 KiB
C++
85 lines
2.2 KiB
C++
#if GEN_TIME
|
|
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
|
#define GEN_IMPLEMENTATION
|
|
#define GEN_BENCHMARK
|
|
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
|
#include "dependencies/gen.hpp"
|
|
#undef min
|
|
#undef max
|
|
#undef cast
|
|
|
|
#define path_gen "./gen/"
|
|
|
|
using namespace gen;
|
|
using GStr = gen::Str;
|
|
|
|
int gen_main()
|
|
{
|
|
gen::Context ctx {};
|
|
gen::init( & ctx);
|
|
log_fmt("Generating code for Handmade Hero: Platform Module\n");
|
|
|
|
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 );
|
|
|
|
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 } );
|
|
|
|
CodeStruct context_struct = {};
|
|
for ( Code code : code_context )
|
|
{
|
|
if ( code->Type == CT_Struct )
|
|
{
|
|
if ( code->Name.is_equal(txt("Context")) )
|
|
{
|
|
context_struct = code;
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
Array<Code> context_data_members = Array<Code>::init_reserve( ctx.Allocator_Temp, kilobytes( 1 ) );
|
|
for ( Code code : context_struct->Body )
|
|
{
|
|
if ( code->Type == CT_Variable )
|
|
{
|
|
context_data_members.append( code );
|
|
}
|
|
}
|
|
|
|
CodeDefine using_context;
|
|
{
|
|
StrBuilder using_context_content = StrBuilder::make_reserve( ctx.Allocator_Temp, kilobytes( 1 ) );
|
|
{
|
|
StrBuilder
|
|
content = using_context_content;
|
|
content.append( "\\\n" );
|
|
|
|
for ( s32 id = 0; id < context_data_members.num() - 1; ++id )
|
|
{
|
|
Code code = context_data_members[ id ];
|
|
content.append( code.to_strbuilder() );
|
|
|
|
// 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" );
|
|
}
|
|
content.append( context_data_members[ context_data_members.num() - 1 ].to_strbuilder() );
|
|
}
|
|
|
|
using_context = def_define( txt("using_context()"), MT_Statement, { {}, using_context_content } );
|
|
}
|
|
|
|
builder.print( using_context );
|
|
builder.write();
|
|
|
|
log_fmt("Generaton finished for Handmade Hero: Platform Module\n\n");
|
|
// gen::deinit();
|
|
return 0;
|
|
}
|
|
#endif
|