diff options
author | Alp Toker <alp@nuanti.com> | 2014-07-01 02:41:55 +0000 |
---|---|---|
committer | Alp Toker <alp@nuanti.com> | 2014-07-01 02:41:55 +0000 |
commit | 41b937ca28362c2ff442cc04530902ed9b8c972d (patch) | |
tree | d3a9c3835bc5ca40837c6215223c1b776131f98c /examples | |
parent | 71f885d820d5180a62eea524db65de595d410ff7 (diff) |
clang-interpreter: interpret instead of JITing
Fixes the build when no targets are selected, or no native target is built.
This also better matches up with the description/title of the example and
demonstrates how clang can be used to run C++ on constrained environments
without file IO or executable memory permissions (e.g. iOS apps).
A comment is added explaining how to extend the demo with JIT support as
needed.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@212083 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'examples')
-rw-r--r-- | examples/clang-interpreter/CMakeLists.txt | 3 | ||||
-rw-r--r-- | examples/clang-interpreter/README.txt | 3 | ||||
-rw-r--r-- | examples/clang-interpreter/main.cpp | 6 |
3 files changed, 6 insertions, 6 deletions
diff --git a/examples/clang-interpreter/CMakeLists.txt b/examples/clang-interpreter/CMakeLists.txt index 10df7e7e06..6d78408f85 100644 --- a/examples/clang-interpreter/CMakeLists.txt +++ b/examples/clang-interpreter/CMakeLists.txt @@ -1,9 +1,8 @@ set(LLVM_LINK_COMPONENTS Core ExecutionEngine - JIT + Interpreter Support - nativecodegen ) add_clang_executable(clang-interpreter diff --git a/examples/clang-interpreter/README.txt b/examples/clang-interpreter/README.txt index 7dd45fad50..b81d3813a1 100644 --- a/examples/clang-interpreter/README.txt +++ b/examples/clang-interpreter/README.txt @@ -10,7 +10,8 @@ It demonstrates the following features: 3. Invoking the Clang compiler to lex, parse, syntax check, and then generate LLVM code. - 4. Use the LLVM JIT functionality to execute the final module. + 4. Use the LLVM interpreter functionality to execute the final module, with + guidance on how to extend the demo with JIT execution. 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 0f083c1514..c255f51cee 100644 --- a/examples/clang-interpreter/main.cpp +++ b/examples/clang-interpreter/main.cpp @@ -18,7 +18,6 @@ #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" @@ -43,11 +42,12 @@ std::string GetExecutablePath(const char *Argv0) { } static int Execute(llvm::Module *Mod, char * const *envp) { - llvm::InitializeNativeTarget(); + // To JIT instead of interpreting, call llvm::InitializeNativeTarget() here + // and pass ForceInterpreter=false to ExecutionEngine::create(). std::string Error; std::unique_ptr<llvm::ExecutionEngine> EE( - llvm::ExecutionEngine::createJIT(Mod, &Error)); + llvm::ExecutionEngine::create(Mod, /*ForceInterpreter*/ true, &Error)); if (!EE) { llvm::errs() << "unable to make execution engine: " << Error << "\n"; return 255; |