mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-26 21:51:28 +00:00
I really don't like the way they're included (I'm really looking forward to #embed, but gotta wait for gcc 15), and I'm a tad grumpy that the documentation for them (https://registry.khronos.org/SPIR-V/specs/unified1/MachineReadableGrammar.html) is wrong (missing fields), but I think I like the result. The grammars (core and glsl.std.450) are parsed into structs that should be fairly easy to interpret: the instructions, kinds, and enumerant values are sorted by name for search with bsearch. Having the data parsed in means source code can refer to the items by name rather than magic numbers, which will be very nice for intrinsics and image types (and probably a few other things).
91 lines
2.3 KiB
C
91 lines
2.3 KiB
C
/*
|
|
spirv_grammar.c
|
|
|
|
SPIR-V grammar json embedding
|
|
|
|
Copyright (C) 2024 Bill Currie
|
|
|
|
Author: Bill Currie <bill@taniwha.org>
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public License
|
|
as published by the Free Software Foundation; either version 2
|
|
of the License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to:
|
|
|
|
Free Software Foundation, Inc.
|
|
59 Temple Place - Suite 330
|
|
Boston, MA 02111-1307, USA
|
|
|
|
*/
|
|
|
|
#ifndef __spirv_grammar_h
|
|
#define __spirv_grammar_h
|
|
|
|
typedef struct spirv_operand_s {
|
|
const char *kind;
|
|
char quantifier; // ?
|
|
const char *name; // ?
|
|
} spirv_operand_t;
|
|
|
|
typedef struct spiv_enumerant_s {
|
|
const char *enumerant;
|
|
uint32_t value;
|
|
uint32_t num_capabilities;
|
|
const char **capabilities;
|
|
const char **extensions;
|
|
uint32_t num_extensions;
|
|
uint32_t num_parameters;
|
|
spirv_operand_t *parameters;
|
|
const char *version;
|
|
const char *lastVersion;
|
|
} spirv_enumerant_t;
|
|
|
|
typedef struct spirv_kind_s {
|
|
const char *category;
|
|
const char *kind;
|
|
const char *doc;
|
|
uint32_t num;
|
|
union {
|
|
spirv_enumerant_t *enumerants;
|
|
const char **bases;
|
|
};
|
|
} spirv_kind_t;
|
|
|
|
typedef struct spirv_instruction_s {
|
|
const char *opname;
|
|
uint32_t opcode;
|
|
uint32_t num_operands;
|
|
spirv_operand_t *operands;
|
|
const char **capabilities;
|
|
uint32_t num_capabilities;
|
|
uint32_t num_extensions;
|
|
const char **extensions;
|
|
const char *version;
|
|
const char *lastVersion;
|
|
} spirv_instruction_t;
|
|
|
|
typedef struct spirv_grammar_s {
|
|
struct spirv_grammar_s *parent; // for inheriting operand kinds
|
|
const char **copyright; // array of string objects
|
|
uint32_t num_copyright;
|
|
uint32_t magic_number;
|
|
uint32_t major_version;
|
|
uint32_t minor_version;
|
|
uint32_t version;
|
|
uint32_t revision;
|
|
spirv_instruction_t *instructions;
|
|
uint32_t num_instructions;
|
|
uint32_t num_operand_kinds;
|
|
spirv_kind_t *operand_kinds;
|
|
} spirv_grammar_t;
|
|
|
|
#endif//__spirv_grammar_h
|