[K/N] Minor -Xcompile-from-bitcode enhancements
This commit is contained in:
committed by
Space Team
parent
349a6b6e82
commit
ca7d1d0194
+1
-6
@@ -502,12 +502,7 @@ class KonanConfig(val project: Project, val configuration: CompilerConfiguration
|
||||
* Path to serialized dependencies to use for bitcode compilation.
|
||||
*/
|
||||
internal val readSerializedDependencies: String? by lazy {
|
||||
configuration.get(KonanConfigKeys.SERIALIZED_DEPENDENCIES).also {
|
||||
if (compileFromBitcode.isNullOrEmpty()) {
|
||||
configuration.report(CompilerMessageSeverity.STRONG_WARNING,
|
||||
"Providing serialized dependencies only works in conjunction with a bitcode file to compile.")
|
||||
}
|
||||
}
|
||||
configuration.get(KonanConfigKeys.SERIALIZED_DEPENDENCIES)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+12
-1
@@ -263,7 +263,7 @@ fun CompilerConfiguration.setupFromArguments(arguments: K2NativeCompilerArgument
|
||||
put(PARTIAL_LINKAGE, arguments.partialLinkage)
|
||||
put(OMIT_FRAMEWORK_BINARY, arguments.omitFrameworkBinary)
|
||||
putIfNotNull(COMPILE_FROM_BITCODE, arguments.compileFromBitcode)
|
||||
putIfNotNull(SERIALIZED_DEPENDENCIES, arguments.serializedDependencies)
|
||||
putIfNotNull(SERIALIZED_DEPENDENCIES, parseSerializedDependencies(arguments, this@setupFromArguments))
|
||||
putIfNotNull(SAVE_DEPENDENCIES_PATH, arguments.saveDependenciesPath)
|
||||
putIfNotNull(SAVE_LLVM_IR_DIRECTORY, arguments.saveLlvmIrDirectory)
|
||||
}
|
||||
@@ -507,3 +507,14 @@ private fun parseBundleId(
|
||||
argumentValue
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseSerializedDependencies(
|
||||
arguments: K2NativeCompilerArguments,
|
||||
configuration: CompilerConfiguration
|
||||
): String? {
|
||||
if (!arguments.serializedDependencies.isNullOrEmpty() && arguments.compileFromBitcode.isNullOrEmpty()) {
|
||||
configuration.report(STRONG_WARNING,
|
||||
"Providing serialized dependencies only works in conjunction with a bitcode file to compile.")
|
||||
}
|
||||
return arguments.serializedDependencies
|
||||
}
|
||||
+5
-2
@@ -5,10 +5,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.konan.driver
|
||||
|
||||
import kotlinx.cinterop.CPointer
|
||||
import kotlinx.cinterop.usingJvmCInteropCallbacks
|
||||
import llvm.LLVMContextCreate
|
||||
import llvm.LLVMContextDispose
|
||||
import llvm.LLVMDisposeModule
|
||||
import llvm.LLVMOpaqueModule
|
||||
import org.jetbrains.kotlin.backend.konan.*
|
||||
import org.jetbrains.kotlin.backend.konan.BitcodePostProcessingContextImpl
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
@@ -133,8 +135,9 @@ internal class DynamicCompilerDriver : CompilerDriver() {
|
||||
|
||||
private fun produceBinaryFromBitcode(engine: PhaseEngine<PhaseContext>, config: KonanConfig, bitcodeFilePath: String) {
|
||||
val llvmContext = LLVMContextCreate()!!
|
||||
val llvmModule = parseBitcodeFile(llvmContext, bitcodeFilePath)
|
||||
var llvmModule: CPointer<LLVMOpaqueModule>? = null
|
||||
try {
|
||||
llvmModule = parseBitcodeFile(llvmContext, bitcodeFilePath)
|
||||
val context = BitcodePostProcessingContextImpl(config, llvmModule, llvmContext)
|
||||
val depsPath = config.readSerializedDependencies
|
||||
val dependencies = if (depsPath.isNullOrEmpty()) DependenciesTrackingResult(emptyList(), emptyList(), emptyList()).also {
|
||||
@@ -142,7 +145,7 @@ internal class DynamicCompilerDriver : CompilerDriver() {
|
||||
} else DependenciesTrackingResult.deserialize(depsPath, File(depsPath).readStrings(), config)
|
||||
engine.runBitcodeBackend(context, dependencies)
|
||||
} finally {
|
||||
LLVMDisposeModule(llvmModule)
|
||||
llvmModule?.let { LLVMDisposeModule(it) }
|
||||
LLVMContextDispose(llvmContext)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user