| Index: include/llvm/Bitcode/NaCl/NaClBitcodeMunge.h
|
| diff --git a/include/llvm/Bitcode/NaCl/NaClBitcodeMunge.h b/include/llvm/Bitcode/NaCl/NaClBitcodeMunge.h
|
| index 2d344ddf38bc6898491c8223be3c4c784fcb0199..d9a46ab91a2c0a36225fa89fa97b9bd74a8fc0ec 100644
|
| --- a/include/llvm/Bitcode/NaCl/NaClBitcodeMunge.h
|
| +++ b/include/llvm/Bitcode/NaCl/NaClBitcodeMunge.h
|
| @@ -13,7 +13,7 @@
|
| // Generates a bitcode memory buffer from an array containing 1 or
|
| // more PNaCl records. Used to test errors in PNaCl bitcode.
|
| //
|
| -// Bitcode records are modeleled using arrays using the format
|
| +// Bitcode records are modeled using arrays using the format
|
| // specified in NaClBitcodeMungeUtils.h.
|
| //
|
| // Note: Since the header record doesn't have any abbreviation indices
|
| @@ -47,7 +47,6 @@
|
|
|
| namespace llvm {
|
|
|
| -class NaClBitstreamWriter;
|
| class NaClBitCodeAbbrev;
|
|
|
| /// Base class to run tests on munged bitcode files.
|
| @@ -57,10 +56,21 @@ public:
|
| NaClBitcodeMunger(const uint64_t Records[], size_t RecordsSize,
|
| uint64_t RecordTerminator)
|
| : MungedBitcode(Records, RecordsSize, RecordTerminator),
|
| - RecordTerminator(RecordTerminator), WriteBlockID(-1), SetBID(-1),
|
| + RecordTerminator(RecordTerminator),
|
| DumpResults("Error: No previous dump results!\n"),
|
| - DumpStream(nullptr), Writer(nullptr), FoundErrors(false),
|
| - FatalBuffer(), FatalStream(FatalBuffer) {}
|
| + DumpStream(nullptr), FoundErrors(false), RunAsDeathTest(false) {}
|
| +
|
| + /// Returns true if running as death test.
|
| + bool getRunAsDeathTest() const {
|
| + return RunAsDeathTest;
|
| + }
|
| +
|
| + /// Sets death test flag. When true, output will be redirected to
|
| + /// the errs() (rather than buffered) so that the test can be
|
| + /// debugged.
|
| + void setRunAsDeathTest(bool NewValue) {
|
| + RunAsDeathTest = NewValue;
|
| + }
|
|
|
| /// Creates MungedInput and DumpStream for running tests, based on
|
| /// given Munges.
|
| @@ -88,52 +98,43 @@ public:
|
| return getLinesWithTextMatch(Prefix, true);
|
| }
|
|
|
| + /// When NewValue, use error recovery when writing bitcode during
|
| + /// next test.
|
| + void setTryToRecoverOnWrite(bool NewValue) {
|
| + WriteFlags.setTryToRecover(NewValue);
|
| + }
|
| +
|
| + /// When NewValue, write bad abbreviation index into bitcode when
|
| + /// writing during next test.
|
| + void setWriteBadAbbrevIndex(bool NewValue) {
|
| + WriteFlags.setWriteBadAbbrevIndex(NewValue);
|
| + }
|
| +
|
| protected:
|
| // The bitcode records being munged.
|
| NaClMungedBitcode MungedBitcode;
|
| // The value used as record terminator.
|
| uint64_t RecordTerminator;
|
| - // The block ID associated with the block being written.
|
| - int WriteBlockID;
|
| - // The SetBID for the blockinfo block.
|
| - int SetBID;
|
| // The results buffer of the last dump.
|
| std::string DumpResults;
|
| // The memory buffer containing the munged input.
|
| std::unique_ptr<MemoryBuffer> MungedInput;
|
| // The stream containing errors and the objdump of the generated bitcode file.
|
| raw_ostream *DumpStream;
|
| - // The bitstream writer to use to generate the bitcode file.
|
| - NaClBitstreamWriter *Writer;
|
| // True if any errors were reported.
|
| bool FoundErrors;
|
| - // The buffer to hold the generated fatal message.
|
| - std::string FatalBuffer;
|
| - // The stream to write the fatal message to.
|
| - raw_string_ostream FatalStream;
|
| - // The stack of maximum abbreviation indices allowed by block enter record.
|
| - SmallVector<uint64_t, 3> AbbrevIndexLimitStack;
|
| // The buffer for the contents of the munged input.
|
| SmallVector<char, 1024> MungedInputBuffer;
|
| + /// The write flags to use when writing bitcode.
|
| + NaClMungedBitcode::WriteFlags WriteFlags;
|
| + // Flag to redirect dump stream if running death test.
|
| + bool RunAsDeathTest;
|
|
|
| // Records that an error occurred, and returns stream to print error
|
| // message to.
|
| raw_ostream &Error() {
|
| FoundErrors = true;
|
| - return *DumpStream << "Error: ";
|
| - }
|
| -
|
| - // Returns stream to print fatal error message to.
|
| - // Note: Once the fatal error message has been dumped to the stream,
|
| - // one must call ReportFatalError to display the error and terminate
|
| - // execution.
|
| - raw_ostream &Fatal() {
|
| - return FatalStream << "Fatal: ";
|
| - }
|
| -
|
| - // Displays the fatal error message and exits the program.
|
| - void ReportFatalError() {
|
| - report_fatal_error(FatalStream.str());
|
| + return getDumpStream() << "Error: ";
|
| }
|
|
|
| // Returns the lines containing the given Substring, from the string
|
| @@ -142,14 +143,12 @@ protected:
|
| std::string getLinesWithTextMatch(const std::string &Substring,
|
| bool MustBePrefix = false) const;
|
|
|
| - // Writes out munged bitcode records.
|
| - void writeMungedBitcode(const NaClMungedBitcode &Bitcode, bool AddHeader);
|
| -
|
| - // Emits the given record to the bitcode file.
|
| - void emitRecord(const NaClBitcodeAbbrevRecord &Record);
|
| -
|
| - // Converts the abbreviation record to the corresponding abbreviation.
|
| - NaClBitCodeAbbrev *buildAbbrev(const NaClBitcodeAbbrevRecord &Record);
|
| + // Returns the log stream to use. When running death tests, redirect output
|
| + // to the error stream (rather than buffering in DumpStream), so that
|
| + // the output can be seen in gtest death tests.
|
| + raw_ostream &getDumpStream() const {
|
| + return RunAsDeathTest ? errs() : *DumpStream;
|
| + }
|
| };
|
|
|
| /// Class to run tests for function llvm::NaClObjDump.
|
| @@ -159,8 +158,7 @@ public:
|
| /// Creates a bitcode munger, based on the given array of values.
|
| NaClObjDumpMunger(const uint64_t Records[], size_t RecordsSize,
|
| uint64_t RecordTerminator)
|
| - : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator),
|
| - RunAsDeathTest(false) {}
|
| + : NaClBitcodeMunger(Records, RecordsSize, RecordTerminator) {}
|
|
|
| /// Runs function NaClObjDump on the sequence of records associated
|
| /// with the instance. The memory buffer containing the bitsequence
|
| @@ -178,18 +176,6 @@ public:
|
| NoAssembly);
|
| }
|
|
|
| - /// Returns true if running as death test.
|
| - bool getRunAsDeathTest() const {
|
| - return RunAsDeathTest;
|
| - }
|
| -
|
| - /// Sets death test flag. When true, output will be redirected to
|
| - /// the errs() (rather than buffered) so that the test can be
|
| - /// debugged.
|
| - void setRunAsDeathTest(bool NewValue) {
|
| - RunAsDeathTest = NewValue;
|
| - }
|
| -
|
| /// Same as above except it runs function NaClObjDump with flags
|
| /// NoRecords and NoAssembly set to false, and AddHeader set to true.
|
| bool runTest(const char *TestName) {
|
| @@ -235,11 +221,6 @@ public:
|
| size_t MungesSize) {
|
| return runTestWithFlags(TestName, Munges, MungesSize, true, true, true);
|
| }
|
| -
|
| -private:
|
| - // Flag to redirect dump stream if running death test.
|
| - bool RunAsDeathTest;
|
| -
|
| };
|
|
|
| // Class to run tests for function NaClParseBitcodeFile.
|
|
|