From 0c962e837aab877dc902826938592498ce76f918 Mon Sep 17 00:00:00 2001 From: sandeep Date: Sat, 11 Mar 2000 23:40:13 +0000 Subject: [PATCH] Some code cleanup & fixed problem of used bdefore definitions inside loops git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@185 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCC.y | 2 + src/SDCCicode.c | 8 +++ src/SDCClrange.c | 139 +++++++++++++++++++++++++++++---------------- src/SDCCmain.c | 4 +- src/SDCCsymt.c | 8 +++ src/SDCCsymt.h | 1 + src/avr/main.c | 110 ++++++++++------------------------- src/mcs51/gen.c | 19 ------- src/mcs51/ralloc.c | 2 +- 9 files changed, 143 insertions(+), 150 deletions(-) diff --git a/src/SDCC.y b/src/SDCC.y index ed7e2a2a..66140dcc 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -922,6 +922,8 @@ pointer case S_EEPROM: DCL_TYPE($3) = EEPPOINTER; break; + default: + werror(W_PTR_TYPE_INVALID); } } else diff --git a/src/SDCCicode.c b/src/SDCCicode.c index c09a183f..2a6faf96 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -1991,6 +1991,14 @@ void setOClass (link *ptr, link *spec) case PPOINTER: SPEC_OCLS(spec) = xstack; break; + + case EEPPOINTER: + SPEC_OCLS(spec) = eeprom; + break; + + default: + break; + } } diff --git a/src/SDCClrange.c b/src/SDCClrange.c index eea9a075..7c71b130 100644 --- a/src/SDCClrange.c +++ b/src/SDCClrange.c @@ -24,6 +24,7 @@ -------------------------------------------------------------------------*/ #include "common.h" +#include "limits.h" int iCodeSeq = 0 ; hTab *liveRanges = NULL; @@ -185,6 +186,85 @@ void setToRange (operand *op,int to, bool check) OP_LIVETO(op) = to; } +/*-----------------------------------------------------------------*/ +/* firstDeOf - finds the first definition in seq for op */ +/*-----------------------------------------------------------------*/ +static iCode *firstDefOf (operand *op) +{ + int i; + iCode *ric=NULL,*lic=NULL; + int fSeq = INT_MAX; + + if (!OP_DEFS(op)) + return NULL; + + for (i=0; i < OP_DEFS(op)->size ;i++) { + if (bitVectBitValue(OP_DEFS(op),i) && + (lic = hTabItemWithKey(iCodehTab,i)) && + lic->seq < fSeq) { + + fSeq = lic->seq ; + ric = lic; + } + } + return ric; +} +/*-----------------------------------------------------------------*/ +/* useDefLoopCheck - check for uses before init inside loops */ +/*-----------------------------------------------------------------*/ +static void useDefLoopCheck(operand *op,iCode *ic) +{ + /* this is for situations like the following + int a,b; + + while (...) { + a = ... ; + ... + _some_usage_of_b_; + ... + b = ... ; + } + in this case the definition of 'b' will flow to the usages + but register allocator cannot handle these situations.so + will mark as spilt */ + + int i =0, fdSeq ; + int er=0; + iCode *tic ; + + /* get the first definition */ + if (!(tic = firstDefOf(op))) + return ; + + fdSeq = tic->seq; + /* now go thru the usages & make sure they follow + the first definition */ + for (i=0; i <= OP_USES(op)->size;i++ ) { + if (bitVectBitValue(OP_USES(op),i) && + (tic = hTabItemWithKey(iCodehTab,i)) && + tic->seq < fdSeq){ + er = 1; + break; + } + } + + /* found a usage without definition */ + if (er) { + if (OP_SYMBOL(op)->isreqv && SPIL_LOC(op) ) { + + werror(W_LOCAL_NOINIT, + SPIL_LOC(op)->name, + ic->filename,ic->lineno); + } else { + + werror(W_LOCAL_NOINIT, + OP_SYMBOL(op)->name, + ic->filename,ic->lineno); + } + OP_SYMBOL(op)->isspilt = 1; + } +} + /*-----------------------------------------------------------------*/ /* operandLUse - check and set the last use for a given operand */ @@ -213,10 +293,12 @@ operand *operandLUse (operand *op, eBBlock **ebbs, } ic->uses = bitVectSetBit(ic->uses,op->key); + if (!OP_SYMBOL(op)->udChked) { link *type = operandType(op); link *etype = getSpec(type); - + + OP_SYMBOL(op)->udChked = 1; /* good place to check if unintialised */ if ((IS_TRUE_SYMOP(op) || OP_SYMBOL(op)->isreqv) && OP_SYMBOL(op)->islocal && @@ -240,56 +322,18 @@ operand *operandLUse (operand *op, eBBlock **ebbs, OP_SYMBOL(op)->name, ic->filename,ic->lineno); } - } - } + } else { + if (ebp->depth && op->usesDefs && + !OP_SYMBOL(op)->_isparm) { + /* check non-inits inside loops */ + useDefLoopCheck(op,ic); + } + } + } } return op; } -/*-----------------------------------------------------------------*/ -/* compLastUse - computes the last usage with certainty */ -/*-----------------------------------------------------------------*/ -void compLastUse () -{ - symbol *sym; - int key; - /* the strategy here is to look for live ranges that are not - induction variables, and find out the usage icode with the - highest sequence number then set the to range to that icode - sequence */ - /* once fully tested we can use only this routine to mark the - to range that will reduce a lot of computations in the - markLiveRanges routine */ - for (sym = hTabFirstItem(liveRanges,&key) ; sym; - sym = hTabNextItem(liveRanges,&key)) { - - int i ; - int maxKey = 0 ; - - if (sym->isind) - continue ; - - if (!sym->uses) - continue ; - - /* go thru all the usages of this live range and find out - the maximum sequence number of the icode that used it */ - for (i = 0 ; i < sym->uses->size ; i++ ) { - iCode *uic ; - - if (!bitVectBitValue(sym->uses,i)) - continue ; - - if ((uic = hTabItemWithKey(iCodehTab,i))) - maxKey = ( uic->seq > maxKey ? uic->seq : maxKey ); - } - - /* got it */ - if (maxKey) - sym->liveTo = maxKey; - } -} - /*-----------------------------------------------------------------*/ /* killAllAlive - mark all the definitions living with this seq */ /*-----------------------------------------------------------------*/ @@ -499,7 +543,6 @@ void computeLiveRanges (eBBlock **ebbs, int count ) for ( i = 0 ; i < count; i++ ) markLiveRanges (ebbs[i],ebbs,count); -/* compLastUse(); */ /* mark the ranges live for each point */ rlivePoint (ebbs,count); } diff --git a/src/SDCCmain.c b/src/SDCCmain.c index 1324cb44..71419921 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -1310,7 +1310,9 @@ int main ( int argc, char **argv , char **envp) glue(); if (!options.c1mode) assemble(envp); - } + } else { + exit(-1); + } } diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index 3f93c923..0ee70628 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -1625,6 +1625,9 @@ void printTypeChain (link *type, FILE *of) case V_BIT: fprintf(of,"bit {%d,%d}",SPEC_BSTR(type),SPEC_BLEN(type)); break; + + default: + break; } } type = type->next; @@ -1669,6 +1672,8 @@ void cdbTypeInfo (link *type,FILE *of) case ARRAY : fprintf (of,"DA%d,",DCL_ELEM(type)); break; + default: + break; } } else { switch (SPEC_NOUN(type)) { @@ -1705,6 +1710,9 @@ void cdbTypeInfo (link *type,FILE *of) case V_BIT: fprintf(of,"SB%d$%d",SPEC_BSTR(type),SPEC_BLEN(type)); break; + + default: + break; } fputs(":",of); if (SPEC_USIGN(type)) diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index 391bf503..f97f554b 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -183,6 +183,7 @@ typedef struct symbol { unsigned isreqv :1 ; /* is the register quivalent of a symbol */ unsigned hasFcall :1 ; /* for functions does it call other functions */ unsigned calleeSave :1 ; /* for functions uses callee save paradigm */ + unsigned udChked :1 ; /* use def checking has been already done */ /* following flags are used by the backend for code generation and can be changed diff --git a/src/avr/main.c b/src/avr/main.c index e7b3f412..5006545c 100644 --- a/src/avr/main.c +++ b/src/avr/main.c @@ -1,7 +1,7 @@ /** @file main.c - mcs51 specific general functions. + avr specific general functions. - Note that mlh prepended _mcs51_ on the static functions. Makes + Note that mlh prepended _avr_ on the static functions. Makes it easier to set a breakpoint using the debugger. */ #include "common.h" @@ -15,36 +15,26 @@ static char _defaultRules[] = }; /* list of key words used by msc51 */ -static char *_mcs51_keywords[] = { +static char *_avr_keywords[] = { "at", - "bit", "code", "critical", - "data", - "far", - "idata", + "eeprom" "interrupt", - "near", - "pdata", - "reentrant", "sfr", "sbit", - "using", "xdata", - "_data", "_code", + "_eeprom" "_generic", - "_near", "_xdata", - "_pdata", - "_idata", NULL }; -void mcs51_assignRegisters (eBBlock **ebbs, int count); +void avr_assignRegisters (eBBlock **ebbs, int count); -static bool _mcs51_parseOptions(int *pargc, char **argv, int *i) +static bool _avr_parseOptions(int *pargc, char **argv, int *i) { /* TODO: allow port-specific command line options to specify * segment names here. @@ -52,75 +42,31 @@ static bool _mcs51_parseOptions(int *pargc, char **argv, int *i) return FALSE; } -static void _mcs51_finaliseOptions(void) +static void _avr_finaliseOptions(void) { - /* Hack-o-matic: if we are using the flat24 model, - * adjust pointer sizes. - */ - if (options.model == MODEL_FLAT24) - { - port->s.fptr_size = 3; - port->s.gptr_size = 4; - port->stack.isr_overhead++; /* Will save dpx on ISR entry. */ - #if 1 - port->stack.call_overhead++; /* This acounts for the extra byte - * of return addres on the stack. - * but is ugly. There must be a - * better way. - */ - #endif - fReturn = fReturn390; - fReturnSize = 5; - } + port->default_local_map = + port->default_globl_map = xdata; } -static void _mcs51_setDefaultOptions(void) +static void _avr_setDefaultOptions(void) { } -static const char *_mcs51_getRegName(struct regs *reg) +static const char *_avr_getRegName(struct regs *reg) { if (reg) return reg->name; return "err"; } -static void _mcs51_genAssemblerPreamble(FILE *of) +static void _avr_genAssemblerPreamble(FILE *of) { - if (options.model == MODEL_FLAT24) - { - fputs(".flat24 on\t\t; 24 bit flat addressing\n", of); - fputs("dpx = 0x93\t\t; dpx register unknown to assembler\n", of); - } } /* Generate interrupt vector table. */ -static int _mcs51_genIVT(FILE *of, symbol **interrupts, int maxInterrupts) +static int _avr_genIVT(FILE *of, symbol **interrupts, int maxInterrupts) { - int i; - - if (options.model != MODEL_FLAT24) - { - /* Let the default code handle it. */ - return FALSE; - } - - fprintf (of, "\tajmp\t__sdcc_gsinit_startup\n"); - - /* now for the other interrupts */ - for (i = 0; i < maxInterrupts; i++) - { - if (interrupts[i]) - { - fprintf(of, "\tljmp\t%s\n\t.ds\t4\n", interrupts[i]->rname); - } - else - { - fprintf(of, "\treti\n\t.ds\t7\n"); - } - } - return TRUE; } @@ -139,9 +85,9 @@ static const char *_asmCmd[] = { }; /* Globals */ -PORT mcs51_port = { - "mcs51", - "MCU 8051", /* Target name */ +PORT avr_port = { + "avr", + "ATMEL AVR", /* Target name */ { TRUE, /* Emit glue around main */ }, @@ -171,23 +117,25 @@ PORT mcs51_port = { "RSEG (DATA)", "GSINIT (CODE)", "OSEG (OVR,DATA)", - "GSFINAL (CODE)" + "GSFINAL (CODE)", + NULL, + NULL, }, { +1, 1, 4, 1, 1 }, - /* mcs51 has an 8 bit mul */ + /* avr has an 8 bit mul */ { 1 }, NULL, - _mcs51_parseOptions, - _mcs51_finaliseOptions, - _mcs51_setDefaultOptions, - mcs51_assignRegisters, - _mcs51_getRegName , - _mcs51_keywords, - _mcs51_genAssemblerPreamble, - _mcs51_genIVT + _avr_parseOptions, + _avr_finaliseOptions, + _avr_setDefaultOptions, + avr_assignRegisters, + _avr_getRegName , + _avr_keywords, + _avr_genAssemblerPreamble, + _avr_genIVT }; diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 770fc084..5e30e412 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -251,25 +251,9 @@ static void genSetDPTR(int n) /*-----------------------------------------------------------------*/ static int pointerCode (link *etype) { - int p_type; return PTR_TYPE(SPEC_OCLS(etype)); -/* if (SPEC_OCLS(etype)->codesp ) { */ -/* p_type = CPOINTER ; */ -/* } */ -/* else */ -/* if (SPEC_OCLS(etype)->fmap && !SPEC_OCLS(etype)->paged) */ -/* p_type = FPOINTER ; */ -/* else */ -/* if (SPEC_OCLS(etype)->fmap && SPEC_OCLS(etype)->paged) */ -/* p_type = PPOINTER; */ -/* else */ -/* if (SPEC_OCLS(etype) == idata ) */ -/* p_type = IPOINTER; */ -/* else */ -/* p_type = POINTER ; */ -/* return p_type; */ } /*-----------------------------------------------------------------*/ @@ -2284,7 +2268,6 @@ static void genEndFunction (iCode *ic) } /* if debug then send end of function */ -/* if (options.debug && currFunc) { */ if (currFunc) { _G.debugLine = 1; emitcode("","C$%s$%d$%d$%d ==.", @@ -2398,8 +2381,6 @@ static int findLabelBackwards(iCode *ic, int key) } } - /* printf("findLabelBackwards: not found.\n"); */ - return 0; } diff --git a/src/mcs51/ralloc.c b/src/mcs51/ralloc.c index b2dff194..1170717b 100644 --- a/src/mcs51/ralloc.c +++ b/src/mcs51/ralloc.c @@ -1139,7 +1139,7 @@ static bitVect *rUmaskForOp (operand *op) rumask = newBitVect(mcs51_nRegs); - for (j = 0; j < sym->nRegs; j++) { + for (j = 0; j < sym->nRegs; j++) { rumask = bitVectSetBit(rumask, sym->regs[j]->rIdx); } -- 2.30.2