backend.native: tie compiler to runtime
to make compiler able to refer entities declared in runtime
This commit is contained in:
@@ -65,6 +65,13 @@ task run(type: JavaExec) {
|
||||
main 'org.jetbrains.kotlin.cli.bc.K2NativeKt'
|
||||
classpath = sourceSets.main.runtimeClasspath.add(files(['build/classes/main']))
|
||||
args '../experiments/translator/src/test/kotlin/tests/classfields_1/classfields_1.kt'
|
||||
|
||||
dependsOn ':runtime:build'
|
||||
|
||||
doFirst {
|
||||
args '-runtime', project(':runtime').build.outputs.files.singleFile
|
||||
println(args)
|
||||
}
|
||||
}
|
||||
|
||||
task jars {
|
||||
|
||||
@@ -10,4 +10,8 @@ public class K2NativeCompilerArguments extends CommonCompilerArguments {
|
||||
@ValueDescription("<path>")
|
||||
public String outputFile;
|
||||
|
||||
@Argument(value = "runtime", description = "Runtime file path")
|
||||
@ValueDescription("<path>")
|
||||
public String runtimeFile;
|
||||
|
||||
}
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package org.jetbrains.kotlin.backend.native.llvm
|
||||
|
||||
import kotlin_native.interop.*
|
||||
import llvm.*
|
||||
|
||||
class Runtime(private val bitcodeFile: String) {
|
||||
val llvmModule: LLVMOpaqueModule
|
||||
|
||||
init {
|
||||
val arena = Arena()
|
||||
try {
|
||||
|
||||
val bufRef = arena.alloc(LLVMOpaqueMemoryBuffer.ref)
|
||||
val errorRef = arena.alloc(Int8Box.ref)
|
||||
val res = LLVMCreateMemoryBufferWithContentsOfFile(bitcodeFile, bufRef, errorRef)
|
||||
if (res != 0) {
|
||||
throw Error(errorRef.value?.asCString()?.toString())
|
||||
}
|
||||
|
||||
val moduleRef = arena.alloc(LLVMOpaqueModule.ref)
|
||||
val parseRes = LLVMParseBitcode2(bufRef.value, moduleRef)
|
||||
if (parseRes != 0) {
|
||||
throw Error(parseRes.toString())
|
||||
}
|
||||
|
||||
llvmModule = moduleRef.value!!
|
||||
|
||||
} finally {
|
||||
arena.clear()
|
||||
}
|
||||
}
|
||||
|
||||
val typeInfoType = LLVMGetTypeByName(llvmModule, "struct.TypeInfo")
|
||||
val fieldTableRecordType = LLVMGetTypeByName(llvmModule, "struct.FieldTableRecord")
|
||||
val methodTableRecordType = LLVMGetTypeByName(llvmModule, "struct.MethodTableRecord")
|
||||
|
||||
val target = LLVMGetTarget(llvmModule)!!.asCString().toString()
|
||||
|
||||
val dataLayout = LLVMGetDataLayout(llvmModule)!!.asCString().toString()
|
||||
|
||||
val targetData = LLVMCreateTargetData(dataLayout)
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user