1b2859b51d094e30a1f0fa6d7e6e8c80f4d2484a
[oota-llvm.git] / unittests / ExecutionEngine / Orc / OrcTestCommon.h
1 //===------ OrcTestCommon.h - Utilities for Orc Unit Tests ------*- 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 // Common utilities for the Orc unit tests.
11 //
12 //===----------------------------------------------------------------------===//
13
14
15 #ifndef LLVM_UNITTESTS_EXECUTIONENGINE_ORC_ORCTESTCOMMON_H
16 #define LLVM_UNITTESTS_EXECUTIONENGINE_ORC_ORCTESTCOMMON_H
17
18 #include "llvm/IR/Function.h"
19 #include "llvm/IR/IRBuilder.h"
20 #include "llvm/IR/LLVMContext.h"
21 #include "llvm/IR/Module.h"
22 #include "llvm/IR/TypeBuilder.h"
23 #include <memory>
24
25 namespace llvm {
26
27   class ModuleBuilder {
28   public:
29     ModuleBuilder(LLVMContext &Context, StringRef Triple,
30                   StringRef Name);
31
32     template <typename FuncType>
33     Function* createFunctionDecl(Module *M, StringRef Name) {
34       return Function::Create(
35                TypeBuilder<FuncType, false>::get(M->getContext()),
36                GlobalValue::ExternalLinkage, Name, M);
37     }
38
39     Module* getModule() { return M.get(); }
40     const Module* getModule() const { return M.get(); }
41     std::unique_ptr<Module> takeModule() { return std::move(M); }
42
43   private:
44     std::unique_ptr<Module> M;
45     IRBuilder<> Builder;
46   };
47
48   // Dummy struct type.
49   struct DummyStruct {
50     int X[256];
51   };
52
53   // TypeBuilder specialization for DummyStruct.
54   template <bool XCompile>
55   class TypeBuilder<DummyStruct, XCompile> {
56   public:
57     static StructType *get(LLVMContext &Context) {
58       return StructType::get(
59           TypeBuilder<types::i<32>[256], XCompile>::get(Context), nullptr);
60     }
61   };
62
63
64 } // namespace llvm
65
66 #endif