IR: prefix immediate values with '#' for human readability reasons (no technical reason)

This commit is contained in:
Irmen de Jong 2024-12-24 08:29:18 +01:00
parent 5071da6784
commit 2ca4aed566
6 changed files with 22 additions and 16 deletions

View File

@ -233,8 +233,8 @@ sys {
cx16 { cx16 {
; the sixteen virtual 16-bit registers that the CX16 has defined in the zeropage ; the sixteen virtual 16-bit registers that the Commander X16 has defined in the zeropage
; they are simulated on the VirtualMachine as well but their location in memory is different ; they are on the VirtualMachine as well, but their location in memory is different
&uword r0 = $ff02 &uword r0 = $ff02
&uword r1 = $ff04 &uword r1 = $ff04
&uword r2 = $ff06 &uword r2 = $ff06

View File

@ -46,9 +46,6 @@ Future Things and Ideas
IR/VM IR/VM
----- -----
- cx16.r0-r15 should not be translated to their (fake) addresses but remain symbolical, so they can be translated to what the actual target system specifies for them.
- prefix immediate values with '#' for readability reasons (no technical reason)
- ExpressionCodeResult: get rid of the separation between single result register and multiple result registers?
- implement missing operators in AssignmentGen (array shifts etc) - implement missing operators in AssignmentGen (array shifts etc)
- support %align on code chunks - support %align on code chunks
- fix call() return value handling - fix call() return value handling
@ -65,6 +62,7 @@ IR/VM
- getting it in shape for code generation... - getting it in shape for code generation...
- make optimizeBitTest work for IR too to use the BIT instruction? - make optimizeBitTest work for IR too to use the BIT instruction?
- make sure that a 6502 codegen based off the IR, still generates BIT instructions when testing bit 7 or 6 of a byte var. - make sure that a 6502 codegen based off the IR, still generates BIT instructions when testing bit 7 or 6 of a byte var.
- ExpressionCodeResult: get rid of the separation between single result register and multiple result registers? maybe not, this requires hundreds of lines to change
Libraries Libraries

View File

@ -1,14 +1,22 @@
%import textio
%zeropage basicsafe %zeropage basicsafe
%option no_sysinit %option no_sysinit
main { main {
sub start() { sub start() {
const ubyte CVALUE = 123 &ubyte mmvar = $2000
const long CLONG = 555555
ubyte @shared vvalue = 99
cx16.r0L = CVALUE + 100 txt.print_ub(@($2000))
cx16.r1L = vvalue + 100 txt.nl()
@($2000) = 123
txt.print_ub(@($2000))
txt.nl()
mmvar = 42
txt.print_ub(@($2000))
txt.nl()
cx16.r0 = 123
} }
} }

View File

@ -1106,11 +1106,11 @@ data class IRInstruction(
result.add(",") result.add(",")
} }
immediate?.let { immediate?.let {
result.add(it.toHex()) result.add("#${it.toHex()}")
result.add(",") result.add(",")
} }
immediateFp?.let { immediateFp?.let {
result.add(it.toString()) result.add("#${it}")
result.add(",") result.add(",")
} }
address?.let { address?.let {

View File

@ -137,8 +137,8 @@ fun parseIRCodeLine(line: String): Either<IRInstruction, String> {
if (fpReg1 == null) fpReg1 = oper.substring(2).toInt() if (fpReg1 == null) fpReg1 = oper.substring(2).toInt()
else if (fpReg2 == null) fpReg2 = oper.substring(2).toInt() else if (fpReg2 == null) fpReg2 = oper.substring(2).toInt()
else throw IRParseException("too many fp register operands") else throw IRParseException("too many fp register operands")
} else if (oper[0].isDigit() || oper[0] == '$' || oper[0] == '%' || oper[0] == '-' || oper.startsWith("0x")) { } else if (oper[0] in "0123456789$%-#" || oper.startsWith("0x")) {
val value = parseIRValue(oper) val value = if(oper[0]=='#') parseIRValue(oper.drop(1)) else parseIRValue(oper)
if (format.immediate) { if (format.immediate) {
if (immediateInt == null && immediateFp == null) { if (immediateInt == null && immediateFp == null) {
if (type == IRDataType.FLOAT) if (type == IRDataType.FLOAT)

View File

@ -34,7 +34,7 @@ class TestInstructions: FunSpec({
ins.immediate shouldBe 0 ins.immediate shouldBe 0
ins.immediateFp shouldBe null ins.immediateFp shouldBe null
ins.labelSymbol shouldBe null ins.labelSymbol shouldBe null
ins.toString() shouldBe "add.b r42,0,$63" ins.toString() shouldBe "add.b r42,#0,$63"
} }
test("with label") { test("with label") {
@ -49,7 +49,7 @@ class TestInstructions: FunSpec({
ins.immediate shouldBe 0 ins.immediate shouldBe 0
ins.immediateFp shouldBe null ins.immediateFp shouldBe null
ins.labelSymbol shouldBe "a.b.c" ins.labelSymbol shouldBe "a.b.c"
ins.toString() shouldBe "add.w r11,0,a.b.c" ins.toString() shouldBe "add.w r11,#0,a.b.c"
} }
test("with output registers") { test("with output registers") {