Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Side by Side Diff: lib/Bitcode/NaCl/TestUtils/NaClBitcodeMunge.cpp

Issue 940243003: PNaCl localmod mods in LLVM to 223109 (local files only) (Closed)
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 //===--- Bitcode/NaCl/TestUtils/NaClBitcodeMunge.cpp - Bitcode Munger -----===// 1 //===--- Bitcode/NaCl/TestUtils/NaClBitcodeMunge.cpp - Bitcode Munger -----===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
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 // Bitcode writer/munger implementation for testing. 10 // Bitcode writer/munger implementation for testing.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 SetBID = -1; 53 SetBID = -1;
54 writeMungedData(Munges, MungesSize, AddHeader); 54 writeMungedData(Munges, MungesSize, AddHeader);
55 55
56 std::string OutBuffer; 56 std::string OutBuffer;
57 raw_string_ostream BitcodeStrm(OutBuffer); 57 raw_string_ostream BitcodeStrm(OutBuffer);
58 for (SmallVectorImpl<char>::const_iterator 58 for (SmallVectorImpl<char>::const_iterator
59 Iter = StreamBuffer.begin(), IterEnd = StreamBuffer.end(); 59 Iter = StreamBuffer.begin(), IterEnd = StreamBuffer.end();
60 Iter != IterEnd; ++Iter) { 60 Iter != IterEnd; ++Iter) {
61 BitcodeStrm << *Iter; 61 BitcodeStrm << *Iter;
62 } 62 }
63 MungedInput.reset(MemoryBuffer::getMemBufferCopy(BitcodeStrm.str(), 63 MungedInput = MemoryBuffer::getMemBufferCopy(BitcodeStrm.str(), TestName);
64 TestName));
65 } 64 }
66 65
67 void NaClBitcodeMunger::cleanupTest() { 66 void NaClBitcodeMunger::cleanupTest() {
68 MungedInput.reset(); 67 MungedInput.reset();
69 assert(DumpStream && "Dump stream removed before cleanup!"); 68 assert(DumpStream && "Dump stream removed before cleanup!");
70 DumpStream->flush(); 69 DumpStream->flush();
71 delete DumpStream; 70 delete DumpStream;
72 DumpStream = nullptr; 71 DumpStream = nullptr;
73 Writer = nullptr; 72 Writer = nullptr;
74 } 73 }
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 ReportFatalError(); 340 ReportFatalError();
342 } 341 }
343 } 342 }
344 return Abbrev; 343 return Abbrev;
345 } 344 }
346 345
347 bool NaClObjDumpMunger::runTestWithFlags( 346 bool NaClObjDumpMunger::runTestWithFlags(
348 const char *Name, const uint64_t Munges[], size_t MungesSize, 347 const char *Name, const uint64_t Munges[], size_t MungesSize,
349 bool AddHeader, bool NoRecords, bool NoAssembly) { 348 bool AddHeader, bool NoRecords, bool NoAssembly) {
350 setupTest(Name, Munges, MungesSize, AddHeader); 349 setupTest(Name, Munges, MungesSize, AddHeader);
350 // TODO(jvoung,kschimpf): Should NaClObjDump take a MemoryBufferRef
351 // like the parser?
Karl 2015/02/20 17:07:02 Probably. File an issue and I will work on it.
jvoung (off chromium) 2015/02/20 17:38:21 Okay thanks, filed: https://code.google.com/p/nat
351 if (NaClObjDump(MungedInput.get(), *DumpStream, NoRecords, NoAssembly)) 352 if (NaClObjDump(MungedInput.get(), *DumpStream, NoRecords, NoAssembly))
352 FoundErrors = true; 353 FoundErrors = true;
353 cleanupTest(); 354 cleanupTest();
354 return !FoundErrors; 355 return !FoundErrors;
355 } 356 }
356 357
357 bool NaClParseBitcodeMunger::runTest( 358 bool NaClParseBitcodeMunger::runTest(
358 const char *Name, const uint64_t Munges[], size_t MungesSize, 359 const char *Name, const uint64_t Munges[], size_t MungesSize,
359 bool VerboseErrors) { 360 bool VerboseErrors) {
360 bool AddHeader = true; 361 bool AddHeader = true;
361 setupTest(Name, Munges, MungesSize, AddHeader); 362 setupTest(Name, Munges, MungesSize, AddHeader);
362 LLVMContext &Context = getGlobalContext(); 363 LLVMContext &Context = getGlobalContext();
363 raw_ostream *VerboseStrm = VerboseErrors ? DumpStream : nullptr; 364 raw_ostream *VerboseStrm = VerboseErrors ? DumpStream : nullptr;
364 ErrorOr<Module *> ModuleOrError = 365 ErrorOr<Module *> ModuleOrError =
365 NaClParseBitcodeFile(MungedInput.get(), Context, VerboseStrm); 366 NaClParseBitcodeFile(MungedInput->getMemBufferRef(), Context,
367 VerboseStrm);
366 if (ModuleOrError) { 368 if (ModuleOrError) {
367 if (VerboseErrors) 369 if (VerboseErrors)
368 *DumpStream << "Successful parse!\n"; 370 *DumpStream << "Successful parse!\n";
369 delete ModuleOrError.get(); 371 delete ModuleOrError.get();
370 } else { 372 } else {
371 Error() << ModuleOrError.getError().message() << "\n"; 373 Error() << ModuleOrError.getError().message() << "\n";
372 } 374 }
373 cleanupTest(); 375 cleanupTest();
374 return !FoundErrors; 376 return !FoundErrors;
375 } 377 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698