2023-07-11 00:10:20 -07:00
|
|
|
#pragma once
|
|
|
|
|
2023-07-18 21:13:12 -07:00
|
|
|
#if GEN_TIME
|
2023-07-15 23:26:55 -07:00
|
|
|
#define GEN_DEFINE_LIBRARY_CODE_CONSTANTS
|
|
|
|
#define GEN_ENFORCE_STRONG_CODE_TYPES
|
2023-07-16 15:00:07 -07:00
|
|
|
#define GEN_EXPOSE_BACKEND
|
|
|
|
#define GEN_BENCHMARK
|
2023-07-11 00:10:20 -07:00
|
|
|
#include "gen.hpp"
|
|
|
|
#include "Buffer.Parsed.hpp"
|
|
|
|
|
|
|
|
using namespace gen;
|
|
|
|
|
|
|
|
Code gen__ring( StrC type )
|
|
|
|
{
|
|
|
|
static Code t_allocator_info = def_type( name(AllocatorInfo) );
|
|
|
|
|
2023-07-11 22:33:11 -07:00
|
|
|
StringCached name;
|
2023-07-11 00:10:20 -07:00
|
|
|
{
|
|
|
|
char const* name_str = str_fmt_buf( "Ring_%s\0", type.Ptr );
|
|
|
|
s32 name_len = str_len( name_str );
|
|
|
|
|
|
|
|
name = get_cached_string({ name_len, name_str });
|
|
|
|
};
|
|
|
|
|
2023-07-11 22:33:11 -07:00
|
|
|
StrC buffer_name = to_StrC( str_fmt_buf( "Buffer_%s", type.Ptr ));
|
|
|
|
|
|
|
|
Code ring = parse_struct( token_fmt( "RingName", (StrC)name, "type", type, "BufferName", buffer_name,
|
|
|
|
stringize(
|
2023-07-11 00:10:20 -07:00
|
|
|
struct <RingName>
|
|
|
|
{
|
|
|
|
using Type = <type>;
|
|
|
|
|
|
|
|
static <RingName> init( AllocatorInfo allocator, uw max_size )
|
|
|
|
{
|
|
|
|
<RingName> result = { 0 };
|
|
|
|
|
|
|
|
result.Backing = allocator;
|
|
|
|
result.Buffer = <BufferName>::init( allocator, max_size + 1 );
|
|
|
|
|
|
|
|
if ( result.Buffer == nullptr )
|
|
|
|
return { nullptr };
|
|
|
|
|
|
|
|
result.Capacity = max_size + 1;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void append( s16 value )
|
|
|
|
{
|
|
|
|
Buffer[ Head ] = value;
|
|
|
|
Head = ( Head + 1 ) % Capacity;
|
|
|
|
if ( Head == Tail )
|
|
|
|
Tail = ( Tail + 1 ) % Capacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void append( Type* values, sw num )
|
|
|
|
{
|
|
|
|
for ( sw idx = 0; idx < num; idx++ )
|
|
|
|
append( values[ idx ] );
|
|
|
|
}
|
|
|
|
|
|
|
|
bool empty( void )
|
|
|
|
{
|
|
|
|
return Head == Tail;
|
|
|
|
}
|
|
|
|
|
|
|
|
void free( void )
|
|
|
|
{
|
|
|
|
Buffer.free();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool full( void )
|
|
|
|
{
|
|
|
|
return ( Head + 1 ) % Capacity == Tail;
|
|
|
|
}
|
|
|
|
|
|
|
|
Type& get( void )
|
|
|
|
{
|
|
|
|
Type& data = Buffer[ Tail ];
|
|
|
|
Tail = ( Tail + 1 ) % Capacity;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wipe( void )
|
|
|
|
{
|
|
|
|
Head = 0;
|
|
|
|
Tail = 0;
|
|
|
|
Buffer.wipe();
|
|
|
|
}
|
|
|
|
|
|
|
|
AllocatorInfo Backing;
|
|
|
|
uw Capacity;
|
|
|
|
uw Head;
|
|
|
|
uw Tail;
|
|
|
|
<BufferName> Buffer;
|
|
|
|
};
|
2023-07-11 22:33:11 -07:00
|
|
|
)
|
2023-07-11 00:10:20 -07:00
|
|
|
));
|
|
|
|
|
|
|
|
return ring;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct GenRingRequest
|
|
|
|
{
|
|
|
|
StrC Dependency;
|
|
|
|
StrC Type;
|
|
|
|
};
|
2023-07-11 15:29:45 -07:00
|
|
|
Array<GenRingRequest> GenRingRequests;
|
2023-07-11 00:10:20 -07:00
|
|
|
|
2023-07-11 22:33:11 -07:00
|
|
|
void gen__ring_request( StrC type, StrC dep = {} )
|
2023-07-11 00:10:20 -07:00
|
|
|
{
|
|
|
|
do_once_start
|
2023-07-29 13:00:06 -07:00
|
|
|
GenRingRequests = Array<GenRingRequest>::init( GlobalAllocator );
|
2023-07-11 00:10:20 -07:00
|
|
|
do_once_end
|
|
|
|
|
|
|
|
// Make sure we don't already have a request for the type.
|
2023-07-11 15:29:45 -07:00
|
|
|
for ( sw idx = 0; idx < GenRingRequests.num(); ++idx )
|
2023-07-11 00:10:20 -07:00
|
|
|
{
|
|
|
|
StrC const reqest_type = GenRingRequests[ idx ].Type;
|
|
|
|
|
|
|
|
if ( reqest_type.Len != type.Len )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ( str_compare( reqest_type.Ptr, type.Ptr, reqest_type.Len ) == 0 )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ring definition depends on a array and buffer definition.
|
|
|
|
gen__buffer_request( type, dep );
|
|
|
|
|
|
|
|
GenRingRequest request = { dep, type };
|
2023-07-11 15:29:45 -07:00
|
|
|
GenRingRequests.append( request );
|
2023-07-11 00:10:20 -07:00
|
|
|
}
|
2023-07-11 22:33:11 -07:00
|
|
|
#define gen_ring( type ) gen__ring_request( code(type) )
|
2023-07-11 00:10:20 -07:00
|
|
|
|
|
|
|
u32 gen_ring_file()
|
|
|
|
{
|
|
|
|
Builder
|
|
|
|
gen_ring_file;
|
|
|
|
gen_ring_file.open( "ring.Parsed.gen.hpp" );
|
|
|
|
|
2023-07-15 19:27:38 -07:00
|
|
|
gen_ring_file.print( def_include( txt_StrC("gen.hpp")) );
|
2023-07-11 22:33:11 -07:00
|
|
|
gen_ring_file.print( def_include( txt_StrC("buffer.Parsed.gen.hpp")) );
|
2023-07-11 00:10:20 -07:00
|
|
|
// gen_ring_file.print( gen__ring_base() );
|
|
|
|
|
2023-07-11 22:33:11 -07:00
|
|
|
gen_ring_file.print( def_using_namespace( name(gen)));
|
|
|
|
|
2023-07-11 00:10:20 -07:00
|
|
|
GenRingRequest* current = GenRingRequests;
|
2023-07-11 15:29:45 -07:00
|
|
|
s32 left = GenRingRequests.num();
|
2023-07-11 00:10:20 -07:00
|
|
|
while (left--)
|
|
|
|
{
|
|
|
|
GenRingRequest const& request = * current;
|
|
|
|
|
|
|
|
Code generated_ring = gen__ring( current->Type );
|
|
|
|
|
|
|
|
if ( request.Dependency )
|
|
|
|
{
|
|
|
|
char const* cmt_str = str_fmt_buf( "// Dependency for %s type", request.Type );
|
|
|
|
s32 cmt_len = str_len( cmt_str );
|
|
|
|
|
|
|
|
Code cmt = def_comment( { cmt_len, cmt_str } );
|
|
|
|
Code include = def_include( request.Dependency );
|
|
|
|
|
|
|
|
gen_ring_file.print( cmt );
|
|
|
|
gen_ring_file.print( include );
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_ring_file.print( generated_ring );
|
|
|
|
current++;
|
|
|
|
}
|
|
|
|
|
|
|
|
gen_ring_file.write();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-07-18 21:13:12 -07:00
|
|
|
#endif // GEN_TIME
|