[vkgen] Recognize char * as a string

Ruamoko currently doesn't support `const`, so that's not relevant, but
recognizing `char *` (via a hack to work around what looks like a bug
with type aliasing) allows strings to be handled without having to use a
custom parser. Things are still a little clunky for custom parsers, but
this seems to be a good start.
This commit is contained in:
Bill Currie 2023-02-09 11:32:38 +09:00
parent d5cd4f6ede
commit 403c6eea73
11 changed files with 83 additions and 7 deletions

View file

@ -17,6 +17,7 @@ vkgen_dat_src= \
libs/video/renderer/vulkan/vkgen/vkfieldtype.r \ libs/video/renderer/vulkan/vkgen/vkfieldtype.r \
libs/video/renderer/vulkan/vkgen/vkfixedarray.r \ libs/video/renderer/vulkan/vkgen/vkfixedarray.r \
libs/video/renderer/vulkan/vkgen/vkgen.r \ libs/video/renderer/vulkan/vkgen/vkgen.r \
libs/video/renderer/vulkan/vkgen/vkstring.r \
libs/video/renderer/vulkan/vkgen/vkstruct.r \ libs/video/renderer/vulkan/vkgen/vkstruct.r \
libs/video/renderer/vulkan/vkgen/vktype.r \ libs/video/renderer/vulkan/vkgen/vktype.r \
libs/video/renderer/vulkan/vkgen/vulkan.r libs/video/renderer/vulkan/vkgen/vulkan.r
@ -60,6 +61,7 @@ EXTRA_DIST += \
libs/video/renderer/vulkan/vkgen/vkfieldtype.h \ libs/video/renderer/vulkan/vkgen/vkfieldtype.h \
libs/video/renderer/vulkan/vkgen/vkfixedarray.h \ libs/video/renderer/vulkan/vkgen/vkfixedarray.h \
libs/video/renderer/vulkan/vkgen/vkgen.h \ libs/video/renderer/vulkan/vkgen/vkgen.h \
libs/video/renderer/vulkan/vkgen/vkstring.h \
libs/video/renderer/vulkan/vkgen/vkstruct.h \ libs/video/renderer/vulkan/vkgen/vkstruct.h \
libs/video/renderer/vulkan/vkgen/vktype.h libs/video/renderer/vulkan/vkgen/vktype.h

View file

@ -7,4 +7,4 @@ typedef int int16_t;
typedef int int32_t; typedef int int32_t;
typedef int int64_t; typedef int int64_t;
typedef int size_t; typedef int size_t;
typedef int char; typedef struct char { int x; } char;

View file

@ -4,6 +4,7 @@
#include "vkfielddef.h" #include "vkfielddef.h"
@interface StringField: FieldDef @interface StringField: FieldDef
+fielddef:(PLItem *)item struct:(Struct *)strct field:(string)fname;
@end @end
#endif//__renderer_vulkan_vkgen_vkfieldstring_h #endif//__renderer_vulkan_vkgen_vkfieldstring_h

View file

