[llvm-objcopy] [COFF] Fix warnings abuilt missing field initialization. NFC.
[llvm-complete.git] / unittests / ExecutionEngine / MCJIT / MCJITTestAPICommon.h
blobd3ebb95abc3a9ace263099eaa144f7a2a51e65fd
1 //===- MCJITTestBase.h - Common base class for MCJIT Unit tests ----------===//
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 // This class implements functionality shared by both MCJIT C API tests, and
11 // the C++ API tests.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_UNITTESTS_EXECUTIONENGINE_MCJIT_MCJITTESTAPICOMMON_H
16 #define LLVM_UNITTESTS_EXECUTIONENGINE_MCJIT_MCJITTESTAPICOMMON_H
18 #include "llvm/ADT/STLExtras.h"
19 #include "llvm/ADT/SmallVector.h"
20 #include "llvm/ADT/Triple.h"
21 #include "llvm/IR/LegacyPassManager.h"
22 #include "llvm/InitializePasses.h"
23 #include "llvm/Support/Host.h"
24 #include "llvm/Support/TargetSelect.h"
26 // Used to skip tests on unsupported architectures and operating systems.
27 // To skip a test, add this macro at the top of a test-case in a suite that
28 // inherits from MCJITTestBase. See MCJITTest.cpp for examples.
29 #define SKIP_UNSUPPORTED_PLATFORM \
30 do \
31 if (!ArchSupportsMCJIT() || !OSSupportsMCJIT()) \
32 return; \
33 while(0)
35 namespace llvm {
37 class MCJITTestAPICommon {
38 protected:
39 MCJITTestAPICommon()
40 : HostTriple(sys::getProcessTriple())
42 InitializeNativeTarget();
43 InitializeNativeTargetAsmPrinter();
45 // FIXME: It isn't at all clear why this is necesasry, but without it we
46 // fail to initialize the AssumptionCacheTracker.
47 initializeAssumptionCacheTrackerPass(*PassRegistry::getPassRegistry());
49 #ifdef _WIN32
50 // On Windows, generate ELF objects by specifying "-elf" in triple
51 HostTriple += "-elf";
52 #endif // _WIN32
53 HostTriple = Triple::normalize(HostTriple);
56 /// Returns true if the host architecture is known to support MCJIT
57 bool ArchSupportsMCJIT() {
58 Triple Host(HostTriple);
59 // If ARCH is not supported, bail
60 if (!is_contained(SupportedArchs, Host.getArch()))
61 return false;
63 // If ARCH is supported and has no specific sub-arch support
64 if (!is_contained(HasSubArchs, Host.getArch()))
65 return true;
67 // If ARCH has sub-arch support, find it
68 SmallVectorImpl<std::string>::const_iterator I = SupportedSubArchs.begin();
69 for(; I != SupportedSubArchs.end(); ++I)
70 if (Host.getArchName().startswith(*I))
71 return true;
73 return false;
76 /// Returns true if the host OS is known to support MCJIT
77 bool OSSupportsMCJIT() {
78 Triple Host(HostTriple);
80 if (find(UnsupportedEnvironments, Host.getEnvironment()) !=
81 UnsupportedEnvironments.end())
82 return false;
84 if (!is_contained(UnsupportedOSs, Host.getOS()))
85 return true;
87 return false;
90 std::string HostTriple;
91 SmallVector<Triple::ArchType, 4> SupportedArchs;
92 SmallVector<Triple::ArchType, 1> HasSubArchs;
93 SmallVector<std::string, 2> SupportedSubArchs; // We need to own the memory
94 SmallVector<Triple::OSType, 4> UnsupportedOSs;
95 SmallVector<Triple::EnvironmentType, 1> UnsupportedEnvironments;
98 } // namespace llvm
100 #endif