From 017d2c1f4453daa7802e031958fab96a9ef7316d Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 23 Dec 2020 22:13:50 +0900 Subject: [PATCH] [vulkan] Refactor vkgen struct generation The addition of data an then string support made keeping track of things in struct's writeTable a nightmare. --- .../video/renderer/vulkan/vkgen/Makemodule.am | 6 + libs/video/renderer/vulkan/vkgen/vkenum.h | 2 +- libs/video/renderer/vulkan/vkgen/vkenum.r | 2 +- .../renderer/vulkan/vkgen/vkfieldarray.h | 12 + .../renderer/vulkan/vkgen/vkfieldarray.r | 52 ++++ .../video/renderer/vulkan/vkgen/vkfieldauto.h | 9 + .../video/renderer/vulkan/vkgen/vkfieldauto.r | 43 ++++ .../video/renderer/vulkan/vkgen/vkfielddata.h | 9 + .../video/renderer/vulkan/vkgen/vkfielddata.r | 45 ++++ libs/video/renderer/vulkan/vkgen/vkfielddef.h | 28 +++ libs/video/renderer/vulkan/vkgen/vkfielddef.r | 95 ++++++++ .../renderer/vulkan/vkgen/vkfieldsingle.h | 12 + .../renderer/vulkan/vkgen/vkfieldsingle.r | 46 ++++ .../renderer/vulkan/vkgen/vkfieldstring.h | 9 + .../renderer/vulkan/vkgen/vkfieldstring.r | 36 +++ libs/video/renderer/vulkan/vkgen/vkgen.h | 1 + libs/video/renderer/vulkan/vkgen/vkgen.r | 9 +- libs/video/renderer/vulkan/vkgen/vkstruct.h | 7 +- libs/video/renderer/vulkan/vkgen/vkstruct.r | 229 +++++------------- libs/video/renderer/vulkan/vkparse.c | 24 +- 20 files changed, 499 insertions(+), 177 deletions(-) create mode 100644 libs/video/renderer/vulkan/vkgen/vkfieldarray.h create mode 100644 libs/video/renderer/vulkan/vkgen/vkfieldarray.r create mode 100644 libs/video/renderer/vulkan/vkgen/vkfieldauto.h create mode 100644 libs/video/renderer/vulkan/vkgen/vkfieldauto.r create mode 100644 libs/video/renderer/vulkan/vkgen/vkfielddata.h create mode 100644 libs/video/renderer/vulkan/vkgen/vkfielddata.r create mode 100644 libs/video/renderer/vulkan/vkgen/vkfielddef.h create mode 100644 libs/video/renderer/vulkan/vkgen/vkfielddef.r create mode 100644 libs/video/renderer/vulkan/vkgen/vkfieldsingle.h create mode 100644 libs/video/renderer/vulkan/vkgen/vkfieldsingle.r create mode 100644 libs/video/renderer/vulkan/vkgen/vkfieldstring.h create mode 100644 libs/video/renderer/vulkan/vkgen/vkfieldstring.r diff --git a/libs/video/renderer/vulkan/vkgen/Makemodule.am b/libs/video/renderer/vulkan/vkgen/Makemodule.am index 66971a2c3..31c22d936 100644 --- a/libs/video/renderer/vulkan/vkgen/Makemodule.am +++ b/libs/video/renderer/vulkan/vkgen/Makemodule.am @@ -4,6 +4,12 @@ noinst_PROGRAMS += $(vkgen) vkgen_dat_src= \ libs/video/renderer/vulkan/vkgen/vkalias.r \ libs/video/renderer/vulkan/vkgen/vkenum.r \ + libs/video/renderer/vulkan/vkgen/vkfieldarray.r \ + libs/video/renderer/vulkan/vkgen/vkfieldauto.r \ + libs/video/renderer/vulkan/vkgen/vkfielddata.r \ + 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/vkgen.r \ libs/video/renderer/vulkan/vkgen/vkstruct.r \ libs/video/renderer/vulkan/vkgen/vktype.r \ diff --git a/libs/video/renderer/vulkan/vkgen/vkenum.h b/libs/video/renderer/vulkan/vkgen/vkenum.h index 6694c24cb..4df770b92 100644 --- a/libs/video/renderer/vulkan/vkgen/vkenum.h +++ b/libs/video/renderer/vulkan/vkgen/vkenum.h @@ -10,7 +10,7 @@ int prefix_length; } -(void) writeTable; --(void) writeSymtabInit:(PLItem *) parse; +-(void) writeSymtabInit; @end #endif//__renderer_vulkan_vkgen_vkenum_h diff --git a/libs/video/renderer/vulkan/vkgen/vkenum.r b/libs/video/renderer/vulkan/vkgen/vkenum.r index e3894902a..234c99b61 100644 --- a/libs/video/renderer/vulkan/vkgen/vkenum.r +++ b/libs/video/renderer/vulkan/vkgen/vkenum.r @@ -123,7 +123,7 @@ skip_value(string name) fprintf (header_file, "extern exprenum_t %s_enum;\n", [self name]); } --(void) writeSymtabInit:(PLItem *) parse +-(void) writeSymtabInit { fprintf (output_file, "\tcexpr_init_symtab (&%s_symtab, context);\n", [self name]); diff --git a/libs/video/renderer/vulkan/vkgen/vkfieldarray.h b/libs/video/renderer/vulkan/vkgen/vkfieldarray.h new file mode 100644 index 000000000..5cf31880b --- /dev/null +++ b/libs/video/renderer/vulkan/vkgen/vkfieldarray.h @@ -0,0 +1,12 @@ +#ifndef __renderer_vulkan_vkgen_vkfieldarray_h +#define __renderer_vulkan_vkgen_vkfieldarray_h + +#include "vkfielddef.h" + +@interface ArrayField: FieldDef +{ + string type; +} +@end + +#endif//__renderer_vulkan_vkgen_vkfieldarray_h diff --git a/libs/video/renderer/vulkan/vkgen/vkfieldarray.r b/libs/video/renderer/vulkan/vkgen/vkfieldarray.r new file mode 100644 index 000000000..dd81dd9f4 --- /dev/null +++ b/libs/video/renderer/vulkan/vkgen/vkfieldarray.r @@ -0,0 +1,52 @@ +#include + +#include "vkfieldarray.h" +#include "vkgen.h" +#include "vktype.h" + +@implementation ArrayField + +-init:(PLItem *) item struct:(Struct *)strct field:(string)fname +{ + self = [super init:item struct:strct field:fname]; + if (!self) { + return self; + } + + PLItem *desc = [item getObjectForKey:"type"]; + type = [[desc getObjectAtIndex:1] string]; + + value_field = [[item getObjectForKey:"values"] string]; + size_field = [[item getObjectForKey:"size"] string]; + return self; +} + +-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); + fprintf (output_file, "\tfield_offset (%s, %s),\n", + struct_name, value_field); + if (size_field) { + fprintf (output_file, "\tfield_offset (%s, %s),\n", + struct_name, size_field); + } else { + fprintf (output_file, "\t-1,\n"); + } + fprintf (output_file, "};\n"); + return self; +} + +-writeField +{ + fprintf (output_file, "\t{\"%s\", 0, %s, parse_%s, &parse_%s_%s_data},\n", + field_name, "QFArray", "array", struct_name, field_name); + return self; +} + +@end diff --git a/libs/video/renderer/vulkan/vkgen/vkfieldauto.h b/libs/video/renderer/vulkan/vkgen/vkfieldauto.h new file mode 100644 index 000000000..a2e05deb8 --- /dev/null +++ b/libs/video/renderer/vulkan/vkgen/vkfieldauto.h @@ -0,0 +1,9 @@ +#ifndef __renderer_vulkan_vkgen_vkfieldauto_h +#define __renderer_vulkan_vkgen_vkfieldauto_h + +#include "vkfielddef.h" + +@interface AutoField: FieldDef +@end + +#endif//__renderer_vulkan_vkgen_vkfieldauto_h diff --git a/libs/video/renderer/vulkan/vkgen/vkfieldauto.r b/libs/video/renderer/vulkan/vkgen/vkfieldauto.r new file mode 100644 index 000000000..dab844c92 --- /dev/null +++ b/libs/video/renderer/vulkan/vkgen/vkfieldauto.r @@ -0,0 +1,43 @@ +#include "vkfieldauto.h" +#include "vkgen.h" +#include "vkstruct.h" + +@implementation AutoField + +-init:(PLItem *) item struct:(Struct *)strct field:(string)fname +{ + self = [super init:item struct:strct field:fname]; + if (!self) { + return self; + } + field = [strct findField:field_name]; + + return self; +} + +-writeParseData +{ + printf("FieldDef: '%s' '%s'\n", struct_name, field_name); + return self; +} + +-writeField +{ + Type *field_type = [Type findType: field.type]; + fprintf (output_file, "\t{\"%s\", field_offset (%s, %s), %s, %s, %s},\n", + field_name, struct_name, field_name, + [field_type parseType], [field_type parseFunc], + [field_type parseData]); + return self; +} + +-writeSymbol +{ + Type *field_type = [Type findType: field.type]; + fprintf (output_file, + "\t{\"%s\", &%s, (void *) field_offset (%s, %s)},\n", + field_name, [field_type cexprType], struct_name, field_name); + return self; +} + +@end diff --git a/libs/video/renderer/vulkan/vkgen/vkfielddata.h b/libs/video/renderer/vulkan/vkgen/vkfielddata.h new file mode 100644 index 000000000..cf8356262 --- /dev/null +++ b/libs/video/renderer/vulkan/vkgen/vkfielddata.h @@ -0,0 +1,9 @@ +#ifndef __renderer_vulkan_vkgen_vkfielddata_h +#define __renderer_vulkan_vkgen_vkfielddata_h + +#include "vkfielddef.h" + +@interface DataField: FieldDef +@end + +#endif//__renderer_vulkan_vkgen_vkfielddata_h diff --git a/libs/video/renderer/vulkan/vkgen/vkfielddata.r b/libs/video/renderer/vulkan/vkgen/vkfielddata.r new file mode 100644 index 000000000..d13ff8965 --- /dev/null +++ b/libs/video/renderer/vulkan/vkgen/vkfielddata.r @@ -0,0 +1,45 @@ +#include + +#include "vkfielddata.h" +#include "vkgen.h" +#include "vkstruct.h" +#include "vktype.h" + +@implementation DataField + +-init:(PLItem *) item struct:(Struct *)strct field:(string)fname +{ + self = [super init:item struct:strct field:fname]; + if (!self) { + return self; + } + + value_field = [[item getObjectForKey:"data"] string]; + size_field = [[item getObjectForKey:"size"] string]; + return self; +} + +-writeParseData +{ + fprintf (output_file, "static parse_data_t parse_%s_%s_data = {\n", + struct_name, field_name); + fprintf (output_file, "\tfield_offset (%s, %s),\n", + struct_name, value_field); + if (size_field) { + fprintf (output_file, "\tfield_offset (%s, %s),\n", + struct_name, size_field); + } else { + fprintf (output_file, "\tt-1,\n"); + } + fprintf (output_file, "};\n"); + return self; +} + +-writeField +{ + fprintf (output_file, "\t{\"%s\", 0, %s, parse_%s, &parse_%s_%s_data},\n", + field_name, "QFBinary", "data", struct_name, field_name); + return self; +} + +@end diff --git a/libs/video/renderer/vulkan/vkgen/vkfielddef.h b/libs/video/renderer/vulkan/vkgen/vkfielddef.h new file mode 100644 index 000000000..0363a9e7f --- /dev/null +++ b/libs/video/renderer/vulkan/vkgen/vkfielddef.h @@ -0,0 +1,28 @@ +#ifndef __renderer_vulkan_vkgen_vkfielddef_h +#define __renderer_vulkan_vkgen_vkfielddef_h + +#include +#include + +@class PLItem; +@class Struct; +@class Type; + +@interface FieldDef: Object +{ + int line; + qfot_var_t *field; + string struct_name; + string field_name; + string value_field; + string size_field; +} ++fielddef:(PLItem *)item struct:(Struct *)strct field:(string)fname; +-init:(PLItem *)item struct:(Struct *)strct field:(string)fname; +-writeParseData; +-writeField; +-writeSymbol; +-(string) name; +@end + +#endif//__renderer_vulkan_vkgen_vkfielddef_h diff --git a/libs/video/renderer/vulkan/vkgen/vkfielddef.r b/libs/video/renderer/vulkan/vkgen/vkfielddef.r new file mode 100644 index 000000000..9cc35c13a --- /dev/null +++ b/libs/video/renderer/vulkan/vkgen/vkfielddef.r @@ -0,0 +1,95 @@ +#include +#include + +#include "vkfieldarray.h" +#include "vkfieldauto.h" +#include "vkfielddata.h" +#include "vkfielddef.h" +#include "vkfieldsingle.h" +#include "vkfieldstring.h" +#include "vkstruct.h" + +@implementation FieldDef + ++fielddef:(PLItem *)item struct:(Struct *)strct field:(string)fname +{ + string record = [item string]; + PLItem *type_desc = [item getObjectForKey:"type"]; + + if (!item) { + record = "auto"; + } + if (!record) { + if (item && !type_desc) { + return nil; + } + record = [type_desc string]; + if (!record) { + record = [[type_desc getObjectAtIndex:0] string]; + } + } + switch (record) { + case "auto": + return [[[AutoField alloc] init:item struct:strct field:fname] autorelease]; + case "string": + return [[[StringField alloc] init:item struct:strct field:fname] autorelease]; + case "data": + return [[[DataField alloc] init:item struct:strct field:fname] autorelease]; + case "single": + return [[[SingleField alloc] init:item struct:strct field:fname] autorelease]; + case "array": + return [[[ArrayField alloc] init:item struct:strct field:fname] autorelease]; + } + return nil; +} + +-init:(PLItem *)item struct:(Struct *)strct field:(string)fname +{ + self = [super init]; + if (!self) { + return self; + } + + line = [item line]; + struct_name = str_hold ([strct outname]); + field_name = str_hold (fname); + return self; +} + +-fromField:(qfot_var_t *)field struct:(Struct *)strct +{ + return self; +} + +-(void)dealloc +{ + str_free (struct_name); + str_free (field_name); +} + +-writeParseData +{ + fprintf (output_file, "undefined record type parse: %d\n", line); + return self; +} + +-writeField +{ + fprintf (output_file, "undefined record type field: %d\n", line); + return self; +} + +-writeSymbol +{ + fprintf (output_file, + "\t{\"%s\", 0/*FIXME*/, (void *) field_offset (%s, %s)},\n", + field_name, struct_name, value_field); + return self; +} + +-(string) name +{ + return field_name; +} + +@end diff --git a/libs/video/renderer/vulkan/vkgen/vkfieldsingle.h b/libs/video/renderer/vulkan/vkgen/vkfieldsingle.h new file mode 100644 index 000000000..2fcd312c4 --- /dev/null +++ b/libs/video/renderer/vulkan/vkgen/vkfieldsingle.h @@ -0,0 +1,12 @@ +#ifndef __renderer_vulkan_vkgen_vkfieldsingle_h +#define __renderer_vulkan_vkgen_vkfieldsingle_h + +#include "vkfielddef.h" + +@interface SingleField: FieldDef +{ + string type; +} +@end + +#endif//__renderer_vulkan_vkgen_vkfieldsingle_h diff --git a/libs/video/renderer/vulkan/vkgen/vkfieldsingle.r b/libs/video/renderer/vulkan/vkgen/vkfieldsingle.r new file mode 100644 index 000000000..e30ced3dd --- /dev/null +++ b/libs/video/renderer/vulkan/vkgen/vkfieldsingle.r @@ -0,0 +1,46 @@ +#include + +#include "vkfieldsingle.h" +#include "vkgen.h" +#include "vktype.h" + +@implementation SingleField + +-init:(PLItem *) item struct:(Struct *)strct field:(string)fname +{ + self = [super init:item struct:strct field:fname]; + if (!self) { + return self; + } + + PLItem *desc = [item getObjectForKey:"type"]; + type = [[desc getObjectAtIndex:1] string]; + + value_field = [[item getObjectForKey:"value"] string]; + return self; +} + +-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); + fprintf (output_file, "\tfield_offset (%s, %s),\n", + struct_name, value_field); + fprintf (output_file, "};\n"); + return self; +} + +-writeField +{ + string parse_type = [[[Type lookup: type] dereference] 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; +} + +@end diff --git a/libs/video/renderer/vulkan/vkgen/vkfieldstring.h b/libs/video/renderer/vulkan/vkgen/vkfieldstring.h new file mode 100644 index 000000000..fead71504 --- /dev/null +++ b/libs/video/renderer/vulkan/vkgen/vkfieldstring.h @@ -0,0 +1,9 @@ +#ifndef __renderer_vulkan_vkgen_vkfieldstring_h +#define __renderer_vulkan_vkgen_vkfieldstring_h + +#include "vkfielddef.h" + +@interface StringField: FieldDef +@end + +#endif//__renderer_vulkan_vkgen_vkfieldstring_h diff --git a/libs/video/renderer/vulkan/vkgen/vkfieldstring.r b/libs/video/renderer/vulkan/vkgen/vkfieldstring.r new file mode 100644 index 000000000..ff0ba525d --- /dev/null +++ b/libs/video/renderer/vulkan/vkgen/vkfieldstring.r @@ -0,0 +1,36 @@ +#include + +#include "vkfieldstring.h" +#include "vkgen.h" + +@implementation StringField + +-init:(PLItem *) item struct:(Struct *)strct field:(string)fname +{ + self = [super init:item struct:strct field:fname]; + if (!self) { + return self; + } + + value_field = [[item getObjectForKey:"string"] string]; + return self; +} + +-writeParseData +{ + fprintf (output_file, "static parse_string_t parse_%s_%s_data = {\n", + struct_name, field_name); + fprintf (output_file, "\tfield_offset (%s, %s),\n", + struct_name, value_field); + fprintf (output_file, "};\n"); + return self; +} + +-writeField +{ + fprintf (output_file, "\t{\"%s\", 0, %s, parse_%s, &parse_%s_%s_data},\n", + field_name, "QFString", "string", struct_name, field_name); + return self; +} + +@end diff --git a/libs/video/renderer/vulkan/vkgen/vkgen.h b/libs/video/renderer/vulkan/vkgen/vkgen.h index e60499f25..8f9cd5c93 100644 --- a/libs/video/renderer/vulkan/vkgen/vkgen.h +++ b/libs/video/renderer/vulkan/vkgen/vkgen.h @@ -12,6 +12,7 @@ void printf (string fmt, ...); void fprintf (QFile file, string format, ...); extern Array *queue; extern Array *output_types; +extern PLItem *parse; extern QFile output_file; extern QFile header_file; extern hashtab_t *processed_types; diff --git a/libs/video/renderer/vulkan/vkgen/vkgen.r b/libs/video/renderer/vulkan/vkgen/vkgen.r index 025e3d2cc..7a1edab8a 100644 --- a/libs/video/renderer/vulkan/vkgen/vkgen.r +++ b/libs/video/renderer/vulkan/vkgen/vkgen.r @@ -37,6 +37,7 @@ hashtab_t *processed_types; Array *queue; Array *output_types; +PLItem *parse; QFile output_file; QFile header_file; @@ -147,7 +148,6 @@ main(int argc, string *argv) QFile plist_file; PLItem *plist; PLItem *search; - PLItem *parse; arp_start (); @@ -199,6 +199,9 @@ main(int argc, string *argv) id obj = [queue objectAtIndex:0]; [queue removeObjectAtIndex:0]; if ([obj class] == [Struct class]) { + if ([[parse getObjectForKey:[obj name]] string] == "skip") { + continue; + } [obj forEachFieldCall:struct_func]; } [output_types addObject:obj]; @@ -235,7 +238,7 @@ main(int argc, string *argv) } arp_start (); - [obj writeTable:parse]; + [obj writeTable]; arp_end (); } fprintf (output_file, "static void\n"); @@ -247,7 +250,7 @@ main(int argc, string *argv) continue; } arp_start (); - [obj writeSymtabInit:parse]; + [obj writeSymtabInit]; arp_end (); } fprintf (output_file, "}\n"); diff --git a/libs/video/renderer/vulkan/vkgen/vkstruct.h b/libs/video/renderer/vulkan/vkgen/vkstruct.h index c251cb4c0..048b3332f 100644 --- a/libs/video/renderer/vulkan/vkgen/vkstruct.h +++ b/libs/video/renderer/vulkan/vkgen/vkstruct.h @@ -10,10 +10,13 @@ @interface Struct: Type { + string outname; } -(void) forEachFieldCall: (varfunc) func; --(void) writeTable: (PLItem *) parse; --(void) writeSymtabInit:(PLItem *) parse; +-(qfot_var_t *)findField:(string) fieldName; +-(void) writeTable; +-(void) writeSymtabInit; +-(string) outname; @end #endif//__renderer_vulkan_vkgen_vkstruct_h diff --git a/libs/video/renderer/vulkan/vkgen/vkstruct.r b/libs/video/renderer/vulkan/vkgen/vkstruct.r index 6e6908bb8..6a8b21caa 100644 --- a/libs/video/renderer/vulkan/vkgen/vkstruct.r +++ b/libs/video/renderer/vulkan/vkgen/vkstruct.r @@ -6,6 +6,7 @@ #include #include +#include "vkfielddef.h" #include "vkgen.h" #include "vkstruct.h" @@ -46,122 +47,33 @@ return nil; } --(void) writeTable: (PLItem *) parse +-(void) writeTable { - string name = [self name]; - PLItem *field_dict = [parse getObjectForKey:name]; - PLItem *field_defs = [field_dict allKeys]; - Type *field_type; + PLItem *field_dict = [parse getObjectForKey:[self name]]; PLItem *new_name = [field_dict getObjectForKey:".name"]; + Array *field_defs = [Array array]; + if ([parse string] == "skip") { + return; + } if (new_name) { - name = [new_name string]; + outname = str_hold ([new_name string]); } - if (field_defs) { - PLItem *field_def; - qfot_var_t *field; + if (field_dict) { + PLItem *field_keys = [field_dict allKeys]; - for (int i = [field_defs count]; i-- > 0; ) { - string field_name = [[field_defs getObjectAtIndex:i] string]; - field_def = [field_dict getObjectForKey:field_name]; - PLItem *type_desc = [field_def getObjectForKey:"type"]; - string type_record; - string type_type; - string size_field = nil; - string value_field = nil; + for (int i = [field_keys count]; i-- > 0; ) { + string field_name = [[field_keys getObjectAtIndex:i] string]; - if (!type_desc || str_mid(field_name, 0, 1) == ".") { - continue; - } - type_record = [[type_desc getObjectAtIndex:0] string]; - type_type = [[type_desc getObjectAtIndex:1] string]; - - field_type = [[Type lookup: type_type] dereference]; - fprintf (output_file, "static parse_%s_t parse_%s_%s_data = {\n", - type_record, name, field_name); - if (type_record == "single") { - fprintf (output_file, "\t%s,\n", [field_type parseType]); - fprintf (output_file, "\tsizeof (%s),\n", type_type); - fprintf (output_file, "\tparse_%s,\n", type_type); - value_field = [[field_def getObjectForKey:"value"] string]; - fprintf (output_file, "\tfield_offset (%s, %s),\n", - name, value_field); - } else if (type_record == "array") { - fprintf (output_file, "\t%s,\n", [field_type parseType]); - fprintf (output_file, "\tsizeof (%s),\n", type_type); - fprintf (output_file, "\tparse_%s,\n", type_type); - value_field = [[field_def getObjectForKey:"values"] string]; - size_field = [[field_def getObjectForKey:"size"] string]; - fprintf (output_file, "\tfield_offset (%s, %s),\n", - name, value_field); - if (size_field) { - fprintf (output_file, "\tfield_offset (%s, %s),\n", - name, size_field); - } else { - fprintf (output_file, "\t-1,\n"); - } - } else if (type_record == "data") { - value_field = [[field_def getObjectForKey:"data"] string]; - size_field = [[field_def getObjectForKey:"size"] string]; - fprintf (output_file, "\tfield_offset (%s, %s),\n", - name, value_field); - if (size_field) { - fprintf (output_file, "\tfield_offset (%s, %s),\n", - name, size_field); - } else { - fprintf (output_file, "\t-1,\n"); - } - } else { - fprintf (output_file, "\tno type,\n"); - } - fprintf (output_file, "};\n"); - } - } - fprintf (output_file, "static plfield_t %s_fields[] = {\n", name); - if (field_defs) { - PLItem *field_def; - qfot_var_t *field; - - for (int i = [field_defs count]; i-- > 0; ) { - string field_name = [[field_defs getObjectAtIndex:i] string]; if (str_mid(field_name, 0, 1) == ".") { continue; } - field_def = [field_dict getObjectForKey:field_name]; - if ([field_def string] == "auto") { - field = [self findField:field_name]; - if (!field) { - continue; - } - field_type = [Type findType: field.type]; - fprintf (output_file, - "\t{\"%s\", field_offset (%s, %s), %s, %s, %s},\n", - field_name, name, field_name, - [field_type parseType], [field_type parseFunc], - [field_type parseData]); - } else { - PLItem *type_desc = [field_def getObjectForKey:"type"]; - string type_record; - string type_type; - string parseType = "no type"; - - type_record = [[type_desc getObjectAtIndex:0] string]; - type_type = [[type_desc getObjectAtIndex:1] string]; - - field_type = [[Type lookup: type_type] dereference]; - if (type_record == "single") { - parseType = [field_type parseType]; - } else if (type_record == "array") { - parseType = "QFArray"; - } else if (type_record == "data") { - parseType = "QFBinary"; - } - fprintf (output_file, - "\t{\"%s\", 0, %s, parse_%s, &parse_%s_%s_data},\n", - field_name, parseType, type_record, - name, field_name); - } + PLItem *field_item = [field_dict getObjectForKey:field_name]; + FieldDef *field_def = [FieldDef fielddef:field_item + struct:self + field:field_name]; + [field_defs addObject: field_def]; } } else { for (int i = 0; i < type.strct.num_fields; i++) { @@ -169,76 +81,47 @@ if (field.name == "sType" || field.name == "pNext") { continue; } - field_type = [Type findType: field.type]; - fprintf (output_file, - "\t{\"%s\", field_offset (%s, %s), %s, %s, %s},\n", - field.name, name, field.name, - [field_type parseType], [field_type parseFunc], - [field_type parseData]); + FieldDef *field_def = [FieldDef fielddef:nil + struct:self + field:field.name]; + [field_defs addObject: field_def]; } } + for (int i = [field_defs count]; i-- > 0; ) { + FieldDef *field_def = [field_defs objectAtIndex:i]; + [field_def writeParseData]; + } + fprintf (output_file, "static plfield_t %s_fields[] = {\n", [self outname]); + for (int i = [field_defs count]; i-- > 0; ) { + FieldDef *field_def = [field_defs objectAtIndex:i]; + [field_def writeField]; + } fprintf (output_file, "\t{ }\n"); fprintf (output_file, "};\n"); fprintf (header_file, "int parse_%s (const plfield_t *field," " const plitem_t *item, void *data, plitem_t *messages," " void *context);\n", - name); + [self outname]); fprintf (output_file, "int parse_%s (const plfield_t *field," " const plitem_t *item, void *data, plitem_t *messages," " void *context)\n", - name); + [self outname]); fprintf (output_file, "{\n"); fprintf (output_file, "\treturn PL_ParseDictionary (%s_fields, item, data, messages," " context);\n", - name); + [self outname]); fprintf (output_file, "}\n"); - fprintf (output_file, "static exprsym_t %s_symbols[] = {\n", name); + fprintf (output_file, "static exprsym_t %s_symbols[] = {\n", [self outname]); if (field_defs) { PLItem *field_def; qfot_var_t *field; for (int i = [field_defs count]; i-- > 0; ) { - string field_name = [[field_defs getObjectAtIndex:i] string]; - field_def = [field_dict getObjectForKey:field_name]; - PLItem *type_desc = [field_def getObjectForKey:"type"]; - string type_record; - string type_type; - string size_field = nil; - string value_field = nil; - - if (str_mid(field_name, 0, 1) == ".") { - continue; - } - field_def = [field_dict getObjectForKey:field_name]; - if ([field_def string] == "auto") { - field = [self findField:field_name]; - if (!field) { - continue; - } - field_type = [Type findType: field.type]; - fprintf (output_file, - "\t{\"%s\", &%s, (void *) field_offset (%s, %s)},\n", - field_name, [field_type cexprType], name, field_name); - } else { - type_record = [[type_desc getObjectAtIndex:0] string]; - if (type_record == "single") { - value_field = [[field_def getObjectForKey:"value"] string]; - } else if (type_record == "array") { - value_field = [[field_def getObjectForKey:"values"] string]; - } else if (type_record == "data") { - value_field = [[field_def getObjectForKey:"data"] string]; - } - if (!value_field) { - value_field = field_name; - } - fprintf (output_file, - "\t{\"%s\", 0/*FIXME*/," - " (void *) field_offset (%s, %s)},\n", - field_name, name, value_field); - } + FieldDef *field_def = [field_defs objectAtIndex:i]; + [field_def writeSymbol]; } } else { for (int i = 0; i < type.strct.num_fields; i++) { @@ -246,40 +129,48 @@ if (field.name == "sType" || field.name == "pNext") { continue; } - field_type = [Type findType: field.type]; + Type *field_type = [Type findType: field.type]; fprintf (output_file, "\t{\"%s\", &%s, (void *) field_offset (%s, %s)},\n", - field.name, [field_type cexprType], name, field.name); + field.name, [field_type cexprType], [self outname], field.name); } } fprintf (output_file, "\t{ }\n"); fprintf (output_file, "};\n"); - fprintf (output_file, "static exprtab_t %s_symtab = {\n", name); - fprintf (output_file, "\t%s_symbols,\n", name); + fprintf (output_file, "static exprtab_t %s_symtab = {\n", [self outname]); + fprintf (output_file, "\t%s_symbols,\n", [self outname]); fprintf (output_file, "};\n"); - fprintf (output_file, "exprtype_t %s_type = {\n", name); - fprintf (output_file, "\t\"%s\",\n", name); - fprintf (output_file, "\tsizeof (%s),\n", name); + fprintf (output_file, "exprtype_t %s_type = {\n", [self outname]); + fprintf (output_file, "\t\"%s\",\n", [self outname]); + fprintf (output_file, "\tsizeof (%s),\n", [self outname]); fprintf (output_file, "\tcexpr_struct_binops,\n"); fprintf (output_file, "\t0,\n"); - fprintf (output_file, "\t&%s_symtab,\n", name); + fprintf (output_file, "\t&%s_symtab,\n", [self outname]); fprintf (output_file, "};\n"); - fprintf (header_file, "extern exprtype_t %s_type;\n", name); + fprintf (output_file, "\n"); + fprintf (header_file, "extern exprtype_t %s_type;\n", [self outname]); } --(void) writeSymtabInit:(PLItem *) parse +-(void) writeSymtabInit { - string name = [self name]; - PLItem *field_dict = [parse getObjectForKey:name]; - PLItem *new_name = [field_dict getObjectForKey:".name"]; + PLItem *field_dict = [parse getObjectForKey:[self outname]]; - if (new_name) { - name = [new_name string]; + if ([parse string] == "skip") { + return; } - fprintf (output_file, "\tcexpr_init_symtab (&%s_symtab, context);\n", name); + fprintf (output_file, "\tcexpr_init_symtab (&%s_symtab, context);\n", + [self outname]); +} + +-(string) outname +{ + if (outname) { + return outname; + } + return [self name]; } -(string) cexprType diff --git a/libs/video/renderer/vulkan/vkparse.c b/libs/video/renderer/vulkan/vkparse.c index fbe46d512..fbfbdf226 100644 --- a/libs/video/renderer/vulkan/vkparse.c +++ b/libs/video/renderer/vulkan/vkparse.c @@ -122,6 +122,10 @@ typedef struct parse_data_s { size_t size_offset; } parse_data_t; +typedef struct parse_string_s { + size_t value_offset; +} parse_string_t; + static int parse_uint32_t (const plfield_t *field, const plitem_t *item, void *data, plitem_t *messages, void *context) { @@ -239,7 +243,7 @@ static int parse_data (const plfield_t *field, const plitem_t *item, const void *bindata = PL_BinaryData (item); size_t binsize = PL_BinarySize (item); - Sys_Printf ("parse_array: %s %zd %d %p %p %p\n", + Sys_Printf ("parse_data: %s %zd %d %p %p %p\n", field->name, field->offset, field->type, field->parser, field->data, data); Sys_Printf (" %zd %zd\n", datad->value_offset, datad->size_offset); @@ -253,6 +257,24 @@ static int parse_data (const plfield_t *field, const plitem_t *item, return 1; } +static int parse_string (const plfield_t *field, const plitem_t *item, + void *data, plitem_t *messages, void *context) +{ + __auto_type string = (parse_string_t *) field->data; + __auto_type value = (char **) ((byte *)data + string->value_offset); + + const char *str = PL_BinaryData (item); + + Sys_Printf ("parse_string: %s %zd %d %p %p %p\n", + field->name, field->offset, field->type, field->parser, + field->data, data); + Sys_Printf (" %zd\n", string->value_offset); + Sys_Printf (" %s\n", str); + + *value = strdup (str); + return 1; +} + #include "libs/video/renderer/vulkan/vkparse.cinc" typedef struct qfv_renderpass_s {