mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 12:50:30 +00:00
reindent this whole file and do a variety of stylistic cleanups.
This code is still a long way from following best practices. llvm-svn: 129140
This commit is contained in:
parent
5789afd1a4
commit
9ba8d74c34
@ -1,12 +1,11 @@
|
|||||||
//===-- examples/ExceptionDemo/ExceptionDemo.cpp -
|
//===-- ExceptionDemo.cpp - An example using llvm Exceptions --------------===//
|
||||||
// An example use of the llvm Exception mechanism --===//
|
|
||||||
//
|
//
|
||||||
// The LLVM Compiler Infrastructure
|
// The LLVM Compiler Infrastructure
|
||||||
//
|
//
|
||||||
// This file is distributed under the University of Illinois Open Source
|
// This file is distributed under the University of Illinois Open Source
|
||||||
// License. See LICENSE.TXT for details.
|
// License. See LICENSE.TXT for details.
|
||||||
//
|
//
|
||||||
//===--------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
//
|
//
|
||||||
// Demo program which implements an example LLVM exception implementation, and
|
// Demo program which implements an example LLVM exception implementation, and
|
||||||
// shows several test cases including the handling of foreign exceptions.
|
// shows several test cases including the handling of foreign exceptions.
|
||||||
@ -46,8 +45,7 @@
|
|||||||
// This code uses code from the llvm compiler-rt project and the llvm
|
// This code uses code from the llvm compiler-rt project and the llvm
|
||||||
// Kaleidoscope project.
|
// Kaleidoscope project.
|
||||||
//
|
//
|
||||||
//===--------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
|
|
||||||
#include "llvm/LLVMContext.h"
|
#include "llvm/LLVMContext.h"
|
||||||
#include "llvm/DerivedTypes.h"
|
#include "llvm/DerivedTypes.h"
|
||||||
@ -64,11 +62,7 @@
|
|||||||
#include "llvm/Support/IRBuilder.h"
|
#include "llvm/Support/IRBuilder.h"
|
||||||
#include "llvm/Support/Dwarf.h"
|
#include "llvm/Support/Dwarf.h"
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
#include <string>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <map>
|
|
||||||
#include <vector>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
|
||||||
@ -212,13 +206,10 @@ llvm::Function *createFunction(llvm::Module& module,
|
|||||||
llvm::GlobalValue::LinkageTypes linkage,
|
llvm::GlobalValue::LinkageTypes linkage,
|
||||||
bool declarationOnly,
|
bool declarationOnly,
|
||||||
bool isVarArg) {
|
bool isVarArg) {
|
||||||
llvm::FunctionType* functType = llvm::FunctionType::get(retType,
|
llvm::FunctionType *functType =
|
||||||
theArgTypes,
|
llvm::FunctionType::get(retType, theArgTypes, isVarArg);
|
||||||
isVarArg);
|
llvm::Function *ret =
|
||||||
llvm::Function* ret = llvm::Function::Create(functType,
|
llvm::Function::Create(functType, linkage, functName, &module);
|
||||||
linkage,
|
|
||||||
functName,
|
|
||||||
&module);
|
|
||||||
if (!ret || declarationOnly)
|
if (!ret || declarationOnly)
|
||||||
return(ret);
|
return(ret);
|
||||||
|
|
||||||
@ -246,7 +237,7 @@ llvm::Function *createFunction(llvm::Module& module,
|
|||||||
static llvm::AllocaInst *createEntryBlockAlloca(llvm::Function& function,
|
static llvm::AllocaInst *createEntryBlockAlloca(llvm::Function& function,
|
||||||
const std::string &varName,
|
const std::string &varName,
|
||||||
const llvm::Type* type,
|
const llvm::Type* type,
|
||||||
llvm::Constant* initWith = NULL) {
|
llvm::Constant* initWith = 0) {
|
||||||
llvm::BasicBlock& block = function.getEntryBlock();
|
llvm::BasicBlock& block = function.getEntryBlock();
|
||||||
llvm::IRBuilder<> tmp(&block, block.begin());
|
llvm::IRBuilder<> tmp(&block, block.begin());
|
||||||
llvm::AllocaInst* ret = tmp.CreateAlloca(type, 0, varName.c_str());
|
llvm::AllocaInst* ret = tmp.CreateAlloca(type, 0, varName.c_str());
|
||||||
@ -1005,10 +996,7 @@ static llvm::BasicBlock* createFinallyBlock(llvm::LLVMContext& context,
|
|||||||
|
|
||||||
std::ostringstream bufferToPrint;
|
std::ostringstream bufferToPrint;
|
||||||
bufferToPrint << "Gen: Executing finally block "
|
bufferToPrint << "Gen: Executing finally block "
|
||||||
<< blockName
|
<< blockName << " in " << functionId << "\n";
|
||||||
<< " in "
|
|
||||||
<< functionId
|
|
||||||
<< std::endl;
|
|
||||||
generateStringPrint(context,
|
generateStringPrint(context,
|
||||||
module,
|
module,
|
||||||
builder,
|
builder,
|
||||||
@ -1253,8 +1241,7 @@ llvm::Function* createCatchWrappedInvokeFunction(llvm::Module& module,
|
|||||||
// Note: Skipping index 0
|
// Note: Skipping index 0
|
||||||
for (unsigned i = 0; i < numExceptionsToCatch; ++i) {
|
for (unsigned i = 0; i < numExceptionsToCatch; ++i) {
|
||||||
// Set up type infos to be caught
|
// Set up type infos to be caught
|
||||||
args.push_back(
|
args.push_back(module.getGlobalVariable(
|
||||||
module.getGlobalVariable(
|
|
||||||
ourTypeInfoNames[exceptionTypesToCatch[i]]));
|
ourTypeInfoNames[exceptionTypesToCatch[i]]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1277,17 +1264,14 @@ llvm::Function* createCatchWrappedInvokeFunction(llvm::Module& module,
|
|||||||
// (_Unwind_Exception instance). This member tells us whether or not
|
// (_Unwind_Exception instance). This member tells us whether or not
|
||||||
// the exception is foreign.
|
// the exception is foreign.
|
||||||
llvm::Value* unwindExceptionClass =
|
llvm::Value* unwindExceptionClass =
|
||||||
builder.CreateLoad(
|
builder.CreateLoad(builder.CreateStructGEP(
|
||||||
builder.CreateStructGEP(
|
builder.CreatePointerCast(unwindException,
|
||||||
builder.CreatePointerCast(
|
|
||||||
unwindException,
|
|
||||||
ourUnwindExceptionType->getPointerTo()),
|
ourUnwindExceptionType->getPointerTo()),
|
||||||
0));
|
0));
|
||||||
|
|
||||||
// Branch to the externalExceptionBlock if the exception is foreign or
|
// Branch to the externalExceptionBlock if the exception is foreign or
|
||||||
// to a catch router if not. Either way the finally block will be run.
|
// to a catch router if not. Either way the finally block will be run.
|
||||||
builder.CreateCondBr(
|
builder.CreateCondBr(builder.CreateICmpEQ(unwindExceptionClass,
|
||||||
builder.CreateICmpEQ(unwindExceptionClass,
|
|
||||||
llvm::ConstantInt::get(builder.getInt64Ty(),
|
llvm::ConstantInt::get(builder.getInt64Ty(),
|
||||||
ourBaseExceptionClass)),
|
ourBaseExceptionClass)),
|
||||||
exceptionRouteBlock,
|
exceptionRouteBlock,
|
||||||
@ -1315,8 +1299,7 @@ llvm::Function* createCatchWrappedInvokeFunction(llvm::Module& module,
|
|||||||
//
|
//
|
||||||
// Note: ourBaseFromUnwindOffset is usually negative
|
// Note: ourBaseFromUnwindOffset is usually negative
|
||||||
llvm::Value* typeInfoThrown =
|
llvm::Value* typeInfoThrown =
|
||||||
builder.CreatePointerCast(
|
builder.CreatePointerCast(builder.CreateConstGEP1_64(unwindException,
|
||||||
builder.CreateConstGEP1_64(unwindException,
|
|
||||||
ourBaseFromUnwindOffset),
|
ourBaseFromUnwindOffset),
|
||||||
ourExceptionType->getPointerTo());
|
ourExceptionType->getPointerTo());
|
||||||
|
|
||||||
@ -1351,8 +1334,7 @@ llvm::Function* createCatchWrappedInvokeFunction(llvm::Module& module,
|
|||||||
for (unsigned i = 1; i <= numExceptionsToCatch; ++i) {
|
for (unsigned i = 1; i <= numExceptionsToCatch; ++i) {
|
||||||
nextTypeToCatch = i - 1;
|
nextTypeToCatch = i - 1;
|
||||||
switchToCatchBlock->addCase(llvm::ConstantInt::get(
|
switchToCatchBlock->addCase(llvm::ConstantInt::get(
|
||||||
llvm::Type::getInt32Ty(context),
|
llvm::Type::getInt32Ty(context), i),
|
||||||
i),
|
|
||||||
catchBlocks[nextTypeToCatch]);
|
catchBlocks[nextTypeToCatch]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1570,8 +1552,7 @@ public:
|
|||||||
|
|
||||||
OurCppRunException& operator = (const OurCppRunException& toCopy) {
|
OurCppRunException& operator = (const OurCppRunException& toCopy) {
|
||||||
return(reinterpret_cast<OurCppRunException&>(
|
return(reinterpret_cast<OurCppRunException&>(
|
||||||
std::runtime_error::operator = (toCopy)
|
std::runtime_error::operator=(toCopy)));
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~OurCppRunException (void) throw () {}
|
~OurCppRunException (void) throw () {}
|
||||||
@ -1605,10 +1586,7 @@ void runExceptionThrow(llvm::ExecutionEngine* engine,
|
|||||||
// Find test's function pointer
|
// Find test's function pointer
|
||||||
OurExceptionThrowFunctType functPtr =
|
OurExceptionThrowFunctType functPtr =
|
||||||
reinterpret_cast<OurExceptionThrowFunctType>(
|
reinterpret_cast<OurExceptionThrowFunctType>(
|
||||||
reinterpret_cast<intptr_t>(
|
reinterpret_cast<intptr_t>(engine->getPointerToFunction(function)));
|
||||||
engine->getPointerToFunction(function)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Run test
|
// Run test
|
||||||
@ -1675,8 +1653,8 @@ static void createStandardUtilityFunctions(unsigned numTypeInfos,
|
|||||||
//
|
//
|
||||||
// Note: Declaring only a portion of the _Unwind_Exception struct.
|
// Note: Declaring only a portion of the _Unwind_Exception struct.
|
||||||
// Does this cause problems?
|
// Does this cause problems?
|
||||||
ourUnwindExceptionType = llvm::StructType::get(context,
|
ourUnwindExceptionType =
|
||||||
TypeArray(builder.getInt64Ty()));
|
llvm::StructType::get(context, TypeArray(builder.getInt64Ty()));
|
||||||
struct OurBaseException_t dummyException;
|
struct OurBaseException_t dummyException;
|
||||||
|
|
||||||
// Calculate offset of OurException::unwindException member.
|
// Calculate offset of OurException::unwindException member.
|
||||||
@ -1922,9 +1900,9 @@ static void createStandardUtilityFunctions(unsigned numTypeInfos,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//===---------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
// Main test driver code.
|
// Main test driver code.
|
||||||
//===---------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
/// Demo main routine which takes the type info types to throw. A test will
|
/// Demo main routine which takes the type info types to throw. A test will
|
||||||
/// be run for each given type info type. While type info types with the value
|
/// be run for each given type info type. While type info types with the value
|
||||||
|
Loading…
Reference in New Issue
Block a user