diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2015-05-27 18:44:32 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2015-05-27 18:44:32 +0000 |
commit | 5a5ac124e1efaf208671f01c46edb15f29ed2a0b (patch) | |
tree | a6140557876943cdd800ee997c9317283394b22c /examples/ExceptionDemo | |
parent | f03b5bed27d0d2eafd68562ce14f8b5e3f1f0801 (diff) |
Diffstat (limited to 'examples/ExceptionDemo')
-rw-r--r-- | examples/ExceptionDemo/CMakeLists.txt | 5 | ||||
-rw-r--r-- | examples/ExceptionDemo/ExceptionDemo.cpp | 56 |
2 files changed, 30 insertions, 31 deletions
diff --git a/examples/ExceptionDemo/CMakeLists.txt b/examples/ExceptionDemo/CMakeLists.txt index 9cadd94c24a59..b4354f66f0d66 100644 --- a/examples/ExceptionDemo/CMakeLists.txt +++ b/examples/ExceptionDemo/CMakeLists.txt @@ -3,6 +3,7 @@ set(LLVM_LINK_COMPONENTS ExecutionEngine MC MCJIT + RuntimeDyld Support nativecodegen ) @@ -11,8 +12,10 @@ set(LLVM_LINK_COMPONENTS set(LLVM_REQUIRES_EH 1) set(LLVM_REQUIRES_RTTI 1) +set(LLVM_BUILD_EXAMPLES OFF) + add_llvm_example(ExceptionDemo ExceptionDemo.cpp ) -set_target_properties(ExceptionDemo PROPERTIES ENABLE_EXPORTS 1) +export_executable_symbols(ExceptionDemo) diff --git a/examples/ExceptionDemo/ExceptionDemo.cpp b/examples/ExceptionDemo/ExceptionDemo.cpp index d50c7769526d9..81337c4823b04 100644 --- a/examples/ExceptionDemo/ExceptionDemo.cpp +++ b/examples/ExceptionDemo/ExceptionDemo.cpp @@ -48,6 +48,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/ADT/STLExtras.h" #include "llvm/IR/Verifier.h" #include "llvm/ExecutionEngine/MCJIT.h" #include "llvm/ExecutionEngine/SectionMemoryManager.h" @@ -56,8 +57,8 @@ #include "llvm/IR/IRBuilder.h" #include "llvm/IR/Intrinsics.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/LegacyPassManager.h" #include "llvm/IR/Module.h" -#include "llvm/PassManager.h" #include "llvm/Support/Dwarf.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Target/TargetOptions.h" @@ -1122,14 +1123,11 @@ static llvm::BasicBlock *createCatchBlock(llvm::LLVMContext &context, /// @param numExceptionsToCatch length of exceptionTypesToCatch array /// @param exceptionTypesToCatch array of type info types to "catch" /// @returns generated function -static -llvm::Function *createCatchWrappedInvokeFunction(llvm::Module &module, - llvm::IRBuilder<> &builder, - llvm::FunctionPassManager &fpm, - llvm::Function &toInvoke, - std::string ourId, - unsigned numExceptionsToCatch, - unsigned exceptionTypesToCatch[]) { +static llvm::Function *createCatchWrappedInvokeFunction( + llvm::Module &module, llvm::IRBuilder<> &builder, + llvm::legacy::FunctionPassManager &fpm, llvm::Function &toInvoke, + std::string ourId, unsigned numExceptionsToCatch, + unsigned exceptionTypesToCatch[]) { llvm::LLVMContext &context = module.getContext(); llvm::Function *toPrint32Int = module.getFunction("print32Int"); @@ -1295,10 +1293,11 @@ llvm::Function *createCatchWrappedInvokeFunction(llvm::Module &module, // (_Unwind_Exception instance). This member tells us whether or not // the exception is foreign. llvm::Value *unwindExceptionClass = - builder.CreateLoad(builder.CreateStructGEP( - builder.CreatePointerCast(unwindException, - ourUnwindExceptionType->getPointerTo()), - 0)); + builder.CreateLoad(builder.CreateStructGEP( + ourUnwindExceptionType, + builder.CreatePointerCast(unwindException, + ourUnwindExceptionType->getPointerTo()), + 0)); // Branch to the externalExceptionBlock if the exception is foreign or // to a catch router if not. Either way the finally block will be run. @@ -1338,10 +1337,10 @@ llvm::Function *createCatchWrappedInvokeFunction(llvm::Module &module, // // Note: Index is not relative to pointer but instead to structure // unlike a true getelementptr (GEP) instruction - typeInfoThrown = builder.CreateStructGEP(typeInfoThrown, 0); + typeInfoThrown = builder.CreateStructGEP(ourExceptionType, typeInfoThrown, 0); llvm::Value *typeInfoThrownType = - builder.CreateStructGEP(typeInfoThrown, 0); + builder.CreateStructGEP(builder.getInt8PtrTy(), typeInfoThrown, 0); generateIntegerPrint(context, module, @@ -1389,13 +1388,11 @@ llvm::Function *createCatchWrappedInvokeFunction(llvm::Module &module, /// @param nativeThrowFunct function which will throw a foreign exception /// if the above nativeThrowType matches generated function's arg. /// @returns generated function -static -llvm::Function *createThrowExceptionFunction(llvm::Module &module, - llvm::IRBuilder<> &builder, - llvm::FunctionPassManager &fpm, - std::string ourId, - int32_t nativeThrowType, - llvm::Function &nativeThrowFunct) { +static llvm::Function * +createThrowExceptionFunction(llvm::Module &module, llvm::IRBuilder<> &builder, + llvm::legacy::FunctionPassManager &fpm, + std::string ourId, int32_t nativeThrowType, + llvm::Function &nativeThrowFunct) { llvm::LLVMContext &context = module.getContext(); namedValues.clear(); ArgTypes unwindArgTypes; @@ -1508,10 +1505,10 @@ static void createStandardUtilityFunctions(unsigned numTypeInfos, /// @param nativeThrowFunctName name of external function which will throw /// a foreign exception /// @returns outermost generated test function. -llvm::Function *createUnwindExceptionTest(llvm::Module &module, - llvm::IRBuilder<> &builder, - llvm::FunctionPassManager &fpm, - std::string nativeThrowFunctName) { +llvm::Function * +createUnwindExceptionTest(llvm::Module &module, llvm::IRBuilder<> &builder, + llvm::legacy::FunctionPassManager &fpm, + std::string nativeThrowFunctName) { // Number of type infos to generate unsigned numTypeInfos = 6; @@ -1577,7 +1574,7 @@ public: std::runtime_error::operator=(toCopy))); } - virtual ~OurCppRunException (void) throw () {} + ~OurCppRunException(void) throw() override {} }; } // end anonymous namespace @@ -1971,13 +1968,12 @@ int main(int argc, char *argv[]) { llvm::ExecutionEngine *executionEngine = factory.create(); { - llvm::FunctionPassManager fpm(module); + llvm::legacy::FunctionPassManager fpm(module); // Set up the optimizer pipeline. // Start with registering info about how the // target lays out data structures. - module->setDataLayout(executionEngine->getDataLayout()); - fpm.add(new llvm::DataLayoutPass()); + module->setDataLayout(*executionEngine->getDataLayout()); // Optimizations turned on #ifdef ADD_OPT_PASSES |