1 //===- MCJITTestBase.h - Common base class for MCJIT Unit tests ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class implements functionality shared by both MCJIT C API tests, and
13 //===----------------------------------------------------------------------===//
15 #ifndef MCJIT_TEST_API_COMMON_H
16 #define MCJIT_TEST_API_COMMON_H
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/Triple.h"
20 #include "llvm/Support/Host.h"
21 #include "llvm/Support/TargetSelect.h"
23 // Used to skip tests on unsupported architectures and operating systems.
24 // To skip a test, add this macro at the top of a test-case in a suite that
25 // inherits from MCJITTestBase. See MCJITTest.cpp for examples.
26 #define SKIP_UNSUPPORTED_PLATFORM \
28 if (!ArchSupportsMCJIT() || !OSSupportsMCJIT()) \
34 class MCJITTestAPICommon {
37 : HostTriple(sys::getProcessTriple())
39 InitializeNativeTarget();
40 InitializeNativeTargetAsmPrinter();
43 // On Windows, generate ELF objects by specifying "-elf" in triple
45 #endif // LLVM_ON_WIN32
46 HostTriple = Triple::normalize(HostTriple);
49 /// Returns true if the host architecture is known to support MCJIT
50 bool ArchSupportsMCJIT() {
51 Triple Host(HostTriple);
52 // If ARCH is not supported, bail
53 if (std::find(SupportedArchs.begin(), SupportedArchs.end(), Host.getArch())
54 == SupportedArchs.end())
57 // If ARCH is supported and has no specific sub-arch support
58 if (std::find(HasSubArchs.begin(), HasSubArchs.end(), Host.getArch())
62 // If ARCH has sub-arch support, find it
63 SmallVectorImpl<std::string>::const_iterator I = SupportedSubArchs.begin();
64 for(; I != SupportedSubArchs.end(); ++I)
65 if (Host.getArchName().startswith(I->c_str()))
71 /// Returns true if the host OS is known to support MCJIT
72 bool OSSupportsMCJIT() {
73 Triple Host(HostTriple);
74 if (std::find(UnsupportedOSs.begin(), UnsupportedOSs.end(), Host.getOS())
75 == UnsupportedOSs.end()) {
81 std::string HostTriple;
82 SmallVector<Triple::ArchType, 4> SupportedArchs;
83 SmallVector<Triple::ArchType, 1> HasSubArchs;
84 SmallVector<std::string, 2> SupportedSubArchs; // We need to own the memory
85 SmallVector<Triple::OSType, 4> UnsupportedOSs;
90 #endif // MCJIT_TEST_API_COMMON_H