daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
Nicolas Capens | 1fbc287 | 2014-01-03 14:12:09 -0500 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 7 | #ifndef COMPILER_TRANSLATOR_SYMBOLTABLE_H_ |
| 8 | #define COMPILER_TRANSLATOR_SYMBOLTABLE_H_ |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 9 | |
| 10 | // |
| 11 | // Symbol table for parsing. Has these design characteristics: |
| 12 | // |
| 13 | // * Same symbol table can be used to compile many shaders, to preserve |
| 14 | // effort of creating and loading with the large numbers of built-in |
| 15 | // symbols. |
| 16 | // |
| 17 | // * Name mangling will be used to give each function a unique name |
| 18 | // so that symbol table lookups are never ambiguous. This allows |
| 19 | // a simpler symbol table structure. |
| 20 | // |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 21 | // * Pushing and popping of scope, so symbol table will really be a stack |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 22 | // of symbol tables. Searched from the top, with new inserts going into |
| 23 | // the top. |
| 24 | // |
| 25 | // * Constants: Compile time constant symbols will keep their values |
| 26 | // in the symbol table. The parser can substitute constants at parse |
| 27 | // time, including doing constant folding and constant propagation. |
| 28 | // |
| 29 | // * No temporaries: Temporaries made from operations (+, --, .xy, etc.) |
| 30 | // are tracked in the intermediate representation, not the symbol table. |
| 31 | // |
| 32 | |
Martin Radev | e93d24e | 2016-07-28 12:06:05 +0300 | [diff] [blame] | 33 | #include <array> |
alokp@chromium.org | 4e4facd | 2010-06-02 15:21:22 +0000 | [diff] [blame] | 34 | #include <assert.h> |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 35 | #include <set> |
alokp@chromium.org | e4249f0 | 2010-07-26 18:13:52 +0000 | [diff] [blame] | 36 | |
Jamie Madill | 703cdd6 | 2013-07-08 15:07:30 -0400 | [diff] [blame] | 37 | #include "common/angleutils.h" |
Olli Etuaho | 2a1e8f9 | 2017-07-14 11:49:36 +0300 | [diff] [blame] | 38 | #include "compiler/translator/ExtensionBehavior.h" |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame^] | 39 | #include "compiler/translator/ImmutableString.h" |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 40 | #include "compiler/translator/InfoSink.h" |
Jamie Madill | b1a85f4 | 2014-08-19 15:23:24 -0400 | [diff] [blame] | 41 | #include "compiler/translator/IntermNode.h" |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame] | 42 | #include "compiler/translator/StaticType.h" |
Olli Etuaho | d4529f3 | 2017-12-12 13:06:40 +0200 | [diff] [blame] | 43 | #include "compiler/translator/Symbol.h" |
alokp@chromium.org | 4388487 | 2010-03-30 00:08:52 +0000 | [diff] [blame] | 44 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 45 | namespace sh |
| 46 | { |
| 47 | |
Gus Fernandez | 964df49 | 2014-10-13 11:54:39 -0700 | [diff] [blame] | 48 | // Define ESymbolLevel as int rather than an enum since level can go |
| 49 | // above GLOBAL_LEVEL and cause atBuiltInLevel() to fail if the |
| 50 | // compiler optimizes the >= of the last element to ==. |
| 51 | typedef int ESymbolLevel; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 52 | const int COMMON_BUILTINS = 0; |
| 53 | const int ESSL1_BUILTINS = 1; |
| 54 | const int ESSL3_BUILTINS = 2; |
Martin Radev | e93d24e | 2016-07-28 12:06:05 +0300 | [diff] [blame] | 55 | const int ESSL3_1_BUILTINS = 3; |
Olli Etuaho | 977ee7e | 2017-07-21 11:38:27 +0300 | [diff] [blame] | 56 | // GLSL_BUILTINS are desktop GLSL builtins that don't exist in ESSL but are used to implement |
| 57 | // features in ANGLE's GLSL backend. They're not visible to the parser. |
| 58 | const int GLSL_BUILTINS = 4; |
| 59 | const int LAST_BUILTIN_LEVEL = GLSL_BUILTINS; |
| 60 | const int GLOBAL_LEVEL = 5; |
shannonwoods@chromium.org | 6e10a0e | 2013-05-30 00:02:13 +0000 | [diff] [blame] | 61 | |
Jamie Madill | f0d10f8 | 2015-03-31 12:56:52 -0400 | [diff] [blame] | 62 | class TSymbolTable : angle::NonCopyable |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 63 | { |
| 64 | public: |
Olli Etuaho | 195be94 | 2017-12-04 23:40:14 +0200 | [diff] [blame] | 65 | TSymbolTable() : mUniqueIdCounter(0), mUserDefinedUniqueIdsStart(-1) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 66 | { |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 67 | // The symbol table cannot be used until push() is called, but |
| 68 | // the lack of an initial call to push() can be used to detect |
| 69 | // that the symbol table has not been preloaded with built-ins. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 72 | ~TSymbolTable(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 73 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 74 | // When the symbol table is initialized with the built-ins, there should |
| 75 | // 'push' calls, so that built-ins are at level 0 and the shader |
| 76 | // globals are at level 1. |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 77 | bool isEmpty() const { return table.empty(); } |
| 78 | bool atBuiltInLevel() const { return currentLevel() <= LAST_BUILTIN_LEVEL; } |
| 79 | bool atGlobalLevel() const { return currentLevel() == GLOBAL_LEVEL; } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 80 | |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 81 | void push(); |
| 82 | void pop(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 83 | |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 84 | // The declare* entry points are used when parsing and declare symbols at the current scope. |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 85 | // They return the created true in case the declaration was successful, and false if the |
| 86 | // declaration failed due to redefinition. |
Olli Etuaho | 195be94 | 2017-12-04 23:40:14 +0200 | [diff] [blame] | 87 | bool declareVariable(TVariable *variable); |
Olli Etuaho | 035419f | 2017-11-28 14:27:15 +0200 | [diff] [blame] | 88 | bool declareStructType(TStructure *str); |
Olli Etuaho | 378c3a5 | 2017-12-04 11:32:13 +0200 | [diff] [blame] | 89 | bool declareInterfaceBlock(TInterfaceBlock *interfaceBlock); |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 90 | // Functions are always declared at global scope. |
| 91 | void declareUserDefinedFunction(TFunction *function, bool insertUnmangledName); |
shannonwoods@chromium.org | 1c84809 | 2013-05-30 00:02:34 +0000 | [diff] [blame] | 92 | |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 93 | // The insert* entry points are used when initializing the symbol table with built-ins. |
Olli Etuaho | 035419f | 2017-11-28 14:27:15 +0200 | [diff] [blame] | 94 | // They return the created symbol / true in case the declaration was successful, and nullptr / |
| 95 | // false if the declaration failed due to redefinition. |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame^] | 96 | TVariable *insertVariable(ESymbolLevel level, const ImmutableString &name, const TType *type); |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 97 | TVariable *insertVariableExt(ESymbolLevel level, |
Olli Etuaho | 2a1e8f9 | 2017-07-14 11:49:36 +0300 | [diff] [blame] | 98 | TExtension ext, |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame^] | 99 | const ImmutableString &name, |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame] | 100 | const TType *type); |
Olli Etuaho | 195be94 | 2017-12-04 23:40:14 +0200 | [diff] [blame] | 101 | bool insertVariable(ESymbolLevel level, TVariable *variable); |
Olli Etuaho | 035419f | 2017-11-28 14:27:15 +0200 | [diff] [blame] | 102 | bool insertStructType(ESymbolLevel level, TStructure *str); |
Olli Etuaho | 378c3a5 | 2017-12-04 11:32:13 +0200 | [diff] [blame] | 103 | bool insertInterfaceBlock(ESymbolLevel level, TInterfaceBlock *interfaceBlock); |
Nicolas Capens | c9d9b30 | 2015-02-20 23:02:15 -0500 | [diff] [blame] | 104 | |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame] | 105 | template <TPrecision precision> |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame^] | 106 | bool insertConstInt(ESymbolLevel level, const ImmutableString &name, int value); |
Nicolas Capens | 49a8887 | 2013-06-20 09:54:03 -0400 | [diff] [blame] | 107 | |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame] | 108 | template <TPrecision precision> |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame^] | 109 | bool insertConstIntExt(ESymbolLevel level, |
| 110 | TExtension ext, |
| 111 | const ImmutableString &name, |
| 112 | int value); |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 113 | |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame] | 114 | template <TPrecision precision> |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame^] | 115 | bool insertConstIvec3(ESymbolLevel level, |
| 116 | const ImmutableString &name, |
| 117 | const std::array<int, 3> &values); |
Martin Radev | e93d24e | 2016-07-28 12:06:05 +0300 | [diff] [blame] | 118 | |
Olli Etuaho | 342b83d | 2018-01-10 13:24:01 +0200 | [diff] [blame] | 119 | // Note that for inserted built-in functions the const char *name needs to remain valid for the |
| 120 | // lifetime of the SymbolTable. SymbolTable does not allocate a copy of it. |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 121 | void insertBuiltIn(ESymbolLevel level, |
| 122 | TOperator op, |
Olli Etuaho | 2a1e8f9 | 2017-07-14 11:49:36 +0300 | [diff] [blame] | 123 | TExtension ext, |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 124 | const TType *rvalue, |
| 125 | const char *name, |
| 126 | const TType *ptype1, |
| 127 | const TType *ptype2 = 0, |
| 128 | const TType *ptype3 = 0, |
| 129 | const TType *ptype4 = 0, |
| 130 | const TType *ptype5 = 0); |
Nicolas Capens | 759b994 | 2014-02-14 17:57:14 -0500 | [diff] [blame] | 131 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 132 | void insertBuiltIn(ESymbolLevel level, |
| 133 | const TType *rvalue, |
| 134 | const char *name, |
| 135 | const TType *ptype1, |
| 136 | const TType *ptype2 = 0, |
| 137 | const TType *ptype3 = 0, |
| 138 | const TType *ptype4 = 0, |
| 139 | const TType *ptype5 = 0) |
Nicolas Capens | 482907e | 2015-02-23 16:56:33 -0500 | [diff] [blame] | 140 | { |
Martin Radev | da6254b | 2016-12-14 17:00:36 +0200 | [diff] [blame] | 141 | insertUnmangledBuiltInName(name, level); |
Olli Etuaho | 2a1e8f9 | 2017-07-14 11:49:36 +0300 | [diff] [blame] | 142 | insertBuiltIn(level, EOpNull, TExtension::UNDEFINED, rvalue, name, ptype1, ptype2, ptype3, |
| 143 | ptype4, ptype5); |
Nicolas Capens | c9d9b30 | 2015-02-20 23:02:15 -0500 | [diff] [blame] | 144 | } |
| 145 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 146 | void insertBuiltIn(ESymbolLevel level, |
Olli Etuaho | 2a1e8f9 | 2017-07-14 11:49:36 +0300 | [diff] [blame] | 147 | TExtension ext, |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 148 | const TType *rvalue, |
| 149 | const char *name, |
| 150 | const TType *ptype1, |
| 151 | const TType *ptype2 = 0, |
| 152 | const TType *ptype3 = 0, |
| 153 | const TType *ptype4 = 0, |
| 154 | const TType *ptype5 = 0) |
Nicolas Capens | c9d9b30 | 2015-02-20 23:02:15 -0500 | [diff] [blame] | 155 | { |
Martin Radev | da6254b | 2016-12-14 17:00:36 +0200 | [diff] [blame] | 156 | insertUnmangledBuiltInName(name, level); |
Nicolas Capens | c9d9b30 | 2015-02-20 23:02:15 -0500 | [diff] [blame] | 157 | insertBuiltIn(level, EOpNull, ext, rvalue, name, ptype1, ptype2, ptype3, ptype4, ptype5); |
| 158 | } |
| 159 | |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame] | 160 | void insertBuiltInOp(ESymbolLevel level, |
| 161 | TOperator op, |
| 162 | const TType *rvalue, |
| 163 | const TType *ptype1, |
| 164 | const TType *ptype2 = 0, |
| 165 | const TType *ptype3 = 0, |
| 166 | const TType *ptype4 = 0, |
| 167 | const TType *ptype5 = 0); |
| 168 | |
| 169 | void insertBuiltInOp(ESymbolLevel level, |
| 170 | TOperator op, |
Olli Etuaho | 2a1e8f9 | 2017-07-14 11:49:36 +0300 | [diff] [blame] | 171 | TExtension ext, |
Olli Etuaho | 492cfab | 2017-01-20 21:18:29 +0000 | [diff] [blame] | 172 | const TType *rvalue, |
| 173 | const TType *ptype1, |
| 174 | const TType *ptype2 = 0, |
| 175 | const TType *ptype3 = 0, |
| 176 | const TType *ptype4 = 0, |
| 177 | const TType *ptype5 = 0); |
Nicolas Capens | 482907e | 2015-02-23 16:56:33 -0500 | [diff] [blame] | 178 | |
Martin Radev | d7c5b0a | 2016-07-27 14:04:43 +0300 | [diff] [blame] | 179 | void insertBuiltInFunctionNoParameters(ESymbolLevel level, |
| 180 | TOperator op, |
| 181 | const TType *rvalue, |
| 182 | const char *name); |
| 183 | |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 184 | void insertBuiltInFunctionNoParametersExt(ESymbolLevel level, |
Olli Etuaho | 2a1e8f9 | 2017-07-14 11:49:36 +0300 | [diff] [blame] | 185 | TExtension ext, |
Jiawei Shao | d27f5c8 | 2017-08-23 09:38:08 +0800 | [diff] [blame] | 186 | TOperator op, |
| 187 | const TType *rvalue, |
| 188 | const char *name); |
| 189 | |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 190 | // These return the TFunction pointer to keep using to refer to this function. |
| 191 | const TFunction *markUserDefinedFunctionHasPrototypeDeclaration( |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame^] | 192 | const ImmutableString &mangledName, |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 193 | bool *hadPrototypeDeclarationOut); |
| 194 | const TFunction *setUserDefinedFunctionParameterNamesFromDefinition(const TFunction *function, |
| 195 | bool *wasDefinedOut); |
Zhenyao Mo | d749096 | 2016-11-09 15:49:51 -0800 | [diff] [blame] | 196 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame^] | 197 | // find() is guaranteed not to retain a reference to the ImmutableString, so an ImmutableString |
| 198 | // with a reference to a short-lived char * is fine to pass here. |
| 199 | const TSymbol *find(const ImmutableString &name, int shaderVersion) const; |
Zhenyao Mo | d749096 | 2016-11-09 15:49:51 -0800 | [diff] [blame] | 200 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame^] | 201 | const TSymbol *findGlobal(const ImmutableString &name) const; |
Zhenyao Mo | d749096 | 2016-11-09 15:49:51 -0800 | [diff] [blame] | 202 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame^] | 203 | const TSymbol *findBuiltIn(const ImmutableString &name, int shaderVersion) const; |
Olli Etuaho | 977ee7e | 2017-07-21 11:38:27 +0300 | [diff] [blame] | 204 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame^] | 205 | const TSymbol *findBuiltIn(const ImmutableString &name, |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 206 | int shaderVersion, |
| 207 | bool includeGLSLBuiltins) const; |
daniel@transgaming.com | 5dd6d09 | 2012-03-20 20:10:28 +0000 | [diff] [blame] | 208 | |
Olli Etuaho | cce8965 | 2017-06-19 16:04:09 +0300 | [diff] [blame] | 209 | void setDefaultPrecision(TBasicType type, TPrecision prec) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 210 | { |
daniel@transgaming.com | a5d7623 | 2010-05-17 09:58:47 +0000 | [diff] [blame] | 211 | int indexOfLastElement = static_cast<int>(precisionStack.size()) - 1; |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 212 | // Uses map operator [], overwrites the current value |
Olli Etuaho | cce8965 | 2017-06-19 16:04:09 +0300 | [diff] [blame] | 213 | (*precisionStack[indexOfLastElement])[type] = prec; |
daniel@transgaming.com | a5d7623 | 2010-05-17 09:58:47 +0000 | [diff] [blame] | 214 | } |
| 215 | |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 216 | // Searches down the precisionStack for a precision qualifier |
| 217 | // for the specified TBasicType |
Zhenyao Mo | e740add | 2014-07-18 17:01:01 -0700 | [diff] [blame] | 218 | TPrecision getDefaultPrecision(TBasicType type) const; |
shannonwoods@chromium.org | 6b70991 | 2013-05-30 00:20:04 +0000 | [diff] [blame] | 219 | |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 220 | // This records invariant varyings declared through |
| 221 | // "invariant varying_name;". |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 222 | void addInvariantVarying(const std::string &originalName); |
| 223 | |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 224 | // If this returns false, the varying could still be invariant |
| 225 | // if it is set as invariant during the varying variable |
| 226 | // declaration - this piece of information is stored in the |
| 227 | // variable's type, not here. |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 228 | bool isVaryingInvariant(const std::string &originalName) const; |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 229 | |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 230 | void setGlobalInvariant(bool invariant); |
Zhenyao Mo | 94ac7b7 | 2014-10-15 18:22:08 -0700 | [diff] [blame] | 231 | |
Olli Etuaho | 2d88e9b | 2017-07-21 16:52:03 +0300 | [diff] [blame] | 232 | const TSymbolUniqueId nextUniqueId() { return TSymbolUniqueId(this); } |
| 233 | |
Martin Radev | da6254b | 2016-12-14 17:00:36 +0200 | [diff] [blame] | 234 | // Checks whether there is a built-in accessible by a shader with the specified version. |
| 235 | bool hasUnmangledBuiltInForShaderVersion(const char *name, int shaderVersion); |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 236 | |
Olli Etuaho | 5d69db1 | 2017-11-24 16:51:15 +0200 | [diff] [blame] | 237 | void markBuiltInInitializationFinished(); |
| 238 | void clearCompilationResults(); |
| 239 | |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 240 | private: |
Olli Etuaho | 2d88e9b | 2017-07-21 16:52:03 +0300 | [diff] [blame] | 241 | friend class TSymbolUniqueId; |
Olli Etuaho | 5d69db1 | 2017-11-24 16:51:15 +0200 | [diff] [blame] | 242 | int nextUniqueIdValue(); |
Olli Etuaho | 2d88e9b | 2017-07-21 16:52:03 +0300 | [diff] [blame] | 243 | |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 244 | class TSymbolTableLevel; |
| 245 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 246 | ESymbolLevel currentLevel() const { return static_cast<ESymbolLevel>(table.size() - 1); } |
daniel@transgaming.com | a5d7623 | 2010-05-17 09:58:47 +0000 | [diff] [blame] | 247 | |
Olli Etuaho | 9d4d7f0 | 2017-12-07 17:11:41 +0100 | [diff] [blame] | 248 | TVariable *insertVariable(ESymbolLevel level, |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame^] | 249 | const ImmutableString &name, |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame] | 250 | const TType *type, |
Olli Etuaho | 9d4d7f0 | 2017-12-07 17:11:41 +0100 | [diff] [blame] | 251 | SymbolType symbolType); |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 252 | |
Olli Etuaho | dd21ecf | 2018-01-10 12:42:09 +0200 | [diff] [blame] | 253 | bool insert(ESymbolLevel level, TSymbol *symbol); |
| 254 | |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame^] | 255 | TFunction *findUserDefinedFunction(const ImmutableString &name) const; |
Olli Etuaho | 0f68463 | 2017-07-13 12:42:15 +0300 | [diff] [blame] | 256 | |
Martin Radev | da6254b | 2016-12-14 17:00:36 +0200 | [diff] [blame] | 257 | // Used to insert unmangled functions to check redeclaration of built-ins in ESSL 3.00 and |
| 258 | // above. |
| 259 | void insertUnmangledBuiltInName(const char *name, ESymbolLevel level); |
| 260 | |
| 261 | bool hasUnmangledBuiltInAtLevel(const char *name, ESymbolLevel level); |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 262 | |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 263 | std::vector<TSymbolTableLevel *> table; |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 264 | typedef TMap<TBasicType, TPrecision> PrecisionStackLevel; |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 265 | std::vector<PrecisionStackLevel *> precisionStack; |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 266 | |
Olli Etuaho | a5e693a | 2017-07-13 16:07:26 +0300 | [diff] [blame] | 267 | int mUniqueIdCounter; |
Olli Etuaho | 2d88e9b | 2017-07-21 16:52:03 +0300 | [diff] [blame] | 268 | |
Olli Etuaho | 5d69db1 | 2017-11-24 16:51:15 +0200 | [diff] [blame] | 269 | // -1 before built-in init has finished, one past the last built-in id afterwards. |
| 270 | // TODO(oetuaho): Make this a compile-time constant once the symbol table is initialized at |
| 271 | // compile time. http://anglebug.com/1432 |
| 272 | int mUserDefinedUniqueIdsStart; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 273 | }; |
| 274 | |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame] | 275 | template <TPrecision precision> |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame^] | 276 | bool TSymbolTable::insertConstInt(ESymbolLevel level, const ImmutableString &name, int value) |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame] | 277 | { |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame^] | 278 | TVariable *constant = new TVariable( |
| 279 | this, name, StaticType::Get<EbtInt, precision, EvqConst, 1, 1>(), SymbolType::BuiltIn); |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame] | 280 | TConstantUnion *unionArray = new TConstantUnion[1]; |
| 281 | unionArray[0].setIConst(value); |
| 282 | constant->shareConstPointer(unionArray); |
| 283 | return insert(level, constant); |
| 284 | } |
| 285 | |
| 286 | template <TPrecision precision> |
| 287 | bool TSymbolTable::insertConstIntExt(ESymbolLevel level, |
| 288 | TExtension ext, |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame^] | 289 | const ImmutableString &name, |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame] | 290 | int value) |
| 291 | { |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame^] | 292 | TVariable *constant = new TVariable( |
| 293 | this, name, StaticType::Get<EbtInt, precision, EvqConst, 1, 1>(), SymbolType::BuiltIn, ext); |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame] | 294 | TConstantUnion *unionArray = new TConstantUnion[1]; |
| 295 | unionArray[0].setIConst(value); |
| 296 | constant->shareConstPointer(unionArray); |
| 297 | return insert(level, constant); |
| 298 | } |
| 299 | |
| 300 | template <TPrecision precision> |
| 301 | bool TSymbolTable::insertConstIvec3(ESymbolLevel level, |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame^] | 302 | const ImmutableString &name, |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame] | 303 | const std::array<int, 3> &values) |
| 304 | { |
Olli Etuaho | fbb1c79 | 2018-01-19 16:26:59 +0200 | [diff] [blame^] | 305 | TVariable *constantIvec3 = new TVariable( |
| 306 | this, name, StaticType::Get<EbtInt, precision, EvqConst, 3, 1>(), SymbolType::BuiltIn); |
Olli Etuaho | b60d30f | 2018-01-16 12:31:06 +0200 | [diff] [blame] | 307 | |
| 308 | TConstantUnion *unionArray = new TConstantUnion[3]; |
| 309 | for (size_t index = 0u; index < 3u; ++index) |
| 310 | { |
| 311 | unionArray[index].setIConst(values[index]); |
| 312 | } |
| 313 | constantIvec3->shareConstPointer(unionArray); |
| 314 | |
| 315 | return insert(level, constantIvec3); |
| 316 | } |
| 317 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 318 | } // namespace sh |
| 319 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 320 | #endif // COMPILER_TRANSLATOR_SYMBOLTABLE_H_ |