Merge of the izt changes.
authormichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 28 Jan 2001 20:07:04 +0000 (20:07 +0000)
committermichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 28 Jan 2001 20:07:04 +0000 (20:07 +0000)
Added validation of the port structures at run time.
Tidied up the asm emitter.  Less hacks, works on PPC.

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@543 4a8a32a2-be11-0410-ad9d-d568d2c75423

17 files changed:
src/Makefile.in
src/SDCChasht.c
src/SDCCicode.h
src/SDCCmain.c
src/SDCCmem.c
src/asm.c
src/avr/main.c
src/ds390/Makefile
src/ds390/main.c
src/izt/gen.c
src/izt/i186.c
src/izt/ralloc.c
src/izt/tlcs900h.c
src/mcs51/main.c
src/pic/main.c
src/port.h
src/z80/main.c

index 96c6f49784eb81b9d5459a243d44a6fa5ef26ce2..c4a1a0265ffb5514d00de081e7fe9b187a814486 100644 (file)
@@ -8,7 +8,7 @@ include $(PRJDIR)/Makefile.common
 
 USE_ALT_LEX    = 0
 
-PORTS          = mcs51 z80 avr ds390 pic
+PORTS          = mcs51 z80 avr ds390 pic izt
 PORT_LIBS      = $(PORTS:%=%/port.a)
 
 ifeq ($(DISABLE_GC),1)
