From a7b667f284a7563166486d08c72a791891a67a5e Mon Sep 17 00:00:00 2001 From: Andre Fachat Date: Thu, 2 Nov 2023 11:17:52 +0100 Subject: [PATCH] oplisting --- xa/src/xalisting.c | 9 ++++++--- xa/src/xat.c | 14 +++++++------- xa/tests/listing/Makefile | 6 +++++- xa/tests/listing/operators.a65 | 16 ++++++++++++++++ xa/tests/listing/operators.out | 17 +++++++++++++++++ 5 files changed, 51 insertions(+), 11 deletions(-) create mode 100644 xa/tests/listing/operators.a65 create mode 100644 xa/tests/listing/operators.out diff --git a/xa/src/xalisting.c b/xa/src/xalisting.c index 8423884..b63f78e 100644 --- a/xa/src/xalisting.c +++ b/xa/src/xalisting.c @@ -448,8 +448,8 @@ int list_tokens(char *buf, signed char *input, int len) { #endif } + int operator = 0; while (inp < len) { - int operator = 0; switch(input[inp]) { case T_CAST: @@ -582,11 +582,14 @@ int list_tokens(char *buf, signed char *input, int len) { if (operator && inp < len) { signed char op = input[inp]; - if (op > 0 && op <= 17) { + if (op > 0 && op <= 20) { // sizeof(arith_ops) outp += list_string(buf+outp, formatp->escape(arith_ops[op])); inp += 1; + operator = 0; } - operator = 0; + // note: falls through for closing brackets which are where an operator would normally be. + // closing bracket is then printed in upper (operand) part in default case before + // another operator is expected after the bracket } } end: diff --git a/xa/src/xat.c b/xa/src/xat.c index c44809d..8abf5d5 100644 --- a/xa/src/xat.c +++ b/xa/src/xat.c @@ -105,13 +105,13 @@ char *kt[] ={ /* arithmetic operators (purely for listing, parsing is done programmatically */ char *arith_ops[] = { - "", "+", "-", - "*", "/", - ">>", "<<", - "<", ">", "=" - "<=", ">=", "<>", - "&", "^", "|", - "&&", "||", "==", "!=", "!" + "", "+", "-", // 0,1,2 + "*", "/", // 3,4 + ">>", "<<", // 5,6 + "<", ">", "=", // 7,8,9 + "<=", ">=", "<>", // 10,11,12 + "&", "^", "|", // 13,14,15 + "&&", "||", "==", "!=", "!" // 16,17,18,19,20 }; /* length of arithmetic operators indexed by operator number */ diff --git a/xa/tests/listing/Makefile b/xa/tests/listing/Makefile index e5d4992..3fceef2 100644 --- a/xa/tests/listing/Makefile +++ b/xa/tests/listing/Makefile @@ -7,7 +7,11 @@ XA=../../xa CA65=ca65 LD65=ld65 -tests: assertx.out assertx.html linebreakx.out include1x.out listblocksx.html listca65x.html listca65_2x.html +tests: operatorsx.out assertx.out assertx.html linebreakx.out include1x.out listblocksx.html listca65x.html listca65_2x.html + +operatorsx.out: operators.a65 + ${XA} -P- -o operatorsx.o65 $< > $@ + ../hextool -cmp=operators.out < $@ assertx.out: assert.a65 ${XA} -P- -o assertx.o65 $< > $@ diff --git a/xa/tests/listing/operators.a65 b/xa/tests/listing/operators.a65 new file mode 100644 index 0000000..512a1e7 --- /dev/null +++ b/xa/tests/listing/operators.a65 @@ -0,0 +1,16 @@ + + +la9a5 =$a9a5 +lac15 =$ac15 +lad24 =$ad24 +lb3c0 =$b3c0 +laf28 =$af28 + +x1 =(la9a5^laf28)&$00ff +x2 =(lac15^laf28)&$00ff +x3 =(lad24^laf28)&$00ff +x4 =(lb3c0^laf28)&$00ff + +x5 =$ff&(la9a5|laf28) +x6 =$ff&(la9a5|laf28)&$00ff + diff --git a/xa/tests/listing/operators.out b/xa/tests/listing/operators.out new file mode 100644 index 0000000..5b142f5 --- /dev/null +++ b/xa/tests/listing/operators.out @@ -0,0 +1,17 @@ + +operators.a65 + + + 3 A:1000 la9a5=$a9a5 + 4 A:1000 lac15=$ac15 + 5 A:1000 lad24=$ad24 + 6 A:1000 lb3c0=$b3c0 + 7 A:1000 laf28=$af28 + + 9 A:1000 x1=(la9a5^laf28)&$ff + 10 A:1000 x2=(lac15^laf28)&$ff + 11 A:1000 x3=(lad24^laf28)&$ff + 12 A:1000 x4=(lb3c0^laf28)&$ff + + 14 A:1000 x5=$ff&(la9a5|laf28) + 15 A:1000 x6=$ff&(la9a5|laf28)&$ff