* src/SDCCpeeph.c (peepHole): Fixed all leaks. Added trace support for freeing...
authormichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 6 Oct 2001 23:44:03 +0000 (23:44 +0000)
committermichaelh <michaelh@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 6 Oct 2001 23:44:03 +0000 (23:44 +0000)
* support/Util/NewAlloc.c: Added ability to use libgc instead of malloc.  Added Safe_free and Safe_strdup.  Added trace support where you can log allocations and free all at once.

* src/z80/gen.c (genZ80Code): Added de-allocation via trace support.

* src/pic/gen.c: Removed Safe_strdup.

* configure.in: Added option to enable libgc support.

* src/SDCCbitv.c (bitVectnBitsOn): Optimised.
(bitVectUnion): Optimised.
(bitVectIntersect): Optimised.
(bitVectBitsInCommon): Optimised.
(bitVectCplAnd): Optimised.

* support/makebin/makebin.c (usage): Removed getopt as mingw32 doesn't have it.  Sigh.

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

35 files changed:
ChangeLog
Makefile.common.in
as/z80/Makefile
configure
configure.in
debugger/mcs51/Makefile.in
link/z80/Makefile
sdccconf_in.h
sim/ucsim/configure.in
sim/ucsim/s51.src/Makefile.in
src/SDCC.lex
src/SDCC.y
src/SDCCBBlock.c
src/SDCCast.c
src/SDCCbitv.c
src/SDCCcse.c
src/SDCChasht.c
src/SDCCicode.c
src/SDCCloop.c
src/SDCCmain.c
src/SDCCmem.c
src/SDCCpeeph.c
src/SDCCset.c
src/SDCCsymt.c
src/SDCCutil.c
src/SDCCval.c
src/common.h
src/pic/gen.c
src/pic/pcode.c
src/pic/pcodepeep.c
src/z80/gen.c
support/Util/MySystem.c
support/Util/NewAlloc.c
support/Util/newalloc.h
support/cpp/Makefile.in

index f77ca2e605e22ba16f932fe6ca535407ceab4966..33d4fa9acf8f8044f119b083e1a43a20e1952a32 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2001-10-06  Michael Hope  <michaelh@juju.net.nz>
+
+       * src/SDCCpeeph.c (peepHole): Fixed all leaks.  Added trace support for freeing lines.  Optimised restart logic to re-run instead of restart.  Now compiles dscan.c on ~60MB instead of ~200MB.
+
+       * support/Util/NewAlloc.c: Added ability to use libgc instead of malloc.  Added Safe_free and Safe_strdup.  Added trace support where you can log allocations and free all at once.
+
+       * src/z80/gen.c (genZ80Code): Added de-allocation via trace support.
+
+       * src/pic/gen.c: Removed Safe_strdup.
+
+       * configure.in: Added option to enable libgc support.
+
+       * src/SDCCbitv.c (bitVectnBitsOn): Optimised.
+       (bitVectUnion): Optimised.
+       (bitVectIntersect): Optimised.
+       (bitVectBitsInCommon): Optimised.
+       (bitVectCplAnd): Optimised.
+
+       * support/makebin/makebin.c (usage): Removed getopt as mingw32 doesn't have it.  Sigh.
+
 2001-10-03 Bernhard Held <bernhard@bernhardheld.de>
 
        * src/SDCCmain.c: distinguish between assembler debug and plain options
        * support/regression/ports/mcs51/spec.mk: removed GENERIC
        * support/regression/ports/z80/spec.mk: removed GENERIC
 
+2001-10-01  Michael Hope  <michaelh@juju.net.nz>
+
+       * support/regression/fwk/lib/testfwk.c (__printf): Removed GENERIC.
+
+       * support/regression/tests/bug-467035.c: Created.
+
 2001-10-01    <johan@FRIJA>
 
        * src/SDCC.y: fixed bug #466586 part 1
index 52fa00254ed85bdf01c320221fbfbe90f6c70889..cd240618d49878259e2aeb5c860726ca6c01a3c4 100644 (file)
@@ -50,6 +50,8 @@ CPPFLAGS        = $(INCLUDEFLAGS) -I. -I$(PRJDIR) -I$(SLIB)
 CFLAGS          = @CFLAGS@ -Wall
 M_OR_MM         = @M_OR_MM@
 
+EXTRALIBS      = @LIBS@
+
 # Shared settings between all the sub Makefiles
 # Done here so that we don't have to start a Make from the top levelport
 # directory.
index b06bac9c6246002e71d142ed6a9703b2ce3d8c9e..9ea2069dd37dc09aeee5d8908d502cb311ae271f 100644 (file)
@@ -16,11 +16,11 @@ SLIBOBJS    = $(SLIBSRC:%.c=$(OBJDIR)/%.o)
 
 BINS   = $(BUILDDIR)as$(EXT)
 
-CFLAGS += $(OPTS) -I. -DINDEXLIB -DMLH_MAP -DUNIX -DSDK
+CFLAGS += $(CPPFLAGS) $(OPTS) -I. -DINDEXLIB -DMLH_MAP -DUNIX -DSDK
 CFLAGS += -funsigned-char
 CFLAGS += -I$(SLIB) 
 
-LDFLAGS += -lm
+LDFLAGS += -lm $(EXTRALIBS)
 
 all:   $(OBJDIR) dep $(BINS)
 
index 32081bc05bc07ca83b0ee33123db9fa5118a9adc..79be8e7c01494e5d0843c4f79eb822cb052d7d48 100755 (executable)
--- a/configure
+++ b/configure
@@ -32,7 +32,9 @@ ac_help="$ac_help
 ac_help="$ac_help
   --disable-device-lib-build Disables automatically building device libraries"
 ac_help="$ac_help
-  -disable-packihx     Disables building packihx"
+  --disable-packihx       Disables building packihx"
+ac_help="$ac_help
+  --enable-libgc          Use the Bohem memory allocator.  Lower runtime footprint."
 
 # Initialize some variables set by options.
 # The variables have the same names as the options, with
@@ -550,7 +552,7 @@ do
 # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:554: checking for $ac_word" >&5
+echo "configure:556: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_AWK'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -581,7 +583,7 @@ done
 
 
 echo $ac_n "checking version of the package""... $ac_c" 1>&6
-echo "configure:585: checking version of the package" >&5
+echo "configure:587: checking version of the package" >&5
 if test -f .version; then
   VERSION=`cat .version`
 elif test -f ../.version; then
@@ -645,7 +647,7 @@ sdcc_cv_versionp=$VERSIONP
 # Extract the first word of "gcc", so it can be a program name with args.
 set dummy gcc; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:649: checking for $ac_word" >&5
+echo "configure:651: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -675,7 +677,7 @@ if test -z "$CC"; then
   # Extract the first word of "cc", so it can be a program name with args.
 set dummy cc; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:679: checking for $ac_word" >&5
+echo "configure:681: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -726,7 +728,7 @@ fi
       # Extract the first word of "cl", so it can be a program name with args.
 set dummy cl; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:730: checking for $ac_word" >&5
+echo "configure:732: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -758,7 +760,7 @@ fi
 fi
 
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:762: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
+echo "configure:764: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5
 
 ac_ext=c
 # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
@@ -769,12 +771,12 @@ cross_compiling=$ac_cv_prog_cc_cross
 
 cat > conftest.$ac_ext << EOF
 
-#line 773 "configure"
+#line 775 "configure"
 #include "confdefs.h"
 
 main(){return(0);}
 EOF
