translator: add mod operator for all types
This commit is contained in:
@@ -716,6 +716,7 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
|||||||
"or" -> firstNativeOp.type!!.operatorOr(firstNativeOp, secondNativeOp)
|
"or" -> firstNativeOp.type!!.operatorOr(firstNativeOp, secondNativeOp)
|
||||||
"xor" -> firstNativeOp.type!!.operatorXor(firstNativeOp, secondNativeOp)
|
"xor" -> firstNativeOp.type!!.operatorXor(firstNativeOp, secondNativeOp)
|
||||||
"and" -> firstNativeOp.type!!.operatorAnd(firstNativeOp, secondNativeOp)
|
"and" -> firstNativeOp.type!!.operatorAnd(firstNativeOp, secondNativeOp)
|
||||||
|
"%" -> firstNativeOp.type!!.operatorMod(firstNativeOp, secondNativeOp)
|
||||||
"shl" -> {
|
"shl" -> {
|
||||||
var secondNativeOpWithRequiredType = secondNativeOp
|
var secondNativeOpWithRequiredType = secondNativeOp
|
||||||
if (firstNativeOp.type != secondNativeOp.type) {
|
if (firstNativeOp.type != secondNativeOp.type) {
|
||||||
@@ -765,6 +766,13 @@ abstract class BlockCodegen(val state: TranslationState, val variableManager: Va
|
|||||||
codeBuilder.storeVariable(firstOp, resultOp)
|
codeBuilder.storeVariable(firstOp, resultOp)
|
||||||
return LLVMExpression(resultOp.type, "load ${firstOp.getType()} $firstOp, align ${firstOp.type!!.align}")
|
return LLVMExpression(resultOp.type, "load ${firstOp.getType()} $firstOp, align ${firstOp.type!!.align}")
|
||||||
}
|
}
|
||||||
|
"%=" -> {
|
||||||
|
val llvmExpression = firstNativeOp.type!!.operatorMod(firstNativeOp, secondNativeOp)
|
||||||
|
val resultOp = codeBuilder.getNewVariable(llvmExpression.variableType)
|
||||||
|
codeBuilder.addAssignment(resultOp, llvmExpression)
|
||||||
|
codeBuilder.storeVariable(firstOp, resultOp)
|
||||||
|
return LLVMExpression(resultOp.type, "load ${firstOp.getType()} $firstOp, align ${firstOp.type!!.align}")
|
||||||
|
}
|
||||||
else -> throw UnsupportedOperationException("Unknown binary operator")
|
else -> throw UnsupportedOperationException("Unknown binary operator")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ class LLVMByteType() : LLVMType() {
|
|||||||
override fun operatorNeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
override fun operatorNeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
LLVMExpression(LLVMBooleanType(), "icmp ne i8 $firstOp, $secondOp")
|
LLVMExpression(LLVMBooleanType(), "icmp ne i8 $firstOp, $secondOp")
|
||||||
|
|
||||||
|
override fun operatorMod(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
|
LLVMExpression(LLVMByteType(), "srem i8 $firstOp, $secondOp")
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
return other is LLVMByteType
|
return other is LLVMByteType
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ class LLVMDoubleType() : LLVMType() {
|
|||||||
override fun operatorNeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
override fun operatorNeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
LLVMExpression(LLVMBooleanType(), "fcmp one double $firstOp, $secondOp")
|
LLVMExpression(LLVMBooleanType(), "fcmp one double $firstOp, $secondOp")
|
||||||
|
|
||||||
|
override fun operatorMod(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
|
LLVMExpression(LLVMDoubleType(), "frem double $firstOp, $secondOp")
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
return other is LLVMDoubleType
|
return other is LLVMDoubleType
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ class LLVMFloatType() : LLVMType() {
|
|||||||
override fun operatorNeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
override fun operatorNeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
LLVMExpression(LLVMBooleanType(), "fcmp one float $firstOp, $secondOp")
|
LLVMExpression(LLVMBooleanType(), "fcmp one float $firstOp, $secondOp")
|
||||||
|
|
||||||
|
override fun operatorMod(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
|
LLVMExpression(LLVMFloatType(), "frem float $firstOp, $secondOp")
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
return other is LLVMFloatType
|
return other is LLVMFloatType
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,6 +61,9 @@ class LLVMIntType() : LLVMType() {
|
|||||||
override fun operatorNeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
override fun operatorNeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
LLVMExpression(LLVMBooleanType(), "icmp ne i32 $firstOp, $secondOp")
|
LLVMExpression(LLVMBooleanType(), "icmp ne i32 $firstOp, $secondOp")
|
||||||
|
|
||||||
|
override fun operatorMod(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
|
LLVMExpression(LLVMIntType(), "srem i32 $firstOp, $secondOp")
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
return other is LLVMIntType
|
return other is LLVMIntType
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ class LLVMLongType() : LLVMType() {
|
|||||||
override fun operatorGt(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
override fun operatorGt(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
LLVMExpression(LLVMBooleanType(), "icmp sgt i64 $firstOp, $secondOp")
|
LLVMExpression(LLVMBooleanType(), "icmp sgt i64 $firstOp, $secondOp")
|
||||||
|
|
||||||
|
|
||||||
override fun operatorLeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
override fun operatorLeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
LLVMExpression(LLVMBooleanType(), "icmp sle i64 $firstOp, $secondOp")
|
LLVMExpression(LLVMBooleanType(), "icmp sle i64 $firstOp, $secondOp")
|
||||||
|
|
||||||
@@ -56,6 +55,9 @@ class LLVMLongType() : LLVMType() {
|
|||||||
override fun operatorNeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
override fun operatorNeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
LLVMExpression(LLVMBooleanType(), "icmp ne i64 $firstOp, $secondOp")
|
LLVMExpression(LLVMBooleanType(), "icmp ne i64 $firstOp, $secondOp")
|
||||||
|
|
||||||
|
override fun operatorMod(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
|
LLVMExpression(LLVMLongType(), "srem i64 $firstOp, $secondOp")
|
||||||
|
|
||||||
override fun convertFrom(source: LLVMSingleValue): LLVMExpression = when (source.type!!) {
|
override fun convertFrom(source: LLVMSingleValue): LLVMExpression = when (source.type!!) {
|
||||||
is LLVMBooleanType,
|
is LLVMBooleanType,
|
||||||
is LLVMByteType,
|
is LLVMByteType,
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ class LLVMShortType() : LLVMType() {
|
|||||||
override fun operatorNeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
override fun operatorNeq(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
LLVMExpression(LLVMBooleanType(), "icmp ne i16 $firstOp, $secondOp")
|
LLVMExpression(LLVMBooleanType(), "icmp ne i16 $firstOp, $secondOp")
|
||||||
|
|
||||||
|
override fun operatorMod(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression =
|
||||||
|
LLVMExpression(LLVMShortType(), "srem i16 $firstOp, $secondOp")
|
||||||
|
|
||||||
override fun equals(other: Any?): Boolean {
|
override fun equals(other: Any?): Boolean {
|
||||||
return other is LLVMShortType
|
return other is LLVMShortType
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ abstract class LLVMType() : Cloneable {
|
|||||||
open fun operatorShl(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = throw UnimplementedException()
|
open fun operatorShl(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = throw UnimplementedException()
|
||||||
open fun operatorShr(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = throw UnimplementedException()
|
open fun operatorShr(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = throw UnimplementedException()
|
||||||
open fun operatorUshr(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = throw UnimplementedException()
|
open fun operatorUshr(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = throw UnimplementedException()
|
||||||
|
open fun operatorMod(firstOp: LLVMSingleValue, secondOp: LLVMSingleValue): LLVMExpression = throw UnimplementedException()
|
||||||
open fun operatorInc(firstOp: LLVMSingleValue): LLVMExpression = throw UnimplementedException()
|
open fun operatorInc(firstOp: LLVMSingleValue): LLVMExpression = throw UnimplementedException()
|
||||||
open fun operatorDec(firstOp: LLVMSingleValue): LLVMExpression = throw UnimplementedException()
|
open fun operatorDec(firstOp: LLVMSingleValue): LLVMExpression = throw UnimplementedException()
|
||||||
open fun parseArg(inputArg: String) = inputArg
|
open fun parseArg(inputArg: String) = inputArg
|
||||||
|
|||||||
Reference in New Issue
Block a user