Move compiler to new version, add primitive types. (#33)
This commit is contained in:
@@ -13,7 +13,8 @@ apply plugin: 'java'
|
||||
apply plugin: 'kotlin'
|
||||
apply plugin: org.jetbrains.kotlin.NativeInteropPlugin
|
||||
|
||||
String kotlinCompilerModule = 'org.jetbrains.kotlin:kotlin-compiler:1.1-20161025.164748-245'
|
||||
String kotlinCompilerModule = 'org.jetbrains.kotlin:kotlin-compiler:1.1-20161102.121224-247'
|
||||
|
||||
|
||||
// (gets applied to this project and all its subprojects)
|
||||
allprojects {
|
||||
@@ -84,13 +85,13 @@ String[] linkerOpts1() {
|
||||
List<String> ldflags = new ArrayList<>()
|
||||
if (System.properties['os.name'].startsWith("Linux"))
|
||||
ldflags.addAll(["-L$llvmDir/lib",
|
||||
"-Wl,-Bstatic", "-Wl,--whole-archive"]
|
||||
"-Wl,-Bstatic", "-Wl,--whole-archive"]
|
||||
+ libs
|
||||
+ ["-Wl,--no-whole-archive", "-Wl,-Bdynamic",
|
||||
"-L$libffiDir/lib -lffi",
|
||||
"-lrt", "-ldl","-lpthread", "-lz", "-lm"])
|
||||
"-L$libffiDir/lib -lffi",
|
||||
"-lrt", "-ldl","-lpthread", "-lz", "-lm"])
|
||||
else
|
||||
ldflags.addAll(["-L$llvmDir/lib", "-lc++"]
|
||||
ldflags.addAll(["-L$llvmDir/lib", "-lc++"]
|
||||
+ libs
|
||||
+ ["-L$libffiDir/lib", "-lffi"])
|
||||
ArrayList<String> strldflags = new ArrayList<>()
|
||||
|
||||
@@ -18,4 +18,17 @@ public class K2NativeCompilerArguments extends CommonCompilerArguments {
|
||||
@ValueDescription("<path>")
|
||||
public String[] headers;
|
||||
|
||||
public K2NativeCompilerArguments() {
|
||||
}
|
||||
|
||||
public K2NativeCompilerArguments(K2NativeCompilerArguments arguments) {
|
||||
super(arguments);
|
||||
this.outputFile = arguments.outputFile;
|
||||
this.runtimeFile = arguments.runtimeFile;
|
||||
this.headers = arguments.headers;
|
||||
}
|
||||
|
||||
public CommonCompilerArguments copy() {
|
||||
return new K2NativeCompilerArguments(this);
|
||||
}
|
||||
}
|
||||
|
||||
+13
-5
@@ -4,10 +4,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.classId
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassNotAny
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperInterfaces
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.*
|
||||
|
||||
/**
|
||||
* List of all implemented interfaces (including those which implemented by a super class)
|
||||
@@ -33,4 +30,15 @@ internal val FunctionDescriptor.implementation: FunctionDescriptor
|
||||
val filtered = OverridingUtil.filterOutOverridden(overridden)
|
||||
return filtered.first { it.modality != Modality.ABSTRACT } as FunctionDescriptor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val intrinsicTypes = setOf(
|
||||
"kotlin.Unit",
|
||||
"kotlin.Boolean", "kotlin.Char",
|
||||
"kotlin.Byte", "kotlin.Short",
|
||||
"kotlin.Int", "kotlin.Long",
|
||||
"kotlin.Float", "kotlin.Double"
|
||||
)
|
||||
|
||||
internal val ClassDescriptor.isIntrinsic: Boolean
|
||||
get() = this.fqNameSafe.asString() in intrinsicTypes
|
||||
+3
@@ -165,4 +165,7 @@ internal interface ContextUtils {
|
||||
|
||||
val FqName.localHash: LocalHash
|
||||
get() = this.toString().localHash
|
||||
|
||||
val pointerSize: Int
|
||||
get() = LLVMPointerSize(llvmTargetData)
|
||||
}
|
||||
+3
-1
@@ -12,7 +12,9 @@ internal fun getLLVMType(type: KotlinType): LLVMOpaqueType {
|
||||
KotlinBuiltIns.isInt(type) -> LLVMInt32Type()
|
||||
KotlinBuiltIns.isLong(type) -> LLVMInt64Type()
|
||||
KotlinBuiltIns.isUnit(type) -> LLVMVoidType() // TODO: handle Unit parameter case
|
||||
KotlinBuiltIns.isFloat(type) -> LLVMFloatType()
|
||||
KotlinBuiltIns.isDouble(type) -> LLVMDoubleType()
|
||||
!KotlinBuiltIns.isPrimitiveType(type) -> LLVMPointerType(LLVMInt8Type(), 0)
|
||||
else -> throw NotImplementedError()
|
||||
else -> throw NotImplementedError(type.toString() + " is not supported")
|
||||
}!!
|
||||
}
|
||||
+12
@@ -2,6 +2,7 @@ package org.jetbrains.kotlin.backend.native.llvm
|
||||
|
||||
import kotlin_native.interop.*
|
||||
import llvm.*
|
||||
import org.jetbrains.kotlin.backend.native.isIntrinsic
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.LazyClassReceiverParameterDescriptor
|
||||
@@ -12,6 +13,7 @@ import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
|
||||
|
||||
fun emitLLVM(module: IrModuleFragment, runtimeFile: String, outFile: String) {
|
||||
@@ -51,6 +53,11 @@ internal class RTTIGeneratorVisitor(context: Context) : IrElementVisitorVoid {
|
||||
return
|
||||
}
|
||||
|
||||
if (declaration.descriptor.isIntrinsic) {
|
||||
// do not generate any code for intrinsic classes as they require special handling
|
||||
return
|
||||
}
|
||||
|
||||
generator.generate(declaration.descriptor)
|
||||
}
|
||||
|
||||
@@ -106,6 +113,11 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
|
||||
return
|
||||
}
|
||||
|
||||
if (declaration.descriptor.isIntrinsic) {
|
||||
// do not generate any code for intrinsic classes as they require special handling
|
||||
return
|
||||
}
|
||||
|
||||
super.visitClass(declaration)
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -26,7 +26,8 @@ internal val ClassDescriptor.symbolName: String
|
||||
get() = when (this.kind) {
|
||||
CLASS -> "kclass:"
|
||||
INTERFACE -> "kinf:"
|
||||
else -> TODO("fixme")
|
||||
OBJECT -> "kclass:"
|
||||
else -> TODO("fixme: " + this.kind)
|
||||
} + fqNameSafe
|
||||
|
||||
internal val ClassDescriptor.typeInfoSymbolName: String
|
||||
|
||||
+6
-5
@@ -128,11 +128,12 @@ internal class RTTIGenerator(override val context: Context) : ContextUtils {
|
||||
}
|
||||
|
||||
private val arrayClasses = mapOf(
|
||||
Pair("kotlin.ByteArray", -1),
|
||||
Pair("kotlin.CharArray", -2),
|
||||
Pair("kotlin.IntArray", -4),
|
||||
Pair("kotlin.String", -1)
|
||||
);
|
||||
"kotlin.Array" to -pointerSize,
|
||||
"kotlin.ByteArray" to -1,
|
||||
"kotlin.CharArray" to -2,
|
||||
"kotlin.IntArray" to -4,
|
||||
"kotlin.String" to -1
|
||||
)
|
||||
|
||||
private fun getInstanceSize(classType: LLVMOpaqueType?, className: FqName) : Int {
|
||||
val arraySize = arrayClasses.get(className.asString());
|
||||
|
||||
Reference in New Issue
Block a user