@ -12,10 +12,19 @@
return self; return self;
} }
value_field = [[item getObjectForKey:"string"] string]; value_field = fname;
if (item) {
value_field = [[item getObjectForKey:"string"] string];
}
return self; return self;
} }
+fielddef:(PLItem *)item struct:(Struct *)strct field:(string)fname
{
return [[[StringField alloc] init:item struct:strct field:fname]
autorelease];
}
-writeParseData -writeParseData
{ {
fprintf (output_file, "static parse_string_t parse_%s_%s_data = {\n", fprintf (output_file, "static parse_string_t parse_%s_%s_data = {\n",

View file

@ -5,6 +5,7 @@
#include <qfile.h> #include <qfile.h>
#include <types.h> #include <types.h>
#include <Array.h> #include <Array.h>
#include <PropertyList.h>
typedef void varfunc (qfot_var_t *var); typedef void varfunc (qfot_var_t *var);

View file

@ -200,7 +200,9 @@ main(int argc, string *argv)
id obj = [queue objectAtIndex:0]; id obj = [queue objectAtIndex:0];
[queue removeObjectAtIndex:0]; [queue removeObjectAtIndex:0];
if ([obj class] == [Struct class]) { if ([obj class] == [Struct class]) {
if ([[parse getObjectForKey:[obj name]] string] == "skip") { string name = [obj name];
if (name == "char" // char type faked via a struct
|| [[parse getObjectForKey:name] string] == "skip") {
continue; continue;
} }
[obj queueFieldTypes]; [obj queueFieldTypes];

View file

@ -0,0 +1,9 @@
#ifndef __renderer_vulkan_vkgen_vkstring_h
#define __renderer_vulkan_vkgen_vkstring_h
#include "vktype.h"
@interface String: Type
@end
#endif//__renderer_vulkan_vkgen_vkstring_h

View file

@ -0,0 +1,28 @@
#include <string.h>
#include "vkfieldstring.h"
#include "vkstring.h"
#include "vkgen.h"
@implementation String
-(string) name
{
return "string";
}
-(FieldDef *)fielddef:(Struct *)strct field:(string)fname
{
return [StringField fielddef:nil struct:strct field:fname];
}
-(string) cexprType
{
return [self name] + "_type";
}
-(string) parseType
{
return "QFString";
}
@end

View file

@ -124,9 +124,13 @@
if (field.name == "sType" || field.name == "pNext") { if (field.name == "sType" || field.name == "pNext") {
continue; continue;
} }
FieldDef *field_def = [FieldDef fielddef:nil Type *field_type = [Type findType: field.type];
struct:self FieldDef *field_def = [field_type fielddef:self field:field.name];
field:field.name]; if (!field_def) {
field_def = [FieldDef fielddef:nil
struct:self
field:field.name];
}
[field_defs addObject: field_def]; [field_defs addObject: field_def];
} }
} }
@ -197,7 +201,8 @@
Type *field_type = [Type findType: field.type]; Type *field_type = [Type findType: field.type];
fprintf (output_file, fprintf (output_file,
"\t{\"%s\", &%s, (void *) field_offset (%s, %s)},\n", "\t{\"%s\", &%s, (void *) field_offset (%s, %s)},\n",
field.name, [field_type cexprType], [self outname], field.name); field.name, [field_type cexprType], [self outname],
field.name);
} }
} }
fprintf (output_file, "\t{ }\n"); fprintf (output_file, "\t{ }\n");

View file

@ -4,6 +4,9 @@
#include <types.h> #include <types.h>
#include <Object.h> #include <Object.h>
@class FieldDef;
@class Struct;
@interface Type: Object @interface Type: Object
{ {
qfot_type_t *type; qfot_type_t *type;
@ -26,6 +29,8 @@
-(string) parseFunc; -(string) parseFunc;
-(string) parseData; -(string) parseData;
-(FieldDef *)fielddef:(Struct *)strct field:(string)fname;
-(int) isPointer; -(int) isPointer;
-(Type *) dereference; -(Type *) dereference;
@end @end

View file

@ -4,6 +4,7 @@
#include "vkenum.h" #include "vkenum.h"
#include "vkfixedarray.h" #include "vkfixedarray.h"
#include "vkgen.h" #include "vkgen.h"
#include "vkstring.h"
#include "vkstruct.h" #include "vkstruct.h"
#include "vktype.h" #include "vktype.h"
@ -51,6 +52,14 @@ static string get_type_key (void *type, void *unused)
} }
switch (type.meta) { switch (type.meta) {
case ty_basic: case ty_basic:
if (type.type == ev_ptr) {
Type *tgt = [Type findType: type.fldptr.aux_type];
if (tgt.type.meta == ty_alias
&& tgt.type.alias.name == "char") {
return [[String alloc] initWithType: type];
}
}
case ty_class: case ty_class:
return [[Type alloc] initWithType: type]; return [[Type alloc] initWithType: type];
case ty_array: case ty_array:
@ -138,6 +147,11 @@ static string get_type_key (void *type, void *unused)
return "0"; return "0";
} }
-(FieldDef *)fielddef:(Struct *)strct field:(string)fname
{
return nil;
}
-(int) isPointer -(int) isPointer
{ {
if ((type.meta == ty_basic || type.meta == ty_alias) if ((type.meta == ty_basic || type.meta == ty_alias)