]> git.gag.com Git - fw/sdcc/commitdiff
a) fixed some aliasing problems
authorsandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 31 Jan 2000 04:17:23 +0000 (04:17 +0000)
committersandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Mon, 31 Jan 2000 04:17:23 +0000 (04:17 +0000)
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

12 files changed:
src/SDCC.lex
src/SDCCast.c
src/SDCCcse.c
src/SDCCmain.c
src/SDCCmem.c
src/SDCCpeeph.def
src/SDCCpeeph.rul
src/mcs51/gen.c
src/mcs51/main.c
src/mcs51/ralloc.c
src/port.h
src/z80/main.c

index 510981ad443219c2eb18a9f56ff926c4746134a6..001e00b26fad93d4590b6432b5dbbc29bedb6783 100644 (file)
@@ -33,13 +33,7 @@ IS       (u|U|l|L)*
 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
-#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  ;
 <asm>.         { *asmp++ = yytext[0]   ; }
 <asm>\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;
+}
index 781f8cbdf5ef2af8e9957c555cf3bbe1b614399c..e26c925e67c4d592466d36844aac1d217210349f 100644 (file)
@@ -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) ) 
index 209057f6b2f8c80df34acd707c3b3827e2cdd10f..d86d00b22f3bba9392b5f0f17291df4e55692091 100644 (file)
@@ -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;
index 3528c6e74f9e2d4bd36defea91bac67407014531..2d72e46bb85bd1b5eee4d996ebc5315a2caad4b9 100644 (file)
@@ -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++)
index e284d32dfa8c5aaded0c11b1258cd0c42f2c21e0..74ff1f7fd605136109b2c252308baefba937ef67 100644 (file)
@@ -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  */
index 75778704811a6a193a75c860a7dc53a3c18d22af..9ae5acff0c8f95a42bb041e278f0aecef6d737cc 100644 (file)
@@ -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
index b6127c7c81ea18649c0d66ce45c1d39c16a83584..8ab8f6134c1985d809ef7731154e8ece1551238b 100644 (file)
 "        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"
 "}\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"
 "} 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"
 "} 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"
index 148c988e412ba72d34c1cda9911f9c64d0b03b3e..47758e7093341de3988b0f64070803b820be764b 100644 (file)
@@ -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");
index bd0716fe8e182ae01ac8914b4ee35ac00105ec60..843bb0ff7998b2e666222eeeb60c3e2d04328270 100644 (file)
@@ -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
+
 };
index 8cd4764beeb9a4c12dc7ab8bdf9aefadcbbf22e2..54e64a4dede18fddcd16fb8ace1aede448b5a542 100644 (file)
@@ -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 */
index 11ff318d0a309355442995592b6395978498dcc3..1630fdb2b419dbaf82b2a5fe74df5e8ae8fba923 100644 (file)
@@ -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;
index bfc1c9fdb5e038c2999c6e774ca2c8bc73b0f193..a5e4697fe14f46029bc78d04c11580e51f4d3e1f 100644 (file)
@@ -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
 };