2020-06-28 10:08:18 +00:00
|
|
|
#include <hash.h>
|
|
|
|
#include <qfile.h>
|
|
|
|
#include <runtime.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <types.h>
|
|
|
|
#include <Array.h>
|
2020-07-05 05:59:56 +00:00
|
|
|
#include <AutoreleasePool.h>
|
|
|
|
#include <PropertyList.h>
|
2020-06-28 10:08:18 +00:00
|
|
|
|
2020-07-02 05:24:39 +00:00
|
|
|
#include "vkgen.h"
|
|
|
|
#include "vkstruct.h"
|
|
|
|
#include "vkenum.h"
|
|
|
|
|
2020-07-05 05:59:56 +00:00
|
|
|
static AutoreleasePool *autorelease_pool;
|
|
|
|
static void
|
|
|
|
arp_start (void)
|
|
|
|
{
|
|
|
|
autorelease_pool = [[AutoreleasePool alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
arp_end (void)
|
|
|
|
{
|
|
|
|
[autorelease_pool release];
|
|
|
|
autorelease_pool = nil;
|
|
|
|
}
|
|
|
|
|
2020-06-28 10:08:18 +00:00
|
|
|
void printf (string fmt, ...) = #0;
|
|
|
|
|
|
|
|
void fprintf (QFile file, string format, ...)
|
|
|
|
{
|
|
|
|
Qputs (file, vsprintf (format, va_copy (@args)));
|
|
|
|
}
|
|
|
|
|
|
|
|
hashtab_t *available_types;
|
|
|
|
hashtab_t *processed_types;
|
|
|
|
Array *queue;
|
|
|
|
Array *output_types;
|
|
|
|
|
2020-12-23 13:13:50 +00:00
|
|
|
PLItem *parse;
|
2020-06-28 10:08:18 +00:00
|
|
|
QFile output_file;
|
2020-12-21 09:38:31 +00:00
|
|
|
QFile header_file;
|
2020-06-28 10:08:18 +00:00
|
|
|
|
|
|
|
qfot_type_encodings_t *encodings;
|
|
|
|
|
|
|
|
qfot_type_t *
|
|
|
|
next_type (qfot_type_t *type)
|
|
|
|
{
|
|
|
|
int size = type.size;
|
|
|
|
if (!size)
|
|
|
|
size = 4;
|
|
|
|
return (qfot_type_t *) ((int *) type + size);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
type_is_null (qfot_type_t *type)
|
|
|
|
{
|
|
|
|
return type.size == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_type (qfot_type_t *type)
|
|
|
|
{
|
|
|
|
printf ("type: %p %d %d %s", type, type.meta, type.size, type.encoding);
|
|
|
|
switch (type.meta) {
|
|
|
|
case ty_basic:
|
|
|
|
printf (" %d", type.type);
|
|
|
|
switch (type.type) {
|
|
|
|
case ev_pointer:
|
|
|
|
case ev_field:
|
|
|
|
printf (" ");
|
|
|
|
print_type (type.fldptr.aux_type);
|
|
|
|
break;
|
|
|
|
case ev_func:
|
|
|
|
printf (" %p %d\n", type.func.return_type,
|
|
|
|
type.func.num_params);
|
|
|
|
default:
|
|
|
|
printf ("\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ty_struct:
|
|
|
|
case ty_union:
|
|
|
|
case ty_enum:
|
|
|
|
printf (" %s %d\n", type.strct.tag, type.strct.num_fields);
|
|
|
|
break;
|
|
|
|
case ty_array:
|
|
|
|
printf (" %p %d %d\n", type.array.type, type.array.base,
|
|
|
|
type.array.size);
|
|
|
|
break;
|
|
|
|
case ty_class:
|
|
|
|
printf (" %s\n", type.class);
|
|
|
|
break;
|
|
|
|
case ty_alias:
|
|
|
|
printf (" %d %s ", type.alias.type, type.alias.name);
|
|
|
|
print_type (type.alias.aux_type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void struct_func (qfot_var_t *var)
|
|
|
|
{
|
2020-07-03 16:40:02 +00:00
|
|
|
Type *type = [Type findType:var.type];
|
|
|
|
[type addToQueue];
|
2020-06-28 10:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
scan_types (void)
|
|
|
|
{
|
|
|
|
qfot_type_t *type;
|
|
|
|
|
|
|
|
for (type = encodings.types;
|
|
|
|
((int *)type - (int *) encodings.types) < encodings.size;
|
|
|
|
type = next_type (type)) {
|
2020-07-03 16:40:02 +00:00
|
|
|
if (type.size) {
|
|
|
|
string tag = str_mid(type.strct.tag, 4);
|
|
|
|
Type *avail_type = [Type fromType: type];
|
|
|
|
if (avail_type) {
|
2021-01-12 04:07:51 +00:00
|
|
|
if (!Hash_Find (available_types, [avail_type name])) {
|
|
|
|
printf ("scan: %s %s\n", tag, [avail_type name]);
|
|
|
|
Hash_Add (available_types, avail_type);
|
|
|
|
}
|
2020-07-03 16:40:02 +00:00
|
|
|
}
|
2020-06-28 10:08:18 +00:00
|
|
|
}
|
2020-07-03 16:40:02 +00:00
|
|
|
}
|
2020-06-28 10:08:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static string
|
|
|
|
get_string_key (void *str, void *unused)
|
|
|
|
{
|
|
|
|
return (string) str;
|
|
|
|
}
|
|
|
|
|
|
|
|
static string
|
|
|
|
get_object_key (void *obj, void *unused)
|
|
|
|
{
|
|
|
|
return [(id)obj name];
|
|
|
|
}
|
|
|
|
|
2020-07-03 16:40:02 +00:00
|
|
|
void
|
|
|
|
usage (string name)
|
|
|
|
{
|
2020-12-21 09:38:31 +00:00
|
|
|
printf ("%s [plist file] [output file] [header file]\n", name);
|
2020-07-03 16:40:02 +00:00
|
|
|
}
|
|
|
|
|
2020-06-28 10:08:18 +00:00
|
|
|
int
|
|
|
|
main(int argc, string *argv)
|
|
|
|
{
|
2020-07-03 16:40:02 +00:00
|
|
|
int do_struct = 0;
|
|
|
|
int do_enum = 0;
|
2020-07-05 05:59:56 +00:00
|
|
|
string plist_filename;
|
|
|
|
QFile plist_file;
|
|
|
|
PLItem *plist;
|
|
|
|
PLItem *search;
|
2021-01-04 23:38:35 +00:00
|
|
|
PLItem *handles;
|
2020-07-05 05:59:56 +00:00
|
|
|
|
|
|
|
arp_start ();
|
2020-07-03 16:40:02 +00:00
|
|
|
|
2020-12-21 09:38:31 +00:00
|
|
|
if (argc != 4) {
|
2020-07-03 16:40:02 +00:00
|
|
|
usage (argv[0]);
|
|
|
|
return 1;
|
|
|
|
}
|
2020-07-05 05:59:56 +00:00
|
|
|
plist_filename = argv[1];
|
|
|
|
plist_file = Qopen (plist_filename, "rt");
|
|
|
|
if (!plist_file) {
|
|
|
|
printf ("could not open property list file: %s\n", plist_filename);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
plist = [[PLItem fromFile: plist_file] retain];
|
|
|
|
if (!plist) {
|
|
|
|
printf ("error parsing: %s\n", plist_filename);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
Qclose (plist_file);
|
|
|
|
if ([plist class] != [PLDictionary class]) {
|
|
|
|
printf ("%s not a dictionary\n", plist_filename);
|
2020-07-03 16:40:02 +00:00
|
|
|
}
|
2020-07-05 05:59:56 +00:00
|
|
|
search = [[plist getObjectForKey: "search"] retain];
|
2021-01-04 23:38:35 +00:00
|
|
|
handles = [[plist getObjectForKey: "handles"] retain];
|
2020-07-05 05:59:56 +00:00
|
|
|
parse = [[plist getObjectForKey: "parse"] retain];
|
|
|
|
|
2020-06-28 10:08:18 +00:00
|
|
|
encodings = PR_FindGlobal (".type_encodings");
|
|
|
|
if (!encodings) {
|
|
|
|
printf ("Can't find encodings\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2020-07-05 05:59:56 +00:00
|
|
|
queue = [[Array array] retain];
|
|
|
|
output_types = [[Array array] retain];
|
2020-06-28 10:08:18 +00:00
|
|
|
available_types = Hash_NewTable (127, get_object_key, nil, nil);
|
|
|
|
processed_types = Hash_NewTable (127, get_string_key, nil, nil);
|
|
|
|
scan_types ();
|
|
|
|
|
2020-07-05 05:59:56 +00:00
|
|
|
for (int i = [search numObjects]; i-- > 0; ) {
|
|
|
|
PLString *str = (PLString *) [search getObjectAtIndex:i];
|
|
|
|
string search_name = [str string];
|
|
|
|
id obj = (id) Hash_Find (available_types, search_name);
|
2020-07-03 16:40:02 +00:00
|
|
|
obj = [obj resolveType];
|
|
|
|
printf("obj: %d %s\n", obj, class_get_class_name([obj class]));
|
2020-06-28 10:08:18 +00:00
|
|
|
if (obj && [obj class] == [Struct class]) {
|
|
|
|
[obj addToQueue];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while ([queue count]) {
|
|
|
|
id obj = [queue objectAtIndex:0];
|
|
|
|
[queue removeObjectAtIndex:0];
|
|
|
|
if ([obj class] == [Struct class]) {
|
2020-12-23 13:13:50 +00:00
|
|
|
if ([[parse getObjectForKey:[obj name]] string] == "skip") {
|
|
|
|
continue;
|
|
|
|
}
|
2020-06-28 10:08:18 +00:00
|
|
|
[obj forEachFieldCall:struct_func];
|
|
|
|
}
|
|
|
|
[output_types addObject:obj];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < argc; i++) {
|
|
|
|
printf ("vkgen %d %s\n", i, argv[i]);
|
|
|
|
}
|
|
|
|
|
2020-07-05 05:59:56 +00:00
|
|
|
arp_end ();
|
|
|
|
|
2020-07-03 16:40:02 +00:00
|
|
|
output_file = Qopen (argv[2], "wt");
|
2020-12-21 09:38:31 +00:00
|
|
|
header_file = Qopen (argv[3], "wt");
|
2020-06-28 10:08:18 +00:00
|
|
|
for (int i = [output_types count]; i-- > 0; ) {
|
|
|
|
id obj = [output_types objectAtIndex:i];
|
|
|
|
if ([obj name] == "VkStructureType") {
|
|
|
|
continue;
|
|
|
|
}
|
2020-07-05 05:59:56 +00:00
|
|
|
if ([obj class] != [Enum class]) {
|
2020-07-03 16:40:02 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-07-05 05:59:56 +00:00
|
|
|
|
|
|
|
arp_start ();
|
|
|
|
[obj writeTable];
|
|
|
|
arp_end ();
|
|
|
|
}
|
|
|
|
for (int i = [output_types count]; i-- > 0; ) {
|
|
|
|
id obj = [output_types objectAtIndex:i];
|
|
|
|
if ([obj name] == "VkStructureType") {
|
2020-06-28 10:08:18 +00:00
|
|
|
continue;
|
|
|
|
}
|
2020-07-05 05:59:56 +00:00
|
|
|
if ([obj class] != [Struct class]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
arp_start ();
|
2020-12-23 13:13:50 +00:00
|
|
|
[obj writeTable];
|
2020-07-05 05:59:56 +00:00
|
|
|
arp_end ();
|
2020-06-28 10:08:18 +00:00
|
|
|
}
|
2020-12-21 09:38:31 +00:00
|
|
|
fprintf (output_file, "static void\n");
|
|
|
|
fprintf (output_file, "vkgen_init_symtabs (exprctx_t *context)\n");
|
|
|
|
fprintf (output_file, "{\n");
|
|
|
|
for (int i = [output_types count]; i-- > 0; ) {
|
|
|
|
id obj = [output_types objectAtIndex:i];
|
|
|
|
if ([obj name] == "VkStructureType") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
arp_start ();
|
2020-12-23 13:13:50 +00:00
|
|
|
[obj writeSymtabInit];
|
2021-01-04 08:26:39 +00:00
|
|
|
[obj writeSymtabEntry];
|
2020-12-21 09:38:31 +00:00
|
|
|
arp_end ();
|
|
|
|
}
|
|
|
|
fprintf (output_file, "}\n");
|
2020-06-28 10:08:18 +00:00
|
|
|
Qclose (output_file);
|
2020-12-21 09:38:31 +00:00
|
|
|
Qclose (header_file);
|
2020-06-28 10:08:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|