daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 2 | // Copyright (c) 2002-2013 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 | |
| 7 | // |
| 8 | // Symbol table for parsing. Most functionaliy and main ideas |
| 9 | // are documented in the header file. |
| 10 | // |
| 11 | |
apatrick@chromium.org | e057c5d | 2012-01-26 19:18:24 +0000 | [diff] [blame] | 12 | #if defined(_MSC_VER) |
| 13 | #pragma warning(disable: 4718) |
| 14 | #endif |
| 15 | |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 16 | #include "compiler/translator/SymbolTable.h" |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 17 | #include "compiler/translator/Cache.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 18 | |
apatrick@chromium.org | 8187fa8 | 2010-06-15 22:09:28 +0000 | [diff] [blame] | 19 | #include <stdio.h> |
kbr@chromium.org | 476541f | 2011-10-27 21:14:51 +0000 | [diff] [blame] | 20 | #include <algorithm> |
| 21 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 22 | namespace sh |
| 23 | { |
| 24 | |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 25 | int TSymbolTable::uniqueIdCounter = 0; |
Nicolas Capens | bd10cf5 | 2013-06-20 09:51:51 -0400 | [diff] [blame] | 26 | |
Olli Etuaho | 476197f | 2016-10-11 13:59:08 +0100 | [diff] [blame] | 27 | TSymbol::TSymbol(const TString *n) : uniqueId(TSymbolTable::nextUniqueId()), name(n) |
| 28 | { |
| 29 | } |
| 30 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 31 | // |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 32 | // Functions have buried pointers to delete. |
| 33 | // |
| 34 | TFunction::~TFunction() |
| 35 | { |
Olli Etuaho | 476197f | 2016-10-11 13:59:08 +0100 | [diff] [blame] | 36 | clearParameters(); |
| 37 | } |
| 38 | |
| 39 | void TFunction::clearParameters() |
| 40 | { |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 41 | for (TParamList::iterator i = parameters.begin(); i != parameters.end(); ++i) |
| 42 | delete (*i).type; |
Olli Etuaho | 476197f | 2016-10-11 13:59:08 +0100 | [diff] [blame] | 43 | parameters.clear(); |
| 44 | mangledName = nullptr; |
| 45 | } |
| 46 | |
| 47 | void TFunction::swapParameters(const TFunction ¶metersSource) |
| 48 | { |
| 49 | clearParameters(); |
| 50 | for (auto parameter : parametersSource.parameters) |
| 51 | { |
| 52 | addParameter(parameter); |
| 53 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Dmitry Skiba | 5883220 | 2015-07-06 16:11:13 -0700 | [diff] [blame] | 56 | const TString *TFunction::buildMangledName() const |
| 57 | { |
Cooper Partin | 149e6e6 | 2015-08-07 16:18:18 -0700 | [diff] [blame] | 58 | std::string newName = mangleName(getName()).c_str(); |
Dmitry Skiba | 5883220 | 2015-07-06 16:11:13 -0700 | [diff] [blame] | 59 | |
| 60 | for (const auto &p : parameters) |
| 61 | { |
Cooper Partin | 149e6e6 | 2015-08-07 16:18:18 -0700 | [diff] [blame] | 62 | newName += p.type->getMangledName().c_str(); |
Dmitry Skiba | 5883220 | 2015-07-06 16:11:13 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Cooper Partin | 149e6e6 | 2015-08-07 16:18:18 -0700 | [diff] [blame] | 65 | return NewPoolTString(newName.c_str()); |
Dmitry Skiba | 5883220 | 2015-07-06 16:11:13 -0700 | [diff] [blame] | 66 | } |
| 67 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 68 | // |
| 69 | // Symbol table levels are a map of pointers to symbols that have to be deleted. |
| 70 | // |
| 71 | TSymbolTableLevel::~TSymbolTableLevel() |
| 72 | { |
daniel@transgaming.com | 0578f81 | 2010-05-17 09:58:39 +0000 | [diff] [blame] | 73 | for (tLevel::iterator it = level.begin(); it != level.end(); ++it) |
| 74 | delete (*it).second; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Nicolas Capens | adfffe4 | 2014-06-17 02:13:36 -0400 | [diff] [blame] | 77 | bool TSymbolTableLevel::insert(TSymbol *symbol) |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 78 | { |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 79 | // returning true means symbol was added to the table |
Nicolas Capens | adfffe4 | 2014-06-17 02:13:36 -0400 | [diff] [blame] | 80 | tInsertResult result = level.insert(tLevelPair(symbol->getMangledName(), symbol)); |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 81 | |
| 82 | return result.second; |
| 83 | } |
| 84 | |
Olli Etuaho | b2983c9 | 2015-03-18 14:02:46 +0200 | [diff] [blame] | 85 | bool TSymbolTableLevel::insertUnmangled(TFunction *function) |
| 86 | { |
Olli Etuaho | b2983c9 | 2015-03-18 14:02:46 +0200 | [diff] [blame] | 87 | // returning true means symbol was added to the table |
| 88 | tInsertResult result = level.insert(tLevelPair(function->getName(), function)); |
| 89 | |
| 90 | return result.second; |
| 91 | } |
| 92 | |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 93 | TSymbol *TSymbolTableLevel::find(const TString &name) const |
| 94 | { |
| 95 | tLevel::const_iterator it = level.find(name); |
| 96 | if (it == level.end()) |
| 97 | return 0; |
| 98 | else |
| 99 | return (*it).second; |
| 100 | } |
| 101 | |
Zhenyao Mo | e740add | 2014-07-18 17:01:01 -0700 | [diff] [blame] | 102 | TSymbol *TSymbolTable::find(const TString &name, int shaderVersion, |
| 103 | bool *builtIn, bool *sameScope) const |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 104 | { |
| 105 | int level = currentLevel(); |
| 106 | TSymbol *symbol; |
| 107 | |
| 108 | do |
| 109 | { |
Martin Radev | e93d24e | 2016-07-28 12:06:05 +0300 | [diff] [blame] | 110 | if (level == ESSL3_1_BUILTINS && shaderVersion != 310) |
| 111 | level--; |
| 112 | if (level == ESSL3_BUILTINS && shaderVersion < 300) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 113 | level--; |
| 114 | if (level == ESSL1_BUILTINS && shaderVersion != 100) |
| 115 | level--; |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 116 | |
| 117 | symbol = table[level]->find(name); |
| 118 | } |
| 119 | while (symbol == 0 && --level >= 0); |
| 120 | |
| 121 | if (builtIn) |
| 122 | *builtIn = (level <= LAST_BUILTIN_LEVEL); |
| 123 | if (sameScope) |
| 124 | *sameScope = (level == currentLevel()); |
| 125 | |
| 126 | return symbol; |
| 127 | } |
| 128 | |
Zhenyao Mo | d749096 | 2016-11-09 15:49:51 -0800 | [diff] [blame] | 129 | TSymbol *TSymbolTable::findGlobal(const TString &name) const |
| 130 | { |
| 131 | ASSERT(table.size() > GLOBAL_LEVEL); |
| 132 | return table[GLOBAL_LEVEL]->find(name); |
| 133 | } |
| 134 | |
Zhenyao Mo | e740add | 2014-07-18 17:01:01 -0700 | [diff] [blame] | 135 | TSymbol *TSymbolTable::findBuiltIn( |
| 136 | const TString &name, int shaderVersion) const |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 137 | { |
| 138 | for (int level = LAST_BUILTIN_LEVEL; level >= 0; level--) |
| 139 | { |
Martin Radev | e93d24e | 2016-07-28 12:06:05 +0300 | [diff] [blame] | 140 | if (level == ESSL3_1_BUILTINS && shaderVersion != 310) |
| 141 | level--; |
| 142 | if (level == ESSL3_BUILTINS && shaderVersion < 300) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 143 | level--; |
| 144 | if (level == ESSL1_BUILTINS && shaderVersion != 100) |
| 145 | level--; |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 146 | |
| 147 | TSymbol *symbol = table[level]->find(name); |
| 148 | |
| 149 | if (symbol) |
| 150 | return symbol; |
| 151 | } |
| 152 | |
| 153 | return 0; |
| 154 | } |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 155 | |
| 156 | TSymbolTable::~TSymbolTable() |
| 157 | { |
| 158 | while (table.size() > 0) |
| 159 | pop(); |
| 160 | } |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 161 | |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 162 | bool IsGenType(const TType *type) |
| 163 | { |
| 164 | if (type) |
| 165 | { |
| 166 | TBasicType basicType = type->getBasicType(); |
| 167 | return basicType == EbtGenType || basicType == EbtGenIType || basicType == EbtGenUType || basicType == EbtGenBType; |
| 168 | } |
| 169 | |
| 170 | return false; |
| 171 | } |
| 172 | |
| 173 | bool IsVecType(const TType *type) |
| 174 | { |
| 175 | if (type) |
| 176 | { |
| 177 | TBasicType basicType = type->getBasicType(); |
| 178 | return basicType == EbtVec || basicType == EbtIVec || basicType == EbtUVec || basicType == EbtBVec; |
| 179 | } |
| 180 | |
| 181 | return false; |
| 182 | } |
| 183 | |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 184 | const TType *SpecificType(const TType *type, int size) |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 185 | { |
| 186 | ASSERT(size >= 1 && size <= 4); |
| 187 | |
| 188 | if (!type) |
| 189 | { |
| 190 | return nullptr; |
| 191 | } |
| 192 | |
| 193 | ASSERT(!IsVecType(type)); |
| 194 | |
| 195 | switch(type->getBasicType()) |
| 196 | { |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 197 | case EbtGenType: return TCache::getType(EbtFloat, static_cast<unsigned char>(size)); |
| 198 | case EbtGenIType: return TCache::getType(EbtInt, static_cast<unsigned char>(size)); |
| 199 | case EbtGenUType: return TCache::getType(EbtUInt, static_cast<unsigned char>(size)); |
| 200 | case EbtGenBType: return TCache::getType(EbtBool, static_cast<unsigned char>(size)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 201 | default: return type; |
| 202 | } |
| 203 | } |
| 204 | |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 205 | const TType *VectorType(const TType *type, int size) |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 206 | { |
| 207 | ASSERT(size >= 2 && size <= 4); |
| 208 | |
| 209 | if (!type) |
| 210 | { |
| 211 | return nullptr; |
| 212 | } |
| 213 | |
| 214 | ASSERT(!IsGenType(type)); |
| 215 | |
| 216 | switch(type->getBasicType()) |
| 217 | { |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 218 | case EbtVec: return TCache::getType(EbtFloat, static_cast<unsigned char>(size)); |
| 219 | case EbtIVec: return TCache::getType(EbtInt, static_cast<unsigned char>(size)); |
| 220 | case EbtUVec: return TCache::getType(EbtUInt, static_cast<unsigned char>(size)); |
| 221 | case EbtBVec: return TCache::getType(EbtBool, static_cast<unsigned char>(size)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 222 | default: return type; |
| 223 | } |
| 224 | } |
| 225 | |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 226 | void TSymbolTable::insertBuiltIn(ESymbolLevel level, TOperator op, const char *ext, const TType *rvalue, const char *name, |
| 227 | const TType *ptype1, const TType *ptype2, const TType *ptype3, const TType *ptype4, const TType *ptype5) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 228 | { |
| 229 | if (ptype1->getBasicType() == EbtGSampler2D) |
| 230 | { |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 231 | insertUnmangledBuiltIn(name); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 232 | bool gvec4 = (rvalue->getBasicType() == EbtGVec4); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 233 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSampler2D), ptype2, ptype3, ptype4, ptype5); |
| 234 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISampler2D), ptype2, ptype3, ptype4, ptype5); |
| 235 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSampler2D), ptype2, ptype3, ptype4, ptype5); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 236 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 237 | else if (ptype1->getBasicType() == EbtGSampler3D) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 238 | { |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 239 | insertUnmangledBuiltIn(name); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 240 | bool gvec4 = (rvalue->getBasicType() == EbtGVec4); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 241 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSampler3D), ptype2, ptype3, ptype4, ptype5); |
| 242 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISampler3D), ptype2, ptype3, ptype4, ptype5); |
| 243 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSampler3D), ptype2, ptype3, ptype4, ptype5); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 244 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 245 | else if (ptype1->getBasicType() == EbtGSamplerCube) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 246 | { |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 247 | insertUnmangledBuiltIn(name); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 248 | bool gvec4 = (rvalue->getBasicType() == EbtGVec4); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 249 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSamplerCube), ptype2, ptype3, ptype4, ptype5); |
| 250 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISamplerCube), ptype2, ptype3, ptype4, ptype5); |
| 251 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSamplerCube), ptype2, ptype3, ptype4, ptype5); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 252 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 253 | else if (ptype1->getBasicType() == EbtGSampler2DArray) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 254 | { |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 255 | insertUnmangledBuiltIn(name); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 256 | bool gvec4 = (rvalue->getBasicType() == EbtGVec4); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 257 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSampler2DArray), ptype2, ptype3, ptype4, ptype5); |
| 258 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISampler2DArray), ptype2, ptype3, ptype4, ptype5); |
| 259 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtUInt, 4) : rvalue, name, TCache::getType(EbtUSampler2DArray), ptype2, ptype3, ptype4, ptype5); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 260 | } |
Martin Radev | 2cc85b3 | 2016-08-05 16:22:53 +0300 | [diff] [blame] | 261 | else if (IsGImage(ptype1->getBasicType())) |
| 262 | { |
| 263 | insertUnmangledBuiltIn(name); |
| 264 | |
| 265 | const TType *floatType = TCache::getType(EbtFloat, 4); |
| 266 | const TType *intType = TCache::getType(EbtInt, 4); |
| 267 | const TType *unsignedType = TCache::getType(EbtUInt, 4); |
| 268 | |
| 269 | const TType *floatImage = |
| 270 | TCache::getType(convertGImageToFloatImage(ptype1->getBasicType())); |
| 271 | const TType *intImage = TCache::getType(convertGImageToIntImage(ptype1->getBasicType())); |
| 272 | const TType *unsignedImage = |
| 273 | TCache::getType(convertGImageToUnsignedImage(ptype1->getBasicType())); |
| 274 | |
| 275 | // GLSL ES 3.10, Revision 4, 8.12 Image Functions |
| 276 | if (rvalue->getBasicType() == EbtGVec4) |
| 277 | { |
| 278 | // imageLoad |
| 279 | insertBuiltIn(level, floatType, name, floatImage, ptype2, ptype3, ptype4, ptype5); |
| 280 | insertBuiltIn(level, intType, name, intImage, ptype2, ptype3, ptype4, ptype5); |
| 281 | insertBuiltIn(level, unsignedType, name, unsignedImage, ptype2, ptype3, ptype4, ptype5); |
| 282 | } |
| 283 | else if (rvalue->getBasicType() == EbtVoid) |
| 284 | { |
| 285 | // imageStore |
| 286 | insertBuiltIn(level, rvalue, name, floatImage, ptype2, floatType, ptype4, ptype5); |
| 287 | insertBuiltIn(level, rvalue, name, intImage, ptype2, intType, ptype4, ptype5); |
| 288 | insertBuiltIn(level, rvalue, name, unsignedImage, ptype2, unsignedType, ptype4, ptype5); |
| 289 | } |
| 290 | else |
| 291 | { |
| 292 | // imageSize |
| 293 | insertBuiltIn(level, rvalue, name, floatImage, ptype2, ptype3, ptype4, ptype5); |
| 294 | insertBuiltIn(level, rvalue, name, intImage, ptype2, ptype3, ptype4, ptype5); |
| 295 | insertBuiltIn(level, rvalue, name, unsignedImage, ptype2, ptype3, ptype4, ptype5); |
| 296 | } |
| 297 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 298 | else if (IsGenType(rvalue) || IsGenType(ptype1) || IsGenType(ptype2) || IsGenType(ptype3)) |
| 299 | { |
| 300 | ASSERT(!ptype4 && !ptype5); |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 301 | insertUnmangledBuiltIn(name); |
Nicolas Capens | c9d9b30 | 2015-02-20 23:02:15 -0500 | [diff] [blame] | 302 | insertBuiltIn(level, op, ext, SpecificType(rvalue, 1), name, SpecificType(ptype1, 1), SpecificType(ptype2, 1), SpecificType(ptype3, 1)); |
| 303 | insertBuiltIn(level, op, ext, SpecificType(rvalue, 2), name, SpecificType(ptype1, 2), SpecificType(ptype2, 2), SpecificType(ptype3, 2)); |
| 304 | insertBuiltIn(level, op, ext, SpecificType(rvalue, 3), name, SpecificType(ptype1, 3), SpecificType(ptype2, 3), SpecificType(ptype3, 3)); |
| 305 | insertBuiltIn(level, op, ext, SpecificType(rvalue, 4), name, SpecificType(ptype1, 4), SpecificType(ptype2, 4), SpecificType(ptype3, 4)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 306 | } |
| 307 | else if (IsVecType(rvalue) || IsVecType(ptype1) || IsVecType(ptype2) || IsVecType(ptype3)) |
| 308 | { |
| 309 | ASSERT(!ptype4 && !ptype5); |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 310 | insertUnmangledBuiltIn(name); |
Nicolas Capens | c9d9b30 | 2015-02-20 23:02:15 -0500 | [diff] [blame] | 311 | insertBuiltIn(level, op, ext, VectorType(rvalue, 2), name, VectorType(ptype1, 2), VectorType(ptype2, 2), VectorType(ptype3, 2)); |
| 312 | insertBuiltIn(level, op, ext, VectorType(rvalue, 3), name, VectorType(ptype1, 3), VectorType(ptype2, 3), VectorType(ptype3, 3)); |
| 313 | insertBuiltIn(level, op, ext, VectorType(rvalue, 4), name, VectorType(ptype1, 4), VectorType(ptype2, 4), VectorType(ptype3, 4)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 314 | } |
| 315 | else |
| 316 | { |
Dmitry Skiba | 7f17a50 | 2015-06-22 15:08:39 -0700 | [diff] [blame] | 317 | TFunction *function = new TFunction(NewPoolTString(name), rvalue, op, ext); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 318 | |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 319 | function->addParameter(TConstParameter(ptype1)); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 320 | |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 321 | if (ptype2) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 322 | { |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 323 | function->addParameter(TConstParameter(ptype2)); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 324 | } |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 325 | |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 326 | if (ptype3) |
| 327 | { |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 328 | function->addParameter(TConstParameter(ptype3)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | if (ptype4) |
| 332 | { |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 333 | function->addParameter(TConstParameter(ptype4)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 334 | } |
| 335 | |
| 336 | if (ptype5) |
| 337 | { |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 338 | function->addParameter(TConstParameter(ptype5)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 339 | } |
| 340 | |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 341 | ASSERT(hasUnmangledBuiltIn(name)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 342 | insert(level, function); |
| 343 | } |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 344 | } |
| 345 | |
Zhenyao Mo | e740add | 2014-07-18 17:01:01 -0700 | [diff] [blame] | 346 | TPrecision TSymbolTable::getDefaultPrecision(TBasicType type) const |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 347 | { |
| 348 | if (!SupportsPrecision(type)) |
| 349 | return EbpUndefined; |
| 350 | |
| 351 | // unsigned integers use the same precision as signed |
| 352 | TBasicType baseType = (type == EbtUInt) ? EbtInt : type; |
| 353 | |
| 354 | int level = static_cast<int>(precisionStack.size()) - 1; |
| 355 | assert(level >= 0); // Just to be safe. Should not happen. |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 356 | // If we dont find anything we return this. Some types don't have predefined default precision. |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 357 | TPrecision prec = EbpUndefined; |
| 358 | while (level >= 0) |
| 359 | { |
| 360 | PrecisionStackLevel::iterator it = precisionStack[level]->find(baseType); |
| 361 | if (it != precisionStack[level]->end()) |
| 362 | { |
| 363 | prec = (*it).second; |
| 364 | break; |
| 365 | } |
| 366 | level--; |
| 367 | } |
| 368 | return prec; |
| 369 | } |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 370 | |
| 371 | } // namespace sh |