backend.native: tie compiler to runtime

to make compiler able to refer entities declared in runtime
This commit is contained in:
Svyatoslav Scherbina
2016-09-29 17:28:36 +07:00
parent 80ed5a2461
commit 78a912f637
3 changed files with 54 additions and 0 deletions
+7
View File
@@ -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;
}
@@ -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)
}