OLD | NEW |
1 //===- subzero/src/IceMangling.cpp - Cross test name mangling --*- C++ -*-===// | 1 //===- subzero/src/IceMangling.cpp - Cross test name mangling --*- C++ -*-===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 /// | 9 /// |
10 /// \file | 10 /// \file |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 } | 110 } |
111 assert(NewName[NewPos] == '\0'); | 111 assert(NewName[NewPos] == '\0'); |
112 OldName = NewName; | 112 OldName = NewName; |
113 } | 113 } |
114 | 114 |
115 } // end of anonymous namespace | 115 } // end of anonymous namespace |
116 | 116 |
117 // In this context, name mangling means to rewrite a symbol using a given | 117 // In this context, name mangling means to rewrite a symbol using a given |
118 // prefix. For a C++ symbol, nest the original symbol inside the "prefix" | 118 // prefix. For a C++ symbol, nest the original symbol inside the "prefix" |
119 // namespace. For other symbols, just prepend the prefix. | 119 // namespace. For other symbols, just prepend the prefix. |
120 IceString mangleName(const IceString &Name) { | 120 std::string mangleName(const std::string &Name) { |
121 // An already-nested name like foo::bar() gets pushed down one level, making | 121 // An already-nested name like foo::bar() gets pushed down one level, making |
122 // it equivalent to Prefix::foo::bar(). | 122 // it equivalent to Prefix::foo::bar(). |
123 // _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz | 123 // _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz |
124 // A non-nested but mangled name like bar() gets nested, making it equivalent | 124 // A non-nested but mangled name like bar() gets nested, making it equivalent |
125 // to Prefix::bar(). | 125 // to Prefix::bar(). |
126 // _Z3barxyz ==> ZN6Prefix3barExyz | 126 // _Z3barxyz ==> ZN6Prefix3barExyz |
127 // An unmangled, extern "C" style name, gets a simple prefix: | 127 // An unmangled, extern "C" style name, gets a simple prefix: |
128 // bar ==> Prefixbar | 128 // bar ==> Prefixbar |
129 if (!BuildDefs::dump() || GlobalContext::getFlags().getTestPrefix().empty()) | 129 if (!BuildDefs::dump() || GlobalContext::getFlags().getTestPrefix().empty()) |
130 return Name; | 130 return Name; |
131 | 131 |
132 const IceString &TestPrefix = GlobalContext::getFlags().getTestPrefix(); | 132 const std::string TestPrefix = GlobalContext::getFlags().getTestPrefix(); |
133 unsigned PrefixLength = TestPrefix.length(); | 133 unsigned PrefixLength = TestPrefix.length(); |
134 ManglerVector NameBase(1 + Name.length()); | 134 ManglerVector NameBase(1 + Name.length()); |
135 const size_t BufLen = 30 + Name.length() + PrefixLength; | 135 const size_t BufLen = 30 + Name.length() + PrefixLength; |
136 ManglerVector NewName(BufLen); | 136 ManglerVector NewName(BufLen); |
137 uint32_t BaseLength = 0; // using uint32_t due to sscanf format string | 137 uint32_t BaseLength = 0; // using uint32_t due to sscanf format string |
138 | 138 |
139 int ItemsParsed = sscanf(Name.c_str(), "_ZN%s", NameBase.data()); | 139 int ItemsParsed = sscanf(Name.c_str(), "_ZN%s", NameBase.data()); |
140 if (ItemsParsed == 1) { | 140 if (ItemsParsed == 1) { |
141 // Transform _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz | 141 // Transform _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz |
142 // (splice in "6Prefix") ^^^^^^^ | 142 // (splice in "6Prefix") ^^^^^^^ |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 incrementSubstitutions(NewName); | 184 incrementSubstitutions(NewName); |
185 return NewName.data(); | 185 return NewName.data(); |
186 } | 186 } |
187 | 187 |
188 // Transform bar ==> Prefixbar | 188 // Transform bar ==> Prefixbar |
189 // ^^^^^^ | 189 // ^^^^^^ |
190 return TestPrefix + Name; | 190 return TestPrefix + Name; |
191 } | 191 } |
192 | 192 |
193 } // end of namespace Ice | 193 } // end of namespace Ice |
OLD | NEW |