+2005-09-08 Maarten Brock <sourceforge.brock AT dse.nl>
+
+ * 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 <rneider AT web.de>
* src/pic16/ralloc.c (pic16_allocDirReg): use device specific
OutputByte((unsigned char)(value/0x100));
}
-void OutputName(char * name)
+void OutputName(unsigned char * name)
{
int k;
OutputByte((unsigned char)strlen(name));
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)
OutputByte((unsigned char)(value/0x100));
}
-void OutputName(char * name)
+void OutputName(unsigned char * name)
{
int k;
OutputByte((unsigned char)strlen(name));
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)
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)
{
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"))
{
fprintf(stderr, ErrMsg, taxp->a_size, taxp->a_size>1?"s":"", tap->a_id);
lkerr++;
}
- }
+ }
for(j=0; j<ramlimit; j++)
{
_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);
/* 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;
}
_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);
#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;
/* 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))
{
#if HAVE_ASSERT_H
# include <assert.h>
#else
-# define assert(arg) ((void) 0)
+# define assert(arg) ((void) 0)
#endif
#include "ltdl.h"
#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
/* 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
/* 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
\f
/* --- REPLACEMENT FUNCTIONS --- */
{
tmp = LT_DLMALLOC (char, 1+ strlen (str));
if (tmp)
- {
- strcpy(tmp, str);
- }
+ {
+ strcpy(tmp, str);
+ }
}
return tmp;
for (;*str1 && *str2; ++str1, ++str2)
{
if (*str1 != *str2)
- break;
+ break;
}
return (int)(*str1 - *str2);
for (p = str; *p != LT_EOS_CHAR; ++p)
{
if (*p == (char) ch)
- {
- q = p;
- }
+ {
+ q = p;
+ }
}
return q;
/* 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
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;
{
/* For zero or less bytes, free the original memory */
if (ptr != 0)
- {
- lt_dlfree (ptr);
- }
+ {
+ lt_dlfree (ptr);
+ }
return (lt_ptr) 0;
}
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;
}
}
# 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)
# 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)
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;
}
# 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)
/* 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. */
--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;
# 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)
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 */
# 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)
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 */
/* 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;
static const char *lt_dlerror_strings[] =
{
-#define LT_ERROR(name, diagnostic) (diagnostic),
+#define LT_ERROR(name, diagnostic) (diagnostic),
lt_dlerror_table
#undef LT_ERROR
/* 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
#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
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
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 ();
/* --- 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);
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 ();
lt_dlseterror (errindex)
int errindex;
{
- int errors = 0;
+ int errors = 0;
LT_DLMUTEX_LOCK ();
#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
* 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)
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;
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;
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)
{
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;
while (cur)
{
if (!cur->module)
- {
- cur = 0;
- break;
- }
+ {
+ cur = 0;
+ break;
+ }
if (cur->module == module)
- {
- break;
- }
+ {
+ break;
+ }
cur = cur->next;
}
lt_user_data loader_data;
lt_module module;
{
- int errors = 0;
+ int errors = 0;
if (FreeLibrary(module) == 0)
{
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)
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)
lists = preloaded_symbols;
while (lists)
{
- lt_dlsymlists_t *tmp = lists;
+ lt_dlsymlists_t *tmp = lists;
lists = lists->next;
LT_DLFREE (tmp);
{
lt_dlsymlists_t *tmp;
lt_dlsymlists_t *lists;
- int errors = 0;
+ int errors = 0;
LT_DLMUTEX_LOCK ();
while (lists)
{
if (lists->syms == preloaded)
- {
- goto done;
- }
+ {
+ goto done;
+ }
lists = lists->next;
}
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;
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;
}
while (syms->address)
{
if (strcmp(syms->name, symbol) == 0)
- {
- return syms->address;
- }
+ {
+ return syms->address;
+ }
++syms;
}
/* 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 ();
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 ();
LT_DLMUTEX_LOCK ();
if (default_preloaded_symbols)
- {
- errors = lt_dlpreload (default_preloaded_symbols);
- }
+ {
+ errors = lt_dlpreload (default_preloaded_symbols);
+ }
LT_DLMUTEX_UNLOCK ();
}
{
/* shut down libltdl */
lt_dlloader *loader;
- int errors = 0;
+ int errors = 0;
LT_DLMUTEX_LOCK ();
loader = loaders;
/* 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;
}
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 */
{
/* 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;
}
{
cur->info.filename = lt_estrdup (filename);
if (!cur->info.filename)
- {
- ++errors;
- goto done;
- }
+ {
+ ++errors;
+ goto done;
+ }
}
else
{
cur->module = loader->module_open (data, filename);
if (cur->module != 0)
- {
- break;
- }
+ {
+ break;
+ }
loader = loader->next;
}
goto done;
}
- cur->loader = loader;
+ cur->loader = loader;
LT_DLMUTEX_SETERROR (saved_error);
done:
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);
if (prefix)
{
error += tryall_dlopen_module (handle,
- (const char *) 0, prefix, filename);
+ (const char *) 0, prefix, filename);
}
else if (tryall_dlopen (handle, filename) != 0)
{
{
/* 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;
}
}
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. */
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;
}
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 ();
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;
+ }
}
}
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);
char *dirend = strrchr (filename, '/');
if (dirend > filename)
- *dirend = LT_EOS_CHAR;
+ *dirend = LT_EOS_CHAR;
LT_DLFREE (*pdir);
*pdir = lt_estrdup (filename);
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)
return 0;
if (!foreach_dirinpath (search_path, base_name, find_handle_callback,
- handle, 0))
+ handle, 0))
return 0;
return handle;
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;
{
save_search_path = lt_estrdup (user_search_path);
if (!save_search_path)
- goto cleanup;
+ goto cleanup;
}
/* extract search paths and count 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 */
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)
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:
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;
/* 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);
{
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;
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);
{
*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;
}
dir = LT_EMALLOC (char, 1+ dirlen);
if (!dir)
- {
- ++errors;
- goto cleanup;
- }
+ {
+ ++errors;
+ goto cleanup;
+ }
strncpy (dir, canonical, dirlen);
dir[dirlen] = LT_EOS_CHAR;
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;
}
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);
/* 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:
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 ();
}
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)
{
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
))
{
LT_DLFREE (tmp);
tmp = LT_EMALLOC (char, len + LT_STRLEN (shlib_ext) + 1);
if (!tmp)
- return 0;
+ return 0;
strcpy (tmp, filename);
}
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;
}
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);
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);
char *p;
for (p = end; p -1 > dp->d_name; --p)
if (strchr (".0123456789", p[-1]) == 0)
- break;
+ break;
if (*p == '.')
end = p;
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;
char **pargz;
size_t *pargz_len;
{
- DIR *dirp = 0;
- int errors = 0;
+ DIR *dirp = 0;
+ int errors = 0;
assert (dirnam && *dirnam);
assert (pargz);
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);
}
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;
char *filename = 0;
while ((filename = argz_next (argz, argz_len, filename)))
if ((is_done = (*func) (filename, data2)))
- break;
+ break;
}
cleanup:
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
}
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);
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;
}
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)
{
{
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;
/* 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);
/* 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);
}
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);
/* 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;
}
{
LT_DLMUTEX_LOCK ();
if (lt_dlpath_insertdir (&user_search_path, 0, search_dir) != 0)
- ++errors;
+ ++errors;
LT_DLMUTEX_UNLOCK ();
}
{
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 ();
}
{
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 ();
}
lt_dlsetsearchpath (search_path)
const char *search_path;
{
- int errors = 0;
+ int errors = 0;
LT_DLMUTEX_LOCK ();
LT_DLFREE (user_search_path);
}
int
-lt_dlisresident (handle)
+lt_dlisresident (handle)
lt_dlhandle handle;
{
if (!handle)
cur = cur->next;
if ((*func) (tmp, data))
- {
- ++errors;
- break;
- }
+ {
+ ++errors;
+ break;
+ }
}
LT_DLMUTEX_UNLOCK ();
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
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;
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;
+ }
}
}
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))
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)
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;
}
{
/* 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 ();
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)
/* 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;
for (place = loaders; place; place = place->next)
{
if (strcmp (place->loader_name, loader_name) == 0)
- {
- break;
- }
+ {
+ break;
+ }
}
LT_DLMUTEX_UNLOCK ();
/* 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;
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 */
--len;
for (p = dest, i = 0; *src != '\0' && i < len; ++src, ++i) {
- *p++ = isspace(*src) ? '_' : *src;
+ *p++ = isspace((unsigned char)*src) ? '_' : *src;
}
*p = '\0';
{
/* 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);
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)
{
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, ","))
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;
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 */
moduleName = Safe_strdup ( fext );
for (fext = moduleName; *fext; fext++)
- if (!isalnum (*fext))
+ if (!isalnum ((unsigned char)*fext))
*fext = '_';
return;
}
/*-------------------------------------------------------------------------
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)
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 <math.h>
#include "common.h"
/*-----------------------------------------------------------------*/
/*-----------------------------------------------------------------*/
/* printSymName - prints the symbol names */
/*-----------------------------------------------------------------*/
-int
+int
printSymName (void *vsym)
{
symbol *sym = vsym;
/*-----------------------------------------------------------------*/
/* cnvToFcall - does the actual conversion to function call */
/*-----------------------------------------------------------------*/
-static void
+static void
cnvToFcall (iCode * ic, eBBlock * ebp)
{
iCode *ip;
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);
/* 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;
/* 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;
}
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);
/*-----------------------------------------------------------------*/
/* cnvToFloatCast - converts casts to floats to function calls */
/*-----------------------------------------------------------------*/
-static void
+static void
cnvToFloatCast (iCode * ic, eBBlock * ebp)
{
iCode *ip, *newic;
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) {
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;
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;
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;
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;
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);
/*-----------------------------------------------------------------*/
/* cnvFromFloatCast - converts casts From floats to function calls */
/*-----------------------------------------------------------------*/
-static void
+static void
cnvFromFloatCast (iCode * ic, eBBlock * ebp)
{
iCode *ip, *newic;
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:
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;
{
/* 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;
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);
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)
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;
{
/* 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;
/*-----------------------------------------------------------------*/
/* 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;
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:
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;
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;
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;
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);
/*-----------------------------------------------------------------*/
/* convertToFcall - converts some operations to fcalls */
/*-----------------------------------------------------------------*/
-static void
+static void
convertToFcall (eBBlock ** ebbs, int count)
{
int i;
/* 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.
}
}
- /* 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));
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);
}
}
- }
+ }
}
}
{
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;
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;
+ }
+ }
}
}
{
int i;
iCode * ic;
-
+
/* for all blocks do */
for (i=0; i<count; i++)
{
/* for all instructions in the block do */
for (ic = ebbs[i]->sch; 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;
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;
}
/*-----------------------------------------------------------------*/
/* printCyclomatic - prints the cyclomatic information */
/*-----------------------------------------------------------------*/
-static void
+static void
printCyclomatic (eBBlock ** ebbs, int count)
{
int nEdges = elementsInSet (graphEdges);
/* discardDeadParamReceives - remove any RECEIVE opcodes which */
/* refer to dead variables. */
/*-----------------------------------------------------------------*/
-static void
+static void
discardDeadParamReceives (eBBlock ** ebbs, int count)
{
int i;
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;
+ }
+ }
+ }
}
}
/* 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;
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);
+ }
+ }
}
}
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);
/* 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);
dumpEbbsToFileExt (DUMP_RAW1, ebbi);
optimizeCastCast (ebbi->bbOrder, ebbi->count);
-
+
/* do common subexpression elimination for each block */
change = cseAllBlocks (ebbi, FALSE);
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
// 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);
+ }
+ }
}
}
}
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);
/* throw away blocks */
setToNull ((void *) &graphEdges);
-
+
return NULL;
}
#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;
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 *);
/* pcDistance - afinds a label back ward or forward */
/*-----------------------------------------------------------------*/
-int
+int
pcDistance (lineNode * cpos, char *lbl, bool back)
{
lineNode *pl = cpos;
{
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));
}
/*-----------------------------------------------------------------*/
/* 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 &&
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)
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<count; i++)
{
lbl = hTabItemWithKey (vars, 5+i);
if (!lbl)
return FALSE;
-
+
dist = pcDistance (currPl, lbl, FALSE);
/* three terms used to calculate allowable distance */
// printf("\nlabel %s %i dist %i cdist 0x%02x 0x%02x\n", lbl, i, dist, dist -(count-i-1)-(7+3*i), 127+(count-i-1)+(7+3*i) - dist);
if (!dist ||
dist > 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 */
)
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;
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";
/* 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 :) */
}
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;
}
else
{
fprintf (stderr, "*** internal error: var %d not bound"
- " in peephole %s rule.\n",
+ " in peephole %s rule.\n",
varNumber, __FUNCTION__);
}
}
/* 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';
}
}
}
-
+
/* Couldn't find the symbol for some reason. Assume volatile. */
return FALSE;
}
}
/* 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);
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"
if (!cmdLine)
return NULL;
-
- while (*cmdLine && isspace(*cmdLine))
+
+ while (*cmdLine && ISCHARSPACE(*cmdLine))
cmdLine++;
while (*cmdLine)
if (*cmdLine == '%')
{
cmdLine++;
- if (!isdigit(*cmdLine))
+ if (!ISCHARDIGIT(*cmdLine))
goto error;
varNumber = strtol(cmdLine, &digitend, 10);
cmdLine = digitend;
else if (*cmdLine == '\'' )
{
char quote = *cmdLine;
-
+
var = ++cmdLine;
while (*cmdLine && *cmdLine != quote)
cmdLine++;
}
else
goto error;
-
- while (*cmdLine && isspace(*cmdLine))
+
+ while (*cmdLine && ISCHARSPACE(*cmdLine))
cmdLine++;
}
{
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;
}
{
set *operands;
const char *op1, *op2;
-
+
operands = setFromConditionArgs (cmdLine, vars);
if (!operands)
"*** 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);
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
{
{
"operandsNotSame8", operandsNotSame8
}
- ,
+ ,
{
"24bitMode", flat24bitMode
}
"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;
*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 */
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;
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;
}
/*-----------------------------------------------------------------*/
peepRule *
newPeepRule (lineNode * match,
- lineNode * replace,
- char *cond,
- int restart)
+ lineNode * replace,
+ char *cond,
+ int restart)
{
peepRule *pr;
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++ ; \
/*-----------------------------------------------------------------*/
/* getPeepLine - parses the peep lines */
/*-----------------------------------------------------------------*/
-static void
+static void
getPeepLine (lineNode ** head, char **bpp)
{
char lines[MAX_PATTERN_LEN];
{
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;
+ }
}
/*-----------------------------------------------------------------*/
/* readRules - reads the rules from a string buffer */
/*-----------------------------------------------------------------*/
-static void
+static void
readRules (char *bp)
{
char restart = 0;
/* then look for either "restart" or '{' */
while (strncmp (bp, "restart", 7) &&
- *bp != '{' && bp)
+ *bp != '{' && bp)
bp++;
/* not found */
if (*bp == '{')
bp++;
else
- { /* must be restart */
+ { /* must be restart */
restart++;
bp += strlen ("restart");
/* look for '{' */
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);
/*-----------------------------------------------------------------*/
/* 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');
/*-----------------------------------------------------------------*/
/* 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];
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';
/*-----------------------------------------------------------------*/
/* matchLine - matches one line */
/*-----------------------------------------------------------------*/
-static bool
+static bool
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
/*-----------------------------------------------------------------*/
/* 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); */
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 */
{
/* 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;
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;
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;
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
*/
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.
*/
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:
/* 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);
{
const char *labelStart;
int labelLength;
-
+
/* skip over any comments */
while (csl!=stail->next && csl->isComment)
csl = csl->next;
}
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.
}
}
-
+
/*-----------------------------------------------------------------*/
/* replaceRule - does replacement of a matching pattern */
/*-----------------------------------------------------------------*/
-static void
+static void
replaceRule (lineNode ** shead, lineNode * stail, peepRule * pr)
{
lineNode *cl = NULL;
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;
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;
}
{
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;
}
/* 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
{
* 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;
* (alnum | $ | _ ) followed by a colon.
*/
- while (*cp && isspace (*cp))
+ while (*cp && ISCHARSPACE (*cp))
{
cp++;
}
*start = cp;
- while (isalnum (*cp) || (*cp == '$') || (*cp == '_'))
+ while (ISCHARALNUM (*cp) || (*cp == '$') || (*cp == '_'))
{
cp++;
}
}
/* Quick & dirty string hash function. */
-static int
+static int
hashSymbolName (const char *name)
{
int hash = 0;
/* 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;
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;
}
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;
}
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
}
matchLine
Where is stuff allocated?
-
+
*/
/*-----------------------------------------------------------------*/
/* peepHole - matches & substitutes rules */
/*-----------------------------------------------------------------*/
-void
+void
peepHole (lineNode ** pls)
{
lineNode *spl;
** 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)
restart = TRUE;
}
}
-
+
if (pr->vars)
{
hTabDeleteAll (pr->vars);
Safe_free (pr->vars);
pr->vars = NULL;
}
-
+
freeTrace (&_G.values);
}
}
/* 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 */
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;
}
/*-----------------------------------------------------------------*/
/* initPeepHole - initialises the peep hole optimizer stuff */
/*-----------------------------------------------------------------*/
-void
+void
initPeepHole ()
{
char *s;
/* 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
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
/* 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;
while (*fileFullName)
{
if ((*fileFullName == '/') || (*fileFullName == '\\') || (*fileFullName == ':'))
- {
- p = fileFullName;
- p++;
- }
+ {
+ p = fileFullName;
+ p++;
+ }
fileFullName++;
}
return p;
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,
// 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';
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 */
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;
fputs (buffer, fp);
}
-void
+void
tsprintf (char *buffer, size_t len, const char *szFormat,...)
{
va_list ap;
va_end(ap);
}
-void
+void
asm_addTree (const ASM_MAPPINGS * pMappings)
{
const ASM_MAPPING *pMap;
break;
}
}
- while (isspace ((int)*ilsP))
+ while (isspace ((unsigned char)*ilsP))
ilsP++;
return ilsP;
"; ---------------------------------"
},
{"functionlabeldef", "%s:"},
- {"bankimmeds", "0 ; PENDING: bank support"},
+ {"bankimmeds", "0 ; PENDING: bank support"},
{"los","(%s & 0xFF)"},
{"his","(%s >> 8)"},
{"hihis","(%s >> 16)"},
"; ---------------------------------"
},
{"functionlabeldef", "%s:"},
- {"bankimmeds", "0 ; PENDING: bank support"},
+ {"bankimmeds", "0 ; PENDING: bank support"},
{NULL, NULL}
};
"; ---------------------------------"
},
{"functionlabeldef", "%s:"},
- {"bankimmeds", "0 ; PENDING: bank support"},
+ {"bankimmeds", "0 ; PENDING: bank support"},
{"los","(%s & 0FFh)"},
{"his","((%s / 256) & 0FFh)"},
{"hihis","((%s / 65536) & 0FFh)"},
"; ---------------------------------"
},
{"functionlabeldef", "%s:"},
- {"bankimmeds", "0 ; PENDING: bank support"},
+ {"bankimmeds", "0 ; PENDING: bank support"},
{"los","(%s & 0FFh)"},
{"his","((%s / 256) & 0FFh)"},
{"hihis","((%s / 65536) & 0FFh)"},
else
vsprintf (lb, fmt, ap);
- while (isspace (*lbp))
+ while (isspace ((unsigned char)*lbp))
lbp++;
if (lbp && *lbp)
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);
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);
tvsprintf (lb, sizeof(lb), fmt, ap);
}
- while (isspace (*lbp))
+ while (isspace ((unsigned char)*lbp))
{
lbp++;
}
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;
*/
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)))
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 ();
size = AOP_SIZE (op) - 1;
while (size--)
- {
+ {
aopPut (AOP (result),
aopGet (AOP (op), offset, FALSE, FALSE, NULL),
offset);
asmLineNode *aln = ds390newAsmLineNode(currentDPS);
char *op, op1[256], op2[256];
int opsize;
- const char *p;
+ const unsigned char *p;
char inst[8];
ds390opcodedata *opdat;
else
vsprintf (lb, fmt, ap);
- while (isspace (*lbp))
+ while (isspace ((unsigned char)*lbp))
lbp++;
if (lbp && *lbp)
if (*inlin == '_')
{
symname = ++inlin;
- while (isalnum(*inlin) || (*inlin == '_'))
+ while (isalnum((unsigned char)*inlin) || (*inlin == '_'))
inlin++;
c = *inlin;
*inlin = '\0';
#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
{
else
tvsprintf (lb, sizeof(lb), fmt, ap);
- while (isspace (*lbp))
+ while (isspace ((unsigned char)*lbp))
lbp++;
if (lbp && *lbp)
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;
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);
}
}
- }
+ }
}
/*-----------------------------------------------------------------*/
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)
strcmp (l, "a"))
{
if (strcmp (l, prev) || *l == '@')
- MOVA (l);
+ MOVA (l);
emitcode ("push", "acc");
}
else
/*-----------------------------------------------------------------*/
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);
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)
{
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);
}
}
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)))
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;
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 */
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);
}
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++;
}
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';
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",""));
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
asmLineNode *aln = newAsmLineNode();
char *op, op1[256], op2[256];
int opsize;
- const char *p;
+ const unsigned char *p;
char inst[8];
mcs51opcodedata *opdat;
},
{
"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 */
{
va_list ap;
char lb[INITIAL_INLINEASM];
- char *lbp = lb;
+ unsigned char *lbp = lb;
if(!debug_verbose && !options.debug)
return;
{
va_list ap;
char lb[INITIAL_INLINEASM];
- char *lbp = lb;
+ unsigned char *lbp = lb;
va_start(ap,fmt);
/* */
/*-----------------------------------------------------------------*/
-int mnem2key(char const *mnem)
+int mnem2key(unsigned char const *mnem)
{
int key = 0;
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 );
}
va_end(ap);
- while(isspace(*lbp))lbp++;
+ while(isspace((unsigned char)*lbp))lbp++;
if(lbp && *lbp)
pcad->arg = Safe_strdup( lbp );
// 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) {
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;
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);
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--;
fprintf (debugF, "%s", buffer);
/*
- while (isspace(*bufferP)) bufferP++;
+ while (isspace((unsigned char)*bufferP)) bufferP++;
if (bufferP && *bufferP)
lineCurr = (lineCurr ?
{
va_list ap;
char lb[INITIAL_INLINEASM];
- char *lbp = lb;
+ unsigned char *lbp = lb;
va_start(ap,fmt);
{
va_list ap;
char lb[INITIAL_INLINEASM];
- char *lbp = lb;
+ unsigned char *lbp = lb;
if(!pic16_debug_verbose)
return;
{
va_list ap;
char lb[INITIAL_INLINEASM];
- char *lbp = lb;
+ unsigned char *lbp = lb;
va_start(ap,fmt);
/* */
/*-----------------------------------------------------------------*/
-int mnem2key(char const *mnem)
+int mnem2key(unsigned char const *mnem)
{
int key = 0;
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 );
}
va_end(ap);
- while(isspace(*lbp))lbp++;
+ while(isspace((unsigned char)*lbp))lbp++;
if(lbp && *lbp)
pcad->arg = Safe_strdup( lbp );
// 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) {
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;
// 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);
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--;
fprintf (debugF, "%s", buffer);
/*
- while (isspace(*bufferP)) bufferP++;
+ while (isspace((unsigned char)*bufferP)) bufferP++;
if (bufferP && *bufferP)
lineCurr = (lineCurr ?
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);
else
vsprintf (lb, fmt, ap);
- while (isspace ((int)*lbp))
+ while (isspace (*lbp))
lbp++;
if (lbp && *lbp)
{
va_list ap;
char lb[INITIAL_INLINEASM];
- char *lbp = lb;
+ unsigned char *lbp = lb;
va_start (ap, fmt);
}
spillCached ();
- /* Mark the regsiters as restored. */
+ /* Mark the registers as restored. */
_G.saves.saved = FALSE;
/* if we need assign a result value */
strncpy (buffer, sz + 5, sizeof (buffer));
buffer[sizeof (buffer) - 1 ] = '\0';
chomp (buffer);
- if (isdigit (buffer[0]))
+ if (isdigit ((unsigned char)buffer[0]))
{
}
{
strcpy (buffer, "HOME");
}
- if (isdigit (buffer[0]))
+ if (isdigit ((unsigned char)buffer[0]))
{
/* Arg was a bank number. Handle in an ASM independent
way. */
*/
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;