Improve interop enums (#341)

* Update build to Kotlin 1.1.0

* Add heuristics and options for selecting C enum interop binding style

Also do some refactoring.

* Add ':Interop:Indexer:updatePrebuilt' Gradle task

* Update Interop/Indexer/prebuilt
This commit is contained in:
SvyatoslavScherbina
2017-03-14 22:52:37 +07:00
committed by Nikolay Igotti
parent ec68a3a24e
commit 2882e6fab7
22 changed files with 630 additions and 505 deletions
-9
View File
@@ -1,9 +0,0 @@
typedef int32_t LLVMAttributeSet;
// Return value type of LLVMGetFunctionAttr is enum LLVMAttribute;
// it is not a strict enum, but used as a set of enum values instead.
// Currently it is not possible to configure interop to treat a enum in such way,
// so redeclare the function with appropriate return value type:
static inline LLVMAttributeSet LLVMGetFunctionAttrSet(LLVMValueRef Fn) {
return LLVMGetFunctionAttr(Fn);
}
-4
View File
@@ -1,9 +1,6 @@
buildscript {
repositories {
mavenCentral()
maven {
url "http://dl.bintray.com/kotlin/kotlin-eap-1.1"
}
}
dependencies {
@@ -135,7 +132,6 @@ List<String> llvmLinkerOpts() {
kotlinNativeInterop {
llvm {
defFile 'llvm.def'
headers files('LlvmHacks.h')
compilerOpts "-fPIC", "-I$llvmDir/include"
linkerOpts llvmLinkerOpts()
}
@@ -281,7 +281,7 @@ internal class CodeGenerator(override val context: Context) : ContextUtils {
val rargs = allocArrayOf(args)[0].ptr
if (LLVMIsAFunction(llvmFunction) != null /* the function declaration */ &&
LLVMAttribute.LLVMNoUnwindAttribute in LLVMGetFunctionAttrSet(llvmFunction)) {
(LLVMGetFunctionAttr(llvmFunction) and LLVMNoUnwindAttribute) != 0) {
return LLVMBuildCall(builder, llvmFunction, rargs, args.size, "")!!
} else {
@@ -187,12 +187,8 @@ internal class Llvm(val context: Context, val llvmModule: LLVMModuleRef) {
val functionType = getFunctionType(externalFunction)
val function = LLVMAddFunction(llvmModule, name, functionType)!!
val attributes = LLVMGetFunctionAttrSet(externalFunction)
for (attribute in LLVMAttribute.values()) {
if (attribute in attributes) {
LLVMAddFunctionAttr(function, attribute)
}
}
val attributes = LLVMGetFunctionAttr(externalFunction)
LLVMAddFunctionAttr(function, attributes)
return function
}
@@ -217,7 +213,7 @@ internal class Llvm(val context: Context, val llvmModule: LLVMModuleRef) {
private fun externalNounwindFunction(name: String, type: LLVMTypeRef): LLVMValueRef {
val function = externalFunction(name, type)
LLVMAddFunctionAttr(function, LLVMAttribute.LLVMNoUnwindAttribute)
LLVMAddFunctionAttr(function, LLVMNoUnwindAttribute)
return function
}
@@ -208,10 +208,6 @@ fun llvmtype2string(type: LLVMTypeRef?): String {
return LLVMPrintTypeToString(type)!!.asCString().toString()
}
internal operator fun LLVMAttributeSet.contains(attribute: LLVMAttribute): Boolean {
return (this and attribute.value) != 0
}
fun getStructElements(type: LLVMTypeRef): List<LLVMTypeRef> {
val count = LLVMCountStructElementTypes(type)
return (0 until count).map {
+2
View File
@@ -21,3 +21,5 @@ linkerOpts.osx = \
linkerOpts.linux=\
-Wl,-z,noexecstack \
-lrt -ldl -lpthread -lz -lm
strictEnums = LLVMIntPredicate LLVMOpcode LLVMDLLStorageClass LLVMCallConv LLVMThreadLocalMode LLVMAtomicOrdering