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:
Alexander Gorshenev
2016-11-14 16:28:09 +03:00
committed by alexander-gorshenev
parent 755194486b
commit ca193efa5c
3 changed files with 27 additions and 4 deletions
@@ -7,7 +7,8 @@ class StubGenerator(
val nativeIndex: NativeIndex,
val pkgName: 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
@@ -583,7 +584,18 @@ class StubGenerator(
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("}")
}
@@ -819,4 +831,4 @@ class StubGenerator(
}
out("}")
}
}
}
@@ -86,6 +86,11 @@ private fun Properties.getSpaceSeparated(name: String): List<String> {
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,
nativeLibsDir: String,
llvmInstallPath: String,
@@ -105,6 +110,7 @@ private fun processLib(ktGenRoot: String,
val additionalHeaders = args["-h"].orEmpty()
val additionalCompilerOpts = args["-copt"].orEmpty()
val additionalLinkerOpts = args["-lopt"].orEmpty()
val generateShims = args["-shims"].isTrue()
val headerFiles = config.getSpaceSeparated("headers") + additionalHeaders
val compilerOpts = config.getSpaceSeparated("compilerOpts") + additionalCompilerOpts
@@ -127,7 +133,7 @@ private fun processLib(ktGenRoot: String,
val nativeIndex = buildNativeIndex(headerFiles, compilerOpts)
val gen = StubGenerator(nativeIndex, outKtPkg, libName, excludedFunctions)
val gen = StubGenerator(nativeIndex, outKtPkg, libName, excludedFunctions, generateShims)
outKtFile.parentFile.mkdirs()
outKtFile.bufferedWriter().use { out ->
@@ -189,4 +195,4 @@ private fun buildNativeIndex(headerFiles: List<String>, compilerOpts: List<Strin
val res = buildNativeIndex(tempHeaderFile, compilerOpts)
println(res)
return res
}
}
@@ -191,6 +191,11 @@ class NamedNativeInteropConfig implements Named {
headers.files.each {
args "-h:$it"
}
if (project.hasProperty("shims")) {
args "-shims:$project.ext.shims"
}
}
}