backend: import external functions with proper attributes

This commit is contained in:
Svyatoslav Scherbina
2016-12-29 17:17:29 +07:00
committed by SvyatoslavScherbina
parent b531d984c8
commit 7374ea642f
2 changed files with 12 additions and 1 deletions
@@ -202,7 +202,14 @@ internal class Llvm(val context: Context, val llvmModule: LLVMModuleRef) {
val externalFunction = LLVMGetNamedFunction(otherModule, name)!!
val functionType = getFunctionType(externalFunction)
return LLVMAddFunction(llvmModule, name, functionType)!!
val function = LLVMAddFunction(llvmModule, name, functionType)!!
val attributes = LLVMGetFunctionAttrSet(externalFunction)
for (attribute in LLVMAttribute.values()) {
if (attribute in attributes) {
LLVMAddFunctionAttr(function, attribute)
}
}
return function
}
private fun importMemset() : LLVMValueRef {
@@ -230,3 +230,7 @@ fun llvmtype2string(type: LLVMTypeRef?): String {
return LLVMPrintTypeToString(type)!!.asCString().toString()
}
internal operator fun LLVMAttributeSet.contains(attribute: LLVMAttribute): Boolean {
return (this and attribute.value) != 0
}