[K/N] Include cstubs into -Xsave-llvm-ir

This way we are able to FileCheck interop bridges.
This commit is contained in:
Sergey Bogolepov
2021-10-19 11:18:07 +07:00
committed by Space
parent 71fb8f90d4
commit 851f4d86d9
2 changed files with 15 additions and 15 deletions
@@ -4,6 +4,10 @@
*/
package org.jetbrains.kotlin.backend.konan
import kotlinx.cinterop.alloc
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.ptr
import kotlinx.cinterop.toKStringFromUtf8
import llvm.*
import org.jetbrains.kotlin.backend.common.serialization.KlibIrVersion
import org.jetbrains.kotlin.backend.common.serialization.metadata.KlibMetadataVersion
@@ -52,6 +56,17 @@ internal fun produceCStubs(context: Context) {
).forEach {
parseAndLinkBitcodeFile(context, llvmModule, it.absolutePath)
}
// TODO: Consider adding LLVM_IR compiler output kind.
if (context.configuration.getBoolean(KonanConfigKeys.SAVE_LLVM_IR)) {
val moduleName: String = memScoped {
val sizeVar = alloc<size_tVar>()
LLVMGetModuleIdentifier(context.llvmModule, sizeVar.ptr)!!.toKStringFromUtf8()
}
val output = context.config.tempFiles.create(moduleName,".ll")
if (LLVMPrintModuleToFile(context.llvmModule, output.absolutePath, null) != 0) {
error("Can't dump LLVM IR to ${output.absolutePath}")
}
}
}
private fun linkAllDependencies(context: Context, generatedBitcodeFiles: List<String>) {
@@ -5,10 +5,6 @@
package org.jetbrains.kotlin.backend.konan.llvm
import kotlinx.cinterop.alloc
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.ptr
import kotlinx.cinterop.toKStringFromUtf8
import llvm.*
import org.jetbrains.kotlin.backend.common.phaser.CompilerPhase
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
@@ -327,17 +323,6 @@ internal val codegenPhase = makeKonanModuleOpPhase(
description = "Code generation",
op = { context, irModule ->
irModule.acceptVoid(context.codegenVisitor)
// TODO: Consider adding LLVM_IR compiler output kind.
if (context.configuration.getBoolean(KonanConfigKeys.SAVE_LLVM_IR)) {
val moduleName: String = memScoped {
val sizeVar = alloc<size_tVar>()
LLVMGetModuleIdentifier(context.llvmModule, sizeVar.ptr)!!.toKStringFromUtf8()
}
val output = context.config.tempFiles.create(moduleName,".ll")
if (LLVMPrintModuleToFile(context.llvmModule, output.absolutePath, null) != 0) {
error("Can't dump LLVM IR to ${output.absolutePath}")
}
}
}
)