From ee5d8cc3cf606b35fc80484d4d7271192e72ad92 Mon Sep 17 00:00:00 2001 From: Nick Downing Date: Thu, 16 Feb 2017 15:41:27 +1100 Subject: [PATCH] Reinstate enum handling, removed since I was confused about a misplaced nl_strp --- c03.c | 20 +++++++++++--------- test/enu0.c | 8 ++++++++ test/enu0.dump | 23 +++++++++++++++++++++++ test/enu0.s | 13 +++++++++++++ test/enu1.c | 8 ++++++++ test/enu1.dump | 23 +++++++++++++++++++++++ test/enu1.s | 13 +++++++++++++ 7 files changed, 99 insertions(+), 9 deletions(-) create mode 100644 test/enu0.c create mode 100644 test/enu0.dump create mode 100644 test/enu0.s create mode 100644 test/enu1.c create mode 100644 test/enu1.dump create mode 100644 test/enu1.s diff --git a/c03.c b/c03.c index 06434e5..ca50a04 100644 --- a/c03.c +++ b/c03.c @@ -97,12 +97,12 @@ int declist(sclass) int sclass; { break; case ENUM: + /* note: this code accepts silly declarations like "enum a int b;" */ + /* it also accepts modifiers if placed later like "enum a long b;" */ + /* eventually we should modify this to be more like the struct case */ if (longf || unsignf) error0("Perverse modifier on 'enum'"); - /* strdec(ismos, cval);*/ - if (dtype) - error0("type clash"); - dtype = (struct type *)strdec(ismos, cval); + strdec(ismos, cval); cval = INT; goto types; @@ -113,15 +113,16 @@ int declist(sclass) int sclass; { error0("type clash"); dtype = (struct type *)strdec(ismos, cval); cval = STRUCT; - goto types; + goto types_struct; case INT: case CHAR: case FLOAT: case DOUBLE: case VOID: + types: if (dtype) goto type_clash; - types: + types_struct: if (tkw>=0 && (tkw!=INT || cval!=INT)) type_clash: error0("Type clash"); @@ -190,6 +191,7 @@ int declist(sclass) int sclass; { struct nmlist *mems[NMEMS]; /* struct nmlist typer;*/ int tagkind; + static struct type t_int = {INT}; if (kind!=ENUM) { tagkind = STRTAG; @@ -252,9 +254,9 @@ int declist(sclass) int sclass; { bitoffs = 0; if (kind==ENUM) { /* typer.nl_type = INT; - typer.nl_strp = strp; - declare(ENUM, &typer, 0);*/ - abort(); + typer.nl_strp = strp;*/ + /* strp above seems to be vestigial, I don't think it is ever referenced */ + declare(ENUM, /*&typer*/&t_int, 0); } else elsize = declist(kind==UNION?MOU:MOS); bitoffs = savebits; diff --git a/test/enu0.c b/test/enu0.c new file mode 100644 index 0000000..acfb503 --- /dev/null +++ b/test/enu0.c @@ -0,0 +1,8 @@ +enum silly { + i, + j +} a; +void main() { + a = i; + a = j; +} diff --git a/test/enu0.dump b/test/enu0.dump new file mode 100644 index 0000000..5edef93 --- /dev/null +++ b/test/enu0.dump @@ -0,0 +1,23 @@ +CSPACE a 2 +SYMDEF main +PROG +RLABEL main +SAVE +SETREG 5 +BRANCH 1 +LABEL 2 +NAME EXTERN INT a +CON INT 0 +ASSIGN INT +EXPR 6 +NAME EXTERN INT a +CON INT 1 +ASSIGN INT +EXPR 7 +LABEL 3 +RETRN +LABEL 1 +SETSTK 0 +BRANCH 2 +EOFC +*EOFC diff --git a/test/enu0.s b/test/enu0.s new file mode 100644 index 0000000..c53fad5 --- /dev/null +++ b/test/enu0.s @@ -0,0 +1,13 @@ +.comm _a,2 +.globl _main +.text +_main: +~~main: +jsr r5,csv +jbr L1 +L2:clr _a +mov $1,_a +L3:jmp cret +L1:jbr L2 +.globl +.data diff --git a/test/enu1.c b/test/enu1.c new file mode 100644 index 0000000..7f12004 --- /dev/null +++ b/test/enu1.c @@ -0,0 +1,8 @@ +enum silly { + i = 5, + j = 6 +} a; +void main() { + a = i; + a = j; +} diff --git a/test/enu1.dump b/test/enu1.dump new file mode 100644 index 0000000..d2b3019 --- /dev/null +++ b/test/enu1.dump @@ -0,0 +1,23 @@ +CSPACE a 2 +SYMDEF main +PROG +RLABEL main +SAVE +SETREG 5 +BRANCH 1 +LABEL 2 +NAME EXTERN INT a +CON INT 5 +ASSIGN INT +EXPR 6 +NAME EXTERN INT a +CON INT 6 +ASSIGN INT +EXPR 7 +LABEL 3 +RETRN +LABEL 1 +SETSTK 0 +BRANCH 2 +EOFC +*EOFC diff --git a/test/enu1.s b/test/enu1.s new file mode 100644 index 0000000..a7f227a --- /dev/null +++ b/test/enu1.s @@ -0,0 +1,13 @@ +.comm _a,2 +.globl _main +.text +_main: +~~main: +jsr r5,csv +jbr L1 +L2:mov $5,_a +mov $6,_a +L3:jmp cret +L1:jbr L2 +.globl +.data -- 2.34.1