From 195ee3f3ee25ce2c5f2a59fbd2779c4cb80527c3 Mon Sep 17 00:00:00 2001 From: maartenbrock Date: Thu, 8 Sep 2005 16:47:48 +0000 Subject: [PATCH] * as/hc08/lkaomf51.c (OutputName): made name unsigned char, (hex2dec): made hex_digit unsigned char, removed ascii dependance * as/mcs51/lkaomf51.c (OutputName): made name unsigned char, (hex2dec): made hex_digit unsigned char, removed ascii dependance * as/mcs51/lkarea.c (lnkarea2): sort absolute areas to the front * packihx/packihx.c (hexDigit): made c unsigned char * as/mcs51/lklibr.c (fndsym), * link/z80/lkgb.c (gb), * link/z80/lklibr.c (fndsym), * link/z80/lkrloc.c (relr), * sim/ucsim/libltdl/ltdl.c (load_deplibs, try_dlopen), * src/SDCC.lex (checkCurrFile, process_pragma), * src/SDCCglue.c (spacesToUnderscores), * src/SDCCmain.c (setParseWithComma, processFile), * src/asm.c (tvsprintf, printCLine), * src/avr/gen.c (emitcode, aopPut), * src/ds390/gen.c (emitcode), * src/hc08/gen.c (emitcode, emitinline), * src/mcs51/gen.c (emitcode, genInline), * src/pic/pcodepeep.c (cvt_extract_destination, cvt_extract_status, tokenizeLineNode), * src/pic/ralloc.c (debugLog), * src/pic16/pcodepeep.c (cvt_extract_destination, cvt_extract_status, tokenizeLineNode), * src/pic16/ralloc.c (debugLog), * src/z80/main.c (_process_pragma): made all ctype.h function calls safe * src/SDCCopt.c: include math.h for fabs * src/SDCCpeeph.c: added macros ISCHARDIGIT, ISCHARSPACE and ISCHARALNUM and used them throughout the code to make ctype.h function calls safe * src/ds390/main.c (asmLineNodeFromLineNode), * src/mcs51/main.c (asmLineNodeFromLineNode): made p unsigned char* * src/pic/gen.c (DEBUGpic14_emitcode, pic14_emitcode): made lbp unsigned char* * src/pic/pcode.c (mnem2key): made mnem unsigned char*, (newpCodeAsmDir): made ctype.h function calls safe * src/pic16/gen.c (pic16_emitpcomment, DEBUGpic16_emitcode, pic16_emitcode): made lbp unsigned char* * src/pic16/pcode.c (mnem2key): made mnem unsigned char*, (pic16_newpCodeAsmDir): made ctype.h function calls safe * src/xa51/gen.c (emitcode), * src/z80/gen.c (_emit2): made lbp unsigned char* * support/Util/MySystem.c (split_command): made cmd_line and p unsigned char* git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3888 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 47 + as/hc08/lkaomf51.c | 12 +- as/mcs51/lkaomf51.c | 12 +- as/mcs51/lkarea.c | 23 +- as/mcs51/lklibr.c | 4 +- link/z80/lkgb.c | 4 +- link/z80/lklibr.c | 4 +- link/z80/lkrloc.c | 2 +- packihx/packihx.c | 2 +- sim/ucsim/libltdl/ltdl.c | 1784 +++++++++++++++++++------------------- src/SDCC.lex | 8 +- src/SDCCglue.c | 14 +- src/SDCCmain.c | 18 +- src/SDCCopt.c | 1257 +++++++++++++-------------- src/SDCCpeeph.c | 796 ++++++++--------- src/asm.c | 204 ++--- src/avr/gen.c | 6 +- src/ds390/gen.c | 22 +- src/ds390/main.c | 2 +- src/hc08/gen.c | 4 +- src/mcs51/gen.c | 88 +- src/mcs51/main.c | 46 +- src/pic/gen.c | 4 +- src/pic/pcode.c | 6 +- src/pic/pcodepeep.c | 18 +- src/pic/ralloc.c | 2 +- src/pic16/gen.c | 6 +- src/pic16/pcode.c | 6 +- src/pic16/pcodepeep.c | 18 +- src/pic16/ralloc.c | 2 +- src/xa51/gen.c | 4 +- src/z80/gen.c | 4 +- src/z80/main.c | 4 +- support/Util/MySystem.c | 4 +- 34 files changed, 2253 insertions(+), 2184 deletions(-) diff --git a/ChangeLog b/ChangeLog index d80d78fb..89deffd7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,50 @@ +2005-09-08 Maarten Brock + + * as/hc08/lkaomf51.c (OutputName): made name unsigned char, + (hex2dec): made hex_digit unsigned char, removed ascii dependance + * as/mcs51/lkaomf51.c (OutputName): made name unsigned char, + (hex2dec): made hex_digit unsigned char, removed ascii dependance + * as/mcs51/lkarea.c (lnkarea2): sort absolute areas to the front + * packihx/packihx.c (hexDigit): made c unsigned char + * as/mcs51/lklibr.c (fndsym), + * link/z80/lkgb.c (gb), + * link/z80/lklibr.c (fndsym), + * link/z80/lkrloc.c (relr), + * sim/ucsim/libltdl/ltdl.c (load_deplibs, try_dlopen), + * src/SDCC.lex (checkCurrFile, process_pragma), + * src/SDCCglue.c (spacesToUnderscores), + * src/SDCCmain.c (setParseWithComma, processFile), + * src/asm.c (tvsprintf, printCLine), + * src/avr/gen.c (emitcode, aopPut), + * src/ds390/gen.c (emitcode), + * src/hc08/gen.c (emitcode, emitinline), + * src/mcs51/gen.c (emitcode, genInline), + * src/pic/pcodepeep.c (cvt_extract_destination, cvt_extract_status, + tokenizeLineNode), + * src/pic/ralloc.c (debugLog), + * src/pic16/pcodepeep.c (cvt_extract_destination, cvt_extract_status, + tokenizeLineNode), + * src/pic16/ralloc.c (debugLog), + * src/z80/main.c (_process_pragma): + made all ctype.h function calls safe + * src/SDCCopt.c: include math.h for fabs + * src/SDCCpeeph.c: added macros ISCHARDIGIT, ISCHARSPACE and ISCHARALNUM + and used them throughout the code to make ctype.h function calls safe + * src/ds390/main.c (asmLineNodeFromLineNode), + * src/mcs51/main.c (asmLineNodeFromLineNode): made p unsigned char* + * src/pic/gen.c (DEBUGpic14_emitcode, pic14_emitcode): made lbp + unsigned char* + * src/pic/pcode.c (mnem2key): made mnem unsigned char*, + (newpCodeAsmDir): made ctype.h function calls safe + * src/pic16/gen.c (pic16_emitpcomment, DEBUGpic16_emitcode, + pic16_emitcode): made lbp unsigned char* + * src/pic16/pcode.c (mnem2key): made mnem unsigned char*, + (pic16_newpCodeAsmDir): made ctype.h function calls safe + * src/xa51/gen.c (emitcode), + * src/z80/gen.c (_emit2): made lbp unsigned char* + * support/Util/MySystem.c (split_command): made cmd_line and p unsigned + char* + 2005-09-05 Raphael Neider * src/pic16/ralloc.c (pic16_allocDirReg): use device specific diff --git a/as/hc08/lkaomf51.c b/as/hc08/lkaomf51.c index fa009e77..7e0122dd 100644 --- a/as/hc08/lkaomf51.c +++ b/as/hc08/lkaomf51.c @@ -203,7 +203,7 @@ void OutputWord(int value) OutputByte((unsigned char)(value/0x100)); } -void OutputName(char * name) +void OutputName(unsigned char * name) { int k; OutputByte((unsigned char)strlen(name)); @@ -869,12 +869,12 @@ void CollectInfoFromCDB(void) fclose(CDBin); } -int hex2dec (char hex_digit) +int hex2dec (unsigned char hex_digit) { - int j; - j=toupper(hex_digit)-'0'; - if (j>9) j -= 7; - return j; + if (isdigit(hex_digit)) + return hex_digit-'0'; + else + return toupper(hex_digit)-'A'+10; } unsigned char GetByte(char * buffer) diff --git a/as/mcs51/lkaomf51.c b/as/mcs51/lkaomf51.c index 82dccb3e..812c616f 100644 --- a/as/mcs51/lkaomf51.c +++ b/as/mcs51/lkaomf51.c @@ -209,7 +209,7 @@ void OutputWord(int value) OutputByte((unsigned char)(value/0x100)); } -void OutputName(char * name) +void OutputName(unsigned char * name) { int k; OutputByte((unsigned char)strlen(name)); @@ -876,12 +876,12 @@ void CollectInfoFromCDB(void) fclose(CDBin); } -int hex2dec (char hex_digit) +int hex2dec (unsigned char hex_digit) { - int j; - j=toupper(hex_digit)-'0'; - if (j>9) j -= 7; - return j; + if (isdigit (hex_digit)) + return hex_digit-'0'; + else + return toupper (hex_digit)-'A'+10; } unsigned char GetByte(char * buffer) diff --git a/as/mcs51/lkarea.c b/as/mcs51/lkarea.c index 608e3e15..3913ae83 100644 --- a/as/mcs51/lkarea.c +++ b/as/mcs51/lkarea.c @@ -495,12 +495,29 @@ VOID lnkarea2 (void) char temp[NCPS]; struct sym *sp; int j; - struct area *dseg_ap=NULL; + struct area *dseg_ap = NULL; + struct area *abs_ap = NULL; struct sym *sp_dseg_s=NULL, *sp_dseg_l=NULL; for(j=0; j<256; j++) idatamap[j]=' '; memset(codemap, 0, sizeof(codemap)); + /* first sort all absolute areas to the front */ + ap = areap; + /* no need to check first area, it's in front anyway */ + while (ap && ap->a_ap) + { + if (ap->a_ap->a_flag & A_ABS) + {/* next area is absolute, move it to front, + reversed sequence is no problem for absolutes */ + abs_ap = ap->a_ap; + ap->a_ap = abs_ap->a_ap; + abs_ap->a_ap = areap; + areap = abs_ap; + } + ap = ap->a_ap; + } + ap = areap; while (ap) { @@ -555,7 +572,7 @@ VOID lnkarea2 (void) to compute the byte size of BSEG_BYTES: */ if (!strcmp(ap->a_id, "BSEG")) { - ap->a_ap->a_axp->a_size = ((ap->a_addr + ap->a_size + 7)/8); /*Bits to bytes*/ + ap->a_ap->a_axp->a_size = ((ap->a_addr + ap->a_size + 7)/8); /*Bits to bytes*/ } else if (!strcmp(ap->a_id, "DSEG")) { @@ -736,7 +753,7 @@ void lnksect2 (struct area *tap, int rloc) fprintf(stderr, ErrMsg, taxp->a_size, taxp->a_size>1?"s":"", tap->a_id); lkerr++; } - } + } for(j=0; jlibspc, PATH_MAX); _fullpath(absPath2, ThisLibr->libspc, PATH_MAX); - for(j=0; absPath1[j]!=0; j++) absPath1[j]=tolower(absPath1[j]); - for(j=0; absPath2[j]!=0; j++) absPath2[j]=tolower(absPath2[j]); + for(j=0; absPath1[j]!=0; j++) absPath1[j]=tolower((unsigned char)absPath1[j]); + for(j=0; absPath2[j]!=0; j++) absPath2[j]=tolower((unsigned char)absPath2[j]); #else realpath(FirstFound->libspc, absPath1); realpath(ThisLibr->libspc, absPath2); diff --git a/link/z80/lkgb.c b/link/z80/lkgb.c index 9fdeb4e6..63af393f 100644 --- a/link/z80/lkgb.c +++ b/link/z80/lkgb.c @@ -95,11 +95,11 @@ VOID gb(int in) /* EOF */ if(cart_name[0] == 0 && linkp->f_idp != NULL) { for(i = strlen(linkp->f_idp); - i > 0 && (isalnum(linkp->f_idp[i-1]) || linkp->f_idp[i-1] == '.'); + i > 0 && (isalnum((unsigned char)linkp->f_idp[i-1]) || linkp->f_idp[i-1] == '.'); i--) ; for(pos = 0; pos < 16 && linkp->f_idp[i] != '.'; pos++, i++) - cart_name[pos] = toupper(linkp->f_idp[i]); + cart_name[pos] = toupper((unsigned char)linkp->f_idp[i]); if(pos < 16) cart_name[pos] = 0; } diff --git a/link/z80/lklibr.c b/link/z80/lklibr.c index bd514511..c3761bbd 100644 --- a/link/z80/lklibr.c +++ b/link/z80/lklibr.c @@ -581,8 +581,8 @@ int fndsym( char *name ) _fullpath(absPath1, FirstFound->libspc, PATH_MAX); _fullpath(absPath2, ThisLibr->libspc, PATH_MAX); - for(j=0; absPath1[j]!=0; j++) absPath1[j]=tolower(absPath1[j]); - for(j=0; absPath2[j]!=0; j++) absPath2[j]=tolower(absPath2[j]); + for(j=0; absPath1[j]!=0; j++) absPath1[j]=tolower((unsigned char)absPath1[j]); + for(j=0; absPath2[j]!=0; j++) absPath2[j]=tolower((unsigned char)absPath2[j]); #else realpath(FirstFound->libspc, absPath1); realpath(ThisLibr->libspc, absPath2); diff --git a/link/z80/lkrloc.c b/link/z80/lkrloc.c index 0746dbbe..e5bdd05a 100644 --- a/link/z80/lkrloc.c +++ b/link/z80/lkrloc.c @@ -295,7 +295,7 @@ relr() #ifdef GAMEBOY { char *s = strrchr(a[aindex]->a_bap->a_id, '_'); - if(s != NULL && isdigit(s[1])) + if(s != NULL && isdigit((unsigned char)s[1])) current_rom_bank = atoi(s+1); else current_rom_bank = 0; diff --git a/packihx/packihx.c b/packihx/packihx.c index a9cf4e7a..779966a5 100644 --- a/packihx/packihx.c +++ b/packihx/packihx.c @@ -46,7 +46,7 @@ int outlineno = 0; /* Convert hex digit to numeric value 0 - 15; assumes input is a * valid digit (i.e. passes isxdigit()). */ -static Uint8 hexDigit(const char c) +static Uint8 hexDigit(const unsigned char c) { if (isdigit(c)) { diff --git a/sim/ucsim/libltdl/ltdl.c b/sim/ucsim/libltdl/ltdl.c index 448bc67c..14f1c128 100644 --- a/sim/ucsim/libltdl/ltdl.c +++ b/sim/ucsim/libltdl/ltdl.c @@ -89,7 +89,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA #if HAVE_ASSERT_H # include #else -# define assert(arg) ((void) 0) +# define assert(arg) ((void) 0) #endif #include "ltdl.h" @@ -105,13 +105,13 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA #ifdef DLL_EXPORT -# define LT_GLOBAL_DATA __declspec(dllexport) +# define LT_GLOBAL_DATA __declspec(dllexport) #else # define LT_GLOBAL_DATA #endif /* fopen() mode flags for reading a text file */ -#undef LT_READTEXT_MODE +#undef LT_READTEXT_MODE #ifdef __WINDOWS__ # define LT_READTEXT_MODE "rt" #else @@ -126,24 +126,24 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA /* Standard libltdl search path environment variable name */ #undef LTDL_SEARCHPATH_VAR -#define LTDL_SEARCHPATH_VAR "LTDL_LIBRARY_PATH" +#define LTDL_SEARCHPATH_VAR "LTDL_LIBRARY_PATH" /* Standard libtool archive file extension. */ #undef LTDL_ARCHIVE_EXT -#define LTDL_ARCHIVE_EXT ".la" +#define LTDL_ARCHIVE_EXT ".la" /* max. filename length */ #ifndef LT_FILENAME_MAX -# define LT_FILENAME_MAX 1024 +# define LT_FILENAME_MAX 1024 #endif /* This is the maximum symbol size that won't require malloc/free */ -#undef LT_SYMBOL_LENGTH -#define LT_SYMBOL_LENGTH 128 +#undef LT_SYMBOL_LENGTH +#define LT_SYMBOL_LENGTH 128 /* This accounts for the _LTX_ separator */ -#undef LT_SYMBOL_OVERHEAD -#define LT_SYMBOL_OVERHEAD 5 +#undef LT_SYMBOL_OVERHEAD +#define LT_SYMBOL_OVERHEAD 5 @@ -154,47 +154,47 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA /* These are the functions used internally. In addition to making use of the associated function pointers above, they also perform error handling. */ -static char *lt_estrdup LT_PARAMS((const char *str)); -static lt_ptr lt_emalloc LT_PARAMS((size_t size)); -static lt_ptr lt_erealloc LT_PARAMS((lt_ptr addr, size_t size)); +static char *lt_estrdup LT_PARAMS((const char *str)); +static lt_ptr lt_emalloc LT_PARAMS((size_t size)); +static lt_ptr lt_erealloc LT_PARAMS((lt_ptr addr, size_t size)); -static lt_ptr rpl_realloc LT_PARAMS((lt_ptr ptr, size_t size)); +static lt_ptr rpl_realloc LT_PARAMS((lt_ptr ptr, size_t size)); /* These are the pointers that can be changed by the caller: */ -LT_GLOBAL_DATA lt_ptr (*lt_dlmalloc) LT_PARAMS((size_t size)) - = (lt_ptr (*) LT_PARAMS((size_t))) malloc; -LT_GLOBAL_DATA lt_ptr (*lt_dlrealloc) LT_PARAMS((lt_ptr ptr, size_t size)) - = (lt_ptr (*) LT_PARAMS((lt_ptr, size_t))) rpl_realloc; -LT_GLOBAL_DATA void (*lt_dlfree) LT_PARAMS((lt_ptr ptr)) - = (void (*) LT_PARAMS((lt_ptr))) free; +LT_GLOBAL_DATA lt_ptr (*lt_dlmalloc) LT_PARAMS((size_t size)) + = (lt_ptr (*) LT_PARAMS((size_t))) malloc; +LT_GLOBAL_DATA lt_ptr (*lt_dlrealloc) LT_PARAMS((lt_ptr ptr, size_t size)) + = (lt_ptr (*) LT_PARAMS((lt_ptr, size_t))) rpl_realloc; +LT_GLOBAL_DATA void (*lt_dlfree) LT_PARAMS((lt_ptr ptr)) + = (void (*) LT_PARAMS((lt_ptr))) free; /* The following macros reduce the amount of typing needed to cast assigned memory. */ #if WITH_DMALLOC -#define LT_DLMALLOC(tp, n) ((tp *) xmalloc ((n) * sizeof(tp))) -#define LT_DLREALLOC(tp, p, n) ((tp *) xrealloc ((p), (n) * sizeof(tp))) -#define LT_DLFREE(p) \ - LT_STMT_START { if (p) (p) = (xfree (p), (lt_ptr) 0); } LT_STMT_END +#define LT_DLMALLOC(tp, n) ((tp *) xmalloc ((n) * sizeof(tp))) +#define LT_DLREALLOC(tp, p, n) ((tp *) xrealloc ((p), (n) * sizeof(tp))) +#define LT_DLFREE(p) \ + LT_STMT_START { if (p) (p) = (xfree (p), (lt_ptr) 0); } LT_STMT_END -#define LT_EMALLOC(tp, n) ((tp *) xmalloc ((n) * sizeof(tp))) -#define LT_EREALLOC(tp, p, n) ((tp *) xrealloc ((p), (n) * sizeof(tp))) +#define LT_EMALLOC(tp, n) ((tp *) xmalloc ((n) * sizeof(tp))) +#define LT_EREALLOC(tp, p, n) ((tp *) xrealloc ((p), (n) * sizeof(tp))) #else -#define LT_DLMALLOC(tp, n) ((tp *) lt_dlmalloc ((n) * sizeof(tp))) -#define LT_DLREALLOC(tp, p, n) ((tp *) rpl_realloc ((p), (n) * sizeof(tp))) -#define LT_DLFREE(p) \ - LT_STMT_START { if (p) (p) = (lt_dlfree (p), (lt_ptr) 0); } LT_STMT_END +#define LT_DLMALLOC(tp, n) ((tp *) lt_dlmalloc ((n) * sizeof(tp))) +#define LT_DLREALLOC(tp, p, n) ((tp *) rpl_realloc ((p), (n) * sizeof(tp))) +#define LT_DLFREE(p) \ + LT_STMT_START { if (p) (p) = (lt_dlfree (p), (lt_ptr) 0); } LT_STMT_END -#define LT_EMALLOC(tp, n) ((tp *) lt_emalloc ((n) * sizeof(tp))) -#define LT_EREALLOC(tp, p, n) ((tp *) lt_erealloc ((p), (n) * sizeof(tp))) +#define LT_EMALLOC(tp, n) ((tp *) lt_emalloc ((n) * sizeof(tp))) +#define LT_EREALLOC(tp, p, n) ((tp *) lt_erealloc ((p), (n) * sizeof(tp))) #endif -#define LT_DLMEM_REASSIGN(p, q) LT_STMT_START { \ - if ((p) != (q)) { if (p) lt_dlfree (p); (p) = (q); (q) = 0; } \ - } LT_STMT_END +#define LT_DLMEM_REASSIGN(p, q) LT_STMT_START { \ + if ((p) != (q)) { if (p) lt_dlfree (p); (p) = (q); (q) = 0; } \ + } LT_STMT_END /* --- REPLACEMENT FUNCTIONS --- */ @@ -215,9 +215,9 @@ strdup(str) { tmp = LT_DLMALLOC (char, 1+ strlen (str)); if (tmp) - { - strcpy(tmp, str); - } + { + strcpy(tmp, str); + } } return tmp; @@ -246,7 +246,7 @@ strcmp (str1, str2) for (;*str1 && *str2; ++str1, ++str2) { if (*str1 != *str2) - break; + break; } return (int)(*str1 - *str2); @@ -299,9 +299,9 @@ strrchr(str, ch) for (p = str; *p != LT_EOS_CHAR; ++p) { if (*p == (char) ch) - { - q = p; - } + { + q = p; + } } return q; @@ -313,11 +313,11 @@ strrchr(str, ch) /* NOTE: Neither bcopy nor the memcpy implementation below can reliably handle copying in overlapping areas of memory. Use memmove (for which there is a fallback implmentation below) - if you need that behaviour. */ + if you need that behaviour. */ #if ! HAVE_MEMCPY # if HAVE_BCOPY -# define memcpy(dest, src, size) bcopy (src, dest, size) +# define memcpy(dest, src, size) bcopy (src, dest, size) # else # define memcpy rpl_memcpy @@ -358,12 +358,12 @@ memmove (dest, src, size) if (dest < src) for (i = 0; i < size; ++i) { - dest[i] = src[i]; + dest[i] = src[i]; } else if (dest > src) for (i = size -1; i >= 0; --i) { - dest[i] = src[i]; + dest[i] = src[i]; } return dest; @@ -391,9 +391,9 @@ realloc (ptr, size) { /* For zero or less bytes, free the original memory */ if (ptr != 0) - { - lt_dlfree (ptr); - } + { + lt_dlfree (ptr); + } return (lt_ptr) 0; } @@ -408,13 +408,13 @@ realloc (ptr, size) lt_ptr mem = lt_dlmalloc (size); if (mem) - { - memcpy (mem, ptr, size); - lt_dlfree (ptr); - } + { + memcpy (mem, ptr, size); + lt_dlfree (ptr); + } /* Note that the contents of PTR are not damaged if there is - insufficient memory to realloc. */ + insufficient memory to realloc. */ return mem; } } @@ -424,7 +424,7 @@ realloc (ptr, size) # define argz_append rpl_argz_append static error_t argz_append LT_PARAMS((char **pargz, size_t *pargz_len, - const char *buf, size_t buf_len)); + const char *buf, size_t buf_len)); static error_t argz_append (pargz, pargz_len, buf, buf_len) @@ -466,7 +466,7 @@ argz_append (pargz, pargz_len, buf, buf_len) # define argz_create_sep rpl_argz_create_sep static error_t argz_create_sep LT_PARAMS((const char *str, int delim, - char **pargz, size_t *pargz_len)); + char **pargz, size_t *pargz_len)); static error_t argz_create_sep (str, delim, pargz, pargz_len) @@ -492,22 +492,22 @@ argz_create_sep (str, delim, pargz, pargz_len) argz = LT_DLMALLOC (char, argz_len); if (!argz) - return ENOMEM; + return ENOMEM; for (p = str, q = argz; *p != LT_EOS_CHAR; ++p) - { - if (*p == delim) - { - /* Ignore leading delimiters, and fold consecutive - delimiters in STR into a single '\0' in ARGZ. */ - if ((q > argz) && (q[-1] != LT_EOS_CHAR)) - *q++ = LT_EOS_CHAR; - else - --argz_len; - } - else - *q++ = *p; - } + { + if (*p == delim) + { + /* Ignore leading delimiters, and fold consecutive + delimiters in STR into a single '\0' in ARGZ. */ + if ((q > argz) && (q[-1] != LT_EOS_CHAR)) + *q++ = LT_EOS_CHAR; + else + --argz_len; + } + else + *q++ = *p; + } /* Copy terminating LT_EOS_CHAR. */ *q = *p; } @@ -529,7 +529,7 @@ argz_create_sep (str, delim, pargz, pargz_len) # define argz_insert rpl_argz_insert static error_t argz_insert LT_PARAMS((char **pargz, size_t *pargz_len, - char *before, const char *entry)); + char *before, const char *entry)); static error_t argz_insert (pargz, pargz_len, before, entry) @@ -545,7 +545,7 @@ argz_insert (pargz, pargz_len, before, entry) /* Either PARGZ/PARGZ_LEN is empty and BEFORE is NULL, or BEFORE points into an address within the ARGZ vector. */ assert ((!*pargz && !*pargz_len && !before) - || ((*pargz <= before) && (before < (*pargz + *pargz_len)))); + || ((*pargz <= before) && (before < (*pargz + *pargz_len)))); /* No BEFORE address indicates ENTRY should be inserted after the current last element. */ @@ -559,10 +559,10 @@ argz_insert (pargz, pargz_len, before, entry) --before; { - size_t entry_len = 1+ LT_STRLEN (entry); - size_t argz_len = *pargz_len + entry_len; - size_t offset = before - *pargz; - char *argz = LT_DLREALLOC (char, *pargz, argz_len); + size_t entry_len = 1+ LT_STRLEN (entry); + size_t argz_len = *pargz_len + entry_len; + size_t offset = before - *pargz; + char *argz = LT_DLREALLOC (char, *pargz, argz_len); if (!argz) return ENOMEM; @@ -591,7 +591,7 @@ argz_insert (pargz, pargz_len, before, entry) # define argz_next rpl_argz_next static char *argz_next LT_PARAMS((char *argz, size_t argz_len, - const char *entry)); + const char *entry)); static char * argz_next (argz, argz_len, entry) @@ -604,28 +604,28 @@ argz_next (argz, argz_len, entry) if (entry) { /* Either ARGZ/ARGZ_LEN is empty, or ENTRY points into an address - within the ARGZ vector. */ + within the ARGZ vector. */ assert ((!argz && !argz_len) - || ((argz <= entry) && (entry < (argz + argz_len)))); + || ((argz <= entry) && (entry < (argz + argz_len)))); /* Move to the char immediately after the terminating - '\0' of ENTRY. */ + '\0' of ENTRY. */ entry = 1+ strchr (entry, LT_EOS_CHAR); /* Return either the new ENTRY, or else NULL if ARGZ is - exhausted. */ + exhausted. */ return (entry >= argz + argz_len) ? 0 : (char *) entry; } else { /* This should probably be flagged as a programmer error, - since starting an argz_next loop with the iterator set - to ARGZ is safer. To preserve semantics, handle the NULL - case by returning the start of ARGZ (if any). */ + since starting an argz_next loop with the iterator set + to ARGZ is safer. To preserve semantics, handle the NULL + case by returning the start of ARGZ (if any). */ if (argz_len > 0) - return argz; + return argz; else - return 0; + return 0; } } #endif /* !HAVE_ARGZ_NEXT */ @@ -636,7 +636,7 @@ argz_next (argz, argz_len, entry) # define argz_stringify rpl_argz_stringify static void argz_stringify LT_PARAMS((char *argz, size_t argz_len, - int sep)); + int sep)); static void argz_stringify (argz, argz_len, sep) @@ -648,12 +648,12 @@ argz_stringify (argz, argz_len, sep) if (sep) { - --argz_len; /* don't stringify the terminating EOS */ + --argz_len; /* don't stringify the terminating EOS */ while (--argz_len > 0) - { - if (argz[argz_len] == LT_EOS_CHAR) - argz[argz_len] = sep; - } + { + if (argz[argz_len] == LT_EOS_CHAR) + argz[argz_len] = sep; + } } } #endif /* !HAVE_ARGZ_STRINGIFY */ @@ -666,8 +666,8 @@ argz_stringify (argz, argz_len, sep) /* This type is used for the array of caller data sets in each handler. */ typedef struct { - lt_dlcaller_id key; - lt_ptr data; + lt_dlcaller_id key; + lt_ptr data; } lt_caller_data; @@ -681,7 +681,7 @@ typedef struct { static const char *lt_dlerror_strings[] = { -#define LT_ERROR(name, diagnostic) (diagnostic), +#define LT_ERROR(name, diagnostic) (diagnostic), lt_dlerror_table #undef LT_ERROR @@ -691,25 +691,25 @@ static const char *lt_dlerror_strings[] = /* This structure is used for the list of registered loaders. */ struct lt_dlloader { struct lt_dlloader *next; - const char *loader_name; /* identifying name for each loader */ - const char *sym_prefix; /* prefix for symbols */ + const char *loader_name; /* identifying name for each loader */ + const char *sym_prefix; /* prefix for symbols */ lt_module_open *module_open; lt_module_close *module_close; - lt_find_sym *find_sym; + lt_find_sym *find_sym; lt_dlloader_exit *dlloader_exit; - lt_user_data dlloader_data; + lt_user_data dlloader_data; }; struct lt_dlhandle_struct { struct lt_dlhandle_struct *next; - lt_dlloader *loader; /* dlopening interface */ - lt_dlinfo info; - int depcount; /* number of dependencies */ - lt_dlhandle *deplibs; /* dependencies */ - lt_module module; /* system module handle */ - lt_ptr system; /* system specific data */ - lt_caller_data *caller_data; /* per caller associated data */ - int flags; /* various boolean stats */ + lt_dlloader *loader; /* dlopening interface */ + lt_dlinfo info; + int depcount; /* number of dependencies */ + lt_dlhandle *deplibs; /* dependencies */ + lt_module module; /* system module handle */ + lt_ptr system; /* system specific data */ + lt_caller_data *caller_data; /* per caller associated data */ + int flags; /* various boolean stats */ }; /* Various boolean flags can be stored in the flags field of an @@ -717,21 +717,21 @@ struct lt_dlhandle_struct { #define LT_DLGET_FLAG(handle, flag) (((handle)->flags & (flag)) == (flag)) #define LT_DLSET_FLAG(handle, flag) ((handle)->flags |= (flag)) -#define LT_DLRESIDENT_FLAG (0x01 << 0) +#define LT_DLRESIDENT_FLAG (0x01 << 0) /* ...add more flags here... */ #define LT_DLIS_RESIDENT(handle) LT_DLGET_FLAG(handle, LT_DLRESIDENT_FLAG) -#define LT_DLSTRERROR(name) lt_dlerror_strings[LT_CONC(LT_ERROR_,name)] +#define LT_DLSTRERROR(name) lt_dlerror_strings[LT_CONC(LT_ERROR_,name)] -static const char objdir[] = LTDL_OBJDIR; -static const char archive_ext[] = LTDL_ARCHIVE_EXT; -#ifdef LTDL_SHLIB_EXT -static const char shlib_ext[] = LTDL_SHLIB_EXT; +static const char objdir[] = LTDL_OBJDIR; +static const char archive_ext[] = LTDL_ARCHIVE_EXT; +#ifdef LTDL_SHLIB_EXT +static const char shlib_ext[] = LTDL_SHLIB_EXT; #endif -#ifdef LTDL_SYSSEARCHPATH -static const char sys_search_path[] = LTDL_SYSSEARCHPATH; +#ifdef LTDL_SYSSEARCHPATH +static const char sys_search_path[] = LTDL_SYSSEARCHPATH; #endif @@ -745,28 +745,28 @@ static const char sys_search_path[] = LTDL_SYSSEARCHPATH; ensure that the stored error message from the last error is not accidentally erased if the current function doesn't generate an error of its own. */ -#define LT_DLMUTEX_LOCK() LT_STMT_START { \ - if (lt_dlmutex_lock_func) (*lt_dlmutex_lock_func)(); \ - } LT_STMT_END -#define LT_DLMUTEX_UNLOCK() LT_STMT_START { \ - if (lt_dlmutex_unlock_func) (*lt_dlmutex_unlock_func)();\ - } LT_STMT_END -#define LT_DLMUTEX_SETERROR(errormsg) LT_STMT_START { \ - if (lt_dlmutex_seterror_func) \ - (*lt_dlmutex_seterror_func) (errormsg); \ - else lt_dllast_error = (errormsg); } LT_STMT_END -#define LT_DLMUTEX_GETERROR(errormsg) LT_STMT_START { \ - if (lt_dlmutex_seterror_func) \ - (errormsg) = (*lt_dlmutex_geterror_func) (); \ - else (errormsg) = lt_dllast_error; } LT_STMT_END +#define LT_DLMUTEX_LOCK() LT_STMT_START { \ + if (lt_dlmutex_lock_func) (*lt_dlmutex_lock_func)(); \ + } LT_STMT_END +#define LT_DLMUTEX_UNLOCK() LT_STMT_START { \ + if (lt_dlmutex_unlock_func) (*lt_dlmutex_unlock_func)();\ + } LT_STMT_END +#define LT_DLMUTEX_SETERROR(errormsg) LT_STMT_START { \ + if (lt_dlmutex_seterror_func) \ + (*lt_dlmutex_seterror_func) (errormsg); \ + else lt_dllast_error = (errormsg); } LT_STMT_END +#define LT_DLMUTEX_GETERROR(errormsg) LT_STMT_START { \ + if (lt_dlmutex_seterror_func) \ + (errormsg) = (*lt_dlmutex_geterror_func) (); \ + else (errormsg) = lt_dllast_error; } LT_STMT_END /* The mutex functions stored here are global, and are necessarily the same for all threads that wish to share access to libltdl. */ -static lt_dlmutex_lock *lt_dlmutex_lock_func = 0; -static lt_dlmutex_unlock *lt_dlmutex_unlock_func = 0; -static lt_dlmutex_seterror *lt_dlmutex_seterror_func = 0; -static lt_dlmutex_geterror *lt_dlmutex_geterror_func = 0; -static const char *lt_dllast_error = 0; +static lt_dlmutex_lock *lt_dlmutex_lock_func = 0; +static lt_dlmutex_unlock *lt_dlmutex_unlock_func = 0; +static lt_dlmutex_seterror *lt_dlmutex_seterror_func = 0; +static lt_dlmutex_geterror *lt_dlmutex_geterror_func = 0; +static const char *lt_dllast_error = 0; /* Either set or reset the mutex functions. Either all the arguments must @@ -781,7 +781,7 @@ lt_dlmutex_register (lock, unlock, seterror, geterror) lt_dlmutex_geterror *geterror; { lt_dlmutex_unlock *old_unlock = unlock; - int errors = 0; + int errors = 0; /* Lock using the old lock() callback, if any. */ LT_DLMUTEX_LOCK (); @@ -815,15 +815,15 @@ lt_dlmutex_register (lock, unlock, seterror, geterror) /* --- ERROR HANDLING --- */ -static const char **user_error_strings = 0; -static int errorcount = LT_ERROR_MAX; +static const char **user_error_strings = 0; +static int errorcount = LT_ERROR_MAX; int lt_dladderror (diagnostic) const char *diagnostic; { - int errindex = 0; - int result = -1; + int errindex = 0; + int result = -1; const char **temp = (const char **) 0; assert (diagnostic); @@ -834,9 +834,9 @@ lt_dladderror (diagnostic) temp = LT_EREALLOC (const char *, user_error_strings, 1 + errindex); if (temp) { - user_error_strings = temp; - user_error_strings[errindex] = diagnostic; - result = errorcount++; + user_error_strings = temp; + user_error_strings[errindex] = diagnostic; + result = errorcount++; } LT_DLMUTEX_UNLOCK (); @@ -848,7 +848,7 @@ int lt_dlseterror (errindex) int errindex; { - int errors = 0; + int errors = 0; LT_DLMUTEX_LOCK (); @@ -928,44 +928,44 @@ lt_estrdup (str) #endif #ifdef RTLD_GLOBAL -# define LT_GLOBAL RTLD_GLOBAL +# define LT_GLOBAL RTLD_GLOBAL #else # ifdef DL_GLOBAL -# define LT_GLOBAL DL_GLOBAL +# define LT_GLOBAL DL_GLOBAL # endif #endif /* !RTLD_GLOBAL */ #ifndef LT_GLOBAL -# define LT_GLOBAL 0 +# define LT_GLOBAL 0 #endif /* !LT_GLOBAL */ /* We may have to define LT_LAZY_OR_NOW in the command line if we find out it does not work in some platform. */ #ifndef LT_LAZY_OR_NOW # ifdef RTLD_LAZY -# define LT_LAZY_OR_NOW RTLD_LAZY +# define LT_LAZY_OR_NOW RTLD_LAZY # else # ifdef DL_LAZY -# define LT_LAZY_OR_NOW DL_LAZY +# define LT_LAZY_OR_NOW DL_LAZY # endif # endif /* !RTLD_LAZY */ #endif #ifndef LT_LAZY_OR_NOW # ifdef RTLD_NOW -# define LT_LAZY_OR_NOW RTLD_NOW +# define LT_LAZY_OR_NOW RTLD_NOW # else # ifdef DL_NOW -# define LT_LAZY_OR_NOW DL_NOW +# define LT_LAZY_OR_NOW DL_NOW # endif # endif /* !RTLD_NOW */ #endif #ifndef LT_LAZY_OR_NOW -# define LT_LAZY_OR_NOW 0 +# define LT_LAZY_OR_NOW 0 #endif /* !LT_LAZY_OR_NOW */ #if HAVE_DLERROR -# define DLERROR(arg) dlerror () +# define DLERROR(arg) dlerror () #else -# define DLERROR(arg) LT_DLSTRERROR (arg) +# define DLERROR(arg) LT_DLSTRERROR (arg) #endif static lt_module @@ -1047,37 +1047,37 @@ static struct lt_user_dlloader sys_dl = * BIND_DEFERRED - Delay code symbol resolution until actual reference. * * Optionally: - * BIND_FIRST - Place the library at the head of the symbol search - * order. + * BIND_FIRST - Place the library at the head of the symbol search + * order. * BIND_NONFATAL - The default BIND_IMMEDIATE behavior is to treat all - * unsatisfied symbols as fatal. This flag allows - * binding of unsatisfied code symbols to be deferred - * until use. - * [Perl: For certain libraries, like DCE, deferred - * binding often causes run time problems. Adding - * BIND_NONFATAL to BIND_IMMEDIATE still allows - * unresolved references in situations like this.] - * BIND_NOSTART - Do not call the initializer for the shared library - * when the library is loaded, nor on a future call to - * shl_unload(). - * BIND_VERBOSE - Print verbose messages concerning possible - * unsatisfied symbols. + * unsatisfied symbols as fatal. This flag allows + * binding of unsatisfied code symbols to be deferred + * until use. + * [Perl: For certain libraries, like DCE, deferred + * binding often causes run time problems. Adding + * BIND_NONFATAL to BIND_IMMEDIATE still allows + * unresolved references in situations like this.] + * BIND_NOSTART - Do not call the initializer for the shared library + * when the library is loaded, nor on a future call to + * shl_unload(). + * BIND_VERBOSE - Print verbose messages concerning possible + * unsatisfied symbols. * * hp9000s700/hp9000s800: * BIND_RESTRICTED - Restrict symbols visible by the library to those - * present at library load time. - * DYNAMIC_PATH - Allow the loader to dynamically search for the - * library specified by the path argument. + * present at library load time. + * DYNAMIC_PATH - Allow the loader to dynamically search for the + * library specified by the path argument. */ -#ifndef DYNAMIC_PATH -# define DYNAMIC_PATH 0 +#ifndef DYNAMIC_PATH +# define DYNAMIC_PATH 0 #endif -#ifndef BIND_RESTRICTED -# define BIND_RESTRICTED 0 +#ifndef BIND_RESTRICTED +# define BIND_RESTRICTED 0 #endif -#define LT_BIND_FLAGS (BIND_IMMEDIATE | BIND_NONFATAL | DYNAMIC_PATH) +#define LT_BIND_FLAGS (BIND_IMMEDIATE | BIND_NONFATAL | DYNAMIC_PATH) static lt_module sys_shl_open (loader_data, filename) @@ -1106,9 +1106,9 @@ sys_shl_open (loader_data, filename) module = shl_load (filename, LT_BIND_FLAGS, 0L); if (!module) - { - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN)); - } + { + LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN)); + } } return module; @@ -1146,9 +1146,9 @@ sys_shl_sym (loader_data, module, symbol) else if (!shl_findsym((shl_t*) &module, symbol, TYPE_UNDEFINED, &address)) { if (!address) - { - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND)); - } + { + LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND)); + } } return address; @@ -1179,12 +1179,12 @@ sys_wll_open (loader_data, filename) lt_user_data loader_data; const char *filename; { - lt_dlhandle cur; - lt_module module = 0; + lt_dlhandle cur; + lt_module module = 0; const char *errormsg = 0; - char *searchname = 0; - char *ext; - char self_name_buf[MAX_PATH]; + char *searchname = 0; + char *ext; + char self_name_buf[MAX_PATH]; if (!filename) { @@ -1206,10 +1206,10 @@ sys_wll_open (loader_data, filename) else { /* Append a `.' to stop Windows from adding an - implicit `.dll' extension. */ + implicit `.dll' extension. */ searchname = LT_EMALLOC (char, 2+ LT_STRLEN (filename)); if (searchname) - sprintf (searchname, "%s.", filename); + sprintf (searchname, "%s.", filename); } if (!searchname) return 0; @@ -1238,15 +1238,15 @@ sys_wll_open (loader_data, filename) while (cur) { if (!cur->module) - { - cur = 0; - break; - } + { + cur = 0; + break; + } if (cur->module == module) - { - break; - } + { + break; + } cur = cur->next; } @@ -1266,7 +1266,7 @@ sys_wll_close (loader_data, module) lt_user_data loader_data; lt_module module; { - int errors = 0; + int errors = 0; if (FreeLibrary(module) == 0) { @@ -1327,7 +1327,7 @@ sys_bedl_open (loader_data, filename) image_info info; int32 cookie = 0; if (get_next_image_info (0, &cookie, &info) == B_OK) - image = load_add_on (info.name); + image = load_add_on (info.name); } if (image <= 0) @@ -1463,11 +1463,11 @@ static struct lt_user_dlloader sys_dld = { typedef struct lt_dlsymlists_t { struct lt_dlsymlists_t *next; - const lt_dlsymlist *syms; + const lt_dlsymlist *syms; } lt_dlsymlists_t; -static const lt_dlsymlist *default_preloaded_symbols = 0; -static lt_dlsymlists_t *preloaded_symbols = 0; +static const lt_dlsymlist *default_preloaded_symbols = 0; +static lt_dlsymlists_t *preloaded_symbols = 0; static int presym_init (loader_data) @@ -1498,7 +1498,7 @@ presym_free_symlists () lists = preloaded_symbols; while (lists) { - lt_dlsymlists_t *tmp = lists; + lt_dlsymlists_t *tmp = lists; lists = lists->next; LT_DLFREE (tmp); @@ -1524,7 +1524,7 @@ presym_add_symlist (preloaded) { lt_dlsymlists_t *tmp; lt_dlsymlists_t *lists; - int errors = 0; + int errors = 0; LT_DLMUTEX_LOCK (); @@ -1532,9 +1532,9 @@ presym_add_symlist (preloaded) while (lists) { if (lists->syms == preloaded) - { - goto done; - } + { + goto done; + } lists = lists->next; } @@ -1562,7 +1562,7 @@ presym_open (loader_data, filename) const char *filename; { lt_dlsymlists_t *lists; - lt_module module = (lt_module) 0; + lt_module module = (lt_module) 0; LT_DLMUTEX_LOCK (); lists = preloaded_symbols; @@ -1587,14 +1587,14 @@ presym_open (loader_data, filename) const lt_dlsymlist *syms = lists->syms; while (syms->name) - { - if (!syms->address && strcmp(syms->name, filename) == 0) - { - module = (lt_module) syms; - goto done; - } - ++syms; - } + { + if (!syms->address && strcmp(syms->name, filename) == 0) + { + module = (lt_module) syms; + goto done; + } + ++syms; + } lists = lists->next; } @@ -1628,9 +1628,9 @@ presym_sym (loader_data, module, symbol) while (syms->address) { if (strcmp(syms->name, symbol) == 0) - { - return syms->address; - } + { + return syms->address; + } ++syms; } @@ -1652,79 +1652,79 @@ static struct lt_user_dlloader presym = { /* The type of a function used at each iteration of foreach_dirinpath(). */ -typedef int foreach_callback_func LT_PARAMS((char *filename, lt_ptr data1, - lt_ptr data2)); - -static int foreach_dirinpath LT_PARAMS((const char *search_path, - const char *base_name, - foreach_callback_func *func, - lt_ptr data1, lt_ptr data2)); - -static int find_file_callback LT_PARAMS((char *filename, lt_ptr data, - lt_ptr ignored)); -static int find_handle_callback LT_PARAMS((char *filename, lt_ptr data, - lt_ptr ignored)); -static int foreachfile_callback LT_PARAMS((char *filename, lt_ptr data1, - lt_ptr data2)); - - -static int canonicalize_path LT_PARAMS((const char *path, - char **pcanonical)); -static int argzize_path LT_PARAMS((const char *path, - char **pargz, - size_t *pargz_len)); -static FILE *find_file LT_PARAMS((const char *search_path, - const char *base_name, - char **pdir)); -static lt_dlhandle *find_handle LT_PARAMS((const char *search_path, - const char *base_name, - lt_dlhandle *handle)); -static int find_module LT_PARAMS((lt_dlhandle *handle, - const char *dir, - const char *libdir, - const char *dlname, - const char *old_name, - int installed)); -static int free_vars LT_PARAMS((char *dlname, char *oldname, - char *libdir, char *deplibs)); -static int load_deplibs LT_PARAMS((lt_dlhandle handle, - char *deplibs)); -static int trim LT_PARAMS((char **dest, - const char *str)); -static int try_dlopen LT_PARAMS((lt_dlhandle *handle, - const char *filename)); -static int tryall_dlopen LT_PARAMS((lt_dlhandle *handle, - const char *filename)); -static int unload_deplibs LT_PARAMS((lt_dlhandle handle)); -static int lt_argz_insert LT_PARAMS((char **pargz, - size_t *pargz_len, - char *before, - const char *entry)); -static int lt_argz_insertinorder LT_PARAMS((char **pargz, - size_t *pargz_len, - const char *entry)); -static int lt_argz_insertdir LT_PARAMS((char **pargz, - size_t *pargz_len, - const char *dirnam, - struct dirent *dp)); -static int lt_dlpath_insertdir LT_PARAMS((char **ppath, - char *before, - const char *dir)); -static int list_files_by_dir LT_PARAMS((const char *dirnam, - char **pargz, - size_t *pargz_len)); -static int file_not_found LT_PARAMS((void)); - -static char *user_search_path= 0; -static lt_dlloader *loaders = 0; -static lt_dlhandle handles = 0; -static int initialized = 0; +typedef int foreach_callback_func LT_PARAMS((char *filename, lt_ptr data1, + lt_ptr data2)); + +static int foreach_dirinpath LT_PARAMS((const char *search_path, + const char *base_name, + foreach_callback_func *func, + lt_ptr data1, lt_ptr data2)); + +static int find_file_callback LT_PARAMS((char *filename, lt_ptr data, + lt_ptr ignored)); +static int find_handle_callback LT_PARAMS((char *filename, lt_ptr data, + lt_ptr ignored)); +static int foreachfile_callback LT_PARAMS((char *filename, lt_ptr data1, + lt_ptr data2)); + + +static int canonicalize_path LT_PARAMS((const char *path, + char **pcanonical)); +static int argzize_path LT_PARAMS((const char *path, + char **pargz, + size_t *pargz_len)); +static FILE *find_file LT_PARAMS((const char *search_path, + const char *base_name, + char **pdir)); +static lt_dlhandle *find_handle LT_PARAMS((const char *search_path, + const char *base_name, + lt_dlhandle *handle)); +static int find_module LT_PARAMS((lt_dlhandle *handle, + const char *dir, + const char *libdir, + const char *dlname, + const char *old_name, + int installed)); +static int free_vars LT_PARAMS((char *dlname, char *oldname, + char *libdir, char *deplibs)); +static int load_deplibs LT_PARAMS((lt_dlhandle handle, + char *deplibs)); +static int trim LT_PARAMS((char **dest, + const char *str)); +static int try_dlopen LT_PARAMS((lt_dlhandle *handle, + const char *filename)); +static int tryall_dlopen LT_PARAMS((lt_dlhandle *handle, + const char *filename)); +static int unload_deplibs LT_PARAMS((lt_dlhandle handle)); +static int lt_argz_insert LT_PARAMS((char **pargz, + size_t *pargz_len, + char *before, + const char *entry)); +static int lt_argz_insertinorder LT_PARAMS((char **pargz, + size_t *pargz_len, + const char *entry)); +static int lt_argz_insertdir LT_PARAMS((char **pargz, + size_t *pargz_len, + const char *dirnam, + struct dirent *dp)); +static int lt_dlpath_insertdir LT_PARAMS((char **ppath, + char *before, + const char *dir)); +static int list_files_by_dir LT_PARAMS((const char *dirnam, + char **pargz, + size_t *pargz_len)); +static int file_not_found LT_PARAMS((void)); + +static char *user_search_path= 0; +static lt_dlloader *loaders = 0; +static lt_dlhandle handles = 0; +static int initialized = 0; /* Initialize libltdl. */ int lt_dlinit () { - int errors = 0; + int errors = 0; LT_DLMUTEX_LOCK (); @@ -1752,15 +1752,15 @@ lt_dlinit () errors += lt_dlloader_add (lt_dlloader_next (0), &presym, "dlpreload"); if (presym_init (presym.dlloader_data)) - { - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INIT_LOADER)); - ++errors; - } + { + LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INIT_LOADER)); + ++errors; + } else if (errors != 0) - { - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (DLOPEN_NOT_SUPPORTED)); - ++errors; - } + { + LT_DLMUTEX_SETERROR (LT_DLSTRERROR (DLOPEN_NOT_SUPPORTED)); + ++errors; + } } LT_DLMUTEX_UNLOCK (); @@ -1784,9 +1784,9 @@ lt_dlpreload (preloaded) LT_DLMUTEX_LOCK (); if (default_preloaded_symbols) - { - errors = lt_dlpreload (default_preloaded_symbols); - } + { + errors = lt_dlpreload (default_preloaded_symbols); + } LT_DLMUTEX_UNLOCK (); } @@ -1808,7 +1808,7 @@ lt_dlexit () { /* shut down libltdl */ lt_dlloader *loader; - int errors = 0; + int errors = 0; LT_DLMUTEX_LOCK (); loader = loaders; @@ -1823,50 +1823,50 @@ lt_dlexit () /* shut down only at last call. */ if (--initialized == 0) { - int level; + int level; while (handles && LT_DLIS_RESIDENT (handles)) - { - handles = handles->next; - } + { + handles = handles->next; + } /* close all modules */ for (level = 1; handles; ++level) - { - lt_dlhandle cur = handles; - int saw_nonresident = 0; - - while (cur) - { - lt_dlhandle tmp = cur; - cur = cur->next; - if (!LT_DLIS_RESIDENT (tmp)) - saw_nonresident = 1; - if (!LT_DLIS_RESIDENT (tmp) && tmp->info.ref_count <= level) - { - if (lt_dlclose (tmp)) - { - ++errors; - } - } - } - /* done if only resident modules are left */ - if (!saw_nonresident) - break; - } + { + lt_dlhandle cur = handles; + int saw_nonresident = 0; + + while (cur) + { + lt_dlhandle tmp = cur; + cur = cur->next; + if (!LT_DLIS_RESIDENT (tmp)) + saw_nonresident = 1; + if (!LT_DLIS_RESIDENT (tmp) && tmp->info.ref_count <= level) + { + if (lt_dlclose (tmp)) + { + ++errors; + } + } + } + /* done if only resident modules are left */ + if (!saw_nonresident) + break; + } /* close all loaders */ while (loader) - { - lt_dlloader *next = loader->next; - lt_user_data data = loader->dlloader_data; - if (loader->dlloader_exit && loader->dlloader_exit (data)) - { - ++errors; - } - - LT_DLMEM_REASSIGN (loader, next); - } + { + lt_dlloader *next = loader->next; + lt_user_data data = loader->dlloader_data; + if (loader->dlloader_exit && loader->dlloader_exit (data)) + { + ++errors; + } + + LT_DLMEM_REASSIGN (loader, next); + } loaders = 0; } @@ -1880,15 +1880,15 @@ tryall_dlopen (handle, filename) lt_dlhandle *handle; const char *filename; { - lt_dlhandle cur; + lt_dlhandle cur; lt_dlloader *loader; - const char *saved_error; - int errors = 0; + const char *saved_error; + int errors = 0; LT_DLMUTEX_GETERROR (saved_error); LT_DLMUTEX_LOCK (); - cur = handles; + cur = handles; loader = loaders; /* check whether the module was already opened */ @@ -1896,15 +1896,15 @@ tryall_dlopen (handle, filename) { /* try to dlopen the program itself? */ if (!cur->info.filename && !filename) - { - break; - } + { + break; + } if (cur->info.filename && filename - && strcmp (cur->info.filename, filename) == 0) - { - break; - } + && strcmp (cur->info.filename, filename) == 0) + { + break; + } cur = cur->next; } @@ -1921,10 +1921,10 @@ tryall_dlopen (handle, filename) { cur->info.filename = lt_estrdup (filename); if (!cur->info.filename) - { - ++errors; - goto done; - } + { + ++errors; + goto done; + } } else { @@ -1938,9 +1938,9 @@ tryall_dlopen (handle, filename) cur->module = loader->module_open (data, filename); if (cur->module != 0) - { - break; - } + { + break; + } loader = loader->next; } @@ -1951,7 +1951,7 @@ tryall_dlopen (handle, filename) goto done; } - cur->loader = loader; + cur->loader = loader; LT_DLMUTEX_SETERROR (saved_error); done: @@ -1967,10 +1967,10 @@ tryall_dlopen_module (handle, prefix, dirname, dlname) const char *dirname; const char *dlname; { - int error = 0; - char *filename = 0; - size_t filename_len = 0; - size_t dirname_len = LT_STRLEN (dirname); + int error = 0; + char *filename = 0; + size_t filename_len = 0; + size_t dirname_len = LT_STRLEN (dirname); assert (handle); assert (dirname); @@ -1999,7 +1999,7 @@ tryall_dlopen_module (handle, prefix, dirname, dlname) if (prefix) { error += tryall_dlopen_module (handle, - (const char *) 0, prefix, filename); + (const char *) 0, prefix, filename); } else if (tryall_dlopen (handle, filename) != 0) { @@ -2032,24 +2032,24 @@ find_module (handle, dir, libdir, dlname, old_name, installed) { /* try to open the installed module */ if (installed && libdir) - { - if (tryall_dlopen_module (handle, - (const char *) 0, libdir, dlname) == 0) - return 0; - } + { + if (tryall_dlopen_module (handle, + (const char *) 0, libdir, dlname) == 0) + return 0; + } /* try to open the not-installed module */ if (!installed) - { - if (tryall_dlopen_module (handle, dir, objdir, dlname) == 0) - return 0; - } + { + if (tryall_dlopen_module (handle, dir, objdir, dlname) == 0) + return 0; + } /* maybe it was moved to another directory */ { - if (tryall_dlopen_module (handle, - (const char *) 0, dir, dlname) == 0) - return 0; + if (tryall_dlopen_module (handle, + (const char *) 0, dir, dlname) == 0) + return 0; } } @@ -2076,38 +2076,38 @@ canonicalize_path (path, pcanonical) size_t src; for (src = 0; path[src] != LT_EOS_CHAR; ++src) { - /* Path separators are not copied to the beginning or end of - the destination, or if another separator would follow - immediately. */ - if (path[src] == LT_PATHSEP_CHAR) - { - if ((dest == 0) - || (path[1+ src] == LT_PATHSEP_CHAR) - || (path[1+ src] == LT_EOS_CHAR)) - continue; - } - - /* Anything other than a directory separator is copied verbatim. */ - if ((path[src] != '/') + /* Path separators are not copied to the beginning or end of + the destination, or if another separator would follow + immediately. */ + if (path[src] == LT_PATHSEP_CHAR) + { + if ((dest == 0) + || (path[1+ src] == LT_PATHSEP_CHAR) + || (path[1+ src] == LT_EOS_CHAR)) + continue; + } + + /* Anything other than a directory separator is copied verbatim. */ + if ((path[src] != '/') #ifdef LT_DIRSEP_CHAR - && (path[src] != LT_DIRSEP_CHAR) + && (path[src] != LT_DIRSEP_CHAR) #endif - ) - { - canonical[dest++] = path[src]; - } - /* Directory separators are converted and copied only if they are - not at the end of a path -- i.e. before a path separator or - NULL terminator. */ - else if ((path[1+ src] != LT_PATHSEP_CHAR) - && (path[1+ src] != LT_EOS_CHAR) + ) + { + canonical[dest++] = path[src]; + } + /* Directory separators are converted and copied only if they are + not at the end of a path -- i.e. before a path separator or + NULL terminator. */ + else if ((path[1+ src] != LT_PATHSEP_CHAR) + && (path[1+ src] != LT_EOS_CHAR) #ifdef LT_DIRSEP_CHAR - && (path[1+ src] != LT_DIRSEP_CHAR) + && (path[1+ src] != LT_DIRSEP_CHAR) #endif - && (path[1+ src] != '/')) - { - canonical[dest++] = '/'; - } + && (path[1+ src] != '/')) + { + canonical[dest++] = '/'; + } } /* Add an end-of-string marker at the end. */ @@ -2135,14 +2135,14 @@ argzize_path (path, pargz, pargz_len) if ((error = argz_create_sep (path, LT_PATHSEP_CHAR, pargz, pargz_len))) { switch (error) - { - case ENOMEM: - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY)); - break; - default: - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (UNKNOWN)); - break; - } + { + case ENOMEM: + LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY)); + break; + default: + LT_DLMUTEX_SETERROR (LT_DLSTRERROR (UNKNOWN)); + break; + } return 1; } @@ -2162,13 +2162,13 @@ foreach_dirinpath (search_path, base_name, func, data1, data2) lt_ptr data1; lt_ptr data2; { - int result = 0; - int filenamesize = 0; - size_t lenbase = LT_STRLEN (base_name); - size_t argz_len = 0; - char *argz = 0; - char *filename = 0; - char *canonical = 0; + int result = 0; + int filenamesize = 0; + size_t lenbase = LT_STRLEN (base_name); + size_t argz_len = 0; + char *argz = 0; + char *filename = 0; + char *canonical = 0; LT_DLMUTEX_LOCK (); @@ -2188,29 +2188,29 @@ foreach_dirinpath (search_path, base_name, func, data1, data2) char *dir_name = 0; while ((dir_name = argz_next (argz, argz_len, dir_name))) { - size_t lendir = LT_STRLEN (dir_name); - - if (lendir +1 +lenbase >= filenamesize) - { - LT_DLFREE (filename); - filenamesize = lendir +1 +lenbase +1; /* "/d" + '/' + "f" + '\0' */ - filename = LT_EMALLOC (char, filenamesize); - if (!filename) - goto cleanup; - } - - strncpy (filename, dir_name, lendir); - if (base_name && *base_name) - { - if (filename[lendir -1] != '/') - filename[lendir++] = '/'; - strcpy (filename +lendir, base_name); - } - - if ((result = (*func) (filename, data1, data2))) - { - break; - } + size_t lendir = LT_STRLEN (dir_name); + + if (lendir +1 +lenbase >= filenamesize) + { + LT_DLFREE (filename); + filenamesize = lendir +1 +lenbase +1; /* "/d" + '/' + "f" + '\0' */ + filename = LT_EMALLOC (char, filenamesize); + if (!filename) + goto cleanup; + } + + strncpy (filename, dir_name, lendir); + if (base_name && *base_name) + { + if (filename[lendir -1] != '/') + filename[lendir++] = '/'; + strcpy (filename +lendir, base_name); + } + + if ((result = (*func) (filename, data1, data2))) + { + break; + } } } @@ -2233,9 +2233,9 @@ find_file_callback (filename, data1, data2) lt_ptr data1; lt_ptr data2; { - char **pdir = (char **) data1; - FILE **pfile = (FILE **) data2; - int is_done = 0; + char **pdir = (char **) data1; + FILE **pfile = (FILE **) data2; + int is_done = 0; assert (filename && *filename); assert (pdir); @@ -2246,7 +2246,7 @@ find_file_callback (filename, data1, data2) char *dirend = strrchr (filename, '/'); if (dirend > filename) - *dirend = LT_EOS_CHAR; + *dirend = LT_EOS_CHAR; LT_DLFREE (*pdir); *pdir = lt_estrdup (filename); @@ -2275,8 +2275,8 @@ find_handle_callback (filename, data, ignored) lt_ptr data; lt_ptr ignored; { - lt_dlhandle *handle = (lt_dlhandle *) data; - int found = access (filename, R_OK); + lt_dlhandle *handle = (lt_dlhandle *) data; + int found = access (filename, R_OK); /* Bail out if file cannot be read... */ if (!found) @@ -2302,7 +2302,7 @@ find_handle (search_path, base_name, handle) return 0; if (!foreach_dirinpath (search_path, base_name, find_handle_callback, - handle, 0)) + handle, 0)) return 0; return handle; @@ -2314,12 +2314,12 @@ load_deplibs (handle, deplibs) char *deplibs; { #if LTDL_DLOPEN_DEPLIBS - char *p, *save_search_path = 0; + char *p, *save_search_path = 0; int depcount = 0; - int i; - char **names = 0; + int i; + char **names = 0; #endif - int errors = 0; + int errors = 0; handle->depcount = 0; @@ -2335,7 +2335,7 @@ load_deplibs (handle, deplibs) { save_search_path = lt_estrdup (user_search_path); if (!save_search_path) - goto cleanup; + goto cleanup; } /* extract search paths and count deplibs */ @@ -2343,34 +2343,34 @@ load_deplibs (handle, deplibs) while (*p) { if (!isspace ((int) *p)) - { - char *end = p+1; - while (*end && !isspace((int) *end)) - { - ++end; - } - - if (strncmp(p, "-L", 2) == 0 || strncmp(p, "-R", 2) == 0) - { - char save = *end; - *end = 0; /* set a temporary string terminator */ - if (lt_dladdsearchdir(p+2)) - { - goto cleanup; - } - *end = save; - } - else - { - ++depcount; - } - - p = end; - } + { + char *end = p+1; + while (*end && !isspace((int) *end)) + { + ++end; + } + + if (strncmp(p, "-L", 2) == 0 || strncmp(p, "-R", 2) == 0) + { + char save = *end; + *end = 0; /* set a temporary string terminator */ + if (lt_dladdsearchdir(p+2)) + { + goto cleanup; + } + *end = save; + } + else + { + ++depcount; + } + + p = end; + } else - { - ++p; - } + { + ++p; + } } /* restore the old search path */ @@ -2394,41 +2394,41 @@ load_deplibs (handle, deplibs) p = deplibs; while (*p) { - if (isspace ((int) *p)) - { - ++p; - } + if (isspace ((unsigned char) *p)) + { + ++p; + } else - { - char *end = p+1; - while (*end && !isspace ((int) *end)) - { - ++end; - } - - if (strncmp(p, "-L", 2) != 0 && strncmp(p, "-R", 2) != 0) - { - char *name; - char save = *end; - *end = 0; /* set a temporary string terminator */ - if (strncmp(p, "-l", 2) == 0) - { - size_t name_len = 3+ /* "lib" */ LT_STRLEN (p + 2); - name = LT_EMALLOC (char, 1+ name_len); - if (name) - sprintf (name, "lib%s", p+2); - } - else - name = lt_estrdup(p); - - if (!name) - goto cleanup_names; - - names[depcount++] = name; - *end = save; - } - p = end; - } + { + char *end = p+1; + while (*end && !isspace ((unsigned char) *end)) + { + ++end; + } + + if (strncmp(p, "-L", 2) != 0 && strncmp(p, "-R", 2) != 0) + { + char *name; + char save = *end; + *end = 0; /* set a temporary string terminator */ + if (strncmp(p, "-l", 2) == 0) + { + size_t name_len = 3+ /* "lib" */ LT_STRLEN (p + 2); + name = LT_EMALLOC (char, 1+ name_len); + if (name) + sprintf (name, "lib%s", p+2); + } + else + name = lt_estrdup(p); + + if (!name) + goto cleanup_names; + + names[depcount++] = name; + *end = save; + } + p = end; + } } /* load the deplibs (in reverse order) @@ -2438,23 +2438,23 @@ load_deplibs (handle, deplibs) later on if the loaded module cannot resolve all of its symbols. */ if (depcount) { - int j = 0; + int j = 0; handle->deplibs = (lt_dlhandle*) LT_EMALLOC (lt_dlhandle *, depcount); if (!handle->deplibs) - goto cleanup; + goto cleanup; for (i = 0; i < depcount; ++i) - { - handle->deplibs[j] = lt_dlopenext(names[depcount-1-i]); - if (handle->deplibs[j]) - { - ++j; - } - } + { + handle->deplibs[j] = lt_dlopenext(names[depcount-1-i]); + if (handle->deplibs[j]) + { + ++j; + } + } - handle->depcount = j; /* Number of successfully loaded deplibs */ - errors = 0; + handle->depcount = j; /* Number of successfully loaded deplibs */ + errors = 0; } cleanup_names: @@ -2480,12 +2480,12 @@ unload_deplibs (handle) if (handle->depcount) { for (i = 0; i < handle->depcount; ++i) - { - if (!LT_DLIS_RESIDENT (handle->deplibs[i])) - { - errors += lt_dlclose (handle->deplibs[i]); - } - } + { + if (!LT_DLIS_RESIDENT (handle->deplibs[i])) + { + errors += lt_dlclose (handle->deplibs[i]); + } + } } return errors; @@ -2499,7 +2499,7 @@ trim (dest, str) /* remove the leading and trailing "'" from str and store the result in dest */ const char *end = strrchr (str, '\''); - size_t len = LT_STRLEN (str); + size_t len = LT_STRLEN (str); char *tmp; LT_DLFREE (*dest); @@ -2508,7 +2508,7 @@ trim (dest, str) { tmp = LT_EMALLOC (char, end - str); if (!tmp) - return 1; + return 1; strncpy(tmp, &str[1], (end - str) - 1); tmp[len-3] = LT_EOS_CHAR; @@ -2542,14 +2542,14 @@ try_dlopen (phandle, filename) lt_dlhandle *phandle; const char *filename; { - const char * ext = 0; - const char * saved_error = 0; - char * canonical = 0; - char * base_name = 0; - char * dir = 0; - char * name = 0; - int errors = 0; - lt_dlhandle newhandle; + const char * ext = 0; + const char * saved_error = 0; + char * canonical = 0; + char * base_name = 0; + char * dir = 0; + char * name = 0; + int errors = 0; + lt_dlhandle newhandle; assert (phandle); assert (*phandle == 0); @@ -2561,19 +2561,19 @@ try_dlopen (phandle, filename) { *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); if (*phandle == 0) - return 1; + return 1; memset (*phandle, 0, sizeof(struct lt_dlhandle_struct)); - newhandle = *phandle; + newhandle = *phandle; /* lt_dlclose()ing yourself is very bad! Disallow it. */ LT_DLSET_FLAG (*phandle, LT_DLRESIDENT_FLAG); if (tryall_dlopen (&newhandle, 0) != 0) - { - LT_DLFREE (*phandle); - return 1; - } + { + LT_DLFREE (*phandle); + return 1; + } goto register_handle; } @@ -2597,10 +2597,10 @@ try_dlopen (phandle, filename) dir = LT_EMALLOC (char, 1+ dirlen); if (!dir) - { - ++errors; - goto cleanup; - } + { + ++errors; + goto cleanup; + } strncpy (dir, canonical, dirlen); dir[dirlen] = LT_EOS_CHAR; @@ -2617,41 +2617,41 @@ try_dlopen (phandle, filename) if (ext && strcmp (ext, archive_ext) == 0) { /* this seems to be a libtool module */ - FILE * file = 0; - char * dlname = 0; - char * old_name = 0; - char * libdir = 0; - char * deplibs = 0; - char * line = 0; - size_t line_len; + FILE * file = 0; + char * dlname = 0; + char * old_name = 0; + char * libdir = 0; + char * deplibs = 0; + char * line = 0; + size_t line_len; /* if we can't find the installed flag, it is probably an - installed libtool archive, produced with an old version - of libtool */ - int installed = 1; + installed libtool archive, produced with an old version + of libtool */ + int installed = 1; /* extract the module name from the file name */ name = LT_EMALLOC (char, ext - base_name + 1); if (!name) - { - ++errors; - goto cleanup; - } + { + ++errors; + goto cleanup; + } /* canonicalize the module name */ { size_t i; for (i = 0; i < ext - base_name; ++i) - { - if (isalnum ((int)(base_name[i]))) - { - name[i] = base_name[i]; - } - else - { - name[i] = '_'; - } - } + { + if (isalnum ((unsigned char)(base_name[i]))) + { + name[i] = base_name[i]; + } + else + { + name[i] = '_'; + } + } name[ext - base_name] = LT_EOS_CHAR; } @@ -2660,146 +2660,146 @@ try_dlopen (phandle, filename) prescribed paths. Otherwise (or in any case if the module was not yet found) try opening just the module name as passed. */ if (!dir) - { - const char *search_path; - - LT_DLMUTEX_LOCK (); - search_path = user_search_path; - if (search_path) - file = find_file (user_search_path, base_name, &dir); - LT_DLMUTEX_UNLOCK (); - - if (!file) - { - search_path = getenv (LTDL_SEARCHPATH_VAR); - if (search_path) - file = find_file (search_path, base_name, &dir); - } + { + const char *search_path; + + LT_DLMUTEX_LOCK (); + search_path = user_search_path; + if (search_path) + file = find_file (user_search_path, base_name, &dir); + LT_DLMUTEX_UNLOCK (); + + if (!file) + { + search_path = getenv (LTDL_SEARCHPATH_VAR); + if (search_path) + file = find_file (search_path, base_name, &dir); + } #ifdef LTDL_SHLIBPATH_VAR - if (!file) - { - search_path = getenv (LTDL_SHLIBPATH_VAR); - if (search_path) - file = find_file (search_path, base_name, &dir); - } + if (!file) + { + search_path = getenv (LTDL_SHLIBPATH_VAR); + if (search_path) + file = find_file (search_path, base_name, &dir); + } #endif #ifdef LTDL_SYSSEARCHPATH - if (!file && sys_search_path) - { - file = find_file (sys_search_path, base_name, &dir); - } + if (!file && sys_search_path) + { + file = find_file (sys_search_path, base_name, &dir); + } #endif - } + } if (!file) - { - file = fopen (filename, LT_READTEXT_MODE); - } + { + file = fopen (filename, LT_READTEXT_MODE); + } /* If we didn't find the file by now, it really isn't there. Set - the status flag, and bail out. */ + the status flag, and bail out. */ if (!file) - { - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND)); - ++errors; - goto cleanup; - } + { + LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND)); + ++errors; + goto cleanup; + } line_len = LT_FILENAME_MAX; line = LT_EMALLOC (char, line_len); if (!line) - { - fclose (file); - ++errors; - goto cleanup; - } + { + fclose (file); + ++errors; + goto cleanup; + } /* read the .la file */ while (!feof (file)) - { - if (!fgets (line, (int) line_len, file)) - { - break; - } - - /* Handle the case where we occasionally need to read a line - that is longer than the initial buffer size. */ - while (line[LT_STRLEN(line) -1] != '\n') - { - line = LT_DLREALLOC (char, line, line_len *2); - if (!fgets (&line[line_len -1], (int) line_len +1, file)) - { - break; - } - line_len *= 2; - } - - if (line[0] == '\n' || line[0] == '#') - { - continue; - } + { + if (!fgets (line, (int) line_len, file)) + { + break; + } + + /* Handle the case where we occasionally need to read a line + that is longer than the initial buffer size. */ + while (line[LT_STRLEN(line) -1] != '\n') + { + line = LT_DLREALLOC (char, line, line_len *2); + if (!fgets (&line[line_len -1], (int) line_len +1, file)) + { + break; + } + line_len *= 2; + } + + if (line[0] == '\n' || line[0] == '#') + { + continue; + } #undef STR_DLNAME -#define STR_DLNAME "dlname=" - if (strncmp (line, STR_DLNAME, sizeof (STR_DLNAME) - 1) == 0) - { - errors += trim (&dlname, &line[sizeof (STR_DLNAME) - 1]); - } +#define STR_DLNAME "dlname=" + if (strncmp (line, STR_DLNAME, sizeof (STR_DLNAME) - 1) == 0) + { + errors += trim (&dlname, &line[sizeof (STR_DLNAME) - 1]); + } #undef STR_OLD_LIBRARY -#define STR_OLD_LIBRARY "old_library=" - else if (strncmp (line, STR_OLD_LIBRARY, - sizeof (STR_OLD_LIBRARY) - 1) == 0) - { - errors += trim (&old_name, &line[sizeof (STR_OLD_LIBRARY) - 1]); - } +#define STR_OLD_LIBRARY "old_library=" + else if (strncmp (line, STR_OLD_LIBRARY, + sizeof (STR_OLD_LIBRARY) - 1) == 0) + { + errors += trim (&old_name, &line[sizeof (STR_OLD_LIBRARY) - 1]); + } #undef STR_LIBDIR -#define STR_LIBDIR "libdir=" - else if (strncmp (line, STR_LIBDIR, sizeof (STR_LIBDIR) - 1) == 0) - { - errors += trim (&libdir, &line[sizeof(STR_LIBDIR) - 1]); - } +#define STR_LIBDIR "libdir=" + else if (strncmp (line, STR_LIBDIR, sizeof (STR_LIBDIR) - 1) == 0) + { + errors += trim (&libdir, &line[sizeof(STR_LIBDIR) - 1]); + } #undef STR_DL_DEPLIBS -#define STR_DL_DEPLIBS "dependency_libs=" - else if (strncmp (line, STR_DL_DEPLIBS, - sizeof (STR_DL_DEPLIBS) - 1) == 0) - { - errors += trim (&deplibs, &line[sizeof (STR_DL_DEPLIBS) - 1]); - } - else if (strcmp (line, "installed=yes\n") == 0) - { - installed = 1; - } - else if (strcmp (line, "installed=no\n") == 0) - { - installed = 0; - } +#define STR_DL_DEPLIBS "dependency_libs=" + else if (strncmp (line, STR_DL_DEPLIBS, + sizeof (STR_DL_DEPLIBS) - 1) == 0) + { + errors += trim (&deplibs, &line[sizeof (STR_DL_DEPLIBS) - 1]); + } + else if (strcmp (line, "installed=yes\n") == 0) + { + installed = 1; + } + else if (strcmp (line, "installed=no\n") == 0) + { + installed = 0; + } #undef STR_LIBRARY_NAMES #define STR_LIBRARY_NAMES "library_names=" - else if (! dlname && strncmp (line, STR_LIBRARY_NAMES, - sizeof (STR_LIBRARY_NAMES) - 1) == 0) - { - char *last_libname; - errors += trim (&dlname, &line[sizeof (STR_LIBRARY_NAMES) - 1]); - if (!errors - && dlname - && (last_libname = strrchr (dlname, ' ')) != 0) - { - last_libname = lt_estrdup (last_libname + 1); - if (!last_libname) - { - ++errors; - goto cleanup; - } - LT_DLMEM_REASSIGN (dlname, last_libname); - } - } - - if (errors) - break; - } + else if (! dlname && strncmp (line, STR_LIBRARY_NAMES, + sizeof (STR_LIBRARY_NAMES) - 1) == 0) + { + char *last_libname; + errors += trim (&dlname, &line[sizeof (STR_LIBRARY_NAMES) - 1]); + if (!errors + && dlname + && (last_libname = strrchr (dlname, ' ')) != 0) + { + last_libname = lt_estrdup (last_libname + 1); + if (!last_libname) + { + ++errors; + goto cleanup; + } + LT_DLMEM_REASSIGN (dlname, last_libname); + } + } + + if (errors) + break; + } fclose (file); LT_DLFREE (line); @@ -2807,83 +2807,83 @@ try_dlopen (phandle, filename) /* allocate the handle */ *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); if (*phandle == 0) - ++errors; + ++errors; if (errors) - { - free_vars (dlname, old_name, libdir, deplibs); - LT_DLFREE (*phandle); - goto cleanup; - } + { + free_vars (dlname, old_name, libdir, deplibs); + LT_DLFREE (*phandle); + goto cleanup; + } assert (*phandle); memset (*phandle, 0, sizeof(struct lt_dlhandle_struct)); if (load_deplibs (*phandle, deplibs) == 0) - { - newhandle = *phandle; - /* find_module may replace newhandle */ - if (find_module (&newhandle, dir, libdir, dlname, old_name, installed)) - { - unload_deplibs (*phandle); - ++errors; - } - } + { + newhandle = *phandle; + /* find_module may replace newhandle */ + if (find_module (&newhandle, dir, libdir, dlname, old_name, installed)) + { + unload_deplibs (*phandle); + ++errors; + } + } else - { - ++errors; - } + { + ++errors; + } free_vars (dlname, old_name, libdir, deplibs); if (errors) - { - LT_DLFREE (*phandle); - goto cleanup; - } + { + LT_DLFREE (*phandle); + goto cleanup; + } if (*phandle != newhandle) - { - unload_deplibs (*phandle); - } + { + unload_deplibs (*phandle); + } } else { /* not a libtool module */ *phandle = (lt_dlhandle) LT_EMALLOC (struct lt_dlhandle_struct, 1); if (*phandle == 0) - { - ++errors; - goto cleanup; - } + { + ++errors; + goto cleanup; + } memset (*phandle, 0, sizeof (struct lt_dlhandle_struct)); newhandle = *phandle; /* If the module has no directory name component, try to find it - first in user_search_path and then other prescribed paths. - Otherwise (or in any case if the module was not yet found) try - opening just the module name as passed. */ + first in user_search_path and then other prescribed paths. + Otherwise (or in any case if the module was not yet found) try + opening just the module name as passed. */ if ((dir || (!find_handle (user_search_path, base_name, &newhandle) - && !find_handle (getenv (LTDL_SEARCHPATH_VAR), base_name, - &newhandle) + && !find_handle (getenv (LTDL_SEARCHPATH_VAR), base_name, + &newhandle) #ifdef LTDL_SHLIBPATH_VAR - && !find_handle (getenv (LTDL_SHLIBPATH_VAR), base_name, - &newhandle) + && !find_handle (getenv (LTDL_SHLIBPATH_VAR), base_name, + &newhandle) #endif #ifdef LTDL_SYSSEARCHPATH - && !find_handle (sys_search_path, base_name, &newhandle) + && !find_handle (sys_search_path, base_name, &newhandle) #endif - ))) - { - tryall_dlopen (&newhandle, filename); - } + ))) + { + tryall_dlopen (&newhandle, filename); + } if (!newhandle) - { - LT_DLFREE (*phandle); - ++errors; - goto cleanup; - } + { + LT_DLFREE (*phandle); + ++errors; + goto cleanup; + } } register_handle: @@ -2891,12 +2891,12 @@ try_dlopen (phandle, filename) if ((*phandle)->info.ref_count == 0) { - (*phandle)->info.ref_count = 1; + (*phandle)->info.ref_count = 1; LT_DLMEM_REASSIGN ((*phandle)->info.name, name); LT_DLMUTEX_LOCK (); - (*phandle)->next = handles; - handles = *phandle; + (*phandle)->next = handles; + handles = *phandle; LT_DLMUTEX_UNLOCK (); } @@ -2946,11 +2946,11 @@ lt_dlhandle lt_dlopenext (filename) const char *filename; { - lt_dlhandle handle = 0; - char * tmp = 0; - char * ext = 0; - size_t len; - int errors = 0; + lt_dlhandle handle = 0; + char * tmp = 0; + char * ext = 0; + size_t len; + int errors = 0; if (!filename) { @@ -2966,7 +2966,7 @@ lt_dlopenext (filename) to try appending additional extensions. */ if (ext && ((strcmp (ext, archive_ext) == 0) #ifdef LTDL_SHLIB_EXT - || (strcmp (ext, shlib_ext) == 0) + || (strcmp (ext, shlib_ext) == 0) #endif )) { @@ -3000,7 +3000,7 @@ lt_dlopenext (filename) LT_DLFREE (tmp); tmp = LT_EMALLOC (char, len + LT_STRLEN (shlib_ext) + 1); if (!tmp) - return 0; + return 0; strcpy (tmp, filename); } @@ -3041,14 +3041,14 @@ lt_argz_insert (pargz, pargz_len, before, entry) if ((error = argz_insert (pargz, pargz_len, before, entry))) { switch (error) - { - case ENOMEM: - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY)); - break; - default: - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (UNKNOWN)); - break; - } + { + case ENOMEM: + LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY)); + break; + default: + LT_DLMUTEX_SETERROR (LT_DLSTRERROR (UNKNOWN)); + break; + } return 1; } @@ -3070,10 +3070,10 @@ lt_argz_insertinorder (pargz, pargz_len, entry) if (*pargz) while ((before = argz_next (*pargz, *pargz_len, before))) { - int cmp = strcmp (entry, before); + int cmp = strcmp (entry, before); - if (cmp < 0) break; - if (cmp == 0) return 0; /* No duplicates! */ + if (cmp < 0) break; + if (cmp == 0) return 0; /* No duplicates! */ } return lt_argz_insert (pargz, pargz_len, before, entry); @@ -3086,12 +3086,12 @@ lt_argz_insertdir (pargz, pargz_len, dirnam, dp) const char *dirnam; struct dirent *dp; { - char *buf = 0; + char *buf = 0; size_t buf_len = 0; - char *end = 0; + char *end = 0; size_t end_offset = 0; size_t dir_len = 0; - int errors = 0; + int errors = 0; assert (pargz); assert (pargz_len); @@ -3105,7 +3105,7 @@ lt_argz_insertdir (pargz, pargz_len, dirnam, dp) char *p; for (p = end; p -1 > dp->d_name; --p) if (strchr (".0123456789", p[-1]) == 0) - break; + break; if (*p == '.') end = p; @@ -3116,16 +3116,16 @@ lt_argz_insertdir (pargz, pargz_len, dirnam, dp) char *p; for (p = end -1; p > dp->d_name; --p) if (*p == '.') - { - end = p; - break; - } + { + end = p; + break; + } } /* Prepend the directory name. */ - end_offset = end - dp->d_name; - buf_len = dir_len + 1+ end_offset; - buf = LT_EMALLOC (char, 1+ buf_len); + end_offset = end - dp->d_name; + buf_len = dir_len + 1+ end_offset; + buf = LT_EMALLOC (char, 1+ buf_len); if (!buf) return ++errors; @@ -3151,8 +3151,8 @@ list_files_by_dir (dirnam, pargz, pargz_len) char **pargz; size_t *pargz_len; { - DIR *dirp = 0; - int errors = 0; + DIR *dirp = 0; + int errors = 0; assert (dirnam && *dirnam); assert (pargz); @@ -3162,15 +3162,15 @@ list_files_by_dir (dirnam, pargz, pargz_len) dirp = opendir (dirnam); if (dirp) { - struct dirent *dp = 0; + struct dirent *dp = 0; while ((dp = readdir (dirp))) - if (dp->d_name[0] != '.') - if (lt_argz_insertdir (pargz, pargz_len, dirnam, dp)) - { - ++errors; - break; - } + if (dp->d_name[0] != '.') + if (lt_argz_insertdir (pargz, pargz_len, dirnam, dp)) + { + ++errors; + break; + } closedir (dirp); } @@ -3190,9 +3190,9 @@ foreachfile_callback (dirname, data1, data2) lt_ptr data2; { int (*func) LT_PARAMS((const char *filename, lt_ptr data)) - = (int (*) LT_PARAMS((const char *filename, lt_ptr data))) data1; + = (int (*) LT_PARAMS((const char *filename, lt_ptr data))) data1; - int is_done = 0; + int is_done = 0; char *argz = 0; size_t argz_len = 0; @@ -3205,7 +3205,7 @@ foreachfile_callback (dirname, data1, data2) char *filename = 0; while ((filename = argz_next (argz, argz_len, filename))) if ((is_done = (*func) (filename, data2))) - break; + break; } cleanup: @@ -3232,34 +3232,34 @@ lt_dlforeachfile (search_path, func, data) if (search_path) { /* If a specific path was passed, search only the directories - listed in it. */ + listed in it. */ is_done = foreach_dirinpath (search_path, 0, - foreachfile_callback, func, data); + foreachfile_callback, func, data); } else { /* Otherwise search the default paths. */ is_done = foreach_dirinpath (user_search_path, 0, - foreachfile_callback, func, data); + foreachfile_callback, func, data); if (!is_done) - { - is_done = foreach_dirinpath (getenv("LTDL_LIBRARY_PATH"), 0, - foreachfile_callback, func, data); - } + { + is_done = foreach_dirinpath (getenv("LTDL_LIBRARY_PATH"), 0, + foreachfile_callback, func, data); + } #ifdef LTDL_SHLIBPATH_VAR if (!is_done) - { - is_done = foreach_dirinpath (getenv(LTDL_SHLIBPATH_VAR), 0, - foreachfile_callback, func, data); - } + { + is_done = foreach_dirinpath (getenv(LTDL_SHLIBPATH_VAR), 0, + foreachfile_callback, func, data); + } #endif #ifdef LTDL_SYSSEARCHPATH if (!is_done) - { - is_done = foreach_dirinpath (getenv(LTDL_SYSSEARCHPATH), 0, - foreachfile_callback, func, data); - } + { + is_done = foreach_dirinpath (getenv(LTDL_SYSSEARCHPATH), 0, + foreachfile_callback, func, data); + } #endif } @@ -3301,13 +3301,13 @@ lt_dlclose (handle) lt_user_data data = handle->loader->dlloader_data; if (handle != handles) - { - last->next = handle->next; - } + { + last->next = handle->next; + } else - { - handles = handle->next; - } + { + handles = handle->next; + } errors += handle->loader->module_close (data, handle->module); errors += unload_deplibs(handle); @@ -3340,8 +3340,8 @@ lt_dlsym (handle, symbol) const char *symbol; { size_t lensym; - char lsym[LT_SYMBOL_LENGTH]; - char *sym; + char lsym[LT_SYMBOL_LENGTH]; + char *sym; lt_ptr address; lt_user_data data; @@ -3358,7 +3358,7 @@ lt_dlsym (handle, symbol) } lensym = LT_STRLEN (symbol) + LT_STRLEN (handle->loader->sym_prefix) - + LT_STRLEN (handle->info.name); + + LT_STRLEN (handle->info.name); if (lensym + LT_SYMBOL_OVERHEAD < LT_SYMBOL_LENGTH) { @@ -3368,10 +3368,10 @@ lt_dlsym (handle, symbol) { sym = LT_EMALLOC (char, lensym + LT_SYMBOL_OVERHEAD + 1); if (!sym) - { - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (BUFFER_OVERFLOW)); - return 0; - } + { + LT_DLMUTEX_SETERROR (LT_DLSTRERROR (BUFFER_OVERFLOW)); + return 0; + } } data = handle->loader->dlloader_data; @@ -3383,14 +3383,14 @@ lt_dlsym (handle, symbol) /* this is a libtool module */ if (handle->loader->sym_prefix) - { - strcpy(sym, handle->loader->sym_prefix); - strcat(sym, handle->info.name); - } + { + strcpy(sym, handle->loader->sym_prefix); + strcat(sym, handle->info.name); + } else - { - strcpy(sym, handle->info.name); - } + { + strcpy(sym, handle->info.name); + } strcat(sym, "_LTX_"); strcat(sym, symbol); @@ -3398,13 +3398,13 @@ lt_dlsym (handle, symbol) /* try "modulename_LTX_symbol" */ address = handle->loader->find_sym (data, handle->module, sym); if (address) - { - if (sym != lsym) - { - LT_DLFREE (sym); - } - return address; - } + { + if (sym != lsym) + { + LT_DLFREE (sym); + } + return address; + } LT_DLMUTEX_SETERROR (saved_error); } @@ -3445,10 +3445,10 @@ lt_dlpath_insertdir (ppath, before, dir) char *before; const char *dir; { - int errors = 0; - char *canonical = 0; - char *argz = 0; - size_t argz_len = 0; + int errors = 0; + char *canonical = 0; + char *argz = 0; + size_t argz_len = 0; assert (ppath); assert (dir && *dir); @@ -3464,12 +3464,12 @@ lt_dlpath_insertdir (ppath, before, dir) /* If *PPATH is empty, set it to DIR. */ if (*ppath == 0) { - assert (!before); /* BEFORE cannot be set without PPATH. */ - assert (dir); /* Without DIR, don't call this function! */ + assert (!before); /* BEFORE cannot be set without PPATH. */ + assert (dir); /* Without DIR, don't call this function! */ *ppath = lt_estrdup (dir); if (*ppath == 0) - ++errors; + ++errors; return errors; } @@ -3521,7 +3521,7 @@ lt_dladdsearchdir (search_dir) { LT_DLMUTEX_LOCK (); if (lt_dlpath_insertdir (&user_search_path, 0, search_dir) != 0) - ++errors; + ++errors; LT_DLMUTEX_UNLOCK (); } @@ -3539,12 +3539,12 @@ lt_dlinsertsearchdir (before, search_dir) { LT_DLMUTEX_LOCK (); if ((before < user_search_path) - || (before >= user_search_path + LT_STRLEN (user_search_path))) - { - LT_DLMUTEX_UNLOCK (); - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_POSITION)); - return 1; - } + || (before >= user_search_path + LT_STRLEN (user_search_path))) + { + LT_DLMUTEX_UNLOCK (); + LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_POSITION)); + return 1; + } LT_DLMUTEX_UNLOCK (); } @@ -3552,10 +3552,10 @@ lt_dlinsertsearchdir (before, search_dir) { LT_DLMUTEX_LOCK (); if (lt_dlpath_insertdir (&user_search_path, - (char *) before, search_dir) != 0) - { - ++errors; - } + (char *) before, search_dir) != 0) + { + ++errors; + } LT_DLMUTEX_UNLOCK (); } @@ -3566,7 +3566,7 @@ int lt_dlsetsearchpath (search_path) const char *search_path; { - int errors = 0; + int errors = 0; LT_DLMUTEX_LOCK (); LT_DLFREE (user_search_path); @@ -3617,7 +3617,7 @@ lt_dlmakeresident (handle) } int -lt_dlisresident (handle) +lt_dlisresident (handle) lt_dlhandle handle; { if (!handle) @@ -3671,10 +3671,10 @@ lt_dlforeach (func, data) cur = cur->next; if ((*func) (tmp, data)) - { - ++errors; - break; - } + { + ++errors; + break; + } } LT_DLMUTEX_UNLOCK (); @@ -3716,10 +3716,10 @@ lt_dlcaller_set_data (key, handle, data) for (i = 0; i < n_elements; ++i) { if (handle->caller_data[i].key == key) - { - stale = handle->caller_data[i].data; - break; - } + { + stale = handle->caller_data[i].data; + break; + } } /* Ensure that there is enough room in this handle's caller_data @@ -3727,13 +3727,13 @@ lt_dlcaller_set_data (key, handle, data) if (i == n_elements) { lt_caller_data *temp - = LT_DLREALLOC (lt_caller_data, handle->caller_data, 2+ n_elements); + = LT_DLREALLOC (lt_caller_data, handle->caller_data, 2+ n_elements); if (!temp) - { - stale = 0; - goto done; - } + { + stale = 0; + goto done; + } handle->caller_data = temp; @@ -3766,11 +3766,11 @@ lt_dlcaller_get_data (key, handle) int i; for (i = 0; handle->caller_data[i].key; ++i) { - if (handle->caller_data[i].key == key) - { - result = handle->caller_data[i].data; - break; - } + if (handle->caller_data[i].key == key) + { + result = handle->caller_data[i].data; + break; + } } } @@ -3793,7 +3793,7 @@ lt_dlloader_add (place, dlloader, loader_name) int errors = 0; lt_dlloader *node = 0, *ptr = 0; - if ((dlloader == 0) /* diagnose null parameters */ + if ((dlloader == 0) /* diagnose null parameters */ || (dlloader->module_open == 0) || (dlloader->module_close == 0) || (dlloader->find_sym == 0)) @@ -3807,14 +3807,14 @@ lt_dlloader_add (place, dlloader, loader_name) if (!node) return 1; - node->next = 0; - node->loader_name = loader_name; - node->sym_prefix = dlloader->sym_prefix; - node->dlloader_exit = dlloader->dlloader_exit; - node->module_open = dlloader->module_open; - node->module_close = dlloader->module_close; - node->find_sym = dlloader->find_sym; - node->dlloader_data = dlloader->dlloader_data; + node->next = 0; + node->loader_name = loader_name; + node->sym_prefix = dlloader->sym_prefix; + node->dlloader_exit = dlloader->dlloader_exit; + node->module_open = dlloader->module_open; + node->module_close = dlloader->module_close; + node->find_sym = dlloader->find_sym; + node->dlloader_data = dlloader->dlloader_data; LT_DLMUTEX_LOCK (); if (!loaders) @@ -3825,11 +3825,11 @@ lt_dlloader_add (place, dlloader, loader_name) else if (!place) { /* If PLACE is not set, add NODE to the end of the - LOADERS list. */ + LOADERS list. */ for (ptr = loaders; ptr->next; ptr = ptr->next) - { - /*NOWORK*/; - } + { + /*NOWORK*/; + } ptr->next = node; } @@ -3843,21 +3843,21 @@ lt_dlloader_add (place, dlloader, loader_name) { /* Find the node immediately preceding PLACE. */ for (ptr = loaders; ptr->next != place; ptr = ptr->next) - { - /*NOWORK*/; - } + { + /*NOWORK*/; + } if (ptr->next != place) - { - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER)); - ++errors; - } + { + LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER)); + ++errors; + } else - { - /* Insert NODE between PTR and PLACE. */ - node->next = place; - ptr->next = node; - } + { + /* Insert NODE between PTR and PLACE. */ + node->next = place; + ptr->next = node; + } } LT_DLMUTEX_UNLOCK (); @@ -3885,11 +3885,11 @@ lt_dlloader_remove (loader_name) for (handle = handles; handle; handle = handle->next) { if (handle->loader == place) - { - LT_DLMUTEX_SETERROR (LT_DLSTRERROR (REMOVE_LOADER)); - ++errors; - goto done; - } + { + LT_DLMUTEX_SETERROR (LT_DLSTRERROR (REMOVE_LOADER)); + ++errors; + goto done; + } } if (place == loaders) @@ -3902,12 +3902,12 @@ lt_dlloader_remove (loader_name) /* Find the loader before the one being removed. */ lt_dlloader *prev; for (prev = loaders; prev->next; prev = prev->next) - { - if (!strcmp (prev->next->loader_name, loader_name)) - { - break; - } - } + { + if (!strcmp (prev->next->loader_name, loader_name)) + { + break; + } + } place = prev->next; prev->next = prev->next->next; @@ -3989,9 +3989,9 @@ lt_dlloader_find (loader_name) for (place = loaders; place; place = place->next) { if (strcmp (place->loader_name, loader_name) == 0) - { - break; - } + { + break; + } } LT_DLMUTEX_UNLOCK (); diff --git a/src/SDCC.lex b/src/SDCC.lex index a0b0297c..4f9b5188 100644 --- a/src/SDCC.lex +++ b/src/SDCC.lex @@ -284,7 +284,7 @@ static int checkCurrFile (char *s) /* get the line number */ lNum = strtol(s, &tptr, 10); - if (tptr == s || !isspace(*tptr)) + if (tptr == s || !isspace((unsigned char)*tptr)) return 0; s = tptr; @@ -783,16 +783,16 @@ static int process_pragma(char *s) s += PRAGMA_LEN; /* look for the directive */ - while(isspace(*s)) + while(isspace((unsigned char)*s)) s++; cp = s; /* look for the end of the directive */ - while ((!isspace(*s)) && (*s != '\n')) + while ((!isspace((unsigned char)*s)) && (*s != '\n')) s++ ; /* skip separating whitespace */ - while (isspace(*s) && (*s != '\n')) + while (isspace((unsigned char)*s) && (*s != '\n')) s++; /* First give the port a chance */ diff --git a/src/SDCCglue.c b/src/SDCCglue.c index 7ec4ad69..199a7c06 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -1562,7 +1562,7 @@ spacesToUnderscores (char *dest, const char *src, size_t len) --len; for (p = dest, i = 0; *src != '\0' && i < len; ++src, ++i) { - *p++ = isspace(*src) ? '_' : *src; + *p++ = isspace((unsigned char)*src) ? '_' : *src; } *p = '\0'; @@ -1694,7 +1694,7 @@ glue (void) { /* copy the sbit segment */ fprintf (asmFile, "%s", iComments2); - fprintf (asmFile, "; special function bits \n"); + fprintf (asmFile, "; special function bits\n"); fprintf (asmFile, "%s", iComments2); copyFile (asmFile, sfrbit->oFile); @@ -1702,16 +1702,16 @@ glue (void) if(RegBankUsed[0]||RegBankUsed[1]||RegBankUsed[2]||RegBankUsed[3]) { fprintf (asmFile, "%s", iComments2); - fprintf (asmFile, "; overlayable register banks \n"); + fprintf (asmFile, "; overlayable register banks\n"); fprintf (asmFile, "%s", iComments2); if(RegBankUsed[0]) - fprintf (asmFile, "\t.area REG_BANK_0\t(REL,OVR,DATA)\n\t.ds 8\n"); + fprintf (asmFile, "\t.area REG_BANK_0\t(REL,OVR,DATA)\n\t.ds 8\n"); if(RegBankUsed[1]||options.parms_in_bank1) - fprintf (asmFile, "\t.area REG_BANK_1\t(REL,OVR,DATA)\n\t.ds 8\n"); + fprintf (asmFile, "\t.area REG_BANK_1\t(REL,OVR,DATA)\n\t.ds 8\n"); if(RegBankUsed[2]) - fprintf (asmFile, "\t.area REG_BANK_2\t(REL,OVR,DATA)\n\t.ds 8\n"); + fprintf (asmFile, "\t.area REG_BANK_2\t(REL,OVR,DATA)\n\t.ds 8\n"); if(RegBankUsed[3]) - fprintf (asmFile, "\t.area REG_BANK_3\t(REL,OVR,DATA)\n\t.ds 8\n"); + fprintf (asmFile, "\t.area REG_BANK_3\t(REL,OVR,DATA)\n\t.ds 8\n"); } if(BitBankUsed) { diff --git a/src/SDCCmain.c b/src/SDCCmain.c index 12893d7e..2c89171d 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -530,12 +530,12 @@ setParseWithComma (set **dest, char *src) int length; /* skip the initial white spaces */ - while (isspace(*src)) + while (isspace((unsigned char)*src)) src++; /* skip the trailing white spaces */ length = strlen(src); - while (length && isspace(src[length-1])) + while (length && isspace((unsigned char)src[length-1])) src[--length] = '\0'; for (p = strtok(src, ","); p != NULL; p = strtok(NULL, ",")) @@ -549,10 +549,10 @@ static void setDefaultOptions (void) { /* first the options part */ - options.stack_loc = 0; /* stack pointer initialised to 0 */ - options.xstack_loc = 0; /* xternal stack starts at 0 */ - options.code_loc = 0; /* code starts at 0 */ - options.data_loc = 0; /* JCF: By default let the linker locate data */ + options.stack_loc = 0; /* stack pointer initialised to 0 */ + options.xstack_loc = 0; /* xternal stack starts at 0 */ + options.code_loc = 0; /* code starts at 0 */ + options.data_loc = 0; /* JCF: By default let the linker locate data */ options.xdata_loc = 0; options.idata_loc = 0x80; options.nopeep = 0; @@ -561,8 +561,8 @@ setDefaultOptions (void) options.nostdinc = 0; options.verbose = 0; options.shortis8bits = 0; - options.std_sdcc = 1; /* enable SDCC language extensions */ - options.std_c99 = 0; /* default to C89 until more C99 support */ + options.std_sdcc = 1; /* enable SDCC language extensions */ + options.std_c99 = 0; /* default to C89 until more C99 support */ options.code_seg = CODE_NAME; /* default to CSEG for generated code */ options.const_seg = CONST_NAME; /* default to CONST for generated code */ @@ -660,7 +660,7 @@ processFile (char *s) moduleName = Safe_strdup ( fext ); for (fext = moduleName; *fext; fext++) - if (!isalnum (*fext)) + if (!isalnum ((unsigned char)*fext)) *fext = '_'; return; } diff --git a/src/SDCCopt.c b/src/SDCCopt.c index bf6d4cbe..64b49c6f 100644 --- a/src/SDCCopt.c +++ b/src/SDCCopt.c @@ -1,9 +1,9 @@ /*------------------------------------------------------------------------- SDCCopt.c - calls all the optimizations routines and does some of the hackier transformations, these include translating iCodes - to function calls and replacing local variables with their - register equivalents etc. Also contains the driver routine - for dead code elimination + to function calls and replacing local variables with their + register equivalents etc. Also contains the driver routine + for dead code elimination Written By - Sandeep Dutta . sandeep.dutta@usa.net (1998) @@ -11,21 +11,22 @@ under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. - + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - + You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + In other words, you are welcome to use, share and improve this program. You are forbidden to forbid anyone else to use, share and improve - what you give them. Help stamp out software-hoarding! + what you give them. Help stamp out software-hoarding! -------------------------------------------------------------------------*/ +#include #include "common.h" /*-----------------------------------------------------------------*/ @@ -38,7 +39,7 @@ char flowChanged = 0; /*-----------------------------------------------------------------*/ /* printSymName - prints the symbol names */ /*-----------------------------------------------------------------*/ -int +int printSymName (void *vsym) { symbol *sym = vsym; @@ -49,7 +50,7 @@ printSymName (void *vsym) /*-----------------------------------------------------------------*/ /* cnvToFcall - does the actual conversion to function call */ /*-----------------------------------------------------------------*/ -static void +static void cnvToFcall (iCode * ic, eBBlock * ebp) { iCode *ip; @@ -60,7 +61,7 @@ cnvToFcall (iCode * ic, eBBlock * ebp) int lineno = ic->lineno; int bytesPushed=0; - ip = ic->next; /* insertion point */ + ip = ic->next; /* insertion point */ /* remove it from the iCode */ remiCodeFromeBBlock (ebp, ic); @@ -145,30 +146,30 @@ cnvToFcall (iCode * ic, eBBlock * ebp) /* first one */ if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) - { - newic = newiCode (SEND, IC_LEFT (ic), NULL); - newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); - } + { + newic = newiCode (SEND, IC_LEFT (ic), NULL); + newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); + } else - { - newic = newiCode ('=', NULL, IC_LEFT (ic)); - IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)); - } + { + newic = newiCode ('=', NULL, IC_LEFT (ic)); + IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)); + } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; /* second one */ if (IS_REGPARM (FUNC_ARGS(func->type)->next->etype)) - { - newic = newiCode (SEND, IC_RIGHT (ic), NULL); - newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->next->etype); - } + { + newic = newiCode (SEND, IC_RIGHT (ic), NULL); + newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->next->etype); + } else - { - newic = newiCode ('=', NULL, IC_RIGHT (ic)); - IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)->next); - } + { + newic = newiCode ('=', NULL, IC_RIGHT (ic)); + IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)->next); + } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; @@ -178,34 +179,34 @@ cnvToFcall (iCode * ic, eBBlock * ebp) /* push right */ if (IS_REGPARM (FUNC_ARGS(func->type)->next->etype)) - { - newic = newiCode (SEND, right, NULL); - newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->next->etype); - } + { + newic = newiCode (SEND, right, NULL); + newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->next->etype); + } else - { - newic = newiCode (IPUSH, right, NULL); - newic->parmPush = 1; - //bytesPushed+=4; - bytesPushed += getSize(operandType(right)); - } + { + newic = newiCode (IPUSH, right, NULL); + newic->parmPush = 1; + //bytesPushed+=4; + bytesPushed += getSize(operandType(right)); + } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; /* insert push left */ if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) - { - newic = newiCode (SEND, left, NULL); - newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); - } + { + newic = newiCode (SEND, left, NULL); + newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); + } else - { - newic = newiCode (IPUSH, left, NULL); - newic->parmPush = 1; - //bytesPushed+=4; - bytesPushed += getSize(operandType(left)); - } + { + newic = newiCode (IPUSH, left, NULL); + newic->parmPush = 1; + //bytesPushed+=4; + bytesPushed += getSize(operandType(left)); + } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; } @@ -217,18 +218,18 @@ cnvToFcall (iCode * ic, eBBlock * ebp) ebp->hasFcall = 1; if (currFunc) FUNC_HASFCALL (currFunc->type) = 1; - + if(TARGET_IS_PIC16) { - /* normally these functions aren't marked external, so we can use their - * _extern field to marked as already added to symbol table */ + /* normally these functions aren't marked external, so we can use their + * _extern field to marked as already added to symbol table */ - if(!SPEC_EXTR(func->etype)) { - memmap *seg = SPEC_OCLS(OP_SYMBOL(IC_LEFT(newic))->etype); - - SPEC_EXTR(func->etype) = 1; - seg = SPEC_OCLS( func->etype ); - addSet(&seg->syms, func); - } + if(!SPEC_EXTR(func->etype)) { + memmap *seg = SPEC_OCLS(OP_SYMBOL(IC_LEFT(newic))->etype); + + SPEC_EXTR(func->etype) = 1; + seg = SPEC_OCLS( func->etype ); + addSet(&seg->syms, func); + } } addiCodeToeBBlock (ebp, newic, ip); @@ -237,7 +238,7 @@ cnvToFcall (iCode * ic, eBBlock * ebp) /*-----------------------------------------------------------------*/ /* cnvToFloatCast - converts casts to floats to function calls */ /*-----------------------------------------------------------------*/ -static void +static void cnvToFloatCast (iCode * ic, eBBlock * ebp) { iCode *ip, *newic; @@ -254,13 +255,13 @@ cnvToFloatCast (iCode * ic, eBBlock * ebp) for (bwd = 0; bwd < 3; bwd++) { for (su = 0; su < 2; su++) - { - if (compareType (type, __multypes[bwd][su]) == 1) - { - func = __conv[0][bwd][su]; - goto found; - } - } + { + if (compareType (type, __multypes[bwd][su]) == 1) + { + func = __conv[0][bwd][su]; + goto found; + } + } } if(compareType (type, fixed16x16Type) == 1) { @@ -275,16 +276,16 @@ found: if (!options.float_rent) { /* first one */ - if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) - { - newic = newiCode (SEND, IC_RIGHT (ic), NULL); - newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); - } + if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) + { + newic = newiCode (SEND, IC_RIGHT (ic), NULL); + newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); + } else - { - newic = newiCode ('=', NULL, IC_RIGHT (ic)); - IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)); - } + { + newic = newiCode ('=', NULL, IC_RIGHT (ic)); + IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)); + } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = linenno; @@ -292,16 +293,16 @@ found: else { /* push the left */ - if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) { - newic = newiCode (SEND, IC_RIGHT (ic), NULL); - newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); - } + if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) { + newic = newiCode (SEND, IC_RIGHT (ic), NULL); + newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); + } else - { - newic = newiCode (IPUSH, IC_RIGHT (ic), NULL); - newic->parmPush = 1; - bytesPushed += getSize(operandType(IC_RIGHT(ic))); - } + { + newic = newiCode (IPUSH, IC_RIGHT (ic), NULL); + newic->parmPush = 1; + bytesPushed += getSize(operandType(IC_RIGHT(ic))); + } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = linenno; @@ -367,16 +368,16 @@ found: if (!options.float_rent) { /* first one */ - if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) - { - newic = newiCode (SEND, IC_RIGHT (ic), NULL); - newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); - } + if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) + { + newic = newiCode (SEND, IC_RIGHT (ic), NULL); + newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); + } else - { - newic = newiCode ('=', NULL, IC_RIGHT (ic)); - IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)); - } + { + newic = newiCode ('=', NULL, IC_RIGHT (ic)); + IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)); + } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = linenno; @@ -384,16 +385,16 @@ found: else { /* push the left */ - if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) { - newic = newiCode (SEND, IC_RIGHT (ic), NULL); - newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); - } + if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) { + newic = newiCode (SEND, IC_RIGHT (ic), NULL); + newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); + } else - { - newic = newiCode (IPUSH, IC_RIGHT (ic), NULL); - newic->parmPush = 1; - bytesPushed += getSize(operandType(IC_RIGHT(ic))); - } + { + newic = newiCode (IPUSH, IC_RIGHT (ic), NULL); + newic->parmPush = 1; + bytesPushed += getSize(operandType(IC_RIGHT(ic))); + } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = linenno; @@ -408,16 +409,16 @@ found: FUNC_HASFCALL (currFunc->type) = 1; if(TARGET_IS_PIC16) { - /* normally these functions aren't marked external, so we can use their - * _extern field to marked as already added to symbol table */ + /* normally these functions aren't marked external, so we can use their + * _extern field to marked as already added to symbol table */ - if(!SPEC_EXTR(func->etype)) { - memmap *seg = SPEC_OCLS(OP_SYMBOL(IC_LEFT(newic))->etype); - - SPEC_EXTR(func->etype) = 1; - seg = SPEC_OCLS( func->etype ); - addSet(&seg->syms, func); - } + if(!SPEC_EXTR(func->etype)) { + memmap *seg = SPEC_OCLS(OP_SYMBOL(IC_LEFT(newic))->etype); + + SPEC_EXTR(func->etype) = 1; + seg = SPEC_OCLS( func->etype ); + addSet(&seg->syms, func); + } } addiCodeToeBBlock (ebp, newic, ip); @@ -427,7 +428,7 @@ found: /*-----------------------------------------------------------------*/ /* cnvFromFloatCast - converts casts From floats to function calls */ /*-----------------------------------------------------------------*/ -static void +static void cnvFromFloatCast (iCode * ic, eBBlock * ebp) { iCode *ip, *newic; @@ -445,13 +446,13 @@ cnvFromFloatCast (iCode * ic, eBBlock * ebp) for (bwd = 0; bwd < 3; bwd++) { for (su = 0; su < 2; su++) - { - if (compareType (type, __multypes[bwd][su]) == 1) - { - func = __conv[1][bwd][su]; - goto found; - } - } + { + if (compareType (type, __multypes[bwd][su]) == 1) + { + func = __conv[1][bwd][su]; + goto found; + } + } } assert (0); found: @@ -460,15 +461,15 @@ found: if (!options.float_rent) { /* first one */ - if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) { - newic = newiCode (SEND, IC_RIGHT (ic), NULL); - newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); - } + if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) { + newic = newiCode (SEND, IC_RIGHT (ic), NULL); + newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); + } else - { - newic = newiCode ('=', NULL, IC_RIGHT (ic)); - IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)); - } + { + newic = newiCode ('=', NULL, IC_RIGHT (ic)); + IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)); + } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; @@ -477,16 +478,16 @@ found: { /* push the left */ - if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) { - newic = newiCode (SEND, IC_RIGHT (ic), NULL); - newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); - } + if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) { + newic = newiCode (SEND, IC_RIGHT (ic), NULL); + newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); + } else - { - newic = newiCode (IPUSH, IC_RIGHT (ic), NULL); - newic->parmPush = 1; - bytesPushed += getSize(operandType(IC_RIGHT(ic))); - } + { + newic = newiCode (IPUSH, IC_RIGHT (ic), NULL); + newic->parmPush = 1; + bytesPushed += getSize(operandType(IC_RIGHT(ic))); + } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; @@ -501,16 +502,16 @@ found: FUNC_HASFCALL (currFunc->type) = 1; if(TARGET_IS_PIC16) { - /* normally these functions aren't marked external, so we can use their - * _extern field to marked as already added to symbol table */ + /* normally these functions aren't marked external, so we can use their + * _extern field to marked as already added to symbol table */ - if(!SPEC_EXTR(func->etype)) { - memmap *seg = SPEC_OCLS(OP_SYMBOL(IC_LEFT(newic))->etype); - - SPEC_EXTR(func->etype) = 1; - seg = SPEC_OCLS( func->etype ); - addSet(&seg->syms, func); - } + if(!SPEC_EXTR(func->etype)) { + memmap *seg = SPEC_OCLS(OP_SYMBOL(IC_LEFT(newic))->etype); + + SPEC_EXTR(func->etype) = 1; + seg = SPEC_OCLS( func->etype ); + addSet(&seg->syms, func); + } } addiCodeToeBBlock (ebp, newic, ip); @@ -538,13 +539,13 @@ cnvFromFixed16x16Cast (iCode * ic, eBBlock * ebp) for (bwd = 0; bwd < 3; bwd++) { for (su = 0; su < 2; su++) - { - if (compareType (type, __multypes[bwd][su]) == 1) - { - func = __fp16x16conv[1][bwd][su]; - goto found; - } - } + { + if (compareType (type, __multypes[bwd][su]) == 1) + { + func = __fp16x16conv[1][bwd][su]; + goto found; + } + } } if (compareType (type, floatType) == 1) @@ -560,15 +561,15 @@ found: if (!options.float_rent) { /* first one */ - if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) { - newic = newiCode (SEND, IC_RIGHT (ic), NULL); - newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); - } + if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) { + newic = newiCode (SEND, IC_RIGHT (ic), NULL); + newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); + } else - { - newic = newiCode ('=', NULL, IC_RIGHT (ic)); - IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)); - } + { + newic = newiCode ('=', NULL, IC_RIGHT (ic)); + IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)); + } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; @@ -577,16 +578,16 @@ found: { /* push the left */ - if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) { - newic = newiCode (SEND, IC_RIGHT (ic), NULL); - newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); - } + if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) { + newic = newiCode (SEND, IC_RIGHT (ic), NULL); + newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); + } else - { - newic = newiCode (IPUSH, IC_RIGHT (ic), NULL); - newic->parmPush = 1; - bytesPushed += getSize(operandType(IC_RIGHT(ic))); - } + { + newic = newiCode (IPUSH, IC_RIGHT (ic), NULL); + newic->parmPush = 1; + bytesPushed += getSize(operandType(IC_RIGHT(ic))); + } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; @@ -622,7 +623,7 @@ extern operand *geniCodeRValue (operand *, bool); /*-----------------------------------------------------------------*/ /* convilong - converts int or long mults or divs to fcalls */ /*-----------------------------------------------------------------*/ -static void +static void convilong (iCode * ic, eBBlock * ebp, sym_link * type, int op) { symbol *func = NULL; @@ -633,34 +634,34 @@ convilong (iCode * ic, eBBlock * ebp, sym_link * type, int op) int su; int bytesPushed=0; - remiCodeFromeBBlock (ebp, ic); - + remiCodeFromeBBlock (ebp, ic); + /* depending on the type */ for (bwd = 0; bwd < 3; bwd++) { for (su = 0; su < 2; su++) - { - if (compareType (type, __multypes[bwd][su]) == 1) - { - if (op == '*') - func = __muldiv[0][bwd][su]; - else if (op == '/') - func = __muldiv[1][bwd][su]; - else if (op == '%') - func = __muldiv[2][bwd][su]; + { + if (compareType (type, __multypes[bwd][su]) == 1) + { + if (op == '*') + func = __muldiv[0][bwd][su]; + else if (op == '/') + func = __muldiv[1][bwd][su]; + else if (op == '%') + func = __muldiv[2][bwd][su]; else if (op == RRC) - func = __rlrr[1][bwd][su]; + func = __rlrr[1][bwd][su]; else if (op == RLC) - func = __rlrr[0][bwd][su]; + func = __rlrr[0][bwd][su]; else if (op == RIGHT_OP) - func = __rlrr[1][bwd][su]; + func = __rlrr[1][bwd][su]; else if (op == LEFT_OP) - func = __rlrr[0][bwd][su]; - else - assert (0); - goto found; - } - } + func = __rlrr[0][bwd][su]; + else + assert (0); + goto found; + } + } } assert (0); found: @@ -668,28 +669,28 @@ found: if (!options.intlong_rent) { /* first one */ - if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) { - newic = newiCode (SEND, IC_LEFT (ic), NULL); - newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); - } + if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) { + newic = newiCode (SEND, IC_LEFT (ic), NULL); + newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); + } else - { - newic = newiCode ('=', NULL, IC_LEFT (ic)); - IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)); - } + { + newic = newiCode ('=', NULL, IC_LEFT (ic)); + IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)); + } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; /* second one */ if (IS_REGPARM (FUNC_ARGS(func->type)->next->etype)) { - newic = newiCode (SEND, IC_RIGHT (ic), NULL); - newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->next->etype); + newic = newiCode (SEND, IC_RIGHT (ic), NULL); + newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->next->etype); } else - { - newic = newiCode ('=', NULL, IC_RIGHT (ic)); - IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)->next); - } + { + newic = newiCode ('=', NULL, IC_RIGHT (ic)); + IC_RESULT (newic) = operandFromValue (FUNC_ARGS(func->type)->next); + } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; @@ -701,15 +702,15 @@ found: if (IS_REGPARM (FUNC_ARGS(func->type)->next->etype)) { newic = newiCode (SEND, IC_RIGHT (ic), NULL); - newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->next->etype); + newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->next->etype); } else - { - newic = newiCode (IPUSH, IC_RIGHT (ic), NULL); - newic->parmPush = 1; + { + newic = newiCode (IPUSH, IC_RIGHT (ic), NULL); + newic->parmPush = 1; - bytesPushed += getSize(operandType(IC_RIGHT(ic))); - } + bytesPushed += getSize(operandType(IC_RIGHT(ic))); + } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; @@ -717,15 +718,15 @@ found: if (IS_REGPARM (FUNC_ARGS(func->type)->etype)) { newic = newiCode (SEND, IC_LEFT (ic), NULL); - newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); + newic->argreg = SPEC_ARGREG(FUNC_ARGS(func->type)->etype); } else - { - newic = newiCode (IPUSH, IC_LEFT (ic), NULL); - newic->parmPush = 1; + { + newic = newiCode (IPUSH, IC_LEFT (ic), NULL); + newic->parmPush = 1; - bytesPushed += getSize(operandType(IC_LEFT(ic))); - } + bytesPushed += getSize(operandType(IC_LEFT(ic))); + } addiCodeToeBBlock (ebp, newic, ip); newic->lineno = lineno; @@ -741,16 +742,16 @@ found: FUNC_HASFCALL (currFunc->type) = 1; if(TARGET_IS_PIC16) { - /* normally these functions aren't marked external, so we can use their - * _extern field to marked as already added to symbol table */ + /* normally these functions aren't marked external, so we can use their + * _extern field to marked as already added to symbol table */ - if(!SPEC_EXTR(func->etype)) { - memmap *seg = SPEC_OCLS(OP_SYMBOL(IC_LEFT(newic))->etype); - - SPEC_EXTR(func->etype) = 1; - seg = SPEC_OCLS( func->etype ); - addSet(&seg->syms, func); - } + if(!SPEC_EXTR(func->etype)) { + memmap *seg = SPEC_OCLS(OP_SYMBOL(IC_LEFT(newic))->etype); + + SPEC_EXTR(func->etype) = 1; + seg = SPEC_OCLS( func->etype ); + addSet(&seg->syms, func); + } } addiCodeToeBBlock (ebp, newic, ip); @@ -759,7 +760,7 @@ found: /*-----------------------------------------------------------------*/ /* convertToFcall - converts some operations to fcalls */ /*-----------------------------------------------------------------*/ -static void +static void convertToFcall (eBBlock ** ebbs, int count) { int i; @@ -771,31 +772,31 @@ convertToFcall (eBBlock ** ebbs, int count) /* for all instructions in the block do */ for (ic = ebbs[i]->sch; ic; ic = ic->next) - { + { - /* floating point operations are - converted to function calls */ - if ((IS_CONDITIONAL (ic) || - IS_ARITHMETIC_OP (ic)) && + /* floating point operations are + converted to function calls */ + if ((IS_CONDITIONAL (ic) || + IS_ARITHMETIC_OP (ic)) && (IS_FLOAT (operandType (IC_RIGHT (ic))) || IS_FIXED( operandType (IC_RIGHT (ic))))) - { + { - cnvToFcall (ic, ebbs[i]); - } + cnvToFcall (ic, ebbs[i]); + } - /* casting is a little different */ - if (ic->op == CAST) - { - if (IS_FLOAT (operandType (IC_RIGHT (ic)))) - cnvFromFloatCast (ic, ebbs[i]); - else if (IS_FLOAT (operandType (IC_LEFT (ic)))) - cnvToFloatCast (ic, ebbs[i]); + /* casting is a little different */ + if (ic->op == CAST) + { + if (IS_FLOAT (operandType (IC_RIGHT (ic)))) + cnvFromFloatCast (ic, ebbs[i]); + else if (IS_FLOAT (operandType (IC_LEFT (ic)))) + cnvToFloatCast (ic, ebbs[i]); if (IS_FIXED16X16 (operandType (IC_RIGHT (ic)))) cnvFromFixed16x16Cast (ic, ebbs[i]); else if (IS_FIXED16X16 (operandType (IC_LEFT (ic)))) cnvToFixed16x16Cast (ic, ebbs[i]); - } + } // Easy special case which avoids function call: modulo by a literal power // of two can be replaced by a bitwise AND. @@ -831,12 +832,12 @@ convertToFcall (eBBlock ** ebbs, int count) } } - /* if long / int mult or divide or mod */ - if (ic->op == '*' || ic->op == '/' || ic->op == '%') - { - sym_link *leftType = operandType (IC_LEFT (ic)); + /* if long / int mult or divide or mod */ + if (ic->op == '*' || ic->op == '/' || ic->op == '%') + { + sym_link *leftType = operandType (IC_LEFT (ic)); - if (IS_INTEGRAL (leftType) && getSize (leftType) > port->support.muldiv) + if (IS_INTEGRAL (leftType) && getSize (leftType) > port->support.muldiv) { sym_link *rightType = operandType (IC_RIGHT (ic)); @@ -850,18 +851,18 @@ convertToFcall (eBBlock ** ebbs, int count) convilong (ic, ebbs[i], leftType, ic->op); } } - } - + } + if (ic->op == RRC || ic->op == RLC || ic->op == LEFT_OP || ic->op == RIGHT_OP) { - sym_link *type = operandType (IC_LEFT (ic)); + sym_link *type = operandType (IC_LEFT (ic)); - if (IS_INTEGRAL (type) && getSize (type) > port->support.shift && port->support.shift >= 0) + if (IS_INTEGRAL (type) && getSize (type) > port->support.shift && port->support.shift >= 0) { convilong (ic, ebbs[i], type, ic->op); } } - } + } } } @@ -874,26 +875,26 @@ isLocalWithoutDef (symbol * sym) { if (!IS_AUTO (sym)) return 0; - + if (IS_VOLATILE (sym->type)) return 0; - + if (sym->_isparm) return 0; - + if (IS_AGGREGATE (sym->type)) return 0; - + if (sym->addrtaken) return 0; - + return !sym->defs; } /*-----------------------------------------------------------------*/ /* replaceRegEqv - replace all local variables with their reqv */ /*-----------------------------------------------------------------*/ -static void +static void replaceRegEqv (ebbIndex * ebbi) { eBBlock ** ebbs = ebbi->bbOrder; @@ -912,121 +913,121 @@ replaceRegEqv (ebbIndex * ebbi) iCode *ic; for (ic = ebbs[i]->sch; ic; ic = ic->next) - { + { - if (SKIP_IC2 (ic)) - continue; + if (SKIP_IC2 (ic)) + continue; - if (ic->op == IFX) - { - if (IC_COND (ic) && - IS_TRUE_SYMOP (IC_COND (ic)) && + if (ic->op == IFX) + { + if (IC_COND (ic) && + IS_TRUE_SYMOP (IC_COND (ic)) && isLocalWithoutDef (OP_SYMBOL (IC_COND (ic)))) - { - werrorfl (ic->filename, ic->lineno, - W_LOCAL_NOINIT, - OP_SYMBOL (IC_COND (ic))->name); - OP_REQV (IC_COND (ic)) = NULL; - OP_SYMBOL (IC_COND (ic))->allocreq = 1; - } - - if (IS_TRUE_SYMOP (IC_COND (ic)) && - OP_REQV (IC_COND (ic))) - IC_COND (ic) = opFromOpWithDU (OP_REQV (IC_COND (ic)), - OP_SYMBOL (IC_COND (ic))->defs, - OP_SYMBOL (IC_COND (ic))->uses); - - continue; - } + { + werrorfl (ic->filename, ic->lineno, + W_LOCAL_NOINIT, + OP_SYMBOL (IC_COND (ic))->name); + OP_REQV (IC_COND (ic)) = NULL; + OP_SYMBOL (IC_COND (ic))->allocreq = 1; + } - - if (ic->op == JUMPTABLE) - { - if (IC_JTCOND (ic) && - IS_TRUE_SYMOP (IC_JTCOND (ic)) && + if (IS_TRUE_SYMOP (IC_COND (ic)) && + OP_REQV (IC_COND (ic))) + IC_COND (ic) = opFromOpWithDU (OP_REQV (IC_COND (ic)), + OP_SYMBOL (IC_COND (ic))->defs, + OP_SYMBOL (IC_COND (ic))->uses); + + continue; + } + + + if (ic->op == JUMPTABLE) + { + if (IC_JTCOND (ic) && + IS_TRUE_SYMOP (IC_JTCOND (ic)) && isLocalWithoutDef (OP_SYMBOL (IC_JTCOND (ic)))) - { - werrorfl (ic->filename, ic->lineno, - W_LOCAL_NOINIT, - OP_SYMBOL (IC_JTCOND (ic))->name); - OP_REQV (IC_JTCOND (ic)) = NULL; - OP_SYMBOL (IC_JTCOND (ic))->allocreq = 1; - } - - if (IS_TRUE_SYMOP (IC_JTCOND (ic)) && - OP_REQV (IC_JTCOND (ic))) - IC_JTCOND (ic) = opFromOpWithDU (OP_REQV (IC_JTCOND (ic)), - OP_SYMBOL (IC_JTCOND (ic))->defs, - OP_SYMBOL (IC_JTCOND (ic))->uses); - continue; - } + { + werrorfl (ic->filename, ic->lineno, + W_LOCAL_NOINIT, + OP_SYMBOL (IC_JTCOND (ic))->name); + OP_REQV (IC_JTCOND (ic)) = NULL; + OP_SYMBOL (IC_JTCOND (ic))->allocreq = 1; + } - if (ic->op == RECEIVE) - { - if (OP_SYMBOL (IC_RESULT (ic))->addrtaken) - OP_SYMBOL (IC_RESULT (ic))->isspilt = 1; - } + if (IS_TRUE_SYMOP (IC_JTCOND (ic)) && + OP_REQV (IC_JTCOND (ic))) + IC_JTCOND (ic) = opFromOpWithDU (OP_REQV (IC_JTCOND (ic)), + OP_SYMBOL (IC_JTCOND (ic))->defs, + OP_SYMBOL (IC_JTCOND (ic))->uses); + continue; + } - /* general case */ - if (IC_RESULT (ic) && - IS_TRUE_SYMOP (IC_RESULT (ic)) && - OP_REQV (IC_RESULT (ic))) - { - if (POINTER_SET (ic)) - { - IC_RESULT (ic) = opFromOpWithDU (OP_REQV (IC_RESULT (ic)), - OP_SYMBOL (IC_RESULT (ic))->defs, - OP_SYMBOL (IC_RESULT (ic))->uses); - IC_RESULT (ic)->isaddr = 1; - } - else - IC_RESULT (ic) = opFromOpWithDU (OP_REQV (IC_RESULT (ic)), - OP_SYMBOL (IC_RESULT (ic))->defs, - OP_SYMBOL (IC_RESULT (ic))->uses); - } + if (ic->op == RECEIVE) + { + if (OP_SYMBOL (IC_RESULT (ic))->addrtaken) + OP_SYMBOL (IC_RESULT (ic))->isspilt = 1; + } - if (IC_RIGHT (ic) && - IS_TRUE_SYMOP (IC_RIGHT (ic)) && - isLocalWithoutDef (OP_SYMBOL (IC_RIGHT (ic)))) - { - werrorfl (ic->filename, ic->lineno, - W_LOCAL_NOINIT, - OP_SYMBOL (IC_RIGHT (ic))->name); - OP_REQV (IC_RIGHT (ic)) = NULL; - OP_SYMBOL (IC_RIGHT (ic))->allocreq = 1; - } - - if (IC_RIGHT (ic) && - IS_TRUE_SYMOP (IC_RIGHT (ic)) && - OP_REQV (IC_RIGHT (ic))) - { - IC_RIGHT (ic) = opFromOpWithDU (OP_REQV (IC_RIGHT (ic)), - OP_SYMBOL (IC_RIGHT (ic))->defs, - OP_SYMBOL (IC_RIGHT (ic))->uses); - IC_RIGHT (ic)->isaddr = 0; - } + /* general case */ + if (IC_RESULT (ic) && + IS_TRUE_SYMOP (IC_RESULT (ic)) && + OP_REQV (IC_RESULT (ic))) + { + if (POINTER_SET (ic)) + { + IC_RESULT (ic) = opFromOpWithDU (OP_REQV (IC_RESULT (ic)), + OP_SYMBOL (IC_RESULT (ic))->defs, + OP_SYMBOL (IC_RESULT (ic))->uses); + IC_RESULT (ic)->isaddr = 1; + } + else + IC_RESULT (ic) = opFromOpWithDU (OP_REQV (IC_RESULT (ic)), + OP_SYMBOL (IC_RESULT (ic))->defs, + OP_SYMBOL (IC_RESULT (ic))->uses); + } - if (IC_LEFT (ic) && - IS_TRUE_SYMOP (IC_LEFT (ic)) && - isLocalWithoutDef (OP_SYMBOL (IC_LEFT (ic)))) - { - werrorfl (ic->filename, ic->lineno, - W_LOCAL_NOINIT, - OP_SYMBOL (IC_LEFT (ic))->name); - OP_REQV (IC_LEFT (ic)) = NULL; - OP_SYMBOL (IC_LEFT (ic))->allocreq = 1; - } - - if (IC_LEFT (ic) && - IS_TRUE_SYMOP (IC_LEFT (ic)) && - OP_REQV (IC_LEFT (ic))) - { - IC_LEFT (ic) = opFromOpWithDU (OP_REQV (IC_LEFT (ic)), - OP_SYMBOL (IC_LEFT (ic))->defs, - OP_SYMBOL (IC_LEFT (ic))->uses); - IC_LEFT (ic)->isaddr = 0; - } - } + if (IC_RIGHT (ic) && + IS_TRUE_SYMOP (IC_RIGHT (ic)) && + isLocalWithoutDef (OP_SYMBOL (IC_RIGHT (ic)))) + { + werrorfl (ic->filename, ic->lineno, + W_LOCAL_NOINIT, + OP_SYMBOL (IC_RIGHT (ic))->name); + OP_REQV (IC_RIGHT (ic)) = NULL; + OP_SYMBOL (IC_RIGHT (ic))->allocreq = 1; + } + + if (IC_RIGHT (ic) && + IS_TRUE_SYMOP (IC_RIGHT (ic)) && + OP_REQV (IC_RIGHT (ic))) + { + IC_RIGHT (ic) = opFromOpWithDU (OP_REQV (IC_RIGHT (ic)), + OP_SYMBOL (IC_RIGHT (ic))->defs, + OP_SYMBOL (IC_RIGHT (ic))->uses); + IC_RIGHT (ic)->isaddr = 0; + } + + if (IC_LEFT (ic) && + IS_TRUE_SYMOP (IC_LEFT (ic)) && + isLocalWithoutDef (OP_SYMBOL (IC_LEFT (ic)))) + { + werrorfl (ic->filename, ic->lineno, + W_LOCAL_NOINIT, + OP_SYMBOL (IC_LEFT (ic))->name); + OP_REQV (IC_LEFT (ic)) = NULL; + OP_SYMBOL (IC_LEFT (ic))->allocreq = 1; + } + + if (IC_LEFT (ic) && + IS_TRUE_SYMOP (IC_LEFT (ic)) && + OP_REQV (IC_LEFT (ic))) + { + IC_LEFT (ic) = opFromOpWithDU (OP_REQV (IC_LEFT (ic)), + OP_SYMBOL (IC_LEFT (ic))->defs, + OP_SYMBOL (IC_LEFT (ic))->uses); + IC_LEFT (ic)->isaddr = 0; + } + } } } @@ -1038,47 +1039,47 @@ findReqv (symbol * prereqv, eBBlock ** ebbs, int count) { int i; iCode * ic; - + /* for all blocks do */ for (i=0; isch; ic; ic = ic->next) - { - if (ic->op == IFX) - { - if (IS_ITEMP (IC_COND (ic)) - && OP_SYMBOL (IC_COND (ic))->prereqv == prereqv) - return IC_COND (ic); - } - else if (ic->op == JUMPTABLE) - { - if (IS_ITEMP (IC_JTCOND (ic)) - && OP_SYMBOL (IC_JTCOND (ic))->prereqv == prereqv) - return IC_JTCOND (ic); - } - else - { - if (IS_ITEMP (IC_LEFT (ic)) - && OP_SYMBOL (IC_LEFT (ic))->prereqv == prereqv) - return IC_LEFT (ic); - if (IS_ITEMP (IC_RIGHT (ic)) - && OP_SYMBOL (IC_RIGHT (ic))->prereqv == prereqv) - return IC_RIGHT (ic); - if (IS_ITEMP (IC_RESULT (ic)) - && OP_SYMBOL (IC_RESULT (ic))->prereqv == prereqv) - return IC_RESULT (ic); - } - } + { + if (ic->op == IFX) + { + if (IS_ITEMP (IC_COND (ic)) + && OP_SYMBOL (IC_COND (ic))->prereqv == prereqv) + return IC_COND (ic); + } + else if (ic->op == JUMPTABLE) + { + if (IS_ITEMP (IC_JTCOND (ic)) + && OP_SYMBOL (IC_JTCOND (ic))->prereqv == prereqv) + return IC_JTCOND (ic); + } + else + { + if (IS_ITEMP (IC_LEFT (ic)) + && OP_SYMBOL (IC_LEFT (ic))->prereqv == prereqv) + return IC_LEFT (ic); + if (IS_ITEMP (IC_RIGHT (ic)) + && OP_SYMBOL (IC_RIGHT (ic))->prereqv == prereqv) + return IC_RIGHT (ic); + if (IS_ITEMP (IC_RESULT (ic)) + && OP_SYMBOL (IC_RESULT (ic))->prereqv == prereqv) + return IC_RESULT (ic); + } + } } - + return NULL; } /*-----------------------------------------------------------------*/ /* killDeadCode - eliminates dead assignments */ /*-----------------------------------------------------------------*/ -int +int killDeadCode (ebbIndex * ebbi) { eBBlock ** ebbs = ebbi->dfOrder; @@ -1107,182 +1108,182 @@ killDeadCode (ebbIndex * ebbi) change = 0; /* for all blocks do */ for (i = 0; i < count; i++) - { - iCode *ic; + { + iCode *ic; - /* for all instructions in the block do */ - for (ic = ebbs[i]->sch; ic; ic = ic->next) - { - int kill, j; - kill = 0; + /* for all instructions in the block do */ + for (ic = ebbs[i]->sch; ic; ic = ic->next) + { + int kill, j; + kill = 0; - if (SKIP_IC (ic) || - ic->op == IFX || - ic->op == RETURN || + if (SKIP_IC (ic) || + ic->op == IFX || + ic->op == RETURN || ic->op == DUMMY_READ_VOLATILE || ic->op == CRITICAL || ic->op == ENDCRITICAL) - continue; + continue; + + /* Since both IFX & JUMPTABLE (in SKIP_IC) have been tested for */ + /* it is now safe to assume IC_LEFT, IC_RIGHT, & IC_RESULT are */ + /* valid. */ - /* Since both IFX & JUMPTABLE (in SKIP_IC) have been tested for */ - /* it is now safe to assume IC_LEFT, IC_RIGHT, & IC_RESULT are */ - /* valid. */ + /* if the result is volatile then continue */ + if (IC_RESULT (ic) && isOperandVolatile (IC_RESULT (ic), FALSE)) + continue; - /* if the result is volatile then continue */ - if (IC_RESULT (ic) && isOperandVolatile (IC_RESULT (ic), FALSE)) - continue; + /* if the result is a temp & isaddr then skip */ + if (IC_RESULT (ic) && POINTER_SET (ic)) + continue; - /* if the result is a temp & isaddr then skip */ - if (IC_RESULT (ic) && POINTER_SET (ic)) - continue; - if (POINTER_GET (ic) && IS_VOLATILE (operandType (IC_LEFT (ic))->next) - && !SPIL_LOC (IC_RESULT (ic))) + && !SPIL_LOC (IC_RESULT (ic))) + continue; + + /* if the result is used in the remainder of the */ + /* block then skip */ + if (usedInRemaining (IC_RESULT (ic), ic->next)) continue; - /* if the result is used in the remainder of the */ - /* block then skip */ - if (usedInRemaining (IC_RESULT (ic), ic->next)) - continue; - - /* does this definition reach the end of the block - or the usage is zero then we can kill */ - if (!bitVectBitValue (ebbs[i]->outDefs, ic->key)) - kill = 1; /* if not we can kill it */ - else - { - /* if this is a global variable or function parameter */ - /* we cannot kill anyway */ - if (isOperandGlobal (IC_RESULT (ic)) || - (OP_SYMBOL (IC_RESULT (ic))->_isparm && - !OP_SYMBOL (IC_RESULT (ic))->ismyparm)) - continue; - - /* if we are sure there are no usages */ - if (bitVectIsZero (OP_USES (IC_RESULT (ic)))) - { - kill = 1; - goto kill; - } - - /* reset visited flag */ - for (j = 0; j < count; ebbs[j++]->visited = 0); - - /* find out if this definition is alive */ - if (applyToSet (ebbs[i]->succList, - isDefAlive, - ic)) - continue; - - kill = 1; + /* does this definition reach the end of the block + or the usage is zero then we can kill */ + if (!bitVectBitValue (ebbs[i]->outDefs, ic->key)) + kill = 1; /* if not we can kill it */ + else + { + /* if this is a global variable or function parameter */ + /* we cannot kill anyway */ + if (isOperandGlobal (IC_RESULT (ic)) || + (OP_SYMBOL (IC_RESULT (ic))->_isparm && + !OP_SYMBOL (IC_RESULT (ic))->ismyparm)) + continue; + + /* if we are sure there are no usages */ + if (bitVectIsZero (OP_USES (IC_RESULT (ic)))) + { + kill = 1; + goto kill; + } + + /* reset visited flag */ + for (j = 0; j < count; ebbs[j++]->visited = 0); + + /* find out if this definition is alive */ + if (applyToSet (ebbs[i]->succList, + isDefAlive, + ic)) + continue; + + kill = 1; } - kill: - /* kill this one if required */ - if (kill) - { - bool volLeft = IS_SYMOP (IC_LEFT (ic)) - && isOperandVolatile (IC_LEFT (ic), FALSE); - bool volRight = IS_SYMOP (IC_RIGHT (ic)) - && isOperandVolatile (IC_RIGHT (ic), FALSE); - - /* a dead address-of operation should die, even if volatile */ - if (ic->op == ADDRESS_OF) - volLeft = FALSE; - - if (ic->next && ic->seqPoint == ic->next->seqPoint - && (ic->next->op == '+' || ic->next->op == '-')) - { - if (isOperandEqual (IC_LEFT(ic), IC_LEFT(ic->next)) - || isOperandEqual (IC_LEFT(ic), IC_RIGHT(ic->next))) - volLeft = FALSE; - if (isOperandEqual (IC_RIGHT(ic), IC_LEFT(ic->next)) - || isOperandEqual (IC_RIGHT(ic), IC_RIGHT(ic->next))) - volRight = FALSE; - } - - if (POINTER_GET (ic) && IS_VOLATILE (operandType (IC_LEFT (ic))->next)) - { - if (SPIL_LOC (IC_RESULT (ic))) - { - IC_RESULT (ic) = newiTempFromOp (IC_RESULT (ic)); - SPIL_LOC (IC_RESULT (ic)) = NULL; - } - continue; - } - - change = 1; - gchange++; - - /* now delete from defUseSet */ - deleteItemIf (&ebbs[i]->outExprs, ifDiCodeIsX, ic); - bitVectUnSetBit (ebbs[i]->outDefs, ic->key); - - /* and defset of the block */ - bitVectUnSetBit (ebbs[i]->defSet, ic->key); - - /* If this is the last of a register equivalent, */ - /* look for a successor register equivalent. */ - bitVectUnSetBit (OP_DEFS (IC_RESULT (ic)), ic->key); - if (IS_ITEMP (IC_RESULT (ic)) - && OP_SYMBOL (IC_RESULT (ic))->isreqv - && bitVectIsZero (OP_DEFS (IC_RESULT (ic)))) - { - symbol * resultsym = OP_SYMBOL (IC_RESULT (ic)); - symbol * prereqv = resultsym->prereqv; - + kill: + /* kill this one if required */ + if (kill) + { + bool volLeft = IS_SYMOP (IC_LEFT (ic)) + && isOperandVolatile (IC_LEFT (ic), FALSE); + bool volRight = IS_SYMOP (IC_RIGHT (ic)) + && isOperandVolatile (IC_RIGHT (ic), FALSE); + + /* a dead address-of operation should die, even if volatile */ + if (ic->op == ADDRESS_OF) + volLeft = FALSE; + + if (ic->next && ic->seqPoint == ic->next->seqPoint + && (ic->next->op == '+' || ic->next->op == '-')) + { + if (isOperandEqual (IC_LEFT(ic), IC_LEFT(ic->next)) + || isOperandEqual (IC_LEFT(ic), IC_RIGHT(ic->next))) + volLeft = FALSE; + if (isOperandEqual (IC_RIGHT(ic), IC_LEFT(ic->next)) + || isOperandEqual (IC_RIGHT(ic), IC_RIGHT(ic->next))) + volRight = FALSE; + } + + if (POINTER_GET (ic) && IS_VOLATILE (operandType (IC_LEFT (ic))->next)) + { + if (SPIL_LOC (IC_RESULT (ic))) + { + IC_RESULT (ic) = newiTempFromOp (IC_RESULT (ic)); + SPIL_LOC (IC_RESULT (ic)) = NULL; + } + continue; + } + + change = 1; + gchange++; + + /* now delete from defUseSet */ + deleteItemIf (&ebbs[i]->outExprs, ifDiCodeIsX, ic); + bitVectUnSetBit (ebbs[i]->outDefs, ic->key); + + /* and defset of the block */ + bitVectUnSetBit (ebbs[i]->defSet, ic->key); + + /* If this is the last of a register equivalent, */ + /* look for a successor register equivalent. */ + bitVectUnSetBit (OP_DEFS (IC_RESULT (ic)), ic->key); + if (IS_ITEMP (IC_RESULT (ic)) + && OP_SYMBOL (IC_RESULT (ic))->isreqv + && bitVectIsZero (OP_DEFS (IC_RESULT (ic)))) + { + symbol * resultsym = OP_SYMBOL (IC_RESULT (ic)); + symbol * prereqv = resultsym->prereqv; + if (prereqv && prereqv->reqv && (OP_SYMBOL (prereqv->reqv) == resultsym)) - { - operand * newreqv; - - IC_RESULT (ic) = NULL; - newreqv = findReqv (prereqv, ebbs, count); - if (newreqv) - { - prereqv->reqv = newreqv; - } - } - } - - /* delete the result */ - IC_RESULT (ic) = NULL; - - if (volLeft || volRight) - { - /* something is volatile, so keep the iCode */ - /* and change the operator instead */ - ic->op = DUMMY_READ_VOLATILE; - - /* keep only the volatile operands */ - if (!volLeft) - IC_LEFT (ic) = NULL; - if (!volRight) - IC_RIGHT (ic) = NULL; - } - else - { - /* nothing is volatile, eliminate the iCode */ - remiCodeFromeBBlock (ebbs[i], ic); - - /* for the left & right remove the usage */ - if (IS_SYMOP (IC_LEFT (ic))) - bitVectUnSetBit (OP_USES (IC_LEFT (ic)), ic->key); - - if (IS_SYMOP (IC_RIGHT (ic))) - bitVectUnSetBit (OP_USES (IC_RIGHT (ic)), ic->key); - } - } - - } /* end of all instructions */ - - if (!ebbs[i]->sch && !ebbs[i]->noPath) + { + operand * newreqv; + + IC_RESULT (ic) = NULL; + newreqv = findReqv (prereqv, ebbs, count); + if (newreqv) + { + prereqv->reqv = newreqv; + } + } + } + + /* delete the result */ + IC_RESULT (ic) = NULL; + + if (volLeft || volRight) + { + /* something is volatile, so keep the iCode */ + /* and change the operator instead */ + ic->op = DUMMY_READ_VOLATILE; + + /* keep only the volatile operands */ + if (!volLeft) + IC_LEFT (ic) = NULL; + if (!volRight) + IC_RIGHT (ic) = NULL; + } + else + { + /* nothing is volatile, eliminate the iCode */ + remiCodeFromeBBlock (ebbs[i], ic); + + /* for the left & right remove the usage */ + if (IS_SYMOP (IC_LEFT (ic))) + bitVectUnSetBit (OP_USES (IC_LEFT (ic)), ic->key); + + if (IS_SYMOP (IC_RIGHT (ic))) + bitVectUnSetBit (OP_USES (IC_RIGHT (ic)), ic->key); + } + } + + } /* end of all instructions */ + + if (!ebbs[i]->sch && !ebbs[i]->noPath) disconBBlock (ebbs[i], ebbi); - } /* end of for all blocks */ + } /* end of for all blocks */ if (!change) - break; - } /* end of while(1) */ + break; + } /* end of while(1) */ return gchange; } @@ -1290,7 +1291,7 @@ killDeadCode (ebbIndex * ebbi) /*-----------------------------------------------------------------*/ /* printCyclomatic - prints the cyclomatic information */ /*-----------------------------------------------------------------*/ -static void +static void printCyclomatic (eBBlock ** ebbs, int count) { int nEdges = elementsInSet (graphEdges); @@ -1307,7 +1308,7 @@ printCyclomatic (eBBlock ** ebbs, int count) /* discardDeadParamReceives - remove any RECEIVE opcodes which */ /* refer to dead variables. */ /*-----------------------------------------------------------------*/ -static void +static void discardDeadParamReceives (eBBlock ** ebbs, int count) { int i; @@ -1317,22 +1318,22 @@ discardDeadParamReceives (eBBlock ** ebbs, int count) for (i = 0; i < count; i++) { for (ic = ebbs[i]->sch; ic; ic = ic->next) - { - if (ic->op == RECEIVE) - { - if (IC_RESULT (ic) && OP_SYMBOL (IC_RESULT (ic)) - && !OP_SYMBOL (IC_RESULT (ic))->used) - { + { + if (ic->op == RECEIVE) + { + if (IC_RESULT (ic) && OP_SYMBOL (IC_RESULT (ic)) + && !OP_SYMBOL (IC_RESULT (ic))->used) + { #if 0 - fprintf (stderr, "discarding dead receive for %s\n", - OP_SYMBOL (IC_RESULT (ic))->name); + fprintf (stderr, "discarding dead receive for %s\n", + OP_SYMBOL (IC_RESULT (ic))->name); #endif - dummyIcode.next = ic->next; - remiCodeFromeBBlock (ebbs[i], ic); - ic = &dummyIcode; - } - } - } + dummyIcode.next = ic->next; + remiCodeFromeBBlock (ebbs[i], ic); + ic = &dummyIcode; + } + } + } } } @@ -1343,7 +1344,7 @@ discardDeadParamReceives (eBBlock ** ebbs, int count) /* char and long are the same, the cast can be safely performed in */ /* a single step. */ /*-----------------------------------------------------------------*/ -static void +static void optimizeCastCast (eBBlock ** ebbs, int count) { int i; @@ -1357,52 +1358,52 @@ optimizeCastCast (eBBlock ** ebbs, int count) for (i = 0; i < count; i++) { for (ic = ebbs[i]->sch; ic; ic = ic->next) - { - - if (ic->op == CAST && IC_RESULT (ic) && IS_ITEMP (IC_RESULT (ic))) - { - type1 = operandType (IC_RIGHT (ic)); - type2 = operandType (IC_RESULT (ic)); - - /* Look only for a cast from an integer type to an */ - /* integer type that has no loss of bits */ - if (!IS_INTEGRAL (type1) || !IS_INTEGRAL (type2)) - continue; - if (getSize (type2) < getSize (type1)) - continue; - - /* There must be only one use of this first result */ - if (bitVectnBitsOn (OP_USES (IC_RESULT (ic))) != 1) - continue; - - /* This use must be a second cast */ - uic = hTabItemWithKey (iCodehTab, - bitVectFirstBit (OP_USES (IC_RESULT (ic)))); - if (!uic || uic->op != CAST) - continue; - - /* It must be a cast to another integer type that */ - /* has no loss of bits */ - type3 = operandType (IC_RESULT (uic)); - if (!IS_INTEGRAL (type3)) - continue; - if (getSize (type3) < getSize (type2)) - continue; - - /* The signedness between the first and last types */ - /* must match */ - if (SPEC_USIGN (type3) != SPEC_USIGN (type1)) - continue; - - /* Change the first cast to a simple assignment and */ - /* let the second cast do all the work */ - ic->op = '='; - IC_LEFT (ic) = NULL; - sym = OP_SYMBOL (IC_RESULT (ic)); - sym->type = copyLinkChain (type1); - sym->etype = getSpec (sym->type); - } - } + { + + if (ic->op == CAST && IC_RESULT (ic) && IS_ITEMP (IC_RESULT (ic))) + { + type1 = operandType (IC_RIGHT (ic)); + type2 = operandType (IC_RESULT (ic)); + + /* Look only for a cast from an integer type to an */ + /* integer type that has no loss of bits */ + if (!IS_INTEGRAL (type1) || !IS_INTEGRAL (type2)) + continue; + if (getSize (type2) < getSize (type1)) + continue; + + /* There must be only one use of this first result */ + if (bitVectnBitsOn (OP_USES (IC_RESULT (ic))) != 1) + continue; + + /* This use must be a second cast */ + uic = hTabItemWithKey (iCodehTab, + bitVectFirstBit (OP_USES (IC_RESULT (ic)))); + if (!uic || uic->op != CAST) + continue; + + /* It must be a cast to another integer type that */ + /* has no loss of bits */ + type3 = operandType (IC_RESULT (uic)); + if (!IS_INTEGRAL (type3)) + continue; + if (getSize (type3) < getSize (type2)) + continue; + + /* The signedness between the first and last types */ + /* must match */ + if (SPEC_USIGN (type3) != SPEC_USIGN (type1)) + continue; + + /* Change the first cast to a simple assignment and */ + /* let the second cast do all the work */ + ic->op = '='; + IC_LEFT (ic) = NULL; + sym = OP_SYMBOL (IC_RESULT (ic)); + sym->type = copyLinkChain (type1); + sym->etype = getSpec (sym->type); + } + } } } @@ -1425,20 +1426,20 @@ eBBlockFromiCode (iCode * ic) eBBNum = 0; - /* optimize the chain for labels & gotos + /* optimize the chain for labels & gotos this will eliminate redundant labels and will change jump to jumps by jumps */ ic = iCodeLabelOptimize (ic); /* break it down into basic blocks */ ebbi = iCodeBreakDown (ic); - + /* hash the iCode keys so that we can quickly index */ /* them in the rest of the optimization steps */ setToNull ((void *) &iCodehTab); iCodehTab = newHashTable (iCodeKey); hashiCodeKeys (ebbi->bbOrder, ebbi->count); - + /* compute the control flow */ computeControlFlow (ebbi); @@ -1448,7 +1449,7 @@ eBBlockFromiCode (iCode * ic) /* replace the local variables with their register equivalents : the liveRange computation - along with the register allocation will determine + along with the register allocation will determine if it finally stays in the registers */ replaceRegEqv (ebbi); @@ -1460,7 +1461,7 @@ eBBlockFromiCode (iCode * ic) dumpEbbsToFileExt (DUMP_RAW1, ebbi); optimizeCastCast (ebbi->bbOrder, ebbi->count); - + /* do common subexpression elimination for each block */ change = cseAllBlocks (ebbi, FALSE); @@ -1498,7 +1499,7 @@ eBBlockFromiCode (iCode * ic) if (options.dump_loop) dumpEbbsToFileExt (DUMP_LOOP, ebbi); - /* recompute the data flow and apply global cse again + /* recompute the data flow and apply global cse again if loops optimizations or dead code caused a change: loops will brings out of the loop which then may be available for use in the later blocks: dead code @@ -1532,16 +1533,16 @@ eBBlockFromiCode (iCode * ic) // the user is on his own with naked functions... if (!IS_VOID(currFunc->etype) && !FUNC_ISNAKED(currFunc->type)) { - eBBlock *bp; - // make sure all predecessors of the last block end in a return + eBBlock *bp; + // make sure all predecessors of the last block end in a return for (bp=setFirstItem(ebbi->bbOrder[ebbi->count-1]->predList); - bp; + bp; bp=setNextItem(ebbi->bbOrder[ebbi->count-1]->predList)) { - if (bp->ech->op != RETURN) { - werrorfl (bp->ech->filename, bp->ech->lineno, - W_VOID_FUNC, currFunc->name); - } - } + if (bp->ech->op != RETURN) { + werrorfl (bp->ech->filename, bp->ech->lineno, + W_VOID_FUNC, currFunc->name); + } + } } } } @@ -1551,7 +1552,7 @@ eBBlockFromiCode (iCode * ic) printCyclomatic (ebbi->bbOrder, ebbi->count); /* convert operations with support routines - written in C to function calls : Iam doing + written in C to function calls : I am doing this at this point since I want all the operations to be as they are for optimzations */ convertToFcall (ebbi->bbOrder, ebbi->count); @@ -1572,7 +1573,7 @@ eBBlockFromiCode (iCode * ic) /* throw away blocks */ setToNull ((void *) &graphEdges); - + return NULL; } diff --git a/src/SDCCpeeph.c b/src/SDCCpeeph.c index 26946581..8225ac5e 100644 --- a/src/SDCCpeeph.c +++ b/src/SDCCpeeph.c @@ -25,6 +25,10 @@ #include "common.h" +#define ISCHARDIGIT(c) isdigit((unsigned char)c) +#define ISCHARSPACE(c) isspace((unsigned char)c) +#define ISCHARALNUM(c) isalnum((unsigned char)c) + static peepRule *rootRules = NULL; static peepRule *currRule = NULL; @@ -51,7 +55,7 @@ static bool matchLine (char *, char *, hTab **); bool isLabelDefinition (const char *line, const char **start, int *len); #define FBYNAME(x) int x (hTab *vars, lineNode *currPl, lineNode *endPl, \ - lineNode *head, char *cmdLine) + lineNode *head, char *cmdLine) #if !OPT_DISABLE_PIC void peepRules2pCode(peepRule *); @@ -65,7 +69,7 @@ void pic16_peepRules2pCode(peepRule *); /* pcDistance - afinds a label back ward or forward */ /*-----------------------------------------------------------------*/ -int +int pcDistance (lineNode * cpos, char *lbl, bool back) { lineNode *pl = cpos; @@ -77,45 +81,45 @@ pcDistance (lineNode * cpos, char *lbl, bool back) { if (pl->line && - *pl->line != ';' && - pl->line[strlen (pl->line) - 1] != ':' && - !pl->isDebug) { - if (port->peep.getSize) { - dist += port->peep.getSize(pl); - } else { - dist += 3; - } - } + *pl->line != ';' && + pl->line[strlen (pl->line) - 1] != ':' && + !pl->isDebug) { + if (port->peep.getSize) { + dist += port->peep.getSize(pl); + } else { + dist += 3; + } + } if (strncmp (pl->line, buff, strlen (buff)) == 0) - return dist; + return dist; if (back) - pl = pl->prev; + pl = pl->prev; else - pl = pl->next; + pl = pl->next; } return 0; } /*-----------------------------------------------------------------*/ -/* flat24bitModeAndPortDS390 - */ +/* flat24bitModeAndPortDS390 - */ /*-----------------------------------------------------------------*/ FBYNAME (flat24bitModeAndPortDS390) { return (((strcmp(port->target,"ds390") == 0) || - (strcmp(port->target,"ds400") == 0)) && - (options.model == MODEL_FLAT24)); + (strcmp(port->target,"ds400") == 0)) && + (options.model == MODEL_FLAT24)); } /*-----------------------------------------------------------------*/ -/* portIsDS390 - return true if port is DS390 */ +/* portIsDS390 - return true if port is DS390 */ /*-----------------------------------------------------------------*/ FBYNAME (portIsDS390) { return ((strcmp(port->target,"ds390") == 0) || - (strcmp(port->target,"ds400") == 0)); + (strcmp(port->target,"ds400") == 0)); } /*-----------------------------------------------------------------*/ @@ -154,7 +158,7 @@ FBYNAME (labelInRange) /* Don't optimize jumps in a jump table; a more generic test */ if (currPl->ic && currPl->ic->op == JUMPTABLE) return FALSE; - + /* if the previous two instructions are "ljmp"s then don't do it since it can be part of a jump table */ if (currPl->prev && currPl->prev->prev && @@ -169,7 +173,7 @@ FBYNAME (labelInRange) for a relative jump. we could get more precise this will suffice for now since it catches > 90% cases */ dist = (pcDistance (currPl, lbl, TRUE) + - pcDistance (currPl, lbl, FALSE)); + pcDistance (currPl, lbl, FALSE)); /* changed to 127, now that pcDistance return actual number of bytes */ if (!dist || dist > 127) @@ -192,13 +196,13 @@ FBYNAME (labelJTInRange) if (!getenv("SDCC_SJMP_JUMPTABLE")) return FALSE; - + /* Only optimize within a jump table */ if (currPl->ic && currPl->ic->op != JUMPTABLE) return FALSE; - + count = elementsInSet( IC_JTLABELS (currPl->ic) ); - + /* check all labels (this is needed if the case statements are unsorted) */ for (i=0; i 127+ /* range of sjmp */ - (7+3*i)+ /* offset between this jump and currPl, + (7+3*i)+ /* offset between this jump and currPl, should use pcDistance instead? */ (count-i-1) /* if peephole applies distance is shortened */ ) @@ -239,16 +243,16 @@ FBYNAME (labelIsReturnOnly) len = strlen(label); for(pl = currPl; pl; pl = pl->next) { - if (pl->line && !pl->isDebug && !pl->isComment && - pl->line[strlen(pl->line)-1] == ':') { - if (strncmp(pl->line, label, len) == 0) break; /* Found Label */ - if (strlen(pl->line) != 7 || !isdigit(*(pl->line)) || - !isdigit(*(pl->line+1)) || !isdigit(*(pl->line+2)) || - !isdigit(*(pl->line+3)) || !isdigit(*(pl->line+4)) || - *(pl->line+5) != '$') { - return FALSE; /* non-local label encountered */ - } - } + if (pl->line && !pl->isDebug && !pl->isComment && + pl->line[strlen(pl->line)-1] == ':') { + if (strncmp(pl->line, label, len) == 0) break; /* Found Label */ + if (strlen(pl->line) != 7 || !ISCHARDIGIT(*(pl->line)) || + !ISCHARDIGIT(*(pl->line+1)) || !ISCHARDIGIT(*(pl->line+2)) || + !ISCHARDIGIT(*(pl->line+3)) || !ISCHARDIGIT(*(pl->line+4)) || + *(pl->line+5) != '$') { + return FALSE; /* non-local label encountered */ + } + } } if (!pl) return FALSE; /* did not find the label */ pl = pl->next; @@ -256,9 +260,9 @@ FBYNAME (labelIsReturnOnly) pl = pl->next; if (!pl || !pl->line || pl->isDebug) return FALSE; /* next line not valid */ p = pl->line; - for (p = pl->line; *p && isspace(*p); p++) - ; - + for (p = pl->line; *p && ISCHARSPACE(*p); p++) + ; + retInst = "ret"; if (TARGET_IS_HC08) retInst = "rts"; @@ -289,15 +293,15 @@ FBYNAME (okToRemoveSLOC) /* Look for any occurance of this SLOC before the peephole match */ for (pl = currPl->prev; pl; pl = pl->prev) { - if (pl->line && !pl->isDebug && !pl->isComment - && *pl->line != ';' && strstr(pl->line, sloc)) - return FALSE; + if (pl->line && !pl->isDebug && !pl->isComment + && *pl->line != ';' && strstr(pl->line, sloc)) + return FALSE; } /* Look for any occurance of this SLOC after the peephole match */ for (pl = endPl->next; pl; pl = pl->next) { - if (pl->line && !pl->isDebug && !pl->isComment - && *pl->line != ';' && strstr(pl->line, sloc)) - return FALSE; + if (pl->line && !pl->isDebug && !pl->isComment + && *pl->line != ';' && strstr(pl->line, sloc)) + return FALSE; } return TRUE; /* safe for a peephole to remove it :) */ } @@ -525,49 +529,49 @@ FBYNAME (labelRefCount) char *label = hTabItemWithKey (vars, varNumber); if (label) - { - labelHashEntry *entry; - - entry = hTabFirstItemWK (labelHash, hashSymbolName (label)); - - while (entry) - { - if (!strcmp (label, entry->name)) - { - break; - } - entry = hTabNextItemWK (labelHash); - } - if (entry) - { + { + labelHashEntry *entry; + + entry = hTabFirstItemWK (labelHash, hashSymbolName (label)); + + while (entry) + { + if (!strcmp (label, entry->name)) + { + break; + } + entry = hTabNextItemWK (labelHash); + } + if (entry) + { #if 0 - /* debug spew. */ - fprintf (stderr, "labelRefCount: %s has refCount %d, want %d\n", - label, entry->refCount, expectedRefCount); + /* debug spew. */ + fprintf (stderr, "labelRefCount: %s has refCount %d, want %d\n", + label, entry->refCount, expectedRefCount); #endif - rc = (expectedRefCount == entry->refCount); - } - else - { - fprintf (stderr, "*** internal error: no label has entry for" - " %s in labelRefCount peephole.\n", - label); - } - } + rc = (expectedRefCount == entry->refCount); + } + else + { + fprintf (stderr, "*** internal error: no label has entry for" + " %s in labelRefCount peephole.\n", + label); + } + } else - { - fprintf (stderr, "*** internal error: var %d not bound" - " in peephole labelRefCount rule.\n", - varNumber); - } + { + fprintf (stderr, "*** internal error: var %d not bound" + " in peephole labelRefCount rule.\n", + varNumber); + } } else { fprintf (stderr, - "*** internal error: labelRefCount peephole restriction" - " malformed: %s\n", cmdLine); + "*** internal error: labelRefCount peephole restriction" + " malformed: %s\n", cmdLine); } return rc; } @@ -636,7 +640,7 @@ FBYNAME (labelRefCountChange) else { fprintf (stderr, "*** internal error: var %d not bound" - " in peephole %s rule.\n", + " in peephole %s rule.\n", varNumber, __FUNCTION__); } } @@ -692,7 +696,7 @@ notVolatileVariable(char *var, lineNode *currPl, lineNode *endPl) /* Extract a symbol name from the variable */ while (*vp && (*vp!='_')) vp++; - while (*vp && (isalnum(*vp) || *vp=='_')) + while (*vp && (ISCHARALNUM(*vp) || *vp=='_')) *p++ = *vp++; *p='\0'; @@ -733,7 +737,7 @@ notVolatileVariable(char *var, lineNode *currPl, lineNode *endPl) } } } - + /* Couldn't find the symbol for some reason. Assume volatile. */ return FALSE; } @@ -795,18 +799,18 @@ FBYNAME (notVolatile) } /* There were parameters; check the volatility of each */ - while (*cmdLine && isspace(*cmdLine)) + while (*cmdLine && ISCHARSPACE(*cmdLine)) cmdLine++; while (*cmdLine) { if (*cmdLine!='%') goto error; cmdLine++; - if (!isdigit(*cmdLine)) + if (!ISCHARDIGIT(*cmdLine)) goto error; varNumber = strtol(cmdLine, &digitend, 10); cmdLine = digitend; - while (*cmdLine && isspace(*cmdLine)) + while (*cmdLine && ISCHARSPACE(*cmdLine)) cmdLine++; var = hTabItemWithKey (vars, varNumber); @@ -818,17 +822,17 @@ FBYNAME (notVolatile) return FALSE; } else - { - fprintf (stderr, "*** internal error: var %d not bound" - " in peephole notVolatile rule.\n", - varNumber); - return FALSE; - } + { + fprintf (stderr, "*** internal error: var %d not bound" + " in peephole notVolatile rule.\n", + varNumber); + return FALSE; + } } return TRUE; - - + + error: fprintf (stderr, "*** internal error: notVolatile peephole restriction" @@ -853,8 +857,8 @@ setFromConditionArgs (char *cmdLine, hTab * vars) if (!cmdLine) return NULL; - - while (*cmdLine && isspace(*cmdLine)) + + while (*cmdLine && ISCHARSPACE(*cmdLine)) cmdLine++; while (*cmdLine) @@ -862,7 +866,7 @@ setFromConditionArgs (char *cmdLine, hTab * vars) if (*cmdLine == '%') { cmdLine++; - if (!isdigit(*cmdLine)) + if (!ISCHARDIGIT(*cmdLine)) goto error; varNumber = strtol(cmdLine, &digitend, 10); cmdLine = digitend; @@ -879,7 +883,7 @@ setFromConditionArgs (char *cmdLine, hTab * vars) else if (*cmdLine == '\'' ) { char quote = *cmdLine; - + var = ++cmdLine; while (*cmdLine && *cmdLine != quote) cmdLine++; @@ -891,8 +895,8 @@ setFromConditionArgs (char *cmdLine, hTab * vars) } else goto error; - - while (*cmdLine && isspace(*cmdLine)) + + while (*cmdLine && ISCHARSPACE(*cmdLine)) cmdLine++; } @@ -910,7 +914,7 @@ operandBaseName (const char *op) { if (!strcmp (op, "acc") || !strncmp (op, "acc.", 4)) return "a"; - if (!strncmp (op, "ar", 2) && isdigit(*(op+2)) && !*(op+3)) + if (!strncmp (op, "ar", 2) && ISCHARDIGIT(*(op+2)) && !*(op+3)) return op+1; } @@ -927,7 +931,7 @@ FBYNAME (operandsNotRelated) { set *operands; const char *op1, *op2; - + operands = setFromConditionArgs (cmdLine, vars); if (!operands) @@ -936,13 +940,13 @@ FBYNAME (operandsNotRelated) "*** internal error: operandsNotRelated peephole restriction" " malformed: %s\n", cmdLine); return FALSE; - } + } while ((op1 = setFirstItem (operands))) { deleteSetItem (&operands, (void*)op1); op1 = operandBaseName (op1); - + for (op2 = setFirstItem (operands); op2; op2 = setNextItem (operands)) { op2 = operandBaseName (op2); @@ -957,17 +961,17 @@ FBYNAME (operandsNotRelated) deleteSet (&operands); return TRUE; } - + /*-----------------------------------------------------------------*/ /* callFuncByName - calls a function as defined in the table */ /*-----------------------------------------------------------------*/ -int +int callFuncByName (char *fname, - hTab * vars, - lineNode * currPl, - lineNode * endPl, - lineNode * head) + hTab * vars, + lineNode * currPl, + lineNode * endPl, + lineNode * head) { struct ftab { @@ -1011,7 +1015,7 @@ callFuncByName (char *fname, { "operandsNotSame8", operandsNotSame8 } - , + , { "24bitMode", flat24bitMode } @@ -1046,16 +1050,16 @@ callFuncByName (char *fname, "labelRefCountChange", labelRefCountChange } }; - int i; + int i; char *cmdCopy, *funcName, *funcArgs, *cmdTerm; char c; - int rc; - - /* Isolate the function name part (we are passed the full condition - * string including arguments) + int rc; + + /* Isolate the function name part (we are passed the full condition + * string including arguments) */ cmdTerm = cmdCopy = Safe_strdup(fname); - + do { funcArgs = funcName = cmdTerm; @@ -1064,12 +1068,12 @@ callFuncByName (char *fname, *funcArgs = '\0'; /* terminate the function name */ if (c) funcArgs++; - + /* Find the start of the arguments */ if (c == ' ' || c == '\t') while ((c = *funcArgs) && (c == ' ' || c == '\t')) funcArgs++; - + /* If the arguments started with an opening parenthesis, */ /* use the closing parenthesis for the end of the */ /* arguments and look for the start of another condition */ @@ -1098,46 +1102,46 @@ callFuncByName (char *fname, if (!*funcArgs) funcArgs = NULL; - + rc = -1; for (i = 0; i < ((sizeof (ftab)) / (sizeof (struct ftab))); i++) { - if (strcmp (ftab[i].fname, funcName) == 0) - { - rc = (*ftab[i].func) (vars, currPl, endPl, head, - funcArgs); + if (strcmp (ftab[i].fname, funcName) == 0) + { + rc = (*ftab[i].func) (vars, currPl, endPl, head, + funcArgs); break; - } + } } - + if (rc == -1) { - fprintf (stderr, - "could not find named function \"%s\" in " - "peephole function table\n", - funcName); + fprintf (stderr, + "could not find named function \"%s\" in " + "peephole function table\n", + funcName); // If the function couldn't be found, let's assume it's - // a bad rule and refuse it. - rc = FALSE; + // a bad rule and refuse it. + rc = FALSE; break; } } while (rc && cmdTerm); - + Safe_free(cmdCopy); - + return rc; } /*-----------------------------------------------------------------*/ /* printLine - prints a line chain into a given file */ /*-----------------------------------------------------------------*/ -void +void printLine (lineNode * head, FILE * of) { iCode *last_ic = NULL; bool debug_iCode_tracking = (getenv("DEBUG_ICODE_TRACKING")!=NULL); - + if (!of) of = stdout; @@ -1155,18 +1159,18 @@ printLine (lineNode * head, FILE * of) fprintf (of, "; iCode lost\n"); } } - + /* don't indent comments & labels */ if (head->line && - (*head->line == ';' || - head->line[strlen (head->line) - 1] == ':')) { - fprintf (of, "%s\n", head->line); + (*head->line == ';' || + head->line[strlen (head->line) - 1] == ':')) { + fprintf (of, "%s\n", head->line); } else { - if (head->isInline && *head->line=='#') { - // comment out preprocessor directives in inline asm - fprintf (of, ";"); - } - fprintf (of, "\t%s\n", head->line); + if (head->isInline && *head->line=='#') { + // comment out preprocessor directives in inline asm + fprintf (of, ";"); + } + fprintf (of, "\t%s\n", head->line); } head = head->next; } @@ -1177,9 +1181,9 @@ printLine (lineNode * head, FILE * of) /*-----------------------------------------------------------------*/ peepRule * newPeepRule (lineNode * match, - lineNode * replace, - char *cond, - int restart) + lineNode * replace, + char *cond, + int restart) { peepRule *pr; @@ -1238,7 +1242,7 @@ connectLine (lineNode * pl1, lineNode * pl2) return pl2; } -#define SKIP_SPACE(x,y) { while (*x && (isspace(*x) || *x == '\n')) x++; \ +#define SKIP_SPACE(x,y) { while (*x && (ISCHARSPACE(*x) || *x == '\n')) x++; \ if (!*x) { fprintf(stderr,y); return ; } } #define EXPECT_STR(x,y,z) { while (*x && strncmp(x,y,strlen(y))) x++ ; \ @@ -1249,7 +1253,7 @@ connectLine (lineNode * pl1, lineNode * pl2) /*-----------------------------------------------------------------*/ /* getPeepLine - parses the peep lines */ /*-----------------------------------------------------------------*/ -static void +static void getPeepLine (lineNode ** head, char **bpp) { char lines[MAX_PATTERN_LEN]; @@ -1262,44 +1266,44 @@ getPeepLine (lineNode ** head, char **bpp) { if (!*bp) - { - fprintf (stderr, "unexpected end of match pattern\n"); - return; - } + { + fprintf (stderr, "unexpected end of match pattern\n"); + return; + } if (*bp == '\n') - { - bp++; - while (isspace (*bp) || - *bp == '\n') - bp++; - } + { + bp++; + while (ISCHARSPACE (*bp) || + *bp == '\n') + bp++; + } if (*bp == '}') - { - bp++; - break; - } + { + bp++; + break; + } /* read till end of line */ lp = lines; while ((*bp != '\n' && *bp != '}') && *bp) - *lp++ = *bp++; + *lp++ = *bp++; *lp = '\0'; - + lp = lines; - while (*lp && isspace(*lp)) + while (*lp && ISCHARSPACE(*lp)) lp++; isComment = (*lp == ';'); - + if (!isComment || (isComment && !options.noPeepComments)) - { - if (!currL) - *head = currL = newLineNode (lines); - else - currL = connectLine (currL, newLineNode (lines)); - currL->isComment = isComment; - } + { + if (!currL) + *head = currL = newLineNode (lines); + else + currL = connectLine (currL, newLineNode (lines)); + currL->isComment = isComment; + } } @@ -1309,7 +1313,7 @@ getPeepLine (lineNode ** head, char **bpp) /*-----------------------------------------------------------------*/ /* readRules - reads the rules from a string buffer */ /*-----------------------------------------------------------------*/ -static void +static void readRules (char *bp) { char restart = 0; @@ -1334,7 +1338,7 @@ top: /* then look for either "restart" or '{' */ while (strncmp (bp, "restart", 7) && - *bp != '{' && bp) + *bp != '{' && bp) bp++; /* not found */ @@ -1348,7 +1352,7 @@ top: if (*bp == '{') bp++; else - { /* must be restart */ + { /* must be restart */ restart++; bp += strlen ("restart"); /* look for '{' */ @@ -1374,26 +1378,26 @@ top: getPeepLine (&replace, &bp); /* look for a 'if' */ - while ((isspace (*bp) || *bp == '\n') && *bp) + while ((ISCHARSPACE (*bp) || *bp == '\n') && *bp) bp++; if (strncmp (bp, "if", 2) == 0) { bp += 2; - while ((isspace (*bp) || *bp == '\n') && *bp) - bp++; + while ((ISCHARSPACE (*bp) || *bp == '\n') && *bp) + bp++; if (!*bp) - { - fprintf (stderr, "expected condition name\n"); - return; - } + { + fprintf (stderr, "expected condition name\n"); + return; + } /* look for the condition */ lp = lines; while (*bp && (*bp != '\n')) - { - *lp++ = *bp++; - } + { + *lp++ = *bp++; + } *lp = '\0'; newPeepRule (match, replace, lines, restart); @@ -1407,12 +1411,12 @@ top: /*-----------------------------------------------------------------*/ /* keyForVar - returns the numeric key for a var */ /*-----------------------------------------------------------------*/ -static int +static int keyForVar (char *d) { int i = 0; - while (isdigit (*d)) + while (ISCHARDIGIT (*d)) { i *= 10; i += (*d++ - '0'); @@ -1424,7 +1428,7 @@ keyForVar (char *d) /*-----------------------------------------------------------------*/ /* bindVar - binds a value to a variable in the given hashtable */ /*-----------------------------------------------------------------*/ -static void +static void bindVar (int key, char **s, hTab ** vtab) { char vval[MAX_PATTERN_LEN]; @@ -1435,30 +1439,30 @@ bindVar (int key, char **s, hTab ** vtab) vvx = *s; /* the value is ended by a ',' or space or newline or null or ) */ while (*vvx && - *vvx != ',' && - !isspace (*vvx) && - *vvx != '\n' && - *vvx != ':' && - *vvx != ')') + *vvx != ',' && + !ISCHARSPACE (*vvx) && + *vvx != '\n' && + *vvx != ':' && + *vvx != ')') { char ubb = 0; /* if we find a '(' then we need to balance it */ if (*vvx == '(') - { - ubb++; - while (ubb) - { - *vv++ = *vvx++; - if (*vvx == '(') - ubb++; - if (*vvx == ')') - ubb--; - } - // include the trailing ')' - *vv++ = *vvx++; - } + { + ubb++; + while (ubb) + { + *vv++ = *vvx++; + if (*vvx == '(') + ubb++; + if (*vvx == ')') + ubb--; + } + // include the trailing ')' + *vv++ = *vvx++; + } else - *vv++ = *vvx++; + *vv++ = *vvx++; } *s = vvx; *vv = '\0'; @@ -1471,7 +1475,7 @@ bindVar (int key, char **s, hTab ** vtab) /*-----------------------------------------------------------------*/ /* matchLine - matches one line */ /*-----------------------------------------------------------------*/ -static bool +static bool matchLine (char *s, char *d, hTab ** vars) { @@ -1482,56 +1486,56 @@ matchLine (char *s, char *d, hTab ** vars) { /* skip white space in both */ - while (isspace (*s)) - s++; - while (isspace (*d)) - d++; + while (ISCHARSPACE (*s)) + s++; + while (ISCHARSPACE (*d)) + d++; /* if the destination is a var */ - if (*d == '%' && isdigit (*(d + 1)) && vars) - { - char *v = hTabItemWithKey (*vars, keyForVar (d + 1)); - /* if the variable is already bound - then it MUST match with dest */ - if (v) - { - while (*v) - if (*v++ != *s++) - return FALSE; - } - else - /* variable not bound we need to - bind it */ - bindVar (keyForVar (d + 1), &s, vars); - - /* in either case go past the variable */ - d++; - while (isdigit (*d)) - d++; - - while (isspace (*s)) - s++; - while (isspace (*d)) - d++; - } + if (*d == '%' && ISCHARDIGIT (*(d + 1)) && vars) + { + char *v = hTabItemWithKey (*vars, keyForVar (d + 1)); + /* if the variable is already bound + then it MUST match with dest */ + if (v) + { + while (*v) + if (*v++ != *s++) + return FALSE; + } + else + /* variable not bound we need to + bind it */ + bindVar (keyForVar (d + 1), &s, vars); + + /* in either case go past the variable */ + d++; + while (ISCHARDIGIT (*d)) + d++; + + while (ISCHARSPACE (*s)) + s++; + while (ISCHARSPACE (*d)) + d++; + } /* they should be an exact match other wise */ if (*s && *d) - { - if (*s++ != *d++) - return FALSE; - } + { + if (*s++ != *d++) + return FALSE; + } } /* get rid of the trailing spaces in both source & destination */ if (*s) - while (isspace (*s)) + while (ISCHARSPACE (*s)) s++; if (*d) - while (isspace (*d)) + while (ISCHARSPACE (*d)) d++; /* after all this if only one of them @@ -1545,14 +1549,14 @@ matchLine (char *s, char *d, hTab ** vars) /*-----------------------------------------------------------------*/ /* matchRule - matches a all the rule lines */ /*-----------------------------------------------------------------*/ -static bool +static bool matchRule (lineNode * pl, - lineNode ** mtail, - peepRule * pr, - lineNode * head) + lineNode ** mtail, + peepRule * pr, + lineNode * head) { - lineNode *spl; /* source pl */ - lineNode *rpl; /* rule peep line */ + lineNode *spl; /* source pl */ + lineNode *rpl; /* rule peep line */ /* setToNull((void *) &pr->vars); */ /* pr->vars = newHashTable(100); */ @@ -1567,18 +1571,18 @@ matchRule (lineNode * pl, comment line don't process or the source line contains == . debugger information skip it */ if (spl->line && - (*spl->line == ';' || spl->isDebug)) - { - spl = spl->next; - continue; - } + (*spl->line == ';' || spl->isDebug)) + { + spl = spl->next; + continue; + } if (!matchLine (spl->line, rpl->line, &pr->vars)) - return FALSE; + return FALSE; rpl = rpl->next; if (rpl) - spl = spl->next; + spl = spl->next; } /* if rules ended */ @@ -1586,20 +1590,20 @@ matchRule (lineNode * pl, { /* if this rule has additional conditions */ if (pr->cond) - { - if (callFuncByName (pr->cond, pr->vars, pl, spl, head)) - { - *mtail = spl; - return TRUE; - } - else - return FALSE; - } + { + if (callFuncByName (pr->cond, pr->vars, pl, spl, head)) + { + *mtail = spl; + return TRUE; + } + else + return FALSE; + } else - { - *mtail = spl; - return TRUE; - } + { + *mtail = spl; + return TRUE; + } } else return FALSE; @@ -1609,8 +1613,8 @@ static void reassociate_ic_down (lineNode *shead, lineNode *stail, lineNode *rhead, lineNode *rtail) { - lineNode *csl; /* current source line */ - lineNode *crl; /* current replacement line */ + lineNode *csl; /* current source line */ + lineNode *crl; /* current replacement line */ csl = shead; crl = rhead; @@ -1641,8 +1645,8 @@ static void reassociate_ic_up (lineNode *shead, lineNode *stail, lineNode *rhead, lineNode *rtail) { - lineNode *csl; /* current source line */ - lineNode *crl; /* current replacement line */ + lineNode *csl; /* current source line */ + lineNode *crl; /* current replacement line */ csl = stail; crl = rtail; @@ -1676,11 +1680,11 @@ static void reassociate_ic (lineNode *shead, lineNode *stail, lineNode *rhead, lineNode *rtail) { - lineNode *csl; /* current source line */ - lineNode *crl; /* current replacement line */ + lineNode *csl; /* current source line */ + lineNode *crl; /* current replacement line */ bool single_iCode; iCode *ic; - + /* Check to see if all the source lines (excluding comments) came ** for the same iCode */ @@ -1706,11 +1710,11 @@ reassociate_ic (lineNode *shead, lineNode *stail, crl->ic = ic; return; } - + single_iCode = FALSE; break; } - + /* If all of the source lines came from the same iCode, then so have ** all of the replacement lines too. */ @@ -1720,7 +1724,7 @@ reassociate_ic (lineNode *shead, lineNode *stail, crl->ic = ic; return; } - + /* The source lines span iCodes, so we may end up with replacement ** lines that we don't know which iCode(s) to associate with. Do the ** best we can by using the following strategies: @@ -1737,7 +1741,7 @@ reassociate_ic (lineNode *shead, lineNode *stail, /* Strategy #1: Start at the top and scan down for matches */ reassociate_ic_down(shead,stail,rhead,rtail); - + /* Strategy #2: Start at the bottom and scan up for matches */ reassociate_ic_up(shead,stail,rhead,rtail); @@ -1749,7 +1753,7 @@ reassociate_ic (lineNode *shead, lineNode *stail, { const char *labelStart; int labelLength; - + /* skip over any comments */ while (csl!=stail->next && csl->isComment) csl = csl->next; @@ -1777,7 +1781,7 @@ reassociate_ic (lineNode *shead, lineNode *stail, } csl = csl->next; } - + /* Try to assign a meaningful iCode to any comment that is missing one. Since they are comments, it's ok to make mistakes; we are just trying to improve continuity to simplify other tests. @@ -1791,11 +1795,11 @@ reassociate_ic (lineNode *shead, lineNode *stail, } } - + /*-----------------------------------------------------------------*/ /* replaceRule - does replacement of a matching pattern */ /*-----------------------------------------------------------------*/ -static void +static void replaceRule (lineNode ** shead, lineNode * stail, peepRule * pr) { lineNode *cl = NULL; @@ -1810,12 +1814,12 @@ replaceRule (lineNode ** shead, lineNode * stail, peepRule * pr) for (cl = *shead; cl != stail; cl = cl->next) { if (cl->line && (*cl->line == ';' || cl->isDebug)) - { - pl = (pl ? connectLine (pl, newLineNode (cl->line)) : - (comment = newLineNode (cl->line))); - pl->isDebug = cl->isDebug; - pl->isComment = cl->isComment || (*cl->line == ';'); - } + { + pl = (pl ? connectLine (pl, newLineNode (cl->line)) : + (comment = newLineNode (cl->line))); + pl->isDebug = cl->isDebug; + pl->isComment = cl->isComment || (*cl->line == ';'); + } } cl = NULL; @@ -1829,34 +1833,34 @@ replaceRule (lineNode ** shead, lineNode * stail, peepRule * pr) l = pl->line; while (*l) - { - /* if the line contains a variable */ - if (*l == '%' && isdigit (*(l + 1))) - { - v = hTabItemWithKey (pr->vars, keyForVar (l + 1)); - if (!v) - { - fprintf (stderr, "used unbound variable in replacement\n"); - l++; - continue; - } - while (*v) { - *lbp++ = *v++; - } - l++; - while (isdigit (*l)) { - l++; - } - continue; - } - *lbp++ = *l++; - } + { + /* if the line contains a variable */ + if (*l == '%' && ISCHARDIGIT (*(l + 1))) + { + v = hTabItemWithKey (pr->vars, keyForVar (l + 1)); + if (!v) + { + fprintf (stderr, "used unbound variable in replacement\n"); + l++; + continue; + } + while (*v) { + *lbp++ = *v++; + } + l++; + while (ISCHARDIGIT (*l)) { + l++; + } + continue; + } + *lbp++ = *l++; + } *lbp = '\0'; if (cl) - cl = connectLine (cl, newLineNode (lb)); + cl = connectLine (cl, newLineNode (lb)); else - lhead = cl = newLineNode (lb); + lhead = cl = newLineNode (lb); cl->isComment = pl->isComment; } @@ -1865,10 +1869,10 @@ replaceRule (lineNode ** shead, lineNode * stail, peepRule * pr) { lineNode *lc = comment; while (lc->next) - lc = lc->next; + lc = lc->next; lc->next = lhead; if (lhead) - lhead->prev = lc; + lhead->prev = lc; lhead = comment; } @@ -1880,18 +1884,18 @@ replaceRule (lineNode ** shead, lineNode * stail, peepRule * pr) /* now we need to connect / replace the original chain */ /* if there is a prev then change it */ if ((*shead)->prev) - { - (*shead)->prev->next = lhead; - lhead->prev = (*shead)->prev; - } + { + (*shead)->prev->next = lhead; + lhead->prev = (*shead)->prev; + } *shead = lhead; /* now for the tail */ if (stail && stail->next) - { - stail->next->prev = cl; - if (cl) - cl->next = stail->next; - } + { + stail->next->prev = cl; + if (cl) + cl->next = stail->next; + } } else { @@ -1909,7 +1913,7 @@ replaceRule (lineNode ** shead, lineNode * stail, peepRule * pr) * If so, start will point to the start of the label name, * and len will be it's length. */ -bool +bool isLabelDefinition (const char *line, const char **start, int *len) { const char *cp = line; @@ -1919,7 +1923,7 @@ isLabelDefinition (const char *line, const char **start, int *len) * (alnum | $ | _ ) followed by a colon. */ - while (*cp && isspace (*cp)) + while (*cp && ISCHARSPACE (*cp)) { cp++; } @@ -1931,7 +1935,7 @@ isLabelDefinition (const char *line, const char **start, int *len) *start = cp; - while (isalnum (*cp) || (*cp == '$') || (*cp == '_')) + while (ISCHARALNUM (*cp) || (*cp == '$') || (*cp == '_')) { cp++; } @@ -1946,7 +1950,7 @@ isLabelDefinition (const char *line, const char **start, int *len) } /* Quick & dirty string hash function. */ -static int +static int hashSymbolName (const char *name) { int hash = 0; @@ -1968,7 +1972,7 @@ hashSymbolName (const char *name) /* Build a hash of all labels in the passed set of lines * and how many times they are referenced. */ -static void +static void buildLabelRefCountHash (lineNode * head) { lineNode *line; @@ -1985,24 +1989,24 @@ buildLabelRefCountHash (lineNode * head) while (line) { if (isLabelDefinition (line->line, &label, &labelLen) - && labelLen <= SDCC_NAME_MAX) - { - labelHashEntry *entry; + && labelLen <= SDCC_NAME_MAX) + { + labelHashEntry *entry; - entry = traceAlloc (&_G.labels, Safe_alloc(sizeof (labelHashEntry))); + entry = traceAlloc (&_G.labels, Safe_alloc(sizeof (labelHashEntry))); + + memcpy (entry->name, label, labelLen); + entry->name[labelLen] = 0; + entry->refCount = -1; - memcpy (entry->name, label, labelLen); - entry->name[labelLen] = 0; - entry->refCount = -1; - /* Assume function entry points are referenced somewhere, */ /* even if we can't find a reference (might be from outside */ /* the function) */ if (line->ic && (line->ic->op == FUNCTION)) entry->refCount++; - hTabAddItem (&labelHash, hashSymbolName (entry->name), entry); - } + hTabAddItem (&labelHash, hashSymbolName (entry->name), entry); + } line = line->next; } @@ -2013,20 +2017,20 @@ buildLabelRefCountHash (lineNode * head) while (line) { for (i = 0; i < HTAB_SIZE; i++) - { - labelHashEntry *thisEntry; - - thisEntry = hTabFirstItemWK (labelHash, i); - - while (thisEntry) - { - if (strstr (line->line, thisEntry->name)) - { - thisEntry->refCount++; - } - thisEntry = hTabNextItemWK (labelHash); - } - } + { + labelHashEntry *thisEntry; + + thisEntry = hTabFirstItemWK (labelHash, i); + + while (thisEntry) + { + if (strstr (line->line, thisEntry->name)) + { + thisEntry->refCount++; + } + thisEntry = hTabNextItemWK (labelHash); + } + } line = line->next; } @@ -2039,11 +2043,11 @@ buildLabelRefCountHash (lineNode * head) thisEntry = hTabFirstItemWK (labelHash, i); while (thisEntry) - { - fprintf (stderr, "label: %s ref %d\n", - thisEntry->name, thisEntry->refCount); - thisEntry = hTabNextItemWK (labelHash); - } + { + fprintf (stderr, "label: %s ref %d\n", + thisEntry->name, thisEntry->refCount); + thisEntry = hTabNextItemWK (labelHash); + } } #endif } @@ -2060,13 +2064,13 @@ buildLabelRefCountHash (lineNode * head) matchLine Where is stuff allocated? - + */ /*-----------------------------------------------------------------*/ /* peepHole - matches & substitutes rules */ /*-----------------------------------------------------------------*/ -void +void peepHole (lineNode ** pls) { lineNode *spl; @@ -2099,21 +2103,21 @@ peepHole (lineNode ** pls) ** or comment */ if (spl->isDebug || spl->isComment || *(spl->line)==';') continue; - + mtail = NULL; /* Tidy up any data stored in the hTab */ - + /* if it matches */ if (matchRule (spl, &mtail, pr, *pls)) { - + /* then replace */ if (spl == *pls) replaceRule (pls, mtail, pr); else replaceRule (&spl, mtail, pr); - + /* if restart rule type then start at the top again */ if (pr->restart) @@ -2121,14 +2125,14 @@ peepHole (lineNode ** pls) restart = TRUE; } } - + if (pr->vars) { hTabDeleteAll (pr->vars); Safe_free (pr->vars); pr->vars = NULL; } - + freeTrace (&_G.values); } } @@ -2167,20 +2171,20 @@ readFileIntoBuffer (char *fname) /* if we maxed out our local buffer */ if (nch >= (MAX_PATTERN_LEN - 2)) - { - lb[nch] = '\0'; - /* copy it into allocated buffer */ - if (rs) - { - rs = Safe_realloc (rs, strlen (rs) + strlen (lb) + 1); - strncatz (rs, lb, strlen (rs) + strlen (lb) + 1); - } - else - { - rs = Safe_strdup (lb); - } - nch = 0; - } + { + lb[nch] = '\0'; + /* copy it into allocated buffer */ + if (rs) + { + rs = Safe_realloc (rs, strlen (rs) + strlen (lb) + 1); + strncatz (rs, lb, strlen (rs) + strlen (lb) + 1); + } + else + { + rs = Safe_strdup (lb); + } + nch = 0; + } } /* if some charaters left over */ @@ -2189,14 +2193,14 @@ readFileIntoBuffer (char *fname) lb[nch] = '\0'; /* copy it into allocated buffer */ if (rs) - { - rs = Safe_realloc (rs, strlen (rs) + strlen (lb) + 1); - strncatz (rs, lb, strlen (rs) + strlen (lb) + 1); - } + { + rs = Safe_realloc (rs, strlen (rs) + strlen (lb) + 1); + strncatz (rs, lb, strlen (rs) + strlen (lb) + 1); + } else - { - rs = Safe_strdup (lb); - } + { + rs = Safe_strdup (lb); + } } return rs; } @@ -2204,7 +2208,7 @@ readFileIntoBuffer (char *fname) /*-----------------------------------------------------------------*/ /* initPeepHole - initialises the peep hole optimizer stuff */ /*-----------------------------------------------------------------*/ -void +void initPeepHole () { char *s; @@ -2224,8 +2228,8 @@ initPeepHole () /* Convert the peep rules into pcode. NOTE: this is only support in the PIC port (at the moment) */ - if (TARGET_IS_PIC) - peepRules2pCode(rootRules); + if (TARGET_IS_PIC) + peepRules2pCode(rootRules); #endif #if !OPT_DISABLE_PIC16 @@ -2233,8 +2237,8 @@ initPeepHole () NOTE: this is only support in the PIC port (at the moment) and the PIC16 port (VR 030601) */ - if (TARGET_IS_PIC16) - pic16_peepRules2pCode(rootRules); + if (TARGET_IS_PIC16) + pic16_peepRules2pCode(rootRules); #endif diff --git a/src/asm.c b/src/asm.c index 9269fc7e..6fc273a5 100644 --- a/src/asm.c +++ b/src/asm.c @@ -11,7 +11,7 @@ /* A 'token' is like !blah or %24f and is under the programmers control. */ -#define MAX_TOKEN_LEN 64 +#define MAX_TOKEN_LEN 64 static hTab *_h; @@ -27,10 +27,10 @@ FileBaseName (char *fileFullName) while (*fileFullName) { if ((*fileFullName == '/') || (*fileFullName == '\\') || (*fileFullName == ':')) - { - p = fileFullName; - p++; - } + { + p = fileFullName; + p++; + } fileFullName++; } return p; @@ -53,7 +53,7 @@ _appendAt (char *at, char *onto, const char *sz, size_t *max) return at + strlen (at); } -void +void tvsprintf (char *buffer, size_t len, const char *format, va_list ap) { // Under Linux PPC va_list is a structure instead of a primitive type, @@ -67,14 +67,14 @@ tvsprintf (char *buffer, size_t len, const char *format, va_list ap) // 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 noTokens[INITIAL_INLINEASM]; - char newFormat[INITIAL_INLINEASM]; - char *pInto = noTokens; - size_t pIntoLen = sizeof(noTokens); - char *p; - char token[MAX_TOKEN_LEN]; - const char *sz = format; + static int count; + char noTokens[INITIAL_INLINEASM]; + char newFormat[INITIAL_INLINEASM]; + char *pInto = noTokens; + size_t pIntoLen = sizeof(noTokens); + char *p; + char token[MAX_TOKEN_LEN]; + const char *sz = format; // NULL terminate it to let strlen work. *pInto = '\0'; @@ -83,42 +83,42 @@ tvsprintf (char *buffer, size_t len, const char *format, va_list ap) while (pIntoLen && *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, noTokens, t, &pIntoLen); - } - else - { - fprintf (stderr, "Cant find token \"%s\"\n", token); - wassert (0); - } - } + { + /* Start of a token. Search until the first + [non alpha, *] and call it a token. */ + const char *t; + p = token; + sz++; + while (isalpha ((unsigned char)*sz) || *sz == '*') + { + *p++ = *sz++; + } + *p = '\0'; + /* Now find the token in the token list */ + if ((t = _findMapping (token))) + { + pInto = _appendAt (pInto, noTokens, t, &pIntoLen); + } + else + { + fprintf (stderr, "Cant find token \"%s\"\n", token); + wassert (0); + } + } else { *pInto++ = *sz++; - pIntoLen--; + pIntoLen--; } } if (!pIntoLen) { fprintf(stderr, - "Internal error: tvsprintf overflowed on pass one.\n"); + "Internal error: tvsprintf overflowed on pass one.\n"); // Might as well go on... } - + *pInto = '\0'; /* Second pass: Expand any macros that we own */ @@ -129,89 +129,89 @@ tvsprintf (char *buffer, size_t len, const char *format, va_list ap) while (pIntoLen && *sz) { if (*sz == '%') - { - // See if its one that we handle. - sz++; - switch (*sz) - { - case 'C': - // Code segment name. - pInto = _appendAt (pInto, newFormat, CODE_NAME, &pIntoLen); + { + // See if its one that we handle. + sz++; + switch (*sz) + { + case 'C': + // Code segment name. + pInto = _appendAt (pInto, newFormat, CODE_NAME, &pIntoLen); sz++; - break; - case 'F': - // Source file name. - pInto = _appendAt (pInto, newFormat, fullSrcFileName, &pIntoLen); + break; + case 'F': + // Source file name. + pInto = _appendAt (pInto, newFormat, fullSrcFileName, &pIntoLen); sz++; - break; + break; case 'N': // Current function name. pInto = _appendAt (pInto, newFormat, currFunc->rname, &pIntoLen); sz++; break; - case 'I': - { - // Unique ID. - char id[20]; - SNPRINTF (id, sizeof(id), "%u", ++count); - pInto = _appendAt (pInto, newFormat, id, &pIntoLen); + case 'I': + { + // Unique ID. + char id[20]; + SNPRINTF (id, sizeof(id), "%u", ++count); + pInto = _appendAt (pInto, newFormat, id, &pIntoLen); sz++; - break; - } - default: - // Not one of ours. Copy until the end. - *pInto++ = '%'; - pIntoLen--; - while (pIntoLen && !isalpha (*sz)) - { - *pInto++ = *sz++; - pIntoLen--; - } - if (pIntoLen) - { - *pInto++ = *sz++; - pIntoLen--; - } - } - } + break; + } + default: + // Not one of ours. Copy until the end. + *pInto++ = '%'; + pIntoLen--; + while (pIntoLen && !isalpha ((unsigned char)*sz)) + { + *pInto++ = *sz++; + pIntoLen--; + } + if (pIntoLen) + { + *pInto++ = *sz++; + pIntoLen--; + } + } + } else - { - *pInto++ = *sz++; - pIntoLen--; - } + { + *pInto++ = *sz++; + pIntoLen--; + } } if (!pIntoLen) { fprintf(stderr, - "Internal error: tvsprintf overflowed on pass two.\n"); + "Internal error: tvsprintf overflowed on pass two.\n"); // Might as well go on... - } - + } + *pInto = '\0'; // Now do the actual printing #if defined(HAVE_VSNPRINTF) { - int wrlen; - wrlen = vsnprintf (buffer, len, newFormat, ap); - - if (wrlen < 0 || (size_t)wrlen >= len) - { - fprintf(stderr, "Internal error: tvsprintf truncated.\n"); - } + int wrlen; + wrlen = vsnprintf (buffer, len, newFormat, ap); + + if (wrlen < 0 || (size_t)wrlen >= len) + { + fprintf(stderr, "Internal error: tvsprintf truncated.\n"); + } } - -#else + +#else vsprintf (buffer, newFormat, ap); if (strlen(buffer) >= len) { - fprintf(stderr, "Internal error: tvsprintf overflowed.\n"); + fprintf(stderr, "Internal error: tvsprintf overflowed.\n"); } -#endif +#endif } -void +void tfprintf (FILE * fp, const char *szFormat,...) { va_list ap; @@ -223,7 +223,7 @@ tfprintf (FILE * fp, const char *szFormat,...) fputs (buffer, fp); } -void +void tsprintf (char *buffer, size_t len, const char *szFormat,...) { va_list ap; @@ -232,7 +232,7 @@ tsprintf (char *buffer, size_t len, const char *szFormat,...) va_end(ap); } -void +void asm_addTree (const ASM_MAPPINGS * pMappings) { const ASM_MAPPING *pMap; @@ -333,7 +333,7 @@ printCLine (char *srcFile, int lineno) break; } } - while (isspace ((int)*ilsP)) + while (isspace ((unsigned char)*ilsP)) ilsP++; return ilsP; @@ -374,7 +374,7 @@ static const ASM_MAPPING _asxxxx_mapping[] = "; ---------------------------------" }, {"functionlabeldef", "%s:"}, - {"bankimmeds", "0 ; PENDING: bank support"}, + {"bankimmeds", "0 ; PENDING: bank support"}, {"los","(%s & 0xFF)"}, {"his","(%s >> 8)"}, {"hihis","(%s >> 16)"}, @@ -427,7 +427,7 @@ static const ASM_MAPPING _gas_mapping[] = "; ---------------------------------" }, {"functionlabeldef", "%s:"}, - {"bankimmeds", "0 ; PENDING: bank support"}, + {"bankimmeds", "0 ; PENDING: bank support"}, {NULL, NULL} }; @@ -466,7 +466,7 @@ static const ASM_MAPPING _a390_mapping[] = "; ---------------------------------" }, {"functionlabeldef", "%s:"}, - {"bankimmeds", "0 ; PENDING: bank support"}, + {"bankimmeds", "0 ; PENDING: bank support"}, {"los","(%s & 0FFh)"}, {"his","((%s / 256) & 0FFh)"}, {"hihis","((%s / 65536) & 0FFh)"}, @@ -518,7 +518,7 @@ static const ASM_MAPPING _xa_asm_mapping[] = "; ---------------------------------" }, {"functionlabeldef", "%s:"}, - {"bankimmeds", "0 ; PENDING: bank support"}, + {"bankimmeds", "0 ; PENDING: bank support"}, {"los","(%s & 0FFh)"}, {"his","((%s / 256) & 0FFh)"}, {"hihis","((%s / 65536) & 0FFh)"}, diff --git a/src/avr/gen.c b/src/avr/gen.c index e9fc7a73..cde734ea 100644 --- a/src/avr/gen.c +++ b/src/avr/gen.c @@ -249,7 +249,7 @@ emitcode (char *inst, char *fmt, ...) else vsprintf (lb, fmt, ap); - while (isspace (*lbp)) + while (isspace ((unsigned char)*lbp)) lbp++; if (lbp && *lbp) @@ -1041,7 +1041,7 @@ aopPut (asmop * aop, char *s, int offset) break; case AOP_REG: - if (toupper (*s) != 'R') { + if (toupper ((unsigned char)*s) != 'R') { if (s == zero) { emitcode ("clr", "%s", aop->aopu.aop_reg[offset]->name); @@ -1109,7 +1109,7 @@ aopPut (asmop * aop, char *s, int offset) case AOP_CRY: /* if used only for a condition code check */ - assert (toupper (*s) == 'R'); + assert (toupper ((unsigned char)*s) == 'R'); if (offset == 0) { emitcode ("xrl", "r0,r0"); emitcode ("cpi", "%s,0", s); diff --git a/src/ds390/gen.c b/src/ds390/gen.c index b1f3b2e8..3cdc68ba 100644 --- a/src/ds390/gen.c +++ b/src/ds390/gen.c @@ -166,7 +166,7 @@ emitcode (char *inst, const char *fmt,...) tvsprintf (lb, sizeof(lb), fmt, ap); } - while (isspace (*lbp)) + while (isspace ((unsigned char)*lbp)) { lbp++; } @@ -742,7 +742,7 @@ aopForRemat (symbol * sym) aop->aopu.aop_immd.from_cast_remat = 1; ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode; ptr_type = pointerTypeToGPByte (DCL_TYPE(from_type), NULL, NULL); - continue ; + continue; } else break; ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode; @@ -1932,10 +1932,10 @@ genCpl (iCode * ic) */ werror(W_COMPLEMENT); emitcode ("setb", "%s", IC_RESULT (ic)->aop->aopu.aop_dir); - goto release; - } - tlbl=newiTempLabel(NULL); - l = aopGet (AOP (IC_LEFT (ic)), offset++, FALSE, FALSE,NULL); + goto release; + } + tlbl=newiTempLabel(NULL); + l = aopGet (AOP (IC_LEFT (ic)), offset++, FALSE, FALSE, NULL); if (AOP_TYPE (IC_LEFT (ic)) == AOP_ACC || AOP_TYPE (IC_LEFT (ic)) == AOP_REG || IS_AOP_PREG (IC_LEFT (ic))) @@ -1947,10 +1947,10 @@ genCpl (iCode * ic) MOVA (l); emitcode ("cjne", "a,#0xFF,%05d$", tlbl->key + 100); } - emitcode ("", "%05d$:", tlbl->key+100); - outBitC (IC_RESULT(ic)); - goto release; - } + emitcode ("", "%05d$:", tlbl->key+100); + outBitC (IC_RESULT(ic)); + goto release; + } size = AOP_SIZE (IC_RESULT (ic)); _startLazyDPSEvaluation (); @@ -1985,7 +1985,7 @@ genUminusFloat (operand * op, operand * result) size = AOP_SIZE (op) - 1; while (size--) - { + { aopPut (AOP (result), aopGet (AOP (op), offset, FALSE, FALSE, NULL), offset); diff --git a/src/ds390/main.c b/src/ds390/main.c index a2e54083..202eb3b9 100644 --- a/src/ds390/main.c +++ b/src/ds390/main.c @@ -705,7 +705,7 @@ asmLineNodeFromLineNode (lineNode *ln, int currentDPS) asmLineNode *aln = ds390newAsmLineNode(currentDPS); char *op, op1[256], op2[256]; int opsize; - const char *p; + const unsigned char *p; char inst[8]; ds390opcodedata *opdat; diff --git a/src/hc08/gen.c b/src/hc08/gen.c index aab19dea..d824ed12 100644 --- a/src/hc08/gen.c +++ b/src/hc08/gen.c @@ -162,7 +162,7 @@ emitcode (char *inst, char *fmt,...) else vsprintf (lb, fmt, ap); - while (isspace (*lbp)) + while (isspace ((unsigned char)*lbp)) lbp++; if (lbp && *lbp) @@ -5340,7 +5340,7 @@ emitinline (iCode * ic, char *inlin) if (*inlin == '_') { symname = ++inlin; - while (isalnum(*inlin) || (*inlin == '_')) + while (isalnum((unsigned char)*inlin) || (*inlin == '_')) inlin++; c = *inlin; *inlin = '\0'; diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 2ac72db6..7ae3fa4e 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -82,9 +82,9 @@ static unsigned short rbank = -1; #define SYM_BP(sym) (SPEC_OCLS (sym->etype)->paged ? "_bpx" : "_bp") #define R0INB _G.bu.bs.r0InB -#define R1INB _G.bu.bs.r1InB -#define OPINB _G.bu.bs.OpInB -#define BINUSE _G.bu.BInUse +#define R1INB _G.bu.bs.r1InB +#define OPINB _G.bu.bs.OpInB +#define BINUSE _G.bu.BInUse static struct { @@ -166,7 +166,7 @@ emitcode (char *inst, const char *fmt,...) else tvsprintf (lb, sizeof(lb), fmt, ap); - while (isspace (*lbp)) + while (isspace ((unsigned char)*lbp)) lbp++; if (lbp && *lbp) @@ -693,7 +693,7 @@ aopForRemat (symbol * sym) aop->aopu.aop_immd.from_cast_remat = 1; ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode; ptr_type = pointerTypeToGPByte (DCL_TYPE(from_type), NULL, NULL); - continue ; + continue; } else break; ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode; @@ -2064,14 +2064,14 @@ saveRegisters (iCode * lic) else { bool bits_pushed = FALSE; - for (i = 0; i < mcs51_nRegs; i++) - { - if (bitVectBitValue (rsave, i)) + for (i = 0; i < mcs51_nRegs; i++) + { + if (bitVectBitValue (rsave, i)) { bits_pushed = pushReg (i, bits_pushed); } } - } + } } /*-----------------------------------------------------------------*/ @@ -2153,19 +2153,19 @@ unsaveRegisters (iCode * ic) else { bool bits_popped = FALSE; - for (i = mcs51_nRegs; i >= 0; i--) - { - if (bitVectBitValue (rsave, i)) + for (i = mcs51_nRegs; i >= 0; i--) + { + if (bitVectBitValue (rsave, i)) { bits_popped = popReg (i, bits_popped); } } - } + } } /*-----------------------------------------------------------------*/ -/* pushSide - */ +/* pushSide - */ /*-----------------------------------------------------------------*/ static void pushSide (operand * oper, int size) @@ -2321,7 +2321,7 @@ genIpush (iCode * ic) strcmp (l, "a")) { if (strcmp (l, prev) || *l == '@') - MOVA (l); + MOVA (l); emitcode ("push", "acc"); } else @@ -2501,11 +2501,11 @@ unsaveRBank (int bank, iCode * ic, bool popPsw) /*-----------------------------------------------------------------*/ static void genSend(set *sendSet) { - iCode *sic; + iCode *sic; int bit_count = 0; /* first we do all bit parameters */ - for (sic = setFirstItem (sendSet); sic; + for (sic = setFirstItem (sendSet); sic; sic = setNextItem (sendSet)) { aopOp (IC_LEFT (sic), sic, FALSE); @@ -2554,19 +2554,19 @@ static void genSend(set *sendSet) for (sic = setFirstItem (sendSet); sic; sic = setNextItem (sendSet)) { - int size, offset = 0; - aopOp (IC_LEFT (sic), sic, FALSE); - size = AOP_SIZE (IC_LEFT (sic)); + int size, offset = 0; + aopOp (IC_LEFT (sic), sic, FALSE); + size = AOP_SIZE (IC_LEFT (sic)); if (sic->argreg == 1) { while (size--) { char *l = aopGet (IC_LEFT (sic), offset, FALSE, FALSE); - if (strcmp (l, fReturn[offset])) - emitcode ("mov", "%s,%s", fReturn[offset], l); - offset++; - } + if (strcmp (l, fReturn[offset])) + emitcode ("mov", "%s,%s", fReturn[offset], l); + offset++; + } } else if (sic->argreg <= 12) { @@ -2575,9 +2575,9 @@ static void genSend(set *sendSet) emitcode ("mov","%s,%s", rb1regs[sic->argreg+offset-5], aopGet (IC_LEFT (sic), offset,FALSE, FALSE)); offset++; - } - } - freeAsmop (IC_LEFT (sic), NULL, sic, TRUE); + } + } + freeAsmop (IC_LEFT (sic), NULL, sic, TRUE); } } @@ -2636,19 +2636,19 @@ genCall (iCode * ic) if (currFunc && dtype && !IFFUNC_ISNAKED(dtype) && (FUNC_REGBANK (currFunc->type) != FUNC_REGBANK (dtype)) && !IFFUNC_ISISR (dtype)) - { + { swapBanks = TRUE; - } + } /* if caller saves & we have not saved then */ if (!ic->regsSaved) saveRegisters (ic); if (swapBanks) - { + { emitcode ("mov", "psw,#0x%02x", ((FUNC_REGBANK(dtype)) << 3) & 0xff); - } + } /* make the call */ if (IFFUNC_ISBANKEDCALL (dtype) && !SPEC_STAT(getSpec(dtype))) @@ -2791,7 +2791,7 @@ genPcall (iCode * ic) if (currFunc && dtype && !IFFUNC_ISNAKED(dtype) && (FUNC_REGBANK (currFunc->type) != FUNC_REGBANK (dtype)) && !IFFUNC_ISISR (dtype)) - { + { // saveRBank (FUNC_REGBANK (dtype), ic, TRUE); // restoreBank=TRUE; swapBanks = TRUE; @@ -4532,14 +4532,14 @@ genMinus (iCode * ic) if (!offset && !size && lit== (unsigned long) -1) { emitcode ("dec", "a"); } else if (!useCarry) { - /* first add without previous c */ + /* first add without previous c */ emitcode ("add", "a,#0x%02x", (unsigned int) ((lit >> (offset * 8)) & 0x0FFL)); useCarry = TRUE; - } else { - emitcode ("addc", "a,#0x%02x", - (unsigned int) ((lit >> (offset * 8)) & 0x0FFL)); - } + } else { + emitcode ("addc", "a,#0x%02x", + (unsigned int) ((lit >> (offset * 8)) & 0x0FFL)); + } aopPut (IC_RESULT (ic), "a", offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); } else { /* no need to add zeroes */ @@ -5637,7 +5637,7 @@ genCmpLt (iCode * ic, iCode * ifx) aopOp (right, ic, FALSE); aopOp (result, ic, TRUE); - genCmp (left, right, result, ifx, sign,ic); + genCmp (left, right, result, ifx, sign, ic); freeAsmop (result, NULL, ic, TRUE); } @@ -6421,12 +6421,12 @@ genAnd (iCode * ic, iCode * ifx) MOVA (aopGet (right, offset, FALSE, FALSE)); emitcode("anl", "a,b"); } - } else { + } else { MOVA (aopGet (right, offset, FALSE, FALSE)); - emitcode ("anl", "a,%s", + emitcode ("anl", "a,%s", aopGet (left, offset, FALSE, FALSE)); + } } - } emitcode ("jnz", "%05d$", tlbl->key + 100); offset++; } @@ -7127,7 +7127,7 @@ genInline (iCode * ic) else { /* Add \n for labels, not dirs such as c:\mydir */ - if ( (*bp == ':') && (isspace(bp[1])) ) + if ( (*bp == ':') && (isspace((unsigned char)bp[1])) ) { bp++; *bp = '\0'; @@ -10699,8 +10699,8 @@ genDjnz (iCode * ic, iCode * ifx) static void genReceive (iCode * ic) { - int size = getSize (operandType (IC_RESULT (ic))); - int offset = 0; + int size = getSize (operandType (IC_RESULT (ic))); + int offset = 0; D(emitcode ("; genReceive","")); diff --git a/src/mcs51/main.c b/src/mcs51/main.c index e3788b23..402993d8 100644 --- a/src/mcs51/main.c +++ b/src/mcs51/main.c @@ -52,7 +52,7 @@ static char *_mcs51_keywords[] = void mcs51_assignRegisters (ebbIndex *); -static int regParmFlg = 0; /* determine if we can register a parameter */ +static int regParmFlg = 0; /* determine if we can register a parameter */ static int regBitParmFlg = 0; /* determine if we can register a bit parameter */ static void @@ -574,7 +574,7 @@ asmLineNodeFromLineNode (lineNode *ln) asmLineNode *aln = newAsmLineNode(); char *op, op1[256], op2[256]; int opsize; - const char *p; + const unsigned char *p; char inst[8]; mcs51opcodedata *opdat; @@ -721,33 +721,33 @@ PORT mcs51_port = }, { "XSTK (PAG,XDATA)", // xstack_name - "STACK (DATA)", // istack_name - "CSEG (CODE)", // code_name - "DSEG (DATA)", // data_name - "ISEG (DATA)", // idata_name - "PSEG (PAG,XDATA)", // pdata_name - "XSEG (XDATA)", // xdata_name - "BSEG (BIT)", // bit_name - "RSEG (DATA)", // reg_name - "GSINIT (CODE)", // static_name - "OSEG (OVR,DATA)", // overlay_name - "GSFINAL (CODE)", // post_static_name - "HOME (CODE)", // home_name - "XISEG (XDATA)", // xidata_name - initialized xdata initialized xdata - "XINIT (CODE)", // xinit_name - a code copy of xiseg - "CONST (CODE)", // const_name - const data (code or not) + "STACK (DATA)", // istack_name + "CSEG (CODE)", // code_name + "DSEG (DATA)", // data_name + "ISEG (DATA)", // idata_name + "PSEG (PAG,XDATA)", // pdata_name + "XSEG (XDATA)", // xdata_name + "BSEG (BIT)", // bit_name + "RSEG (DATA)", // reg_name + "GSINIT (CODE)", // static_name + "OSEG (OVR,DATA)", // overlay_name + "GSFINAL (CODE)", // post_static_name + "HOME (CODE)", // home_name + "XISEG (XDATA)", // xidata_name - initialized xdata initialized xdata + "XINIT (CODE)", // xinit_name - a code copy of xiseg + "CONST (CODE)", // const_name - const data (code or not) NULL, NULL, 1 }, { _mcs51_genExtraAreas, NULL }, { - +1, /* direction (+1 = stack grows up) */ - 0, /* bank_overhead (switch between register banks) */ - 4, /* isr_overhead */ - 1, /* call_overhead (2 for return address - 1 for pre-incrementing push */ - 1, /* reent_overhead */ - 0 /* banked_overhead (switch between code banks) */ + +1, /* direction (+1 = stack grows up) */ + 0, /* bank_overhead (switch between register banks) */ + 4, /* isr_overhead */ + 1, /* call_overhead (2 for return address - 1 for pre-incrementing push */ + 1, /* reent_overhead */ + 0 /* banked_overhead (switch between code banks) */ }, { /* mcs51 has an 8 bit mul */ diff --git a/src/pic/gen.c b/src/pic/gen.c index 621357fa..ac092203 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -174,7 +174,7 @@ void DEBUGpic14_emitcode (char *inst,char *fmt, ...) { va_list ap; char lb[INITIAL_INLINEASM]; - char *lbp = lb; + unsigned char *lbp = lb; if(!debug_verbose && !options.debug) return; @@ -272,7 +272,7 @@ void pic14_emitcode (char *inst,char *fmt, ...) { va_list ap; char lb[INITIAL_INLINEASM]; - char *lbp = lb; + unsigned char *lbp = lb; va_start(ap,fmt); diff --git a/src/pic/pcode.c b/src/pic/pcode.c index 91886caa..5128c5ad 100644 --- a/src/pic/pcode.c +++ b/src/pic/pcode.c @@ -1397,7 +1397,7 @@ void pCodeInitRegisters(void) /* */ /*-----------------------------------------------------------------*/ -int mnem2key(char const *mnem) +int mnem2key(unsigned char const *mnem) { int key = 0; @@ -2067,7 +2067,7 @@ pCode *newpCodeAsmDir(char *asdir, char *argfmt, ...) if(asdir && *asdir) { - while(isspace(*asdir))asdir++; // strip any white space from the beginning + while(isspace((unsigned char)*asdir))asdir++; // strip any white space from the beginning pcad->directive = Safe_strdup( asdir ); } @@ -2080,7 +2080,7 @@ pCode *newpCodeAsmDir(char *asdir, char *argfmt, ...) va_end(ap); - while(isspace(*lbp))lbp++; + while(isspace((unsigned char)*lbp))lbp++; if(lbp && *lbp) pcad->arg = Safe_strdup( lbp ); diff --git a/src/pic/pcodepeep.c b/src/pic/pcodepeep.c index f9ca9d3f..6c6c4720 100644 --- a/src/pic/pcodepeep.c +++ b/src/pic/pcodepeep.c @@ -259,7 +259,7 @@ static int cvt_extract_destination(parsedPattern *pp) // just check first letter for now - if(toupper(*pp->pct[0].tok.s) == 'F') + if(toupper((unsigned char)*pp->pct[0].tok.s) == 'F') return 1; } else if (pp->pct[0].tt == PCT_NUMBER) { @@ -290,14 +290,14 @@ static pCodeOp *cvt_extract_status(char *reg, char *bit) if(len == 1) { // check C,Z - if(toupper(*bit) == 'C') + if(toupper((unsigned char)*bit) == 'C') return PCOP(popCopyGPR2Bit(&pc_status,PIC_C_BIT)); - if(toupper(*bit) == 'Z') + if(toupper((unsigned char)*bit) == 'Z') return PCOP(popCopyGPR2Bit(&pc_status,PIC_Z_BIT)); } // Check DC - if(len ==2 && toupper(bit[0]) == 'D' && toupper(bit[1]) == 'C') + if(len ==2 && toupper((unsigned char)bit[0]) == 'D' && toupper((unsigned char)bit[1]) == 'C') return PCOP(popCopyGPR2Bit(&pc_status,PIC_DC_BIT)); return NULL; @@ -745,15 +745,15 @@ static void tokenizeLineNode(char *ln) while(*ln) { - if(isspace(*ln)) { + if(isspace((unsigned char)*ln)) { // add a SPACE token and eat the extra spaces. tokArr[tokIdx++].tt = PCT_SPACE; - while (isspace (*ln)) + while (isspace ((unsigned char)*ln)) ln++; continue; } - if(isdigit(*ln)) { + if(isdigit((unsigned char)*ln)) { tokArr[tokIdx].tt = PCT_NUMBER; tokArr[tokIdx++].tok.n = strtol(ln, &ln, 0); @@ -786,11 +786,11 @@ static void tokenizeLineNode(char *ln) default: - if(isalpha(*ln) || (*ln == '_') ) { + if(isalpha((unsigned char)*ln) || (*ln == '_') ) { char buffer[50]; int i=0; - while( (isalpha(*ln) || isdigit(*ln) || (*ln == '_')) && i<49) + while( (isalpha((unsigned char)*ln) || isdigit((unsigned char)*ln) || (*ln == '_')) && i<49) buffer[i++] = *ln++; ln--; diff --git a/src/pic/ralloc.c b/src/pic/ralloc.c index a6e5aef7..50c224ad 100644 --- a/src/pic/ralloc.c +++ b/src/pic/ralloc.c @@ -134,7 +134,7 @@ static void fprintf (debugF, "%s", buffer); /* - while (isspace(*bufferP)) bufferP++; + while (isspace((unsigned char)*bufferP)) bufferP++; if (bufferP && *bufferP) lineCurr = (lineCurr ? diff --git a/src/pic16/gen.c b/src/pic16/gen.c index 2139f358..9ca5da16 100644 --- a/src/pic16/gen.c +++ b/src/pic16/gen.c @@ -234,7 +234,7 @@ void pic16_emitpcomment (char *fmt, ...) { va_list ap; char lb[INITIAL_INLINEASM]; - char *lbp = lb; + unsigned char *lbp = lb; va_start(ap,fmt); @@ -260,7 +260,7 @@ void DEBUGpic16_emitcode (char *inst,char *fmt, ...) { va_list ap; char lb[INITIAL_INLINEASM]; - char *lbp = lb; + unsigned char *lbp = lb; if(!pic16_debug_verbose) return; @@ -340,7 +340,7 @@ void pic16_emitcode (char *inst,char *fmt, ...) { va_list ap; char lb[INITIAL_INLINEASM]; - char *lbp = lb; + unsigned char *lbp = lb; va_start(ap,fmt); diff --git a/src/pic16/pcode.c b/src/pic16/pcode.c index 11e825c4..24f36331 100644 --- a/src/pic16/pcode.c +++ b/src/pic16/pcode.c @@ -3113,7 +3113,7 @@ void pic16_pCodeInitRegisters(void) /* */ /*-----------------------------------------------------------------*/ -int mnem2key(char const *mnem) +int mnem2key(unsigned char const *mnem) { int key = 0; @@ -3856,7 +3856,7 @@ pCode *pic16_newpCodeAsmDir(char *asdir, char *argfmt, ...) if(asdir && *asdir) { - while(isspace(*asdir))asdir++; // strip any white space from the beginning + while(isspace((unsigned char)*asdir))asdir++; // strip any white space from the beginning pcad->directive = Safe_strdup( asdir ); } @@ -3869,7 +3869,7 @@ pCode *pic16_newpCodeAsmDir(char *asdir, char *argfmt, ...) va_end(ap); - while(isspace(*lbp))lbp++; + while(isspace((unsigned char)*lbp))lbp++; if(lbp && *lbp) pcad->arg = Safe_strdup( lbp ); diff --git a/src/pic16/pcodepeep.c b/src/pic16/pcodepeep.c index 07fbf87e..fd009a33 100644 --- a/src/pic16/pcodepeep.c +++ b/src/pic16/pcodepeep.c @@ -276,7 +276,7 @@ static int cvt_extract_destination(parsedPattern *pp) // just check first letter for now - if(toupper(*pp->pct[0].tok.s) == 'F') + if(toupper((unsigned char)*pp->pct[0].tok.s) == 'F') return 1; } else if (pp->pct[0].tt == PCT_NUMBER) { @@ -307,14 +307,14 @@ static pCodeOp *cvt_extract_status(char *reg, char *bit) if(len == 1) { // check C,Z - if(toupper(*bit) == 'C') + if(toupper((unsigned char)*bit) == 'C') return PCOP(pic16_popCopyGPR2Bit(&pic16_pc_status,PIC_C_BIT)); - if(toupper(*bit) == 'Z') + if(toupper((unsigned char)*bit) == 'Z') return PCOP(pic16_popCopyGPR2Bit(&pic16_pc_status,PIC_Z_BIT)); } // Check DC - if(len ==2 && toupper(bit[0]) == 'D' && toupper(bit[1]) == 'C') + if(len ==2 && toupper((unsigned char)bit[0]) == 'D' && toupper((unsigned char)bit[1]) == 'C') return PCOP(pic16_popCopyGPR2Bit(&pic16_pc_status,PIC_DC_BIT)); return NULL; @@ -962,15 +962,15 @@ static void tokenizeLineNode(char *ln) // fprintf(stderr, "%s:%d: processing %s\n", __FILE__, __LINE__, ln); while(*ln) { - if(isspace(*ln)) { + if(isspace((unsigned char)*ln)) { // add a SPACE token and eat the extra spaces. tokArr[tokIdx++].tt = PCT_SPACE; - while (isspace (*ln)) + while (isspace ((unsigned char)*ln)) ln++; continue; } - if(isdigit(*ln)) { + if(isdigit((unsigned char)*ln)) { tokArr[tokIdx].tt = PCT_NUMBER; tokArr[tokIdx++].tok.n = strtol(ln, &ln, 0); @@ -1003,11 +1003,11 @@ static void tokenizeLineNode(char *ln) default: // hack to allow : goto $ - if(isalpha(*ln) || (*ln == '_') || (!parsing_peeps && (*ln == '$'))) { + if(isalpha((unsigned char)*ln) || (*ln == '_') || (!parsing_peeps && (*ln == '$'))) { char buffer[50]; int i=0; - while( (isalpha(*ln) || isdigit(*ln) || (*ln == '_') || (*ln == '$')) && i<49) + while( (isalpha((unsigned char)*ln) || isdigit((unsigned char)*ln) || (*ln == '_') || (*ln == '$')) && i<49) buffer[i++] = *ln++; ln--; diff --git a/src/pic16/ralloc.c b/src/pic16/ralloc.c index 476626a6..5fa12896 100644 --- a/src/pic16/ralloc.c +++ b/src/pic16/ralloc.c @@ -154,7 +154,7 @@ debugLog (char *fmt,...) fprintf (debugF, "%s", buffer); /* - while (isspace(*bufferP)) bufferP++; + while (isspace((unsigned char)*bufferP)) bufferP++; if (bufferP && *bufferP) lineCurr = (lineCurr ? diff --git a/src/xa51/gen.c b/src/xa51/gen.c index 2eace679..ecd1867c 100755 --- a/src/xa51/gen.c +++ b/src/xa51/gen.c @@ -97,7 +97,7 @@ void bailOut (char *mesg) { static void emitcode (char *inst, char *fmt,...) { va_list ap; char lb[INITIAL_INLINEASM]; - char *lbp = lb; + unsigned char *lbp = lb; va_start (ap, fmt); @@ -112,7 +112,7 @@ static void emitcode (char *inst, char *fmt,...) { else vsprintf (lb, fmt, ap); - while (isspace ((int)*lbp)) + while (isspace (*lbp)) lbp++; if (lbp && *lbp) diff --git a/src/z80/gen.c b/src/z80/gen.c index 88324bab..72d57266 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -463,7 +463,7 @@ _emit2 (const char *inst, const char *fmt,...) { va_list ap; char lb[INITIAL_INLINEASM]; - char *lbp = lb; + unsigned char *lbp = lb; va_start (ap, fmt); @@ -2914,7 +2914,7 @@ emitCall (iCode * ic, bool ispcall) } spillCached (); - /* Mark the regsiters as restored. */ + /* Mark the registers as restored. */ _G.saves.saved = FALSE; /* if we need assign a result value */ diff --git a/src/z80/main.c b/src/z80/main.c index 248e31b5..3de32035 100644 --- a/src/z80/main.c +++ b/src/z80/main.c @@ -151,7 +151,7 @@ _process_pragma (const char *sz) strncpy (buffer, sz + 5, sizeof (buffer)); buffer[sizeof (buffer) - 1 ] = '\0'; chomp (buffer); - if (isdigit (buffer[0])) + if (isdigit ((unsigned char)buffer[0])) { } @@ -159,7 +159,7 @@ _process_pragma (const char *sz) { strcpy (buffer, "HOME"); } - if (isdigit (buffer[0])) + if (isdigit ((unsigned char)buffer[0])) { /* Arg was a bank number. Handle in an ASM independent way. */ diff --git a/support/Util/MySystem.c b/support/Util/MySystem.c index b78d99aa..004a2f7c 100644 --- a/support/Util/MySystem.c +++ b/support/Util/MySystem.c @@ -45,9 +45,9 @@ set *binPathSet = NULL; /* set of binary paths */ */ static void -split_command(const char *cmd_line, char **command, char **params) +split_command(const unsigned char *cmd_line, char **command, char **params) { - const char *p, *cmd_start; + const unsigned char *p, *cmd_start; char delim; char *str; unsigned len; -- 2.30.2