zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 1 | // |
zmo@google.com | 89c9813 | 2012-01-06 02:17:03 +0000 | [diff] [blame] | 2 | // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +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 | #include "compiler/MapLongVariableNames.h" |
| 8 | |
| 9 | namespace { |
| 10 | |
zmo@google.com | 9996b8e | 2012-01-19 01:43:55 +0000 | [diff] [blame^] | 11 | TString mapLongName(int id, const TString& name, bool isVarying) |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 12 | { |
kbr@chromium.org | 2215211 | 2011-10-26 01:18:28 +0000 | [diff] [blame] | 13 | ASSERT(name.size() > MAX_SHORTENED_IDENTIFIER_SIZE); |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 14 | TStringStream stream; |
zmo@google.com | 24c08c4 | 2011-05-27 17:40:48 +0000 | [diff] [blame] | 15 | stream << "webgl_"; |
zmo@google.com | 9996b8e | 2012-01-19 01:43:55 +0000 | [diff] [blame^] | 16 | if (isVarying) |
| 17 | stream << "v"; |
zmo@google.com | 24c08c4 | 2011-05-27 17:40:48 +0000 | [diff] [blame] | 18 | stream << id << "_"; |
kbr@chromium.org | 2215211 | 2011-10-26 01:18:28 +0000 | [diff] [blame] | 19 | stream << name.substr(0, MAX_SHORTENED_IDENTIFIER_SIZE - stream.str().size()); |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 20 | return stream.str(); |
| 21 | } |
| 22 | |
| 23 | } // anonymous namespace |
| 24 | |
zmo@google.com | 9996b8e | 2012-01-19 01:43:55 +0000 | [diff] [blame^] | 25 | MapLongVariableNames::MapLongVariableNames( |
| 26 | std::map<std::string, std::string>& varyingLongNameMap) |
| 27 | : mVaryingLongNameMap(varyingLongNameMap) |
zmo@google.com | 24c08c4 | 2011-05-27 17:40:48 +0000 | [diff] [blame] | 28 | { |
| 29 | } |
| 30 | |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 31 | void MapLongVariableNames::visitSymbol(TIntermSymbol* symbol) |
| 32 | { |
| 33 | ASSERT(symbol != NULL); |
kbr@chromium.org | 2215211 | 2011-10-26 01:18:28 +0000 | [diff] [blame] | 34 | if (symbol->getSymbol().size() > MAX_SHORTENED_IDENTIFIER_SIZE) { |
zmo@google.com | 24c08c4 | 2011-05-27 17:40:48 +0000 | [diff] [blame] | 35 | switch (symbol->getQualifier()) { |
| 36 | case EvqVaryingIn: |
| 37 | case EvqVaryingOut: |
| 38 | case EvqInvariantVaryingIn: |
| 39 | case EvqInvariantVaryingOut: |
zmo@google.com | 89c9813 | 2012-01-06 02:17:03 +0000 | [diff] [blame] | 40 | case EvqUniform: |
zmo@google.com | 24c08c4 | 2011-05-27 17:40:48 +0000 | [diff] [blame] | 41 | symbol->setSymbol( |
zmo@google.com | 9996b8e | 2012-01-19 01:43:55 +0000 | [diff] [blame^] | 42 | mapVaryingLongName(symbol->getSymbol())); |
zmo@google.com | 24c08c4 | 2011-05-27 17:40:48 +0000 | [diff] [blame] | 43 | break; |
| 44 | default: |
| 45 | symbol->setSymbol( |
| 46 | mapLongName(symbol->getId(), symbol->getSymbol(), false)); |
| 47 | break; |
| 48 | }; |
| 49 | } |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 50 | } |
| 51 | |
zmo@google.com | 216aa5e | 2011-06-17 22:31:32 +0000 | [diff] [blame] | 52 | bool MapLongVariableNames::visitLoop(Visit, TIntermLoop* node) |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 53 | { |
zmo@google.com | 216aa5e | 2011-06-17 22:31:32 +0000 | [diff] [blame] | 54 | if (node->getInit()) |
| 55 | node->getInit()->traverse(this); |
zmo@google.com | fd747b8 | 2011-04-23 01:30:07 +0000 | [diff] [blame] | 56 | return true; |
| 57 | } |
| 58 | |
zmo@google.com | 9996b8e | 2012-01-19 01:43:55 +0000 | [diff] [blame^] | 59 | TString MapLongVariableNames::mapVaryingLongName(const TString& name) |
zmo@google.com | 24c08c4 | 2011-05-27 17:40:48 +0000 | [diff] [blame] | 60 | { |
zmo@google.com | 9996b8e | 2012-01-19 01:43:55 +0000 | [diff] [blame^] | 61 | std::map<std::string, std::string>::const_iterator it = mVaryingLongNameMap.find(name.c_str()); |
| 62 | if (it != mVaryingLongNameMap.end()) |
zmo@google.com | 46974d2 | 2011-09-27 21:26:19 +0000 | [diff] [blame] | 63 | return (*it).second.c_str(); |
zmo@google.com | 24c08c4 | 2011-05-27 17:40:48 +0000 | [diff] [blame] | 64 | |
zmo@google.com | 9996b8e | 2012-01-19 01:43:55 +0000 | [diff] [blame^] | 65 | int id = mVaryingLongNameMap.size(); |
zmo@google.com | 24c08c4 | 2011-05-27 17:40:48 +0000 | [diff] [blame] | 66 | TString mappedName = mapLongName(id, name, true); |
zmo@google.com | 9996b8e | 2012-01-19 01:43:55 +0000 | [diff] [blame^] | 67 | mVaryingLongNameMap.insert( |
zmo@google.com | 46974d2 | 2011-09-27 21:26:19 +0000 | [diff] [blame] | 68 | std::map<std::string, std::string>::value_type(name.c_str(), mappedName.c_str())); |
zmo@google.com | 24c08c4 | 2011-05-27 17:40:48 +0000 | [diff] [blame] | 69 | return mappedName; |
| 70 | } |