• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- BitcodeMunge.cpp - Subzero Bitcode Munger ----------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Test harness for testing malformed bitcode files in Subzero.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "BitcodeMunge.h"
15 #include "IceCfg.h"
16 #include "IceClFlags.h"
17 #include "PNaClTranslator.h"
18 #include "IceTypes.h"
19 
20 namespace IceTest {
21 
resetMungeFlags()22 void IceTest::SubzeroBitcodeMunger::resetMungeFlags() {
23   Ice::ClFlags::Flags.setAllowErrorRecovery(true);
24   Ice::ClFlags::Flags.setDisableTranslation(false);
25   Ice::ClFlags::Flags.setGenerateUnitTestMessages(true);
26   Ice::ClFlags::Flags.setOptLevel(Ice::Opt_m1);
27   Ice::ClFlags::Flags.setOutFileType(Ice::FT_Iasm);
28   Ice::ClFlags::Flags.setTargetArch(Ice::Target_X8632);
29   Ice::ClFlags::Flags.setNumTranslationThreads(0);
30   Ice::ClFlags::Flags.setParseParallel(false);
31 }
32 
runTest(const uint64_t Munges[],size_t MungeSize,bool DisableTranslation)33 bool IceTest::SubzeroBitcodeMunger::runTest(const uint64_t Munges[],
34                                             size_t MungeSize,
35                                             bool DisableTranslation) {
36   const bool AddHeader = true;
37   setupTest(Munges, MungeSize, AddHeader);
38   Ice::GlobalContext Ctx(DumpStream, DumpStream, DumpStream, nullptr);
39   Ctx.startWorkerThreads();
40   Ice::PNaClTranslator Translator(&Ctx);
41   const char *BufferName = "Test";
42   Ice::ClFlags::Flags.setDisableTranslation(DisableTranslation);
43   Translator.translateBuffer(BufferName, MungedInput.get());
44   Ctx.waitForWorkerThreads();
45 
46   cleanupTest();
47   return Translator.getErrorStatus().value() == 0;
48 }
49 
50 } // end of namespace IceTest
51