• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- BitcodeMunge.h - 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. Uses NaCl's
11 // bitcode munger to do this.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #ifndef SUBZERO_UNITTEST_BITCODEMUNGE_H
16 #define SUBZERO_UNITTEST_BITCODEMUNGE_H
17 
18 #pragma clang diagnostic push
19 #pragma clang diagnostic ignored "-Wunused-parameter"
20 #include "llvm/Bitcode/NaCl/NaClBitcodeMunge.h"
21 #pragma clang diagnostic pop
22 
23 #include "IceClFlags.h"
24 #include "IceGlobalContext.h"
25 
26 namespace IceTest {
27 
28 // Class to run tests on Subzero's bitcode parser. Runs a Subzero
29 // translation, using (possibly) edited bitcode record values.  For
30 // more details on how to represent the input arrays, see
31 // NaClBitcodeMunge.h.
32 class SubzeroBitcodeMunger : public llvm::NaClBitcodeMunger {
33 public:
SubzeroBitcodeMunger(const uint64_t Records[],size_t RecordSize,uint64_t RecordTerminator)34   SubzeroBitcodeMunger(const uint64_t Records[], size_t RecordSize,
35                        uint64_t RecordTerminator)
36       : llvm::NaClBitcodeMunger(Records, RecordSize, RecordTerminator) {
37     resetMungeFlags();
38   }
39 
40   /// Runs PNaClTranslator to parse and (optionally) translate bitcode records
41   /// (with defined record Munges), and puts output into DumpResults. Returns
42   /// true if parse is successful.
43   bool runTest(const uint64_t Munges[], size_t MungeSize,
44                bool DisableTranslation = false);
45 
46   /// Same as above, but without any edits.
47   bool runTest(bool DisableTranslation = false) {
48     uint64_t NoMunges[] = {0};
49     return runTest(NoMunges, 0, DisableTranslation);
50   }
51 
52 private:
53   void resetMungeFlags();
54 };
55 
56 } // end of namespace IceTest
57 
58 #endif // SUBZERO_UNITTEST_BITCODEMUNGE_H
59