translator: fix resolving between arm, x64
This commit is contained in:
@@ -28,7 +28,7 @@ class ClassCodegen(state: TranslationState,
|
||||
override val type: LLVMReferenceType
|
||||
|
||||
init {
|
||||
type = LLVMReferenceType(structName, "class", align = state.pointerAlign, size = state.pointerSize, byRef = true)
|
||||
type = LLVMReferenceType(structName, "class", align = TranslationState.pointerAlign, size = TranslationState.pointerSize, byRef = true)
|
||||
if (parentCodegen != null) {
|
||||
type.location.addAll(parentCodegen.type.location)
|
||||
type.location.add(parentCodegen.structName)
|
||||
@@ -45,7 +45,7 @@ class ClassCodegen(state: TranslationState,
|
||||
|
||||
calculateTypeSize()
|
||||
type.size = size
|
||||
type.align = state.pointerAlign
|
||||
type.align = TranslationState.pointerAlign
|
||||
}
|
||||
|
||||
private fun indexFields(parameters: MutableList<KtParameter>) {
|
||||
|
||||
@@ -21,7 +21,7 @@ class ObjectCodegen(state: TranslationState,
|
||||
override val type: LLVMReferenceType
|
||||
|
||||
init {
|
||||
type = LLVMReferenceType(structName, "class", align = state.pointerAlign, size = state.pointerSize, byRef = true)
|
||||
type = LLVMReferenceType(structName, "class", align = TranslationState.pointerAlign, size = TranslationState.pointerSize, byRef = true)
|
||||
if (parentCodegen != null) {
|
||||
type.location.addAll(parentCodegen.type.location)
|
||||
type.location.add(parentCodegen.structName)
|
||||
@@ -33,7 +33,7 @@ class ObjectCodegen(state: TranslationState,
|
||||
|
||||
calculateTypeSize()
|
||||
type.size = size
|
||||
type.align = state.pointerAlign
|
||||
type.align = TranslationState.pointerAlign
|
||||
}
|
||||
|
||||
override fun prepareForGenerate() {
|
||||
|
||||
@@ -55,7 +55,7 @@ abstract class StructCodegen(val state: TranslationState,
|
||||
size = 0
|
||||
|
||||
for (item in fields) {
|
||||
val currentFieldType = if (item.pointer > 0) state.pointerSize else item.type.size
|
||||
val currentFieldType = if (item.pointer > 0) TranslationState.pointerSize else item.type.size
|
||||
alignmentRemainder -= (alignmentRemainder % currentFieldType)
|
||||
if (alignmentRemainder < currentFieldType) {
|
||||
size += classAlignment
|
||||
|
||||
@@ -26,6 +26,15 @@ import org.kotlinnative.translator.llvm.LLVMVariable
|
||||
import java.util.*
|
||||
|
||||
class TranslationState(val environment: KotlinCoreEnvironment, val bindingContext: BindingContext, val arm: Boolean) {
|
||||
companion object {
|
||||
var pointerAlign = 4
|
||||
var pointerSize = 4
|
||||
}
|
||||
|
||||
init {
|
||||
pointerAlign = if (arm) 4 else 8
|
||||
pointerSize = if (arm) 4 else 8
|
||||
}
|
||||
|
||||
var externalFunctions = HashMap<String, FunctionCodegen>()
|
||||
var functions = HashMap<String, FunctionCodegen>()
|
||||
@@ -34,8 +43,7 @@ class TranslationState(val environment: KotlinCoreEnvironment, val bindingContex
|
||||
var objects = HashMap<String, ObjectCodegen>()
|
||||
var properties = HashMap<String, PropertyCodegen>()
|
||||
val codeBuilder = LLVMBuilder(arm)
|
||||
val pointerAlign = if (arm) 4 else 8
|
||||
val pointerSize = if (arm) 4 else 8
|
||||
|
||||
val extensionFunctions = HashMap<String, HashMap<String, FunctionCodegen>>()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.kotlinnative.translator.llvm
|
||||
|
||||
import org.kotlinnative.translator.TranslationState
|
||||
import org.kotlinnative.translator.llvm.types.*
|
||||
import java.util.*
|
||||
|
||||
class LLVMBuilder(val arm: Boolean = false) {
|
||||
private val POINTER_SIZE = 4
|
||||
|
||||
private var localCode: StringBuilder = StringBuilder()
|
||||
private var globalCode: StringBuilder = StringBuilder()
|
||||
@@ -166,7 +166,7 @@ class LLVMBuilder(val arm: Boolean = false) {
|
||||
}
|
||||
|
||||
fun storeNull(result: LLVMVariable) {
|
||||
val code = "store ${result.getType().dropLast(1)} null, ${result.getType()} $result, align $POINTER_SIZE"
|
||||
val code = "store ${result.getType().dropLast(1)} null, ${result.getType()} $result, align ${TranslationState.pointerAlign}"
|
||||
localCode.appendln(code)
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ class LLVMBuilder(val arm: Boolean = false) {
|
||||
fun allocStaticVar(target: LLVMVariable, asValue: Boolean = false) {
|
||||
val allocated = getNewVariable(LLVMCharType(), pointer = 1)
|
||||
|
||||
val size = if (target.pointer > 0) POINTER_SIZE else target.type.size
|
||||
val size = if (target.pointer > 0) TranslationState.pointerSize else target.type.size
|
||||
val alloc = "$allocated = call i8* @malloc_heap(i32 $size)"
|
||||
localCode.appendln(alloc)
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ fun LLVMInstanceOfStandardType(name: String, type: KotlinType, scope: LLVMScope
|
||||
type.isUnit() -> LLVMVariable("", LLVMVoidType(), name, scope)
|
||||
type.isMarkedNullable -> LLVMVariable(name, LLVMReferenceType(typeName, prefix = "class"), name, scope, pointer = pointerMark)
|
||||
else -> {
|
||||
val refType = state.classes[type.toString()]?.type ?: LLVMReferenceType(typeName, align = state.pointerAlign, prefix = "class")
|
||||
val refType = state.classes[type.toString()]?.type ?: LLVMReferenceType(typeName, align = TranslationState.pointerAlign, prefix = "class")
|
||||
|
||||
val result = LLVMVariable(name, refType, name, scope, pointer = 1)
|
||||
refType.location.addAll(type.getSubtypesPredicate().toString().split(".").dropLast(1))
|
||||
|
||||
+6
-1
@@ -1,10 +1,15 @@
|
||||
package org.kotlinnative.translator.llvm.types
|
||||
|
||||
import org.kotlinnative.translator.TranslationState
|
||||
import org.kotlinnative.translator.llvm.LLVMExpression
|
||||
import org.kotlinnative.translator.llvm.LLVMSingleValue
|
||||
import java.util.*
|
||||
|
||||
class LLVMReferenceType(val type: String, var prefix: String = "", override var align: Int = 4, override var size: Int = 4, var byRef: Boolean = true) : LLVMReferred, LLVMType() {
|
||||
class LLVMReferenceType(val type: String,
|
||||
var prefix: String = "",
|
||||
override var align: Int = TranslationState.pointerAlign,
|
||||
override var size: Int = TranslationState.pointerSize,
|
||||
var byRef: Boolean = true) : LLVMReferred, LLVMType() {
|
||||
|
||||
override val defaultValue: String = "null"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user