2023-07-30 15:55:57 -07:00
|
|
|
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
|
|
|
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
|
|
|
#define GEN_EXPOSE_BACKEND
|
|
|
|
#define GEN_BENCHMARK
|
2023-08-20 09:31:24 -07:00
|
|
|
#include "gen.hpp"
|
|
|
|
#include "gen.builder.hpp"
|
|
|
|
#include "gen.scanner.hpp"
|
2023-07-30 15:55:57 -07:00
|
|
|
using namespace gen;
|
|
|
|
|
|
|
|
void check_singleheader_ast()
|
|
|
|
{
|
2023-08-20 12:45:06 -07:00
|
|
|
#define project_dir "../"
|
2023-07-30 15:55:57 -07:00
|
|
|
gen::init();
|
|
|
|
log_fmt("\ncheck_singleheader_ast:\n");
|
|
|
|
|
2023-08-06 14:46:17 -07:00
|
|
|
FileContents file = file_read_contents( GlobalAllocator, true, project_dir "singleheader/gen/gen.hpp" );
|
|
|
|
u64 time_start = time_rel_ms();
|
|
|
|
CodeBody ast = parse_global_body( { file.size, (char const*)file.data } );
|
2023-07-30 15:55:57 -07:00
|
|
|
|
2023-08-06 14:46:17 -07:00
|
|
|
log_fmt("\nAst generated. Time taken: %llu ms\n", time_rel_ms() - time_start);
|
2023-07-30 15:55:57 -07:00
|
|
|
|
2023-08-06 14:46:17 -07:00
|
|
|
log_fmt("\nSerializng ast:\n");
|
|
|
|
time_start = time_rel_ms();
|
2023-08-01 11:02:54 -07:00
|
|
|
|
2023-08-06 14:46:17 -07:00
|
|
|
Builder
|
2023-08-20 10:02:50 -07:00
|
|
|
builder = Builder::open( "gen/singleheader_copy.gen.hpp" );
|
2023-07-30 15:55:57 -07:00
|
|
|
builder.print( ast );
|
|
|
|
builder.write();
|
|
|
|
|
2023-08-23 10:17:22 -07:00
|
|
|
log_fmt("Serialized. Time taken: %llu ms\n", time_rel_ms() - time_start);
|
|
|
|
|
|
|
|
FileContents file_gen = file_read_contents( GlobalAllocator, true, "gen/singleheader_copy.gen.hpp" );
|
|
|
|
|
2023-08-23 10:17:30 -07:00
|
|
|
log_fmt("\nReconstructing from generated file:\n");
|
2023-08-23 10:17:22 -07:00
|
|
|
time_start = time_rel_ms();
|
|
|
|
CodeBody ast_gen = parse_global_body( { file_gen.size, (char const*)file_gen.data } );
|
|
|
|
|
2023-08-23 18:19:31 -07:00
|
|
|
log_fmt("\nAst generated. Time taken: %llu ms\n\n", time_rel_ms() - time_start);
|
2023-08-23 10:17:22 -07:00
|
|
|
|
|
|
|
time_start = time_rel_ms();
|
|
|
|
|
|
|
|
if ( ast.is_equal( ast_gen ) )
|
2023-08-23 15:16:45 -07:00
|
|
|
log_fmt( "\nPassed!: AST passed validation!\n" );
|
2023-08-23 10:17:22 -07:00
|
|
|
else
|
2023-08-23 15:16:45 -07:00
|
|
|
log_fmt( "\nFailed: AST did not pass validation\n" );
|
2023-08-23 10:17:22 -07:00
|
|
|
|
|
|
|
log_fmt( "Time taken: %llu ms\n", time_rel_ms() - time_start );
|
2023-08-06 14:46:17 -07:00
|
|
|
|
2023-07-30 15:55:57 -07:00
|
|
|
gen::deinit();
|
|
|
|
}
|