mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-04-07 01:42:04 +00:00
[qfcc] Redo interface blocks as namespaces
There's no direct support for namespaces in Ruamoko yet, nor even in qfcc, but glsl's blocks bring in a bit of foundation for them, even the concept of "using" (for blocks with no instance name). The members don't get locations allocated to them yet, but fstrianglest.vert compiles and links correctly otherwise. Also, there's no error checking yet.
This commit is contained in:
parent
291898b46f
commit
9b2b841a55
8 changed files with 197 additions and 23 deletions
|
@ -45,4 +45,17 @@ extern language_t lang_glsl_tese;
|
|||
extern language_t lang_glsl_geom;
|
||||
extern language_t lang_glsl_frag;
|
||||
|
||||
typedef struct glsl_block_s {
|
||||
struct glsl_block_s *next;
|
||||
const char *name;
|
||||
struct symtab_s *members;
|
||||
struct symbol_s *instance_name;
|
||||
} glsl_block_t;
|
||||
|
||||
struct specifier_s;
|
||||
|
||||
void glsl_block_clear (void);
|
||||
void glsl_declare_block (struct specifier_s spec, struct symbol_s *block_sym,
|
||||
struct symbol_s *instance_name);
|
||||
|
||||
#endif//__glsl_lang_h
|
||||
|
|
|
@ -59,6 +59,7 @@ typedef enum {
|
|||
sy_class, ///< symbol refers to a class
|
||||
sy_convert, ///< symbol refers to a conversion function
|
||||
sy_macro, ///< symbol refers to a macro definition
|
||||
sy_namespace, ///< symbol refers to a namespace definition
|
||||
} sy_type_e;
|
||||
|
||||
typedef struct symconv_s {
|
||||
|
@ -74,7 +75,7 @@ typedef struct symbol_s {
|
|||
sy_type_e sy_type; ///< symbol type
|
||||
const struct type_s *type; ///< type of object to which symbol refers
|
||||
struct param_s *params; ///< the parameters if a function
|
||||
unsigned no_auto_init; ///< skip for non-designated initializers
|
||||
bool no_auto_init:1; ///< skip for non-designated initializers
|
||||
union {
|
||||
int offset; ///< sy_var (in a struct/union/macro)
|
||||
struct def_s *def; ///< sy_var
|
||||
|
@ -83,6 +84,7 @@ typedef struct symbol_s {
|
|||
struct metafunc_s *metafunc;///< sy_func
|
||||
symconv_t convert; ///< sy_convert
|
||||
struct rua_macro_s *macro; ///< sy_macro
|
||||
struct symtab_s *namespace; ///< sy_namespace
|
||||
};
|
||||
} symbol_t;
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ qfcc_SOURCES = \
|
|||
tools/qfcc/source/evaluate.c \
|
||||
tools/qfcc/source/flow.c \
|
||||
tools/qfcc/source/function.c \
|
||||
tools/qfcc/source/glsl-block.c \
|
||||
tools/qfcc/source/glsl-builtins.c \
|
||||
tools/qfcc/source/glsl-parse.y \
|
||||
tools/qfcc/source/grab.c \
|
||||
|
|
|
@ -107,6 +107,7 @@ is_lvalue (const expr_t *expr)
|
|||
case sy_convert:
|
||||
break;
|
||||
case sy_macro:
|
||||
case sy_namespace:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
|
143
tools/qfcc/source/glsl-block.c
Normal file
143
tools/qfcc/source/glsl-block.c
Normal file
|
@ -0,0 +1,143 @@
|
|||
/*
|
||||
glsl-block.c
|
||||
|
||||
GLSL specific block handling
|
||||
|
||||
Copyright (C) 2024 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
|
||||
|
||||
*/
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
#endif
|
||||
|
||||
#include "QF/alloc.h"
|
||||
#include "QF/hash.h"
|
||||
#include "QF/va.h"
|
||||
|
||||
#include "tools/qfcc/include/def.h"
|
||||
#include "tools/qfcc/include/diagnostic.h"
|
||||
#include "tools/qfcc/include/glsl-lang.h"
|
||||
#include "tools/qfcc/include/shared.h"
|
||||
#include "tools/qfcc/include/strpool.h"
|
||||
#include "tools/qfcc/include/symtab.h"
|
||||
|
||||
ALLOC_STATE (glsl_block_t, blocks);
|
||||
|
||||
static hashtab_t *input_blocks;
|
||||
static hashtab_t *output_blocks;
|
||||
static hashtab_t *uniform_blocks;
|
||||
static hashtab_t *buffer_blocks;
|
||||
static hashtab_t *shared_blocks;
|
||||
|
||||
static const char *
|
||||
block_get_key (const void *_b, void *)
|
||||
{
|
||||
auto b = (const glsl_block_t *) _b;
|
||||
return b->name;
|
||||
}
|
||||
|
||||
void
|
||||
glsl_block_clear (void)
|
||||
{
|
||||
if (input_blocks) {
|
||||
Hash_FlushTable (input_blocks);
|
||||
Hash_FlushTable (output_blocks);
|
||||
Hash_FlushTable (uniform_blocks);
|
||||
Hash_FlushTable (buffer_blocks);
|
||||
Hash_FlushTable (shared_blocks);
|
||||
} else {
|
||||
input_blocks = Hash_NewTable (127, block_get_key, 0, 0, 0);
|
||||
output_blocks = Hash_NewTable (127, block_get_key, 0, 0, 0);
|
||||
uniform_blocks = Hash_NewTable (127, block_get_key, 0, 0, 0);
|
||||
buffer_blocks = Hash_NewTable (127, block_get_key, 0, 0, 0);
|
||||
shared_blocks = Hash_NewTable (127, block_get_key, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static const expr_t *
|
||||
block_sym_ref (symbol_t *sym, void *data)
|
||||
{
|
||||
return new_symbol_expr (data);
|
||||
}
|
||||
|
||||
void
|
||||
glsl_declare_block (specifier_t spec, symbol_t *block_sym,
|
||||
symbol_t *instance_name)
|
||||
{
|
||||
hashtab_t *block_tab = nullptr;
|
||||
switch (spec.storage) {
|
||||
case sc_in:
|
||||
block_tab = input_blocks;
|
||||
break;
|
||||
case sc_out:
|
||||
block_tab = output_blocks;
|
||||
break;
|
||||
case sc_uniform:
|
||||
block_tab = uniform_blocks;
|
||||
break;
|
||||
case sc_buffer:
|
||||
block_tab = buffer_blocks;
|
||||
break;
|
||||
case sc_shared:
|
||||
block_tab = shared_blocks;
|
||||
break;
|
||||
case sc_global:
|
||||
case sc_system:
|
||||
case sc_extern:
|
||||
case sc_static:
|
||||
case sc_param:
|
||||
case sc_local:
|
||||
case sc_argument:
|
||||
break;
|
||||
}
|
||||
if (!block_tab) {
|
||||
error (0, "invalid storage for block");
|
||||
return;
|
||||
}
|
||||
glsl_block_t *block;
|
||||
ALLOC (64, glsl_block_t, blocks, block);
|
||||
*block = (glsl_block_t) {
|
||||
.name = save_string (block_sym->name),
|
||||
.members = block_sym->namespace,
|
||||
.instance_name = instance_name,
|
||||
};
|
||||
Hash_Add (block_tab, block);
|
||||
for (auto sym = block->members->symbols; sym; sym = sym->next) {
|
||||
auto def = new_def (sym->name, nullptr, nullptr, spec.storage);
|
||||
def->type = sym->type;
|
||||
sym->sy_type = sy_var;
|
||||
sym->def = def;
|
||||
}
|
||||
if (instance_name) {
|
||||
//namespace_add (instance_name, block->members);
|
||||
} else {
|
||||
for (auto sym = block->members->symbols; sym; sym = sym->next) {
|
||||
auto new = new_symbol (sym->name);
|
||||
new->sy_type = sy_convert;
|
||||
new->convert = (symconv_t) {
|
||||
.conv = block_sym_ref,
|
||||
.data = sym,
|
||||
};
|
||||
|
||||
symtab_addsymbol (current_symtab, new);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -823,44 +823,51 @@ glsl_parse_vars (const char *var_src)
|
|||
glsl_parse_string (var_src);
|
||||
}
|
||||
|
||||
static void
|
||||
glsl_init_common (void)
|
||||
{
|
||||
glsl_block_clear ();
|
||||
glsl_parse_vars (glsl_system_constants);
|
||||
}
|
||||
|
||||
void
|
||||
glsl_init_comp (void)
|
||||
{
|
||||
glsl_parse_vars (glsl_system_constants);
|
||||
glsl_init_common ();
|
||||
glsl_parse_vars (glsl_compute_vars);
|
||||
}
|
||||
|
||||
void
|
||||
glsl_init_vert (void)
|
||||
{
|
||||
glsl_parse_vars (glsl_system_constants);
|
||||
glsl_init_common ();
|
||||
glsl_parse_vars (glsl_Vulkan_vertex_vars);
|
||||
}
|
||||
|
||||
void
|
||||
glsl_init_tesc (void)
|
||||
{
|
||||
glsl_parse_vars (glsl_system_constants);
|
||||
glsl_init_common ();
|
||||
glsl_parse_vars (glsl_tesselation_control_vars);
|
||||
}
|
||||
|
||||
void
|
||||
glsl_init_tese (void)
|
||||
{
|
||||
glsl_parse_vars (glsl_system_constants);
|
||||
glsl_init_common ();
|
||||
glsl_parse_vars (glsl_tesselation_evaluation_vars);
|
||||
}
|
||||
|
||||
void
|
||||
glsl_init_geom (void)
|
||||
{
|
||||
glsl_parse_vars (glsl_system_constants);
|
||||
glsl_init_common ();
|
||||
glsl_parse_vars (glsl_geometry_vars);
|
||||
}
|
||||
|
||||
void
|
||||
glsl_init_frag (void)
|
||||
{
|
||||
glsl_parse_vars (glsl_system_constants);
|
||||
glsl_init_common ();
|
||||
glsl_parse_vars (glsl_fragment_vars);
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ int yylex (YYSTYPE *yylval, YYLTYPE *yylloc);
|
|||
%token <spec> LOW_PRECISION DISCARD COHERENT
|
||||
|
||||
%type <symbol> variable_identifier
|
||||
%type <symtab> block_declaration
|
||||
%type <symbol> block_declaration
|
||||
%type <expr> expression primary_exprsssion assignment_expression
|
||||
%type <expr> for_init_statement conditionopt expressionopt else
|
||||
%type <expr> conditional_expression unary_expression postfix_expression
|
||||
|
@ -546,17 +546,23 @@ declaration
|
|||
{
|
||||
auto spec = $1;
|
||||
auto block = $2;
|
||||
for (auto s = block->symbols; s; s = s->next) {
|
||||
auto b_spec = spec_merge (spec, (specifier_t) {
|
||||
.type = s->type,
|
||||
.sym = new_symbol (s->name),
|
||||
});
|
||||
b_spec.storage = sc_extern;
|
||||
declare_symbol (b_spec, nullptr, current_symtab);
|
||||
}
|
||||
glsl_declare_block (spec, block, nullptr);
|
||||
}
|
||||
| type_qualifier block_declaration IDENTIFIER ';'
|
||||
{
|
||||
auto spec = $1;
|
||||
auto block = $2;
|
||||
auto instance_name = $3;
|
||||
glsl_declare_block (spec, block, instance_name);
|
||||
}
|
||||
| type_qualifier block_declaration IDENTIFIER array_specifier ';'
|
||||
{
|
||||
auto spec = $1;
|
||||
auto block = $2;
|
||||
auto instance_name = $3;
|
||||
instance_name->type = $4;
|
||||
glsl_declare_block (spec, block, instance_name);
|
||||
}
|
||||
| type_qualifier ';'
|
||||
| type_qualifier IDENTIFIER ';'
|
||||
| type_qualifier IDENTIFIER identifier_list ';'
|
||||
|
@ -565,15 +571,16 @@ declaration
|
|||
block_declaration
|
||||
: IDENTIFIER '{'
|
||||
{
|
||||
int op = 's';//FIXME 'b' might be better (for block)
|
||||
auto sym = $1;
|
||||
current_symtab = start_struct (&op, sym, current_symtab);
|
||||
auto block = new_symtab (current_symtab, stab_struct);
|
||||
current_symtab = block;
|
||||
}
|
||||
struct_declaration_list '}'
|
||||
{
|
||||
auto block = current_symtab;
|
||||
current_symtab = block->parent;
|
||||
$$ = block;
|
||||
auto sym = $1;
|
||||
sym->sy_type = sy_namespace;
|
||||
sym->namespace = current_symtab;
|
||||
current_symtab = sym->namespace->parent;
|
||||
$$ = sym;
|
||||
}
|
||||
;
|
||||
|
||||
|
|
|
@ -212,7 +212,7 @@ build_struct (int su, symbol_t *tag, symtab_t *symtab, const type_t *type,
|
|||
s = s->next;
|
||||
s->offset += offset;
|
||||
s->table = symtab;
|
||||
s->no_auto_init = 1;
|
||||
s->no_auto_init = true;
|
||||
Hash_Add (symtab->tab, s);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue