From abf72462cc7dd96c3089b77078e322cfd60020ed Mon Sep 17 00:00:00 2001 From: michaelh Date: Sun, 28 Jan 2001 20:07:04 +0000 Subject: [PATCH] Merge of the izt changes. 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 --- src/Makefile.in | 2 +- src/SDCChasht.c | 11 +++-- src/SDCCicode.h | 22 +++++----- src/SDCCmain.c | 20 +++++++++ src/SDCCmem.c | 2 +- src/asm.c | 103 ++++++++++++++++++++++++++++++++++++++++++--- src/avr/main.c | 2 +- src/ds390/Makefile | 1 - src/ds390/main.c | 3 +- src/izt/gen.c | 3 +- src/izt/i186.c | 3 +- src/izt/ralloc.c | 8 ++++ src/izt/tlcs900h.c | 9 +++- src/mcs51/main.c | 3 +- src/pic/main.c | 3 +- src/port.h | 10 +++++ src/z80/main.c | 12 +++++- 17 files changed, 182 insertions(+), 35 deletions(-) diff --git a/src/Makefile.in b/src/Makefile.in index 96c6f497..c4a1a026 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -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) diff --git a/src/SDCChasht.c b/src/SDCChasht.c index ce646461..d083faa3 100644 --- a/src/SDCChasht.c +++ b/src/SDCChasht.c @@ -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; } diff --git a/src/SDCCicode.h b/src/SDCCicode.h index 62ea5b41..c22e63d1 100644 --- a/src/SDCCicode.h +++ b/src/SDCCicode.h @@ -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 { diff --git a/src/SDCCmain.c b/src/SDCCmain.c index ea961cbb..3c53bb8f 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -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; imagic != 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)) { diff --git a/src/SDCCmem.c b/src/SDCCmem.c index 3b47782f..38304065 100644 --- a/src/SDCCmem.c +++ b/src/SDCCmem.c @@ -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; diff --git a/src/asm.c b/src/asm.c index 7455b69b..353e60f3 100644 --- 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, ...) { diff --git a/src/avr/main.c b/src/avr/main.c index 808ac5ce..ddbacc36 100644 --- a/src/avr/main.c +++ b/src/avr/main.c @@ -207,6 +207,6 @@ PORT avr_port = { 0, /* leave ge */ 0, /* leave != */ 0, /* leave == */ - + PORT_MAGIC }; diff --git a/src/ds390/Makefile b/src/ds390/Makefile index 3694994d..c269aae7 100644 --- a/src/ds390/Makefile +++ b/src/ds390/Makefile @@ -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) diff --git a/src/ds390/main.c b/src/ds390/main.c index 68e24823..e6974bf7 100644 --- a/src/ds390/main.c +++ b/src/ds390/main.c @@ -263,6 +263,7 @@ PORT ds390_port = { 1, /* transform <= to ! > */ 1, /* transform >= to ! < */ 1, /* transform != to !(a == b) */ - 0 /* leave == */ + 0, /* leave == */ + PORT_MAGIC }; diff --git a/src/izt/gen.c b/src/izt/gen.c index 7d13682c..945ae004 100644 --- a/src/izt/gen.c +++ b/src/izt/gen.c @@ -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++; } diff --git a/src/izt/i186.c b/src/izt/i186.c index 16b539ad..d0ed8308 100644 --- a/src/izt/i186.c +++ b/src/izt/i186.c @@ -228,5 +228,6 @@ PORT i186_port = { 1, /* transform <= to ! > */ 1, /* transform >= to ! < */ 1, /* transform != to !(a == b) */ - 0 /* leave == */ + 0, /* leave == */ + PORT_MAGIC }; diff --git a/src/izt/ralloc.c b/src/izt/ralloc.c index f01ec1b8..f9ba3a63 100644 --- a/src/izt/ralloc.c +++ b/src/izt/ralloc.c @@ -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); +} diff --git a/src/izt/tlcs900h.c b/src/izt/tlcs900h.c index bd43248b..82b5c4bc 100644 --- a/src/izt/tlcs900h.c +++ b/src/izt/tlcs900h.c @@ -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 }; diff --git a/src/mcs51/main.c b/src/mcs51/main.c index eb4843ba..137d0fdb 100644 --- a/src/mcs51/main.c +++ b/src/mcs51/main.c @@ -266,6 +266,7 @@ PORT mcs51_port = { 1, /* transform <= to ! > */ 1, /* transform >= to ! < */ 1, /* transform != to !(a == b) */ - 0 /* leave == */ + 0, /* leave == */ + PORT_MAGIC }; diff --git a/src/pic/main.c b/src/pic/main.c index c785693d..0dc512ca 100644 --- a/src/pic/main.c +++ b/src/pic/main.c @@ -267,6 +267,7 @@ PORT pic14_port = { 1, /* transform <= to ! > */ 1, /* transform >= to ! < */ 1, /* transform != to !(a == b) */ - 0 /* leave == */ + 0, /* leave == */ + PORT_MAGIC }; diff --git a/src/port.h b/src/port.h index 2e4efd54..44156d35 100644 --- a/src/port.h +++ b/src/port.h @@ -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) diff --git a/src/z80/main.c b/src/z80/main.c index aef74af8..b3dd2ec3 100644 --- a/src/z80/main.c +++ b/src/z80/main.c @@ -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 }; -- 2.39.5