Files
mtmc-web/src/jvmMain/kotlin/mtmc/asm/instructions/ALUOp.kt

45 lines
991 B
Kotlin

package mtmc.asm.instructions
import java.util.*
enum class ALUOp(val opCode: Int, val isUnary: Boolean) {
ADD(0x0000, false),
SUB(0x0001, false),
MUL(0x0002, false),
DIV(0x0003, false),
MOD(0x0004, false),
AND(0x0005, false),
OR(0x0006, false),
XOR(0x0007, false),
SHL(0x0008, false),
SHR(0x0009, false),
MIN(0x000A, false),
MAX(0x000B, false),
NOT(0x000C, true),
LNOT(0x000D, true),
NEG(0x000E, true),
IMM(0x000F, true);
companion object {
@JvmStatic
fun toInteger(instruction: String): Int {
return valueOf(instruction.uppercase(Locale.getDefault())).opCode
}
@JvmStatic
fun fromInt(opCode: Short): String {
return entries[opCode.toInt()].name.lowercase(Locale.getDefault())
}
@JvmStatic
fun isALUOp(op: String): Boolean {
try {
val aluOp = valueOf(op.uppercase(Locale.getDefault()))
return true
} catch (e: IllegalArgumentException) {
return false
}
}
}
}