2010-03-19 11:42:45 -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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GLSL_SYMBOL_TABLE
|
|
|
|
#define GLSL_SYMBOL_TABLE
|
|
|
|
|
2010-06-23 15:47:04 -07:00
|
|
|
#include <new>
|
|
|
|
|
2010-07-26 17:47:59 -07:00
|
|
|
#include "program/symbol_table.h"
|
2010-03-19 11:42:45 -07:00
|
|
|
#include "ir.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;
|
2014-06-14 23:37:41 -07:00
|
|
|
struct glsl_type;
|
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-03-19 11:42:45 -07:00
|
|
|
/**
|
|
|
|
* Facade class for _mesa_symbol_table
|
|
|
|
*
|
|
|
|
* Wraps the existing \c _mesa_symbol_table data structure to enforce some
|
|
|
|
* type safe and some symbol table invariants.
|
|
|
|
*/
|
2010-08-14 15:35:57 +01:00
|
|
|
struct glsl_symbol_table {
|
2014-09-30 00:12:40 -04:00
|
|
|
DECLARE_RALLOC_CXX_OPERATORS(glsl_symbol_table)
|
2010-06-23 15:47:04 -07: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
|
|
|
glsl_symbol_table();
|
|
|
|
~glsl_symbol_table();
|
2010-03-19 11:42:45 -07:00
|
|
|
|
2012-08-01 17:44:02 -07:00
|
|
|
/* In 1.10, functions and variables have separate namespaces. */
|
|
|
|
bool separate_function_namespace;
|
2010-03-19 11:42:45 -07: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
|
|
|
void push_scope();
|
|
|
|
void pop_scope();
|
2010-03-19 11:42:45 -07:00
|
|
|
|
2010-03-19 15:37:01 -07:00
|
|
|
/**
|
|
|
|
* Determine whether a name was declared at the current scope
|
|
|
|
*/
|
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
|
|
|
bool name_declared_this_scope(const char *name);
|
2010-03-19 15:37:01 -07:00
|
|
|
|
2010-03-19 11:42:45 -07:00
|
|
|
/**
|
|
|
|
* \name Methods to add symbols to the table
|
|
|
|
*
|
|
|
|
* There is some temptation to rename all these functions to \c add_symbol
|
|
|
|
* or similar. However, this breaks symmetry with the getter functions and
|
|
|
|
* reduces the clarity of the intention of code that uses these methods.
|
|
|
|
*/
|
|
|
|
/*@{*/
|
2010-11-05 06:11:24 -07:00
|
|
|
bool add_variable(ir_variable *v);
|
2010-09-01 14:10:39 -07:00
|
|
|
bool add_type(const char *name, const glsl_type *t);
|
2010-11-05 06:08:45 -07:00
|
|
|
bool add_function(ir_function *f);
|
2013-03-21 09:57:20 -07:00
|
|
|
bool add_interface(const char *name, const glsl_type *i,
|
|
|
|
enum ir_variable_mode mode);
|
2015-02-26 12:15:16 +01:00
|
|
|
bool add_default_precision_qualifier(const char *type_name, int precision);
|
2010-03-19 11:42:45 -07:00
|
|
|
/*@}*/
|
|
|
|
|
2010-12-06 10:54:21 -08:00
|
|
|
/**
|
|
|
|
* Add an function at global scope without checking for scoping conflicts.
|
|
|
|
*/
|
|
|
|
void add_global_function(ir_function *f);
|
|
|
|
|
2010-03-19 11:42:45 -07:00
|
|
|
/**
|
|
|
|
* \name Methods to get symbols from the table
|
|
|
|
*/
|
|
|
|
/*@{*/
|
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 *get_variable(const char *name);
|
|
|
|
const glsl_type *get_type(const char *name);
|
2010-09-01 14:16:53 -07:00
|
|
|
ir_function *get_function(const char *name);
|
2013-03-21 09:57:20 -07:00
|
|
|
const glsl_type *get_interface(const char *name,
|
|
|
|
enum ir_variable_mode mode);
|
2015-02-26 12:15:16 +01:00
|
|
|
int get_default_precision_qualifier(const char *type_name);
|
2010-03-19 11:42:45 -07:00
|
|
|
/*@}*/
|
|
|
|
|
2013-10-01 16:33:56 -07:00
|
|
|
/**
|
|
|
|
* Disable a previously-added variable so that it no longer appears to be
|
|
|
|
* in the symbol table. This is necessary when gl_PerVertex is redeclared,
|
|
|
|
* to ensure that previously-available built-in variables are no longer
|
|
|
|
* available.
|
|
|
|
*/
|
|
|
|
void disable_variable(const char *name);
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Replaces the variable in the entry by the new variable.
|
|
|
|
*/
|
|
|
|
void replace_variable(const char *name, ir_variable *v);
|
|
|
|
|
2010-03-19 11:42:45 -07:00
|
|
|
private:
|
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 *get_entry(const char *name);
|
|
|
|
|
2010-03-19 11:42:45 -07:00
|
|
|
struct _mesa_symbol_table *table;
|
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 *mem_ctx;
|
2016-10-07 19:17:15 +02:00
|
|
|
void *linalloc;
|
2010-03-19 11:42:45 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GLSL_SYMBOL_TABLE */
|