[vulkan] Make array and single parsing smarter

Array and single type overrides now allow the parsing of the items
themselves to be customized. This makes it easy to handle arrays and
pointers to single items while also using custom specifications, rather
than relying entirely on the custom override.
This commit is contained in:
Bill Currie 2021-01-04 15:30:27 +09:00
parent 0426879bf6
commit a6a3d4c6b5
7 changed files with 103 additions and 15 deletions

View file

@ -11,6 +11,7 @@ vkgen_dat_src= \
libs/video/renderer/vulkan/vkgen/vkfielddef.r \
libs/video/renderer/vulkan/vkgen/vkfieldsingle.r \
libs/video/renderer/vulkan/vkgen/vkfieldstring.r \
libs/video/renderer/vulkan/vkgen/vkfieldtype.r \
libs/video/renderer/vulkan/vkgen/vkgen.r \
libs/video/renderer/vulkan/vkgen/vkstruct.r \
libs/video/renderer/vulkan/vkgen/vktype.r \

View file

@ -3,9 +3,11 @@
#include "vkfielddef.h"
@class FieldType;
@interface ArrayField: FieldDef
{
string type;
FieldType *type;
}
@end

View file

@ -1,6 +1,7 @@
#include <PropertyList.h>
#include "vkfieldarray.h"
#include "vkfieldtype.h"
#include "vkgen.h"
#include "vktype.h"
@ -14,7 +15,7 @@
}
PLItem *desc = [item getObjectForKey:"type"];
type = [[desc getObjectAtIndex:1] string];
type = [[FieldType fieldType:[desc getObjectAtIndex:1]] retain];
value_field = [[item getObjectForKey:"values"] string];
size_field = [[item getObjectForKey:"size"] string];
@ -23,13 +24,9 @@
-writeParseData
{
Type *field_type = [[Type lookup: type] dereference];
fprintf (output_file, "static parse_array_t parse_%s_%s_data = {\n",
struct_name, field_name);
fprintf (output_file, "\t%s,\n", [field_type parseType]);
fprintf (output_file, "\tsizeof (%s),\n", type);
fprintf (output_file, "\tparse_%s,\n", type);
[type writeParseData];
fprintf (output_file, "\tfield_offset (%s, %s),\n",
struct_name, value_field);
if (size_field) {

View file

@ -3,9 +3,11 @@
#include "vkfielddef.h"
@class FieldType;
@interface SingleField: FieldDef
{
string type;
FieldType *type;
}
@end

View file

@ -1,6 +1,7 @@
#include <PropertyList.h>
#include "vkfieldsingle.h"
#include "vkfieldtype.h"
#include "vkgen.h"
#include "vktype.h"
@ -14,7 +15,7 @@
}
PLItem *desc = [item getObjectForKey:"type"];
type = [[desc getObjectAtIndex:1] string];
type = [[FieldType fieldType:[desc getObjectAtIndex:1]] retain];
value_field = [[item getObjectForKey:"value"] string];
return self;
@ -22,13 +23,9 @@
-writeParseData
{
Type *field_type = [[Type lookup: type] dereference];
fprintf (output_file, "static parse_single_t parse_%s_%s_data = {\n",
struct_name, field_name);
fprintf (output_file, "\t%s,\n", [field_type parseType]);
fprintf (output_file, "\tsizeof (%s),\n", type);
fprintf (output_file, "\tparse_%s,\n", type);
[type writeParseData];
fprintf (output_file, "\tfield_offset (%s, %s),\n",
struct_name, value_field);
fprintf (output_file, "};\n");
@ -37,7 +34,7 @@
-writeField
{
string parse_type = [[[Type lookup: type] dereference] parseType];
string parse_type = [type parseType];
fprintf (output_file, "\t{\"%s\", 0, %s, parse_%s, &parse_%s_%s_data},\n",
field_name, parse_type, "single", struct_name, field_name);
return self;

View file

@ -0,0 +1,20 @@
#ifndef __renderer_vulkan_vkgen_vkfieldtype_h
#define __renderer_vulkan_vkgen_vkfieldtype_h
#include <Object.h>
@class PLItem;
@interface FieldType: Object
{
string parse_type;
string type;
string parser;
}
+fieldType:(PLItem *)item;
-initWithItem:(PLItem *)item;
-writeParseData;
-(string)parseType;
@end
#endif//__renderer_vulkan_vkgen_vkfieldtype_h

View file

@ -0,0 +1,69 @@
#include <PropertyList.h>
#include <string.h>
#include "vkfieldtype.h"
#include "vkgen.h"
#include "vktype.h"
@implementation FieldType
+fieldType:(PLItem *)item
{
return [[[self alloc] initWithItem:item] autorelease];
}
-(void)dealloc
{
str_free (parser);
str_free (parse_type);
}
static string
parseItemType (PLItem *item)
{
string str = [item string];
if (str) {
return str;
}
string mask = "QFMultiType";
for (int i = [item count]; i-- > 0; ) {
str = [[item getObjectAtIndex:i] string];
mask = mask + " | (1 << " + str + ")";
}
return str_hold (mask);
}
-initWithItem:(PLItem *)item
{
if (!(self = [super init])) {
return nil;
}
type = [item string];
if (type) {
Type *field_type = [[Type lookup:type] dereference];
parse_type = [field_type parseType];
parser = str_hold ("parse_" + type);
} else {
parse_type = parseItemType([item getObjectForKey:"parse_type"]);
type = [[item getObjectForKey:"type"] string];
parser = [[item getObjectForKey:"parser"] string];
}
return self;
}
-writeParseData
{
fprintf (output_file, "\t%s,\n", parse_type);
fprintf (output_file, "\tsizeof (%s),\n", type);
fprintf (output_file, "\t%s,\n", parser);
return self;
}
-(string) parseType
{
return parse_type;
}
@end