Refactor code to hide direct IrFunction->func usage and add convenient functions (#1911)

This commit is contained in:
Ivan Butygin 2017-01-18 00:40:32 +03:00 committed by Johan Engelen
parent 09cef87178
commit a26bfc1223
17 changed files with 158 additions and 73 deletions

View file

@ -38,6 +38,47 @@ void IrFunction::setAlwaysInline() {
func->addFnAttr(llvm::Attribute::AlwaysInline);
}
void IrFunction::setLLVMFunc(llvm::Function *function) {
assert(function != nullptr);
func = function;
}
llvm::Function *IrFunction::getLLVMFunc() const {
return func;
}
llvm::CallingConv::ID IrFunction::getCallingConv() const {
assert(func != nullptr);
return func->getCallingConv();
}
llvm::FunctionType *IrFunction::getLLVMFuncType() const {
assert(func != nullptr);
return func->getFunctionType();
}
#if LDC_LLVM_VER >= 307
bool IrFunction::hasLLVMPersonalityFn() const {
assert(func != nullptr);
return func->hasPersonalityFn();
}
void IrFunction::setLLVMPersonalityFn(llvm::Constant *personality) {
assert(func != nullptr);
func->setPersonalityFn(personality);
}
#endif
llvm::StringRef IrFunction::getLLVMFuncName() const {
assert(func != nullptr);
return func->getName();
}
llvm::Function *IrFunction::getLLVMCallee() const {
assert(func != nullptr);
return func;
}
IrFunction *getIrFunc(FuncDeclaration *decl, bool create) {
if (!isIrFuncCreated(decl) && create) {
assert(decl->ir->irFunc == NULL);
@ -55,3 +96,13 @@ bool isIrFuncCreated(FuncDeclaration *decl) {
assert(t == IrDsymbol::FuncType || t == IrDsymbol::NotSet);
return t == IrDsymbol::FuncType;
}
llvm::Function *DtoFunction(FuncDeclaration *decl, bool create) {
assert(decl != nullptr);
return getIrFunc(decl, create)->getLLVMFunc();
}
llvm::Function *DtoCallee(FuncDeclaration *decl, bool create) {
assert(decl != nullptr);
return getIrFunc(decl, create)->getLLVMCallee();
}