From 54aa66b96ea507e74b58131e45859bc76221352d Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Sun, 23 Apr 2023 10:09:42 +0200 Subject: [PATCH] Treating ASM bytes as expressions. --- .../dk/camelot64/kickc/fragment/AsmFragmentInstance.java | 9 ++++++--- src/test/ref/asm-culling-jmp.asm | 2 +- src/test/ref/asm-culling-jmp.log | 4 ++-- src/test/ref/c64dtv-8bppcharstretch.asm | 2 +- src/test/ref/c64dtv-8bppcharstretch.log | 4 ++-- src/test/ref/c64dtv-8bppchunkystretch.asm | 2 +- src/test/ref/c64dtv-8bppchunkystretch.log | 4 ++-- 7 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentInstance.java b/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentInstance.java index 38701f530..28c0e441b 100644 --- a/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentInstance.java +++ b/src/main/java/dk/camelot64/kickc/fragment/AsmFragmentInstance.java @@ -250,15 +250,18 @@ public class AsmFragmentInstance { @Override public Object visitAsmBytes(KickCParser.AsmBytesContext ctx) { + List asmExpr = ctx.asmExpr(); ArrayList values = new ArrayList<>(); - for(int i = 1; i < ctx.getChildCount(); i = i + 2) { - values.add(ctx.getChild(i).getText()); + for(int i = 0; i < asmExpr.size(); i++) { + if(asmExpr.get(i) != null) { + AsmParameter par = (AsmParameter)this.visit(asmExpr.get(i)); + values.add(par.getParam()); + } } AsmDataNumeric data = new AsmDataNumeric(null, AsmDataNumeric.Type.BYTE, values); handleTags(data, ctx.ASM_TAG()); return null; } - @Override public Object visitAsmInstruction(KickCParser.AsmInstructionContext ctx) { KickCParser.AsmParamModeContext paramModeCtx = ctx.asmParamMode(); diff --git a/src/test/ref/asm-culling-jmp.asm b/src/test/ref/asm-culling-jmp.asm index 39c886fa8..152a669fe 100644 --- a/src/test/ref/asm-culling-jmp.asm +++ b/src/test/ref/asm-culling-jmp.asm @@ -12,7 +12,7 @@ main: { // asm jmp qwe - .byte 0, 25, 51, 76, 102, 128, 153, 179, 204, 230 + .byte 0, $19, $33, $4c, $66, $80, $99, $b3, $cc, $e6 qwe: lda #$32 // *((char*)0x0400) = 'c' diff --git a/src/test/ref/asm-culling-jmp.log b/src/test/ref/asm-culling-jmp.log index 8f295f1ae..9870ae91e 100644 --- a/src/test/ref/asm-culling-jmp.log +++ b/src/test/ref/asm-culling-jmp.log @@ -83,7 +83,7 @@ ASSEMBLER BEFORE OPTIMIZATION main: { // asm { jmpqwe .byte0,25,51,76,102,128,153,179,204,230 qwe: lda#50 } jmp qwe - .byte 0, 25, 51, 76, 102, 128, 153, 179, 204, 230 + .byte 0, $19, $33, $4c, $66, $80, $99, $b3, $cc, $e6 qwe: lda #$32 // [1] *((char *) 1024) = 'c' -- _deref_pbuc1=vbuc2 @@ -130,7 +130,7 @@ main: { // asm // asm { jmpqwe .byte0,25,51,76,102,128,153,179,204,230 qwe: lda#50 } jmp qwe - .byte 0, 25, 51, 76, 102, 128, 153, 179, 204, 230 + .byte 0, $19, $33, $4c, $66, $80, $99, $b3, $cc, $e6 qwe: lda #$32 // *((char*)0x0400) = 'c' diff --git a/src/test/ref/c64dtv-8bppcharstretch.asm b/src/test/ref/c64dtv-8bppcharstretch.asm index 13c88352a..8fadfc7eb 100644 --- a/src/test/ref/c64dtv-8bppcharstretch.asm +++ b/src/test/ref/c64dtv-8bppcharstretch.asm @@ -457,7 +457,7 @@ dtvSetCpuBankSegment1: { // asm .byte $32, $dd lda.z $ff - .byte $32, $00 + .byte $32, 0 // } rts } diff --git a/src/test/ref/c64dtv-8bppcharstretch.log b/src/test/ref/c64dtv-8bppcharstretch.log index 4c5a4bc2e..9e674183c 100644 --- a/src/test/ref/c64dtv-8bppcharstretch.log +++ b/src/test/ref/c64dtv-8bppcharstretch.log @@ -1872,7 +1872,7 @@ dtvSetCpuBankSegment1: { // asm { .byte$32,$dd lda$ff .byte$32,$00 } .byte $32, $dd lda.z $ff - .byte $32, $00 + .byte $32, 0 jmp __breturn // dtvSetCpuBankSegment1::@return __breturn: @@ -2714,7 +2714,7 @@ dtvSetCpuBankSegment1: { // asm { .byte$32,$dd lda$ff .byte$32,$00 } .byte $32, $dd lda.z $ff - .byte $32, $00 + .byte $32, 0 // dtvSetCpuBankSegment1::@return // } // [87] return diff --git a/src/test/ref/c64dtv-8bppchunkystretch.asm b/src/test/ref/c64dtv-8bppchunkystretch.asm index 7ebe19652..becb0cb59 100644 --- a/src/test/ref/c64dtv-8bppchunkystretch.asm +++ b/src/test/ref/c64dtv-8bppchunkystretch.asm @@ -365,7 +365,7 @@ dtvSetCpuBankSegment1: { // asm .byte $32, $dd lda.z $ff - .byte $32, $00 + .byte $32, 0 // } rts } diff --git a/src/test/ref/c64dtv-8bppchunkystretch.log b/src/test/ref/c64dtv-8bppchunkystretch.log index cc100204f..932a1908c 100644 --- a/src/test/ref/c64dtv-8bppchunkystretch.log +++ b/src/test/ref/c64dtv-8bppchunkystretch.log @@ -1260,7 +1260,7 @@ dtvSetCpuBankSegment1: { // asm { .byte$32,$dd lda$ff .byte$32,$00 } .byte $32, $dd lda.z $ff - .byte $32, $00 + .byte $32, 0 jmp __breturn // dtvSetCpuBankSegment1::@return __breturn: @@ -1881,7 +1881,7 @@ dtvSetCpuBankSegment1: { // asm { .byte$32,$dd lda$ff .byte$32,$00 } .byte $32, $dd lda.z $ff - .byte $32, $00 + .byte $32, 0 // dtvSetCpuBankSegment1::@return // } // [57] return