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 | e740add | 2014-07-18 17:01:01 -0700 | [diff] [blame] | 129 | TSymbol *TSymbolTable::findBuiltIn( |
| 130 | const TString &name, int shaderVersion) const |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 131 | { |
| 132 | for (int level = LAST_BUILTIN_LEVEL; level >= 0; level--) |
| 133 | { |
Martin Radev | e93d24e | 2016-07-28 12:06:05 +0300 | [diff] [blame] | 134 | if (level == ESSL3_1_BUILTINS && shaderVersion != 310) |
| 135 | level--; |
| 136 | if (level == ESSL3_BUILTINS && shaderVersion < 300) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 137 | level--; |
| 138 | if (level == ESSL1_BUILTINS && shaderVersion != 100) |
| 139 | level--; |
shannonwoods@chromium.org | 96e7ba1 | 2013-05-30 00:02:41 +0000 | [diff] [blame] | 140 | |
| 141 | TSymbol *symbol = table[level]->find(name); |
| 142 | |
| 143 | if (symbol) |
| 144 | return symbol; |
| 145 | } |
| 146 | |
| 147 | return 0; |
| 148 | } |
Alok Priyadarshi | bc3f1ac | 2013-09-23 14:57:02 -0400 | [diff] [blame] | 149 | |
| 150 | TSymbolTable::~TSymbolTable() |
| 151 | { |
| 152 | while (table.size() > 0) |
| 153 | pop(); |
| 154 | } |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 155 | |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 156 | bool IsGenType(const TType *type) |
| 157 | { |
| 158 | if (type) |
| 159 | { |
| 160 | TBasicType basicType = type->getBasicType(); |
| 161 | return basicType == EbtGenType || basicType == EbtGenIType || basicType == EbtGenUType || basicType == EbtGenBType; |
| 162 | } |
| 163 | |
| 164 | return false; |
| 165 | } |
| 166 | |
| 167 | bool IsVecType(const TType *type) |
| 168 | { |
| 169 | if (type) |
| 170 | { |
| 171 | TBasicType basicType = type->getBasicType(); |
| 172 | return basicType == EbtVec || basicType == EbtIVec || basicType == EbtUVec || basicType == EbtBVec; |
| 173 | } |
| 174 | |
| 175 | return false; |
| 176 | } |
| 177 | |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 178 | const TType *SpecificType(const TType *type, int size) |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 179 | { |
| 180 | ASSERT(size >= 1 && size <= 4); |
| 181 | |
| 182 | if (!type) |
| 183 | { |
| 184 | return nullptr; |
| 185 | } |
| 186 | |
| 187 | ASSERT(!IsVecType(type)); |
| 188 | |
| 189 | switch(type->getBasicType()) |
| 190 | { |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 191 | case EbtGenType: return TCache::getType(EbtFloat, static_cast<unsigned char>(size)); |
| 192 | case EbtGenIType: return TCache::getType(EbtInt, static_cast<unsigned char>(size)); |
| 193 | case EbtGenUType: return TCache::getType(EbtUInt, static_cast<unsigned char>(size)); |
| 194 | case EbtGenBType: return TCache::getType(EbtBool, static_cast<unsigned char>(size)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 195 | default: return type; |
| 196 | } |
| 197 | } |
| 198 | |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 199 | const TType *VectorType(const TType *type, int size) |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 200 | { |
| 201 | ASSERT(size >= 2 && size <= 4); |
| 202 | |
| 203 | if (!type) |
| 204 | { |
| 205 | return nullptr; |
| 206 | } |
| 207 | |
| 208 | ASSERT(!IsGenType(type)); |
| 209 | |
| 210 | switch(type->getBasicType()) |
| 211 | { |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 212 | case EbtVec: return TCache::getType(EbtFloat, static_cast<unsigned char>(size)); |
| 213 | case EbtIVec: return TCache::getType(EbtInt, static_cast<unsigned char>(size)); |
| 214 | case EbtUVec: return TCache::getType(EbtUInt, static_cast<unsigned char>(size)); |
| 215 | case EbtBVec: return TCache::getType(EbtBool, static_cast<unsigned char>(size)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 216 | default: return type; |
| 217 | } |
| 218 | } |
| 219 | |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 220 | void TSymbolTable::insertBuiltIn(ESymbolLevel level, TOperator op, const char *ext, const TType *rvalue, const char *name, |
| 221 | 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] | 222 | { |
| 223 | if (ptype1->getBasicType() == EbtGSampler2D) |
| 224 | { |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 225 | insertUnmangledBuiltIn(name); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 226 | bool gvec4 = (rvalue->getBasicType() == EbtGVec4); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 227 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSampler2D), ptype2, ptype3, ptype4, ptype5); |
| 228 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISampler2D), ptype2, ptype3, ptype4, ptype5); |
| 229 | 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] | 230 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 231 | else if (ptype1->getBasicType() == EbtGSampler3D) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 232 | { |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 233 | insertUnmangledBuiltIn(name); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 234 | bool gvec4 = (rvalue->getBasicType() == EbtGVec4); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 235 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSampler3D), ptype2, ptype3, ptype4, ptype5); |
| 236 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISampler3D), ptype2, ptype3, ptype4, ptype5); |
| 237 | 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] | 238 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 239 | else if (ptype1->getBasicType() == EbtGSamplerCube) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 240 | { |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 241 | insertUnmangledBuiltIn(name); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 242 | bool gvec4 = (rvalue->getBasicType() == EbtGVec4); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 243 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSamplerCube), ptype2, ptype3, ptype4, ptype5); |
| 244 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISamplerCube), ptype2, ptype3, ptype4, ptype5); |
| 245 | 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] | 246 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 247 | else if (ptype1->getBasicType() == EbtGSampler2DArray) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 248 | { |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 249 | insertUnmangledBuiltIn(name); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 250 | bool gvec4 = (rvalue->getBasicType() == EbtGVec4); |
Dmitry Skiba | 0197111 | 2015-07-10 14:54:00 -0400 | [diff] [blame] | 251 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtFloat, 4) : rvalue, name, TCache::getType(EbtSampler2DArray), ptype2, ptype3, ptype4, ptype5); |
| 252 | insertBuiltIn(level, gvec4 ? TCache::getType(EbtInt, 4) : rvalue, name, TCache::getType(EbtISampler2DArray), ptype2, ptype3, ptype4, ptype5); |
| 253 | 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] | 254 | } |
Martin Radev | 2cc85b3 | 2016-08-05 16:22:53 +0300 | [diff] [blame] | 255 | else if (IsGImage(ptype1->getBasicType())) |
| 256 | { |
| 257 | insertUnmangledBuiltIn(name); |
| 258 | |
| 259 | const TType *floatType = TCache::getType(EbtFloat, 4); |
| 260 | const TType *intType = TCache::getType(EbtInt, 4); |
| 261 | const TType *unsignedType = TCache::getType(EbtUInt, 4); |
| 262 | |
| 263 | const TType *floatImage = |
| 264 | TCache::getType(convertGImageToFloatImage(ptype1->getBasicType())); |
| 265 | const TType *intImage = TCache::getType(convertGImageToIntImage(ptype1->getBasicType())); |
| 266 | const TType *unsignedImage = |
| 267 | TCache::getType(convertGImageToUnsignedImage(ptype1->getBasicType())); |
| 268 | |
| 269 | // GLSL ES 3.10, Revision 4, 8.12 Image Functions |
| 270 | if (rvalue->getBasicType() == EbtGVec4) |
| 271 | { |
| 272 | // imageLoad |
| 273 | insertBuiltIn(level, floatType, name, floatImage, ptype2, ptype3, ptype4, ptype5); |
| 274 | insertBuiltIn(level, intType, name, intImage, ptype2, ptype3, ptype4, ptype5); |
| 275 | insertBuiltIn(level, unsignedType, name, unsignedImage, ptype2, ptype3, ptype4, ptype5); |
| 276 | } |
| 277 | else if (rvalue->getBasicType() == EbtVoid) |
| 278 | { |
| 279 | // imageStore |
| 280 | insertBuiltIn(level, rvalue, name, floatImage, ptype2, floatType, ptype4, ptype5); |
| 281 | insertBuiltIn(level, rvalue, name, intImage, ptype2, intType, ptype4, ptype5); |
| 282 | insertBuiltIn(level, rvalue, name, unsignedImage, ptype2, unsignedType, ptype4, ptype5); |
| 283 | } |
| 284 | else |
| 285 | { |
| 286 | // imageSize |
| 287 | insertBuiltIn(level, rvalue, name, floatImage, ptype2, ptype3, ptype4, ptype5); |
| 288 | insertBuiltIn(level, rvalue, name, intImage, ptype2, ptype3, ptype4, ptype5); |
| 289 | insertBuiltIn(level, rvalue, name, unsignedImage, ptype2, ptype3, ptype4, ptype5); |
| 290 | } |
| 291 | } |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 292 | else if (IsGenType(rvalue) || IsGenType(ptype1) || IsGenType(ptype2) || IsGenType(ptype3)) |
| 293 | { |
| 294 | ASSERT(!ptype4 && !ptype5); |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 295 | insertUnmangledBuiltIn(name); |
Nicolas Capens | c9d9b30 | 2015-02-20 23:02:15 -0500 | [diff] [blame] | 296 | insertBuiltIn(level, op, ext, SpecificType(rvalue, 1), name, SpecificType(ptype1, 1), SpecificType(ptype2, 1), SpecificType(ptype3, 1)); |
| 297 | insertBuiltIn(level, op, ext, SpecificType(rvalue, 2), name, SpecificType(ptype1, 2), SpecificType(ptype2, 2), SpecificType(ptype3, 2)); |
| 298 | insertBuiltIn(level, op, ext, SpecificType(rvalue, 3), name, SpecificType(ptype1, 3), SpecificType(ptype2, 3), SpecificType(ptype3, 3)); |
| 299 | 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] | 300 | } |
| 301 | else if (IsVecType(rvalue) || IsVecType(ptype1) || IsVecType(ptype2) || IsVecType(ptype3)) |
| 302 | { |
| 303 | ASSERT(!ptype4 && !ptype5); |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 304 | insertUnmangledBuiltIn(name); |
Nicolas Capens | c9d9b30 | 2015-02-20 23:02:15 -0500 | [diff] [blame] | 305 | insertBuiltIn(level, op, ext, VectorType(rvalue, 2), name, VectorType(ptype1, 2), VectorType(ptype2, 2), VectorType(ptype3, 2)); |
| 306 | insertBuiltIn(level, op, ext, VectorType(rvalue, 3), name, VectorType(ptype1, 3), VectorType(ptype2, 3), VectorType(ptype3, 3)); |
| 307 | 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] | 308 | } |
| 309 | else |
| 310 | { |
Dmitry Skiba | 7f17a50 | 2015-06-22 15:08:39 -0700 | [diff] [blame] | 311 | TFunction *function = new TFunction(NewPoolTString(name), rvalue, op, ext); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 312 | |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 313 | function->addParameter(TConstParameter(ptype1)); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 314 | |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 315 | if (ptype2) |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 316 | { |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 317 | function->addParameter(TConstParameter(ptype2)); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 318 | } |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 319 | |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 320 | if (ptype3) |
| 321 | { |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 322 | function->addParameter(TConstParameter(ptype3)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | if (ptype4) |
| 326 | { |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 327 | function->addParameter(TConstParameter(ptype4)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | if (ptype5) |
| 331 | { |
Dmitry Skiba | efa3d8e | 2015-06-22 14:52:10 -0700 | [diff] [blame] | 332 | function->addParameter(TConstParameter(ptype5)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 333 | } |
| 334 | |
Olli Etuaho | c4a96d6 | 2015-07-23 17:37:39 +0530 | [diff] [blame] | 335 | ASSERT(hasUnmangledBuiltIn(name)); |
Nicolas Capens | f3cc4ae | 2015-02-23 13:51:25 -0500 | [diff] [blame] | 336 | insert(level, function); |
| 337 | } |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Zhenyao Mo | e740add | 2014-07-18 17:01:01 -0700 | [diff] [blame] | 340 | TPrecision TSymbolTable::getDefaultPrecision(TBasicType type) const |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 341 | { |
| 342 | if (!SupportsPrecision(type)) |
| 343 | return EbpUndefined; |
| 344 | |
| 345 | // unsigned integers use the same precision as signed |
| 346 | TBasicType baseType = (type == EbtUInt) ? EbtInt : type; |
| 347 | |
| 348 | int level = static_cast<int>(precisionStack.size()) - 1; |
| 349 | assert(level >= 0); // Just to be safe. Should not happen. |
Olli Etuaho | 183d7e2 | 2015-11-20 15:59:09 +0200 | [diff] [blame] | 350 | // 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] | 351 | TPrecision prec = EbpUndefined; |
| 352 | while (level >= 0) |
| 353 | { |
| 354 | PrecisionStackLevel::iterator it = precisionStack[level]->find(baseType); |
| 355 | if (it != precisionStack[level]->end()) |
| 356 | { |
| 357 | prec = (*it).second; |
| 358 | break; |
| 359 | } |
| 360 | level--; |
| 361 | } |
| 362 | return prec; |
| 363 | } |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 364 | |
| 365 | } // namespace sh |