translator: add resolve Byte, Char and Boolean types, fix char type, add byte type
This commit is contained in:
@@ -380,7 +380,7 @@ abstract class BlockCodegen(open val state: TranslationState, open val variableM
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
val newVar = variableManager.receiveVariable(identifier, assignExpression.type!!, LLVMRegisterScope(), pointer = 1)
|
val newVar = variableManager.receiveVariable(identifier, LLVMMapStandardType(identifier, variable.type).type, LLVMRegisterScope(), pointer = 1)
|
||||||
codeBuilder.addConstant(newVar, assignExpression)
|
codeBuilder.addConstant(newVar, assignExpression)
|
||||||
variableManager.addVariable(identifier, newVar, scopeDepth)
|
variableManager.addVariable(identifier, newVar, scopeDepth)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ fun LLVMMapStandardType(name: String, type: KotlinType, scope: LLVMScope = LLVMR
|
|||||||
type.isFunctionTypeOrSubtype -> LLVMVariable(name, LLVMFunctionType(type), type.toString(), scope, pointer = 1)
|
type.isFunctionTypeOrSubtype -> LLVMVariable(name, LLVMFunctionType(type), type.toString(), scope, pointer = 1)
|
||||||
type.toString() == "Int" -> LLVMVariable(name, LLVMIntType(), type.toString(), scope)
|
type.toString() == "Int" -> LLVMVariable(name, LLVMIntType(), type.toString(), scope)
|
||||||
type.toString() == "Double" -> LLVMVariable(name, LLVMDoubleType(), type.toString(), scope)
|
type.toString() == "Double" -> LLVMVariable(name, LLVMDoubleType(), type.toString(), scope)
|
||||||
|
type.toString() == "Byte" -> LLVMVariable(name, LLVMByteType(), type.toString(), scope)
|
||||||
|
type.toString() == "Char" -> LLVMVariable(name, LLVMCharType(), type.toString(), scope)
|
||||||
|
type.toString() == "Boolean" -> LLVMVariable(name, LLVMBooleanType(), type.toString(), scope)
|
||||||
type.isUnit() -> LLVMVariable("", LLVMVoidType(), "", scope)
|
type.isUnit() -> LLVMVariable("", LLVMVoidType(), "", scope)
|
||||||
type.isMarkedNullable -> LLVMVariable(name, LLVMReferenceType("${type.toString().dropLast(1)}"), name, scope, pointer = 1)
|
type.isMarkedNullable -> LLVMVariable(name, LLVMReferenceType("${type.toString().dropLast(1)}"), name, scope, pointer = 1)
|
||||||
else -> LLVMVariable(name, LLVMReferenceType("$type"), name, scope, pointer = 1)
|
else -> LLVMVariable(name, LLVMReferenceType("$type"), name, scope, pointer = 1)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package org.kotlinnative.translator.llvm.types
|
|||||||
import org.kotlinnative.translator.llvm.LLVMExpression
|
import org.kotlinnative.translator.llvm.LLVMExpression
|
||||||
import org.kotlinnative.translator.llvm.LLVMSingleValue
|
import org.kotlinnative.translator.llvm.LLVMSingleValue
|
||||||
|
|
||||||
class LLVMCharType() : LLVMType() {
|
class LLVMByteType() : LLVMType() {
|
||||||
override fun operatorLt(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
override fun operatorLt(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
LLVMExpression(LLVMBooleanType(), "icmp slt i8 $firstOp, $secondOp")
|
LLVMExpression(LLVMBooleanType(), "icmp slt i8 $firstOp, $secondOp")
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package org.kotlinnative.translator.llvm.types
|
||||||
|
|
||||||
|
import org.kotlinnative.translator.llvm.LLVMExpression
|
||||||
|
import org.kotlinnative.translator.llvm.LLVMSingleValue
|
||||||
|
|
||||||
|
class LLVMCharType() : LLVMType() {
|
||||||
|
override fun operatorLt(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
|
LLVMExpression(LLVMBooleanType(), "icmp slt i8 $firstOp, $secondOp")
|
||||||
|
|
||||||
|
override fun operatorGt(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
|
LLVMExpression(LLVMBooleanType(), "icmp sgt i8 $firstOp, $secondOp")
|
||||||
|
|
||||||
|
override fun operatorLeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
|
LLVMExpression(LLVMBooleanType(), "icmp sle i8 $firstOp, $secondOp")
|
||||||
|
|
||||||
|
override fun operatorGeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
|
LLVMExpression(LLVMBooleanType(), "icmp sge i8 $firstOp, $secondOp")
|
||||||
|
|
||||||
|
override fun operatorEq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
|
LLVMExpression(LLVMBooleanType(), "icmp eq i8 $firstOp, $secondOp")
|
||||||
|
|
||||||
|
override fun operatorNeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
|
LLVMExpression(LLVMBooleanType(), "icmp ne i8 $firstOp, $secondOp")
|
||||||
|
|
||||||
|
override val align = 1
|
||||||
|
override val size: Byte = 1
|
||||||
|
override fun toString(): String = "i8"
|
||||||
|
override val defaultValue = "0"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user