translator: add basic for enum types
This commit is contained in:
@@ -7,10 +7,7 @@ import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.kotlinnative.translator.exceptions.TranslationException
|
||||
import org.kotlinnative.translator.llvm.*
|
||||
import org.kotlinnative.translator.llvm.types.LLVMCharType
|
||||
import org.kotlinnative.translator.llvm.types.LLVMReferenceType
|
||||
import org.kotlinnative.translator.llvm.types.LLVMType
|
||||
import org.kotlinnative.translator.llvm.types.LLVMVoidType
|
||||
import org.kotlinnative.translator.llvm.types.*
|
||||
import java.util.*
|
||||
|
||||
class ClassCodegen(val state: TranslationState, val variableManager: VariableManager, val clazz: KtClass, val codeBuilder: LLVMBuilder) {
|
||||
@@ -43,6 +40,16 @@ class ClassCodegen(val state: TranslationState, val variableManager: VariableMan
|
||||
offset++
|
||||
}
|
||||
}
|
||||
when (descriptor.kind) {
|
||||
ClassKind.ENUM_CLASS -> {
|
||||
val item = LLVMClassVariable("enum_item", LLVMEnumItemType())
|
||||
item.offset = offset
|
||||
fields.add(item)
|
||||
fieldsIndex["enum_item"] = item
|
||||
currentSize += type.size
|
||||
offset++
|
||||
}
|
||||
}
|
||||
|
||||
size = currentSize
|
||||
}
|
||||
@@ -77,6 +84,9 @@ class ClassCodegen(val state: TranslationState, val variableManager: VariableMan
|
||||
}
|
||||
|
||||
private fun generatePrimaryConstructor() {
|
||||
val classData = state.bindingContext.get(BindingContext.CLASS, clazz)
|
||||
val classKind = classData?.kind
|
||||
//if (classKind == ClassKind.ENUM_CLASS)
|
||||
val argFields = ArrayList<LLVMVariable>()
|
||||
val refType = type.makeClone() as LLVMReferenceType
|
||||
refType.addParam("sret")
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.kotlinnative.translator.llvm.types
|
||||
|
||||
import org.kotlinnative.translator.llvm.LLVMExpression
|
||||
import org.kotlinnative.translator.llvm.LLVMSingleValue
|
||||
|
||||
|
||||
class LLVMEnumItemType() : LLVMType() {
|
||||
|
||||
override val align = 4
|
||||
override val size: Byte = 4
|
||||
override val defaultValue = "0"
|
||||
|
||||
override fun toString() = "i32"
|
||||
}
|
||||
Reference in New Issue
Block a user