2020-07-02 05:24:39 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "vkenum.h"
|
|
|
|
#include "vkgen.h"
|
|
|
|
|
2021-01-12 04:07:51 +00:00
|
|
|
typedef enum VkBool32 {
|
|
|
|
VK_FALSE,
|
|
|
|
VK_TRUE,
|
|
|
|
VK_MAX_ENUM = VK_TRUE
|
|
|
|
} VkBool32;
|
|
|
|
|
2020-07-02 05:24:39 +00:00
|
|
|
@implementation Enum
|
|
|
|
-(void)process
|
|
|
|
{
|
|
|
|
string end = "_MAX_ENUM";
|
|
|
|
int len;
|
|
|
|
string prefix = nil;
|
|
|
|
|
|
|
|
if (str_mid([self name], -8) == "FlagBits") {
|
|
|
|
end = "_FLAG_BITS_MAX_ENUM";
|
2021-11-29 04:04:08 +00:00
|
|
|
} else if (str_mid([self name], -11) == "FlagBitsEXT") {
|
|
|
|
end = "_FLAG_BITS_MAX_ENUM_EXT";
|
2022-04-24 06:40:28 +00:00
|
|
|
} else if (str_mid([self name], -3) == "KHR") {
|
|
|
|
end = "_MAX_ENUM_KHR";
|
2023-06-16 09:49:58 +00:00
|
|
|
} else if (str_mid([self name], 0, 4) == "qfv_") {
|
|
|
|
prefix = "qfv_";
|
2020-07-02 05:24:39 +00:00
|
|
|
}
|
|
|
|
len = -strlen (end);
|
2023-06-16 09:49:58 +00:00
|
|
|
if (!prefix) {
|
|
|
|
for (int i = 0; i < type.strct.num_fields; i++) {
|
|
|
|
qfot_var_t *var = &type.strct.fields[i];
|
|
|
|
if (str_mid (var.name, len) == end) {
|
|
|
|
// len is negative so +1 consumes 1 more char (_)
|
|
|
|
prefix = str_hold (str_mid (var.name, 0, len + 1));
|
|
|
|
}
|
2020-07-02 05:24:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (prefix) {
|
|
|
|
prefix_length = strlen (prefix);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
-initWithType: (qfot_type_t *) type
|
|
|
|
{
|
|
|
|
if (!(self = [super initWithType: type])) {
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
[self process];
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(string) name
|
|
|
|
{
|
|
|
|
return str_mid(type.strct.tag, 4);
|
|
|
|
}
|
|
|
|
|
2020-07-03 16:40:02 +00:00
|
|
|
-(void) addToQueue
|
|
|
|
{
|
|
|
|
string name = [self name];
|
|
|
|
if (!Hash_Find (processed_types, name)) {
|
2021-07-06 03:27:21 +00:00
|
|
|
//printf (" +%s\n", name);
|
2020-07-03 16:40:02 +00:00
|
|
|
Hash_Add (processed_types, (void *) name);
|
|
|
|
[queue addObject: self];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-21 09:38:31 +00:00
|
|
|
static int
|
|
|
|
skip_value(string name)
|
|
|
|
{
|
|
|
|
return (str_str (name, "_MAX_ENUM") >= 0
|
|
|
|
|| str_str (name, "_BEGIN_RANGE") >= 0
|
|
|
|
|| str_str (name, "_END_RANGE") >= 0
|
|
|
|
|| str_str (name, "_RANGE_SIZE") >= 0);
|
|
|
|
}
|
|
|
|
|
2021-04-02 15:06:54 +00:00
|
|
|
-(int) isEmpty
|
|
|
|
{
|
|
|
|
int num_values = 0;
|
|
|
|
|
|
|
|
for (int i = 0, index = 0; i < type.strct.num_fields; i++) {
|
|
|
|
qfot_var_t *var = &type.strct.fields[i];
|
|
|
|
if (skip_value (var.name)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
num_values++;
|
|
|
|
}
|
|
|
|
return !num_values;
|
|
|
|
}
|
|
|
|
|
2023-02-09 12:20:27 +00:00
|
|
|
-(void) writeForward
|
|
|
|
{
|
|
|
|
fprintf (output_file, "static exprenum_t %s_enum;\n", [self name]);
|
|
|
|
}
|
|
|
|
|
2020-07-02 05:24:39 +00:00
|
|
|
-(void) writeTable
|
|
|
|
{
|
|
|
|
int strip_bit = 0;
|
2022-04-24 06:40:28 +00:00
|
|
|
int strip_khr = 0;
|
2021-11-29 04:04:08 +00:00
|
|
|
if (str_mid([self name], -8) == "FlagBits"
|
|
|
|
|| str_mid([self name], -11) == "FlagBitsEXT") {
|
2020-07-02 05:24:39 +00:00
|
|
|
strip_bit = 1;
|
|
|
|
}
|
2022-04-24 06:40:28 +00:00
|
|
|
if (str_mid([self name], -3) == "KHR") {
|
|
|
|
strip_khr = 1;
|
|
|
|
}
|
2020-07-02 05:24:39 +00:00
|
|
|
|
2022-04-24 05:55:35 +00:00
|
|
|
fprintf (output_file, "exprtype_t %s_type = {\n", [self name]);
|
|
|
|
fprintf (output_file, "\t.name = \"%s\",\n", [self name]);
|
|
|
|
fprintf (output_file, "\t.size = sizeof (int),\n");
|
2020-12-21 09:38:31 +00:00
|
|
|
if (strip_bit) {
|
2022-04-24 05:55:35 +00:00
|
|
|
fprintf (output_file, "\t.binops = flag_binops,\n");
|
|
|
|
fprintf (output_file, "\t.unops = flag_unops,\n");
|
2022-04-24 06:04:08 +00:00
|
|
|
fprintf (output_file, "\t.get_string = cexpr_flags_get_string,\n");
|
2020-12-21 09:38:31 +00:00
|
|
|
} else {
|
2022-04-24 05:55:35 +00:00
|
|
|
fprintf (output_file, "\t.binops = enum_binops,\n");
|
|
|
|
fprintf (output_file, "\t.unops = 0,\n");
|
2022-04-24 06:04:08 +00:00
|
|
|
fprintf (output_file, "\t.get_string = cexpr_enum_get_string,\n");
|
2020-12-21 09:38:31 +00:00
|
|
|
}
|
2022-04-24 05:55:35 +00:00
|
|
|
fprintf (output_file, "\t.data = &%s_enum,\n", [self name]);
|
2020-12-21 09:38:31 +00:00
|
|
|
fprintf (output_file, "};\n");
|
|
|
|
|
2021-04-02 15:06:54 +00:00
|
|
|
if (![self isEmpty]) {
|
|
|
|
fprintf (output_file, "static %s %s_values[] = {\n", [self name], [self name]);
|
|
|
|
for (int i = 0, index = 0; i < type.strct.num_fields; i++) {
|
|
|
|
qfot_var_t *var = &type.strct.fields[i];
|
|
|
|
if (skip_value (var.name)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
fprintf (output_file, "\t%s, // %d 0x%x\n",
|
|
|
|
var.name, var.offset, var.offset);
|
|
|
|
index++;
|
2020-12-21 09:38:31 +00:00
|
|
|
}
|
2021-04-02 15:06:54 +00:00
|
|
|
fprintf (output_file, "};\n");
|
2020-12-21 09:38:31 +00:00
|
|
|
}
|
2023-02-09 12:20:27 +00:00
|
|
|
fprintf (output_file, "static exprsym_t %s_symbols[] = {\n", [self name]);
|
2020-12-21 09:38:31 +00:00
|
|
|
for (int i = 0, index = 0; i < type.strct.num_fields; i++) {
|
2020-07-02 05:24:39 +00:00
|
|
|
qfot_var_t *var = &type.strct.fields[i];
|
2020-12-21 09:38:31 +00:00
|
|
|
if (skip_value (var.name)) {
|
2020-07-02 05:24:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-12-21 09:38:31 +00:00
|
|
|
fprintf (output_file, "\t{\"%s\", &%s_type, %s_values + %d},\n",
|
|
|
|
var.name, [self name], [self name], index);
|
2020-07-02 05:24:39 +00:00
|
|
|
if (prefix_length) {
|
|
|
|
string shortname = str_mid (var.name, prefix_length);
|
|
|
|
if (strip_bit) {
|
|
|
|
int bit_pos = str_str (shortname, "_BIT");
|
|
|
|
if (bit_pos >= 0) {
|
|
|
|
shortname = str_mid (shortname, 0, bit_pos);
|
|
|
|
}
|
2022-04-24 06:40:28 +00:00
|
|
|
} else if (strip_khr) {
|
|
|
|
int khr_pos = str_str (shortname, "_KHR");
|
|
|
|
if (khr_pos >= 0) {
|
|
|
|
shortname = str_mid (shortname, 0, khr_pos);
|
|
|
|
}
|
2020-07-02 05:24:39 +00:00
|
|
|
}
|
2020-12-21 09:38:31 +00:00
|
|
|
fprintf (output_file, "\t{\"%s\", &%s_type, %s_values + %d},\n",
|
|
|
|
str_lower(shortname), [self name], [self name], index);
|
2020-07-02 05:24:39 +00:00
|
|
|
}
|
2020-12-21 09:38:31 +00:00
|
|
|
index++;
|
2020-07-02 05:24:39 +00:00
|
|
|
}
|
|
|
|
fprintf (output_file, "\t{ }\n");
|
|
|
|
fprintf (output_file, "};\n");
|
2023-02-09 12:20:27 +00:00
|
|
|
fprintf (output_file, "static exprtab_t %s_symtab = {\n", [self name]);
|
2020-12-21 09:38:31 +00:00
|
|
|
fprintf (output_file, "\t%s_symbols,\n", [self name]);
|
|
|
|
fprintf (output_file, "};\n");
|
2023-02-09 12:20:27 +00:00
|
|
|
fprintf (output_file, "static exprenum_t %s_enum = {\n", [self name]);
|
2020-12-21 09:38:31 +00:00
|
|
|
fprintf (output_file, "\t&%s_type,\n", [self name]);
|
|
|
|
fprintf (output_file, "\t&%s_symtab,\n", [self name]);
|
|
|
|
fprintf (output_file, "};\n");
|
|
|
|
|
2020-12-24 15:17:20 +00:00
|
|
|
fprintf (output_file, "static plfield_t %s_field = { 0, 0, QFString,"
|
|
|
|
" parse_enum, &%s_enum};\n",
|
|
|
|
[self name], [self name]);
|
|
|
|
fprintf (output_file, "int parse_%s (const plfield_t *field,"
|
|
|
|
" const plitem_t *item, void *data, plitem_t *messages,"
|
|
|
|
" void *context)\n",
|
|
|
|
[self name]);
|
|
|
|
fprintf (output_file, "{\n");
|
|
|
|
fprintf (output_file,
|
|
|
|
"\treturn parse_enum (&%s_field, item, data, messages,"
|
|
|
|
" context);\n",
|
|
|
|
[self name]);
|
|
|
|
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",
|
|
|
|
[self name]);
|
2022-04-24 05:55:35 +00:00
|
|
|
fprintf (header_file, "extern exprtype_t %s_type;\n", [self name]);
|
2020-12-21 09:38:31 +00:00
|
|
|
}
|
|
|
|
|
2020-12-23 13:13:50 +00:00
|
|
|
-(void) writeSymtabInit
|
2020-12-21 09:38:31 +00:00
|
|
|
{
|
|
|
|
fprintf (output_file, "\tcexpr_init_symtab (&%s_symtab, context);\n",
|
|
|
|
[self name]);
|
|
|
|
}
|
|
|
|
|
2021-01-04 08:26:39 +00:00
|
|
|
-(void) writeSymtabEntry
|
|
|
|
{
|
|
|
|
fprintf (output_file, "\tHash_Add (enum_symtab, &%s_enum);\n",
|
|
|
|
[self name]);
|
|
|
|
}
|
|
|
|
|
2020-12-21 09:38:31 +00:00
|
|
|
-(string) cexprType
|
|
|
|
{
|
|
|
|
return [self name] + "_type";
|
2020-07-02 05:24:39 +00:00
|
|
|
}
|
2020-07-05 05:59:56 +00:00
|
|
|
|
|
|
|
-(string) parseType
|
|
|
|
{
|
|
|
|
return "QFString";
|
|
|
|
}
|
|
|
|
|
|
|
|
-(string) parseFunc
|
|
|
|
{
|
|
|
|
return "parse_enum";
|
|
|
|
}
|
|
|
|
|
|
|
|
-(string) parseData
|
|
|
|
{
|
2020-12-21 09:38:31 +00:00
|
|
|
return "&" + [self name] + "_enum";
|
2020-07-05 05:59:56 +00:00
|
|
|
}
|
2020-07-02 05:24:39 +00:00
|
|
|
@end
|