From 6d5732239ca066c1757ae16f69942fd4b320e612 Mon Sep 17 00:00:00 2001 From: maartenbrock Date: Wed, 8 Sep 2004 05:46:46 +0000 Subject: [PATCH] * device/lib/_gptrget.c, * device/lib/_gptrput.c: updated comment * device/lib/calloc.c, * device/lib/free.c, * device/lib/malloc.c, * device/lib/realloc.c: added LGPL, made them reentrant-safe * src/SDCCcse.c (cseBBlock), * src/SDCCicode.c (printOperand, geniCodeArray), * src/SDCCicode.h (struct operand): fixed bug 868103 * support/regression/tests/bug-868103.c: added * src/SDCCast.c (searchLitOp), * src/SDCCcse.h (struct cseDef), * src/SDCCglue.c (printIvalArray, spacesToUnderscores), * src/SDCCicode.h (struct operand), * src/SDCCsymt.h (struct sym_link), * src/avr/gen.c (hasInc), * src/ds390/gen.c (hasInc), * src/hc08/gen.c (genPlusIncr, hasInc), * src/mcs51/gen.c (hasInc), * src/pic16/glue.c (pic16_printIvalChar), * src/pic16/ralloc.c (regWithIdx), * src/xa51/gen.c (hasInc) : removed warnings * src/SDCCast.c (createBlock): added comment ??? * src/hc08/ralloc.c: updated comments git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3482 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 27 + device/lib/_gptrget.c | 114 +- device/lib/_gptrput.c | 142 +- device/lib/calloc.c | 22 +- device/lib/free.c | 56 +- device/lib/malloc.c | 183 ++- device/lib/realloc.c | 104 +- src/SDCCast.c | 4 +- src/SDCCcse.c | 1882 +++++++++++++------------ src/SDCCcse.h | 2 +- src/SDCCglue.c | 4 +- src/SDCCicode.c | 30 +- src/SDCCicode.h | 213 +-- src/SDCCsymt.h | 2 +- src/avr/gen.c | 4 +- src/ds390/gen.c | 4 +- src/hc08/gen.c | 16 +- src/hc08/ralloc.c | 6 +- src/mcs51/gen.c | 13 +- src/pic16/glue.c | 2 +- src/pic16/ralloc.c | 2 +- src/xa51/gen.c | 2 +- support/regression/tests/bug-868103.c | 34 + 23 files changed, 1550 insertions(+), 1318 deletions(-) create mode 100644 support/regression/tests/bug-868103.c diff --git a/ChangeLog b/ChangeLog index a2166d66..b1e84471 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,30 @@ +2004-09-08 Maarten Brock + + * device/lib/_gptrget.c, + * device/lib/_gptrput.c: updated comment + * device/lib/calloc.c, + * device/lib/free.c, + * device/lib/malloc.c, + * device/lib/realloc.c: added LGPL, made them reentrant-safe + * src/SDCCcse.c (cseBBlock), + * src/SDCCicode.c (printOperand, geniCodeArray), + * src/SDCCicode.h (struct operand): fixed bug 868103 + * support/regression/tests/bug-868103.c: added + * src/SDCCast.c (searchLitOp), + * src/SDCCcse.h (struct cseDef), + * src/SDCCglue.c (printIvalArray, spacesToUnderscores), + * src/SDCCicode.h (struct operand), + * src/SDCCsymt.h (struct sym_link), + * src/avr/gen.c (hasInc), + * src/ds390/gen.c (hasInc), + * src/hc08/gen.c (genPlusIncr, hasInc), + * src/mcs51/gen.c (hasInc), + * src/pic16/glue.c (pic16_printIvalChar), + * src/pic16/ralloc.c (regWithIdx), + * src/xa51/gen.c (hasInc) : removed warnings + * src/SDCCast.c (createBlock): added comment ??? + * src/hc08/ralloc.c: updated comments + 2004-09-07 Frieder Ferlemann * doc/sdccman.lyx: updated section on switch statements, added diff --git a/device/lib/_gptrget.c b/device/lib/_gptrget.c index 25a42125..30f98297 100644 --- a/device/lib/_gptrget.c +++ b/device/lib/_gptrget.c @@ -23,9 +23,11 @@ what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ -/* not all devices use P2 to page pdata memory, therefore __XPAGE was - introduced. On some targets __XPAGE itself is a paged SFR so it is - not save for all platforms to set this */ +/* not all devices use P2 to page pdata memory, therefore __XPAGE was + introduced. On some targets __XPAGE itself is a paged SFR so it is + not safe for all platforms to set this. Furthermore some targets + can be configured to behave differently for movx @dptr vs. movx @Ri + (don't drive high byte of address bus for movx @Ri only) */ #define USE_PDATA_PAGING_REGISTER 0 /* the return value is expected to be in acc, and not in the standard @@ -34,36 +36,36 @@ void _gptrget (char *gptr) { gptr; /* hush the compiler */ - + _asm ; save values passed ; ; depending on the pointer type acc. to SDCCsymt.h ; mov a,b - jz 00001$ ; 0 near - dec a - jz 00002$ ; 1 far + jz 00001$ ; 0 near + dec a + jz 00002$ ; 1 far + dec a + jz 00003$ ; 2 code + dec a + jz 00004$ ; 3 pdata + dec a ; 4 skip generic pointer dec a - jz 00003$ ; 2 code - dec a - jz 00004$ ; 3 pdata - dec a ; 4 skip generic pointer - dec a - jz 00001$ ; 5 idata + jz 00001$ ; 5 idata ; ; any other value for type ; return xFF - mov a,#0xff - sjmp 00005$ + mov a,#0xff + sjmp 00005$ ; ; Pointer to data space ; 00001$: - push ar0 + push ar0 ; - mov r0,dpl ; use only low order address - mov a,@r0 + mov r0,dpl ; use only low order address + mov a,@r0 ; pop ar0 ; @@ -78,7 +80,7 @@ _gptrget (char *gptr) ; pointer to code area ; 00003$: - ; clr a is already 0 + ; clr a is already 0 movc a,@a+dptr sjmp 00005$ ; @@ -89,12 +91,12 @@ _gptrget (char *gptr) mov dph,__XPAGE ; __XPAGE (usually p2) holds high byte for pdata access movx a,@dptr #else - push ar0 - mov r0,dpl + push ar0 + mov r0,dpl movx a,@r0 - pop ar0 -#endif - + pop ar0 +#endif + ; ; return ; @@ -115,69 +117,69 @@ _gptrgetWord (unsigned *gptr) ; depending on the pointer type acc. to SDCCsymt.h ; mov a,b - jz 00001$ ; 0 near - dec a - jz 00002$ ; 1 far + jz 00001$ ; 0 near dec a - jz 00003$ ; 2 code - dec a - jz 00004$ ; 3 pdata - dec a ; 4 skip generic pointer - dec a - jz 00001$ ; 5 idata + jz 00002$ ; 1 far + dec a + jz 00003$ ; 2 code + dec a + jz 00004$ ; 3 pdata + dec a ; 4 skip generic pointer + dec a + jz 00001$ ; 5 idata ; ; any other value for type ; return xFF - mov a,#0xff - sjmp 00006$ + mov a,#0xff + sjmp 00006$ ; ; Pointer to data space ; 00001$: - push ar0 - mov r0,dpl ; use only low order address - mov _ap,@r0 - inc r0 - mov a,@r0 - inc dpl + push ar0 + mov r0,dpl ; use only low order address + mov _ap,@r0 + inc r0 + mov a,@r0 + inc dpl sjmp 00005$ ; ; pointer to xternal data ; 00002$: movx a,@dptr - mov _ap,a - inc dptr - movx a,@dptr + mov _ap,a + inc dptr + movx a,@dptr sjmp 00006$ ; ; pointer to code area ; 00003$: - ; clr a is already 0 + ; clr a is already 0 + movc a,@a+dptr + mov _ap,a + clr a + inc dptr movc a,@a+dptr - mov _ap,a - clr a - inc dptr - movc a,@a+dptr sjmp 00006$ ; ; pointer to xternal stack ; 00004$: - push ar0 - mov r0,dpl + push ar0 + mov r0,dpl + movx a,@r0 + mov _ap,a + inc r0 movx a,@r0 - mov _ap,a - inc r0 - movx a,@r0 - inc dpl + inc dpl ; ; restore and return ; 00005$: pop ar0 -00006$: +00006$: _endasm ; } diff --git a/device/lib/_gptrput.c b/device/lib/_gptrput.c index 242a7f53..f7aadc33 100644 --- a/device/lib/_gptrput.c +++ b/device/lib/_gptrput.c @@ -1,6 +1,6 @@ /*------------------------------------------------------------------------- - _gptrput.c :- put value for a generic pointer + _gptrput.c :- put value for a generic pointer Written By - Sandeep Dutta . sandeep.dutta@usa.net (1999) @@ -8,24 +8,26 @@ under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. - + You should have received a copy of the GNU Library General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve - what you give them. Help stamp out software-hoarding! + what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ -/* not all devices use P2 to page pdata memory, therefore __XPAGE was - introduced. On some targets __XPAGE itself is a paged SFR so it is - not save for all platforms to set this */ +/* not all devices use P2 to page pdata memory, therefore __XPAGE was + introduced. On some targets __XPAGE itself is a paged SFR so it is + not safe for all platforms to set this. Furthermore some targets + can be configured to behave differently for movx @dptr vs. movx @Ri + (don't drive high byte of address bus for movx @Ri only) */ #define USE_PDATA_PAGING_REGISTER 0 void @@ -34,53 +36,53 @@ _gptrput (char *gptr, char c) gptr; c; /* hush the compiler */ _asm - push acc + push acc ; ; depending on the pointer type acc. to SDCCsymt.h ; mov a,b - jz 00001$ ; 0 near + jz 00001$ ; 0 near dec a - jz 00002$ ; 1 far + jz 00002$ ; 1 far dec a - jz 00003$ ; 2 code + jz 00003$ ; 2 code dec a jz 00004$ ; 3 pdata - dec a ; 4 skip generic pointer - dec a - jz 00001$ ; 5 idata + dec a ; 4 skip generic pointer + dec a + jz 00001$ ; 5 idata 00003$: - pop acc ; do nothing - sjmp 00005$ -; + pop acc ; do nothing + sjmp 00005$ +; ; store into near space ; 00001$: - pop acc - push ar0 - mov r0,dpl - mov @r0,a - pop ar0 - sjmp 00005$ + pop acc + push ar0 + mov r0,dpl + mov @r0,a + pop ar0 + sjmp 00005$ 00002$: - pop acc - movx @dptr,a - sjmp 00005$ + pop acc + movx @dptr,a + sjmp 00005$ 00004$: #if USE_PDATA_PAGING_REGISTER - pop acc - mov dph,__XPAGE ; __XPAGE (usually p2) holds high byte for pdata access - movx @dptr,a + pop acc + mov dph,__XPAGE ; __XPAGE (usually p2) holds high byte for pdata access + movx @dptr,a #else - pop acc - push ar0 - mov r0,dpl + pop acc + push ar0 + mov r0,dpl movx @r0,a - pop ar0 -#endif + pop ar0 +#endif 00005$: _endasm; @@ -91,60 +93,60 @@ void _gptrputWord () { _asm - push acc + push acc ; ; depending on the pointer type acc. to SDCCsymt.h ; mov a,b - jz 00011$ ; 0 near + jz 00011$ ; 0 near dec a - jz 00012$ ; 1 far + jz 00012$ ; 1 far dec a - jz 00013$ ; 2 code + jz 00013$ ; 2 code dec a jz 00014$ ; 3 pdata - dec a ; 4 skip generic pointer - dec a - jz 00011$ ; 5 idata - pop acc - sjmp 00016$ + dec a ; 4 skip generic pointer + dec a + jz 00011$ ; 5 idata + pop acc + sjmp 00016$ ; ; store into near space ; 00011$: - pop acc - push ar0 - mov r0,dpl - mov @r0,_ap - inc r0 - mov @r0,a - sjmp 00015$ + pop acc + push ar0 + mov r0,dpl + mov @r0,_ap + inc r0 + mov @r0,a + sjmp 00015$ 00012$: - mov a, _ap - movx @dptr,a - inc dptr - pop acc + mov a, _ap movx @dptr,a - sjmp 00016$ + inc dptr + pop acc + movx @dptr,a + sjmp 00016$ 00013$: - pop acc ; do nothing - sjmp 00016$ + pop acc ; do nothing + sjmp 00016$ 00014$: - pop acc - push ar0 - mov r0,dpl - xch a,_ap - movx @r0,a - inc r0 - xch a,_ap - movx @r0, a - 00015$: - inc dptr - pop ar0 - 00016$: + pop acc + push ar0 + mov r0,dpl + xch a,_ap + movx @r0,a + inc r0 + xch a,_ap + movx @r0, a + 00015$: + inc dptr + pop ar0 + 00016$: _endasm; } diff --git a/device/lib/calloc.c b/device/lib/calloc.c index 6abb4242..fa99ac49 100644 --- a/device/lib/calloc.c +++ b/device/lib/calloc.c @@ -1,9 +1,27 @@ +/*------------------------------------------------------------------------- + calloc.c - allocate cleared memory. + + Copyright (C) 2004 - Maarten Brock, sourceforge.brock@dse.nl + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------*/ + #include #include #include -//-------------------------------------------------------------------- -//Written by Maarten Brock, 2004 //-------------------------------------------------------------------- //calloc function implementation for embedded system //Non-ANSI keywords are C51 specific. diff --git a/device/lib/free.c b/device/lib/free.c index ff1c16c4..9634434c 100644 --- a/device/lib/free.c +++ b/device/lib/free.c @@ -1,6 +1,32 @@ +/*------------------------------------------------------------------------- + free.c - release allocated memory. + + Copyright (C) 2004 - Maarten Brock, sourceforge.brock@dse.nl + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------*/ + #include #include +#if defined(SDCC_STACK_AUTO) || defined(SDCC_z80) || defined(SDCC_gbz80) + #define CRITICAL critical +#else + #define CRITICAL +#endif + #if _SDCC_MALLOC_TYPE_MLH typedef struct _MEMHEADER MEMHEADER; @@ -42,6 +68,7 @@ free (void *p) MEMHEADER *prev_header, *pthis; if ( p ) //For allocated pointers only! + CRITICAL { pthis = (MEMHEADER * )((char *) p - HEADER_SIZE); //to start of header if ( pthis->prev ) // For the regular header @@ -88,16 +115,16 @@ free (void *p) register MEMHEADER xdata * cur_header; if (!p) - return NULL; + return NULL; pthis = (MEMHEADER xdata *) p; pthis -= 1; //to start of header cur_header = _sdcc_first_memheader; _sdcc_prev_memheader = NULL; while (cur_header && pthis != cur_header) - { - _sdcc_prev_memheader = cur_header; - cur_header = cur_header->next; - } + { + _sdcc_prev_memheader = cur_header; + cur_header = cur_header->next; + } return (cur_header); } @@ -105,16 +132,19 @@ free (void *p) { register MEMHEADER xdata * pthis; - pthis = _sdcc_find_memheader(p); - if (pthis) //For allocated pointers only! + CRITICAL { - if (!_sdcc_prev_memheader) - { - pthis->len = 0; - } - else + pthis = _sdcc_find_memheader(p); + if (pthis) //For allocated pointers only! { - _sdcc_prev_memheader->next = pthis->next; + if (!_sdcc_prev_memheader) + { + pthis->len = 0; + } + else + { + _sdcc_prev_memheader->next = pthis->next; + } } } } diff --git a/device/lib/malloc.c b/device/lib/malloc.c index cf6f905c..4754095c 100644 --- a/device/lib/malloc.c +++ b/device/lib/malloc.c @@ -1,6 +1,32 @@ +/*------------------------------------------------------------------------- + malloc.c - allocate memory. + + Copyright (C) 2004 - Maarten Brock, sourceforge.brock@dse.nl + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------*/ + #include #include +#if defined(SDCC_STACK_AUTO) || defined(SDCC_z80) || defined(SDCC_gbz80) + #define CRITICAL critical +#else + #define CRITICAL +#endif + #if _SDCC_MALLOC_TYPE_MLH typedef struct _MEMHEADER MEMHEADER; @@ -36,8 +62,9 @@ _sdcc_heap_init(void) void * malloc (unsigned int size) { - MEMHEADER * current_header; - MEMHEADER * new_header; + register MEMHEADER * current_header; + register MEMHEADER * new_header; + register void * ret; if (size>(0xFFFF-HEADER_SIZE)) { @@ -47,48 +74,56 @@ malloc (unsigned int size) size += HEADER_SIZE; //We need a memory for header too current_header = &_sdcc_heap_start; - while (1) + CRITICAL { - // current - // | len next - // v v v - //....*****.........******.... - // ^^^^^^^^^ - // spare - - if ((((unsigned int)current_header->next) - - ((unsigned int)current_header) - - current_header->len) >= size) + while (1) { - break; //if spare is more than need + // current + // | len next + // v v v + //....*****.........******.... + // ^^^^^^^^^ + // spare + + if ((((unsigned int)current_header->next) - + ((unsigned int)current_header) - + current_header->len) >= size) + { //if spare is more than needed + ret = ¤t_header->mem; + break; + } + current_header = current_header->next; //else try next + if (!current_header->next) + { //if end_of_list reached + ret = NULL; + break; + } } - current_header = current_header->next; //else try next - if (!current_header->next) + + if (ret) { - return NULL; //if end_of_list reached + if (!current_header->len) + { //This code works only for first_header in the list and only + current_header->len = size; //for first allocation } - } - - if (!current_header->len) - { //This code works only for first_header in the list and only - current_header->len = size; //for first allocation - return ¤t_header->mem; - } - else - { - //else create new header at the begin of spare - new_header = (MEMHEADER * )((char *)current_header + current_header->len); - new_header->next = current_header->next; //and plug it into the chain - new_header->prev = current_header; - current_header->next = new_header; - if (new_header->next) + else { - new_header->next->prev = new_header; + //else create new header at the begin of spare + new_header = (MEMHEADER * )((char *)current_header + current_header->len); + new_header->next = current_header->next; //and plug it into the chain + new_header->prev = current_header; + current_header->next = new_header; + if (new_header->next) + { + new_header->next->prev = new_header; + } + new_header->len = size; //mark as used + ret = &new_header->mem; } - new_header->len = size; //mark as used - return &new_header->mem; } } + return ret; +} #else @@ -129,54 +164,72 @@ malloc (unsigned int size) // current_buffer = malloc(0x100); // // - MEMHEADER xdata * array = (MEMHEADER xdata *)heap; + char xdata * array = (char xdata *)heap; if ( !array ) //Reserved memory starts at 0x0000 but that's NULL... { //So, we lost one byte! - array = (MEMHEADER xdata * )((char xdata * ) array + 1) ; + array++; size--; } - _sdcc_first_memheader = array; + _sdcc_first_memheader = (MEMHEADER xdata * ) array; //Reserve a mem for last header - array->next = (MEMHEADER xdata * )(((char xdata * ) array) + size - sizeof(MEMHEADER xdata *)); - array->next->next = (MEMHEADER xdata * ) NULL; //And mark it as last - array->len = 0; //Empty and ready. + _sdcc_first_memheader->next = (MEMHEADER xdata * )(array + size - sizeof(MEMHEADER xdata *)); + _sdcc_first_memheader->next->next = (MEMHEADER xdata * ) NULL; //And mark it as last + _sdcc_first_memheader->len = 0; //Empty and ready. } void xdata * malloc (unsigned int size) { register MEMHEADER xdata * current_header; register MEMHEADER xdata * new_header; + register void xdata * ret; if (size>(0xFFFF-HEADER_SIZE)) return (void xdata *) NULL; //To prevent overflow in next line size += HEADER_SIZE; //We need a memory for header too current_header = _sdcc_first_memheader; - while (1) + CRITICAL { - - // current - // | len next - // v v v - //....*****.........******.... - // ^^^^^^^^^ - // spare - - if ((((unsigned int)current_header->next) - - ((unsigned int)current_header) - - current_header->len) >= size) break; //if spare is more than need - current_header = current_header->next; //else try next - if (!current_header->next) return (void xdata *) NULL; //if end_of_list reached + while (1) + { + + // current + // | len next + // v v v + //....*****.........******.... + // ^^^^^^^^^ + // spare + + if ((((unsigned int)current_header->next) - + ((unsigned int)current_header) - + current_header->len) >= size) + { //if spare is more than needed + ret = current_header->mem; + break; + } + current_header = current_header->next; //else try next + if (!current_header->next) + { //if end_of_list reached + ret = (void xdata *) NULL; + break; + } + } + if (ret) + { + if (!current_header->len) + { //This code works only for first_header in the list and only + current_header->len = size; //for first allocation + } + else + { //else create new header at the begin of spare + new_header = (MEMHEADER xdata * )((char xdata *)current_header + current_header->len); + new_header->next = current_header->next; //and plug it into the chain + current_header->next = new_header; + new_header->len = size; //mark as used + ret = new_header->mem; + } + } } - if (!current_header->len) - { //This code works only for first_header in the list and only - current_header->len = size; //for first allocation - return current_header->mem; - } //else create new header at the begin of spare - new_header = (MEMHEADER xdata * )((char xdata *)current_header + current_header->len); - new_header->next = current_header->next; //and plug it into the chain - current_header->next = new_header; - new_header->len = size; //mark as used - return new_header->mem; + return ret; } //END OF MODULE diff --git a/device/lib/realloc.c b/device/lib/realloc.c index 54fde7f9..c41ff866 100644 --- a/device/lib/realloc.c +++ b/device/lib/realloc.c @@ -1,9 +1,33 @@ +/*------------------------------------------------------------------------- + realloc.c - reallocate allocated memory. + + Copyright (C) 2004 - Maarten Brock, sourceforge.brock@dse.nl + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------*/ + #include #include #include -//-------------------------------------------------------------------- -//Written by Maarten Brock, 2004 +#if defined(SDCC_STACK_AUTO) || defined(SDCC_z80) || defined(SDCC_gbz80) + #define CRITICAL critical +#else + #define CRITICAL +#endif + //-------------------------------------------------------------------- //realloc function implementation for embedded system //Non-ANSI keywords are C51 specific. @@ -25,10 +49,12 @@ struct _MEMHEADER }; #define HEADER_SIZE (sizeof(MEMHEADER)-sizeof(char)) +#define MEM(x) (&x->mem) #else #define HEADER_SIZE sizeof(MEMHEADER) +#define MEM(x) (x->mem) #endif @@ -42,42 +68,56 @@ void xdata * realloc (void * p, size_t size) { register MEMHEADER xdata * pthis; register MEMHEADER xdata * pnew; + register void xdata * ret; - pthis = _sdcc_find_memheader(p); - if (pthis) + CRITICAL { - if (size>(0xFFFF-HEADER_SIZE)) return (void xdata *) NULL; //To prevent overflow in next line - size += HEADER_SIZE; //We need a memory for header too - - if ((((unsigned int)pthis->next) - ((unsigned int)pthis)) >= size) - {//if spare is more than need - pthis->len = size; - return p; - } - - if ((_sdcc_prev_memheader) && - ((((unsigned int)pthis->next) - - ((unsigned int)_sdcc_prev_memheader) - - _sdcc_prev_memheader->len) >= size)) + pthis = _sdcc_find_memheader(p); + if (pthis) { - pnew = (MEMHEADER xdata * )((char xdata *)_sdcc_prev_memheader + _sdcc_prev_memheader->len); - _sdcc_prev_memheader->next = pnew; - memmove(pnew, pthis, pthis->len); - pnew->len = size; - return pnew->mem; + if (size > (0xFFFF-HEADER_SIZE)) + { + ret = (void xdata *) NULL; //To prevent overflow in next line + } + else + { + size += HEADER_SIZE; //We need a memory for header too + + if ((((unsigned int)pthis->next) - ((unsigned int)pthis)) >= size) + {//if spare is more than needed + pthis->len = size; + ret = p; + } + else + { + if ((_sdcc_prev_memheader) && + ((((unsigned int)pthis->next) - + ((unsigned int)_sdcc_prev_memheader) - + _sdcc_prev_memheader->len) >= size)) + { + pnew = (MEMHEADER xdata * )((char xdata *)_sdcc_prev_memheader + _sdcc_prev_memheader->len); + _sdcc_prev_memheader->next = pnew; + memmove(pnew, pthis, pthis->len); + pnew->len = size; + ret = MEM(pnew); + } + else + { + ret = malloc(size - HEADER_SIZE); + if (ret) + { + memcpy(ret, MEM(pthis), pthis->len - HEADER_SIZE); + free(p); + } + } + } + } } - - pnew = malloc(size - HEADER_SIZE); - if (pnew) + else { - memcpy(pnew, pthis->mem, pthis->len - HEADER_SIZE); - free(p); + ret = malloc(size); } - return pnew; - } - else - { - return malloc(size); } + return ret; } //END OF MODULE diff --git a/src/SDCCast.c b/src/SDCCast.c index 46b4466e..d0898d7e 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -1969,7 +1969,7 @@ reverseLoop (ast * loop, symbol * sym, ast * init, ast * end) /* searchLitOp - search tree (*ops only) for an ast with literal */ /*-----------------------------------------------------------------*/ static ast * -searchLitOp (ast *tree, ast **parent, const char *ops) +searchLitOp (ast *tree, ast **parent, const unsigned char *ops) { ast *ret; @@ -4416,7 +4416,7 @@ createBlock (symbol * decl, ast * body) ex = newNode (BLOCK, NULL, body); ex->values.sym = decl; - ex->right = ex->right; + ex->right = ex->right;///????? ex->level++; ex->lineno = 0; return ex; diff --git a/src/SDCCcse.c b/src/SDCCcse.c index 6094b044..51dc9977 100644 --- a/src/SDCCcse.c +++ b/src/SDCCcse.c @@ -56,7 +56,7 @@ newCseDef (operand * sym, iCode * ic) cdp->fromGlobal |= isOperandGlobal (IC_RIGHT (ic)); } } - + return cdp; } @@ -66,7 +66,7 @@ updateCseDefAncestors(cseDef *cdp, set * cseSet) cseDef *loop; set *sl; iCode *ic = cdp->diCode; - + if (ic->op!=IF && ic->op!=JUMPTABLE) { if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic))) @@ -104,7 +104,7 @@ updateCseDefAncestors(cseDef *cdp, set * cseSet) /*-----------------------------------------------------------------*/ /* int isCseDefEqual - two definitions are equal */ /*-----------------------------------------------------------------*/ -int +int isCseDefEqual (void *vsrc, void *vdest) { cseDef *src = vsrc; @@ -114,14 +114,14 @@ isCseDefEqual (void *vsrc, void *vdest) return 1; return (src->key == dest->key && - src->diCode == dest->diCode); + src->diCode == dest->diCode); } /*-----------------------------------------------------------------*/ /* pcseDef - in the cseDef */ /*-----------------------------------------------------------------*/ -int +int pcseDef (void *item, va_list ap) { cseDef *cdp = item; @@ -140,8 +140,8 @@ pcseDef (void *item, va_list ap) void ReplaceOpWithCheaperOp(operand **op, operand *cop) { #ifdef RANGEHUNT printf ("ReplaceOpWithCheaperOp %s with %s: ", - IS_SYMOP((*op)) ? OP_SYMBOL((*op))->name : "!SYM", - IS_SYMOP(cop) ? OP_SYMBOL(cop)->name : "!SYM"); + IS_SYMOP((*op)) ? OP_SYMBOL((*op))->name : "!SYM", + IS_SYMOP(cop) ? OP_SYMBOL(cop)->name : "!SYM"); // if op is a register equivalent if (IS_ITEMP(cop) && OP_SYMBOL((*op))->isreqv) { operand **rop = &OP_SYMBOL((*op))->usl.spillLoc->reqv; @@ -174,84 +174,84 @@ replaceAllSymBySym (iCode * ic, operand * from, operand * to, bitVect ** ndpset) /* do the special cases first */ if (lic->op == IFX) - { - if (IS_SYMOP (to) && - IC_COND (lic)->key == from->key) - { + { + if (IS_SYMOP (to) && + IC_COND (lic)->key == from->key) + { - bitVectUnSetBit (OP_USES (from), lic->key); - OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key); - siaddr = IC_COND (lic)->isaddr; - IC_COND (lic) = operandFromOperand (to); - IC_COND (lic)->isaddr = siaddr; + bitVectUnSetBit (OP_USES (from), lic->key); + OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key); + siaddr = IC_COND (lic)->isaddr; + IC_COND (lic) = operandFromOperand (to); + IC_COND (lic)->isaddr = siaddr; - } - continue; - } + } + continue; + } if (lic->op == JUMPTABLE) - { - if (IS_SYMOP (to) && - IC_JTCOND (lic)->key == from->key) - { - - bitVectUnSetBit (OP_USES (from), lic->key); - OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key); - siaddr = IC_COND (lic)->isaddr; - IC_JTCOND (lic) = operandFromOperand (to); - IC_JTCOND (lic)->isaddr = siaddr; - - } - continue; - } - - if (IS_SYMOP(to) && - IC_RESULT (lic) && IC_RESULT (lic)->key == from->key) - { - /* maintain du chains */ - if (POINTER_SET (lic)) - { - bitVectUnSetBit (OP_USES (from), lic->key); - OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key); - - /* also check if the "from" was in the non-dominating - pointer sets and replace it with "to" in the bitVector */ - if (bitVectBitValue (*ndpset, from->key)) - { - bitVectUnSetBit (*ndpset, from->key); - bitVectSetBit (*ndpset, to->key); - } - - } - else - { - bitVectUnSetBit (OP_DEFS (from), lic->key); - OP_DEFS(to)=bitVectSetBit (OP_DEFS (to), lic->key); - } - siaddr = IC_RESULT (lic)->isaddr; - IC_RESULT (lic) = operandFromOperand (to); - IC_RESULT (lic)->isaddr = siaddr; - } + { + if (IS_SYMOP (to) && + IC_JTCOND (lic)->key == from->key) + { + + bitVectUnSetBit (OP_USES (from), lic->key); + OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key); + siaddr = IC_COND (lic)->isaddr; + IC_JTCOND (lic) = operandFromOperand (to); + IC_JTCOND (lic)->isaddr = siaddr; + + } + continue; + } + + if (IS_SYMOP(to) && + IC_RESULT (lic) && IC_RESULT (lic)->key == from->key) + { + /* maintain du chains */ + if (POINTER_SET (lic)) + { + bitVectUnSetBit (OP_USES (from), lic->key); + OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key); + + /* also check if the "from" was in the non-dominating + pointer sets and replace it with "to" in the bitVector */ + if (bitVectBitValue (*ndpset, from->key)) + { + bitVectUnSetBit (*ndpset, from->key); + bitVectSetBit (*ndpset, to->key); + } + + } + else + { + bitVectUnSetBit (OP_DEFS (from), lic->key); + OP_DEFS(to)=bitVectSetBit (OP_DEFS (to), lic->key); + } + siaddr = IC_RESULT (lic)->isaddr; + IC_RESULT (lic) = operandFromOperand (to); + IC_RESULT (lic)->isaddr = siaddr; + } if (IS_SYMOP (to) && - IC_RIGHT (lic) && IC_RIGHT (lic)->key == from->key) - { - bitVectUnSetBit (OP_USES (from), lic->key); - OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key); - siaddr = IC_RIGHT (lic)->isaddr; - IC_RIGHT (lic) = operandFromOperand (to); - IC_RIGHT (lic)->isaddr = siaddr; - } + IC_RIGHT (lic) && IC_RIGHT (lic)->key == from->key) + { + bitVectUnSetBit (OP_USES (from), lic->key); + OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key); + siaddr = IC_RIGHT (lic)->isaddr; + IC_RIGHT (lic) = operandFromOperand (to); + IC_RIGHT (lic)->isaddr = siaddr; + } if (IS_SYMOP (to) && - IC_LEFT (lic) && IC_LEFT (lic)->key == from->key) - { - bitVectUnSetBit (OP_USES (from), lic->key); - OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key); - siaddr = IC_LEFT (lic)->isaddr; - IC_LEFT (lic) = operandFromOperand (to); - IC_LEFT (lic)->isaddr = siaddr; - } + IC_LEFT (lic) && IC_LEFT (lic)->key == from->key) + { + bitVectUnSetBit (OP_USES (from), lic->key); + OP_USES(to)=bitVectSetBit (OP_USES (to), lic->key); + siaddr = IC_LEFT (lic)->isaddr; + IC_LEFT (lic) = operandFromOperand (to); + IC_LEFT (lic)->isaddr = siaddr; + } } } @@ -295,7 +295,7 @@ DEFSETFUNC (removeFromInExprs) /*-----------------------------------------------------------------*/ /* isGlobalInNearSpace - return TRUE if valriable is a globalin data */ /*-----------------------------------------------------------------*/ -static bool +static bool isGlobalInNearSpace (operand * op) { sym_link *type = getSpec (operandType (op)); @@ -334,41 +334,41 @@ DEFSETFUNC (findCheaperOp) /* constant propagation & dead code elim */ /* for assignments only */ if (cdp->diCode->op == '=') { - /* if the result is volatile then return result */ - if (IS_OP_VOLATILE (IC_RESULT (cdp->diCode))) - *opp = IC_RESULT (cdp->diCode); - else - /* if this is a straight assignment and - left is a temp then prefer the temporary to the - true symbol */ - if (!POINTER_SET (cdp->diCode) && - IS_ITEMP (IC_RESULT (cdp->diCode)) && - IS_TRUE_SYMOP (IC_RIGHT (cdp->diCode))) - *opp = IC_RESULT (cdp->diCode); - else { - /* if straight assignement && and both - are temps then prefer the one that - will not need extra space to spil, also - take into consideration if right side - an induction variable - */ - if (!POINTER_SET (cdp->diCode) && - IS_ITEMP (IC_RESULT (cdp->diCode)) && - IS_ITEMP (IC_RIGHT (cdp->diCode)) && - !OP_SYMBOL (IC_RIGHT (cdp->diCode))->isind && - !OP_SYMBOL(IC_RIGHT (cdp->diCode))->isreqv && - ((!SPIL_LOC (IC_RIGHT (cdp->diCode)) && - SPIL_LOC (IC_RESULT (cdp->diCode))) || - (SPIL_LOC (IC_RESULT (cdp->diCode)) && - SPIL_LOC (IC_RESULT (cdp->diCode)) == - SPIL_LOC (IC_RIGHT (cdp->diCode))))) - *opp = IC_RESULT (cdp->diCode); - else - *opp = IC_RIGHT (cdp->diCode); - } + /* if the result is volatile then return result */ + if (IS_OP_VOLATILE (IC_RESULT (cdp->diCode))) + *opp = IC_RESULT (cdp->diCode); + else + /* if this is a straight assignment and + left is a temp then prefer the temporary to the + true symbol */ + if (!POINTER_SET (cdp->diCode) && + IS_ITEMP (IC_RESULT (cdp->diCode)) && + IS_TRUE_SYMOP (IC_RIGHT (cdp->diCode))) + *opp = IC_RESULT (cdp->diCode); + else { + /* if straight assignement && and both + are temps then prefer the one that + will not need extra space to spil, also + take into consideration if right side + an induction variable + */ + if (!POINTER_SET (cdp->diCode) && + IS_ITEMP (IC_RESULT (cdp->diCode)) && + IS_ITEMP (IC_RIGHT (cdp->diCode)) && + !OP_SYMBOL (IC_RIGHT (cdp->diCode))->isind && + !OP_SYMBOL(IC_RIGHT (cdp->diCode))->isreqv && + ((!SPIL_LOC (IC_RIGHT (cdp->diCode)) && + SPIL_LOC (IC_RESULT (cdp->diCode))) || + (SPIL_LOC (IC_RESULT (cdp->diCode)) && + SPIL_LOC (IC_RESULT (cdp->diCode)) == + SPIL_LOC (IC_RIGHT (cdp->diCode))))) + *opp = IC_RESULT (cdp->diCode); + else + *opp = IC_RIGHT (cdp->diCode); + } } else - *opp = IC_RESULT (cdp->diCode); + *opp = IC_RESULT (cdp->diCode); } /* if this is an assign to a temp. then check @@ -384,50 +384,50 @@ DEFSETFUNC (findCheaperOp) if ((*opp) && (isOperandLiteral(*opp) || !checkSign || (checkSign && - IS_SPEC(operandType (cop)) && IS_SPEC(operandType (*opp)) && - (SPEC_USIGN(operandType (cop))==SPEC_USIGN(operandType (*opp)) && - (SPEC_LONG(operandType (cop))==SPEC_LONG(operandType (*opp))))))) + IS_SPEC(operandType (cop)) && IS_SPEC(operandType (*opp)) && + (SPEC_USIGN(operandType (cop))==SPEC_USIGN(operandType (*opp)) && + (SPEC_LONG(operandType (cop))==SPEC_LONG(operandType (*opp))))))) { if ((isGlobalInNearSpace (cop) && - !isOperandLiteral (*opp)) || - isOperandVolatile (*opp, FALSE) - ) - { - *opp = NULL; - return 0; - } + !isOperandLiteral (*opp)) || + isOperandVolatile (*opp, FALSE) + ) + { + *opp = NULL; + return 0; + } if (cop->key == (*opp)->key) - { - *opp = NULL; - return 0; - } + { + *opp = NULL; + return 0; + } if ((*opp)->isaddr != cop->isaddr && IS_ITEMP (cop)) - { - *opp = operandFromOperand (*opp); - (*opp)->isaddr = cop->isaddr; - } + { + *opp = operandFromOperand (*opp); + (*opp)->isaddr = cop->isaddr; + } if (IS_SPEC(operandType (cop)) && IS_SPEC(operandType (*opp)) && - SPEC_NOUN(operandType(cop)) != SPEC_NOUN(operandType(*opp))) - { - // special case: we can make an unsigned char literal - // into an int literal with no cost. - if (isOperandLiteral(*opp) - && SPEC_NOUN(operandType(*opp)) == V_CHAR - && SPEC_NOUN(operandType(cop)) == V_INT) - { - *opp = operandFromOperand (*opp); - SPEC_NOUN(operandType(*opp)) = V_INT; - } - else - { - // No clue... - *opp = NULL; - return 0; - } + SPEC_NOUN(operandType(cop)) != SPEC_NOUN(operandType(*opp))) + { + // special case: we can make an unsigned char literal + // into an int literal with no cost. + if (isOperandLiteral(*opp) + && SPEC_NOUN(operandType(*opp)) == V_CHAR + && SPEC_NOUN(operandType(cop)) == V_INT) + { + *opp = operandFromOperand (*opp); + SPEC_NOUN(operandType(*opp)) = V_INT; + } + else + { + // No clue... + *opp = NULL; + return 0; + } } @@ -518,7 +518,7 @@ DEFSETFUNC (ifAssignedFromGlobal) DEFSETFUNC (ifFromGlobal) { cseDef *cdp = item; - + return cdp->fromGlobal; } @@ -554,7 +554,7 @@ DEFSETFUNC (ifOperandsHave) if (bitVectBitValue(cdp->ancestors, op->key)) return 1; - + if (IC_LEFT (cdp->diCode) && IS_SYMOP (IC_LEFT (cdp->diCode)) && IC_LEFT (cdp->diCode)->key == op->key) @@ -597,7 +597,7 @@ ifDefSymIs (set * cseSet, operand * sym) { loop = sl->item; if (loop->sym->key == sym->key) - return 1; + return 1; } return 0; } @@ -611,7 +611,7 @@ DEFSETFUNC (ifDefSymIsX) cseDef *cdp = item; V_ARG (operand *, op); int match; - + if (op && cdp->sym) match = cdp->sym->key == op->key; else @@ -625,7 +625,7 @@ DEFSETFUNC (ifDefSymIsX) /*-----------------------------------------------------------------*/ -/* ifDiCodeIs - returns truw if diCode is same */ +/* ifDiCodeIs - returns true if diCode is same */ /*-----------------------------------------------------------------*/ int ifDiCodeIs (set * cseSet, iCode * ic) @@ -640,7 +640,7 @@ ifDiCodeIs (set * cseSet, iCode * ic) { loop = sl->item; if (loop->diCode == ic) - return 1; + return 1; } return 0; @@ -697,8 +697,8 @@ iCode *findBackwardDef(operand *op,iCode *ic) iCode *lic; for (lic = ic; lic ; lic = lic->prev) { - if (IC_RESULT(lic) && isOperandEqual(op,IC_RESULT(lic))) - return lic; + if (IC_RESULT(lic) && isOperandEqual(op,IC_RESULT(lic))) + return lic; } return NULL; } @@ -731,9 +731,9 @@ algebraicOpts (iCode * ic, eBBlock * ebp) { IC_RIGHT (ic) = operandOperation (IC_LEFT (ic), - IC_RIGHT (ic), - ic->op, - operandType (IC_RESULT (ic))); + IC_RIGHT (ic), + ic->op, + operandType (IC_RESULT (ic))); ic->op = '='; IC_LEFT (ic) = NULL; SET_RESULT_RIGHT (ic); @@ -748,9 +748,9 @@ algebraicOpts (iCode * ic, eBBlock * ebp) { IC_RIGHT (ic) = operandOperation (IC_LEFT (ic), - IC_RIGHT (ic), - ic->op, - operandType (IC_RESULT (ic))); + IC_RIGHT (ic), + ic->op, + operandType (IC_RESULT (ic))); ic->op = '='; IC_LEFT (ic) = NULL; SET_RESULT_RIGHT (ic); @@ -764,33 +764,33 @@ algebraicOpts (iCode * ic, eBBlock * ebp) { if (IS_ITEMP (IC_RESULT (ic)) && - IS_TRUE_SYMOP (IC_LEFT (ic))) - { - - ic->op = '='; - IC_RIGHT (ic) = operandFromOperand (IC_LEFT (ic)); - IC_RIGHT (ic)->isaddr = 0; - IC_LEFT (ic) = NULL; - IC_RESULT (ic) = operandFromOperand (IC_RESULT (ic)); - IC_RESULT (ic)->isaddr = 0; - setOperandType (IC_RESULT (ic), operandType (IC_RIGHT (ic))); - return; - } + IS_TRUE_SYMOP (IC_LEFT (ic))) + { + + ic->op = '='; + IC_RIGHT (ic) = operandFromOperand (IC_LEFT (ic)); + IC_RIGHT (ic)->isaddr = 0; + IC_LEFT (ic) = NULL; + IC_RESULT (ic) = operandFromOperand (IC_RESULT (ic)); + IC_RESULT (ic)->isaddr = 0; + setOperandType (IC_RESULT (ic), operandType (IC_RIGHT (ic))); + return; + } if (IS_ITEMP (IC_LEFT (ic)) && - IS_ITEMP (IC_RESULT (ic)) && + IS_ITEMP (IC_RESULT (ic)) && /* !OP_SYMBOL(IC_RESULT(ic))->isreqv && */ /* !OP_SYMBOL(IC_LEFT(ic))->isreqv && */ - !IC_LEFT (ic)->isaddr) - { - ic->op = '='; - IC_RIGHT (ic) = operandFromOperand (IC_LEFT (ic)); - IC_RIGHT (ic)->isaddr = 0; - IC_RESULT (ic) = operandFromOperand (IC_RESULT (ic)); - IC_RESULT (ic)->isaddr = 0; - IC_LEFT (ic) = NULL; - return; - } + !IC_LEFT (ic)->isaddr) + { + ic->op = '='; + IC_RIGHT (ic) = operandFromOperand (IC_LEFT (ic)); + IC_RIGHT (ic)->isaddr = 0; + IC_RESULT (ic) = operandFromOperand (IC_RESULT (ic)); + IC_RESULT (ic)->isaddr = 0; + IC_LEFT (ic) = NULL; + return; + } } @@ -801,88 +801,88 @@ algebraicOpts (iCode * ic, eBBlock * ebp) case '+': /* if adding the same thing change to left shift by 1 */ if (IC_LEFT (ic)->key == IC_RIGHT (ic)->key && - !IS_FLOAT (operandType (IC_RESULT (ic)))) - { - ic->op = LEFT_OP; - IC_RIGHT (ic) = operandFromLit (1); - return; - } + !IS_FLOAT (operandType (IC_RESULT (ic)))) + { + ic->op = LEFT_OP; + IC_RIGHT (ic) = operandFromLit (1); + return; + } /* if addition then check if one of them is a zero */ /* if yes turn it into assignmnt or cast */ if (IS_OP_LITERAL (IC_LEFT (ic)) && - operandLitValue (IC_LEFT (ic)) == 0.0) - { - if (compareType (operandType (IC_RESULT (ic)), - operandType (IC_RIGHT (ic)))<0) - { - ic->op = CAST; - IC_LEFT (ic) = operandFromLink (operandType (IC_RESULT (ic))); - } - else + operandLitValue (IC_LEFT (ic)) == 0.0) + { + if (compareType (operandType (IC_RESULT (ic)), + operandType (IC_RIGHT (ic)))<0) + { + ic->op = CAST; + IC_LEFT (ic) = operandFromLink (operandType (IC_RESULT (ic))); + } + else { - ic->op = '='; - IC_LEFT (ic) = NULL; + ic->op = '='; + IC_LEFT (ic) = NULL; } - SET_ISADDR (IC_RESULT (ic), 0); - SET_ISADDR (IC_RIGHT (ic), 0); - return; - } + SET_ISADDR (IC_RESULT (ic), 0); + SET_ISADDR (IC_RIGHT (ic), 0); + return; + } if (IS_OP_LITERAL (IC_RIGHT (ic)) && - operandLitValue (IC_RIGHT (ic)) == 0.0) - { - if (compareType (operandType (IC_RESULT (ic)), - operandType (IC_LEFT (ic)))<0) - { - ic->op = CAST; - IC_RIGHT (ic) = IC_LEFT (ic); - IC_LEFT (ic) = operandFromLink (operandType (IC_RESULT (ic))); - } - else + operandLitValue (IC_RIGHT (ic)) == 0.0) + { + if (compareType (operandType (IC_RESULT (ic)), + operandType (IC_LEFT (ic)))<0) { - ic->op = '='; - IC_RIGHT (ic) = IC_LEFT (ic); - IC_LEFT (ic) = NULL; + ic->op = CAST; + IC_RIGHT (ic) = IC_LEFT (ic); + IC_LEFT (ic) = operandFromLink (operandType (IC_RESULT (ic))); } - SET_ISADDR (IC_RIGHT (ic), 0); - SET_ISADDR (IC_RESULT (ic), 0); - return; - } + else + { + ic->op = '='; + IC_RIGHT (ic) = IC_LEFT (ic); + IC_LEFT (ic) = NULL; + } + SET_ISADDR (IC_RIGHT (ic), 0); + SET_ISADDR (IC_RESULT (ic), 0); + return; + } break; case '-': /* if subtracting the the same thing then zero */ if (IC_LEFT (ic)->key == IC_RIGHT (ic)->key) - { - ic->op = '='; - IC_RIGHT (ic) = operandFromLit (0); - IC_LEFT (ic) = NULL; - IC_RESULT (ic) = operandFromOperand (IC_RESULT (ic)); - IC_RESULT (ic)->isaddr = 0; - return; - } + { + ic->op = '='; + IC_RIGHT (ic) = operandFromLit (0); + IC_LEFT (ic) = NULL; + IC_RESULT (ic) = operandFromOperand (IC_RESULT (ic)); + IC_RESULT (ic)->isaddr = 0; + return; + } /* if subtraction then check if one of the operand */ /* is zero then depending on which operand change */ /* to assignment or unary minus */ if (IS_OP_LITERAL (IC_RIGHT (ic)) && - operandLitValue (IC_RIGHT (ic)) == 0.0) - { - /* right size zero change to assignment */ - ic->op = '='; - IC_RIGHT (ic) = IC_LEFT (ic); - IC_LEFT (ic) = NULL; - SET_ISADDR (IC_RIGHT (ic), 0); - SET_ISADDR (IC_RESULT (ic), 0); - return; - } + operandLitValue (IC_RIGHT (ic)) == 0.0) + { + /* right size zero change to assignment */ + ic->op = '='; + IC_RIGHT (ic) = IC_LEFT (ic); + IC_LEFT (ic) = NULL; + SET_ISADDR (IC_RIGHT (ic), 0); + SET_ISADDR (IC_RESULT (ic), 0); + return; + } if (IS_OP_LITERAL (IC_LEFT (ic)) && - operandLitValue (IC_LEFT (ic)) == 0.0) - { - /* left zero turn into an unary minus */ - ic->op = UNARYMINUS; - IC_LEFT (ic) = IC_RIGHT (ic); - IC_RIGHT (ic) = NULL; - return; - } + operandLitValue (IC_LEFT (ic)) == 0.0) + { + /* left zero turn into an unary minus */ + ic->op = UNARYMINUS; + IC_LEFT (ic) = IC_RIGHT (ic); + IC_RIGHT (ic) = NULL; + return; + } break; /* if multiplication then check if either of */ /* them is zero then the result is zero */ @@ -890,158 +890,158 @@ algebraicOpts (iCode * ic, eBBlock * ebp) /* the other one */ case '*': if (IS_OP_LITERAL (IC_LEFT (ic))) - { - - if (operandLitValue (IC_LEFT (ic)) == 0.0) - { - ic->op = '='; - IC_RIGHT (ic) = IC_LEFT (ic); - IC_LEFT (ic) = NULL; - SET_RESULT_RIGHT (ic); - return; - } - if (operandLitValue (IC_LEFT (ic)) == 1.0) - { - /* '*' can have two unsigned chars as operands */ - /* and an unsigned int as result. */ - if (compareType (operandType (IC_RESULT (ic)), - operandType (IC_RIGHT (ic))) == 1) - { - ic->op = '='; - IC_LEFT (ic) = NULL; - SET_RESULT_RIGHT (ic); - } - else - { - ic->op = CAST; - IC_LEFT (ic) = operandFromOperand (IC_LEFT (ic)); - IC_LEFT (ic)->type = TYPE; - IC_LEFT (ic)->isLiteral = 0; - setOperandType (IC_LEFT (ic), operandType (IC_RESULT (ic))); - } - return; - } - } + { + + if (operandLitValue (IC_LEFT (ic)) == 0.0) + { + ic->op = '='; + IC_RIGHT (ic) = IC_LEFT (ic); + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } + if (operandLitValue (IC_LEFT (ic)) == 1.0) + { + /* '*' can have two unsigned chars as operands */ + /* and an unsigned int as result. */ + if (compareType (operandType (IC_RESULT (ic)), + operandType (IC_RIGHT (ic))) == 1) + { + ic->op = '='; + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + } + else + { + ic->op = CAST; + IC_LEFT (ic) = operandFromOperand (IC_LEFT (ic)); + IC_LEFT (ic)->type = TYPE; + IC_LEFT (ic)->isLiteral = 0; + setOperandType (IC_LEFT (ic), operandType (IC_RESULT (ic))); + } + return; + } + } if (IS_OP_LITERAL (IC_RIGHT (ic))) - { - - if (operandLitValue (IC_RIGHT (ic)) == 0.0) - { - ic->op = '='; - IC_LEFT (ic) = NULL; - SET_RESULT_RIGHT (ic); - return; - } - - if (operandLitValue (IC_RIGHT (ic)) == 1.0) - { - /* '*' can have two unsigned chars as operands */ - /* and an unsigned int as result. */ - if (compareType (operandType (IC_RESULT (ic)), - operandType (IC_LEFT (ic))) == 1) - { - ic->op = '='; - IC_RIGHT (ic) = IC_LEFT (ic); - IC_LEFT (ic) = NULL; - SET_RESULT_RIGHT (ic); - } - else - { + { + + if (operandLitValue (IC_RIGHT (ic)) == 0.0) + { + ic->op = '='; + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } + + if (operandLitValue (IC_RIGHT (ic)) == 1.0) + { + /* '*' can have two unsigned chars as operands */ + /* and an unsigned int as result. */ + if (compareType (operandType (IC_RESULT (ic)), + operandType (IC_LEFT (ic))) == 1) + { + ic->op = '='; + IC_RIGHT (ic) = IC_LEFT (ic); + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + } + else + { operand *op; - ic->op = CAST; - op = IC_RIGHT (ic); - IC_RIGHT (ic) = IC_LEFT (ic); - IC_LEFT (ic) = operandFromOperand (op); - IC_LEFT (ic)->type = TYPE; - IC_LEFT (ic)->isLiteral = 0; - setOperandType (IC_LEFT (ic), operandType (IC_RESULT (ic))); - } - return; - } - } + ic->op = CAST; + op = IC_RIGHT (ic); + IC_RIGHT (ic) = IC_LEFT (ic); + IC_LEFT (ic) = operandFromOperand (op); + IC_LEFT (ic)->type = TYPE; + IC_LEFT (ic)->isLiteral = 0; + setOperandType (IC_LEFT (ic), operandType (IC_RESULT (ic))); + } + return; + } + } break; case '/': /* if division by self then 1 */ if (IC_LEFT (ic)->key == IC_RIGHT (ic)->key) - { - ic->op = '='; - IC_RIGHT (ic) = operandFromLit (1); - IC_LEFT (ic) = NULL; - IC_RESULT (ic) = operandFromOperand (IC_RESULT (ic)); - IC_RESULT (ic)->isaddr = 0; - break; - } + { + ic->op = '='; + IC_RIGHT (ic) = operandFromLit (1); + IC_LEFT (ic) = NULL; + IC_RESULT (ic) = operandFromOperand (IC_RESULT (ic)); + IC_RESULT (ic)->isaddr = 0; + break; + } /* if this is a division then check if right */ /* is one then change it to an assignment */ if (IS_OP_LITERAL (IC_RIGHT (ic)) && - operandLitValue (IC_RIGHT (ic)) == 1.0) - { - - ic->op = '='; - IC_RIGHT (ic) = IC_LEFT (ic); - IC_LEFT (ic) = NULL; - SET_RESULT_RIGHT (ic); - return; - } + operandLitValue (IC_RIGHT (ic)) == 1.0) + { + + ic->op = '='; + IC_RIGHT (ic) = IC_LEFT (ic); + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } break; /* if both are the same for an comparison operators */ case EQ_OP: case LE_OP: case GE_OP: if (isOperandEqual (IC_LEFT (ic), IC_RIGHT (ic))) - { - ic->op = '='; - IC_RIGHT (ic) = operandFromLit (1); - IC_LEFT (ic) = NULL; - SET_RESULT_RIGHT (ic); - } + { + ic->op = '='; + IC_RIGHT (ic) = operandFromLit (1); + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + } break; case NE_OP: case '>': case '<': if (isOperandEqual (IC_LEFT (ic), IC_RIGHT (ic))) - { - ic->op = '='; - IC_RIGHT (ic) = operandFromLit (0); - IC_LEFT (ic) = NULL; - SET_RESULT_RIGHT (ic); - } + { + ic->op = '='; + IC_RIGHT (ic) = operandFromLit (0); + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + } break; case CAST: - { - sym_link *otype = operandType(IC_RIGHT(ic)); - sym_link *ctype = operandType(IC_LEFT(ic)); - /* if this is a cast of a literal value */ - if (IS_OP_LITERAL (IC_RIGHT (ic)) && - !(IS_GENPTR(ctype) && (IS_PTR(otype) && !IS_GENPTR(otype)))) { - ic->op = '='; - IC_RIGHT (ic) = - operandFromValue (valCastLiteral (operandType (IC_LEFT (ic)), - operandLitValue (IC_RIGHT (ic)))); - IC_LEFT (ic) = NULL; - SET_ISADDR (IC_RESULT (ic), 0); - } - /* if casting to the same */ - if (compareType (operandType (IC_RESULT (ic)), - operandType (IC_RIGHT (ic))) == 1) { - ic->op = '='; - IC_LEFT (ic) = NULL; - SET_ISADDR (IC_RESULT (ic), 0); - } - } - break; + { + sym_link *otype = operandType(IC_RIGHT(ic)); + sym_link *ctype = operandType(IC_LEFT(ic)); + /* if this is a cast of a literal value */ + if (IS_OP_LITERAL (IC_RIGHT (ic)) && + !(IS_GENPTR(ctype) && (IS_PTR(otype) && !IS_GENPTR(otype)))) { + ic->op = '='; + IC_RIGHT (ic) = + operandFromValue (valCastLiteral (operandType (IC_LEFT (ic)), + operandLitValue (IC_RIGHT (ic)))); + IC_LEFT (ic) = NULL; + SET_ISADDR (IC_RESULT (ic), 0); + } + /* if casting to the same */ + if (compareType (operandType (IC_RESULT (ic)), + operandType (IC_RIGHT (ic))) == 1) { + ic->op = '='; + IC_LEFT (ic) = NULL; + SET_ISADDR (IC_RESULT (ic), 0); + } + } + break; case '!': if (IS_OP_LITERAL (IC_LEFT (ic))) - { - ic->op = '='; - IC_RIGHT (ic) = - (operandLitValue (IC_LEFT (ic)) == 0 ? - operandFromLit (1) : operandFromLit (0)); - IC_LEFT (ic) = NULL; - SET_ISADDR (IC_RESULT (ic), 0); - } + { + ic->op = '='; + IC_RIGHT (ic) = + (operandLitValue (IC_LEFT (ic)) == 0 ? + operandFromLit (1) : operandFromLit (0)); + IC_LEFT (ic) = NULL; + SET_ISADDR (IC_RESULT (ic), 0); + } break; case BITWISEAND: /* if both operands are equal */ @@ -1049,73 +1049,73 @@ algebraicOpts (iCode * ic, eBBlock * ebp) if (isOperandEqual (IC_LEFT (ic), IC_RIGHT (ic))) { if (IS_OP_VOLATILE (IC_LEFT (ic))) - { - iCode *newic = newiCode (DUMMY_READ_VOLATILE, NULL, IC_LEFT (ic)); - IC_RESULT (newic) = IC_LEFT (ic); - newic->lineno = ic->lineno; - addiCodeToeBBlock (ebp, newic, ic->next); - } - ic->op = '='; - IC_LEFT (ic) = NULL; - SET_RESULT_RIGHT (ic); - return; - } + { + iCode *newic = newiCode (DUMMY_READ_VOLATILE, NULL, IC_LEFT (ic)); + IC_RESULT (newic) = IC_LEFT (ic); + newic->lineno = ic->lineno; + addiCodeToeBBlock (ebp, newic, ic->next); + } + ic->op = '='; + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } /* swap literal to right ic */ if (IS_OP_LITERAL (IC_LEFT (ic))) { - operand *op; + operand *op; - op = IC_LEFT (ic); - IC_LEFT (ic) = IC_RIGHT (ic); - IC_RIGHT (ic) = op; - } + op = IC_LEFT (ic); + IC_LEFT (ic) = IC_RIGHT (ic); + IC_RIGHT (ic) = op; + } if (IS_OP_LITERAL (IC_RIGHT (ic))) { - /* if BITWISEAND then check if one of them is a zero */ - /* if yes turn it into 0 assignment */ - if (operandLitValue (IC_RIGHT (ic)) == 0.0) - { - if (IS_OP_VOLATILE (IC_LEFT (ic))) - { - iCode *newic = newiCode (DUMMY_READ_VOLATILE, NULL, IC_LEFT (ic)); - IC_RESULT (newic) = IC_LEFT (ic); - newic->lineno = ic->lineno; - addiCodeToeBBlock (ebp, newic, ic->next); - } - ic->op = '='; - IC_LEFT (ic) = NULL; - SET_RESULT_RIGHT (ic); - return; - } - /* if BITWISEAND then check if one of them is 0xff... */ - /* if yes turn it into assignment */ - { - unsigned val; - - switch (getSize (operandType (IC_RIGHT (ic)))) - { - case 1: - val = 0xff; - break; - case 2: - val = 0xffff; - break; - case 4: - val = 0xffffffff; - break; - default: - return; - } - if (((unsigned) operandLitValue (IC_RIGHT (ic)) & val) == val) - { - ic->op = '='; - IC_RIGHT (ic) = IC_LEFT (ic); - IC_LEFT (ic) = NULL; - SET_RESULT_RIGHT (ic); - return; - } - } - } + /* if BITWISEAND then check if one of them is a zero */ + /* if yes turn it into 0 assignment */ + if (operandLitValue (IC_RIGHT (ic)) == 0.0) + { + if (IS_OP_VOLATILE (IC_LEFT (ic))) + { + iCode *newic = newiCode (DUMMY_READ_VOLATILE, NULL, IC_LEFT (ic)); + IC_RESULT (newic) = IC_LEFT (ic); + newic->lineno = ic->lineno; + addiCodeToeBBlock (ebp, newic, ic->next); + } + ic->op = '='; + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } + /* if BITWISEAND then check if one of them is 0xff... */ + /* if yes turn it into assignment */ + { + unsigned val; + + switch (getSize (operandType (IC_RIGHT (ic)))) + { + case 1: + val = 0xff; + break; + case 2: + val = 0xffff; + break; + case 4: + val = 0xffffffff; + break; + default: + return; + } + if (((unsigned) operandLitValue (IC_RIGHT (ic)) & val) == val) + { + ic->op = '='; + IC_RIGHT (ic) = IC_LEFT (ic); + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } + } + } break; case '|': /* if both operands are equal */ @@ -1123,73 +1123,73 @@ algebraicOpts (iCode * ic, eBBlock * ebp) if (isOperandEqual (IC_LEFT (ic), IC_RIGHT (ic))) { if (IS_OP_VOLATILE (IC_LEFT (ic))) - { - iCode *newic = newiCode (DUMMY_READ_VOLATILE, NULL, IC_LEFT (ic)); - IC_RESULT (newic) = IC_LEFT (ic); - newic->lineno = ic->lineno; - addiCodeToeBBlock (ebp, newic, ic->next); - } - ic->op = '='; - IC_LEFT (ic) = NULL; - SET_RESULT_RIGHT (ic); - return; - } + { + iCode *newic = newiCode (DUMMY_READ_VOLATILE, NULL, IC_LEFT (ic)); + IC_RESULT (newic) = IC_LEFT (ic); + newic->lineno = ic->lineno; + addiCodeToeBBlock (ebp, newic, ic->next); + } + ic->op = '='; + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } /* swap literal to right ic */ if (IS_OP_LITERAL (IC_LEFT (ic))) { - operand *op; + operand *op; - op = IC_LEFT (ic); - IC_LEFT (ic) = IC_RIGHT (ic); - IC_RIGHT (ic) = op; - } + op = IC_LEFT (ic); + IC_LEFT (ic) = IC_RIGHT (ic); + IC_RIGHT (ic) = op; + } if (IS_OP_LITERAL (IC_RIGHT (ic))) { - /* if BITWISEOR then check if one of them is a zero */ - /* if yes turn it into assignment */ - if (operandLitValue (IC_RIGHT (ic)) == 0.0) - { - ic->op = '='; - IC_RIGHT (ic) = IC_LEFT (ic); - IC_LEFT (ic) = NULL; - SET_RESULT_RIGHT (ic); - return; - } - /* if BITWISEOR then check if one of them is 0xff... */ - /* if yes turn it into 0xff... assignment */ - { - unsigned val; - - switch (getSize (operandType (IC_RIGHT (ic)))) - { - case 1: - val = 0xff; - break; - case 2: - val = 0xffff; - break; - case 4: - val = 0xffffffff; - break; - default: - return; - } - if (((unsigned) operandLitValue (IC_RIGHT (ic)) & val) == val) - { - if (IS_OP_VOLATILE (IC_LEFT (ic))) - { - iCode *newic = newiCode (DUMMY_READ_VOLATILE, NULL, IC_LEFT (ic)); - IC_RESULT (newic) = IC_LEFT (ic); - newic->lineno = ic->lineno; - addiCodeToeBBlock (ebp, newic, ic->next); - } - ic->op = '='; - IC_LEFT (ic) = NULL; - SET_RESULT_RIGHT (ic); - return; - } - } - } + /* if BITWISEOR then check if one of them is a zero */ + /* if yes turn it into assignment */ + if (operandLitValue (IC_RIGHT (ic)) == 0.0) + { + ic->op = '='; + IC_RIGHT (ic) = IC_LEFT (ic); + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } + /* if BITWISEOR then check if one of them is 0xff... */ + /* if yes turn it into 0xff... assignment */ + { + unsigned val; + + switch (getSize (operandType (IC_RIGHT (ic)))) + { + case 1: + val = 0xff; + break; + case 2: + val = 0xffff; + break; + case 4: + val = 0xffffffff; + break; + default: + return; + } + if (((unsigned) operandLitValue (IC_RIGHT (ic)) & val) == val) + { + if (IS_OP_VOLATILE (IC_LEFT (ic))) + { + iCode *newic = newiCode (DUMMY_READ_VOLATILE, NULL, IC_LEFT (ic)); + IC_RESULT (newic) = IC_LEFT (ic); + newic->lineno = ic->lineno; + addiCodeToeBBlock (ebp, newic, ic->next); + } + ic->op = '='; + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } + } + } break; case '^': /* if both operands are equal */ @@ -1197,45 +1197,45 @@ algebraicOpts (iCode * ic, eBBlock * ebp) if (isOperandEqual (IC_LEFT (ic), IC_RIGHT (ic))) { if (IS_OP_VOLATILE (IC_LEFT (ic))) - { - iCode *newic = newiCode (DUMMY_READ_VOLATILE, NULL, IC_LEFT (ic)); - IC_RESULT (newic) = IC_LEFT (ic); - newic->lineno = ic->lineno; - addiCodeToeBBlock (ebp, newic, ic->next); - - newic = newiCode (DUMMY_READ_VOLATILE, NULL, IC_LEFT (ic)); - IC_RESULT (newic) = IC_LEFT (ic); - newic->lineno = ic->lineno; - addiCodeToeBBlock (ebp, newic, ic->next); - } - ic->op = '='; - IC_RIGHT (ic) = operandFromLit (0); - IC_LEFT (ic) = NULL; - SET_RESULT_RIGHT (ic); - return; - } + { + iCode *newic = newiCode (DUMMY_READ_VOLATILE, NULL, IC_LEFT (ic)); + IC_RESULT (newic) = IC_LEFT (ic); + newic->lineno = ic->lineno; + addiCodeToeBBlock (ebp, newic, ic->next); + + newic = newiCode (DUMMY_READ_VOLATILE, NULL, IC_LEFT (ic)); + IC_RESULT (newic) = IC_LEFT (ic); + newic->lineno = ic->lineno; + addiCodeToeBBlock (ebp, newic, ic->next); + } + ic->op = '='; + IC_RIGHT (ic) = operandFromLit (0); + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } /* swap literal to right ic */ if (IS_OP_LITERAL (IC_LEFT (ic))) { - operand *op; + operand *op; - op = IC_LEFT (ic); - IC_LEFT (ic) = IC_RIGHT (ic); - IC_RIGHT (ic) = op; - } + op = IC_LEFT (ic); + IC_LEFT (ic) = IC_RIGHT (ic); + IC_RIGHT (ic) = op; + } /* if XOR then check if one of them is a zero */ /* if yes turn it into assignment */ if (IS_OP_LITERAL (IC_RIGHT (ic))) - { - if (operandLitValue (IC_RIGHT (ic)) == 0.0) - { - ic->op = '='; - IC_RIGHT (ic) = IC_LEFT (ic); - IC_LEFT (ic) = NULL; - SET_RESULT_RIGHT (ic); - return; - } - } + { + if (operandLitValue (IC_RIGHT (ic)) == 0.0) + { + ic->op = '='; + IC_RIGHT (ic) = IC_LEFT (ic); + IC_LEFT (ic) = NULL; + SET_RESULT_RIGHT (ic); + return; + } + } break; } @@ -1248,79 +1248,79 @@ algebraicOpts (iCode * ic, eBBlock * ebp) void updateSpillLocation (iCode * ic, int induction) { - sym_link *setype; + sym_link *setype; - if (POINTER_SET (ic)) - return; + if (POINTER_SET (ic)) + return; - if (ic->nosupdate) - return; + if (ic->nosupdate) + return; #if 0 - /* for the form true_symbol := iTempNN */ - if (ASSIGN_ITEMP_TO_SYM (ic) && - !SPIL_LOC (IC_RIGHT (ic))) { - - setype = getSpec (operandType (IC_RESULT (ic))); - - if (!OP_SYMBOL(IC_RIGHT (ic))->noSpilLoc && - !IS_VOLATILE (setype) && - !IN_FARSPACE (SPEC_OCLS (setype)) && - !OTHERS_PARM (OP_SYMBOL (IC_RESULT (ic)))) - { - wassert(IS_SYMOP(IC_RESULT (ic))); - wassert(IS_SYMOP(IC_RIGHT (ic))); - SPIL_LOC (IC_RIGHT (ic)) = - IC_RESULT (ic)->operand.symOperand; - } - - } + /* for the form true_symbol := iTempNN */ + if (ASSIGN_ITEMP_TO_SYM (ic) && + !SPIL_LOC (IC_RIGHT (ic))) { + + setype = getSpec (operandType (IC_RESULT (ic))); + + if (!OP_SYMBOL(IC_RIGHT (ic))->noSpilLoc && + !IS_VOLATILE (setype) && + !IN_FARSPACE (SPEC_OCLS (setype)) && + !OTHERS_PARM (OP_SYMBOL (IC_RESULT (ic)))) + { + wassert(IS_SYMOP(IC_RESULT (ic))); + wassert(IS_SYMOP(IC_RIGHT (ic))); + SPIL_LOC (IC_RIGHT (ic)) = + IC_RESULT (ic)->operand.symOperand; + } + + } #endif #if 0 /* this needs furthur investigation can save a lot of code */ - if (ASSIGN_SYM_TO_ITEMP(ic) && - !SPIL_LOC(IC_RESULT(ic))) { - if (!OTHERS_PARM (OP_SYMBOL (IC_RIGHT (ic)))) - SPIL_LOC (IC_RESULT (ic)) = - IC_RIGHT (ic)->operand.symOperand; - } + if (ASSIGN_SYM_TO_ITEMP(ic) && + !SPIL_LOC(IC_RESULT(ic))) { + if (!OTHERS_PARM (OP_SYMBOL (IC_RIGHT (ic)))) + SPIL_LOC (IC_RESULT (ic)) = + IC_RIGHT (ic)->operand.symOperand; + } #endif - if (ASSIGN_ITEMP_TO_ITEMP (ic)) { - - if (!SPIL_LOC (IC_RIGHT (ic)) && - !bitVectBitsInCommon (OP_DEFS (IC_RIGHT (ic)), OP_USES (IC_RESULT (ic))) && - OP_SYMBOL (IC_RESULT (ic))->isreqv) { - - setype = getSpec (operandType (IC_RESULT (ic))); - - if (!OP_SYMBOL(IC_RIGHT (ic))->noSpilLoc && - !IS_VOLATILE (setype) && - !IN_FARSPACE (SPEC_OCLS (setype)) && - !OTHERS_PARM (OP_SYMBOL (IC_RESULT (ic)))) { - - SPIL_LOC (IC_RIGHT (ic)) = - SPIL_LOC (IC_RESULT (ic)); - OP_SYMBOL (IC_RIGHT (ic))->prereqv = - OP_SYMBOL (IC_RESULT (ic))->prereqv; - } - } - /* special case for inductions */ - if (induction && - OP_SYMBOL(IC_RIGHT(ic))->isreqv && - !OP_SYMBOL(IC_RESULT (ic))->noSpilLoc && - !SPIL_LOC(IC_RESULT(ic))) { - SPIL_LOC (IC_RESULT (ic)) = SPIL_LOC (IC_RIGHT (ic)); - OP_SYMBOL (IC_RESULT (ic))->prereqv = - OP_SYMBOL (IC_RIGHT (ic))->prereqv; - } - } + if (ASSIGN_ITEMP_TO_ITEMP (ic)) { + + if (!SPIL_LOC (IC_RIGHT (ic)) && + !bitVectBitsInCommon (OP_DEFS (IC_RIGHT (ic)), OP_USES (IC_RESULT (ic))) && + OP_SYMBOL (IC_RESULT (ic))->isreqv) { + + setype = getSpec (operandType (IC_RESULT (ic))); + + if (!OP_SYMBOL(IC_RIGHT (ic))->noSpilLoc && + !IS_VOLATILE (setype) && + !IN_FARSPACE (SPEC_OCLS (setype)) && + !OTHERS_PARM (OP_SYMBOL (IC_RESULT (ic)))) { + + SPIL_LOC (IC_RIGHT (ic)) = + SPIL_LOC (IC_RESULT (ic)); + OP_SYMBOL (IC_RIGHT (ic))->prereqv = + OP_SYMBOL (IC_RESULT (ic))->prereqv; + } + } + /* special case for inductions */ + if (induction && + OP_SYMBOL(IC_RIGHT(ic))->isreqv && + !OP_SYMBOL(IC_RESULT (ic))->noSpilLoc && + !SPIL_LOC(IC_RESULT(ic))) { + SPIL_LOC (IC_RESULT (ic)) = SPIL_LOC (IC_RIGHT (ic)); + OP_SYMBOL (IC_RESULT (ic))->prereqv = + OP_SYMBOL (IC_RIGHT (ic))->prereqv; + } + } } /*-----------------------------------------------------------------*/ /* setUsesDef - sets the uses def bitvector for a given operand */ /*-----------------------------------------------------------------*/ -void +void setUsesDefs (operand * op, bitVect * bdefs, - bitVect * idefs, bitVect ** oud) + bitVect * idefs, bitVect ** oud) { /* compute the definitions alive at this point */ bitVect *adefs = bitVectUnion (bdefs, idefs); @@ -1339,7 +1339,7 @@ setUsesDefs (operand * op, bitVect * bdefs, /*-----------------------------------------------------------------*/ /* unsetDefsAndUses - clear this operation for the operands */ /*-----------------------------------------------------------------*/ -void +void unsetDefsAndUses (iCode * ic) { if (ic->op == JUMPTABLE) @@ -1351,18 +1351,18 @@ unsetDefsAndUses (iCode * ic) { /* turn off def set */ if (IS_SYMOP (IC_RESULT (ic))) - { - if (!POINTER_SET (ic)) - bitVectUnSetBit (OP_DEFS (IC_RESULT (ic)), ic->key); - else - bitVectUnSetBit (OP_USES (IC_RESULT (ic)), ic->key); - } + { + if (!POINTER_SET (ic)) + bitVectUnSetBit (OP_DEFS (IC_RESULT (ic)), ic->key); + else + bitVectUnSetBit (OP_USES (IC_RESULT (ic)), ic->key); + } /* turn off the useSet for the operands */ if (IS_SYMOP (IC_LEFT (ic))) - bitVectUnSetBit (OP_USES (IC_LEFT (ic)), ic->key); + bitVectUnSetBit (OP_USES (IC_LEFT (ic)), ic->key); if (IS_SYMOP (IC_RIGHT (ic))) - bitVectUnSetBit (OP_USES (IC_RIGHT (ic)), ic->key); + bitVectUnSetBit (OP_USES (IC_RIGHT (ic)), ic->key); } else /* must be ifx turn off the use */ if (IS_SYMOP (IC_COND (ic))) @@ -1372,11 +1372,11 @@ unsetDefsAndUses (iCode * ic) /*-----------------------------------------------------------------*/ /* ifxOptimize - changes ifx conditions if it can */ /*-----------------------------------------------------------------*/ -void +void ifxOptimize (iCode * ic, set * cseSet, - int computeOnly, - eBBlock * ebb, int *change, - eBBlock ** ebbs, int count) + int computeOnly, + eBBlock * ebb, int *change, + eBBlock ** ebbs, int count) { operand *pdop; symbol *label; @@ -1387,10 +1387,10 @@ ifxOptimize (iCode * ic, set * cseSet, pdop = NULL; applyToSetFTrue (cseSet, findCheaperOp, IC_COND (ic), &pdop, 0); if (pdop) - { - ReplaceOpWithCheaperOp(&IC_COND (ic), pdop); - (*change)++; - } + { + ReplaceOpWithCheaperOp(&IC_COND (ic), pdop); + (*change)++; + } } /* if the conditional is a literal then */ @@ -1398,30 +1398,30 @@ ifxOptimize (iCode * ic, set * cseSet, { if ((operandLitValue (IC_COND (ic)) != 0.0) && IC_TRUE (ic)) - { + { - /* change to a goto */ - ic->op = GOTO; - IC_LABEL (ic) = IC_TRUE (ic); - (*change)++; + /* change to a goto */ + ic->op = GOTO; + IC_LABEL (ic) = IC_TRUE (ic); + (*change)++; - } + } else - { - - if (!operandLitValue (IC_COND (ic)) && IC_FALSE (ic)) - { - ic->op = GOTO; - IC_LABEL (ic) = IC_FALSE (ic); - (*change)++; - - } - else - { - /* then kill this if condition */ - remiCodeFromeBBlock (ebb, ic); - } - } + { + + if (!operandLitValue (IC_COND (ic)) && IC_FALSE (ic)) + { + ic->op = GOTO; + IC_LABEL (ic) = IC_FALSE (ic); + (*change)++; + + } + else + { + /* then kill this if condition */ + remiCodeFromeBBlock (ebb, ic); + } + } /* now we need to recompute the control flow */ /* since the control flow has changed */ @@ -1430,7 +1430,7 @@ ifxOptimize (iCode * ic, set * cseSet, /* the price */ computeControlFlow (ebbs, count, 1); if (!options.lessPedantic) { - werrorfl (ic->filename, ic->lineno, W_CONTROL_FLOW); + werrorfl (ic->filename, ic->lineno, W_CONTROL_FLOW); } return; } @@ -1444,21 +1444,21 @@ ifxOptimize (iCode * ic, set * cseSet, { if (!options.lessPedantic) { - werrorfl (ic->filename, ic->lineno, W_CONTROL_FLOW); + werrorfl (ic->filename, ic->lineno, W_CONTROL_FLOW); } if (IS_OP_VOLATILE (IC_COND (ic))) - { - IC_RIGHT (ic) = IC_COND (ic); - IC_LEFT (ic) = NULL; - IC_RESULT (ic) = NULL; - ic->op = DUMMY_READ_VOLATILE; - } + { + IC_RIGHT (ic) = IC_COND (ic); + IC_LEFT (ic) = NULL; + IC_RESULT (ic) = NULL; + ic->op = DUMMY_READ_VOLATILE; + } else { - remiCodeFromeBBlock (ebb, ic); - computeControlFlow (ebbs, count, 1); - return; - } + remiCodeFromeBBlock (ebb, ic); + computeControlFlow (ebbs, count, 1); + return; + } } @@ -1502,7 +1502,7 @@ DEFSETFUNC (diCodeForSym) /*-----------------------------------------------------------------*/ /* constFold - does some constant folding */ /*-----------------------------------------------------------------*/ -int +int constFold (iCode * ic, set * cseSet) { iCode *dic = NULL; @@ -1555,10 +1555,10 @@ constFold (iCode * ic, set * cseSet) IC_LEFT (ic) = operandFromOperand (IC_LEFT (dic)); if (ic->op == dic->op) IC_RIGHT (ic) = operandFromLit (operandLitValue (IC_RIGHT (ic)) + - operandLitValue (IC_RIGHT (dic))); + operandLitValue (IC_RIGHT (dic))); else IC_RIGHT (ic) = operandFromLit (operandLitValue (IC_RIGHT (ic)) - - operandLitValue (IC_RIGHT (dic))); + operandLitValue (IC_RIGHT (dic))); if (IS_ITEMP (IC_RESULT (ic))) { @@ -1575,7 +1575,7 @@ constFold (iCode * ic, set * cseSet) /* will delete from cseSet all get pointers computed from this */ /* pointer. A simple ifOperandsHave is not good enough here */ /*-----------------------------------------------------------------*/ -static void +static void deleteGetPointers (set ** cseSet, set ** pss, operand * op, eBBlock * ebb) { set *compItems = NULL; @@ -1588,7 +1588,7 @@ deleteGetPointers (set ** cseSet, set ** pss, operand * op, eBBlock * ebb) return; addSet (&compItems, op); - + /* Recursively find all items computed from this operand . This done fairly simply go thru the list and find those that are computed by arthimetic with these @@ -1601,26 +1601,26 @@ deleteGetPointers (set ** cseSet, set ** pss, operand * op, eBBlock * ebb) { changes = 0; for (cdp = setFirstItem (*cseSet); cdp; cdp = setNextItem (*cseSet)) - { - if (IS_ARITHMETIC_OP (cdp->diCode) || POINTER_GET(cdp->diCode)) - { - if (isinSetWith (compItems, (void*)IC_LEFT (cdp->diCode), - (insetwithFunc)isOperandEqual) || - isinSetWith (compItems, (void*)IC_RIGHT (cdp->diCode), - (insetwithFunc)isOperandEqual)) - { - if (!isinSetWith (compItems, (void*)IC_RESULT (cdp->diCode), - (insetwithFunc)isOperandEqual)) - { - addSet (&compItems, IC_RESULT (cdp->diCode)); - changes++; - } - } - } - } + { + if (IS_ARITHMETIC_OP (cdp->diCode) || POINTER_GET(cdp->diCode)) + { + if (isinSetWith (compItems, (void*)IC_LEFT (cdp->diCode), + (insetwithFunc)isOperandEqual) || + isinSetWith (compItems, (void*)IC_RIGHT (cdp->diCode), + (insetwithFunc)isOperandEqual)) + { + if (!isinSetWith (compItems, (void*)IC_RESULT (cdp->diCode), + (insetwithFunc)isOperandEqual)) + { + addSet (&compItems, IC_RESULT (cdp->diCode)); + changes++; + } + } + } + } } while (changes); - + /* now for the computed items */ for (cop = setFirstItem (compItems); cop; cop = setNextItem (compItems)) { @@ -1706,7 +1706,7 @@ static int isSignedOp (iCode *ic) case IFX: case RECEIVE: case SEND: - return 0; + return 0; case '*': case '/': case '%': @@ -1721,9 +1721,9 @@ static int isSignedOp (iCode *ic) case RIGHT_OP: case CAST: case ARRAYINIT: - return 1; + return 1; default: - return 0; + return 0; } } @@ -1751,7 +1751,7 @@ dumpCseSet(set *cseSet) /*-----------------------------------------------------------------*/ int cseBBlock (eBBlock * ebb, int computeOnly, - eBBlock ** ebbs, int count) + eBBlock ** ebbs, int count) { set *cseSet; iCode *ic; @@ -1791,157 +1791,179 @@ cseBBlock (eBBlock * ebb, int computeOnly, ic->eBBlockNum = ebb->bbnum; if (SKIP_IC2 (ic)) - continue; + continue; /* if this is an assignment from true symbol to a temp then do pointer post inc/dec optimzation */ if (ic->op == '=' && !POINTER_SET (ic) && - IS_PTR (operandType (IC_RESULT (ic)))) - { - ptrPostIncDecOpt (ic); - } + IS_PTR (operandType (IC_RESULT (ic)))) + { + ptrPostIncDecOpt (ic); + } /* clear the def & use chains for the operands involved */ /* in this operation . since it can change due to opts */ unsetDefsAndUses (ic); if (ic->op == PCALL || ic->op == CALL || ic->op == RECEIVE) - { - /* add to defSet of the symbol */ - OP_DEFS(IC_RESULT (ic))= - bitVectSetBit (OP_DEFS (IC_RESULT (ic)), ic->key); - /* add to the definition set of this block */ - ebb->defSet = bitVectSetBit (ebb->defSet, ic->key); - ebb->ldefs = bitVectSetBit (ebb->ldefs, ic->key); - ebb->outDefs = bitVectCplAnd (ebb->outDefs, OP_DEFS (IC_RESULT (ic))); - setUsesDefs (IC_RESULT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs); - /* delete global variables from the cseSet - since they can be modified by the function call */ - deleteItemIf (&cseSet, ifDefGlobal); - - /* and also itemps derived from globals */ - deleteItemIf (&cseSet, ifFromGlobal); - - /* delete all getpointer iCodes from cseSet, this should - be done only for global arrays & pointers but at this - point we don't know if globals, so to be safe do all */ - deleteItemIf (&cseSet, ifAnyGetPointer); - + { + /* add to defSet of the symbol */ + OP_DEFS(IC_RESULT (ic))= + bitVectSetBit (OP_DEFS (IC_RESULT (ic)), ic->key); + /* add to the definition set of this block */ + ebb->defSet = bitVectSetBit (ebb->defSet, ic->key); + ebb->ldefs = bitVectSetBit (ebb->ldefs, ic->key); + ebb->outDefs = bitVectCplAnd (ebb->outDefs, OP_DEFS (IC_RESULT (ic))); + setUsesDefs (IC_RESULT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs); + /* delete global variables from the cseSet + since they can be modified by the function call */ + deleteItemIf (&cseSet, ifDefGlobal); + + /* and also itemps derived from globals */ + deleteItemIf (&cseSet, ifFromGlobal); + + /* delete all getpointer iCodes from cseSet, this should + be done only for global arrays & pointers but at this + point we don't know if globals, so to be safe do all */ + deleteItemIf (&cseSet, ifAnyGetPointer); + /* can't cache pointer set/get operations across a call */ deleteSet (&ptrSetSet); - } + } /* for pcall & ipush we need to add to the useSet */ if ((ic->op == PCALL || - ic->op == IPUSH || - ic->op == IPOP || - ic->op == SEND) && - IS_SYMOP (IC_LEFT (ic))) - { - - /* check if they can be replaced */ - if (!computeOnly) - { - pdop = NULL; - applyToSetFTrue (cseSet, findCheaperOp, IC_LEFT (ic), &pdop, 0); - if (pdop) - ReplaceOpWithCheaperOp(&IC_LEFT(ic), pdop); - } - /* the lookup could have changed it */ - if (IS_SYMOP (IC_LEFT (ic))) - { - OP_USES(IC_LEFT (ic))= - bitVectSetBit (OP_USES (IC_LEFT (ic)), ic->key); - setUsesDefs (IC_LEFT (ic), ebb->defSet, - ebb->outDefs, &ebb->usesDefs); - } - - - /* if we a sending a pointer as a parameter - then kill all cse since the pointed to item - might be changed in the function being called */ - if ((ic->op == IPUSH || ic->op == SEND) && - IS_PTR (operandType (IC_LEFT (ic)))) - { - deleteGetPointers (&cseSet, &ptrSetSet, IC_LEFT (ic), ebb); - ebb->ptrsSet = bitVectSetBit (ebb->ptrsSet, IC_LEFT (ic)->key); - for (i = 0; i < count; ebbs[i++]->visited = 0); - applyToSet (ebb->succList, delGetPointerSucc, - IC_LEFT (ic), ebb->dfnum); - } - continue; - } + ic->op == IPUSH || + ic->op == IPOP || + ic->op == SEND) && + IS_SYMOP (IC_LEFT (ic))) + { + + /* check if they can be replaced */ + if (!computeOnly) + { + pdop = NULL; + applyToSetFTrue (cseSet, findCheaperOp, IC_LEFT (ic), &pdop, 0); + if (pdop) + ReplaceOpWithCheaperOp(&IC_LEFT(ic), pdop); + } + /* the lookup could have changed it */ + if (IS_SYMOP (IC_LEFT (ic))) + { + OP_USES(IC_LEFT (ic))= + bitVectSetBit (OP_USES (IC_LEFT (ic)), ic->key); + setUsesDefs (IC_LEFT (ic), ebb->defSet, + ebb->outDefs, &ebb->usesDefs); + } + + + /* if we a sending a pointer as a parameter + then kill all cse since the pointed to item + might be changed in the function being called */ + if ((ic->op == IPUSH || ic->op == SEND) && + IS_PTR (operandType (IC_LEFT (ic)))) + { + deleteGetPointers (&cseSet, &ptrSetSet, IC_LEFT (ic), ebb); + ebb->ptrsSet = bitVectSetBit (ebb->ptrsSet, IC_LEFT (ic)->key); + for (i = 0; i < count; ebbs[i++]->visited = 0); + applyToSet (ebb->succList, delGetPointerSucc, + IC_LEFT (ic), ebb->dfnum); + } + continue; + } /* if jumptable then mark the usage */ if (ic->op == JUMPTABLE) - { + { if (IS_SYMOP (IC_JTCOND (ic))) - { - OP_USES(IC_JTCOND (ic)) = - bitVectSetBit (OP_USES (IC_JTCOND (ic)), ic->key); - setUsesDefs (IC_JTCOND (ic), ebb->defSet, - ebb->outDefs, &ebb->usesDefs); - } - continue; - } + { + OP_USES(IC_JTCOND (ic)) = + bitVectSetBit (OP_USES (IC_JTCOND (ic)), ic->key); + setUsesDefs (IC_JTCOND (ic), ebb->defSet, + ebb->outDefs, &ebb->usesDefs); + } + continue; + } if (SKIP_IC (ic)) - continue; + continue; - if (!computeOnly) { - /* do some algebraic optimizations if possible */ - algebraicOpts (ic, ebb); - while (constFold (ic, cseSet)); - } + if (!computeOnly) + { + /* do some algebraic optimizations if possible */ + algebraicOpts (ic, ebb); + while (constFold (ic, cseSet)); + } - /* small klugde */ - if (POINTER_GET (ic) && !IS_PTR (operandType (IC_LEFT (ic)))) - { - setOperandType (IC_LEFT (ic), - aggrToPtr (operandType (IC_LEFT (ic)), FALSE)); - fixUpTypes (ic); + /* small kludge */ + if (POINTER_GET (ic)) + { + if (!IS_PTR (operandType (IC_LEFT (ic)))) + { + setOperandType (IC_LEFT (ic), + aggrToPtr (operandType (IC_LEFT (ic)), FALSE)); + IC_LEFT (ic)->aggr2ptr = 0; + fixUpTypes (ic); + } + else if (IC_LEFT (ic)->aggr2ptr) + {/* band aid for kludge */ + setOperandType (IC_LEFT (ic), + aggrToPtr (operandType (IC_LEFT (ic)), TRUE)); + IC_LEFT (ic)->aggr2ptr = 0; + fixUpTypes (ic); + } + } - } - if (POINTER_SET (ic) && !IS_PTR (operandType (IC_RESULT (ic)))) - { - setOperandType (IC_RESULT (ic), - aggrToPtr (operandType (IC_RESULT (ic)), FALSE)); - } + if (POINTER_SET (ic)) + { + if (!IS_PTR (operandType (IC_RESULT (ic)))) + { + setOperandType (IC_RESULT (ic), + aggrToPtr (operandType (IC_RESULT (ic)), FALSE)); + IC_RESULT (ic)->aggr2ptr = 0; + } + else if (IC_RESULT (ic)->aggr2ptr) + {/* band aid for kludge */ + setOperandType (IC_RESULT (ic), + aggrToPtr (operandType (IC_RESULT (ic)), TRUE)); + IC_RESULT (ic)->aggr2ptr = 0; + } + } /* if this is a condition statement then */ /* check if the condition can be replaced */ if (ic->op == IFX) - { - ifxOptimize (ic, cseSet, computeOnly, - ebb, &change, - ebbs, count); - continue; - } + { + ifxOptimize (ic, cseSet, computeOnly, + ebb, &change, + ebbs, count); + continue; + } /* if the assignment & result is a temp */ /* see if we can replace it */ if (!computeOnly && ic->op == '=') - { - - /* update the spill location for this */ - updateSpillLocation (ic,0); - - if (POINTER_SET (ic) && - !(IS_BITFIELD (OP_SYMBOL (IC_RESULT (ic))->etype))) - { - pdop = NULL; - applyToSetFTrue (cseSet, findCheaperOp, IC_RESULT (ic), &pdop, 0); - if (pdop && !computeOnly && IS_ITEMP (pdop)) - { - ReplaceOpWithCheaperOp (&IC_RESULT(ic), pdop); - if (!IS_PTR (operandType (IC_RESULT (ic)))) - { - setOperandType (IC_RESULT (ic), - aggrToPtr (operandType (IC_RESULT (ic)), FALSE)); - } - } - } - } + { + + /* update the spill location for this */ + updateSpillLocation (ic,0); + + if (POINTER_SET (ic) && + !(IS_BITFIELD (OP_SYMBOL (IC_RESULT (ic))->etype))) + { + pdop = NULL; + applyToSetFTrue (cseSet, findCheaperOp, IC_RESULT (ic), &pdop, 0); + if (pdop && !computeOnly && IS_ITEMP (pdop)) + { + ReplaceOpWithCheaperOp (&IC_RESULT(ic), pdop); + if (!IS_PTR (operandType (IC_RESULT (ic)))) + { + setOperandType (IC_RESULT (ic), + aggrToPtr (operandType (IC_RESULT (ic)), FALSE)); + } + } + } + } checkSign = isSignedOp(ic); @@ -1952,72 +1974,72 @@ cseBBlock (eBBlock * ebb, int computeOnly, /* left operand */ /* and left is a symbol */ if (IS_SYMOP (IC_LEFT (ic)) && - !computeOnly && ic->op != ADDRESS_OF) - { - - pdop = NULL; - applyToSetFTrue (cseSet, findCheaperOp, IC_LEFT (ic), &pdop, checkSign); - if (pdop) - { - if (POINTER_GET (ic)) - { - if (IS_ITEMP (pdop) || IS_OP_LITERAL (pdop)) - { - /* some non dominating block does POINTER_SET with - this variable .. unsafe to remove any POINTER_GETs */ - if (bitVectBitValue(ebb->ndompset,IC_LEFT(ic)->key)) - ebb->ptrsSet = bitVectSetBit(ebb->ptrsSet,pdop->key); - ReplaceOpWithCheaperOp(&IC_LEFT(ic), pdop); - change = 1; - } - /* check if there is a pointer set - for the same pointer visible if yes - then change this into an assignment */ - pdop = NULL; - if (applyToSetFTrue (cseSet, findPointerSet, IC_LEFT (ic), &pdop, IC_RESULT (ic)) && - !bitVectBitValue (ebb->ptrsSet, pdop->key)) - { - ic->op = '='; - IC_LEFT (ic) = NULL; - ReplaceOpWithCheaperOp(&IC_RIGHT(ic), pdop); - SET_ISADDR (IC_RESULT (ic), 0); - } - - } - else - { - ReplaceOpWithCheaperOp(&IC_LEFT(ic), pdop); - change = 1; - } - } - } + !computeOnly && ic->op != ADDRESS_OF) + { + + pdop = NULL; + applyToSetFTrue (cseSet, findCheaperOp, IC_LEFT (ic), &pdop, checkSign); + if (pdop) + { + if (POINTER_GET (ic)) + { + if (IS_ITEMP (pdop) || IS_OP_LITERAL (pdop)) + { + /* some non dominating block does POINTER_SET with + this variable .. unsafe to remove any POINTER_GETs */ + if (bitVectBitValue(ebb->ndompset,IC_LEFT(ic)->key)) + ebb->ptrsSet = bitVectSetBit(ebb->ptrsSet,pdop->key); + ReplaceOpWithCheaperOp(&IC_LEFT(ic), pdop); + change = 1; + } + /* check if there is a pointer set + for the same pointer visible if yes + then change this into an assignment */ + pdop = NULL; + if (applyToSetFTrue (cseSet, findPointerSet, IC_LEFT (ic), &pdop, IC_RESULT (ic)) && + !bitVectBitValue (ebb->ptrsSet, pdop->key)) + { + ic->op = '='; + IC_LEFT (ic) = NULL; + ReplaceOpWithCheaperOp(&IC_RIGHT(ic), pdop); + SET_ISADDR (IC_RESULT (ic), 0); + } + + } + else + { + ReplaceOpWithCheaperOp(&IC_LEFT(ic), pdop); + change = 1; + } + } + } /*right operand */ if (IS_SYMOP (IC_RIGHT (ic)) && !computeOnly) - { + { - pdop = NULL; - applyToSetFTrue (cseSet, findCheaperOp, IC_RIGHT (ic), &pdop, checkSign); - if (pdop) { - ReplaceOpWithCheaperOp(&IC_RIGHT(ic), pdop); - change = 1; - } - } + pdop = NULL; + applyToSetFTrue (cseSet, findCheaperOp, IC_RIGHT (ic), &pdop, checkSign); + if (pdop) { + ReplaceOpWithCheaperOp(&IC_RIGHT(ic), pdop); + change = 1; + } + } /* if left or right changed then do algebraic */ if (!computeOnly && change) - { - algebraicOpts (ic, ebb); - while (constFold (ic, cseSet)); - } + { + algebraicOpts (ic, ebb); + while (constFold (ic, cseSet)); + } /* if after all this it becomes an assignment to self then delete it and continue */ if (ASSIGNMENT_TO_SELF (ic)) - { - remiCodeFromeBBlock (ebb, ic); - continue; - } + { + remiCodeFromeBBlock (ebb, ic); + continue; + } /* now we will check to see if the entire */ /* operation has been performed before */ @@ -2027,43 +2049,43 @@ cseBBlock (eBBlock * ebb, int computeOnly, /* it only if result is a temporary */ pdic = NULL; if (!(POINTER_GET (ic) && - (IS_BITFIELD (OP_SYMBOL (IC_RESULT (ic))->etype) || - isOperandVolatile (IC_LEFT (ic), TRUE) || - bitVectBitValue (ebb->ndompset, IC_LEFT (ic)->key))) && - !ASSIGNMENT (ic) && - IS_ITEMP (IC_RESULT (ic)) && - !computeOnly) - { - applyToSet (cseSet, findPrevIc, ic, &pdic); - if (pdic && compareType (operandType (IC_RESULT (pdic)), - operandType (IC_RESULT (ic))) != 1) - pdic = NULL; - if (pdic && port->cseOk && (*port->cseOk)(ic,pdic) == 0) - pdic = NULL; - } + (IS_BITFIELD (OP_SYMBOL (IC_RESULT (ic))->etype) || + isOperandVolatile (IC_LEFT (ic), TRUE) || + bitVectBitValue (ebb->ndompset, IC_LEFT (ic)->key))) && + !ASSIGNMENT (ic) && + IS_ITEMP (IC_RESULT (ic)) && + !computeOnly) + { + applyToSet (cseSet, findPrevIc, ic, &pdic); + if (pdic && compareType (operandType (IC_RESULT (pdic)), + operandType (IC_RESULT (ic))) != 1) + pdic = NULL; + if (pdic && port->cseOk && (*port->cseOk)(ic,pdic) == 0) + pdic = NULL; + } /* Alternate code */ if (pdic && IS_ITEMP(IC_RESULT(ic))) { - if (POINTER_GET(ic) && bitVectBitValue(ebb->ptrsSet,IC_LEFT(ic)->key)) { - /* Mmm, found an equivalent pointer get at a lower level. - This could be a loop however with the same pointer set - later on */ - } else { - /* if previous definition found change this to an assignment */ - ic->op = '='; - IC_LEFT(ic) = NULL; - IC_RIGHT(ic) = operandFromOperand(IC_RESULT(pdic)); - SET_ISADDR(IC_RESULT(ic),0); - SET_ISADDR(IC_RIGHT (ic),0); - } + if (POINTER_GET(ic) && bitVectBitValue(ebb->ptrsSet,IC_LEFT(ic)->key)) { + /* Mmm, found an equivalent pointer get at a lower level. + This could be a loop however with the same pointer set + later on */ + } else { + /* if previous definition found change this to an assignment */ + ic->op = '='; + IC_LEFT(ic) = NULL; + IC_RIGHT(ic) = operandFromOperand(IC_RESULT(pdic)); + SET_ISADDR(IC_RESULT(ic),0); + SET_ISADDR(IC_RIGHT (ic),0); + } } if (!(POINTER_SET (ic)) && IC_RESULT (ic)) { cseDef *csed; - deleteItemIf (&cseSet, ifDefSymIsX, IC_RESULT (ic)); + deleteItemIf (&cseSet, ifDefSymIsX, IC_RESULT (ic)); csed = newCseDef (IC_RESULT (ic), ic); updateCseDefAncestors (csed, cseSet); - addSetHead (&cseSet, csed); + addSetHead (&cseSet, csed); } defic = ic; @@ -2071,98 +2093,98 @@ cseBBlock (eBBlock * ebb, int computeOnly, mine and type is a pointer then delete pointerGets to take care of aliasing */ if (ASSIGNMENT (ic) && - OTHERS_PARM (OP_SYMBOL (IC_RESULT (ic))) && - IS_PTR (operandType (IC_RESULT (ic)))) - { - deleteGetPointers (&cseSet, &ptrSetSet, IC_RIGHT (ic), ebb); - for (i = 0; i < count; ebbs[i++]->visited = 0); - applyToSet (ebb->succList, delGetPointerSucc, IC_RIGHT (ic), ebb->dfnum); - ebb->ptrsSet = bitVectSetBit (ebb->ptrsSet, IC_RIGHT (ic)->key); - } + OTHERS_PARM (OP_SYMBOL (IC_RESULT (ic))) && + IS_PTR (operandType (IC_RESULT (ic)))) + { + deleteGetPointers (&cseSet, &ptrSetSet, IC_RIGHT (ic), ebb); + for (i = 0; i < count; ebbs[i++]->visited = 0); + applyToSet (ebb->succList, delGetPointerSucc, IC_RIGHT (ic), ebb->dfnum); + ebb->ptrsSet = bitVectSetBit (ebb->ptrsSet, IC_RIGHT (ic)->key); + } /* if this is a pointerget then see if we can replace this with a previously assigned pointer value */ if (POINTER_GET (ic) && - !(IS_BITFIELD (OP_SYMBOL (IC_RESULT (ic))->etype) || - isOperandVolatile (IC_LEFT (ic), TRUE))) - { - pdop = NULL; - applyToSet (ptrSetSet, findPointerSet, IC_LEFT (ic), &pdop, IC_RESULT (ic)); - /* if we find it then locally replace all - references to the result with what we assigned */ - if (pdop) - { - replaceAllSymBySym (ic->next, IC_RESULT (ic), pdop, &ebb->ndompset); - } - } + !(IS_BITFIELD (OP_SYMBOL (IC_RESULT (ic))->etype) || + isOperandVolatile (IC_LEFT (ic), TRUE))) + { + pdop = NULL; + applyToSet (ptrSetSet, findPointerSet, IC_LEFT (ic), &pdop, IC_RESULT (ic)); + /* if we find it then locally replace all + references to the result with what we assigned */ + if (pdop) + { + replaceAllSymBySym (ic->next, IC_RESULT (ic), pdop, &ebb->ndompset); + } + } /* delete from the cseSet anything that has */ /* operands matching the result of this */ /* except in case of pointer access */ if (!(POINTER_SET (ic)) && IC_RESULT (ic)) - { - deleteItemIf (&cseSet, ifOperandsHave, IC_RESULT (ic)); - /* delete any previous definitions */ - ebb->defSet = bitVectCplAnd (ebb->defSet, OP_DEFS (IC_RESULT (ic))); + { + deleteItemIf (&cseSet, ifOperandsHave, IC_RESULT (ic)); + /* delete any previous definitions */ + ebb->defSet = bitVectCplAnd (ebb->defSet, OP_DEFS (IC_RESULT (ic))); - } + } /* add the left & right to the defUse set */ if (IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic))) - { - OP_USES(IC_LEFT (ic))= - bitVectSetBit (OP_USES (IC_LEFT (ic)), ic->key); - setUsesDefs (IC_LEFT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs); + { + OP_USES(IC_LEFT (ic))= + bitVectSetBit (OP_USES (IC_LEFT (ic)), ic->key); + setUsesDefs (IC_LEFT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs); - } + } if (IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic))) - { - OP_USES(IC_RIGHT (ic))= - bitVectSetBit (OP_USES (IC_RIGHT (ic)), ic->key); - setUsesDefs (IC_RIGHT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs); + { + OP_USES(IC_RIGHT (ic))= + bitVectSetBit (OP_USES (IC_RIGHT (ic)), ic->key); + setUsesDefs (IC_RIGHT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs); - } + } /* for the result it is special case, put the result */ /* in the defuseSet if it a pointer or array access */ if (POINTER_SET (defic)) - { - OP_USES(IC_RESULT (ic))= - bitVectSetBit (OP_USES (IC_RESULT (ic)), ic->key); - setUsesDefs (IC_RESULT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs); - deleteItemIf (&cseSet, ifPointerGet, IC_RESULT (ic)); - ebb->ptrsSet = bitVectSetBit (ebb->ptrsSet, IC_RESULT (ic)->key); - /* delete from inexpressions of all successors which - have dfNum > than this block */ - for (i = 0; i < count; ebbs[i++]->visited = 0); - applyToSet (ebb->succList, delGetPointerSucc, IC_RESULT (ic), ebb->dfnum); - - /* delete from cseSet all other pointer sets - for this operand */ - deleteItemIf (&ptrSetSet, ifPointerSet, IC_RESULT (ic)); - /* add to the local pointerset set */ - addSetHead (&ptrSetSet, newCseDef (IC_RESULT (ic), ic)); - } + { + OP_USES(IC_RESULT (ic))= + bitVectSetBit (OP_USES (IC_RESULT (ic)), ic->key); + setUsesDefs (IC_RESULT (ic), ebb->defSet, ebb->outDefs, &ebb->usesDefs); + deleteItemIf (&cseSet, ifPointerGet, IC_RESULT (ic)); + ebb->ptrsSet = bitVectSetBit (ebb->ptrsSet, IC_RESULT (ic)->key); + /* delete from inexpressions of all successors which + have dfNum > than this block */ + for (i = 0; i < count; ebbs[i++]->visited = 0); + applyToSet (ebb->succList, delGetPointerSucc, IC_RESULT (ic), ebb->dfnum); + + /* delete from cseSet all other pointer sets + for this operand */ + deleteItemIf (&ptrSetSet, ifPointerSet, IC_RESULT (ic)); + /* add to the local pointerset set */ + addSetHead (&ptrSetSet, newCseDef (IC_RESULT (ic), ic)); + } else - /* add the result to defintion set */ if (IC_RESULT (ic)) - { - OP_DEFS(IC_RESULT (ic))= - bitVectSetBit (OP_DEFS (IC_RESULT (ic)), ic->key); - ebb->defSet = bitVectSetBit (ebb->defSet, ic->key); - ebb->outDefs = bitVectCplAnd (ebb->outDefs, OP_DEFS (IC_RESULT (ic))); - ebb->ldefs = bitVectSetBit (ebb->ldefs, ic->key); - } + /* add the result to defintion set */ if (IC_RESULT (ic)) + { + OP_DEFS(IC_RESULT (ic))= + bitVectSetBit (OP_DEFS (IC_RESULT (ic)), ic->key); + ebb->defSet = bitVectSetBit (ebb->defSet, ic->key); + ebb->outDefs = bitVectCplAnd (ebb->outDefs, OP_DEFS (IC_RESULT (ic))); + ebb->ldefs = bitVectSetBit (ebb->ldefs, ic->key); + } /* if this is an addressof instruction then */ /* put the symbol in the address of list & */ /* delete it from the cseSet */ if (defic->op == ADDRESS_OF) - { - addSetHead (&ebb->addrOf, IC_LEFT (ic)); - deleteItemIf (&cseSet, ifDefSymIsX, IC_LEFT (ic)); - } + { + addSetHead (&ebb->addrOf, IC_LEFT (ic)); + deleteItemIf (&cseSet, ifDefSymIsX, IC_LEFT (ic)); + } } for (expr=setFirstItem (ebb->inExprs); expr; expr=setNextItem (ebb->inExprs)) diff --git a/src/SDCCcse.h b/src/SDCCcse.h index 88684378..0074f75e 100644 --- a/src/SDCCcse.h +++ b/src/SDCCcse.h @@ -31,7 +31,7 @@ typedef struct cseDef { - unsigned int key; + int key; operand *sym; /* defining symbol */ iCode *diCode; /* defining instruction */ bitVect *ancestors; /* keys of the symbol's ancestors */ diff --git a/src/SDCCglue.c b/src/SDCCglue.c index c4acdfe5..1c463a29 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -825,7 +825,7 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist, FILE * oFile) { initList *iloop; - int size = 0; + unsigned int size = 0; if (ilist) { /* take care of the special case */ @@ -1571,7 +1571,7 @@ emitOverlay (FILE * afile) static char * spacesToUnderscores (char *dest, const char *src, size_t len) { - int i; + unsigned int i; char *p; assert(dest != NULL); diff --git a/src/SDCCicode.c b/src/SDCCicode.c index b46ab976..c024091a 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -234,12 +234,12 @@ printOperand (operand * op, FILE * file) case SYMBOL: #define REGA 1 #ifdef REGA - fprintf (file, "%s [k%d lr%d:%d so:%d]{ ia%d re%d rm%d nos%d ru%d dp%d}", /*{ar%d rm%d ru%d p%d a%d u%d i%d au%d k%d ks%d}" , */ + fprintf (file, "%s [k%d lr%d:%d so:%d]{ ia%d a2p%d re%d rm%d nos%d ru%d dp%d}", /*{ar%d rm%d ru%d p%d a%d u%d i%d au%d k%d ks%d}" , */ (OP_SYMBOL (op)->rname[0] ? OP_SYMBOL (op)->rname : OP_SYMBOL (op)->name), op->key, OP_LIVEFROM (op), OP_LIVETO (op), OP_SYMBOL (op)->stack, - op->isaddr, OP_SYMBOL (op)->isreqv, + op->isaddr, op->aggr2ptr, OP_SYMBOL (op)->isreqv, OP_SYMBOL (op)->remat,OP_SYMBOL(op)->noSpilLoc, OP_SYMBOL(op)->ruonly,OP_SYMBOL(op)->dptr ); @@ -2307,7 +2307,7 @@ geniCodeAdd (operand * left, operand * right, RESULT_TYPE resultType, int lvl) } /*-----------------------------------------------------------------*/ -/* aggrToPtr - changes an aggregate to pointer to an aggregate */ +/* aggrToPtr - changes an "aggregate" to a "pointer to aggregate" */ /*-----------------------------------------------------------------*/ sym_link * aggrToPtr (sym_link * type, bool force) @@ -2416,7 +2416,11 @@ geniCodeArray (operand * left, operand * right, int lvl) !IS_PTR (ltype->next)) ? ltype : ltype->next), 0); - IC_RESULT (ic)->isaddr = (!IS_AGGREGATE (ltype->next)); + if (!IS_AGGREGATE (ltype->next)) + { + IC_RESULT (ic)->isaddr = 1; + IC_RESULT (ic)->aggr2ptr = 1; + } ADDTOCHAIN (ic); return IC_RESULT (ic); @@ -2436,7 +2440,7 @@ geniCodeStruct (operand * left, operand * right, bool islval) right->operand.symOperand); wassert(IS_SYMOP(right)); - + /* add the offset */ ic = newiCode ('+', left, operandFromLit (element->offset)); @@ -2449,10 +2453,10 @@ geniCodeStruct (operand * left, operand * right, bool islval) SPEC_OCLS (retype) = SPEC_OCLS (etype); SPEC_VOLATILE (retype) |= SPEC_VOLATILE (etype); SPEC_CONST (retype) |= SPEC_CONST (etype); - + if (IS_PTR (element->type)) setOperandType (IC_RESULT (ic), aggrToPtr (operandType (IC_RESULT (ic)), TRUE)); - + IC_RESULT (ic)->isaddr = (!IS_AGGREGATE (element->type)); ADDTOCHAIN (ic); @@ -3495,18 +3499,18 @@ geniCodeJumpTable (operand * cond, value * caseVals, ast * tree) /* inserts jumps to the default label for the missing numbers */ /* and decides later whether it is worth it */ min = (int) floatFromVal (vch = caseVals); - + while (vch->next) { cnt++; vch = vch->next; } max = (int) floatFromVal (vch); - + /* Exit if the range is too large to handle with a jump table. */ if (1 + max - min > port->jumptableCost.maxCount) return 0; - + switch (getSize (operandType (cond))) { case 1: sizeIndex = 0; break; @@ -3536,7 +3540,7 @@ geniCodeJumpTable (operand * cond, value * caseVals, ast * tree) if (1 + max <= port->jumptableCost.maxCount) min = 0; } - + /* Compute the total size cost of a jump table. */ sizeofJumpTable = (1 + max - min) * port->jumptableCost.sizeofElement + port->jumptableCost.sizeofDispatch @@ -3548,7 +3552,7 @@ geniCodeJumpTable (operand * cond, value * caseVals, ast * tree) /* If the size cost of the jump table is uneconomical then exit */ if (sizeofMatchJump < sizeofJumpTable) return 0; - + /* The jump table is preferable. */ /* First, a label for the default or missing cases. */ @@ -3565,7 +3569,7 @@ geniCodeJumpTable (operand * cond, value * caseVals, ast * tree) tree->values.switchVals.swNum); } falseLabel = newiTempLabel (buffer); - + /* Build the list of labels for the jump table. */ vch = caseVals; t = (int) floatFromVal (vch); diff --git a/src/SDCCicode.h b/src/SDCCicode.h index 3069ff10..e5dbe9d8 100644 --- a/src/SDCCicode.h +++ b/src/SDCCicode.h @@ -1,25 +1,25 @@ /*------------------------------------------------------------------------- - SDCCicode.h - intermediate code generation etc. + SDCCicode.h - intermediate code generation etc. Written By - Sandeep Dutta . sandeep.dutta@usa.net (1998) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve - what you give them. Help stamp out software-hoarding! + what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ #include "SDCCbitv.h" #include "SDCCset.h" @@ -73,35 +73,36 @@ OPTYPE; /* typedef for operand */ typedef struct operand { - OPTYPE type; /* type of operand */ - unsigned int isaddr:1; /* is an address */ - unsigned int isvolatile:1; /* is a volatile operand */ - unsigned int isGlobal:1; /* is a global operand */ - unsigned int isPtr:1; /* is assigned a pointer */ - unsigned int isGptr:1; /* is a generic pointer */ - unsigned int isParm:1; /* is a parameter */ - unsigned int isLiteral:1; /* operand is literal */ - - unsigned key; + OPTYPE type; /* type of operand */ + unsigned int isaddr:1; /* is an address */ + unsigned int aggr2ptr:1; /* must change aggregate to pointer to aggregate */ + unsigned int isvolatile:1; /* is a volatile operand */ + unsigned int isGlobal:1; /* is a global operand */ + unsigned int isPtr:1; /* is assigned a pointer */ + unsigned int isGptr:1; /* is a generic pointer */ + unsigned int isParm:1; /* is a parameter */ + unsigned int isLiteral:1; /* operand is literal */ + + int key; union { - struct symbol *symOperand; /* operand is of type symbol */ - struct value *valOperand; /* operand is of type value */ - struct sym_link *typeOperand; /* operand is of type typechain */ + struct symbol *symOperand; /* operand is of type symbol */ + struct value *valOperand; /* operand is of type value */ + struct sym_link *typeOperand; /* operand is of type typechain */ } operand; - bitVect *usesDefs; /* which definitions are used by this */ - struct asmop *aop; /* asm op for this operand */ + bitVect *usesDefs; /* which definitions are used by this */ + struct asmop *aop; /* asm op for this operand */ } operand; -extern operand *validateOpType(operand *op, - const char *macro, - const char *args, - OPTYPE type, - const char *file, - unsigned line); +extern operand *validateOpType(operand *op, + const char *macro, + const char *args, + OPTYPE type, + const char *file, + unsigned line); #define OP_SYMBOL(op) validateOpType(op, "OP_SYMBOL", #op, SYMBOL, __FILE__, __LINE__)->operand.symOperand #define OP_VALUE(op) validateOpType(op, "OP_VALUE", #op, VALUE, __FILE__, __LINE__)->operand.valOperand @@ -127,71 +128,71 @@ extern operand *validateOpType(operand *op, typedef struct iCode { - unsigned int op; /* operation defined */ - int key; /* running key for this iCode */ - int seq; /* sequence number within routine */ - int seqPoint; /* sequence point */ - short depth; /* loop depth of this iCode */ - short level; /* scope level */ - short block; /* sequential block number */ - unsigned nosupdate:1; /* don't update spillocation with this */ - unsigned generated:1; /* code generated for this one */ - unsigned parmPush:1; /* parameter push Vs spill push */ - unsigned supportRtn:1; /* will cause a call to a support routine */ - unsigned regsSaved:1; /* registers have been saved */ - unsigned bankSaved:1; /* register bank has been saved */ + unsigned int op; /* operation defined */ + int key; /* running key for this iCode */ + int seq; /* sequence number within routine */ + int seqPoint; /* sequence point */ + short depth; /* loop depth of this iCode */ + short level; /* scope level */ + short block; /* sequential block number */ + unsigned nosupdate:1; /* don't update spillocation with this */ + unsigned generated:1; /* code generated for this one */ + unsigned parmPush:1; /* parameter push Vs spill push */ + unsigned supportRtn:1; /* will cause a call to a support routine */ + unsigned regsSaved:1; /* registers have been saved */ + unsigned bankSaved:1; /* register bank has been saved */ unsigned builtinSEND:1; /* SEND for parameter of builtin function */ - struct iCode *next; /* next in chain */ - struct iCode *prev; /* previous in chain */ - set *movedFrom; /* if this iCode gets moved to another block */ - bitVect *rlive; /* ranges that are live at this point */ - int defKey; /* key for the operand being defined */ - bitVect *uses; /* vector of key of used symbols */ - bitVect *rUsed; /* registers used by this instruction */ - bitVect *rMask; /* registers in use during this instruction */ + struct iCode *next; /* next in chain */ + struct iCode *prev; /* previous in chain */ + set *movedFrom; /* if this iCode gets moved to another block */ + bitVect *rlive; /* ranges that are live at this point */ + int defKey; /* key for the operand being defined */ + bitVect *uses; /* vector of key of used symbols */ + bitVect *rUsed; /* registers used by this instruction */ + bitVect *rMask; /* registers in use during this instruction */ union { - struct - { - operand *left; /* left if any */ - operand *right; /* right if any */ - operand *result; /* result of this op */ - } - lrr; - - struct - { - operand *condition; /* if this is a conditional */ - symbol *trueLabel; /* true for conditional */ - symbol *falseLabel; /* false for conditional */ - } - cnd; - - struct - { - operand *condition; /* condition for the jump */ - set *labels; /* ordered set of labels */ - } - jmpTab; + struct + { + operand *left; /* left if any */ + operand *right; /* right if any */ + operand *result; /* result of this op */ + } + lrr; + + struct + { + operand *condition; /* if this is a conditional */ + symbol *trueLabel; /* true for conditional */ + symbol *falseLabel; /* false for conditional */ + } + cnd; + + struct + { + operand *condition; /* condition for the jump */ + set *labels; /* ordered set of labels */ + } + jmpTab; } ulrrcnd; - symbol *label; /* for a goto statement */ + symbol *label; /* for a goto statement */ - char *inlineAsm; /* pointer to inline assembler code */ + char *inlineAsm; /* pointer to inline assembler code */ literalList *arrayInitList; /* point to array initializer list. */ - int lineno; /* file & lineno for debug information */ + int lineno; /* file & lineno for debug information */ char *filename; - - int parmBytes; /* if call/pcall, count of parameter bytes - on stack */ - int argreg; /* argument regno for SEND/RECEIVE */ + + int parmBytes; /* if call/pcall, count of parameter bytes + on stack */ + int argreg; /* argument regno for SEND/RECEIVE */ int eBBlockNum; /* belongs to which eBBlock */ - char riu; /* after ralloc, the registers in use */ - struct ast * tree; /* ast node for this iCode (if not NULL) */ + char riu; /* after ralloc, the registers in use */ + struct ast * tree; /* ast node for this iCode (if not NULL) */ } iCode; @@ -207,37 +208,37 @@ iCodeTable; /* useful macros */ #define SKIP_IC2(x) (x->op == GOTO || \ - x->op == LABEL || \ - x->op == FUNCTION || \ + x->op == LABEL || \ + x->op == FUNCTION || \ x->op == INLINEASM || \ - x->op == ENDFUNCTION ) + x->op == ENDFUNCTION ) #define SKIP_IC1(x) (x->op == CALL || \ - SKIP_IC2(x) ) + SKIP_IC2(x) ) #define SKIP_IC(x) (x->op == PCALL || \ - x->op == IPUSH || \ + x->op == IPUSH || \ x->op == IPOP || \ x->op == JUMPTABLE || \ x->op == RECEIVE || \ - x->op == ARRAYINIT || \ - SKIP_IC1(x)|| \ - x->op == SEND ) + x->op == ARRAYINIT || \ + SKIP_IC1(x)|| \ + x->op == SEND ) -#define SKIP_IC3(x) (SKIP_IC2(x) || \ - x->op == JUMPTABLE ) +#define SKIP_IC3(x) (SKIP_IC2(x) || \ + x->op == JUMPTABLE ) #define IS_CONDITIONAL(x) (x->op == EQ_OP || \ - x->op == '<' || \ - x->op == '>' || \ - x->op == LE_OP || \ - x->op == GE_OP || \ - x->op == NE_OP ) + x->op == '<' || \ + x->op == '>' || \ + x->op == LE_OP || \ + x->op == GE_OP || \ + x->op == NE_OP ) #define IS_TRUE_SYMOP(op) (op && IS_SYMOP(op) && !IS_ITEMP(op)) #define POINTER_SET(ic) ( ic && ic->op == '=' \ - && IS_ITEMP(IC_RESULT(ic)) \ + && IS_ITEMP(IC_RESULT(ic)) \ && IC_RESULT(ic)->isaddr ) #define POINTER_GET(ic) ( ic && ic->op == GET_VALUE_AT_ADDRESS \ @@ -245,10 +246,10 @@ iCodeTable; && IC_LEFT(ic)->isaddr ) #define IS_ARITHMETIC_OP(x) (x && (x->op == '+' || \ - x->op == '-' || \ - x->op == '/' || \ - x->op == '*' || \ - x->op == '%')) + x->op == '-' || \ + x->op == '/' || \ + x->op == '*' || \ + x->op == '%')) #define IS_BITWISE_OP(x) (x && (x->op == BITWISEAND || \ x->op == '|' || \ x->op == '^')) @@ -256,25 +257,25 @@ iCodeTable; #define ASSIGNMENT(ic) ( ic && ic->op == '=') #define ASSIGN_SYM_TO_ITEMP(ic) (ic && ic->op == '=' && \ - IS_TRUE_SYMOP(IC_RIGHT(ic)) && \ + IS_TRUE_SYMOP(IC_RIGHT(ic)) && \ IS_ITEMP(IC_RESULT(ic))) #define ASSIGN_ITEMP_TO_SYM(ic) (ic && ic->op == '=' && \ - IS_TRUE_SYMOP(IC_RESULT(ic)) && \ + IS_TRUE_SYMOP(IC_RESULT(ic)) && \ IS_ITEMP(IC_RIGHT(ic))) #define ASSIGN_ITEMP_TO_ITEMP(ic) (ic && ic->op == '=' &&\ - !POINTER_SET(ic) &&\ - IS_ITEMP(IC_RIGHT(ic)) &&\ - IS_ITEMP(IC_RESULT(ic))) + !POINTER_SET(ic) &&\ + IS_ITEMP(IC_RIGHT(ic)) &&\ + IS_ITEMP(IC_RESULT(ic))) #define ADD_SUBTRACT_ITEMP(ic) (ic && (ic->op == '+' || ic->op == '-') && \ - IS_ITEMP(IC_RESULT(ic)) && \ - ( ( IS_ITEMP(IC_LEFT(ic)) ) || ( IS_SYMOP(IC_LEFT(ic)) ) ) && \ + IS_ITEMP(IC_RESULT(ic)) && \ + ( ( IS_ITEMP(IC_LEFT(ic)) ) || ( IS_SYMOP(IC_LEFT(ic)) ) ) && \ IS_OP_LITERAL(IC_RIGHT(ic))) #define ASSIGNMENT_TO_SELF(ic) (!POINTER_SET(ic) && !POINTER_GET(ic) && \ - ic->op == '=' && IC_RESULT(ic)->key == IC_RIGHT(ic)->key ) + ic->op == '=' && IC_RESULT(ic)->key == IC_RIGHT(ic)->key ) #define IS_CAST_ICODE(ic) (ic && ic->op == CAST) #define SET_ISADDR(op,v) {op = operandFromOperand(op); op->isaddr = v;} diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index c24d6d99..68992145 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -224,7 +224,7 @@ typedef struct sym_link unsigned intrtn:1; /* this is an interrupt routin */ unsigned rbank:1; /* seperate register bank */ unsigned intno; /* 1=Interrupt svc routine */ - unsigned regbank; /* register bank 2b used */ + short regbank; /* register bank 2b used */ unsigned builtin; /* is a builtin function */ unsigned javaNative; /* is a JavaNative Function (TININative ONLY) */ unsigned overlay; /* force parameters & locals into overlay segment */ diff --git a/src/avr/gen.c b/src/avr/gen.c index 5993a46c..08b68b1c 100644 --- a/src/avr/gen.c +++ b/src/avr/gen.c @@ -296,7 +296,7 @@ hasInc (operand *op, iCode *ic) return lic; } /* if the operand used or deffed */ - if (bitVectBitValue(OP_USES(op),lic->key) || ((unsigned) lic->defKey == op->key)) { + if (bitVectBitValue(OP_USES(op),lic->key) || (lic->defKey == op->key)) { return NULL; } lic = lic->next; @@ -1545,7 +1545,7 @@ static void genCall (iCode * ic) { - /* if send set is not empty the assign */ + /* if send set is not empty then assign */ if (_G.sendSet) { iCode *sic; int rnum = 16; diff --git a/src/ds390/gen.c b/src/ds390/gen.c index 8301d4c4..518e36cc 100644 --- a/src/ds390/gen.c +++ b/src/ds390/gen.c @@ -2638,7 +2638,7 @@ genCall (iCode * ic) if (!ic->regsSaved) saveRegisters (ic); - /* if send set is not empty the assign */ + /* if send set is not empty then assign */ /* We've saved all the registers we care about; * therefore, we may clobber any register not used * in the calling convention (i.e. anything not in @@ -6394,7 +6394,7 @@ hasInc (operand *op, iCode *ic, int osize) return lic; } /* if the operand used or deffed */ - if (bitVectBitValue(OP_USES(op),lic->key) || (unsigned) lic->defKey == op->key) { + if (bitVectBitValue(OP_USES(op),lic->key) || lic->defKey == op->key) { return NULL; } /* if GOTO or IFX */ diff --git a/src/hc08/gen.c b/src/hc08/gen.c index 3d2101b5..f799360b 100644 --- a/src/hc08/gen.c +++ b/src/hc08/gen.c @@ -651,7 +651,7 @@ loadRegFromAop (regs *reg, asmop *aop, int loffset) } forceload: - + switch (regidx) { case A_IDX: @@ -1123,7 +1123,7 @@ storeRegToFullAop (regs *reg, asmop *aop, bool isSigned) /*--------------------------------------------------------------------------*/ /* transferAopAop - Transfer the value at logical offset srcofs of asmop */ -/* srcaop to logical offset dstofs of asmop dstofs. */ +/* srcaop to logical offset dstofs of asmop dstaop. */ /*--------------------------------------------------------------------------*/ static void transferAopAop (asmop *srcaop, int srcofs, asmop *dstaop, int dstofs) @@ -1329,10 +1329,10 @@ rmwWithAop (char *rmwop, asmop *aop, int loffset) break; case AOP_EXT: needpula = pushRegIfUsed (hc08_reg_a); - loadRegFromAop (hc08_reg_a, aop, loffset); + loadRegFromAop (hc08_reg_a, aop, loffset); rmwWithReg (rmwop, hc08_reg_a); if (strcmp ("tst", rmwop)) - storeRegToAop (hc08_reg_a, aop, loffset); + storeRegToAop (hc08_reg_a, aop, loffset); pullOrFreeReg (hc08_reg_a, needpula); break; case AOP_DUMMY: @@ -2658,7 +2658,7 @@ static void genSend(set *sendSet) iCode *sic; for (sic = setFirstItem (sendSet); sic; - sic = setNextItem (sendSet)) { + sic = setNextItem (sendSet)) { int size, offset = 0; aopOp (IC_LEFT (sic), sic, FALSE); size = AOP_SIZE (IC_LEFT (sic)); @@ -2688,7 +2688,7 @@ genCall (iCode * ic) D(emitcode("; genCall","")); dtype = operandType (IC_LEFT (ic)); - /* if send set is not empty the assign */ + /* if send set is not empty then assign */ if (_G.sendSet) { if (IFFUNC_ISREENT(dtype)) { /* need to reverse the send set */ @@ -3218,7 +3218,7 @@ genPlusIncr (iCode * ic) bool needpulh; bool needpula; unsigned int size = getDataSize (IC_RESULT (ic)); - int offset; + unsigned int offset; symbol *tlbl = NULL; left = IC_LEFT (ic); @@ -4647,7 +4647,7 @@ hasInc (operand *op, iCode *ic,int osize) return lic; } /* if the operand used or deffed */ - if (bitVectBitValue(OP_USES(op),lic->key) || (unsigned) lic->defKey == op->key) { + if (bitVectBitValue(OP_USES(op),lic->key) || lic->defKey == op->key) { return NULL; } /* if GOTO or IFX */ diff --git a/src/hc08/ralloc.c b/src/hc08/ralloc.c index fdb71ba6..a4dc8526 100644 --- a/src/hc08/ralloc.c +++ b/src/hc08/ralloc.c @@ -1,6 +1,6 @@ /*------------------------------------------------------------------------ - SDCCralloc.c - source file for register allocation. (8051) specific + SDCCralloc.c - source file for register allocation. 68HC08 specific Written By - Sandeep Dutta . sandeep.dutta@usa.net (1998) @@ -655,7 +655,7 @@ spillThis (symbol * sym) if (!(sym->remat || sym->usl.spillLoc)) createStackSpil (sym); - /* mark it has spilt & put it in the spilt set */ + /* mark it as spilt & put it in the spilt set */ sym->isspilt = sym->spillA = 1; _G.spiltSet = bitVectSetBit (_G.spiltSet, sym->key); @@ -1414,7 +1414,7 @@ static void fillGaps() if (getenv("DISABLE_FILL_GAPS")) return; - /* look for livernages that was spilt by the allocator */ + /* look for liveranges that were spilt by the allocator */ for (sym = hTabFirstItem(liveRanges,&key) ; sym ; sym = hTabNextItem(liveRanges,&key)) { diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 83cadf84..a19a133b 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -137,8 +137,6 @@ emitcode (char *inst, const char *fmt,...) while (isspace (*lbp)) lbp++; - //printf ("%s\n", lb); - if (lbp && *lbp) lineCurr = (lineCurr ? connectLine (lineCurr, newLineNode (lb)) : @@ -181,8 +179,8 @@ mova (const char *x) static regs * getFreePtr (iCode * ic, asmop ** aopp, bool result) { - bool r0iu = FALSE, r1iu = FALSE; - bool r0ou = FALSE, r1ou = FALSE; + bool r0iu, r1iu; + bool r0ou, r1ou; /* the logic: if r0 & r1 used in the instruction then we are in trouble otherwise */ @@ -633,7 +631,7 @@ operandsEqu (operand * op1, operand * op2) { symbol *sym1, *sym2; - /* if they not symbols */ + /* if they're not symbols */ if (!IS_SYMOP (op1) || !IS_SYMOP (op2)) return FALSE; @@ -650,6 +648,7 @@ operandsEqu (operand * op1, operand * op2) if (sym1 == sym2) return TRUE; + /* if they have the same rname */ if (sym1->rname[0] && sym2->rname[0] && strcmp (sym1->rname, sym2->rname) == 0) return TRUE; @@ -2222,7 +2221,7 @@ genCall (iCode * ic) D(emitcode("; genCall","")); dtype = operandType (IC_LEFT (ic)); - /* if send set is not empty the assign */ + /* if send set is not empty then assign */ if (_G.sendSet) { if (IFFUNC_ISREENT(dtype)) { /* need to reverse the send set */ @@ -5226,7 +5225,7 @@ hasInc (operand *op, iCode *ic,int osize) return lic; } /* if the operand used or deffed */ - if (bitVectBitValue(OP_USES(op),lic->key) || (unsigned) lic->defKey == op->key) { + if (bitVectBitValue(OP_USES(op),lic->key) || lic->defKey == op->key) { return NULL; } /* if GOTO or IFX */ diff --git a/src/pic16/glue.c b/src/pic16/glue.c index 17767c4e..f78f83a3 100644 --- a/src/pic16/glue.c +++ b/src/pic16/glue.c @@ -640,7 +640,7 @@ static int pic16_printIvalChar (sym_link * type, initList * ilist, char *s, char ptype, void *p) { value *val; - int remain; + unsigned int remain; if(!p) return 0; diff --git a/src/pic16/ralloc.c b/src/pic16/ralloc.c index 4a026fcc..ffd938c2 100644 --- a/src/pic16/ralloc.c +++ b/src/pic16/ralloc.c @@ -401,7 +401,7 @@ regs* newReg(short type, short pc_type, int rIdx, char *name, int size, int alia /* regWithIdx - Search through a set of registers that matches idx */ /*-----------------------------------------------------------------*/ static regs * -regWithIdx (set *dRegs, int idx, int fixed) +regWithIdx (set *dRegs, int idx, unsigned fixed) { regs *dReg; diff --git a/src/xa51/gen.c b/src/xa51/gen.c index f30aed63..2eace679 100755 --- a/src/xa51/gen.c +++ b/src/xa51/gen.c @@ -1207,7 +1207,7 @@ static iCode *hasInc (operand *op, iCode *ic, int osize) { } } /* if the operand used or deffed */ - if (bitVectBitValue(OP_USES(op),lic->key) || (unsigned) lic->defKey == op->key) { + if (bitVectBitValue(OP_USES(op),lic->key) || lic->defKey == op->key) { return NULL; } /* if GOTO or IFX */ diff --git a/support/regression/tests/bug-868103.c b/support/regression/tests/bug-868103.c new file mode 100644 index 00000000..ed2c04e7 --- /dev/null +++ b/support/regression/tests/bug-868103.c @@ -0,0 +1,34 @@ +/** Bug 868103 tests. + + storage1: near, far, code, + storage2: near, far, +*/ + +#ifndef STORAGE1 +#define STORAGE1 {storage1} +#endif + +#ifndef STORAGE2 +#define STORAGE2 {storage2} +#endif + +#include + +#if defined(PORT_HOST) || defined(SDCC_z80) || defined(SDCC_gbz80) +# define near +# define far +# define code +#endif + +typedef struct { + STORAGE1 char * bar[2]; +} foo; + +STORAGE1 char c = 'x'; +STORAGE2 foo f; + +void bug868103(void) +{ + f.bar[1] = &c; + ASSERT(f.bar[1] == &c); +} -- 2.30.2