From 5df1b9a579235d42fcec8a8884808334ed99a246 Mon Sep 17 00:00:00 2001 From: michaelh Date: Sat, 6 Oct 2001 23:44:03 +0000 Subject: [PATCH] * 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. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1362 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 26 +++ Makefile.common.in | 2 + as/z80/Makefile | 4 +- configure | 315 ++++++++++++++++++++++------------ configure.in | 11 +- debugger/mcs51/Makefile.in | 4 +- link/z80/Makefile | 4 +- sdccconf_in.h | 2 + sim/ucsim/configure.in | 1 + sim/ucsim/s51.src/Makefile.in | 5 +- src/SDCC.lex | 4 +- src/SDCC.y | 2 +- src/SDCCBBlock.c | 7 +- src/SDCCast.c | 9 +- src/SDCCbitv.c | 123 +++++++++++-- src/SDCCcse.c | 2 +- src/SDCChasht.c | 10 +- src/SDCCicode.c | 8 +- src/SDCCloop.c | 4 +- src/SDCCmain.c | 16 +- src/SDCCmem.c | 2 +- src/SDCCpeeph.c | 134 ++++++++++----- src/SDCCset.c | 9 +- src/SDCCsymt.c | 10 +- src/SDCCutil.c | 2 +- src/SDCCval.c | 10 +- src/common.h | 2 + src/pic/gen.c | 2 - src/pic/pcode.c | 18 -- src/pic/pcodepeep.c | 1 - src/z80/gen.c | 61 ++++--- support/Util/MySystem.c | 6 +- support/Util/NewAlloc.c | 144 +++++++++++++++- support/Util/newalloc.h | 28 +++ support/cpp/Makefile.in | 2 +- 35 files changed, 709 insertions(+), 281 deletions(-) diff --git a/ChangeLog b/ChangeLog index f77ca2e6..33d4fa9a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2001-10-06 Michael Hope + + * 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 * src/SDCCmain.c: distinguish between assembler debug and plain options @@ -56,6 +76,12 @@ * support/regression/ports/mcs51/spec.mk: removed GENERIC * support/regression/ports/z80/spec.mk: removed GENERIC +2001-10-01 Michael Hope + + * support/regression/fwk/lib/testfwk.c (__printf): Removed GENERIC. + + * support/regression/tests/bug-467035.c: Created. + 2001-10-01 * src/SDCC.y: fixed bug #466586 part 1 diff --git a/Makefile.common.in b/Makefile.common.in index 52fa0025..cd240618 100644 --- a/Makefile.common.in +++ b/Makefile.common.in @@ -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. diff --git a/as/z80/Makefile b/as/z80/Makefile index b06bac9c..9ea2069d 100644 --- a/as/z80/Makefile +++ b/as/z80/Makefile @@ -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) diff --git a/configure b/configure index 32081bc0..79be8e7c 100755 --- 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 < 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 < 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 < 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 <&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 < #include @@ -1464,7 +1466,7 @@ else #include 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 @@ -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 @@ -1520,7 +1522,7 @@ if test "$cross_compiling" = yes; then : else cat > conftest.$ac_ext < #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 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 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 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 <&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 +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 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 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 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 < #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 <&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 <&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 < @@ -1945,7 +1987,7 @@ fi rm -f conftest* cat > conftest.$ac_ext < @@ -1961,7 +2003,7 @@ fi rm -f conftest* cat > conftest.$ac_ext < @@ -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 <&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 <&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 <&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 <&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 <&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 <&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 <&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 <&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 < #include @@ -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 <&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 <&6 +fi + + OPT_ENABLE_LIBGC=1 +else + OPT_ENABLE_LIBGC=0 +fi +cat >> confdefs.h <ports mv ports ports.all diff --git a/configure.in b/configure.in index 1f4f1bf9..541e1e54 100755 --- a/configure.in +++ b/configure.in @@ -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 diff --git a/debugger/mcs51/Makefile.in b/debugger/mcs51/Makefile.in index 8c44c9c7..b85db47a 100644 --- a/debugger/mcs51/Makefile.in +++ b/debugger/mcs51/Makefile.in @@ -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 diff --git a/link/z80/Makefile b/link/z80/Makefile index e45d6c38..9a9c80b9 100644 --- a/link/z80/Makefile +++ b/link/z80/Makefile @@ -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) diff --git a/sdccconf_in.h b/sdccconf_in.h index df659b19..8965b21d 100644 --- a/sdccconf_in.h +++ b/sdccconf_in.h @@ -38,6 +38,8 @@ #undef OPT_DISABLE_I186 #undef OPT_DISABLE_TLCS900H +#undef OPT_ENABLE_LIBGC + #endif /* End of config.h */ diff --git a/sim/ucsim/configure.in b/sim/ucsim/configure.in index 3e397711..de2bcba6 100644 --- a/sim/ucsim/configure.in +++ b/sim/ucsim/configure.in @@ -34,6 +34,7 @@ AC_PROG_INSTALL AC_PROG_RANLIB AC_LANG_CPLUSPLUS +AC_CHECK_PROG(STRIP, strip, strip, :) # Checking for header files. # =========================================================================== diff --git a/sim/ucsim/s51.src/Makefile.in b/sim/ucsim/s51.src/Makefile.in index 64e696ca..2588ff2d 100644 --- a/sim/ucsim/s51.src/Makefile.in +++ b/sim/ucsim/s51.src/Makefile.in @@ -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 diff --git a/src/SDCC.lex b/src/SDCC.lex index 8d2dc055..4eddd3ee 100644 --- a/src/SDCC.lex +++ b/src/SDCC.lex @@ -91,7 +91,7 @@ struct options save_options ; "_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; } diff --git a/src/SDCC.y b/src/SDCC.y index 952d3532..d6217c53 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -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; } diff --git a/src/SDCCBBlock.c b/src/SDCCBBlock.c index 2d83d9f3..79126353 100644 --- a/src/SDCCBBlock.c +++ b/src/SDCCBBlock.c @@ -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) { diff --git a/src/SDCCast.c b/src/SDCCast.c index 1300ecba..235ee037 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -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; diff --git a/src/SDCCbitv.c b/src/SDCCbitv.c index c2d5d64f..da8c692a 100644 --- a/src/SDCCbitv.c +++ b/src/SDCCbitv.c @@ -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; } /*-----------------------------------------------------------------*/ diff --git a/src/SDCCcse.c b/src/SDCCcse.c index 1bff79e1..34ab12cd 100644 --- a/src/SDCCcse.c +++ b/src/SDCCcse.c @@ -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; diff --git a/src/SDCChasht.c b/src/SDCChasht.c index 71821860..e33f08cb 100644 --- a/src/SDCChasht.c +++ b/src/SDCChasht.c @@ -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); } } diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 3968b3ea..69c611ef 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -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 */ diff --git a/src/SDCCloop.c b/src/SDCCloop.c index 0be4da81..34bb23d3 100644 --- a/src/SDCCloop.c +++ b/src/SDCCloop.c @@ -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; } diff --git a/src/SDCCmain.c b/src/SDCCmain.c index a0fff7ce..06118067 100644 --- a/src/SDCCmain.c +++ b/src/SDCCmain.c @@ -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 && diff --git a/src/SDCCmem.c b/src/SDCCmem.c index 4692be48..9084d1ec 100644 --- a/src/SDCCmem.c +++ b/src/SDCCmem.c @@ -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); diff --git a/src/SDCCpeeph.c b/src/SDCCpeeph.c index 0a5a8d23..ada11ff9 100644 --- a/src/SDCCpeeph.c +++ b/src/SDCCpeeph.c @@ -24,11 +24,9 @@ -------------------------------------------------------------------------*/ #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); } } diff --git a/src/SDCCset.c b/src/SDCCset.c index f56b6cf4..1746a5a9 100644 --- a/src/SDCCset.c +++ b/src/SDCCset.c @@ -23,11 +23,6 @@ -------------------------------------------------------------------------*/ #include -#if defined(__APPLE__) && defined(__MACH__) -#include -#else -#include -#endif #include "newalloc.h" #include #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; } diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index 217265cd..de4b9d4b 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -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; diff --git a/src/SDCCutil.c b/src/SDCCutil.c index ba665ff1..edbe8e6e 100644 --- a/src/SDCCutil.c +++ b/src/SDCCutil.c @@ -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; } diff --git a/src/SDCCval.c b/src/SDCCval.c index c540a4fe..800f0046 100644 --- a/src/SDCCval.c +++ b/src/SDCCval.c @@ -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; diff --git a/src/common.h b/src/common.h index 5694aa77..0909e7dc 100644 --- a/src/common.h +++ b/src/common.h @@ -32,3 +32,5 @@ #include "asm.h" #include "port.h" + +#include "newalloc.h" diff --git a/src/pic/gen.c b/src/pic/gen.c index 4e8456e4..73f965e2 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -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; diff --git a/src/pic/pcode.c b/src/pic/pcode.c index dd15d09c..062fac95 100644 --- a/src/pic/pcode.c +++ b/src/pic/pcode.c @@ -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 */ diff --git a/src/pic/pcodepeep.c b/src/pic/pcodepeep.c index 2f1fd188..3a8d5265 100644 --- a/src/pic/pcodepeep.c +++ b/src/pic/pcodepeep.c @@ -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); diff --git a/src/z80/gen.c b/src/z80/gen.c index 474d8981..87c9de40 100644 --- a/src/z80/gen.c +++ b/src/z80/gen.c @@ -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)); } diff --git a/support/Util/MySystem.c b/support/Util/MySystem.c index 46d29f9d..e18646b2 100644 --- a/support/Util/MySystem.c +++ b/support/Util/MySystem.c @@ -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 { diff --git a/support/Util/NewAlloc.c b/support/Util/NewAlloc.c index 22aa198b..949b1a85 100644 --- a/support/Util/NewAlloc.c +++ b/support/Util/NewAlloc.c @@ -36,8 +36,76 @@ functions. #include #include #include - +#include #include "newalloc.h" +#include "sdccconf.h" + +#if OPT_ENABLE_LIBGC +#include + +#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; +} + diff --git a/support/Util/newalloc.h b/support/Util/newalloc.h index e0fb3309..9e583c9d 100644 --- a/support/Util/newalloc.h +++ b/support/Util/newalloc.h @@ -33,6 +33,13 @@ functions. #include +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 diff --git a/support/cpp/Makefile.in b/support/cpp/Makefile.in index 3efd4693..f949d890 100644 --- a/support/cpp/Makefile.in +++ b/support/cpp/Makefile.in @@ -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 -- 2.30.2