blob: 35869096a99c6c7d05e9e821d29378bcf36c085f [file] [log] [blame]
Karl Schimpf2e7daef2015-01-09 13:04:13 -08001//===- 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
Jim Stichnoth98da9662015-06-27 06:38:08 -070018#pragma clang diagnostic push
19#pragma clang diagnostic ignored "-Wunused-parameter"
Karl Schimpf2e7daef2015-01-09 13:04:13 -080020#include "llvm/Bitcode/NaCl/NaClBitcodeMunge.h"
Jim Stichnoth98da9662015-06-27 06:38:08 -070021#pragma clang diagnostic pop
Karl Schimpf2e7daef2015-01-09 13:04:13 -080022
Karl Schimpfd8b32892015-04-16 15:47:25 -070023#include "IceClFlags.h"
24
Karl Schimpf2e7daef2015-01-09 13:04:13 -080025namespace IceTest {
26
27// Class to run tests on Subzero's bitcode parser. Runs a Subzero
28// translation, using (possibly) edited bitcode record values. For
29// more details on how to represent the input arrays, see
30// NaClBitcodeMunge.h.
31class SubzeroBitcodeMunger : public llvm::NaClBitcodeMunger {
32public:
33 SubzeroBitcodeMunger(const uint64_t Records[], size_t RecordSize,
34 uint64_t RecordTerminator)
Karl Schimpfd8b32892015-04-16 15:47:25 -070035 : llvm::NaClBitcodeMunger(Records, RecordSize, RecordTerminator) {
36 resetMungeFlags();
37 }
Karl Schimpf2e7daef2015-01-09 13:04:13 -080038
John Porto8eefffa2015-06-11 15:14:37 -070039 /// Runs PNaClTranslator to parse and (optionally) translate bitcode records
40 /// (with defined record Munges), and puts output into DumpResults. Returns
41 /// true if parse is successful.
42 bool runTest(const uint64_t Munges[], size_t MungeSize,
43 bool DisableTranslation = false);
Karl Schimpf2e7daef2015-01-09 13:04:13 -080044
45 /// Same as above, but without any edits.
John Porto8eefffa2015-06-11 15:14:37 -070046 bool runTest(bool DisableTranslation = false) {
Karl Schimpf2e7daef2015-01-09 13:04:13 -080047 uint64_t NoMunges[] = {0};
John Porto8eefffa2015-06-11 15:14:37 -070048 return runTest(NoMunges, 0, DisableTranslation);
Karl Schimpf2e7daef2015-01-09 13:04:13 -080049 }
Karl Schimpfd8b32892015-04-16 15:47:25 -070050
Karl Schimpfd8b32892015-04-16 15:47:25 -070051 /// Flags to use to run tests. Use to change default assumptions.
52 Ice::ClFlags Flags;
53
54private:
55 void resetMungeFlags();
Karl Schimpf2e7daef2015-01-09 13:04:13 -080056};
57
58} // end of namespace IceTest
59
60#endif // SUBZERO_UNITTEST_BITCODEMUNGE_H