[K/N] Get rid of predefined values in TempFiles

One step closer to getting rid of this class at all.
This commit is contained in:
Sergey Bogolepov
2023-01-25 12:33:52 +02:00
committed by Space Team
parent 1182903b20
commit a11be433e2
3 changed files with 7 additions and 18 deletions
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.backend.konan.driver.phases
import org.jetbrains.kotlin.backend.konan.*
import org.jetbrains.kotlin.backend.konan.driver.PhaseContext
import org.jetbrains.kotlin.backend.konan.driver.PhaseEngine
import org.jetbrains.kotlin.backend.konan.llvm.getName
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
@@ -137,7 +138,8 @@ internal fun PhaseEngine<NativeGenerationState>.compileModule(module: IrModuleFr
if (context.config.produce.isCache) {
runPhase(SaveAdditionalCacheInfoPhase)
}
val bitcodeFile = context.tempFiles.nativeBinaryFile.javaFile()
// TODO: Currently, all llvm modules are named as "out" which might lead to collisions.
val bitcodeFile = context.tempFiles.create(context.llvm.module.getName(), ".bc").javaFile()
runPhase(WriteBitcodeFilePhase, WriteBitcodeFileInput(context.llvm.module, bitcodeFile))
val dependenciesTrackingResult = DependenciesTrackingResult(
context.dependenciesTracker.bitcodeToLink,
@@ -175,8 +177,8 @@ internal fun PhaseEngine<NativeGenerationState>.runBackendCodegen(module: IrModu
mergeDependencies(module, dependenciesToCompile)
runCodegen(module)
val generatedBitcodeFiles = if (context.config.produce.isNativeLibrary) {
val cppAdapterFile = context.tempFiles.cAdapterCpp.javaFile()
val bitcodeAdapterFile = context.tempFiles.cAdapterBitcode.javaFile()
val cppAdapterFile = context.tempFiles.create("api", ".cpp").javaFile()
val bitcodeAdapterFile = context.tempFiles.create("api", ".bc").javaFile()
val input = CExportGenerateApiInput(
context.context.cAdapterExportedElements!!,
headerFile = context.outputFiles.cAdapterHeader.javaFile(),
@@ -6,14 +6,13 @@
package org.jetbrains.kotlin.backend.konan.driver.utilities
import kotlinx.cinterop.*
import llvm.LLVMGetModuleIdentifier
import llvm.LLVMModuleRef
import llvm.LLVMPrintModuleToFile
import llvm.size_tVar
import org.jetbrains.kotlin.backend.common.phaser.Action
import org.jetbrains.kotlin.backend.common.phaser.ActionState
import org.jetbrains.kotlin.backend.konan.KonanConfigKeys
import org.jetbrains.kotlin.backend.konan.driver.PhaseContext
import org.jetbrains.kotlin.backend.konan.llvm.getName
import org.jetbrains.kotlin.backend.konan.llvm.verifyModule
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
import java.io.File
@@ -39,10 +38,7 @@ private fun <Data, Context : PhaseContext> createLlvmDumperAction(): Action<Data
"Cannot dump LLVM IR ${state.beforeOrAfter.name.lowercase()} ${state.phase.name}")
return
}
val moduleName: String = memScoped {
val sizeVar = alloc<size_tVar>()
LLVMGetModuleIdentifier(llvmModule, sizeVar.ptr)!!.toKStringFromUtf8()
}
val moduleName: String = llvmModule.getName()
val output = File(context.config.saveLlvmIrDirectory, "$moduleName.${state.phase.name}.ll")
if (LLVMPrintModuleToFile(llvmModule, output.absolutePath, null) != 0) {
error("Can't dump LLVM IR to ${output.absolutePath}")
@@ -30,17 +30,8 @@ class TempFiles(outputPath: String, pathToTemporaryDir: String? = null) {
}
}
private val outputName = File(outputPath).name
val deleteOnExit = pathToTemporaryDir == null || pathToTemporaryDir.isEmpty()
val nativeBinaryFile by lazy { create(outputName,".kt.bc") }
val cAdapterCpp by lazy { create("api", ".cpp") }
val cAdapterBitcode by lazy { create("api", ".bc") }
val nativeBinaryFileName get() = nativeBinaryFile.absolutePath
val cAdapterCppName get() = cAdapterCpp.absolutePath
val cAdapterBitcodeName get() = cAdapterBitcode.absolutePath
private val dir by lazy {
if (deleteOnExit) {
createTempDir("konan_temp")