BrainF example: fixing segfault caused by outdated code with missing MCJIT dependency
Differential Revision: https://reviews.llvm.org/D26280
llvm-svn: 289857
GitOrigin-RevId: b76f6c2745f7afb5912ce13110f4e9bd2405f47b
diff --git a/examples/BrainF/BrainFDriver.cpp b/examples/BrainF/BrainFDriver.cpp
index 686f476..57a86fb 100644
--- a/examples/BrainF/BrainFDriver.cpp
+++ b/examples/BrainF/BrainFDriver.cpp
@@ -29,6 +29,7 @@
#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/ExecutionEngine/ExecutionEngine.h"
#include "llvm/ExecutionEngine/GenericValue.h"
+#include "llvm/ExecutionEngine/MCJIT.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
@@ -153,10 +154,15 @@
//Write it out
if (JIT) {
InitializeNativeTarget();
+ InitializeNativeTargetAsmPrinter();
outs() << "------- Running JIT -------\n";
Module &M = *Mod;
ExecutionEngine *ee = EngineBuilder(std::move(Mod)).create();
+ if (!ee) {
+ errs() << "Error: execution engine creation failed.\n";
+ abort();
+ }
std::vector<GenericValue> args;
Function *brainf_func = M.getFunction("brainf");
GenericValue gv = ee->runFunction(brainf_func, args);
diff --git a/examples/BrainF/CMakeLists.txt b/examples/BrainF/CMakeLists.txt
index cf1cf1b..7b44b3a 100644
--- a/examples/BrainF/CMakeLists.txt
+++ b/examples/BrainF/CMakeLists.txt
@@ -3,6 +3,7 @@
Core
ExecutionEngine
MC
+ MCJIT
Support
nativecodegen
)