blob: f66863ef3de4d73f74b5092f191a9807bf8d09b5 [file] [log] [blame]
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00001//
Nicolas Capens1fbc2872014-01-03 14:12:09 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Geoff Lang0a73dd82014-11-19 16:18:08 -05007#ifndef COMPILER_TRANSLATOR_SYMBOLTABLE_H_
8#define COMPILER_TRANSLATOR_SYMBOLTABLE_H_
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +00009
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 Madilld7b1ab52016-12-12 14:42:19 -050021// * Pushing and popping of scope, so symbol table will really be a stack
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000022// 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 Radeve93d24e2016-07-28 12:06:05 +030033#include <array>
alokp@chromium.org4e4facd2010-06-02 15:21:22 +000034#include <assert.h>
Zhenyao Mo94ac7b72014-10-15 18:22:08 -070035#include <set>
alokp@chromium.orge4249f02010-07-26 18:13:52 +000036
Jamie Madill703cdd62013-07-08 15:07:30 -040037#include "common/angleutils.h"
Olli Etuaho2a1e8f92017-07-14 11:49:36 +030038#include "compiler/translator/ExtensionBehavior.h"
Geoff Lang17732822013-08-29 13:46:49 -040039#include "compiler/translator/InfoSink.h"
Jamie Madillb1a85f42014-08-19 15:23:24 -040040#include "compiler/translator/IntermNode.h"
Olli Etuahob60d30f2018-01-16 12:31:06 +020041#include "compiler/translator/StaticType.h"
Olli Etuahod4529f32017-12-12 13:06:40 +020042#include "compiler/translator/Symbol.h"
alokp@chromium.org43884872010-03-30 00:08:52 +000043
Jamie Madill45bcc782016-11-07 13:58:48 -050044namespace sh
45{
46
Zhenyao Mo9eedea02014-05-12 16:02:35 -070047class TSymbolTableLevel
48{
49 public:
Kai Ninomiyad4556df2017-09-27 16:45:22 -070050 typedef TUnorderedMap<TString, TSymbol *> tLevel;
alokp@chromium.org43884872010-03-30 00:08:52 +000051 typedef tLevel::const_iterator const_iterator;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000052 typedef const tLevel::value_type tLevelPair;
53 typedef std::pair<tLevel::iterator, bool> tInsertResult;
54
Jamie Madilld7b1ab52016-12-12 14:42:19 -050055 TSymbolTableLevel() : mGlobalInvariant(false) {}
alokp@chromium.org43884872010-03-30 00:08:52 +000056 ~TSymbolTableLevel();
57
Nicolas Capensadfffe42014-06-17 02:13:36 -040058 bool insert(TSymbol *symbol);
Nicolas Capensbd10cf52013-06-20 09:51:51 -040059
Olli Etuahob2983c92015-03-18 14:02:46 +020060 // Insert a function using its unmangled name as the key.
61 bool insertUnmangled(TFunction *function);
62
Jamie Madillbfa91f42014-06-05 15:45:18 -040063 TSymbol *find(const TString &name) const;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000064
Jamie Madilld7b1ab52016-12-12 14:42:19 -050065 void addInvariantVarying(const std::string &name) { mInvariantVaryings.insert(name); }
Qiankun Miaof69682b2016-08-16 14:50:42 +080066
67 bool isVaryingInvariant(const std::string &name)
68 {
69 return (mGlobalInvariant || mInvariantVaryings.count(name) > 0);
70 }
71
72 void setGlobalInvariant(bool invariant) { mGlobalInvariant = invariant; }
73
Olli Etuaho342b83d2018-01-10 13:24:01 +020074 void insertUnmangledBuiltInName(const char *name);
75 bool hasUnmangledBuiltIn(const char *name) const;
Martin Radevda6254b2016-12-14 17:00:36 +020076
Zhenyao Mo9eedea02014-05-12 16:02:35 -070077 protected:
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000078 tLevel level;
Qiankun Miaof69682b2016-08-16 14:50:42 +080079 std::set<std::string> mInvariantVaryings;
80 bool mGlobalInvariant;
Martin Radevda6254b2016-12-14 17:00:36 +020081
82 private:
Olli Etuaho342b83d2018-01-10 13:24:01 +020083 struct CharArrayComparator
84 {
85 bool operator()(const char *a, const char *b) const { return strcmp(a, b) < 0; }
86 };
87 std::set<const char *, CharArrayComparator> mUnmangledBuiltInNames;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +000088};
89
Gus Fernandez964df492014-10-13 11:54:39 -070090// Define ESymbolLevel as int rather than an enum since level can go
91// above GLOBAL_LEVEL and cause atBuiltInLevel() to fail if the
92// compiler optimizes the >= of the last element to ==.
93typedef int ESymbolLevel;
Jamie Madilld7b1ab52016-12-12 14:42:19 -050094const int COMMON_BUILTINS = 0;
95const int ESSL1_BUILTINS = 1;
96const int ESSL3_BUILTINS = 2;
Martin Radeve93d24e2016-07-28 12:06:05 +030097const int ESSL3_1_BUILTINS = 3;
Olli Etuaho977ee7e2017-07-21 11:38:27 +030098// GLSL_BUILTINS are desktop GLSL builtins that don't exist in ESSL but are used to implement
99// features in ANGLE's GLSL backend. They're not visible to the parser.
100const int GLSL_BUILTINS = 4;
101const int LAST_BUILTIN_LEVEL = GLSL_BUILTINS;
102const int GLOBAL_LEVEL = 5;
shannonwoods@chromium.org6e10a0e2013-05-30 00:02:13 +0000103
Jamie Madillf0d10f82015-03-31 12:56:52 -0400104class TSymbolTable : angle::NonCopyable
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700105{
106 public:
Olli Etuaho195be942017-12-04 23:40:14 +0200107 TSymbolTable() : mUniqueIdCounter(0), mUserDefinedUniqueIdsStart(-1)
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000108 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000109 // The symbol table cannot be used until push() is called, but
110 // the lack of an initial call to push() can be used to detect
111 // that the symbol table has not been preloaded with built-ins.
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000112 }
113
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400114 ~TSymbolTable();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000115
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000116 // When the symbol table is initialized with the built-ins, there should
117 // 'push' calls, so that built-ins are at level 0 and the shader
118 // globals are at level 1.
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500119 bool isEmpty() const { return table.empty(); }
120 bool atBuiltInLevel() const { return currentLevel() <= LAST_BUILTIN_LEVEL; }
121 bool atGlobalLevel() const { return currentLevel() == GLOBAL_LEVEL; }
alokp@chromium.org43884872010-03-30 00:08:52 +0000122 void push()
alokp@chromium.orge4249f02010-07-26 18:13:52 +0000123 {
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000124 table.push_back(new TSymbolTableLevel);
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400125 precisionStack.push_back(new PrecisionStackLevel);
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000126 }
127
alokp@chromium.org43884872010-03-30 00:08:52 +0000128 void pop()
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400129 {
130 delete table.back();
131 table.pop_back();
132
133 delete precisionStack.back();
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000134 precisionStack.pop_back();
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000135 }
136
Olli Etuaho0f684632017-07-13 12:42:15 +0300137 // The declare* entry points are used when parsing and declare symbols at the current scope.
Olli Etuaho035419f2017-11-28 14:27:15 +0200138 // They return the created symbol / true in case the declaration was successful, and nullptr /
139 // false if the declaration failed due to redefinition.
Olli Etuaho195be942017-12-04 23:40:14 +0200140 bool declareVariable(TVariable *variable);
Olli Etuaho035419f2017-11-28 14:27:15 +0200141 bool declareStructType(TStructure *str);
Olli Etuaho378c3a52017-12-04 11:32:13 +0200142 bool declareInterfaceBlock(TInterfaceBlock *interfaceBlock);
shannonwoods@chromium.org1c848092013-05-30 00:02:34 +0000143
Olli Etuaho0f684632017-07-13 12:42:15 +0300144 // The insert* entry points are used when initializing the symbol table with built-ins.
Olli Etuaho035419f2017-11-28 14:27:15 +0200145 // They return the created symbol / true in case the declaration was successful, and nullptr /
146 // false if the declaration failed due to redefinition.
Olli Etuahob60d30f2018-01-16 12:31:06 +0200147 TVariable *insertVariable(ESymbolLevel level, const char *name, const TType *type);
Olli Etuaho0f684632017-07-13 12:42:15 +0300148 TVariable *insertVariableExt(ESymbolLevel level,
Olli Etuaho2a1e8f92017-07-14 11:49:36 +0300149 TExtension ext,
Olli Etuaho0f684632017-07-13 12:42:15 +0300150 const char *name,
Olli Etuahob60d30f2018-01-16 12:31:06 +0200151 const TType *type);
Olli Etuaho195be942017-12-04 23:40:14 +0200152 bool insertVariable(ESymbolLevel level, TVariable *variable);
Olli Etuaho035419f2017-11-28 14:27:15 +0200153 bool insertStructType(ESymbolLevel level, TStructure *str);
Olli Etuaho378c3a52017-12-04 11:32:13 +0200154 bool insertInterfaceBlock(ESymbolLevel level, TInterfaceBlock *interfaceBlock);
Nicolas Capensc9d9b302015-02-20 23:02:15 -0500155
Olli Etuahob60d30f2018-01-16 12:31:06 +0200156 template <TPrecision precision>
157 bool insertConstInt(ESymbolLevel level, const char *name, int value);
Nicolas Capens49a88872013-06-20 09:54:03 -0400158
Olli Etuahob60d30f2018-01-16 12:31:06 +0200159 template <TPrecision precision>
160 bool insertConstIntExt(ESymbolLevel level, TExtension ext, const char *name, int value);
Kimmo Kinnunenb18609b2015-07-16 14:13:11 +0300161
Olli Etuahob60d30f2018-01-16 12:31:06 +0200162 template <TPrecision precision>
163 bool insertConstIvec3(ESymbolLevel level, const char *name, const std::array<int, 3> &values);
Martin Radeve93d24e2016-07-28 12:06:05 +0300164
Olli Etuaho342b83d2018-01-10 13:24:01 +0200165 // Note that for inserted built-in functions the const char *name needs to remain valid for the
166 // lifetime of the SymbolTable. SymbolTable does not allocate a copy of it.
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500167 void insertBuiltIn(ESymbolLevel level,
168 TOperator op,
Olli Etuaho2a1e8f92017-07-14 11:49:36 +0300169 TExtension ext,
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500170 const TType *rvalue,
171 const char *name,
172 const TType *ptype1,
173 const TType *ptype2 = 0,
174 const TType *ptype3 = 0,
175 const TType *ptype4 = 0,
176 const TType *ptype5 = 0);
Nicolas Capens759b9942014-02-14 17:57:14 -0500177
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500178 void insertBuiltIn(ESymbolLevel level,
179 const TType *rvalue,
180 const char *name,
181 const TType *ptype1,
182 const TType *ptype2 = 0,
183 const TType *ptype3 = 0,
184 const TType *ptype4 = 0,
185 const TType *ptype5 = 0)
Nicolas Capens482907e2015-02-23 16:56:33 -0500186 {
Martin Radevda6254b2016-12-14 17:00:36 +0200187 insertUnmangledBuiltInName(name, level);
Olli Etuaho2a1e8f92017-07-14 11:49:36 +0300188 insertBuiltIn(level, EOpNull, TExtension::UNDEFINED, rvalue, name, ptype1, ptype2, ptype3,
189 ptype4, ptype5);
Nicolas Capensc9d9b302015-02-20 23:02:15 -0500190 }
191
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500192 void insertBuiltIn(ESymbolLevel level,
Olli Etuaho2a1e8f92017-07-14 11:49:36 +0300193 TExtension ext,
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500194 const TType *rvalue,
195 const char *name,
196 const TType *ptype1,
197 const TType *ptype2 = 0,
198 const TType *ptype3 = 0,
199 const TType *ptype4 = 0,
200 const TType *ptype5 = 0)
Nicolas Capensc9d9b302015-02-20 23:02:15 -0500201 {
Martin Radevda6254b2016-12-14 17:00:36 +0200202 insertUnmangledBuiltInName(name, level);
Nicolas Capensc9d9b302015-02-20 23:02:15 -0500203 insertBuiltIn(level, EOpNull, ext, rvalue, name, ptype1, ptype2, ptype3, ptype4, ptype5);
204 }
205
Olli Etuaho492cfab2017-01-20 21:18:29 +0000206 void insertBuiltInOp(ESymbolLevel level,
207 TOperator op,
208 const TType *rvalue,
209 const TType *ptype1,
210 const TType *ptype2 = 0,
211 const TType *ptype3 = 0,
212 const TType *ptype4 = 0,
213 const TType *ptype5 = 0);
214
215 void insertBuiltInOp(ESymbolLevel level,
216 TOperator op,
Olli Etuaho2a1e8f92017-07-14 11:49:36 +0300217 TExtension ext,
Olli Etuaho492cfab2017-01-20 21:18:29 +0000218 const TType *rvalue,
219 const TType *ptype1,
220 const TType *ptype2 = 0,
221 const TType *ptype3 = 0,
222 const TType *ptype4 = 0,
223 const TType *ptype5 = 0);
Nicolas Capens482907e2015-02-23 16:56:33 -0500224
Martin Radevd7c5b0a2016-07-27 14:04:43 +0300225 void insertBuiltInFunctionNoParameters(ESymbolLevel level,
226 TOperator op,
227 const TType *rvalue,
228 const char *name);
229
Jiawei Shaod27f5c82017-08-23 09:38:08 +0800230 void insertBuiltInFunctionNoParametersExt(ESymbolLevel level,
Olli Etuaho2a1e8f92017-07-14 11:49:36 +0300231 TExtension ext,
Jiawei Shaod27f5c82017-08-23 09:38:08 +0800232 TOperator op,
233 const TType *rvalue,
234 const char *name);
235
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500236 TSymbol *find(const TString &name,
237 int shaderVersion,
Yunchao He4f285442017-04-21 12:15:49 +0800238 bool *builtIn = nullptr,
239 bool *sameScope = nullptr) const;
Zhenyao Mod7490962016-11-09 15:49:51 -0800240
241 TSymbol *findGlobal(const TString &name) const;
242
Zhenyao Moe740add2014-07-18 17:01:01 -0700243 TSymbol *findBuiltIn(const TString &name, int shaderVersion) const;
Zhenyao Mod7490962016-11-09 15:49:51 -0800244
Olli Etuaho977ee7e2017-07-21 11:38:27 +0300245 TSymbol *findBuiltIn(const TString &name, int shaderVersion, bool includeGLSLBuiltins) const;
246
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700247 TSymbolTableLevel *getOuterLevel()
248 {
shannonwoods@chromium.org6e10a0e2013-05-30 00:02:13 +0000249 assert(currentLevel() >= 1);
daniel@transgaming.com5dd6d092012-03-20 20:10:28 +0000250 return table[currentLevel() - 1];
251 }
252
Olli Etuahocce89652017-06-19 16:04:09 +0300253 void setDefaultPrecision(TBasicType type, TPrecision prec)
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700254 {
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000255 int indexOfLastElement = static_cast<int>(precisionStack.size()) - 1;
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700256 // Uses map operator [], overwrites the current value
Olli Etuahocce89652017-06-19 16:04:09 +0300257 (*precisionStack[indexOfLastElement])[type] = prec;
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000258 }
259
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700260 // Searches down the precisionStack for a precision qualifier
261 // for the specified TBasicType
Zhenyao Moe740add2014-07-18 17:01:01 -0700262 TPrecision getDefaultPrecision(TBasicType type) const;
shannonwoods@chromium.org6b709912013-05-30 00:20:04 +0000263
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700264 // This records invariant varyings declared through
265 // "invariant varying_name;".
Jamie Madill2c433252014-12-03 12:36:54 -0500266 void addInvariantVarying(const std::string &originalName)
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700267 {
Qiankun Miaof69682b2016-08-16 14:50:42 +0800268 ASSERT(atGlobalLevel());
269 table[currentLevel()]->addInvariantVarying(originalName);
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700270 }
271 // If this returns false, the varying could still be invariant
272 // if it is set as invariant during the varying variable
273 // declaration - this piece of information is stored in the
274 // variable's type, not here.
Jamie Madill2c433252014-12-03 12:36:54 -0500275 bool isVaryingInvariant(const std::string &originalName) const
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700276 {
Qiankun Miaof69682b2016-08-16 14:50:42 +0800277 ASSERT(atGlobalLevel());
278 return table[currentLevel()]->isVaryingInvariant(originalName);
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700279 }
280
Qiankun Miaof69682b2016-08-16 14:50:42 +0800281 void setGlobalInvariant(bool invariant)
282 {
283 ASSERT(atGlobalLevel());
284 table[currentLevel()]->setGlobalInvariant(invariant);
285 }
Zhenyao Mo94ac7b72014-10-15 18:22:08 -0700286
Olli Etuaho2d88e9b2017-07-21 16:52:03 +0300287 const TSymbolUniqueId nextUniqueId() { return TSymbolUniqueId(this); }
288
Martin Radevda6254b2016-12-14 17:00:36 +0200289 // Checks whether there is a built-in accessible by a shader with the specified version.
290 bool hasUnmangledBuiltInForShaderVersion(const char *name, int shaderVersion);
Olli Etuahoc4a96d62015-07-23 17:37:39 +0530291
Olli Etuaho5d69db12017-11-24 16:51:15 +0200292 void markBuiltInInitializationFinished();
293 void clearCompilationResults();
294
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700295 private:
Olli Etuaho2d88e9b2017-07-21 16:52:03 +0300296 friend class TSymbolUniqueId;
Olli Etuaho5d69db12017-11-24 16:51:15 +0200297 int nextUniqueIdValue();
Olli Etuaho2d88e9b2017-07-21 16:52:03 +0300298
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500299 ESymbolLevel currentLevel() const { return static_cast<ESymbolLevel>(table.size() - 1); }
daniel@transgaming.coma5d76232010-05-17 09:58:47 +0000300
Olli Etuaho9d4d7f02017-12-07 17:11:41 +0100301 TVariable *insertVariable(ESymbolLevel level,
302 const TString *name,
Olli Etuahob60d30f2018-01-16 12:31:06 +0200303 const TType *type,
Olli Etuaho9d4d7f02017-12-07 17:11:41 +0100304 SymbolType symbolType);
Olli Etuaho0f684632017-07-13 12:42:15 +0300305
Olli Etuaho5d69db12017-11-24 16:51:15 +0200306 bool insert(ESymbolLevel level, TSymbol *symbol)
Olli Etuaho0f684632017-07-13 12:42:15 +0300307 {
Olli Etuaho5d69db12017-11-24 16:51:15 +0200308 ASSERT(level > LAST_BUILTIN_LEVEL || mUserDefinedUniqueIdsStart == -1);
Olli Etuaho0f684632017-07-13 12:42:15 +0300309 return table[level]->insert(symbol);
310 }
311
Martin Radevda6254b2016-12-14 17:00:36 +0200312 // Used to insert unmangled functions to check redeclaration of built-ins in ESSL 3.00 and
313 // above.
314 void insertUnmangledBuiltInName(const char *name, ESymbolLevel level);
315
316 bool hasUnmangledBuiltInAtLevel(const char *name, ESymbolLevel level);
Olli Etuahoc4a96d62015-07-23 17:37:39 +0530317
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700318 std::vector<TSymbolTableLevel *> table;
Alok Priyadarshibc3f1ac2013-09-23 14:57:02 -0400319 typedef TMap<TBasicType, TPrecision> PrecisionStackLevel;
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500320 std::vector<PrecisionStackLevel *> precisionStack;
Jamie Madillbfa91f42014-06-05 15:45:18 -0400321
Olli Etuahoa5e693a2017-07-13 16:07:26 +0300322 int mUniqueIdCounter;
Olli Etuaho2d88e9b2017-07-21 16:52:03 +0300323
Olli Etuaho5d69db12017-11-24 16:51:15 +0200324 // -1 before built-in init has finished, one past the last built-in id afterwards.
325 // TODO(oetuaho): Make this a compile-time constant once the symbol table is initialized at
326 // compile time. http://anglebug.com/1432
327 int mUserDefinedUniqueIdsStart;
daniel@transgaming.com4f39fd92010-03-08 20:26:45 +0000328};
329
Olli Etuahob60d30f2018-01-16 12:31:06 +0200330template <TPrecision precision>
331bool TSymbolTable::insertConstInt(ESymbolLevel level, const char *name, int value)
332{
333 TVariable *constant =
334 new TVariable(this, NewPoolTString(name),
335 StaticType::Get<EbtInt, precision, EvqConst, 1, 1>(), SymbolType::BuiltIn);
336 TConstantUnion *unionArray = new TConstantUnion[1];
337 unionArray[0].setIConst(value);
338 constant->shareConstPointer(unionArray);
339 return insert(level, constant);
340}
341
342template <TPrecision precision>
343bool TSymbolTable::insertConstIntExt(ESymbolLevel level,
344 TExtension ext,
345 const char *name,
346 int value)
347{
348 TVariable *constant = new TVariable(this, NewPoolTString(name),
349 StaticType::Get<EbtInt, precision, EvqConst, 1, 1>(),
350 SymbolType::BuiltIn, ext);
351 TConstantUnion *unionArray = new TConstantUnion[1];
352 unionArray[0].setIConst(value);
353 constant->shareConstPointer(unionArray);
354 return insert(level, constant);
355}
356
357template <TPrecision precision>
358bool TSymbolTable::insertConstIvec3(ESymbolLevel level,
359 const char *name,
360 const std::array<int, 3> &values)
361{
362 TVariable *constantIvec3 =
363 new TVariable(this, NewPoolTString(name),
364 StaticType::Get<EbtInt, precision, EvqConst, 3, 1>(), SymbolType::BuiltIn);
365
366 TConstantUnion *unionArray = new TConstantUnion[3];
367 for (size_t index = 0u; index < 3u; ++index)
368 {
369 unionArray[index].setIConst(values[index]);
370 }
371 constantIvec3->shareConstPointer(unionArray);
372
373 return insert(level, constantIvec3);
374}
375
Jamie Madill45bcc782016-11-07 13:58:48 -0500376} // namespace sh
377
Jamie Madilld7b1ab52016-12-12 14:42:19 -0500378#endif // COMPILER_TRANSLATOR_SYMBOLTABLE_H_