Karl Schimpf | 2e7daef | 2015-01-09 13:04:13 -0800 | [diff] [blame] | 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" |
Karl Schimpf | 2e7daef | 2015-01-09 13:04:13 -0800 | [diff] [blame] | 17 | #include "IceTypes.h" |
Antonio Maiorano | ca8a16e | 2020-11-10 16:56:20 -0500 | [diff] [blame] | 18 | #include "PNaClTranslator.h" |
Karl Schimpf | 2e7daef | 2015-01-09 13:04:13 -0800 | [diff] [blame] | 19 | |
| 20 | namespace IceTest { |
| 21 | |
Karl Schimpf | d8b3289 | 2015-04-16 15:47:25 -0700 | [diff] [blame] | 22 | void IceTest::SubzeroBitcodeMunger::resetMungeFlags() { |
Karl Schimpf | d469994 | 2016-04-02 09:55:31 -0700 | [diff] [blame] | 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); |
Karl Schimpf | d8b3289 | 2015-04-16 15:47:25 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Karl Schimpf | cbb1d3d | 2015-06-08 09:25:15 -0700 | [diff] [blame] | 33 | bool IceTest::SubzeroBitcodeMunger::runTest(const uint64_t Munges[], |
John Porto | 8eefffa | 2015-06-11 15:14:37 -0700 | [diff] [blame] | 34 | size_t MungeSize, |
| 35 | bool DisableTranslation) { |
Karl Schimpf | d8b3289 | 2015-04-16 15:47:25 -0700 | [diff] [blame] | 36 | const bool AddHeader = true; |
Karl Schimpf | cbb1d3d | 2015-06-08 09:25:15 -0700 | [diff] [blame] | 37 | setupTest(Munges, MungeSize, AddHeader); |
Jim Stichnoth | 98ba006 | 2016-03-07 09:26:22 -0800 | [diff] [blame] | 38 | Ice::GlobalContext Ctx(DumpStream, DumpStream, DumpStream, nullptr); |
Karl Schimpf | e8457a2 | 2016-03-31 10:20:23 -0700 | [diff] [blame] | 39 | Ctx.startWorkerThreads(); |
Jim Stichnoth | bbca754 | 2015-02-11 16:08:31 -0800 | [diff] [blame] | 40 | Ice::PNaClTranslator Translator(&Ctx); |
Karl Schimpf | cbb1d3d | 2015-06-08 09:25:15 -0700 | [diff] [blame] | 41 | const char *BufferName = "Test"; |
Karl Schimpf | d469994 | 2016-04-02 09:55:31 -0700 | [diff] [blame] | 42 | Ice::ClFlags::Flags.setDisableTranslation(DisableTranslation); |
Karl Schimpf | cbb1d3d | 2015-06-08 09:25:15 -0700 | [diff] [blame] | 43 | Translator.translateBuffer(BufferName, MungedInput.get()); |
Karl Schimpf | e8457a2 | 2016-03-31 10:20:23 -0700 | [diff] [blame] | 44 | Ctx.waitForWorkerThreads(); |
Karl Schimpf | 2e7daef | 2015-01-09 13:04:13 -0800 | [diff] [blame] | 45 | |
| 46 | cleanupTest(); |
Jim Stichnoth | fa4efea | 2015-01-27 05:06:03 -0800 | [diff] [blame] | 47 | return Translator.getErrorStatus().value() == 0; |
Karl Schimpf | 2e7daef | 2015-01-09 13:04:13 -0800 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | } // end of namespace IceTest |