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
#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"
}
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;