translator: add not operator
This commit is contained in:
@@ -568,6 +568,13 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
||||
KtTokens.PLUS -> {
|
||||
return addPrimitiveBinaryOperation(operator!!, operationReference, LLVMConstant("0", firstOp.type), firstOp)
|
||||
}
|
||||
KtTokens.EXCL -> {
|
||||
val firstNativeOp = codeBuilder.receiveNativeValue(firstOp)
|
||||
val llvmExpression = addPrimitiveReferenceOperationByName("xor", LLVMConstant("true", LLVMBooleanType()), firstNativeOp)
|
||||
val resultOp = codeBuilder.getNewVariable(llvmExpression.variableType)
|
||||
codeBuilder.addAssignment(resultOp, llvmExpression)
|
||||
return resultOp
|
||||
}
|
||||
else -> throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
@@ -606,9 +613,12 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
||||
return left
|
||||
}
|
||||
|
||||
fun addPrimitiveReferenceOperation(referenceName: KtSimpleNameExpression, firstOp: LLVMSingleValue, secondNativeOp: LLVMSingleValue): LLVMExpression {
|
||||
fun addPrimitiveReferenceOperation(referenceName: KtSimpleNameExpression, firstOp: LLVMSingleValue, secondNativeOp: LLVMSingleValue): LLVMExpression
|
||||
= addPrimitiveReferenceOperationByName(referenceName.getReferencedName(), firstOp, secondNativeOp)
|
||||
|
||||
fun addPrimitiveReferenceOperationByName(operator: String, firstOp: LLVMSingleValue, secondNativeOp: LLVMSingleValue): LLVMExpression {
|
||||
val firstNativeOp = codeBuilder.receiveNativeValue(firstOp)
|
||||
return when (referenceName.getReferencedName()) {
|
||||
return when (operator) {
|
||||
"or" -> firstNativeOp.type!!.operatorOr(firstNativeOp, secondNativeOp)
|
||||
"xor" -> firstNativeOp.type!!.operatorXor(firstNativeOp, secondNativeOp)
|
||||
"and" -> firstNativeOp.type!!.operatorAnd(firstNativeOp, secondNativeOp)
|
||||
|
||||
@@ -37,6 +37,15 @@ class LLVMBooleanType() : LLVMType() {
|
||||
override fun operatorNeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||
LLVMExpression(LLVMBooleanType(), "icmp ne i1 $firstOp, $secondOp")
|
||||
|
||||
override fun operatorOr(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||
LLVMExpression(LLVMBooleanType(), "or i1 $firstOp, $secondOp")
|
||||
|
||||
override fun operatorAnd(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||
LLVMExpression(LLVMBooleanType(), "and i1 $firstOp, $secondOp")
|
||||
|
||||
override fun operatorXor(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||
LLVMExpression(LLVMBooleanType(), "xor i1 $firstOp, $secondOp")
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return other is LLVMBooleanType
|
||||
}
|
||||
|
||||
@@ -2,3 +2,5 @@ unary_operator_1_minus_Int(-5) == 5
|
||||
unary_operator_1_minus_Int(5) == -5
|
||||
unary_operator_1_plus_Int(-5) == -5
|
||||
unary_operator_1_plus_Int(5) == 5
|
||||
unary_operator_1_not_Boolean(1) == 0
|
||||
unary_operator_1_not_Boolean(0) == 1
|
||||
|
||||
@@ -4,4 +4,8 @@ fun unary_operator_1_minus(x : Int): Int {
|
||||
|
||||
fun unary_operator_1_plus(x : Int): Int {
|
||||
return x
|
||||
}
|
||||
|
||||
fun unary_operator_1_not(x : Boolean): Boolean {
|
||||
return !x
|
||||
}
|
||||
Reference in New Issue
Block a user