OLD | NEW |
---|---|
1 //===-- NaClObjDumpStream.cpp --------------------------------------------===// | 1 //===-- NaClObjDumpStream.cpp --------------------------------------------===// |
2 // Implements an objdump stream (bitcode records/assembly code). | 2 // Implements an objdump stream (bitcode records/assembly code). |
3 // | 3 // |
4 // The LLVM Compiler Infrastructure | 4 // The LLVM Compiler Infrastructure |
5 // | 5 // |
6 // This file is distributed under the University of Illinois Open Source | 6 // This file is distributed under the University of Illinois Open Source |
7 // License. See LICENSE.TXT for details. | 7 // License. See LICENSE.TXT for details. |
8 // | 8 // |
9 //===----------------------------------------------------------------------===// | 9 //===----------------------------------------------------------------------===// |
10 | 10 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 } | 145 } |
146 | 146 |
147 | 147 |
148 TextFormatter::Directive *TextFormatter::GetTokenDirective:: | 148 TextFormatter::Directive *TextFormatter::GetTokenDirective:: |
149 Allocate(TextFormatter *Formatter, const std::string &Text) { | 149 Allocate(TextFormatter *Formatter, const std::string &Text) { |
150 GetTokenDirective *Dir = Formatter->GetTokenFreeList.Allocate(Formatter); | 150 GetTokenDirective *Dir = Formatter->GetTokenFreeList.Allocate(Formatter); |
151 Dir->Text = Text; | 151 Dir->Text = Text; |
152 return Dir; | 152 return Dir; |
153 } | 153 } |
154 | 154 |
155 std::string RecordTextFormatter::getBitAddress(uint64_t Bit) { | |
156 std::string Address = naclbitc::getBitAddress(Bit); | |
157 size_t AddressSize = Address.size(); | |
158 if (AddressSize >= AddressWriteWidth) | |
159 return Address; | |
160 | |
161 // Pad address with leading spaces. | |
162 std::string Buffer; | |
163 raw_string_ostream StrBuf(Buffer); | |
164 for (size_t i = AddressWriteWidth - AddressSize; i > 0; --i) { | |
165 StrBuf << " "; | |
166 } | |
167 StrBuf << Address; | |
168 return StrBuf.str(); | |
169 } | |
170 | |
155 RecordTextFormatter::RecordTextFormatter(ObjDumpStream *ObjDump) | 171 RecordTextFormatter::RecordTextFormatter(ObjDumpStream *ObjDump) |
156 : TextFormatter(ObjDump->Records(), 0, " "), | 172 : TextFormatter(ObjDump->Records(), 0, " "), |
157 OpenBrace(this, "<"), | 173 OpenBrace(this, "<"), |
158 CloseBrace(this, ">"), | 174 CloseBrace(this, ">"), |
159 Comma(this, ","), | 175 Comma(this, ","), |
160 Space(this), | 176 Space(this), |
161 Endline(this), | 177 Endline(this), |
162 StartCluster(this), | 178 StartCluster(this), |
163 FinishCluster(this) { | 179 FinishCluster(this) { |
164 // Handle fact that 64-bit values can take up to 21 characters. | 180 // Handle fact that 64-bit values can take up to 21 characters. |
165 MinLineWidth = 21; | 181 MinLineWidth = 21; |
166 Label = NaClBitstreamReader::getBitAddress(0, AddressWriteWidth); | 182 Label = getBitAddress(0); |
167 } | 183 } |
168 | 184 |
169 std::string RecordTextFormatter::GetEmptyLabelColumn() { | 185 std::string RecordTextFormatter::GetEmptyLabelColumn() { |
170 std::string Buffer; | 186 std::string Buffer; |
171 raw_string_ostream StrmBuffer(Buffer); | 187 raw_string_ostream StrmBuffer(Buffer); |
172 for (size_t i = 0; i < Label.size(); ++i) { | 188 for (size_t i = 0; i < Label.size(); ++i) { |
173 StrmBuffer << ' '; | 189 StrmBuffer << ' '; |
174 } | 190 } |
175 StrmBuffer << '|'; | 191 StrmBuffer << '|'; |
176 return StrmBuffer.str(); | 192 return StrmBuffer.str(); |
177 } | 193 } |
178 | 194 |
179 void RecordTextFormatter::WriteLineIndents() { | 195 void RecordTextFormatter::WriteLineIndents() { |
180 if (AtInstructionBeginning) { | 196 if (AtInstructionBeginning) { |
181 BaseStream << Label << '|'; | 197 BaseStream << Label << '|'; |
182 } else { | 198 } else { |
183 BaseStream << GetEmptyLabelColumn(); | 199 BaseStream << GetEmptyLabelColumn(); |
184 } | 200 } |
185 LinePosition += Label.size() + 1; | 201 LinePosition += Label.size() + 1; |
186 TextFormatter::WriteLineIndents(); | 202 TextFormatter::WriteLineIndents(); |
187 } | 203 } |
188 | 204 |
189 void RecordTextFormatter::WriteValues(uint64_t Bit, | 205 void RecordTextFormatter::WriteValues(uint64_t Bit, |
190 const llvm::NaClBitcodeValues &Values, | 206 const llvm::NaClBitcodeValues &Values, |
191 int32_t AbbrevIndex) { | 207 int32_t AbbrevIndex) { |
192 Label = NaClBitstreamReader::getBitAddress( | 208 Label = getBitAddress(Bit); |
193 Bit, RecordTextFormatter::AddressWriteWidth); | |
194 if (AbbrevIndex != ABBREV_INDEX_NOT_SPECIFIED) { | 209 if (AbbrevIndex != ABBREV_INDEX_NOT_SPECIFIED) { |
195 TextStream << AbbrevIndex << ":" << Space; | 210 TextStream << AbbrevIndex << ":" << Space; |
196 } | 211 } |
197 TextStream << OpenBrace; | 212 TextStream << OpenBrace; |
198 for (size_t i = 0; i < Values.size(); ++i) { | 213 for (size_t i = 0; i < Values.size(); ++i) { |
199 if (i > 0) { | 214 if (i > 0) { |
200 TextStream << Comma << FinishCluster << Space; | 215 TextStream << Comma << FinishCluster << Space; |
201 } | 216 } |
202 TextStream << StartCluster << Values[i]; | 217 TextStream << StartCluster << Values[i]; |
203 } | 218 } |
(...skipping 26 matching lines...) Expand all Loading... | |
230 RecordStream(RecordBuffer), | 245 RecordStream(RecordBuffer), |
231 RecordFormatter(this) { | 246 RecordFormatter(this) { |
232 if (DumpRecords) { | 247 if (DumpRecords) { |
233 RecordWidth = DumpAssembly | 248 RecordWidth = DumpAssembly |
234 ? ComboObjDumpSeparatorColumn | 249 ? ComboObjDumpSeparatorColumn |
235 : RecordObjectDumpLength; | 250 : RecordObjectDumpLength; |
236 RecordFormatter.SetLineWidth(RecordWidth); | 251 RecordFormatter.SetLineWidth(RecordWidth); |
237 } | 252 } |
238 } | 253 } |
239 | 254 |
240 raw_ostream &ObjDumpStream::Error(uint64_t Bit) { | 255 raw_ostream &ObjDumpStream::ErrorAt(naclbitc::ErrorLevel Level, uint64_t Bit) { |
256 // Note: Since this method only prints the error line prefix, and | |
257 // lets the caller fill in the rest of the error, we can't stop | |
jvoung (off chromium)
2015/03/06 22:30:28
we can't stop "the" executable ?
Karl
2015/03/06 22:54:20
Done.
| |
258 // executable at this point. Instead, we let Flush empty the buffers, | |
259 // and print out existing errors, and then exit the executable. | |
260 if (NumErrors >= MaxErrors) | |
261 Flush(); | |
241 LastKnownBit = Bit; | 262 LastKnownBit = Bit; |
242 if (NumErrors >= MaxErrors) | 263 if (Level >= naclbitc::Error) |
243 Fatal(Bit, "Too many errors"); | 264 ++NumErrors; |
244 ++NumErrors; | 265 return naclbitc::ErrorAt(Comments(), Level, Bit); |
245 return PrintMessagePrefix("Error", Bit); | |
246 } | 266 } |
247 | 267 |
248 void ObjDumpStream::Fatal(uint64_t Bit, const std::string &Message) { | 268 void ObjDumpStream::FatalAt(uint64_t Bit, const std::string &Message) { |
249 LastKnownBit = Bit; | |
250 if (!Message.empty()) | 269 if (!Message.empty()) |
251 PrintMessagePrefix("Error", Bit) << Message << "\n"; | 270 naclbitc::ErrorAt(Comments(), naclbitc::Fatal, Bit) << Message << "\n"; |
252 Flush(); | 271 Flush(); |
253 llvm::report_fatal_error("Unable to continue"); | 272 report_fatal_error("Unable to continue"); |
254 } | 273 } |
255 | 274 |
256 void ObjDumpStream::Fatal(uint64_t Bit, | 275 void ObjDumpStream::FatalAt(uint64_t Bit, |
257 const llvm::NaClBitcodeRecordData &Record, | 276 const llvm::NaClBitcodeRecordData &Record, |
258 const std::string &Message) { | 277 const std::string &Message) { |
259 LastKnownBit = Bit; | 278 naclbitc::ErrorAt(Comments(), naclbitc::Fatal, Bit) << Message; |
260 PrintMessagePrefix("Error", Bit) << Message; | |
261 Write(Bit, Record); | 279 Write(Bit, Record); |
262 Flush(); | 280 Flush(); |
263 llvm::report_fatal_error("Unable to continue"); | 281 report_fatal_error("Unable to continue"); |
264 } | 282 } |
265 | 283 |
266 // Dumps the next line of text in the buffer. Returns the number of characters | 284 // Dumps the next line of text in the buffer. Returns the number of characters |
267 // printed. | 285 // printed. |
268 static size_t DumpLine(raw_ostream &Stream, | 286 static size_t DumpLine(raw_ostream &Stream, |
269 const std::string &Buffer, | 287 const std::string &Buffer, |
270 size_t &Index, | 288 size_t &Index, |
271 size_t Size) { | 289 size_t Size) { |
272 size_t Count = 0; | 290 size_t Count = 0; |
273 while (Index < Size) { | 291 while (Index < Size) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
319 // Dump next assembly line. | 337 // Dump next assembly line. |
320 DumpLine(Stream, AssemblyBuffer, AssemblyIndex, AssemblySize); | 338 DumpLine(Stream, AssemblyBuffer, AssemblyIndex, AssemblySize); |
321 Stream << '\n'; | 339 Stream << '\n'; |
322 } | 340 } |
323 } | 341 } |
324 | 342 |
325 // Print out messages and reset buffers. | 343 // Print out messages and reset buffers. |
326 Stream << MessageBuffer; | 344 Stream << MessageBuffer; |
327 ResetBuffers(); | 345 ResetBuffers(); |
328 if (NumErrors >= MaxErrors) { | 346 if (NumErrors >= MaxErrors) { |
329 // Note: we don't call Fatal here because that will call Flush, causing | 347 report_fatal_error("Too many errors, Unable to continue"); |
330 // an infinite loop. | |
331 Stream << "Error(" << NaClBitstreamReader::getBitAddress(LastKnownBit) | |
332 << "): Too many errors\n"; | |
333 llvm::report_fatal_error("Unable to continue"); | |
334 } | 348 } |
335 Stream.flush(); | 349 Stream.flush(); |
336 } | 350 } |
337 | 351 |
338 } | 352 } |
339 } | 353 } |
OLD | NEW |