OLD | NEW |
---|---|
1 //===- subzero/src/IceGlobalContext.cpp - Global context defs ---*- C++ -*-===// | 1 //===- subzero/src/IceGlobalContext.cpp - Global context defs ---*- 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 // This file defines aspects of the compilation that persist across | 10 // This file defines aspects of the compilation that persist across |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 // _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz | 92 // _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz |
93 // A non-nested but mangled name like bar() gets nested, making it | 93 // A non-nested but mangled name like bar() gets nested, making it |
94 // equivalent to Prefix::bar(). | 94 // equivalent to Prefix::bar(). |
95 // _Z3barxyz ==> ZN6Prefix3barExyz | 95 // _Z3barxyz ==> ZN6Prefix3barExyz |
96 // An unmangled, extern "C" style name, gets a simple prefix: | 96 // An unmangled, extern "C" style name, gets a simple prefix: |
97 // bar ==> Prefixbar | 97 // bar ==> Prefixbar |
98 if (getTestPrefix().empty()) | 98 if (getTestPrefix().empty()) |
99 return Name; | 99 return Name; |
100 | 100 |
101 unsigned PrefixLength = getTestPrefix().length(); | 101 unsigned PrefixLength = getTestPrefix().length(); |
102 char NameBase[1 + Name.length()]; | 102 llvm::OwningArrayPtr<char> NameBaseOwner(new char[1 + Name.length()]); |
JF
2014/05/23 16:45:22
Ew. VLAs aren't that evil in this context... What
Jim Stichnoth
2014/05/23 18:26:45
I don't know what the maximum identifier length is
| |
103 char *NameBase = NameBaseOwner.get(); | |
103 const size_t BufLen = 30 + Name.length() + PrefixLength; | 104 const size_t BufLen = 30 + Name.length() + PrefixLength; |
104 char NewName[BufLen]; | 105 llvm::OwningArrayPtr<char> NewNameOwner(new char[BufLen]); |
106 char *NewName = NewNameOwner.get(); | |
105 uint32_t BaseLength = 0; // using uint32_t due to sscanf format string | 107 uint32_t BaseLength = 0; // using uint32_t due to sscanf format string |
106 | 108 |
107 int ItemsParsed = sscanf(Name.c_str(), "_ZN%s", NameBase); | 109 int ItemsParsed = sscanf(Name.c_str(), "_ZN%s", NameBase); |
108 if (ItemsParsed == 1) { | 110 if (ItemsParsed == 1) { |
109 // Transform _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz | 111 // Transform _ZN3foo3barExyz ==> _ZN6Prefix3foo3barExyz |
110 // (splice in "6Prefix") ^^^^^^^ | 112 // (splice in "6Prefix") ^^^^^^^ |
111 snprintf(NewName, BufLen, "_ZN%u%s%s", PrefixLength, | 113 snprintf(NewName, BufLen, "_ZN%u%s%s", PrefixLength, |
112 getTestPrefix().c_str(), NameBase); | 114 getTestPrefix().c_str(), NameBase); |
113 // We ignore the snprintf return value (here and below). If we | 115 // We ignore the snprintf return value (here and below). If we |
114 // somehow miscalculated the output buffer length, the output will | 116 // somehow miscalculated the output buffer length, the output will |
115 // be truncated, but it will be truncated consistently for all | 117 // be truncated, but it will be truncated consistently for all |
116 // mangleName() calls on the same input string. | 118 // mangleName() calls on the same input string. |
117 return NewName; | 119 return NewName; |
118 } | 120 } |
119 | 121 |
120 ItemsParsed = sscanf(Name.c_str(), "_Z%u%s", &BaseLength, NameBase); | 122 ItemsParsed = sscanf(Name.c_str(), "_Z%u%s", &BaseLength, NameBase); |
121 if (ItemsParsed == 2 && BaseLength <= strlen(NameBase)) { | 123 if (ItemsParsed == 2 && BaseLength <= strlen(NameBase)) { |
122 // Transform _Z3barxyz ==> _ZN6Prefix3barExyz | 124 // Transform _Z3barxyz ==> _ZN6Prefix3barExyz |
123 // ^^^^^^^^ ^ | 125 // ^^^^^^^^ ^ |
124 // (splice in "N6Prefix", and insert "E" after "3bar") | 126 // (splice in "N6Prefix", and insert "E" after "3bar") |
125 // But an "I" after the identifier indicates a template argument | 127 // But an "I" after the identifier indicates a template argument |
126 // list terminated with "E"; insert the new "E" before/after the | 128 // list terminated with "E"; insert the new "E" before/after the |
127 // old "E". E.g.: | 129 // old "E". E.g.: |
128 // Transform _Z3barIabcExyz ==> _ZN6Prefix3barIabcEExyz | 130 // Transform _Z3barIabcExyz ==> _ZN6Prefix3barIabcEExyz |
129 // ^^^^^^^^ ^ | 131 // ^^^^^^^^ ^ |
130 // (splice in "N6Prefix", and insert "E" after "3barIabcE") | 132 // (splice in "N6Prefix", and insert "E" after "3barIabcE") |
131 char OrigName[Name.length()]; | 133 llvm::OwningArrayPtr<char> OrigNameOwner(new char[Name.length()]); |
132 char OrigSuffix[Name.length()]; | 134 char *OrigName = OrigNameOwner.get(); |
135 llvm::OwningArrayPtr<char> OrigSuffixOwner(new char[Name.length()]); | |
136 char *OrigSuffix = OrigSuffixOwner.get(); | |
133 uint32_t ActualBaseLength = BaseLength; | 137 uint32_t ActualBaseLength = BaseLength; |
134 if (NameBase[ActualBaseLength] == 'I') { | 138 if (NameBase[ActualBaseLength] == 'I') { |
135 ++ActualBaseLength; | 139 ++ActualBaseLength; |
136 while (NameBase[ActualBaseLength] != 'E' && | 140 while (NameBase[ActualBaseLength] != 'E' && |
137 NameBase[ActualBaseLength] != '\0') | 141 NameBase[ActualBaseLength] != '\0') |
138 ++ActualBaseLength; | 142 ++ActualBaseLength; |
139 } | 143 } |
140 strncpy(OrigName, NameBase, ActualBaseLength); | 144 strncpy(OrigName, NameBase, ActualBaseLength); |
141 OrigName[ActualBaseLength] = '\0'; | 145 OrigName[ActualBaseLength] = '\0'; |
142 strcpy(OrigSuffix, NameBase + ActualBaseLength); | 146 strcpy(OrigSuffix, NameBase + ActualBaseLength); |
(...skipping 30 matching lines...) Expand all Loading... | |
173 | 177 |
174 void Timer::printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const { | 178 void Timer::printElapsedUs(GlobalContext *Ctx, const IceString &Tag) const { |
175 if (Ctx->isVerbose(IceV_Timing)) { | 179 if (Ctx->isVerbose(IceV_Timing)) { |
176 // Prefixing with '#' allows timing strings to be included | 180 // Prefixing with '#' allows timing strings to be included |
177 // without error in textual assembly output. | 181 // without error in textual assembly output. |
178 Ctx->getStrDump() << "# " << getElapsedUs() << " usec " << Tag << "\n"; | 182 Ctx->getStrDump() << "# " << getElapsedUs() << " usec " << Tag << "\n"; |
179 } | 183 } |
180 } | 184 } |
181 | 185 |
182 } // end of namespace Ice | 186 } // end of namespace Ice |
OLD | NEW |