index ce646461d6056b112c5f6c2de06ea5dab5bd9330..d083faa3b2460551a83f63161f8382cd51e6c31d 100644 (file)
@@ -223,13 +223,16 @@ static const hashtItem *_findByKey(hTab *htab, int key, const void *pkey, int (*
     if (!htab)
        return NULL;
     
-    for (htip = htab->table[key] ; htip ; htip = htip->next ) {
+    for (htip = htab->table[key] ; htip ; htip = htip->next) {
        /* if a compare function is given use it */
-       if (compare && compare(pkey, htip->pkey))
+       if (compare && compare(pkey, htip->pkey)) {
            break;
-       else
-           if (pkey == htip->pkey)
+       }
+       else {
+           if (pkey == htip->pkey) {
                break;
+           }
+       }
     }
     return htip;
 }
index 62ea5b41bdaa7643e823585f4fbee8a67d410277..c22e63d1c128458f82ba9580b7a55b3615d822d0 100644 (file)
@@ -94,17 +94,17 @@ typedef struct operand {
 } operand ;
 
 /* definition for intermediate code */ 
-#define IC_RESULT(x) x->ulrrcnd.lrr.result
-#define IC_LEFT(x)   x->ulrrcnd.lrr.left
-#define IC_RIGHT(x)  x->ulrrcnd.lrr.right
-#define IC_COND(x)   x->ulrrcnd.cnd.condition
-#define IC_TRUE(x)   x->ulrrcnd.cnd.trueLabel
-#define IC_FALSE(x)  x->ulrrcnd.cnd.falseLabel
-#define IC_LABEL(x)  x->argLabel.label
-#define IC_ARGS(x)   x->argLabel.args
-#define IC_JTCOND(x) x->ulrrcnd.jmpTab.condition
-#define IC_JTLABELS(x) x->ulrrcnd.jmpTab.labels
-#define IC_INLINE(x) x->inlineAsm
+#define IC_RESULT(x) (x)->ulrrcnd.lrr.result
+#define IC_LEFT(x)   (x)->ulrrcnd.lrr.left
+#define IC_RIGHT(x)  (x)->ulrrcnd.lrr.right
+#define IC_COND(x)   (x)->ulrrcnd.cnd.condition
+#define IC_TRUE(x)   (x)->ulrrcnd.cnd.trueLabel
+#define IC_FALSE(x)  (x)->ulrrcnd.cnd.falseLabel
+#define IC_LABEL(x)  (x)->argLabel.label
+#define IC_ARGS(x)   (x)->argLabel.args
+#define IC_JTCOND(x) (x)->ulrrcnd.jmpTab.condition
+#define IC_JTLABELS(x) (x)->ulrrcnd.jmpTab.labels
+#define IC_INLINE(x) (x)->inlineAsm
 
 typedef struct iCode 
 {
index ea961cbbab4f30819a409a6756dc8d14d3bc005e..3c53bb8fb1ab67ee11a4150d4914632f60e1cc1b 100644 (file)
@@ -40,6 +40,7 @@
 // No unistd.h in Borland C++
 extern int access(const char *, int);
 #define X_OK 1
+
 #endif
 
 //REMOVE ME!!!
@@ -150,6 +151,12 @@ static PORT *_ports[] = {
 #if !OPT_DISABLE_PIC
     &pic14_port,
 #endif
+#if !OPT_DISABLE_I186
+   &i186_port,
+#endif
+#if !OPT_DISABLE_TLCS900H
+   &tlcs900h_port,
+#endif
 };
 
 #define NUM_PORTS (sizeof(_ports)/sizeof(_ports[0]))
@@ -177,6 +184,17 @@ static int _setPort(const char *name)
     exit(1);
 }
 
+static void _validatePorts(void)
+{
+    int i;
+    for (i=0; i<NUM_PORTS; i++) {
+       if (_ports[i]->magic != PORT_MAGIC) {
+           printf("Error: port %s is incomplete.\n", _ports[i]->target);
+           wassert(0);
+       }
+    }
+}
+
 void buildCmdLine(char *into, char **args, const char **cmds, 
                          const char *p1, const char *p2, 
                          const char *p3, const char **list)
@@ -1360,6 +1378,8 @@ static int preProcess (char **envp)
 
 static void _findPort(int argc, char **argv)
 {
+    _validatePorts();
+
     argc--;
     while (argc) {
        if (!strncmp(*argv, "-m", 2)) {
index 3b47782fff85f20232733bf07ed3f3411ed53138..3830406544cf0218b771677e3dd849ec4793a33d 100644 (file)
@@ -787,7 +787,7 @@ int allocVariables ( symbol *symChain )
 /*-----------------------------------------------------------------*/
 /* redoStackOffsets :- will reassign the values for stack offsets  */
 /*-----------------------------------------------------------------*/
-void redoStackOffsets ()
+void redoStackOffsets(void)
 {
     symbol *sym;
     int sPtr = 0;
index 7455b69b3e6f91b7713eed8c39b0a69e6c6f7275..353e60f3a53ea0b147ccb4999f39bfd59bbbee01 100644 (file)
--- a/src/asm.c
+++ b/src/asm.c
@@ -20,7 +20,8 @@ static const char *_findMapping(const char *szKey)
     return shash_find(_h, szKey);
 }
 
-static va_list _iprintf(char *pInto, const char *sz, va_list ap)
+#if 0
+static void _iprintf(char *pInto, const char *sz, va_list *pap)
 {
     char format[MAX_TOKEN_LEN];
     char *pStart = pInto;
@@ -58,9 +59,9 @@ static va_list _iprintf(char *pInto, const char *sz, va_list ap)
                        *p++ = *sz++;
                    *p++ = *sz++;
                    *p = '\0';
-                   vsprintf(pInto, format, ap);
+                   vsprintf(pInto, format, *pap);
                    /* PENDING: Assume that the arg length was an int */
-                   (void)va_arg(ap, int);
+                   (void)va_arg(*pap, int);
                }
            }
            pInto = pStart + strlen(pStart);
@@ -70,8 +71,6 @@ static va_list _iprintf(char *pInto, const char *sz, va_list ap)
        }
     }
     *pInto = '\0';
-
-    return ap;
 }
 
 void tvsprintf(char *buffer, const char *sz, va_list ap)
@@ -95,7 +94,8 @@ void tvsprintf(char *buffer, const char *sz, va_list ap)
            *p = '\0';
            /* Now find the token in the token list */
            if ((t = _findMapping(token))) {
-               ap = _iprintf(pInto, t, ap);
+               printf("tvsprintf: found token \"%s\" to \"%s\"\n", token, t);
+               _iprintf(pInto, t, &ap);
                pInto = buffer + strlen(buffer);
            }
            else {
@@ -121,6 +121,97 @@ void tvsprintf(char *buffer, const char *sz, va_list ap)
     }
     *pInto = '\0';
 }
