mirror of
https://github.com/Ed94/gencpp.git
synced 2025-06-15 03:01:47 -07:00
WIP: Design is almost done, impl this weekend.
This commit is contained in:
22
test/c99/meson.build
Normal file
22
test/c99/meson.build
Normal file
@ -0,0 +1,22 @@
|
||||
project( 'test', 'c', default_options : ['buildtype=debug'] )
|
||||
|
||||
# add_global_arguments('-E', language : 'cpp')
|
||||
|
||||
includes = include_directories(
|
||||
[
|
||||
'../gen',
|
||||
'../../singleheader'
|
||||
])
|
||||
|
||||
# get_sources = files('./get_sources.ps1')
|
||||
# sources = files(run_command('powershell', get_sources, check: true).stdout().strip().split('\n'))
|
||||
|
||||
sources = [ 'test.c99.c' ]
|
||||
|
||||
if get_option('buildtype').startswith('debug')
|
||||
|
||||
add_project_arguments('-DBuild_Debug', language : ['c' ])
|
||||
|
||||
endif
|
||||
|
||||
executable( 'test_c99', sources, include_directories : includes )
|
79
test/c99/table.h
Normal file
79
test/c99/table.h
Normal file
@ -0,0 +1,79 @@
|
||||
#include "gen.h"
|
||||
|
||||
#define Table( Type_ ) Table_##Type_
|
||||
|
||||
typedef u64(*)(void*) HashingFn;
|
||||
|
||||
#if gen_time
|
||||
# define gen_table( Type_, HashingFn_ ) gen_request_table( #Type_, sizeof(Type_), HashingFn_ )
|
||||
|
||||
u64 table_default_hash_fn( void* address )
|
||||
{
|
||||
return crc32( address, 4 );
|
||||
}
|
||||
|
||||
Code gen_table_code( char const* type_str, sw type_size, HashingFn hash_fn )
|
||||
{
|
||||
Code table;
|
||||
|
||||
return table;
|
||||
}
|
||||
|
||||
struct TableRequest
|
||||
{
|
||||
char const* Type;
|
||||
sw Size;
|
||||
HashingFn HashFn;
|
||||
};
|
||||
|
||||
array(TableRequest) TableRequests;
|
||||
|
||||
void gen_request_table( const char* type_str, sw type_size, HashingFn hash_fn )
|
||||
{
|
||||
TableRequest request = { type_str, type_size, hash_fn };
|
||||
|
||||
array_append( TableRequests, request );
|
||||
}
|
||||
|
||||
u32 gen_table_file()
|
||||
{
|
||||
gen_table( u32 );
|
||||
gen_table( char const* );
|
||||
|
||||
array(Code) array_asts;
|
||||
array_init( array_asts, g_allocator );
|
||||
|
||||
sw left = array_count( TableRequests );
|
||||
sw index = 0;
|
||||
while( left -- )
|
||||
{
|
||||
ArrayRequest request = TableRequests[index];
|
||||
|
||||
Code result = gen_table_code( request.Name, request.Size, request.HashFn );
|
||||
|
||||
array_append( array_asts, result );
|
||||
}
|
||||
|
||||
Builder
|
||||
arraygen;
|
||||
arraygen.open( "table.gen.h" );
|
||||
|
||||
left = array_count( array_asts );
|
||||
index = 0;
|
||||
|
||||
while( left-- )
|
||||
{
|
||||
Code code = array_asts[index];
|
||||
|
||||
arraygen.print( code );
|
||||
}
|
||||
|
||||
arraygen.write();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifndef gen_time
|
||||
# include "table.gen.h"
|
||||
#endif
|
||||
|
40
test/c99/test.c99.c
Normal file
40
test/c99/test.c99.c
Normal file
@ -0,0 +1,40 @@
|
||||
#define GENC_IMPLEMENTATION
|
||||
#include "genc.h"
|
||||
#include "table.h"
|
||||
|
||||
|
||||
struct Test
|
||||
{
|
||||
u64 A;
|
||||
u64 B;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#if gen_time
|
||||
|
||||
|
||||
u64 hash_struct( void* test )
|
||||
{
|
||||
return crc32( ((Test)test).A, sizeof(u64) );
|
||||
}
|
||||
|
||||
|
||||
int gen_main()
|
||||
{
|
||||
gen_table( Test, & hash_struct )
|
||||
|
||||
gen_table_file();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if runtime
|
||||
int main()
|
||||
{
|
||||
Table(Test) test_table;
|
||||
|
||||
|
||||
}
|
||||
#endif
|
Reference in New Issue
Block a user