Skip to content

Commit 60c88cb

Browse files
committed
clang-interpreter: use LLVM interpreter if JIT is unavailable
Update the strategy in r212083 to try JIT first and otherwise fall back to the interpreter. This gives the best of both worlds and still builds fine with no targets enabled. Requires supporting changes from LLVM r212086. llvm-svn: 212087
1 parent 568c31f commit 60c88cb

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

clang/examples/clang-interpreter/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ set(LLVM_LINK_COMPONENTS
22
Core
33
ExecutionEngine
44
Interpreter
5+
JIT
56
Support
7+
native
68
)
79

810
add_clang_executable(clang-interpreter

clang/examples/clang-interpreter/README.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ It demonstrates the following features:
1010
3. Invoking the Clang compiler to lex, parse, syntax check, and then generate
1111
LLVM code.
1212

13-
4. Use the LLVM interpreter functionality to execute the final module, with
14-
guidance on how to extend the demo with JIT execution.
13+
4. Use the LLVM JIT functionality to execute the final module.
1514

1615
The implementation has many limitations and is not designed to be a full fledged
1716
C interpreter. It is designed to demonstrate a simple but functional use of the

clang/examples/clang-interpreter/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "clang/Frontend/TextDiagnosticPrinter.h"
1919
#include "llvm/ADT/SmallString.h"
2020
#include "llvm/ExecutionEngine/ExecutionEngine.h"
21+
#include "llvm/ExecutionEngine/JIT.h"
2122
#include "llvm/IR/Module.h"
2223
#include "llvm/Support/FileSystem.h"
2324
#include "llvm/Support/Host.h"
@@ -42,12 +43,11 @@ std::string GetExecutablePath(const char *Argv0) {
4243
}
4344

4445
static int Execute(llvm::Module *Mod, char * const *envp) {
45-
// To JIT instead of interpreting, call llvm::InitializeNativeTarget() here
46-
// and pass ForceInterpreter=false to ExecutionEngine::create().
46+
llvm::InitializeNativeTarget();
4747

4848
std::string Error;
4949
std::unique_ptr<llvm::ExecutionEngine> EE(
50-
llvm::ExecutionEngine::create(Mod, /*ForceInterpreter*/ true, &Error));
50+
llvm::ExecutionEngine::create(Mod, /*ForceInterpreter*/ false, &Error));
5151
if (!EE) {
5252
llvm::errs() << "unable to make execution engine: " << Error << "\n";
5353
return 255;

0 commit comments

Comments
 (0)