Commit e7970c3e by Clemen Deng Committed by Commit Bot

BasicMangledName class

Need a class for basic mangled names since with the addition of GLSL types the number of basic types is > 52 (a-z, A-Z), so we need more than one character to represent a type Bug: angleproject:3719 Change-Id: I98beee9d42a016cb0c017f56ab82538c89212e33 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1742221 Commit-Queue: Clemen Deng <clemendeng@google.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent bca3e7b2
{ {
"src/compiler/translator/ImmutableString_autogen.cpp": "src/compiler/translator/ImmutableString_autogen.cpp":
"e7c9b98db7d7b435f57ff26fc265efb3", "a47e4acb32dac769b179bb1e884fbece",
"src/compiler/translator/ParseContext_autogen.h": "src/compiler/translator/ParseContext_autogen.h":
"58786d2f352ee1a58d529fb7572c86a4", "58786d2f352ee1a58d529fb7572c86a4",
"src/compiler/translator/SymbolTable_autogen.cpp": "src/compiler/translator/SymbolTable_autogen.cpp":
"040a451ff0ad57612d5614d853cebd5a", "cd0abc040d6902e1688d048d19ca70a9",
"src/compiler/translator/SymbolTable_autogen.h": "src/compiler/translator/SymbolTable_autogen.h":
"bdb3c8eab0d48267a2f264e3af635e1a", "bdb3c8eab0d48267a2f264e3af635e1a",
"src/compiler/translator/builtin_function_declarations.txt": "src/compiler/translator/builtin_function_declarations.txt":
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
"src/compiler/translator/builtin_variables.json": "src/compiler/translator/builtin_variables.json":
"04f763459cfbd47831bec22299287e82", "04f763459cfbd47831bec22299287e82",
"src/compiler/translator/gen_builtin_symbols.py": "src/compiler/translator/gen_builtin_symbols.py":
"466747c0158bab9d4792f066b70bf5ed", "5527c49f0e939aa593fa14f0f0cf84c5",
"src/compiler/translator/tree_util/BuiltIn_autogen.h": "src/compiler/translator/tree_util/BuiltIn_autogen.h":
"69268b2f3bda048ba8aaabe60c9b9912", "8960db32b50614ad1f339bd0f5fdca2a",
"src/tests/compiler_tests/ImmutableString_test_autogen.cpp": "src/tests/compiler_tests/ImmutableString_test_autogen.cpp":
"aafd90302c36e2a848711576aa3a1aee" "7b9cded5c25f8e433b866a3f4be334c3"
} }
\ No newline at end of file
...@@ -113,19 +113,35 @@ enum TBasicType ...@@ -113,19 +113,35 @@ enum TBasicType
EbtLast = EbtInterfaceBlock EbtLast = EbtInterfaceBlock
}; };
constexpr char GetBasicMangledName(TBasicType t) class TBasicMangledName
{ {
if (t > EbtLastSimpleType) public:
constexpr TBasicMangledName(TBasicType t) : mName{'\0', '\0'}
{ {
return '{'; if (t > EbtLastSimpleType)
{
mName[0] = '{';
mName[1] = '\0';
}
else if (t < 26)
{
mName[0] = '0';
mName[1] = static_cast<char>('A' + t);
}
else if (t < 52)
{
mName[0] = '0';
mName[1] = static_cast<char>('a' - 26 + t);
}
} }
static_assert(EbtLastSimpleType < 52, "We only use alphabetic characters for mangled names");
if (t < 26) constexpr char *getName() { return mName; }
{
return static_cast<char>('A' + t); static constexpr int mangledNameSize = 2;
}
return static_cast<char>('a' - 26 + t); private:
} char mName[mangledNameSize];
};
const char *getBasicString(TBasicType t); const char *getBasicString(TBasicType t);
......
...@@ -27,7 +27,7 @@ namespace Helpers ...@@ -27,7 +27,7 @@ namespace Helpers
// Size of the constexpr-generated mangled name. // Size of the constexpr-generated mangled name.
// If this value is too small, the compiler will produce errors. // If this value is too small, the compiler will produce errors.
static constexpr size_t kStaticMangledNameLength = 2; static constexpr size_t kStaticMangledNameLength = TBasicMangledName::mangledNameSize + 1;
// Type which holds the mangled names for constexpr-generated TTypes. // Type which holds the mangled names for constexpr-generated TTypes.
// This simple struct is needed so that a char array can be returned by value. // This simple struct is needed so that a char array can be returned by value.
...@@ -46,8 +46,12 @@ constexpr StaticMangledName BuildStaticMangledName(TBasicType basicType, ...@@ -46,8 +46,12 @@ constexpr StaticMangledName BuildStaticMangledName(TBasicType basicType,
{ {
StaticMangledName name = {}; StaticMangledName name = {};
name.name[0] = TType::GetSizeMangledName(primarySize, secondarySize); name.name[0] = TType::GetSizeMangledName(primarySize, secondarySize);
name.name[1] = GetBasicMangledName(basicType); TBasicMangledName typeName(basicType);
name.name[2] = '\0'; char *mangledName = typeName.getName();
static_assert(TBasicMangledName::mangledNameSize == 2, "Mangled name size is not 2");
name.name[1] = mangledName[0];
name.name[2] = mangledName[1];
name.name[3] = '\0';
return name; return name;
} }
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -454,10 +454,13 @@ const char *TType::buildMangledName() const ...@@ -454,10 +454,13 @@ const char *TType::buildMangledName() const
{ {
TString mangledName(1, GetSizeMangledName(primarySize, secondarySize)); TString mangledName(1, GetSizeMangledName(primarySize, secondarySize));
char basicMangledName = GetBasicMangledName(type); TBasicMangledName typeName(type);
if (basicMangledName != '{') char *basicMangledName = typeName.getName();
static_assert(TBasicMangledName::mangledNameSize == 2, "Mangled name size is not 2");
if (basicMangledName[0] != '{')
{ {
mangledName += basicMangledName; mangledName += basicMangledName[0];
mangledName += basicMangledName[1];
} }
else else
{ {
......
...@@ -359,8 +359,8 @@ def set_working_dir(): ...@@ -359,8 +359,8 @@ def set_working_dir():
def get_basic_mangled_name(basic): def get_basic_mangled_name(basic):
index = basic_types_enumeration.index(basic) index = basic_types_enumeration.index(basic)
if index < 26: if index < 26:
return chr(ord('A') + index) return '0' + chr(ord('A') + index)
return chr(ord('a') + index - 26) return '0' + chr(ord('a') + index - 26)
levels = ['ESSL3_1_BUILTINS', 'ESSL3_BUILTINS', 'ESSL1_BUILTINS', 'COMMON_BUILTINS'] levels = ['ESSL3_1_BUILTINS', 'ESSL3_BUILTINS', 'ESSL1_BUILTINS', 'COMMON_BUILTINS']
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -43,17 +43,24 @@ TEST(Type, VectorAndMatrixMangledNameConsistent) ...@@ -43,17 +43,24 @@ TEST(Type, VectorAndMatrixMangledNameConsistent)
// Verify that basic type mangled names are unique. // Verify that basic type mangled names are unique.
TEST(Type, BaseTypeMangledNamesUnique) TEST(Type, BaseTypeMangledNamesUnique)
{ {
std::set<char> uniqueNames; // Types have either a 0-prefix or a 1-prefix
std::set<char> uniqueNames0;
std::set<char> uniqueNames1;
for (int i = static_cast<int>(EbtVoid); i < static_cast<int>(EbtLast); ++i) for (int i = static_cast<int>(EbtVoid); i < static_cast<int>(EbtLast); ++i)
{ {
if (i == static_cast<int>(EbtStruct) || i == static_cast<int>(EbtInterfaceBlock)) if (i == static_cast<int>(EbtStruct) || i == static_cast<int>(EbtInterfaceBlock))
{ {
continue; continue;
} }
char mangledName = GetBasicMangledName(static_cast<TBasicType>(i)); TBasicMangledName typeName(static_cast<TBasicType>(i));
if (mangledName != '{') char *mangledName = typeName.getName();
static_assert(TBasicMangledName::mangledNameSize == 2, "Mangled name size is not 2");
if (mangledName[0] != '{')
{ {
ASSERT_TRUE(uniqueNames.insert(mangledName).second); if (mangledName[0] == '0')
ASSERT_TRUE(uniqueNames0.insert(mangledName[1]).second);
if (mangledName[0] == '1')
ASSERT_TRUE(uniqueNames1.insert(mangledName[1]).second);
} }
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment