From: sandeep Date: Mon, 31 Jan 2000 04:17:23 +0000 (+0000) Subject: a) fixed some aliasing problems X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=f22d71b2e50aa54d681a0532b60a54f525c8ebb5;p=fw%2Fsdcc a) fixed some aliasing problems b) Made language extension keywords e.g 'data'... target specific git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@41 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/SDCC.lex b/src/SDCC.lex index 510981ad..001e00b2 100644 --- a/src/SDCC.lex +++ b/src/SDCC.lex @@ -33,13 +33,7 @@ IS (u|U|l|L)* #include #include #include -#include "SDCCglobl.h" -#include "SDCCsymt.h" -#include "SDCCval.h" -#include "SDCCast.h" -#include "SDCCy.h" -#include "SDCChasht.h" -#include "SDCCmem.h" +#include "common.h" char *stringLiteral(); char *currFname; @@ -57,10 +51,12 @@ int yywrap YY_PROTO((void)) { return(1); } - +#define TKEYWORD(token) return (isTargetKeyword(yytext) ? token :\ + check_type(yytext)) char asmbuff[MAX_INLINEASM] ; char *asmp ; -extern int check_type ( ); +extern int check_type (); + extern int isTargetKeyword (); extern int checkCurrFile (char *); extern int processPragma (char *); extern int printListing (int ); @@ -94,39 +90,39 @@ struct options save_options ; . { *asmp++ = yytext[0] ; } \n { count(); *asmp++ = '\n' ;} "/*" { comment(); } -"at" { count(); return(AT) ; } -"auto" { count(); return(AUTO); } -"bit" { count(); return(BIT) ; } -"break" { count(); return(BREAK); } -"case" { count(); return(CASE); } +"at" { count(); TKEYWORD(AT) ; } +"auto" { count(); return(AUTO); } +"bit" { count(); TKEYWORD(BIT) ; } +"break" { count(); return(BREAK); } +"case" { count(); return(CASE); } "char" { count(); return(CHAR); } -"code" { count(); return(CODE); } +"code" { count(); TKEYWORD(CODE); } "const" { count(); return(CONST); } "continue" { count(); return(CONTINUE); } -"critical" { count(); return(CRITICAL); } -"data" { count(); return(DATA); } +"critical" { count(); TKEYWORD(CRITICAL); } +"data" { count(); TKEYWORD(DATA); } "default" { count(); return(DEFAULT); } "do" { count(); return(DO); } "double" { count(); werror(W_DOUBLE_UNSUPPORTED);return(FLOAT); } "else" { count(); return(ELSE); } "enum" { count(); return(ENUM); } "extern" { count(); return(EXTERN); } -"far" { count(); return(XDATA); } +"far" { count(); TKEYWORD(XDATA); } "float" { count(); return(FLOAT); } "for" { count(); return(FOR); } "goto" { count(); return(GOTO); } -"idata" { count(); return(IDATA);} +"idata" { count(); TKEYWORD(IDATA);} "if" { count(); return(IF); } "int" { count(); return(INT); } "interrupt" { count(); return(INTERRUPT);} "long" { count(); return(LONG); } -"near" { count(); return(DATA);} +"near" { count(); TKEYWORD(DATA);} "pdata" { count(); return(PDATA); } -"reentrant" { count(); return(REENTRANT);} +"reentrant" { count(); TKEYWORD(REENTRANT);} "register" { count(); return(REGISTER); } "return" { count(); return(RETURN); } -"sfr" { count(); return(SFR) ; } -"sbit" { count(); return(SBIT) ; } +"sfr" { count(); TKEYWORD(SFR) ; } +"sbit" { count(); TKEYWORD(SBIT) ; } "short" { count(); return(SHORT); } "signed" { count(); return(SIGNED); } "sizeof" { count(); return(SIZEOF); } @@ -138,17 +134,17 @@ struct options save_options ; "unsigned" { count(); return(UNSIGNED); } "void" { count(); return(VOID); } "volatile" { count(); return(VOLATILE); } -"using" { count(); return(USING); } +"using" { count(); TKEYWORD(USING); } "while" { count(); return(WHILE); } -"xdata" { count(); return(XDATA); } -"_data" { count(); return(_NEAR); } -"_code" { count(); return(_CODE); } -"_generic" { count(); return(_GENERIC); } -"_near" { count(); return(_NEAR); } -"_xdata" { count(); return(_XDATA);} -"_pdata" { count () ; return(_PDATA); } -"_idata" { count () ; return(_IDATA); } -"..." { count(); return(VAR_ARGS);} +"xdata" { count(); TKEYWORD(XDATA); } +"_data" { count(); TKEYWORD(_NEAR); } +"_code" { count(); TKEYWORD(_CODE); } +"_generic" { count(); TKEYWORD(_GENERIC); } +"_near" { count(); TKEYWORD(_NEAR); } +"_xdata" { count(); TKEYWORD(_XDATA);} +"_pdata" { count(); TKEYWORD(_PDATA); } +"_idata" { count(); TKEYWORD(_IDATA); } +"..." { count(); return(VAR_ARGS);} {L}({L}|{D})* { count(); return(check_type()); } 0[xX]{H}+{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); } 0{D}+{IS}? { count(); yylval.val = constVal(yytext); return(CONSTANT); } @@ -180,8 +176,8 @@ struct options save_options ; "==" { count(); return(EQ_OP); } "!=" { count(); return(NE_OP); } ";" { count(); return(';'); } -"{" { count() ; NestLevel++ ; return('{'); } -"}" { count(); NestLevel--; return('}'); } +"{" { count(); NestLevel++ ; return('{'); } +"}" { count(); NestLevel--; return('}'); } "," { count(); return(','); } ":" { count(); return(':'); } "=" { count(); return('='); } @@ -497,3 +493,19 @@ int process_pragma(char *s) werror(W_UNKNOWN_PRAGMA,cp); return 0; } + +/* will return 1 if the string is a part + of a target specific keyword */ +int isTargetKeyword(char *s) +{ + int i; + + if (port->keywords == NULL) + return 0; + for ( i = 0 ; port->keywords[i] ; i++ ) { + if (strcmp(port->keywords[i],s) == 0) + return 1; + } + + return 0; +} diff --git a/src/SDCCast.c b/src/SDCCast.c index 781f8cbd..e26c925e 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -2773,7 +2773,7 @@ ast *backPatchLabels (ast *tree, symbol *trueLabel, symbol *falseLabel ) /* change not */ if (IS_NOT(tree)) { - tree->left = backPatchLabels (tree->left,trueLabel,falseLabel); + tree->left = backPatchLabels (tree->left,falseLabel,trueLabel); /* if the left is already a IFX */ if ( ! IS_IFX(tree->left) ) diff --git a/src/SDCCcse.c b/src/SDCCcse.c index 209057f6..d86d00b2 100644 --- a/src/SDCCcse.c +++ b/src/SDCCcse.c @@ -1146,7 +1146,8 @@ int cseBBlock ( eBBlock *ebb, int computeOnly, 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); + applyToSet(ebb->succList,delGetPointerSucc, + IC_LEFT(ic),ebb->dfnum); } continue; } @@ -1167,6 +1168,16 @@ int cseBBlock ( eBBlock *ebb, int computeOnly, algebraicOpts (ic); 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)); + } + if (POINTER_SET(ic) && !IS_PTR(operandType(IC_RESULT(ic)))) { + setOperandType(IC_RESULT(ic), + aggrToPtr(operandType(IC_RESULT(ic)),FALSE)); + } + /* if this is a condition statment then */ /* check if the condition can be replaced */ if (ic->op == IFX ) { @@ -1212,7 +1223,8 @@ int cseBBlock ( eBBlock *ebb, int computeOnly, for the same pointer visible if yes then change this into an assignment */ pdop = NULL; - if (applyToSetFTrue(cseSet,findPointerSet,IC_LEFT(ic),&pdop)){ + if (applyToSetFTrue(cseSet,findPointerSet,IC_LEFT(ic),&pdop) && + !bitVectBitValue(ebb->ptrsSet,pdop->key)){ ic->op = '='; IC_LEFT(ic) = NULL; IC_RIGHT(ic) = pdop; diff --git a/src/SDCCmain.c b/src/SDCCmain.c index 3528c6e7..2d72e46b 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -1017,10 +1017,7 @@ static void assemble (char **envp) asmArgs[0] = port->assembler.exec_name; -/* if (options.debug) */ asmArgs[1] = port->assembler.debug_opts; -/* else */ -/* asmArgs[1] = port->assembler.plain_opts; */ /* add the extra options if any */ for (; asmOptions[i-2] ; i++) diff --git a/src/SDCCmem.c b/src/SDCCmem.c index e284d32d..74ff1f7f 100644 --- a/src/SDCCmem.c +++ b/src/SDCCmem.c @@ -30,7 +30,7 @@ int maxRegBank = 0; int fatalError = 0 ;/* fatal error flag */ /*-----------------------------------------------------------------*/ -/* allocMap - allocates a memory map */ +/* allocMap - allocates a memory map */ /*-----------------------------------------------------------------*/ memmap *allocMap (char rspace, /* sfr space */ char farmap, /* far or near segment */ diff --git a/src/SDCCpeeph.def b/src/SDCCpeeph.def index 75778704..9ae5acff 100644 --- a/src/SDCCpeeph.def +++ b/src/SDCCpeeph.def @@ -217,11 +217,21 @@ replace { ljmp %5 %2: } by { - ; Peephole 112 removed ljmp by inverse jump logic + ; Peephole 112 removed ljmp by inverse jump logic jb %1,%5 %2: } if labelInRange +replace { + ljmp %5 +%1: +} by { + ; Peephole 132 changed ljmp to sjmp + sjmp %5 +%1: +} if labelInRange + + replace { clr a cjne %1,%2,%3 @@ -490,15 +500,6 @@ replace { mov %2,%1 } -replace { - ljmp %5 -%1: -} by { - ; Peephole 132 changed ljmp to sjmp - sjmp %5 -%1: -} if labelInRange - replace { mov r%1,%2 mov ar%3,@r%1 @@ -845,7 +846,8 @@ replace { } by { ; Peephole 164 removed sjmp by inverse jump logic jb %3,%2 -%1:} +%1: +} replace { jb %3,%1 @@ -854,7 +856,8 @@ replace { } by { ; Peephole 165 removed sjmp by inverse jump logic jnb %3,%2 -%1:} +%1: +} replace { mov %1,%2 @@ -1623,4 +1626,4 @@ replace { mov @r%1,a inc r%1 mov @r%1,a -} +} \ No newline at end of file diff --git a/src/SDCCpeeph.rul b/src/SDCCpeeph.rul index b6127c7c..8ab8f613 100644 --- a/src/SDCCpeeph.rul +++ b/src/SDCCpeeph.rul @@ -200,12 +200,22 @@ " ljmp %5\n" "%2:\n" "} by {\n" -" ; Peephole 112 removed ljmp by inverse jump logic\n" +" ; Peephole 112 removed ljmp by inverse jump logic\n" " jb %1,%5\n" "%2:\n" "} if labelInRange\n" "\n" "replace {\n" +" ljmp %5\n" +"%1:\n" +"} by {\n" +" ; Peephole 132 changed ljmp to sjmp\n" +" sjmp %5\n" +"%1:\n" +"} if labelInRange\n" +"\n" +"\n" +"replace {\n" " clr a\n" " cjne %1,%2,%3\n" " cpl a\n" @@ -474,15 +484,6 @@ "}\n" "\n" "replace {\n" -" ljmp %5\n" -"%1:\n" -"} by {\n" -" ; Peephole 132 changed ljmp to sjmp\n" -" sjmp %5\n" -"%1:\n" -"} if labelInRange\n" -"\n" -"replace {\n" " mov r%1,%2\n" " mov ar%3,@r%1\n" " inc r%3\n" @@ -828,7 +829,8 @@ "} by {\n" " ; Peephole 164 removed sjmp by inverse jump logic\n" " jb %3,%2\n" -"%1:}\n" +"%1:\n" +"}\n" "\n" "replace {\n" " jb %3,%1\n" @@ -837,7 +839,8 @@ "} by {\n" " ; Peephole 165 removed sjmp by inverse jump logic\n" " jnb %3,%2\n" -"%1:}\n" +"%1:\n" +"}\n" "\n" "replace {\n" " mov %1,%2\n" diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 148c988e..47758e70 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -4161,12 +4161,13 @@ static void genXor (iCode *ic, iCode *ifx) // c = bit ^ val // if val>>1 != 0, result = 1 emitcode("setb","c"); - while(sizer--){ + while(sizer){ MOVA(aopGet(AOP(right),sizer-1,FALSE,FALSE)); if(sizer == 1) // test the msb of the lsb emitcode("anl","a,#0xfe"); emitcode("jnz","%05d$",tlbl->key+100); + sizer--; } // val = (0,1) emitcode("rrc","a"); diff --git a/src/mcs51/main.c b/src/mcs51/main.c index bd0716fe..843bb0ff 100644 --- a/src/mcs51/main.c +++ b/src/mcs51/main.c @@ -8,6 +8,33 @@ #include "main.h" #include "ralloc.h" +/* list of key words used by msc51 */ +static char *_mcs51_keywords[] = { + "at", + "bit", + "code", + "critical", + "data", + "far", + "idata", + "interrupt", + "near", + "pdata", + "reentrant", + "sfr", + "sbit", + "using", + "xdata", + "_data", + "_code", + "_generic", + "_near", + "_xdata", + "_pdata", + "_idata", + NULL +}; + void mcs51_assignRegisters (eBBlock **ebbs, int count); @@ -71,5 +98,7 @@ PORT mcs51_port = { _mcs51_finaliseOptions, _mcs51_setDefaultOptions, mcs51_assignRegisters, - _mcs51_getRegName + _mcs51_getRegName , + _mcs51_keywords + }; diff --git a/src/mcs51/ralloc.c b/src/mcs51/ralloc.c index 8cd4764b..54e64a4d 100644 --- a/src/mcs51/ralloc.c +++ b/src/mcs51/ralloc.c @@ -1802,7 +1802,7 @@ static iCode *packRegsForOneuse (iCode *ic, operand *op , eBBlock *ebp) operation is a '*','/' or '%' then 'b' may cause a problem */ if (( dic->op == '%' || dic->op == '/' || dic->op == '*') && - getSize(aggrToPtr(operandType(op),FALSE)) >= 3) + getSize(operandType(op)) >= 3) return NULL; /* if left or right or result is in far space */ diff --git a/src/port.h b/src/port.h index 11ff318d..1630fdb2 100644 --- a/src/port.h +++ b/src/port.h @@ -9,8 +9,11 @@ typedef struct { /** Target name used for -m */ const char *target; + /** Target name string, used for --help */ const char *target_name; + + /* assembler related information */ struct { /** Command to run (eg as-z80) */ const char *exec_name; @@ -21,10 +24,13 @@ typedef struct { /** TRUE if the output file name should be pre-pended to the args */ bool requires_output_name; } assembler; + + /* linker related info */ struct { /** Command to run (eg link-z80) */ const char *exec_name; } linker; + /** Basic type sizes */ struct { int char_size; @@ -38,6 +44,7 @@ typedef struct { int float_size; int max_base_size; } s; + /** Names for all the memory regions */ struct { const char *xstack_name; @@ -51,6 +58,8 @@ typedef struct { const char *static_name; const char *overlay_name; } mem; + + /* stack related information */ struct { /** -1 for grows down (z80), +1 for grows up (mcs51) */ int direction; @@ -65,10 +74,12 @@ typedef struct { } stack; struct { - /** One more than the smallest mul/div operation the processor can do nativley + /** One more than the smallest + mul/div operation the processor can do nativley Eg if the processor has an 8 bit mul, nativebelow is 2 */ int nativebelow; } muldiv; + /** Parses one option + its arguments */ bool (*parseOption)(int *pargc, char **argv); /** Called after all the options have been parsed. */ @@ -78,9 +89,14 @@ typedef struct { void (*setDefaultOptions)(void); /** Does the dirty work. */ void (*assignRegisters)(eBBlock **, int); + /** Returns the register name of a symbol. Used so that 'regs' can be an incomplete type. */ const char *(*getRegName)(struct regs *reg); + + /* list of keywords that are used by this + target (used by lexer) */ + char **keywords; } PORT; extern PORT *port; diff --git a/src/z80/main.c b/src/z80/main.c index bfc1c9fd..a5e4697f 100644 --- a/src/z80/main.c +++ b/src/z80/main.c @@ -1,6 +1,8 @@ #include "common.h" #include "ralloc.h" +static char *_z80_keywords[] = { NULL }; + void z80_assignRegisters (eBBlock **ebbs, int count); static bool _z80_parseOptions(int *pargc, char **argv) @@ -78,6 +80,7 @@ PORT z80_port = { _z80_finaliseOptions, _z80_setDefaultOptions, z80_assignRegisters, - _z80_getRegName + _z80_getRegName, + _z80_keywords };