glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
/* -*- c++ -*- */
|
|
|
|
|
/*
|
|
|
|
|
* Copyright © 2010 Intel Corporation
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "glsl_symbol_table.h"
|
2015-02-26 12:15:16 +01:00
|
|
|
#include "ast.h"
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
|
|
|
|
|
class symbol_table_entry {
|
|
|
|
|
public:
|
2016-10-07 20:41:10 +02:00
|
|
|
DECLARE_LINEAR_ALLOC_CXX_OPERATORS(symbol_table_entry);
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
|
2013-03-21 09:57:20 -07:00
|
|
|
bool add_interface(const glsl_type *i, enum ir_variable_mode mode)
|
|
|
|
|
{
|
|
|
|
|
const glsl_type **dest;
|
|
|
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case ir_var_uniform:
|
|
|
|
|
dest = &ibu;
|
|
|
|
|
break;
|
2015-05-13 10:41:55 +02:00
|
|
|
case ir_var_shader_storage:
|
|
|
|
|
dest = &iss;
|
|
|
|
|
break;
|
2013-03-21 09:57:20 -07:00
|
|
|
case ir_var_shader_in:
|
|
|
|
|
dest = &ibi;
|
|
|
|
|
break;
|
|
|
|
|
case ir_var_shader_out:
|
|
|
|
|
dest = &ibo;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(!"Unsupported interface variable mode!");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (*dest != NULL) {
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
*dest = i;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const glsl_type *get_interface(enum ir_variable_mode mode)
|
|
|
|
|
{
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case ir_var_uniform:
|
|
|
|
|
return ibu;
|
2015-05-13 10:41:55 +02:00
|
|
|
case ir_var_shader_storage:
|
|
|
|
|
return iss;
|
2013-03-21 09:57:20 -07:00
|
|
|
case ir_var_shader_in:
|
|
|
|
|
return ibi;
|
|
|
|
|
case ir_var_shader_out:
|
|
|
|
|
return ibo;
|
|
|
|
|
default:
|
|
|
|
|
assert(!"Unsupported interface variable mode!");
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
symbol_table_entry(ir_variable *v) :
|
2015-05-13 10:41:55 +02:00
|
|
|
v(v), f(0), t(0), ibu(0), iss(0), ibi(0), ibo(0), a(0) {}
|
2013-03-21 09:57:20 -07:00
|
|
|
symbol_table_entry(ir_function *f) :
|
2015-05-13 10:41:55 +02:00
|
|
|
v(0), f(f), t(0), ibu(0), iss(0), ibi(0), ibo(0), a(0) {}
|
2013-03-21 09:57:20 -07:00
|
|
|
symbol_table_entry(const glsl_type *t) :
|
2015-05-13 10:41:55 +02:00
|
|
|
v(0), f(0), t(t), ibu(0), iss(0), ibi(0), ibo(0), a(0) {}
|
2013-03-21 09:57:20 -07:00
|
|
|
symbol_table_entry(const glsl_type *t, enum ir_variable_mode mode) :
|
2015-05-13 10:41:55 +02:00
|
|
|
v(0), f(0), t(0), ibu(0), iss(0), ibi(0), ibo(0), a(0)
|
2013-03-21 09:57:20 -07:00
|
|
|
{
|
|
|
|
|
assert(t->is_interface());
|
|
|
|
|
add_interface(t, mode);
|
|
|
|
|
}
|
2013-06-25 00:27:41 -07:00
|
|
|
symbol_table_entry(const class ast_type_specifier *a):
|
2015-05-13 10:41:55 +02:00
|
|
|
v(0), f(0), t(0), ibu(0), iss(0), ibi(0), ibo(0), a(a) {}
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
|
|
|
|
|
ir_variable *v;
|
|
|
|
|
ir_function *f;
|
|
|
|
|
const glsl_type *t;
|
2013-03-21 09:57:20 -07:00
|
|
|
const glsl_type *ibu;
|
2015-05-13 10:41:55 +02:00
|
|
|
const glsl_type *iss;
|
2013-03-21 09:57:20 -07:00
|
|
|
const glsl_type *ibi;
|
|
|
|
|
const glsl_type *ibo;
|
2013-06-25 00:27:41 -07:00
|
|
|
const class ast_type_specifier *a;
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
glsl_symbol_table::glsl_symbol_table()
|
|
|
|
|
{
|
2012-08-01 17:44:02 -07:00
|
|
|
this->separate_function_namespace = false;
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
this->table = _mesa_symbol_table_ctor();
|
2011-01-21 14:32:31 -08:00
|
|
|
this->mem_ctx = ralloc_context(NULL);
|
2016-10-07 19:17:15 +02:00
|
|
|
this->linalloc = linear_alloc_parent(this->mem_ctx, 0);
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
glsl_symbol_table::~glsl_symbol_table()
|
|
|
|
|
{
|
|
|
|
|
_mesa_symbol_table_dtor(table);
|
2011-01-21 14:32:31 -08:00
|
|
|
ralloc_free(mem_ctx);
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void glsl_symbol_table::push_scope()
|
|
|
|
|
{
|
|
|
|
|
_mesa_symbol_table_push_scope(table);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void glsl_symbol_table::pop_scope()
|
|
|
|
|
{
|
|
|
|
|
_mesa_symbol_table_pop_scope(table);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool glsl_symbol_table::name_declared_this_scope(const char *name)
|
|
|
|
|
{
|
2016-10-21 16:50:52 +11:00
|
|
|
return _mesa_symbol_table_symbol_scope(table, name) == 0;
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
}
|
|
|
|
|
|
2010-11-05 06:11:24 -07:00
|
|
|
bool glsl_symbol_table::add_variable(ir_variable *v)
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
{
|
2014-07-08 18:53:09 -07:00
|
|
|
assert(v->data.mode != ir_var_temporary);
|
|
|
|
|
|
2012-08-01 17:44:02 -07:00
|
|
|
if (this->separate_function_namespace) {
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
/* In 1.10, functions and variables have separate namespaces. */
|
2010-11-05 06:11:24 -07:00
|
|
|
symbol_table_entry *existing = get_entry(v->name);
|
|
|
|
|
if (name_declared_this_scope(v->name)) {
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
/* If there's already an existing function (not a constructor!) in
|
|
|
|
|
* the current scope, just update the existing entry to include 'v'.
|
|
|
|
|
*/
|
|
|
|
|
if (existing->v == NULL && existing->t == NULL) {
|
|
|
|
|
existing->v = v;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
/* If not declared at this scope, add a new entry. But if an existing
|
|
|
|
|
* entry includes a function, propagate that to this block - otherwise
|
|
|
|
|
* the new variable declaration would shadow the function.
|
|
|
|
|
*/
|
2016-10-07 20:41:10 +02:00
|
|
|
symbol_table_entry *entry = new(linalloc) symbol_table_entry(v);
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
if (existing != NULL)
|
|
|
|
|
entry->f = existing->f;
|
2016-10-21 16:50:52 +11:00
|
|
|
int added = _mesa_symbol_table_add_symbol(table, v->name, entry);
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
assert(added == 0);
|
2010-08-30 13:53:15 +01:00
|
|
|
(void)added;
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 1.20+ rules: */
|
2016-10-07 20:41:10 +02:00
|
|
|
symbol_table_entry *entry = new(linalloc) symbol_table_entry(v);
|
2016-10-21 16:50:52 +11:00
|
|
|
return _mesa_symbol_table_add_symbol(table, v->name, entry) == 0;
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
}
|
|
|
|
|
|
2010-09-01 14:10:39 -07:00
|
|
|
bool glsl_symbol_table::add_type(const char *name, const glsl_type *t)
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
{
|
2016-10-07 20:41:10 +02:00
|
|
|
symbol_table_entry *entry = new(linalloc) symbol_table_entry(t);
|
2016-10-21 16:50:52 +11:00
|
|
|
return _mesa_symbol_table_add_symbol(table, name, entry) == 0;
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
}
|
|
|
|
|
|
2013-03-21 09:57:20 -07:00
|
|
|
bool glsl_symbol_table::add_interface(const char *name, const glsl_type *i,
|
|
|
|
|
enum ir_variable_mode mode)
|
|
|
|
|
{
|
|
|
|
|
assert(i->is_interface());
|
|
|
|
|
symbol_table_entry *entry = get_entry(name);
|
|
|
|
|
if (entry == NULL) {
|
|
|
|
|
symbol_table_entry *entry =
|
2016-10-07 20:41:10 +02:00
|
|
|
new(linalloc) symbol_table_entry(i, mode);
|
2013-03-21 09:57:20 -07:00
|
|
|
bool add_interface_symbol_result =
|
2016-10-21 16:50:52 +11:00
|
|
|
_mesa_symbol_table_add_symbol(table, name, entry) == 0;
|
2013-03-21 09:57:20 -07:00
|
|
|
assert(add_interface_symbol_result);
|
|
|
|
|
return add_interface_symbol_result;
|
|
|
|
|
} else {
|
|
|
|
|
return entry->add_interface(i, mode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-05 06:08:45 -07:00
|
|
|
bool glsl_symbol_table::add_function(ir_function *f)
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
{
|
2012-08-01 17:44:02 -07:00
|
|
|
if (this->separate_function_namespace && name_declared_this_scope(f->name)) {
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
/* In 1.10, functions and variables have separate namespaces. */
|
2010-11-05 06:08:45 -07:00
|
|
|
symbol_table_entry *existing = get_entry(f->name);
|
2010-09-01 14:08:08 -07:00
|
|
|
if ((existing->f == NULL) && (existing->t == NULL)) {
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
existing->f = f;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-07 20:41:10 +02:00
|
|
|
symbol_table_entry *entry = new(linalloc) symbol_table_entry(f);
|
2016-10-21 16:50:52 +11:00
|
|
|
return _mesa_symbol_table_add_symbol(table, f->name, entry) == 0;
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
}
|
|
|
|
|
|
2015-02-26 12:15:16 +01:00
|
|
|
bool glsl_symbol_table::add_default_precision_qualifier(const char *type_name,
|
|
|
|
|
int precision)
|
|
|
|
|
{
|
|
|
|
|
char *name = ralloc_asprintf(mem_ctx, "#default_precision_%s", type_name);
|
|
|
|
|
|
2016-10-07 19:17:15 +02:00
|
|
|
ast_type_specifier *default_specifier = new(linalloc) ast_type_specifier(name);
|
2015-02-26 12:15:16 +01:00
|
|
|
default_specifier->default_precision = precision;
|
|
|
|
|
|
|
|
|
|
symbol_table_entry *entry =
|
2016-10-07 20:41:10 +02:00
|
|
|
new(linalloc) symbol_table_entry(default_specifier);
|
2015-02-26 12:15:16 +01:00
|
|
|
|
2016-10-21 08:23:59 +02:00
|
|
|
if (!get_entry(name))
|
|
|
|
|
return _mesa_symbol_table_add_symbol(table, name, entry) == 0;
|
|
|
|
|
|
|
|
|
|
return _mesa_symbol_table_replace_symbol(table, name, entry) == 0;
|
2015-02-26 12:15:16 +01:00
|
|
|
}
|
|
|
|
|
|
2010-12-06 10:54:21 -08:00
|
|
|
void glsl_symbol_table::add_global_function(ir_function *f)
|
|
|
|
|
{
|
2016-10-07 20:41:10 +02:00
|
|
|
symbol_table_entry *entry = new(linalloc) symbol_table_entry(f);
|
2016-10-21 16:50:52 +11:00
|
|
|
int added = _mesa_symbol_table_add_global_symbol(table, f->name, entry);
|
2010-12-06 10:54:21 -08:00
|
|
|
assert(added == 0);
|
2011-03-16 09:16:01 +00:00
|
|
|
(void)added;
|
2010-12-06 10:54:21 -08:00
|
|
|
}
|
|
|
|
|
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
ir_variable *glsl_symbol_table::get_variable(const char *name)
|
|
|
|
|
{
|
|
|
|
|
symbol_table_entry *entry = get_entry(name);
|
|
|
|
|
return entry != NULL ? entry->v : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const glsl_type *glsl_symbol_table::get_type(const char *name)
|
|
|
|
|
{
|
|
|
|
|
symbol_table_entry *entry = get_entry(name);
|
|
|
|
|
return entry != NULL ? entry->t : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-21 09:57:20 -07:00
|
|
|
const glsl_type *glsl_symbol_table::get_interface(const char *name,
|
|
|
|
|
enum ir_variable_mode mode)
|
|
|
|
|
{
|
|
|
|
|
symbol_table_entry *entry = get_entry(name);
|
|
|
|
|
return entry != NULL ? entry->get_interface(mode) : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-01 14:16:53 -07:00
|
|
|
ir_function *glsl_symbol_table::get_function(const char *name)
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
{
|
|
|
|
|
symbol_table_entry *entry = get_entry(name);
|
2010-09-01 14:16:53 -07:00
|
|
|
return entry != NULL ? entry->f : NULL;
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
}
|
|
|
|
|
|
2015-02-26 12:15:16 +01:00
|
|
|
int glsl_symbol_table::get_default_precision_qualifier(const char *type_name)
|
|
|
|
|
{
|
|
|
|
|
char *name = ralloc_asprintf(mem_ctx, "#default_precision_%s", type_name);
|
|
|
|
|
symbol_table_entry *entry = get_entry(name);
|
|
|
|
|
if (!entry)
|
|
|
|
|
return ast_precision_none;
|
|
|
|
|
return entry->a->default_precision;
|
|
|
|
|
}
|
|
|
|
|
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
symbol_table_entry *glsl_symbol_table::get_entry(const char *name)
|
|
|
|
|
{
|
|
|
|
|
return (symbol_table_entry *)
|
2016-10-21 16:50:52 +11:00
|
|
|
_mesa_symbol_table_find_symbol(table, name);
|
glsl: Use a single shared namespace in the symbol table.
As of 1.20, variable names, function names, and structure type names all
share a single namespace, and should conflict with one another in the
same scope, or hide each other in nested scopes.
However, in 1.10, variables and functions can share the same name in the
same scope. Structure types, however, conflict with/hide both.
Fixes piglit tests redeclaration-06.vert, redeclaration-11.vert,
redeclaration-19.vert, and struct-05.vert.
2010-08-21 20:23:18 -07:00
|
|
|
}
|
2013-10-01 16:33:56 -07:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
glsl_symbol_table::disable_variable(const char *name)
|
|
|
|
|
{
|
|
|
|
|
/* Ideally we would remove the variable's entry from the symbol table, but
|
|
|
|
|
* that would be difficult. Fortunately, since this is only used for
|
|
|
|
|
* built-in variables, it won't be possible for the shader to re-introduce
|
|
|
|
|
* the variable later, so all we really need to do is to make sure that
|
|
|
|
|
* further attempts to access it using get_variable() will return NULL.
|
|
|
|
|
*/
|
|
|
|
|
symbol_table_entry *entry = get_entry(name);
|
|
|
|
|
if (entry != NULL) {
|
|
|
|
|
entry->v = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
glsl: use var with initializer on global var validation
Currently, when cross validating global variables, all global variables
seen in the shaders that are part of a program are saved in a table.
When checking a variable this already exist in the table, we check both
are initialized to the same value. If the already saved variable does
not have an initializer, we copy it from the new variable.
Unfortunately this is wrong, as we are modifying something it is
constant. Also, if this modified variable is used in
another program, it will keep the initializer, when it should have none.
Instead of copying the initializer, this commit replaces the old
variable with the new one. So if we see again the same variable with an
initializer, we can compare if both are the same or not.
v2: convert tabs in whitespaces (Kenenth Graunke)
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
2016-05-11 13:48:18 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
glsl_symbol_table::replace_variable(const char *name,
|
|
|
|
|
ir_variable *v)
|
|
|
|
|
{
|
|
|
|
|
symbol_table_entry *entry = get_entry(name);
|
|
|
|
|
if (entry != NULL) {
|
|
|
|
|
entry->v = v;
|
|
|
|
|
}
|
|
|
|
|
}
|