From 3bd3fd874994a669a554b41e3b9d3b31f3c65534 Mon Sep 17 00:00:00 2001 From: Chris Cacciatore Date: Sun, 14 Aug 2016 19:55:03 -0700 Subject: [PATCH 1/5] Removed check for LCURLY in switch statements. --- src/cc65/swstmt.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/cc65/swstmt.c b/src/cc65/swstmt.c index 0aefc051c..f71c3e40a 100644 --- a/src/cc65/swstmt.c +++ b/src/cc65/swstmt.c @@ -144,11 +144,6 @@ void SwitchStatement (void) /* Create a loop so we may use break. */ AddLoop (ExitLabel, 0); - /* Make sure a curly brace follows */ - if (CurTok.Tok != TOK_LCURLY) { - Error ("`{' expected"); - } - /* Parse the following statement, which will actually be a compound ** statement because of the curly brace at the current input position */ From c4823c6fd4c152c6cdf037984a804b35969114d2 Mon Sep 17 00:00:00 2001 From: Chris Cacciatore Date: Mon, 15 Aug 2016 11:26:03 -0700 Subject: [PATCH 2/5] Added Duff's Device to tests. --- test/val/duffs-device.c | 76 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 test/val/duffs-device.c diff --git a/test/val/duffs-device.c b/test/val/duffs-device.c new file mode 100644 index 000000000..effb33bb2 --- /dev/null +++ b/test/val/duffs-device.c @@ -0,0 +1,76 @@ +/* + !!DESCRIPTION!! Implementation of Duff's device (loop unrolling). + !!ORIGIN!! + !!LICENCE!! GPL, read COPYING.GPL +*/ + +#include +#include + +#define ASIZE (100) + +unsigned char success=0; +unsigned char failures=0; +unsigned char dummy=0; + +#ifdef SUPPORT_BIT_TYPES +bit bit0 = 0; +#endif + +void done() +{ + dummy++; +} + +int acmp(char* a, char* b, int count) +{ + int i; + + for(i = 0; i < count; i++) { + if(a[i] != b[i]) { + return 1; + } + } + return 0; +} + +void duffit (char* to, char* from, int count) +{ + int n = (count + 7) / 8; + + switch(count % 8) { + case 0: do { *to++ = *from++; + case 7: *to++ = *from++; + case 6: *to++ = *from++; + case 5: *to++ = *from++; + case 4: *to++ = *from++; + case 3: *to++ = *from++; + case 2: *to++ = *from++; + case 1: *to++ = *from++; + } while(--n > 0); + } +} + +int main(void) +{ + char a[ASIZE] = {1}; + char b[ASIZE] = {2}; + + /* a and b should be different */ + if(!acmp(a, b, ASIZE)) { + failures++; + } + + duffit(a, b, ASIZE); + + /* a and b should be the same */ + if(acmp(a, b, ASIZE)) { + failures++; + } + + success=failures; + done(); + printf("failures: %d\n",failures); + + return failures; +} From ac4bdbd411af5cafe1062693816b806f51f3b6e7 Mon Sep 17 00:00:00 2001 From: Chris Cacciatore Date: Mon, 15 Aug 2016 11:36:50 -0700 Subject: [PATCH 3/5] Now testing switch statements with empty bodies. --- test/val/switch2.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/val/switch2.c diff --git a/test/val/switch2.c b/test/val/switch2.c new file mode 100644 index 000000000..00206b0f6 --- /dev/null +++ b/test/val/switch2.c @@ -0,0 +1,39 @@ +/* + !!DESCRIPTION!! Testing empty bodied switch statements. + !!ORIGIN!! + !!LICENCE!! GPL, read COPYING.GPL +*/ + +#include + +unsigned char success=0; +unsigned char failures=0; +unsigned char dummy=0; + +void done() +{ + dummy++; +} + +void switch_no_body(void) +{ + switch(0); +} + +void switch_empty_body(void) +{ + switch(0) {}; +} + +/* only worried about this file compiling successfully */ +int main(void) +{ + switch_no_body(); + switch_empty_body(); + + success=failures; + done(); + printf("failures: %d\n",failures); + + return failures; +} From 791981237851b289533696a0583b340a0613fb7f Mon Sep 17 00:00:00 2001 From: Chris Cacciatore Date: Fri, 19 Aug 2016 20:21:10 -0700 Subject: [PATCH 4/5] Updated switch statement comments. * Now comments represent the fact that there may not be curly braces. --- src/cc65/swstmt.c | 4 ++-- test/val/switch2.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cc65/swstmt.c b/src/cc65/swstmt.c index f71c3e40a..e995bd0b7 100644 --- a/src/cc65/swstmt.c +++ b/src/cc65/swstmt.c @@ -144,8 +144,8 @@ void SwitchStatement (void) /* Create a loop so we may use break. */ AddLoop (ExitLabel, 0); - /* Parse the following statement, which will actually be a compound - ** statement because of the curly brace at the current input position + /* Parse the following statement, which may actually be a compound + ** statement if there is a curly brace at the current input position */ HaveBreak = Statement (&RCurlyBrace); diff --git a/test/val/switch2.c b/test/val/switch2.c index 00206b0f6..65c24eeda 100644 --- a/test/val/switch2.c +++ b/test/val/switch2.c @@ -22,7 +22,7 @@ void switch_no_body(void) void switch_empty_body(void) { - switch(0) {}; + switch(0) {} } /* only worried about this file compiling successfully */ From e9295b2a98734dc7a422f4a5b161a024d2f4ec22 Mon Sep 17 00:00:00 2001 From: Chris Cacciatore Date: Sat, 20 Aug 2016 09:42:29 -0700 Subject: [PATCH 5/5] Updated comment regarding curly braces. --- src/cc65/swstmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cc65/swstmt.c b/src/cc65/swstmt.c index e995bd0b7..512f4257d 100644 --- a/src/cc65/swstmt.c +++ b/src/cc65/swstmt.c @@ -194,7 +194,7 @@ void SwitchStatement (void) /* Free the case value tree */ FreeCaseNodeColl (SwitchData.Nodes); - /* If the case statement was (correctly) terminated by a closing curly + /* If the case statement was terminated by a closing curly ** brace, skip it now. */ if (RCurlyBrace) {