HandmadeHero/project/codegen/engine_postbuild_gen.cpp

117 lines
3.3 KiB
C++
Raw Normal View History

2023-09-28 18:57:52 -07:00
#include "platform/compiler_ignores.hpp"
#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"
2023-09-28 18:57:52 -07:00
#undef ccast
#undef pcast
#undef rcast
#undef scast
2023-09-28 18:57:52 -07:00
#undef do_once
#undef do_once_start
#undef do_once_end
using namespace gen;
#include <math.h>
2023-10-11 14:52:13 -07:00
#include "platform/platform_module.hpp"
2023-10-06 23:33:39 -07:00
#include "platform/grime.hpp"
#include "platform/macros.hpp"
#include "platform/generics.hpp"
2023-10-06 23:33:39 -07:00
#include "platform/types.hpp"
#include "platform/intrinsics.hpp"
2023-10-06 23:33:39 -07:00
#include "platform/strings.hpp"
#include "platform/platform.hpp"
2023-09-28 18:57:52 -07:00
2023-10-11 14:52:13 -07:00
#include "engine/engine_module.hpp"
#include "engine/gen/vectors.hpp"
#include "engine/gen/physics.hpp"
2023-10-11 14:52:13 -07:00
#include "engine/input.hpp"
#include "engine/tile_map.hpp"
2023-10-06 23:33:39 -07:00
#include "engine/engine.hpp"
#include "engine/engine_to_platform_api.hpp"
2023-09-28 18:57:52 -07:00
constexpr StrC fname_handmade_engine_symbols = txt("handmade_engine.symbols");
2023-09-29 12:58:18 -07:00
void get_symbols_from_module_table( FileContents symbol_table, Array<String> symbols )
{
struct Token
{
char const* Ptr;
u32 Len;
};
char const* scanner = rcast( char const*, symbol_table.data );
u32 left = symbol_table.size;
while ( left )
{
if ( *scanner == '\n' || *scanner == '\r' )
{
++ scanner;
-- left;
}
else
{
2023-09-29 12:58:18 -07:00
Token token {};
token.Ptr = scanner;
while ( left && *scanner != '\r' && *scanner != '\n' )
{
-- left;
++ scanner;
2023-09-29 12:58:18 -07:00
++ token.Len;
}
2023-09-29 12:58:18 -07:00
symbols.append( String::make_length( GlobalAllocator, token.Ptr, token.Len ) );
}
}
}
int gen_main()
{
gen::init();
log_fmt("Generating code for Handmade Hero: Engine Module (Post-Build)\n");
FileContents symbol_table = file_read_contents( GlobalAllocator, true, fname_handmade_engine_symbols );
#pragma push_macro("str_ascii")
#undef str_ascii
2023-10-20 20:15:35 -07:00
Builder builder = Builder::open( "engine_symbols.gen.hpp" );
builder.print( pragma_once );
builder.print( def_include( txt("engine/engine.hpp") ) );
builder.print( fmt_newline );
builder.print_fmt( "NS_ENGINE_BEGIN\n\n" );
2023-09-29 12:58:18 -07:00
Array<String> symbols = Array<String>::init_reserve( GlobalAllocator, kilobytes(1) );
get_symbols_from_module_table( symbol_table, symbols );
using ModuleAPI = engine::ModuleAPI;
2023-09-29 12:58:18 -07:00
builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_OnModuleReload], stringize(
constexpr const Str symbol_on_module_load = str_ascii("<symbol>");
))));
2023-09-29 12:58:18 -07:00
builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_Startup], stringize(
constexpr const Str symbol_startup = str_ascii("<symbol>");
))));
2023-09-29 12:58:18 -07:00
builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_Shutdown], stringize(
constexpr const Str symbol_shutdown = str_ascii("<symbol>");
))));
2023-09-29 12:58:18 -07:00
builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_UpdateAndRender], stringize(
constexpr const Str symbol_update_and_render = str_ascii("<symbol>");
))));
2023-09-29 12:58:18 -07:00
builder.print( parse_variable( token_fmt( "symbol", (StrC)symbols[ModuleAPI::Sym_UpdateAudio], stringize(
constexpr const Str symbol_update_audio = str_ascii("<symbol>");
))));
builder.print_fmt( "\nNS_ENGINE_END" );
builder.print( fmt_newline );
builder.write();
#pragma pop_macro("str_ascii")
log_fmt("Generaton finished for Handmade Hero: Engine Module (Post-Build)\n\n");
// gen::deinit();
return 0;
}
#endif