[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.
|
* Path to serialized dependencies to use for bitcode compilation.
|
||||||
*/
|
*/
|
||||||
internal val readSerializedDependencies: String? by lazy {
|
internal val readSerializedDependencies: String? by lazy {
|
||||||
configuration.get(KonanConfigKeys.SERIALIZED_DEPENDENCIES).also {
|
configuration.get(KonanConfigKeys.SERIALIZED_DEPENDENCIES)
|
||||||
if (compileFromBitcode.isNullOrEmpty()) {
|
|
||||||
configuration.report(CompilerMessageSeverity.STRONG_WARNING,
|
|
||||||
"Providing serialized dependencies only works in conjunction with a bitcode file to compile.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+12
-1
@@ -263,7 +263,7 @@ fun CompilerConfiguration.setupFromArguments(arguments: K2NativeCompilerArgument
|
|||||||
put(PARTIAL_LINKAGE, arguments.partialLinkage)
|
put(PARTIAL_LINKAGE, arguments.partialLinkage)
|
||||||
put(OMIT_FRAMEWORK_BINARY, arguments.omitFrameworkBinary)
|
put(OMIT_FRAMEWORK_BINARY, arguments.omitFrameworkBinary)
|
||||||
putIfNotNull(COMPILE_FROM_BITCODE, arguments.compileFromBitcode)
|
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_DEPENDENCIES_PATH, arguments.saveDependenciesPath)
|
||||||
putIfNotNull(SAVE_LLVM_IR_DIRECTORY, arguments.saveLlvmIrDirectory)
|
putIfNotNull(SAVE_LLVM_IR_DIRECTORY, arguments.saveLlvmIrDirectory)
|
||||||
}
|
}
|
||||||
@@ -507,3 +507,14 @@ private fun parseBundleId(
|
|||||||
argumentValue
|
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
|
package org.jetbrains.kotlin.backend.konan.driver
|
||||||
|
|
||||||
|
import kotlinx.cinterop.CPointer
|
||||||
import kotlinx.cinterop.usingJvmCInteropCallbacks
|
import kotlinx.cinterop.usingJvmCInteropCallbacks
|
||||||
import llvm.LLVMContextCreate
|
import llvm.LLVMContextCreate
|
||||||
import llvm.LLVMContextDispose
|
import llvm.LLVMContextDispose
|
||||||
import llvm.LLVMDisposeModule
|
import llvm.LLVMDisposeModule
|
||||||
|
import llvm.LLVMOpaqueModule
|
||||||
import org.jetbrains.kotlin.backend.konan.*
|
import org.jetbrains.kotlin.backend.konan.*
|
||||||
import org.jetbrains.kotlin.backend.konan.BitcodePostProcessingContextImpl
|
import org.jetbrains.kotlin.backend.konan.BitcodePostProcessingContextImpl
|
||||||
import org.jetbrains.kotlin.backend.konan.Context
|
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) {
|
private fun produceBinaryFromBitcode(engine: PhaseEngine<PhaseContext>, config: KonanConfig, bitcodeFilePath: String) {
|
||||||
val llvmContext = LLVMContextCreate()!!
|
val llvmContext = LLVMContextCreate()!!
|
||||||
val llvmModule = parseBitcodeFile(llvmContext, bitcodeFilePath)
|
var llvmModule: CPointer<LLVMOpaqueModule>? = null
|
||||||
try {
|
try {
|
||||||
|
llvmModule = parseBitcodeFile(llvmContext, bitcodeFilePath)
|
||||||
val context = BitcodePostProcessingContextImpl(config, llvmModule, llvmContext)
|
val context = BitcodePostProcessingContextImpl(config, llvmModule, llvmContext)
|
||||||
val depsPath = config.readSerializedDependencies
|
val depsPath = config.readSerializedDependencies
|
||||||
val dependencies = if (depsPath.isNullOrEmpty()) DependenciesTrackingResult(emptyList(), emptyList(), emptyList()).also {
|
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)
|
} else DependenciesTrackingResult.deserialize(depsPath, File(depsPath).readStrings(), config)
|
||||||
engine.runBitcodeBackend(context, dependencies)
|
engine.runBitcodeBackend(context, dependencies)
|
||||||
} finally {
|
} finally {
|
||||||
LLVMDisposeModule(llvmModule)
|
llvmModule?.let { LLVMDisposeModule(it) }
|
||||||
LLVMContextDispose(llvmContext)
|
LLVMContextDispose(llvmContext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user