Andrew Kaylor | d2755af | 2013-04-29 17:49:40 +0000 | [diff] [blame] | 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. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef MCJIT_TEST_API_COMMON_H |
| 16 | #define MCJIT_TEST_API_COMMON_H |
| 17 | |
| 18 | #include "llvm/ADT/SmallVector.h" |
| 19 | #include "llvm/ADT/Triple.h" |
| 20 | #include "llvm/Support/Host.h" |
| 21 | #include "llvm/Support/TargetSelect.h" |
| 22 | |
| 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 \ |
| 27 | do \ |
| 28 | if (!ArchSupportsMCJIT() || !OSSupportsMCJIT()) \ |
| 29 | return; \ |
| 30 | while(0) |
| 31 | |
| 32 | namespace llvm { |
| 33 | |
| 34 | class MCJITTestAPICommon { |
| 35 | protected: |
| 36 | MCJITTestAPICommon() |
| 37 | : HostTriple(sys::getProcessTriple()) |
| 38 | { |
| 39 | InitializeNativeTarget(); |
| 40 | InitializeNativeTargetAsmPrinter(); |
| 41 | |
| 42 | #ifdef LLVM_ON_WIN32 |
| 43 | // On Windows, generate ELF objects by specifying "-elf" in triple |
| 44 | HostTriple += "-elf"; |
| 45 | #endif // LLVM_ON_WIN32 |
| 46 | HostTriple = Triple::normalize(HostTriple); |
| 47 | } |
| 48 | |
| 49 | /// Returns true if the host architecture is known to support MCJIT |
| 50 | bool ArchSupportsMCJIT() { |
| 51 | Triple Host(HostTriple); |
Renato Golin | 4e4464b | 2013-05-19 20:10:10 +0000 | [diff] [blame^] | 52 | // If ARCH is not supported, bail |
Andrew Kaylor | d2755af | 2013-04-29 17:49:40 +0000 | [diff] [blame] | 53 | if (std::find(SupportedArchs.begin(), SupportedArchs.end(), Host.getArch()) |
Renato Golin | 4e4464b | 2013-05-19 20:10:10 +0000 | [diff] [blame^] | 54 | == SupportedArchs.end()) |
Andrew Kaylor | d2755af | 2013-04-29 17:49:40 +0000 | [diff] [blame] | 55 | return false; |
Renato Golin | 4e4464b | 2013-05-19 20:10:10 +0000 | [diff] [blame^] | 56 | |
| 57 | // If ARCH is supported and has no specific sub-arch support |
| 58 | if (std::find(HasSubArchs.begin(), HasSubArchs.end(), Host.getArch()) |
| 59 | == HasSubArchs.end()) |
| 60 | return true; |
| 61 | |
| 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())) |
| 66 | return true; |
| 67 | |
| 68 | return false; |
Andrew Kaylor | d2755af | 2013-04-29 17:49:40 +0000 | [diff] [blame] | 69 | } |
| 70 | |
| 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()) { |
| 76 | return true; |
| 77 | } |
| 78 | return false; |
| 79 | } |
| 80 | |
| 81 | std::string HostTriple; |
| 82 | SmallVector<Triple::ArchType, 4> SupportedArchs; |
Renato Golin | 4e4464b | 2013-05-19 20:10:10 +0000 | [diff] [blame^] | 83 | SmallVector<Triple::ArchType, 1> HasSubArchs; |
| 84 | SmallVector<std::string, 2> SupportedSubArchs; // We need to own the memory |
Andrew Kaylor | d2755af | 2013-04-29 17:49:40 +0000 | [diff] [blame] | 85 | SmallVector<Triple::OSType, 4> UnsupportedOSs; |
| 86 | }; |
| 87 | |
| 88 | } // namespace llvm |
| 89 | |
| 90 | #endif // MCJIT_TEST_API_COMMON_H |
| 91 | |