summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAlp Toker <alp@nuanti.com>2014-07-01 03:19:50 +0000
committerAlp Toker <alp@nuanti.com>2014-07-01 03:19:50 +0000
commit73e75f0db89eaa33b3a9cf8432aba75172d0ea98 (patch)
tree4d42e1b9ee17742d3015e92025cbd1cf5ae0a1b4 /examples
parent9a5685c64f31ffe26884b199620f8b33be063658 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212087 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'examples')
-rw-r--r--examples/clang-interpreter/CMakeLists.txt2
-rw-r--r--examples/clang-interpreter/README.txt3
-rw-r--r--examples/clang-interpreter/main.cpp6
3 files changed, 6 insertions, 5 deletions
diff --git a/examples/clang-interpreter/CMakeLists.txt b/examples/clang-interpreter/CMakeLists.txt
index 6d78408f85..d454539fda 100644
--- a/examples/clang-interpreter/CMakeLists.txt
+++ b/examples/clang-interpreter/CMakeLists.txt
@@ -2,7 +2,9 @@ set(LLVM_LINK_COMPONENTS
Core
ExecutionEngine
Interpreter
+ JIT
Support
+ native
)
add_clang_executable(clang-interpreter
diff --git a/examples/clang-interpreter/README.txt b/examples/clang-interpreter/README.txt
index b81d3813a1..7dd45fad50 100644
--- a/examples/clang-interpreter/README.txt
+++ b/examples/clang-interpreter/README.txt
@@ -10,8 +10,7 @@ It demonstrates the following features:
3. Invoking the Clang compiler to lex, parse, syntax check, and then generate
LLVM code.
- 4. Use the LLVM interpreter functionality to execute the final module, with
- guidance on how to extend the demo with JIT execution.
+ 4. Use the LLVM JIT functionality to execute the final module.
The implementation has many limitations and is not designed to be a full fledged
C interpreter. It is designed to demonstrate a simple but functional use of the
diff --git a/examples/clang-interpreter/main.cpp b/examples/clang-interpreter/main.cpp
index c255f51cee..fb9d298f0a 100644
--- a/examples/clang-interpreter/main.cpp
+++ b/examples/clang-interpreter/main.cpp
@@ -18,6 +18,7 @@
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
+#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Host.h"
@@ -42,12 +43,11 @@ std::string GetExecutablePath(const char *Argv0) {
}
static int Execute(llvm::Module *Mod, char * const *envp) {
- // To JIT instead of interpreting, call llvm::InitializeNativeTarget() here
- // and pass ForceInterpreter=false to ExecutionEngine::create().
+ llvm::InitializeNativeTarget();
std::string Error;
std::unique_ptr<llvm::ExecutionEngine> EE(
- llvm::ExecutionEngine::create(Mod, /*ForceInterpreter*/ true, &Error));
+ llvm::ExecutionEngine::create(Mod, /*ForceInterpreter*/ false, &Error));
if (!EE) {
llvm::errs() << "unable to make execution engine: " << Error << "\n";
return 255;