| 1 |
//===- unittests/Interpreter/InterpreterTestBase.h ------------------ C++ -===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#ifndef LLVM_CLANG_UNITTESTS_INTERPRETER_INTERPRETERTESTBASE_H |
| 10 |
#define LLVM_CLANG_UNITTESTS_INTERPRETER_INTERPRETERTESTBASE_H |
| 11 |
|
| 12 |
#include "llvm/ExecutionEngine/Orc/LLJIT.h" |
| 13 |
#include "llvm/Support/Error.h" |
| 14 |
#include "llvm/Support/ManagedStatic.h" |
| 15 |
#include "llvm/Support/TargetSelect.h" |
| 16 |
|
| 17 |
#include "gtest/gtest.h" |
| 18 |
|
| 19 |
#if defined(_AIX) || defined(__MVS__) |
| 20 |
#define CLANG_INTERPRETER_PLATFORM_CANNOT_CREATE_LLJIT |
| 21 |
#endif |
| 22 |
|
| 23 |
namespace clang { |
| 24 |
|
| 25 |
class InterpreterTestBase : public ::testing::Test { |
| 26 |
protected: |
| 27 |
static bool HostSupportsJIT() { |
| 28 |
#ifdef CLANG_INTERPRETER_PLATFORM_CANNOT_CREATE_LLJIT |
| 29 |
return false; |
| 30 |
#else |
| 31 |
if (auto JIT = llvm::orc::LLJITBuilder().create()) { |
| 32 |
return true; |
| 33 |
} else { |
| 34 |
llvm::consumeError(JIT.takeError()); |
| 35 |
return false; |
| 36 |
} |
| 37 |
#endif |
| 38 |
} |
| 39 |
|
| 40 |
void SetUp() override { |
| 41 |
// FIXME : WebAssembly doesn't currently support Jit (see |
| 42 |
// https: // github.com/llvm/llvm-project/pull/150977#discussion_r2237521095). |
| 43 |
// so this check of HostSupportsJIT has been skipped |
| 44 |
// over until support is added, and HostSupportsJIT can return true. |
| 45 |
#ifndef __EMSCRIPTEN__ |
| 46 |
if (!HostSupportsJIT()) |
| 47 |
GTEST_SKIP(); |
| 48 |
#endif |
| 49 |
} |
| 50 |
|
| 51 |
void TearDown() override {} |
| 52 |
|
| 53 |
static void SetUpTestSuite() { |
| 54 |
llvm::InitializeNativeTarget(); |
| 55 |
llvm::InitializeNativeTargetAsmPrinter(); |
| 56 |
} |
| 57 |
|
| 58 |
static void TearDownTestSuite() { llvm::llvm_shutdown(); } |
| 59 |
}; |
| 60 |
|
| 61 |
} // namespace clang |
| 62 |
|
| 63 |
#undef CLANG_INTERPRETER_PLATFORM_CANNOT_CREATE_LLJIT |
| 64 |
|
| 65 |
#endif // LLVM_CLANG_UNITTESTS_INTERPRETER_INTERPRETERTESTBASE_H |