Introduced shims for LLVM StubGenerator.
Run your gradlew task with -Dshims=true to dump the trace This is not a complete executable solution yet, but already very useful for llvm api tracing
This commit is contained in:
committed by
alexander-gorshenev
parent
755194486b
commit
ca193efa5c
+14
-2
@@ -7,7 +7,8 @@ class StubGenerator(
|
|||||||
val nativeIndex: NativeIndex,
|
val nativeIndex: NativeIndex,
|
||||||
val pkgName: String,
|
val pkgName: String,
|
||||||
val libName: String,
|
val libName: String,
|
||||||
val excludedFunctions: Set<String>) {
|
val excludedFunctions: Set<String>,
|
||||||
|
val dumpShims: Boolean) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The names that should not be used for struct classes to prevent name clashes
|
* The names that should not be used for struct classes to prevent name clashes
|
||||||
@@ -583,7 +584,18 @@ class StubGenerator(
|
|||||||
out(binding.convFree.invoke(externalParamNames[i]))
|
out(binding.convFree.invoke(externalParamNames[i]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (dumpShims) {
|
||||||
|
val returnValueRepresentation = retValBinding.conv("res")
|
||||||
|
out("print(\"\${${returnValueRepresentation}}\\t= \")")
|
||||||
|
out("print(\"${func.name}( \")")
|
||||||
|
val argsRepresentation = paramNames.map{"\${${it}}"}.joinToString(", ")
|
||||||
|
out("print(\"${argsRepresentation}\")")
|
||||||
|
out("println(\")\")")
|
||||||
|
}
|
||||||
|
|
||||||
out("return " + retValBinding.conv("res"))
|
out("return " + retValBinding.conv("res"))
|
||||||
|
|
||||||
}
|
}
|
||||||
out("}")
|
out("}")
|
||||||
}
|
}
|
||||||
@@ -819,4 +831,4 @@ class StubGenerator(
|
|||||||
}
|
}
|
||||||
out("}")
|
out("}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-2
@@ -86,6 +86,11 @@ private fun Properties.getSpaceSeparated(name: String): List<String> {
|
|||||||
return this.getProperty(name)?.split(' ') ?: emptyList()
|
return this.getProperty(name)?.split(' ') ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun List<String>?.isTrue(): Boolean {
|
||||||
|
// The rightmost wins
|
||||||
|
return this?.last() == "true" ?: false
|
||||||
|
}
|
||||||
|
|
||||||
private fun processLib(ktGenRoot: String,
|
private fun processLib(ktGenRoot: String,
|
||||||
nativeLibsDir: String,
|
nativeLibsDir: String,
|
||||||
llvmInstallPath: String,
|
llvmInstallPath: String,
|
||||||
@@ -105,6 +110,7 @@ private fun processLib(ktGenRoot: String,
|
|||||||
val additionalHeaders = args["-h"].orEmpty()
|
val additionalHeaders = args["-h"].orEmpty()
|
||||||
val additionalCompilerOpts = args["-copt"].orEmpty()
|
val additionalCompilerOpts = args["-copt"].orEmpty()
|
||||||
val additionalLinkerOpts = args["-lopt"].orEmpty()
|
val additionalLinkerOpts = args["-lopt"].orEmpty()
|
||||||
|
val generateShims = args["-shims"].isTrue()
|
||||||
|
|
||||||
val headerFiles = config.getSpaceSeparated("headers") + additionalHeaders
|
val headerFiles = config.getSpaceSeparated("headers") + additionalHeaders
|
||||||
val compilerOpts = config.getSpaceSeparated("compilerOpts") + additionalCompilerOpts
|
val compilerOpts = config.getSpaceSeparated("compilerOpts") + additionalCompilerOpts
|
||||||
@@ -127,7 +133,7 @@ private fun processLib(ktGenRoot: String,
|
|||||||
|
|
||||||
val nativeIndex = buildNativeIndex(headerFiles, compilerOpts)
|
val nativeIndex = buildNativeIndex(headerFiles, compilerOpts)
|
||||||
|
|
||||||
val gen = StubGenerator(nativeIndex, outKtPkg, libName, excludedFunctions)
|
val gen = StubGenerator(nativeIndex, outKtPkg, libName, excludedFunctions, generateShims)
|
||||||
|
|
||||||
outKtFile.parentFile.mkdirs()
|
outKtFile.parentFile.mkdirs()
|
||||||
outKtFile.bufferedWriter().use { out ->
|
outKtFile.bufferedWriter().use { out ->
|
||||||
@@ -189,4 +195,4 @@ private fun buildNativeIndex(headerFiles: List<String>, compilerOpts: List<Strin
|
|||||||
val res = buildNativeIndex(tempHeaderFile, compilerOpts)
|
val res = buildNativeIndex(tempHeaderFile, compilerOpts)
|
||||||
println(res)
|
println(res)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -191,6 +191,11 @@ class NamedNativeInteropConfig implements Named {
|
|||||||
headers.files.each {
|
headers.files.each {
|
||||||
args "-h:$it"
|
args "-h:$it"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (project.hasProperty("shims")) {
|
||||||
|
args "-shims:$project.ext.shims"
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user