+#else
+// Append a string onto another, and update the pointer to the end of
+// the new string.
+static char *_appendAt(char *at, char *onto, const char *sz)
+{
+    wassert(at && onto && sz);
+    strcpy(at, sz);
+    return at + strlen(sz);
+}
+
+void tvsprintf(char *buffer, const char *format, va_list ap)
+{
+    // Under Linux PPC va_list is a structure instead of a primitive type,
+    // and doesnt like being passed around.  This version turns everything
+    // into one function.
+    
+    // Supports:
+    //  !tokens
+    //  %[CIF] - special formats with no argument (ie list isnt touched)
+    //  All of the system formats
+
+    // This is acheived by expanding the tokens and zero arg formats into
+    // one big format string, which is passed to the native printf.
+    static int count;
+    char newformat[MAX_INLINEASM];
+    char *pInto = newformat;
+    char *p;
+    char token[MAX_TOKEN_LEN];
+    const char *sz = format;
+
+    // NULL terminate it to let strlen work.
+    *pInto = '\0';
+    
+    while (*sz) {
+       if (*sz == '!') {
+           /* Start of a token.  Search until the first
+              [non alpha, *] and call it a token. */
+           const char *t;
+           p = token;
+           sz++;
+           while (isalpha(*sz) || *sz == '*') {
+               *p++ = *sz++;
+           }
+           *p = '\0';
+           /* Now find the token in the token list */
+           if ((t = _findMapping(token))) {
+               pInto = _appendAt(pInto, newformat, t);
+           }
+           else {
+               fprintf(stderr, "Cant find token \"%s\"\n", token);
+               wassert(0);
+           }
+       }
+       else if (*sz == '%') {
+           // See if its one that we handle.
+           sz++;
+           switch (*sz) {
+           case 'C':
+               // Code segment name.
+               pInto = _appendAt(pInto, newformat, CODE_NAME);
+               break;
+           case 'F':
+               // Source file name.
+               pInto = _appendAt(pInto, newformat, srcFileName);
+               break;
+           case 'I': {
+               // Unique ID.
+               char id[20];
+               sprintf(id, "%u", ++count);
+               pInto = _appendAt(pInto, newformat, id);
+               break;
+           }
+           default:
+               // Not one of ours.  Copy until the end.
+               *pInto++ = '%';
+               while (!isalpha(*sz)) {
+                   *pInto++ = *sz++;
+               }
+               *pInto++ = *sz++;
+           }
+       }
+       else {
+           *pInto++ = *sz++;
+       }
+    }
+    *pInto = '\0';
+    
+    // Now do the actual printing
+    vsprintf(buffer, newformat, ap); 
+}
+#endif
 
 void tfprintf(FILE *fp, const char *szFormat, ...)
 {
index 808ac5cebed1887bd1bc6cf54f2c093cbe05937f..ddbacc367410ecf31e0cf6165a6914c642a6cd1e 100644 (file)
@@ -207,6 +207,6 @@ PORT avr_port = {
     0,   /* leave ge */
     0,   /* leave !=  */
     0,   /* leave == */
-
+    PORT_MAGIC
 };
 
index 3694994dc7653dbab04c85961d4a2dbd8a339d88..c269aae762208ca7b7ca0476b85062a04c0eeb10 100644 (file)
@@ -5,7 +5,6 @@ include $(PRJDIR)/Makefile.common
 OBJ = gen.o ralloc.o main.o
 LIB = port.a
 
-CFLAGS = -g -Wall -O2
 CFLAGS += -I.. -I.
 
 all: $(LIB)
index 68e24823c424ebf1168308850a0ec3b7f47fc47a..e6974bf7a3a67138a32f11c12087bc54291a3138 100644 (file)
@@ -263,6 +263,7 @@ PORT ds390_port = {
     1,  /* transform <= to ! > */
     1,  /* transform >= to ! < */
     1,  /* transform != to !(a == b) */
-    0   /* leave == */
+    0,  /* leave == */
+    PORT_MAGIC
 };
 
index 7d13682c4468493149799597c7e3469365941f09..945ae004a01b85fde7de5a4a8f3757626f6a3dca 100644 (file)
@@ -43,7 +43,7 @@ void iemit(const char *szFormat, ...)
 
     va_start(ap, szFormat);
 
-    vsprintf(buffer, szFormat, ap);
+    tvsprintf(buffer, szFormat, ap);
 
     _tidyUp(buffer);
 
@@ -235,7 +235,6 @@ static bool _tryEmittingiCode(hTab *h, iCode *ic)
 void izt_addEmittersToHTab(hTab **into, EMITTER _base_emitters[])
 {
     while (_base_emitters->emit != NULL) {
-       printf("Added an emitter for %u %p\n", _base_emitters->op, _base_emitters);
        hTabAddItemLong(into, _base_emitters->op, _base_emitters, _base_emitters);
        _base_emitters++;
     }
index 16b539ad629df3761aa189a1dc7c41489b83d7fd..d0ed83086fb565736b5897148dcddcfab1787856 100644 (file)
@@ -228,5 +228,6 @@ PORT i186_port = {
     1,  /* transform <= to ! > */
     1,  /* transform >= to ! < */
     1,  /* transform != to !(a == b) */
-    0   /* leave == */
+    0,  /* leave == */
+    PORT_MAGIC
 };
index f01ec1b8ab1305d7e9d3c1a74cfddeeb0b1096d8..f9ba3a63fac1ad003c57fd305791d713fcd6bbee 100644 (file)
@@ -810,3 +810,11 @@ void izt_assignRegisters(eBBlock **ebbs, int count)
     // And free all registers.
     _freeAllRegs();
 }
+
+void warningStopper(void)
+{
+    // For now references all unused functions.
+    _dumpRegs();
+    _packRegisters(NULL);
+    _getSubReg(NULL, 0, 0);
+}
index bd43248b3b6f6da8b0974469965e2e02103951e8..82b5c4bc8762d38152990bfbdf553644c3822ac5 100644 (file)
@@ -15,12 +15,15 @@ static REG _tlcs900h_regs[] = {
     { 0, REG_ID_NONE,"??",  0, { REG_ID_NONE, REG_ID_NONE, REG_ID_NONE } }
 };
 
+static IZT_PORT _tlcs900h_port = {
+    _tlcs900h_regs
+};
+
 static char _defaultRules[] =
 {
     //#include "peeph.rul"
 };
 
-/* list of key words used by msc51 */
 static char *_tlcs900h_keywords[] =     {
     NULL
 };
@@ -30,6 +33,7 @@ void tlcs900h_assignRegisters (eBBlock **ebbs, int count);
 static void _tlcs900h_init(void)
 {
     asm_addTree(&asm_asxxxx_mapping);
+    izt_init(&_tlcs900h_port);
 }
 
 static void _tlcs900h_reset_regparm()
@@ -170,5 +174,6 @@ PORT tlcs900h_port = {
     1,  /* transform <= to ! > */
     1,  /* transform >= to ! < */
     1,  /* transform != to !(a == b) */
-    0   /* leave == */
+    0,  /* leave == */
+    PORT_MAGIC
 };
index eb4843ba52875ff0149dae64e522a7d6ba6d7098..137d0fdb4a1a3094bfaf0ea4362208f9da9c8573 100644 (file)
@@ -266,6 +266,7 @@ PORT mcs51_port = {
     1,  /* transform <= to ! > */
     1,  /* transform >= to ! < */
     1,  /* transform != to !(a == b) */
-    0   /* leave == */
+    0,  /* leave == */
+    PORT_MAGIC
 };
 
index c785693d4bb799706a7b9eea0b2cac34dfbc6cc8..0dc512cadc76eb554f4ac978f822f23cfa659634 100644 (file)
@@ -267,6 +267,7 @@ PORT pic14_port = {
     1,  /* transform <= to ! > */
     1,  /* transform >= to ! < */
     1,  /* transform != to !(a == b) */
-    0   /* leave == */
+    0,  /* leave == */
+    PORT_MAGIC
 };
 
index 2e4efd54dc5b9c2067b73f4a1f765eef1ffa6355..44156d3528f38f354e493d57322aa85e06bb8d51 100644 (file)
@@ -169,6 +169,10 @@ typedef struct {
     bool ge_nlt ;     /* transform (a >= b) to !(a < b)   */
     bool ne_neq ;     /* transform a != b --> ! (a == b)  */
     bool eq_nne ;     /* transform a == b --> ! (a != b)  */
+
+#define PORT_MAGIC 0xAC32
+    /** Used at runtime to detect if this structure has been completly filled in. */
+    int magic;
 } PORT;
 
 extern PORT *port;
@@ -191,6 +195,12 @@ extern PORT ds390_port;
 #if !OPT_DISABLE_PIC
 extern PORT pic14_port;
 #endif
+#if !OPT_DISABLE_I186
+extern PORT i186_port;
+#endif
+#if !OPT_DISABLE_TLCS900H
+extern PORT tlcs900h_port;
+#endif
 
 /* Test to see if we are current compiling in DS390 mode. */
 #define IS_MCS51_PORT (port == &mcs51_port)
index aef74af8869b2218c4e2b925e90e355cee99cef5..b3dd2ec3ac767b654a7d90ebc77646c2a602c671 100644 (file)
@@ -340,7 +340,14 @@ PORT z80_port = {
     _reset_regparm,
     _reg_parm,
     _process_pragma,
-    TRUE
+    TRUE,
+    0,  /* leave lt */
+    0,  /* leave gt */
+    1,  /* transform <= to ! > */
+    1,  /* transform >= to ! < */
+    1,  /* transform != to !(a == b) */
+    0,   /* leave == */
+    PORT_MAGIC
 };
 
 /* Globals */
@@ -413,5 +420,6 @@ PORT gbz80_port = {
     1,  /* transform <= to ! > */
     1,  /* transform >= to ! < */
     1,  /* transform != to !(a == b) */
-    0   /* leave == */
+    0,   /* leave == */
+    PORT_MAGIC
 };