-if { (eval echo configure:778: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:780: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   ac_cv_prog_cc_works=yes
   # If we can't run a trivial program, we are probably using a cross compiler.
   if (./conftest; exit) 2>/dev/null; then
@@ -800,12 +802,12 @@ if test $ac_cv_prog_cc_works = no; then
   { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; }
 fi
 echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
-echo "configure:804: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "configure:806: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5
 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6
 cross_compiling=$ac_cv_prog_cc_cross
 
 echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6
-echo "configure:809: checking whether we are using GNU C" >&5
+echo "configure:811: checking whether we are using GNU C" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -814,7 +816,7 @@ else
   yes;
 #endif
 EOF
-if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:818: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:820: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
   ac_cv_prog_gcc=yes
 else
   ac_cv_prog_gcc=no
@@ -833,7 +835,7 @@ ac_test_CFLAGS="${CFLAGS+set}"
 ac_save_CFLAGS="$CFLAGS"
 CFLAGS=
 echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6
-echo "configure:837: checking whether ${CC-cc} accepts -g" >&5
+echo "configure:839: checking whether ${CC-cc} accepts -g" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -869,7 +871,7 @@ do
 # Extract the first word of "$ac_prog", so it can be a program name with args.
 set dummy $ac_prog; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:873: checking for $ac_word" >&5
+echo "configure:875: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CXX'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -901,7 +903,7 @@ test -n "$CXX" || CXX="gcc"
 
 
 echo $ac_n "checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works""... $ac_c" 1>&6
-echo "configure:905: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works" >&5
+echo "configure:907: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) works" >&5
 
 ac_ext=C
 # CXXFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options.
@@ -912,12 +914,12 @@ cross_compiling=$ac_cv_prog_cxx_cross
 
 cat > conftest.$ac_ext << EOF
 
-#line 916 "configure"
+#line 918 "configure"
 #include "confdefs.h"
 
 int main(){return(0);}
 EOF
-if { (eval echo configure:921: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:923: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   ac_cv_prog_cxx_works=yes
   # If we can't run a trivial program, we are probably using a cross compiler.
   if (./conftest; exit) 2>/dev/null; then
@@ -943,12 +945,12 @@ if test $ac_cv_prog_cxx_works = no; then
   { echo "configure: error: installation or configuration problem: C++ compiler cannot create executables." 1>&2; exit 1; }
 fi
 echo $ac_n "checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6
-echo "configure:947: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler" >&5
+echo "configure:949: checking whether the C++ compiler ($CXX $CXXFLAGS $LDFLAGS) is a cross-compiler" >&5
 echo "$ac_t""$ac_cv_prog_cxx_cross" 1>&6
 cross_compiling=$ac_cv_prog_cxx_cross
 
 echo $ac_n "checking whether we are using GNU C++""... $ac_c" 1>&6
-echo "configure:952: checking whether we are using GNU C++" >&5
+echo "configure:954: checking whether we are using GNU C++" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_gxx'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -957,7 +959,7 @@ else
   yes;
 #endif
 EOF
-if { ac_try='${CXX-g++} -E conftest.C'; { (eval echo configure:961: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
+if { ac_try='${CXX-g++} -E conftest.C'; { (eval echo configure:963: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then
   ac_cv_prog_gxx=yes
 else
   ac_cv_prog_gxx=no
@@ -976,7 +978,7 @@ ac_test_CXXFLAGS="${CXXFLAGS+set}"
 ac_save_CXXFLAGS="$CXXFLAGS"
 CXXFLAGS=
 echo $ac_n "checking whether ${CXX-g++} accepts -g""... $ac_c" 1>&6
-echo "configure:980: checking whether ${CXX-g++} accepts -g" >&5
+echo "configure:982: checking whether ${CXX-g++} accepts -g" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_cxx_g'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1008,7 +1010,7 @@ else
 fi
 
 echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6
-echo "configure:1012: checking how to run the C preprocessor" >&5
+echo "configure:1014: checking how to run the C preprocessor" >&5
 # On Suns, sometimes $CPP names a directory.
 if test -n "$CPP" && test -d "$CPP"; then
   CPP=
@@ -1023,13 +1025,13 @@ else
   # On the NeXT, cc -E runs the code through the compiler's parser,
   # not just through cpp.
   cat > conftest.$ac_ext <<EOF
-#line 1027 "configure"
+#line 1029 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1033: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1035: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   :
@@ -1040,13 +1042,13 @@ else
   rm -rf conftest*
   CPP="${CC-cc} -E -traditional-cpp"
   cat > conftest.$ac_ext <<EOF
-#line 1044 "configure"
+#line 1046 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1050: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1052: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   :
@@ -1057,13 +1059,13 @@ else
   rm -rf conftest*
   CPP="${CC-cc} -nologo -E"
   cat > conftest.$ac_ext <<EOF
-#line 1061 "configure"
+#line 1063 "configure"
 #include "confdefs.h"
 #include <assert.h>
 Syntax Error
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1067: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1069: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   :
@@ -1118,7 +1120,7 @@ ac_configure=$ac_aux_dir/configure # This should be Cygnus configure.
 # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
 # ./install, which can be erroneously created by make from ./install.sh.
 echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6
-echo "configure:1122: checking for a BSD compatible install" >&5
+echo "configure:1124: checking for a BSD compatible install" >&5
 if test -z "$INSTALL"; then
 if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1173,7 +1175,7 @@ test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
 # Extract the first word of "ranlib", so it can be a program name with args.
 set dummy ranlib; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1177: checking for $ac_word" >&5
+echo "configure:1179: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1203,7 +1205,7 @@ fi
 # Extract the first word of "flex", so it can be a program name with args.
 set dummy flex; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1207: checking for $ac_word" >&5
+echo "configure:1209: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_LEX'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1237,7 +1239,7 @@ then
   *) ac_lib=l ;;
   esac
   echo $ac_n "checking for yywrap in -l$ac_lib""... $ac_c" 1>&6
-echo "configure:1241: checking for yywrap in -l$ac_lib" >&5
+echo "configure:1243: checking for yywrap in -l$ac_lib" >&5
 ac_lib_var=`echo $ac_lib'_'yywrap | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1245,7 +1247,7 @@ else
   ac_save_LIBS="$LIBS"
 LIBS="-l$ac_lib  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1249 "configure"
+#line 1251 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1256,7 +1258,7 @@ int main() {
 yywrap()
 ; return 0; }
 EOF
-if { (eval echo configure:1260: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1262: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1281,7 +1283,7 @@ fi
 # Extract the first word of "bison", so it can be a program name with args.
 set dummy bison; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1285: checking for $ac_word" >&5
+echo "configure:1287: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_YACC'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1311,7 +1313,7 @@ fi
 # Extract the first word of "autoconf", so it can be a program name with args.
 set dummy autoconf; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1315: checking for $ac_word" >&5
+echo "configure:1317: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_AUTOCONF'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1341,7 +1343,7 @@ fi
 # Extract the first word of "strip", so it can be a program name with args.
 set dummy strip; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1345: checking for $ac_word" >&5
+echo "configure:1347: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_STRIP'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1371,7 +1373,7 @@ fi
 # Extract the first word of "as", so it can be a program name with args.
 set dummy as; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1375: checking for $ac_word" >&5
+echo "configure:1377: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_AS'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1401,7 +1403,7 @@ fi
 # Extract the first word of "cp", so it can be a program name with args.
 set dummy cp; ac_word=$2
 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6
-echo "configure:1405: checking for $ac_word" >&5
+echo "configure:1407: checking for $ac_word" >&5
 if eval "test \"`echo '$''{'ac_cv_prog_CP'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -1451,12 +1453,12 @@ cross_compiling=$ac_cv_prog_cc_cross
 # Checking for header files.
 # ===========================================================================
 echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6
-echo "configure:1455: checking for ANSI C header files" >&5
+echo "configure:1457: checking for ANSI C header files" >&5
 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1460 "configure"
+#line 1462 "configure"
 #include "confdefs.h"
 #include <stdlib.h>
 #include <stdarg.h>
@@ -1464,7 +1466,7 @@ else
 #include <float.h>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1468: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1470: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1481,7 +1483,7 @@ rm -f conftest*
 if test $ac_cv_header_stdc = yes; then
   # SunOS 4.x string.h does not declare mem*, contrary to ANSI.
 cat > conftest.$ac_ext <<EOF
-#line 1485 "configure"
+#line 1487 "configure"
 #include "confdefs.h"
 #include <string.h>
 EOF
@@ -1499,7 +1501,7 @@ fi
 if test $ac_cv_header_stdc = yes; then
   # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI.
 cat > conftest.$ac_ext <<EOF
-#line 1503 "configure"
+#line 1505 "configure"
 #include "confdefs.h"
 #include <stdlib.h>
 EOF
@@ -1520,7 +1522,7 @@ if test "$cross_compiling" = yes; then
   :
 else
   cat > conftest.$ac_ext <<EOF
-#line 1524 "configure"
+#line 1526 "configure"
 #include "confdefs.h"
 #include <ctype.h>
 #define ISLOWER(c) ('a' <= (c) && (c) <= 'z')
@@ -1531,7 +1533,7 @@ if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2);
 exit (0); }
 
 EOF
-if { (eval echo configure:1535: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
+if { (eval echo configure:1537: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null
 then
   :
 else
@@ -1558,17 +1560,17 @@ for ac_hdr in getopt.h
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1562: checking for $ac_hdr" >&5
+echo "configure:1564: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1567 "configure"
+#line 1569 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1572: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1574: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1598,17 +1600,17 @@ for ac_hdr in unistd.h
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1602: checking for $ac_hdr" >&5
+echo "configure:1604: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1607 "configure"
+#line 1609 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1612: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1614: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1638,17 +1640,57 @@ for ac_hdr in endian.h
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1642: checking for $ac_hdr" >&5
+echo "configure:1644: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1647 "configure"
+#line 1649 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1652: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1654: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
+if test -z "$ac_err"; then
+  rm -rf conftest*
+  eval "ac_cv_header_$ac_safe=yes"
+else
+  echo "$ac_err" >&5
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_header_$ac_safe=no"
+fi
+rm -f conftest*
+fi
+if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+    ac_tr_hdr=HAVE_`echo $ac_hdr | sed 'y%abcdefghijklmnopqrstuvwxyz./-%ABCDEFGHIJKLMNOPQRSTUVWXYZ___%'`
+  cat >> confdefs.h <<EOF
+#define $ac_tr_hdr 1
+EOF
+else
+  echo "$ac_t""no" 1>&6
+fi
+done
+
+for ac_hdr in machine/endian.h
+do
+ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
+echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
+echo "configure:1684: checking for $ac_hdr" >&5
+if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  cat > conftest.$ac_ext <<EOF
+#line 1689 "configure"
+#include "confdefs.h"
+#include <$ac_hdr>
+EOF
+ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
+{ (eval echo configure:1694: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1678,17 +1720,17 @@ for ac_hdr in malloc.h
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1682: checking for $ac_hdr" >&5
+echo "configure:1724: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1687 "configure"
+#line 1729 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1692: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1734: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1718,17 +1760,17 @@ for ac_hdr in sys/isa_defs.h
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1722: checking for $ac_hdr" >&5
+echo "configure:1764: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1727 "configure"
+#line 1769 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1732: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1774: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1758,17 +1800,17 @@ for ac_hdr in sys/socket.h
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6
-echo "configure:1762: checking for $ac_hdr" >&5
+echo "configure:1804: checking for $ac_hdr" >&5
 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1767 "configure"
+#line 1809 "configure"
 #include "confdefs.h"
 #include <$ac_hdr>
 EOF
 ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out"
-{ (eval echo configure:1772: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
+{ (eval echo configure:1814: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }
 ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"`
 if test -z "$ac_err"; then
   rm -rf conftest*
@@ -1799,12 +1841,12 @@ for ac_hdr in dirent.h sys/ndir.h sys/dir.h ndir.h
 do
 ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'`
 echo $ac_n "checking for $ac_hdr that defines DIR""... $ac_c" 1>&6
-echo "configure:1803: checking for $ac_hdr that defines DIR" >&5
+echo "configure:1845: checking for $ac_hdr that defines DIR" >&5
 if eval "test \"`echo '$''{'ac_cv_header_dirent_$ac_safe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 1808 "configure"
+#line 1850 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <$ac_hdr>
@@ -1812,7 +1854,7 @@ int main() {
 DIR *dirp = 0;
 ; return 0; }
 EOF
-if { (eval echo configure:1816: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:1858: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   eval "ac_cv_header_dirent_$ac_safe=yes"
 else
@@ -1837,7 +1879,7 @@ done
 # Two versions of opendir et al. are in -ldir and -lx on SCO Xenix.
 if test $ac_header_dirent = dirent.h; then
 echo $ac_n "checking for opendir in -ldir""... $ac_c" 1>&6
-echo "configure:1841: checking for opendir in -ldir" >&5
+echo "configure:1883: checking for opendir in -ldir" >&5
 ac_lib_var=`echo dir'_'opendir | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1845,7 +1887,7 @@ else
   ac_save_LIBS="$LIBS"
 LIBS="-ldir  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1849 "configure"
+#line 1891 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1856,7 +1898,7 @@ int main() {
 opendir()
 ; return 0; }
 EOF
-if { (eval echo configure:1860: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1902: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1878,7 +1920,7 @@ fi
 
 else
 echo $ac_n "checking for opendir in -lx""... $ac_c" 1>&6
-echo "configure:1882: checking for opendir in -lx" >&5
+echo "configure:1924: checking for opendir in -lx" >&5
 ac_lib_var=`echo x'_'opendir | sed 'y%./+-%__p_%'`
 if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
@@ -1886,7 +1928,7 @@ else
   ac_save_LIBS="$LIBS"
 LIBS="-lx  $LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 1890 "configure"
+#line 1932 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -1897,7 +1939,7 @@ int main() {
 opendir()
 ; return 0; }
 EOF
-if { (eval echo configure:1901: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:1943: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_lib_$ac_lib_var=yes"
 else
@@ -1923,13 +1965,13 @@ fi
 # This must be after CPP
 
 echo $ac_n "checking which header file defines FD_ macros""... $ac_c" 1>&6
-echo "configure:1927: checking which header file defines FD_ macros" >&5
+echo "configure:1969: checking which header file defines FD_ macros" >&5
 if eval "test \"`echo '$''{'s51_cv_fd'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   sdcc_cv_fd="unknown"
 cat > conftest.$ac_ext <<EOF
-#line 1933 "configure"
+#line 1975 "configure"
 #include "confdefs.h"
 
 #include <sys/time.h>
@@ -1945,7 +1987,7 @@ fi
 rm -f conftest*
 
 cat > conftest.$ac_ext <<EOF
-#line 1949 "configure"
+#line 1991 "configure"
 #include "confdefs.h"
 
 #include <sys/types.h>
@@ -1961,7 +2003,7 @@ fi
 rm -f conftest*
 
 cat > conftest.$ac_ext <<EOF
-#line 1965 "configure"
+#line 2007 "configure"
 #include "confdefs.h"
 
 #include <sys/select.h>
@@ -2041,12 +2083,12 @@ EOF
 for ac_func in strlen strcpy strcat strstr strcmp strerror strtok strdup
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:2045: checking for $ac_func" >&5
+echo "configure:2087: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2050 "configure"
+#line 2092 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
@@ -2069,7 +2111,7 @@ $ac_func();
 
 ; return 0; }
 EOF
-if { (eval echo configure:2073: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2115: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
@@ -2096,12 +2138,12 @@ done
 for ac_func in strchr memcpy
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:2100: checking for $ac_func" >&5
+echo "configure:2142: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2105 "configure"
+#line 2147 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
@@ -2124,7 +2166,7 @@ $ac_func();
 
 ; return 0; }
 EOF
-if { (eval echo configure:2128: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2170: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
@@ -2151,12 +2193,12 @@ done
 for ac_func in fgets
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:2155: checking for $ac_func" >&5
+echo "configure:2197: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2160 "configure"
+#line 2202 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
@@ -2179,7 +2221,7 @@ $ac_func();
 
 ; return 0; }
 EOF
-if { (eval echo configure:2183: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2225: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
@@ -2206,12 +2248,12 @@ done
 for ac_func in yylex
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
-echo "configure:2210: checking for $ac_func" >&5
+echo "configure:2252: checking for $ac_func" >&5
 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2215 "configure"
+#line 2257 "configure"
 #include "confdefs.h"
 /* System header to define __stub macros and hopefully few prototypes,
     which can conflict with char $ac_func(); below.  */
@@ -2234,7 +2276,7 @@ $ac_func();
 
 ; return 0; }
 EOF
-if { (eval echo configure:2238: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2280: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   eval "ac_cv_func_$ac_func=yes"
 else
@@ -2262,14 +2304,14 @@ done
 # check if -lsocket && -lxnet is required to compile socket stuff
 
 echo $ac_n "checking for library containing socket""... $ac_c" 1>&6
-echo "configure:2266: checking for library containing socket" >&5
+echo "configure:2308: checking for library containing socket" >&5
 if eval "test \"`echo '$''{'ac_cv_search_socket'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_func_search_save_LIBS="$LIBS"
 ac_cv_search_socket="no"
 cat > conftest.$ac_ext <<EOF
-#line 2273 "configure"
+#line 2315 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -2280,7 +2322,7 @@ int main() {
 socket()
 ; return 0; }
 EOF
-if { (eval echo configure:2284: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2326: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   ac_cv_search_socket="none required"
 else
@@ -2291,7 +2333,7 @@ rm -f conftest*
 test "$ac_cv_search_socket" = "no" && for i in socket; do
 LIBS="-l$i  $ac_func_search_save_LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 2295 "configure"
+#line 2337 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -2302,7 +2344,7 @@ int main() {
 socket()
 ; return 0; }
 EOF
-if { (eval echo configure:2306: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2348: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   ac_cv_search_socket="-l$i"
 break
@@ -2324,14 +2366,14 @@ else :
 fi
 
 echo $ac_n "checking for library containing inet_addr""... $ac_c" 1>&6
-echo "configure:2328: checking for library containing inet_addr" >&5
+echo "configure:2370: checking for library containing inet_addr" >&5
 if eval "test \"`echo '$''{'ac_cv_search_inet_addr'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   ac_func_search_save_LIBS="$LIBS"
 ac_cv_search_inet_addr="no"
 cat > conftest.$ac_ext <<EOF
-#line 2335 "configure"
+#line 2377 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -2342,7 +2384,7 @@ int main() {
 inet_addr()
 ; return 0; }
 EOF
-if { (eval echo configure:2346: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2388: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   ac_cv_search_inet_addr="none required"
 else
@@ -2353,7 +2395,7 @@ rm -f conftest*
 test "$ac_cv_search_inet_addr" = "no" && for i in nsl xnet; do
 LIBS="-l$i  $ac_func_search_save_LIBS"
 cat > conftest.$ac_ext <<EOF
-#line 2357 "configure"
+#line 2399 "configure"
 #include "confdefs.h"
 /* Override any gcc2 internal prototype to avoid an error.  */
 /* We use char because int might match the return type of a gcc2
@@ -2364,7 +2406,7 @@ int main() {
 inet_addr()
 ; return 0; }
 EOF
-if { (eval echo configure:2368: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+if { (eval echo configure:2410: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
   rm -rf conftest*
   ac_cv_search_inet_addr="-l$i"
 break
@@ -2398,7 +2440,7 @@ fi
 # Checking characteristics of compilers and other programs
 # --------------------------------------------------------
 echo $ac_n "checking whether preprocessor accepts -MM or -M""... $ac_c" 1>&6
-echo "configure:2402: checking whether preprocessor accepts -MM or -M" >&5
+echo "configure:2444: checking whether preprocessor accepts -MM or -M" >&5
 if eval "test \"`echo '$''{'sdcc_cv_MM'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2420,7 +2462,7 @@ M_OR_MM=$sdcc_cv_MM
 # This is the first time when CFLAGS are set/modified!!
 
 echo $ac_n "checking whether $CC accepts -ggdb""... $ac_c" 1>&6
-echo "configure:2424: checking whether $CC accepts -ggdb" >&5
+echo "configure:2466: checking whether $CC accepts -ggdb" >&5
 if eval "test \"`echo '$''{'sdcc_cv_CCggdb'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2445,7 +2487,7 @@ fi
 
 
 echo $ac_n "checking whether $CC accepts -pipe""... $ac_c" 1>&6
-echo "configure:2449: checking whether $CC accepts -pipe" >&5
+echo "configure:2491: checking whether $CC accepts -pipe" >&5
 if eval "test \"`echo '$''{'sdcc_cv_CCpipe'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
@@ -2472,12 +2514,12 @@ fi
 # Checks for typedefs, structures, and compiler characteristics.
 # ===========================================================================
 echo $ac_n "checking return type of signal handlers""... $ac_c" 1>&6
-echo "configure:2476: checking return type of signal handlers" >&5
+echo "configure:2518: checking return type of signal handlers" >&5
 if eval "test \"`echo '$''{'ac_cv_type_signal'+set}'`\" = set"; then
   echo $ac_n "(cached) $ac_c" 1>&6
 else
   cat > conftest.$ac_ext <<EOF
-#line 2481 "configure"
+#line 2523 "configure"
 #include "confdefs.h"
 #include <sys/types.h>
 #include <signal.h>
@@ -2494,7 +2536,7 @@ int main() {
 int i;
 ; return 0; }
 EOF
-if { (eval echo configure:2498: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
+if { (eval echo configure:2540: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
   rm -rf conftest*
   ac_cv_type_signal=void
 else
@@ -2772,6 +2814,69 @@ fi
 OPT_ENABLE_PACKIHX=$enable_packihx
 
 
+# Check whether --enable-libgc or --disable-libgc was given.
+if test "${enable_libgc+set}" = set; then
+  enableval="$enable_libgc"
+  :
+fi
+
+if test "$enable_libgc" = "yes"; then
+        echo $ac_n "checking for GC_malloc in -lgc""... $ac_c" 1>&6
+echo "configure:2826: checking for GC_malloc in -lgc" >&5
+ac_lib_var=`echo gc'_'GC_malloc | sed 'y%./+-%__p_%'`
+if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then
+  echo $ac_n "(cached) $ac_c" 1>&6
+else
+  ac_save_LIBS="$LIBS"
+LIBS="-lgc  $LIBS"
+cat > conftest.$ac_ext <<EOF
+#line 2834 "configure"
+#include "confdefs.h"
+/* Override any gcc2 internal prototype to avoid an error.  */
+/* We use char because int might match the return type of a gcc2
+    builtin and then its argument prototype would still apply.  */
+char GC_malloc();
+
+int main() {
+GC_malloc()
+; return 0; }
+EOF
+if { (eval echo configure:2845: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=yes"
+else
+  echo "configure: failed program was:" >&5
+  cat conftest.$ac_ext >&5
+  rm -rf conftest*
+  eval "ac_cv_lib_$ac_lib_var=no"
+fi
+rm -f conftest*
+LIBS="$ac_save_LIBS"
+
+fi
+if eval "test \"`echo '$ac_cv_lib_'$ac_lib_var`\" = yes"; then
+  echo "$ac_t""yes" 1>&6
+    ac_tr_lib=HAVE_LIB`echo gc | sed -e 's/[^a-zA-Z0-9_]/_/g' \
+    -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/'`
+  cat >> confdefs.h <<EOF
+#define $ac_tr_lib 1
+EOF
+
+  LIBS="-lgc $LIBS"
+
+else
+  echo "$ac_t""no" 1>&6
+fi
+
+        OPT_ENABLE_LIBGC=1
+else
+        OPT_ENABLE_LIBGC=0
+fi
+cat >> confdefs.h <<EOF
+#define OPT_ENABLE_LIBGC $OPT_ENABLE_LIBGC
+EOF
+
+
 #remove duplicates
 cat ports.all | uniq >ports
 mv ports ports.all
index 1f4f1bf96828f0b959047790ec2401475ec61b80..541e1e5493a678a3cc1a73094c5e38dd3aa43abb 100755 (executable)
@@ -300,10 +300,19 @@ AC_ARG_ENABLE(device-lib-build,[  --disable-device-lib-build Disables automatica
 OPT_ENABLE_DEVICE_LIB_BUILD=$enable_device_lib_build
 AC_SUBST(OPT_ENABLE_DEVICE_LIB_BUILD)
 
-AC_ARG_ENABLE(packihx,[  -disable-packihx     Disables building packihx])
+AC_ARG_ENABLE(packihx,[  --disable-packihx       Disables building packihx])
 OPT_ENABLE_PACKIHX=$enable_packihx
 AC_SUBST(OPT_ENABLE_PACKIHX)
 
+AC_ARG_ENABLE(libgc,[  --enable-libgc          Use the Bohem memory allocator.  Lower runtime footprint.])
+if test "$enable_libgc" = "yes"; then
+        AC_CHECK_LIB(gc, GC_malloc)
+        OPT_ENABLE_LIBGC=1
+else
+        OPT_ENABLE_LIBGC=0
+fi
+AC_DEFINE_UNQUOTED(OPT_ENABLE_LIBGC, $OPT_ENABLE_LIBGC)
+
 #remove duplicates
 cat ports.all | uniq >ports
 mv ports ports.all
index 8c44c9c75e083dc685d9702876a64195e09ee5ea..b85db47ad14d9c6b0ca72d0c0d4199f8ce118c7f 100644 (file)
@@ -11,6 +11,7 @@ SHELL         = /bin/sh
 CC             = @CC@
 CPP            = @CPP@
 INSTALL                = @INSTALL@
+STRIP           = @STRIP@
 
 PRJDIR         = ../..
 SLIB           = $(PRJDIR)/support/Util
@@ -53,7 +54,8 @@ all: checkconf $(TARGET)
 # Compiling and installing everything and runing test
 # ---------------------------------------------------
 install: all installdirs
-       $(INSTALL) -s $(TARGET) $(bindir)/sdcdb
+       $(INSTALL) $(TARGET) $(bindir)/sdcdb
+       $(STRIP) $(bindir)/sdcdb
        cp $(PRJDIR)/debugger/mcs51/sdcdb.el $(bindir)/sdcdb.el
        cp $(PRJDIR)/debugger/mcs51/sdcdbsrc.el $(bindir)/sdcdbsrc.el
 
index e45d6c3815333363676966c39ed3231150e30b96..9a9c80b9c03589520ebb140db66f3289de697240 100644 (file)
@@ -15,10 +15,12 @@ SLIBOBJS    = $(SLIBSRC:%.c=$(OBJDIR)/%.o)
 
 BINS   = $(BUILDDIR)link$(EXT)
 
-CFLAGS += $(OPTS) -DINDEXLIB -DMLH_MAP -DUNIX -DSDK
+CFLAGS += $(CPPFLAGS) $(OPTS) -DINDEXLIB -DMLH_MAP -DUNIX -DSDK
 CFLAGS += -funsigned-char -DUNIX
 CFLAGS += -I$(PRJDIR)/as/$(PORT) -I$(SLIB) 
 
+LDFLAGS += -lm $(EXTRALIBS)
+
 all:   $(BINS)
 
 $(BINS): $(OBJDIR) $(OBJS) $(SLIBOBJS)
index df659b1981151e80fa1a3568f4ed70c7fca3c39f..8965b21d2a1d646a77400b0be98d6c5e653c8427 100644 (file)
@@ -38,6 +38,8 @@
 #undef OPT_DISABLE_I186
 #undef OPT_DISABLE_TLCS900H
 
+#undef OPT_ENABLE_LIBGC
+
 #endif
 
 /* End of config.h */
index 3e3977117727958cce18d04894570ebeb6477efc..de2bcba66ac4579b37bd306063c5304bc0ac3e0f 100644 (file)
@@ -34,6 +34,7 @@ AC_PROG_INSTALL
 AC_PROG_RANLIB
 AC_LANG_CPLUSPLUS
 
+AC_CHECK_PROG(STRIP, strip, strip, :)
 
 # Checking for header files.
 # ===========================================================================
index 64e696ca8b23e886a6e0030369c17677c6a4f0db..2588ff2d9e8a63ae72530173edfa462e721c69fc 100644 (file)
@@ -12,6 +12,7 @@ CPP           = @CPP@
 CXXCPP         = @CXXCPP@
 RANLIB         = @RANLIB@
 INSTALL                = @INSTALL@
+STRIP          = @STRIP@
 
 PRJDIR         = ..
 
@@ -66,8 +67,8 @@ test_ser.ihx: test_ser.rel
 # Compiling and installing everything and runing test
 # ---------------------------------------------------
 install: all installdirs
-       if test -f s51.exe; then $(INSTALL) -s s51.exe $(bindir);fi
-       if test -f s51; then $(INSTALL) -s s51 $(bindir);fi
+       if test -f s51.exe; then $(INSTALL) s51.exe $(bindir); $(STRIP) $(bindir)/s51.exe; fi
+       if test -f s51; then $(INSTALL) s51 $(bindir); $(STRIP) $(bindir)/s51; fi
 
 
 # Deleting all the installed files
index 8d2dc055ce846c7f682e7ab8c05c51b05f4dac92..4eddd3ee77a507cd4513327bcce86108b9577e48 100644 (file)
@@ -91,7 +91,7 @@ struct options  save_options  ;
 <asm>"_endasm" { 
   count();
   *asmp = '\0';
-  yylval.yyinline = Safe_calloc (1, strlen(asmbuff)+1);
+  yylval.yyinline = Safe_alloc (strlen(asmbuff)+1);
   strcpy(yylval.yyinline,asmbuff);
   BEGIN(INITIAL);
   return (INLINEASM);
@@ -288,7 +288,7 @@ int checkCurrFile ( char *s)
        /* mark the end of the filename */
        while (*s != '"') s++;
        *s = '\0';
-       currFname = Safe_calloc(1,strlen(sb)+1);
+       currFname = Safe_alloc (strlen(sb)+1);
        strcpy(currFname,sb);
        lineno = yylineno = lNum;
     }
index 952d35322d9006532e873baca4ff904f14dd1479..d6217c53507e566b6ee1df511debc642addcba9a 100644 (file)
@@ -1135,7 +1135,7 @@ statement
    | jump_statement
    | INLINEASM  ';'      {
                             ast *ex = newNode(INLINEASM,NULL,NULL);
-                           ex->values.inlineasm = Safe_calloc(1,strlen($1)+1);
+                           ex->values.inlineasm = Safe_alloc(strlen($1)+1);
                            strcpy(ex->values.inlineasm,$1);                        
                            $$ = ex;
                          }   
index 2d83d9f3da6dc0adee0446a8baab7b8d4af46fa0..79126353fafca4d4cd5a4d7275850fc146abd9b4 100644 (file)
@@ -24,7 +24,6 @@
 -------------------------------------------------------------------------*/
 
 #include "common.h"
-#include "newalloc.h"
 
 int eBBNum = 0;
 set *graphEdges = NULL;                /* list of edges in this flow graph */
@@ -65,7 +64,7 @@ neweBBlock ()
 {
   eBBlock *ebb;
 
-  ebb = Safe_calloc (1, sizeof (eBBlock));
+  ebb = Safe_alloc (sizeof (eBBlock));
   return ebb;
 }
 
@@ -77,7 +76,7 @@ newEdge (eBBlock * from, eBBlock * to)
 {
   edge *ep;
 
-  ep = Safe_calloc (1, sizeof (edge));
+  ep = Safe_alloc (sizeof (edge));
 
   ep->from = from;
   ep->to = to;
@@ -437,7 +436,7 @@ iCodeBreakDown (iCode * ic, int *count)
 
   /* allocate for the first entry */
 
-  ebbs = Safe_calloc (1, sizeof (eBBlock **));
+  ebbs = Safe_alloc (sizeof (eBBlock **));
 
   while (loop)
     {
index 1300ecba98892aa3f084544c461df7c9331f1193..235ee0376df623e51d8ccc51e1c871825af84b2f 100644 (file)
@@ -23,7 +23,6 @@
 -------------------------------------------------------------------------*/
 
 #include "common.h"
-#include "newalloc.h"
 
 int currLineno = 0;
 set *astList = NULL;
@@ -75,7 +74,7 @@ newAst (int type, void *op)
   ast *ex;
   static int oldLineno = 0;
 
-  Safe_calloc (1, ex, sizeof (ast));
+  ex = Safe_alloc ( sizeof (ast));
 
   ex->type = type;
   ex->lineno = (noLineno ? oldLineno : yylineno);
@@ -110,7 +109,7 @@ newAst_ (unsigned type)
   ast *ex;
   static int oldLineno = 0;
 
-  ex = Safe_calloc (1, sizeof (ast));
+  ex = Safe_alloc ( sizeof (ast));
 
   ex->type = type;
   ex->lineno = (noLineno ? oldLineno : yylineno);
@@ -221,7 +220,7 @@ copyAstValues (ast * dest, ast * src)
       break;
 
     case INLINEASM:
-      dest->values.inlineasm = Safe_calloc (1, strlen (src->values.inlineasm) + 1);
+      dest->values.inlineasm = Safe_alloc (strlen (src->values.inlineasm) + 1);
       strcpy (dest->values.inlineasm, src->values.inlineasm);
       break;
 
@@ -252,7 +251,7 @@ copyAst (ast * src)
   if (!src)
     return NULL;
 
-  dest = Safe_calloc (1, sizeof (ast));
+  dest = Safe_alloc ( sizeof (ast));
 
   dest->type = src->type;
   dest->lineno = src->lineno;
index c2d5d64fb4a66ced5196c9a6fe4680e33b3f2478..da8c692a0ea4a4e3859a801e4b60d29149a53975 100644 (file)
@@ -151,6 +151,8 @@ bitVectUnion (bitVect * bvp1, bitVect * bvp2)
 {
   int i;
   bitVect *newBvp;
+  unsigned int *pn, *p1, *p2;
+  int nbits;
 
   /* if both null */
   if (!bvp1 && !bvp2)
@@ -171,8 +173,20 @@ bitVectUnion (bitVect * bvp1, bitVect * bvp2)
     bvp2 = bitVectResize (bvp2, bvp1->size);
 
   newBvp = newBitVect (bvp1->size);
+  nbits = bvp1->bSize;
+  i = 0;
 
-  for (i = 0; i < bvp1->bSize; i++)
+  pn = (unsigned int *)newBvp->vect; 
+  p1 = (unsigned int *)bvp1->vect;
+  p2 = (unsigned int *)bvp2->vect;
+
+  while ((nbits - i) >= sizeof(*pn))
+    {
+      *pn++ = *p1++ | *p2++;
+      i += sizeof(*pn);
+    }
+
+  for (; i < nbits; i++)
     newBvp->vect[i] = bvp1->vect[i] | bvp2->vect[i];
 
 
@@ -187,6 +201,8 @@ bitVectIntersect (bitVect * bvp1, bitVect * bvp2)
 {
   int i;
   bitVect *newBvp;
+  unsigned int *pn, *p1, *p2;
+  int nbits;
 
   if (!bvp2 || !bvp1)
     return NULL;
@@ -199,8 +215,20 @@ bitVectIntersect (bitVect * bvp1, bitVect * bvp2)
     bvp2 = bitVectResize (bvp2, bvp1->size);
 
   newBvp = newBitVect (bvp1->size);
+  nbits = bvp1->bSize;
+  i = 0;
 
-  for (i = 0; i < bvp1->bSize; i++)
+  pn = (unsigned int *)newBvp->vect; 
+  p1 = (unsigned int *)bvp1->vect;
+  p2 = (unsigned int *)bvp2->vect;
+
+  while ((nbits - i) >= sizeof(*pn))
+    {
+      *pn++ = *p1++ & *p2++;
+      i += sizeof(*pn);
+    }
+
+  for (; i < nbits; i++)
     newBvp->vect[i] = bvp1->vect[i] & bvp2->vect[i];
 
   return newBvp;
@@ -214,11 +242,27 @@ int
 bitVectBitsInCommon (bitVect * bvp1, bitVect * bvp2)
 {
   int i;
+  int nbits;
+  unsigned int *p1, *p2;
 
   if (!bvp1 || !bvp2)
     return 0;
 
-  for (i = 0; i < min (bvp1->bSize, bvp2->bSize); i++)
+  nbits = min (bvp1->bSize, bvp2->bSize);
+  i = 0;
+
+  p1 = (unsigned int *)bvp1->vect;
+  p2 = (unsigned int *)bvp2->vect;
+
+  while ((nbits-i) >= sizeof(*p1))
+    {
+      if (*p1 & *p2)
+        return 1;
+      p1++; p2++;
+      i += sizeof(*p1);
+    }
+
+  for (; i < nbits; i++)
     if (bvp1->vect[i] & bvp2->vect[i])
       return 1;
 
@@ -232,6 +276,8 @@ bitVect *
 bitVectCplAnd (bitVect * bvp1, bitVect * bvp2)
 {
   int i;
+  unsigned int *p1, *p2;
+  int nbits;
 
   if (!bvp2)
     return bvp1;
@@ -246,7 +292,20 @@ bitVectCplAnd (bitVect * bvp1, bitVect * bvp2)
   else if (bvp2->size < bvp1->size)
     bvp2 = bitVectResize (bvp2, bvp1->size);
 
-  for (i = 0; i < bvp1->bSize; i++)
+  nbits = bvp1->bSize;
+  i = 0;
+
+  p1 = (unsigned int *)bvp1->vect;
+  p2 = (unsigned int *)bvp2->vect;
+
+  while ((nbits - i) >= sizeof(*p1))
+    {
+      *p1 = *p1 & (~*p2);
+      p2++; p1++;
+      i += sizeof(*p1);
+    }
+
+  for (; i < nbits; i++)
     bvp1->vect[i] = bvp1->vect[i] & (~bvp2->vect[i]);
 
   return bvp1;
@@ -319,31 +378,59 @@ bitVectCopy (bitVect * bvp)
 int 
 bitVectnBitsOn (bitVect * bvp)
 {
-  int i, j, k;
+  int i, j;
   unsigned char byte;
   int count = 0;
+  unsigned int *p1;
+
+  /* The bit vector is highest to lowest.  Interesting. */
+  unsigned int mask[] = {
+    0, 128, 128+64, 128+64+32, 128+64+32+16,
+    128+64+32+16+8, 128+64+32+16+8+4, 128+64+32+16+8+4+2
+  };
 
   if (!bvp)
     return 0;
 
-  /* rip through most of the data in byte sized chunks */
-  j = (bvp->size) / 8;
-  for (i = 0; i < j; i++)
+  /* j is the number of bytes in the bitvect */
+  j = (bvp->size+7) / 8;
+
+  /* Fix up the highest bits in the top byte so that we can iterate over
+     all of them. */
+  if (bvp->size%8 != 0)
     {
-      byte = bvp->vect[i];
-      for (k = 0; k < 8; k++)
-       {
-         count += byte & 1;
-         byte = byte >> 1;
-       }
+      bvp->vect[j-1] &= mask[bvp->size&7];
     }
 
-  /* finish up the last fractional byte, if any */
-  for (i = j * 8; i < bvp->size; i++)
-    count += bitVectBitValue (bvp, i);
+  /* Take care of things in machine word chunks if possible.  As we
+     are only counting bits it does not matter which order they are
+     counted in.
+  */
+  i = 0;
+  p1 = (unsigned int *)bvp->vect;
 
-  return count;
+  while ((j-i) >= sizeof(*p1))
+    {
+      unsigned int word = *p1++;
+      while (word)
+        {
+          count++;
+          word &= word-1;
+        }
+      i += sizeof(*p1);
+    }
 
+  /* Take care of the rest of the bitvect. */
+  for (; i < j; i++)
+    {
+      byte = bvp->vect[i];
+      while (byte)
+        {
+          count++;
+          byte &= byte-1;
+        }
+    }
+  return count;
 }
 
 /*-----------------------------------------------------------------*/
index 1bff79e102f6ea631e3ddd69921710a554bd9d27..34ab12cde515cd8b4b6676ee46f424234ad6ce1d 100644 (file)
@@ -34,7 +34,7 @@ newCseDef (operand * sym, iCode * ic)
   cseDef *cdp;
 
   assert (sym);
-  cdp = Safe_calloc (1, sizeof (cseDef));
+  cdp = Safe_alloc (sizeof (cseDef));
 
   cdp->sym = sym;
   cdp->diCode = ic;
index 71821860912bff87a50720c5a815399850190a96..e33f08cb28a9c0c9b5c141557078cc015247eb09 100644 (file)
@@ -40,7 +40,7 @@ _newHashtItem (int key, void *pkey, void *item)
 {
   hashtItem *htip;
 
-  htip = Safe_calloc (1, sizeof (hashtItem));
+  htip = Safe_alloc ( sizeof (hashtItem));
 
   htip->key = key;
   htip->pkey = pkey;
@@ -57,9 +57,9 @@ newHashTable (int size)
 {
   hTab *htab;
 
-  htab = Safe_calloc (1, sizeof (hTab));
+  htab = Safe_alloc ( sizeof (hTab));
 
-  if (!(htab->table = calloc ((size + 1), sizeof (hashtItem *))))
+  if (!(htab->table = Safe_alloc ((size + 1) * sizeof (hashtItem *))))
     {
       fprintf (stderr, "out of virtual memory %s %d\n",
               __FILE__, (size + 1) * sizeof (hashtItem *));
@@ -193,13 +193,13 @@ hTabDeleteAll (hTab * p)
          jn = jc->next;
          while (jc)
            {
-             free (jc);
+             Safe_free (jc);
              if ((jc = jn))
                jn = jc->next;
            }
          p->table[i] = NULL;
        }
-      free (p->table);
+      Safe_free (p->table);
     }
 }
 
index 3968b3ea3302b07300dd5abbe717a535137d3928..69c611efddb425b45ae846d8002ec13d200b3289 100644 (file)
@@ -499,7 +499,7 @@ newOperand ()
 {
   operand *op;
 
-  op = Safe_calloc (1, sizeof (operand));
+  op = Safe_alloc ( sizeof (operand));
 
   op->key = 0;
   return op;
@@ -513,7 +513,7 @@ newiCode (int op, operand * left, operand * right)
 {
   iCode *ic;
 
-  ic = Safe_calloc (1, sizeof (iCode));
+  ic = Safe_alloc ( sizeof (iCode));
 
   ic->lineno = lineno;
   ic->filename = filename;
@@ -3167,7 +3167,7 @@ lvalItem;
 /*-----------------------------------------------------------------*/
 void addLvaluereq(int lvl)
 {
-  lvalItem * lpItem = (lvalItem *)Safe_calloc (1, sizeof (lvalItem));
+  lvalItem * lpItem = (lvalItem *)Safe_alloc ( sizeof (lvalItem));
   lpItem->req=1;
   lpItem->lvl=lvl;
   addSetHead(&lvaluereqSet,lpItem);
@@ -3180,7 +3180,7 @@ void delLvaluereq()
 {
   lvalItem * lpItem;
   lpItem = getSet(&lvaluereqSet);
-  if(lpItem) free(lpItem);
+  if(lpItem) Safe_free(lpItem);
 }
 /*-----------------------------------------------------------------*/
 /* clearLvaluereq - clear lvalreq flag                            */
index 0be4da81cb3dcaf2976c81905cb3f69313716e4a..34bb23d38653ee6f41cbdf70071f65ec4e0af00a 100644 (file)
@@ -39,7 +39,7 @@ newInduction (operand * sym, unsigned int op,
 {
   induction *ip;
 
-  ip = Safe_calloc (1, sizeof (induction));
+  ip = Safe_alloc ( sizeof (induction));
 
   ip->sym = sym;
   ip->asym = asym;
@@ -58,7 +58,7 @@ newRegion ()
 {
   region *lp;
 
-  lp = Safe_calloc (1, sizeof (region));
+  lp = Safe_alloc ( sizeof (region));
 
   return lp;
 }
index a0fff7cee509a26149f5eada32ea5c08273d3c9a..06118067a330728f6dba24e987f43c290ea7a832 100644 (file)
@@ -509,7 +509,7 @@ processFile (char *s)
 
       /* get rid of the "." */
       strtok (buffer, ".");
-      srcFileName = Safe_calloc (1, strlen (buffer) + 1);
+      srcFileName = Safe_alloc ( strlen (buffer) + 1);
       strcpy (srcFileName, buffer);
 
       /* get rid of any path information
@@ -522,7 +522,7 @@ processFile (char *s)
             *(fext - 1) != '/' &&
             *(fext - 1) != ':')
        fext--;
-      moduleName = Safe_calloc (1, strlen (fext) + 1);
+      moduleName = Safe_alloc ( strlen (fext) + 1);
       strcpy (moduleName, fext);
 
       return;
@@ -1076,7 +1076,7 @@ linkEdit (char **envp)
     segName = strdup(N); \
     c = strtok(segName, " \t"); \
     fprintf (lnkfile,"-b %s = 0x%04x\n", c, L); \
-    if (segName) { free(segName); }
+    if (segName) { Safe_free(segName); }
 
   /* code segment start */
   WRITE_SEG_LOC (CODE_NAME, options.code_loc);
@@ -1268,7 +1268,7 @@ preProcess (char **envp)
       setMainValue ("cppextraopts", join(preArgv));
       
       if (!preProcOnly)
-          preOutName = strdup (tempfilename ());
+          preOutName = Safe_strdup (tempfilename ());
 
       /* Have to set cppoutfilename to something, even if just pre-processing. */
       setMainValue ("cppoutfilename", preOutName ? preOutName : "");
@@ -1284,7 +1284,7 @@ preProcess (char **envp)
           if (preOutName)
             {
               unlink (preOutName);
-              free (preOutName);
+              Safe_free (preOutName);
             }
           // EndFix
          exit (1);
@@ -1544,7 +1544,7 @@ main (int argc, char **argv, char **envp)
                   if (yyin && yyin != stdin)
                     fclose (yyin);
                   unlink (preOutName);
-                  free (preOutName);
+                  Safe_free (preOutName);
                 }
               // EndFix
              return 1;
@@ -1564,7 +1564,7 @@ main (int argc, char **argv, char **envp)
               if (yyin && yyin != stdin)
                 fclose (yyin);
               unlink (preOutName);
-              free (preOutName);
+              Safe_free (preOutName);
             }
           // EndFix
           #if defined (__MINGW32__) || defined (__CYGWIN__) || defined (_MSC_VER)
@@ -1583,7 +1583,7 @@ main (int argc, char **argv, char **envp)
   if (preOutName && !options.c1mode)
     {
       unlink (preOutName);
-      free (preOutName);
+      Safe_free (preOutName);
     }
 
   if (!options.cc_only &&
index 4692be48e609842c9020b1e5f950311272e2c707..9084d1ec23371247dc916ae33d4796cbcf017d58 100644 (file)
@@ -46,7 +46,7 @@ allocMap (char rspace,                /* sfr space            */
 {
   memmap *map;
 
-  if (!(map = calloc (sizeof (memmap), 1)))
+  if (!(map = Safe_alloc (sizeof (memmap))))
     {
       werror (E_OUT_OF_MEM, __FILE__, sizeof (memmap));
       exit (1);
index 0a5a8d2394d0a65a388d7182362481aa35848211..ada11ff9e4a431c3adda955b18b16f6d431af2cf 100644 (file)
 -------------------------------------------------------------------------*/
 
 #include "common.h"
-#include "SDCCpeeph.h"
-#include "newalloc.h"
 
-peepRule *rootRules = NULL;
-peepRule *currRule = NULL;
+static peepRule *rootRules = NULL;
+static peepRule *currRule = NULL;
 
 #define HTAB_SIZE 53
 typedef struct
@@ -38,7 +36,13 @@ typedef struct
   }
 labelHashEntry;
 
-hTab *labelHash = NULL;
+static hTab *labelHash = NULL;
+
+static struct
+{
+  allocTrace values;
+  allocTrace labels;
+} _G;
 
 static int hashSymbolName (const char *name);
 static void buildLabelRefCountHash (lineNode * head);
@@ -105,7 +109,7 @@ FBYNAME (labelInRange)
   if (!lbl)
     return FALSE;
 
-  /* if the previous teo instructions are "ljmp"s then don't
+  /* 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 &&
       strstr (currPl->prev->line, "ljmp") &&
@@ -300,14 +304,14 @@ newPeepRule (lineNode * match,
 {
   peepRule *pr;
 
-  pr = Safe_calloc (1, sizeof (peepRule));
+  pr = Safe_alloc ( sizeof (peepRule));
   pr->match = match;
   pr->replace = replace;
   pr->restart = restart;
 
   if (cond && *cond)
     {
-      pr->cond = Safe_calloc (1, strlen (cond) + 1);
+      pr->cond = Safe_alloc ( strlen (cond) + 1);
       strcpy (pr->cond, cond);
     }
   else
@@ -332,8 +336,8 @@ newLineNode (char *line)
 {
   lineNode *pl;
 
-  pl = Safe_calloc (1, sizeof (lineNode));
-  pl->line = Safe_calloc (1, strlen (line) + 1);
+  pl = Safe_alloc ( sizeof (lineNode));
+  pl->line = Safe_alloc ( strlen (line) + 1);
   strcpy (pl->line, line);
   return pl;
 }
@@ -568,10 +572,10 @@ bindVar (int key, char **s, hTab ** vtab)
   *s = vvx;
   *vv = '\0';
   /* got value */
-  vvx = Safe_calloc (1, strlen (vval) + 1);
+  vvx = traceAlloc (&_G.values, Safe_alloc(strlen (vval) + 1));
   strcpy (vvx, vval);
-  hTabAddItem (vtab, key, vvx);
 
+  hTabAddItem (vtab, key, vvx);
 }
 
 /*-----------------------------------------------------------------*/
@@ -659,7 +663,6 @@ matchRule (lineNode * pl,
   lineNode *spl;               /* source pl */
   lineNode *rpl;               /* rule peep line */
 
-  hTabClearAll (pr->vars);
 /*     setToNull((void **) &pr->vars);    */
 /*     pr->vars = newHashTable(100); */
 
@@ -891,7 +894,7 @@ buildLabelRefCountHash (lineNode * head)
        {
          labelHashEntry *entry;
 
-         entry = Safe_calloc (1, sizeof (labelHashEntry));
+         entry = traceAlloc (&_G.labels, Safe_alloc(sizeof (labelHashEntry)));
 
          memcpy (entry->name, label, labelLen);
          entry->name[labelLen] = 0;
@@ -944,6 +947,21 @@ buildLabelRefCountHash (lineNode * head)
 #endif
 }
 
+/* How does this work?
+   peepHole
+    For each rule,
+     For each line,
+      Try to match
+      If it matches,
+       replace and restart.
+
+    matchRule
+     matchLine
+
+  Where is stuff allocated?
+  
+*/
+
 /*-----------------------------------------------------------------*/
 /* peepHole - matches & substitutes rules                          */
 /*-----------------------------------------------------------------*/
@@ -953,43 +971,65 @@ peepHole (lineNode ** pls)
   lineNode *spl;
   peepRule *pr;
   lineNode *mtail = NULL;
+  bool restart;
+
+  assert(labelHash == NULL);
+
+  do
+    {
+      restart = FALSE;
+
+      /* for all rules */
+      for (pr = rootRules; pr; pr = pr->next)
+        {
+          fflush(stdout);
+          
+          for (spl = *pls; spl; spl = spl->next)
+            {
+              /* if inline assembler then no peep hole */
+              if (spl->isInline)
+                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);
+            }
+        }
+    } while (restart == TRUE);
 
   if (labelHash)
     {
       hTabDeleteAll (labelHash);
+      freeTrace (&_G.labels);
     }
   labelHash = NULL;
-
-top:
-  /* for all rules */
-  for (pr = rootRules; pr; pr = pr->next)
-    {
-
-      for (spl = *pls; spl; spl = spl->next)
-       {
-         /* if inline assembler then no peep hole */
-         if (spl->isInline)
-           continue;
-
-         mtail = NULL;
-
-         /* 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)
-               goto top;
-           }
-       }
-    }
 }
 
 
@@ -1027,7 +1067,7 @@ readFileIntoBuffer (char *fname)
            }
          else
            {
-             rs = Safe_calloc (1, strlen (lb) + 1);
+             rs = Safe_alloc ( strlen (lb) + 1);
              strcpy (rs, lb);
            }
          nch = 0;
@@ -1046,7 +1086,7 @@ readFileIntoBuffer (char *fname)
        }
       else
        {
-         rs = Safe_calloc (1, strlen (lb) + 1);
+         rs = Safe_alloc ( strlen (lb) + 1);
          strcpy (rs, lb);
        }
     }
index f56b6cf4d1644c046e94c910d716f36b2dffbd1a..1746a5a9023aa38ce567523129cb624ffbdebaec 100644 (file)
 -------------------------------------------------------------------------*/
 
 #include <stdio.h>
-#if defined(__APPLE__) && defined(__MACH__)
-#include <sys/malloc.h>
-#else
-#include <malloc.h>
-#endif
 #include "newalloc.h"
 #include <assert.h>
 #include "SDCCset.h"
@@ -40,7 +35,7 @@ newSet ()
 {
   set *lp;
 
-  lp = Safe_calloc (1, sizeof (set));
+  lp = Safe_alloc ( sizeof (set));
 //  if (lp == 0) {
   //  fprintf(stderr, "out of virtual memory: %s\n", __FILE__);
   //  exit(1);
@@ -558,6 +553,6 @@ setToNull (void **item)
 
   if (!*item)
     return;
-  free (*item);
+  Safe_free (*item);
   *item = NULL;
 }
index 217265cd1f8902dafbf89d314e5d1d88d0f67107..de4b9d4b82184df0772590ee07123764807d9e18 100644 (file)
@@ -72,7 +72,7 @@ newBucket ()
 {
   bucket *bp;
 
-  bp = Safe_calloc (1, sizeof (bucket));
+  bp = Safe_alloc ( sizeof (bucket));
 
   return bp;
 }
@@ -121,7 +121,7 @@ addSym (bucket ** stab,
   /* the symbols are always added at the head of the list  */
   i = hashKey (sname);
   /* get a free entry */
-  bp = Safe_calloc (1, sizeof (bucket));
+  bp = Safe_alloc ( sizeof (bucket));
 
   bp->sym = sym;               /* update the symbol pointer  */
   bp->level = level;           /* update the nest level      */
@@ -273,7 +273,7 @@ newSymbol (char *name, int scope)
 {
   symbol *sym;
 
-  sym = Safe_calloc (1, sizeof (symbol));
+  sym = Safe_alloc ( sizeof (symbol));
 
   strcpy (sym->name, name);    /* copy the name    */
   sym->level = scope;          /* set the level    */
@@ -290,7 +290,7 @@ newLink ()
 {
   sym_link *p;
 
-  p = Safe_calloc (1, sizeof (sym_link));
+  p = Safe_alloc ( sizeof (sym_link));
 
   return p;
 }
@@ -303,7 +303,7 @@ newStruct (char *tag)
 {
   structdef *s;
 
-  s = Safe_calloc (1, sizeof (structdef));
+  s = Safe_alloc ( sizeof (structdef));
 
   strcpy (s->tag, tag);                /* copy the tag            */
   return s;
index ba665ff1694c707beee66a13bbbbf0e8572ffe25..edbe8e6e7fc15869fbb306e66262c81d0e5c7e7f 100644 (file)
@@ -291,7 +291,7 @@ char *
 gc_strdup (const char *s)
 {
   char *ret;
-  ret = Safe_calloc (1, strlen (s) + 1);
+  ret = Safe_alloc ( strlen (s) + 1);
   strcpy (ret, s);
   return ret;
 }
index c540a4fe1ec2c40637d449b08293ff80c326bcc6..800f0046ee7c84fef74b049827bb2824ddb1c9a3 100644 (file)
@@ -39,7 +39,7 @@ newValue ()
 {
   value *val;
 
-  val = Safe_calloc (1, sizeof (value));
+  val = Safe_alloc (sizeof (value));
 
   return val;
 }
@@ -53,7 +53,7 @@ newiList (int type, void *ilist)
   initList *nilist;
 
 
-  nilist = Safe_calloc (1, sizeof (initList));
+  nilist = Safe_alloc (sizeof (initList));
 
   nilist->type = type;
   nilist->lineno = yylineno;
@@ -139,7 +139,7 @@ convertIListToConstList(initList *src, literalList **lList)
        }
        else
        {
-           newL = Safe_malloc(sizeof(literalList));
+           newL = Safe_alloc(sizeof(literalList));
            newL->literalValue = val;
            newL->count = 1;
            newL->next = NULL;
@@ -175,7 +175,7 @@ copyLiteralList(literalList *src)
     
     while (src)
     {
-       newL = Safe_malloc(sizeof(literalList));
+       newL = Safe_alloc(sizeof(literalList));
        
        newL->literalValue = src->literalValue;
        newL->count = src->count;
@@ -652,7 +652,7 @@ strVal (char *s)
   SPEC_NOUN (val->etype) = V_CHAR;
   SPEC_SCLS (val->etype) = S_LITERAL;
 
-  SPEC_CVAL (val->etype).v_char = Safe_calloc (1, strlen (s) + 1);
+  SPEC_CVAL (val->etype).v_char = Safe_alloc (strlen (s) + 1);
   DCL_ELEM (val->type) = copyStr (SPEC_CVAL (val->etype).v_char, s);
 
   return val;
index 5694aa7750a5b1a9621242d05530b3845acde40b..0909e7dce993176f972803d55171ff61b45878e1 100644 (file)
@@ -32,3 +32,5 @@
 
 #include "asm.h"
 #include "port.h"
+
+#include "newalloc.h"
index 4e8456e48de942c6c742b91079067beac5512757..73f965e270952736712b3193804c028fdebdebd1 100644 (file)
@@ -93,8 +93,6 @@ static struct {
     set *sendSet;
 } _G;
 
-char *Safe_strdup(char *str);  // in pcode.c
-
 extern int pic14_ptrRegReq ;
 extern int pic14_nRegs;
 extern FILE *codeOutFile;
index dd15d09c0b03d5b37671a65ac30be36d06ca3f16..062fac95d6dbd5afb01e3e2ac350dc3b47433c16 100644 (file)
@@ -737,24 +737,6 @@ pCodeInstruction pciXORLW = {
 #define MAX_PIC14MNEMONICS 100
 pCodeInstruction *pic14Mnemonics[MAX_PIC14MNEMONICS];
 
-char *Safe_strdup(char *str)
-{
-  char *copy;
-
-  if(!str)
-    return NULL;
-
-  copy = strdup(str);
-  if(!copy) {
-    fprintf(stderr, "out of memory %s,%d\n",__FUNCTION__,__LINE__);
-    exit(1);
-  }
-
-  return copy;
-    
-}
-
-
 /*-----------------------------------------------------------------*/
 /* SAFE_snprintf - like snprintf except the string pointer is      */
 /*                 after the string has been printed to. This is   */
index 2f1fd188bd1f07c57117b28d4fb692e275a923d0..3a8d52654825b78bde9cf56ea9c0d87bf890074c 100644 (file)
@@ -40,7 +40,6 @@ pCodeOp *popCopyGPR2Bit(pCodeOpReg *pc, int bitval);
 pCodeOp *newpCodeOpWild(int id, pCodePeep *pcp, pCodeOp *subtype);
 pCode *newpCodeWild(int pCodeID, pCodeOp *optional_operand, pCodeOp *optional_label);
 pCode * findNextInstruction(pCode *pc);
-char *Safe_strdup(char *str);
 int getpCode(char *mnem,int dest);
 void pBlockMergeLabels(pBlock *pb);
 char *pCode2str(char *str, int size, pCode *pc);
index 474d89815f8c91e93c140c0f6222f331c6c9ab06..87c9de40d47fd5d68dd6bbeef3f4473f324bd90f 100644 (file)
@@ -220,8 +220,13 @@ static struct
     lineNode *head;
     lineNode *current;
     int isInline;
+    allocTrace trace;
   } lines;
 
+  struct
+  {
+    allocTrace aops;
+  } trace;
 } _G;
 
 static const char *aopGet (asmop * aop, int offset, bool bit16);
@@ -268,6 +273,17 @@ _tidyUp (char *buf)
     }
 }
 
+static lineNode *
+_newLineNode (char *line)
+{
+  lineNode *pl;
+
+  pl = traceAlloc(&_G.lines.trace, Safe_alloc ( sizeof (lineNode)));
+  pl->line = traceAlloc(&_G.lines.trace, Safe_strdup (line));
+
+  return pl;
+}
+
 static void
 _vemit2 (const char *szFormat, va_list ap)
 {
@@ -277,8 +293,8 @@ _vemit2 (const char *szFormat, va_list ap)
 
   _tidyUp (buffer);
   _G.lines.current = (_G.lines.current ?
-             connectLine (_G.lines.current, newLineNode (buffer)) :
-             (_G.lines.head = newLineNode (buffer)));
+             connectLine (_G.lines.current, _newLineNode (buffer)) :
+             (_G.lines.head = _newLineNode (buffer)));
 
   _G.lines.current->isInline = _G.lines.isInline;
 }
@@ -336,8 +352,8 @@ _emit2 (const char *inst, const char *fmt,...)
   if (lbp && *lbp)
     {
       _G.lines.current = (_G.lines.current ?
-                  connectLine (_G.lines.current, newLineNode (lb)) :
-                  (_G.lines.head = newLineNode (lb)));
+                  connectLine (_G.lines.current, _newLineNode (lb)) :
+                  (_G.lines.head = _newLineNode (lb)));
     }
   _G.lines.current->isInline = _G.lines.isInline;
   va_end (ap);
@@ -496,7 +512,7 @@ newAsmop (short type)
 {
   asmop *aop;
 
-  aop = Safe_calloc (1, sizeof (asmop));
+  aop = traceAlloc(&_G.trace.aops, Safe_alloc (sizeof (asmop)));
   aop->type = type;
   return aop;
 }
@@ -534,8 +550,7 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool requires_a)
   if (IS_FUNC (sym->type))
     {
       sym->aop = aop = newAsmop (AOP_IMMD);
-      aop->aopu.aop_immd = Safe_calloc (1, strlen (sym->rname) + 1);
-      strcpy (aop->aopu.aop_immd, sym->rname);
+      aop->aopu.aop_immd = traceAlloc(&_G.trace.aops, Safe_strdup (sym->rname));
       aop->size = 2;
       return aop;
     }
@@ -601,8 +616,7 @@ aopForRemat (symbol * sym)
       break;
     }
 
-  aop->aopu.aop_immd = Safe_calloc (1, strlen (buffer) + 1);
-  strcpy (aop->aopu.aop_immd, buffer);
+  aop->aopu.aop_immd = traceAlloc(&_G.trace.aops, Safe_strdup(buffer));
   return aop;
 }
 
@@ -918,7 +932,7 @@ aopGetLitWordLong (asmop * aop, int offset, bool with_hash)
         {
           tsprintf (s, "%s + %d", aop->aopu.aop_immd, offset);
         }
-      return gc_strdup(s);
+      return traceAlloc(&_G.trace.aops, Safe_strdup(s));
 
     case AOP_LIT:
       {
@@ -947,7 +961,7 @@ aopGetLitWordLong (asmop * aop, int offset, bool with_hash)
            else
              tsprintf (buffer, "!constword", v);
 
-            return gc_strdup(buffer);
+            return traceAlloc(&_G.trace.aops, Safe_strdup(buffer));
          }
        else
          {
@@ -1060,7 +1074,7 @@ fetchLitPair (PAIR_ID pairId, asmop * left, int offset)
            }
        }
       _G.pairs[pairId].last_type = left->type;
-      _G.pairs[pairId].base = gc_strdup (base);
+      _G.pairs[pairId].base = traceAlloc(&_G.trace.aops, Safe_strdup (base));
       _G.pairs[pairId].offset = offset;
     }
   /* Both a lit on the right and a true symbol on the left */
@@ -1190,7 +1204,7 @@ aopGet (asmop * aop, int offset, bool bit16)
       aop->type != AOP_LIT) 
     {
       tsprintf (s, "!zero");
-      return gc_strdup(s);
+      return traceAlloc(&_G.trace.aops, Safe_strdup(s));
     }
 
   /* depending on type */
@@ -1216,21 +1230,21 @@ aopGet (asmop * aop, int offset, bool bit16)
            wassertl (0, "Fetching from beyond the limits of an immediate value.");
          }
 
-      return gc_strdup(s);
+      return traceAlloc(&_G.trace.aops, Safe_strdup(s));
 
     case AOP_DIR:
       wassert (IS_GB);
       emit2 ("ld a,(%s+%d)", aop->aopu.aop_dir, offset);
       sprintf (s, "a");
 
-      return gc_strdup(s);
+      return traceAlloc(&_G.trace.aops, Safe_strdup(s));
 
     case AOP_SFR:
       wassert (IS_GB);
       emit2 ("ldh a,(%s+%d)", aop->aopu.aop_dir, offset);
       sprintf (s, "a");
 
-      return gc_strdup(s);
+      return traceAlloc(&_G.trace.aops, Safe_strdup(s));
 
     case AOP_REG:
       return aop->aopu.aop_reg[offset]->name;
@@ -1240,14 +1254,14 @@ aopGet (asmop * aop, int offset, bool bit16)
       setupPair (PAIR_HL, aop, offset);
       tsprintf (s, "!*hl");
 
-      return gc_strdup (s);
+      return traceAlloc(&_G.trace.aops, Safe_strdup (s));
 
     case AOP_IY:
       wassert (IS_Z80);
       setupPair (PAIR_IY, aop, offset);
       tsprintf (s, "!*iyx", offset);
 
-      return gc_strdup(s);
+      return traceAlloc(&_G.trace.aops, Safe_strdup(s));
 
     case AOP_STK:
       if (IS_GB)
@@ -1262,7 +1276,7 @@ aopGet (asmop * aop, int offset, bool bit16)
          tsprintf (s, "!*ixx", aop->aopu.aop_stk + offset);
        }
 
-      return gc_strdup(s);
+      return traceAlloc(&_G.trace.aops, Safe_strdup(s));
 
     case AOP_CRY:
       wassertl (0, "Tried to fetch from a bit variable");
@@ -1275,7 +1289,7 @@ aopGet (asmop * aop, int offset, bool bit16)
       else
         {
           tsprintf(s, "!zero");
-          return gc_strdup(s);
+          return traceAlloc(&_G.trace.aops, Safe_strdup(s));
         }
 
     case AOP_HLREG:
@@ -1292,7 +1306,7 @@ aopGet (asmop * aop, int offset, bool bit16)
         v >>= (offset * 8);
         tsprintf (s, "!immedbyte", (unsigned int) v & 0xff);
         
-        return gc_strdup(s);
+        return traceAlloc(&_G.trace.aops, Safe_strdup(s));
       }
     case AOP_STR:
       aop->coff = offset;
@@ -6206,6 +6220,9 @@ genZ80Code (iCode * lic)
       }
     codeOutFile = fp;
   }
+
+  freeTrace(&_G.lines.trace);
+  freeTrace(&_G.trace.aops);
 }
 
 /*
@@ -6246,7 +6263,7 @@ fetchLitSpecial (asmop * aop, bool negate, bool xor)
   v &= 0xFFFF;
 
   tsprintf (buffer, "!immedword", v);
-  return gc_strdup (buffer);
+  return traceAlloc(&_G.trace.aops, Safe_strdup (buffer));
 }
 
 
index 46d29f9d5a42d5825b486062f48a5f2791aa0747..e18646b211fa94adf5bd0cf261c5e82020f6c174 100644 (file)
@@ -57,7 +57,7 @@ my_system (const char *cmd)
   // try to find the command in predefined path's
   while (ExePathList[i])
     {
-      cmdLine = (char *) Safe_malloc (strlen (ExePathList[i]) + strlen (cmd) + 10);
+      cmdLine = (char *) Safe_alloc (strlen (ExePathList[i]) + strlen (cmd) + 10);
       strcpy (cmdLine, ExePathList[i]);        // the path
 
       strcat (cmdLine, DIR_SEPARATOR_STRING);
@@ -73,7 +73,7 @@ my_system (const char *cmd)
          strcat (cmdLine, cmd + argsStart);
          break;
        }
-      free (cmdLine);
+      Safe_free (cmdLine);
       cmdLine = NULL;
       i++;
     }
@@ -87,7 +87,7 @@ my_system (const char *cmd)
     {
       // command found in predefined path
       e = system (cmdLine);
-      free (cmdLine);
+      Safe_free (cmdLine);
     }
   else
     {
index 22aa198b5c8f3cc779f0fc1fbd9da7ab4c98a9e5..949b1a8537b8f24bbe8aec5f041bff52a003509e 100644 (file)
@@ -36,8 +36,76 @@ functions.
 #include <stdlib.h>
 #include <string.h>
 #include <memory.h>
-
+#include <assert.h>
 #include "newalloc.h"
+#include "sdccconf.h"
+
+#if OPT_ENABLE_LIBGC
+#include <gc/gc.h>
+
+#define MALLOC GC_malloc
+#define REALLOC GC_realloc
+#define FREE   GC_free
+
+#else
+
+#define MALLOC malloc
+#define REALLOC realloc
+#define FREE   free
+
+#endif
+
+#define TRACEMALLOC    0
+
+#if TRACEMALLOC
+enum 
+  {
+    TRACESIZE = 4096
+  };
+
+static int _allocs[TRACESIZE];
+static int _above;
+
+static void
+_dumpTrace(int code, void *parg)
+{
+  int i;
+  for (i = 0; i < TRACESIZE; i++)
+    {
+      if (_allocs[i])
+        {
+          printf("%u %u\n", _allocs[i], i);
+        }
+    }
+  printf("%u above\n", _above);
+}
+
+static void
+_log(int size)
+{
+  static int registered;
+
+  if (registered == 0)
+    {
+      on_exit(_dumpTrace, NULL);
+      registered = 1;
+    }
+  if (size == 12)
+    {
+      _above++;
+    }
+
+  if (size >= TRACESIZE)
+    {
+      _above++;
+    }
+  else
+    {
+      _allocs[size]++;
+    }
+}
+#endif
+
 /*
 -------------------------------------------------------------------------------
 Clear_realloc - Reallocate a memory block and clear any memory added with
@@ -51,7 +119,7 @@ void *Clear_realloc(void *OldPtr,size_t OldSize,size_t NewSize)
 {
 void *NewPtr ;
 
-NewPtr = realloc(OldPtr,NewSize) ;
+NewPtr = REALLOC(OldPtr,NewSize) ;
 
 if (!NewPtr)
   {
@@ -78,7 +146,7 @@ void *Safe_realloc(void *OldPtr,size_t NewSize)
 {
 void *NewPtr ;
 
-NewPtr = realloc(OldPtr,NewSize) ;
+NewPtr = REALLOC(OldPtr,NewSize) ;
 
 if (!NewPtr)
   {
@@ -102,8 +170,11 @@ void *Safe_calloc(size_t Elements,size_t Size)
 {
 void *NewPtr ;
 
-NewPtr = calloc(Elements,Size) ;
-
+NewPtr = MALLOC(Elements*Size) ;
+#if TRACEMALLOC
+ _log(Elements*Size);
+#endif
 if (!NewPtr)
   {
   printf("ERROR - No more memory\n") ;
@@ -111,6 +182,8 @@ if (!NewPtr)
   exit (1);
   }
 
+ memset(NewPtr, 0, Elements*Size);
+
 return NewPtr ;
 }
 /*
@@ -126,7 +199,11 @@ void *Safe_malloc(size_t Size)
 {
 void *NewPtr ;
 
-NewPtr = malloc(Size) ;
+NewPtr = MALLOC(Size) ;
+
+#if TRACEMALLOC
+ _log(Size);
+#endif
 
 if (!NewPtr)
   {
@@ -137,3 +214,58 @@ if (!NewPtr)
 
 return NewPtr ;
 }
+
+void *Safe_alloc(size_t Size)
+{
+  return Safe_calloc(1, Size);
+}
+
+void Safe_free(void *p)
+{
+  FREE(p);
+}
+
+char *Safe_strdup(const char *sz)
+{
+  char *pret;
+  assert(sz);
+
+  pret = Safe_alloc(strlen(sz) +1);
+  strcpy(pret, sz);
+
+  return pret;
+}
+
+void *traceAlloc(allocTrace *ptrace, void *p)
+{
+  assert(ptrace);
+  assert(p);
+
+  /* Also handles where max == 0 */
+  if (ptrace->num == ptrace->max)
+    {
+      /* Add an offset to handle max == 0 */
+      ptrace->max = (ptrace->max+2)*2;
+      ptrace->palloced = Safe_realloc(ptrace->palloced, ptrace->max * sizeof(*ptrace->palloced));
+    }
+  ptrace->palloced[ptrace->num++] = p;
+
+  return p;
+}
+
+void freeTrace(allocTrace *ptrace)
+{
+  int i;
+  assert(ptrace);
+
+  for (i = 0; i < ptrace->num; i++)
+    {
+      Safe_free(ptrace->palloced[i]);
+    }
+  ptrace->num = 0;
+
+  Safe_free(ptrace->palloced);
+  ptrace->palloced = NULL;
+  ptrace->max = 0;
+}
+
index e0fb3309b6dac6bf3a9ca8f7ba7b29c13038bace..9e583c9d591e1980f09257ae8e6c082b9f46015c 100644 (file)
@@ -33,6 +33,13 @@ functions.
 
 #include <memory.h>
 
+typedef struct _allocTrace
+{
+  int num;
+  int max;
+  void **palloced;
+} allocTrace;
+
 /*
 -------------------------------------------------------------------------------
 Clear_realloc - Reallocate a memory block and clear any memory added with
@@ -72,4 +79,25 @@ and checking for out or memory errors.
 
 void *Safe_malloc(size_t Size) ;
 
+/** Replacement for Safe_malloc that also zeros memory.  To make it interchangable.
+ */
+void *Safe_alloc(size_t Size) ;
+
+/** Function to make the replacements complete.
+ */
+void Safe_free(void *p);
+
+/** Creates a copy of a string in a safe way.
+ */
+char *Safe_strdup(const char *sz);
+
+/** Logs the allocated memory 'p' in the given trace for batch freeing
+    later using freeTrace.
+*/
+void *traceAlloc(allocTrace *ptrace, void *p);
+
+/** Frees all the memory logged in the trace and resets the trace.
+ */
+void freeTrace(allocTrace *ptrace);
+
 #endif
index 3efd4693693bbb48266395455b73491bec45c65a..f949d8905ae4133ecc81aac65c8fa2fb4b62cd0d 100644 (file)
@@ -35,7 +35,7 @@ STD_INC               = @sdcc_include_dir@
 CPPFLAGS       = @CPPFLAGS@ -I. -I$(PRJDIR) -I$(SLIB) -D_FORASXXXX_
 CFLAGS         = @CFLAGS@
 M_OR_MM                = @M_OR_MM@
-LDFLAGS                = @LDFLAGS@
+LDFLAGS                = @LDFLAGS@ @LIBS@
 
 SLIBOBJS       = NewAlloc.o