[m-rev.] for review: filter gcc output
Peter Wang
novalazy at gmail.com
Fri Jul 9 14:34:45 AEST 2010
Only if we can't figure out something better.
Branches: main, 10.04
Filter out warning message from gcc 4.x which are emitted when compiling
low-level C code using assembler labels, at least until a better fix is
available.
util/.cvsignore:
util/Mmakefile:
util/mfiltercc.c:
Add a new program, mfiltercc.
compiler/options.m:
Add `--filtercc-command' option (undocumented).
compiler/compile_target_code.m:
Filter gcc output with mfiltercc. Output from other compilers
is not affected.
scripts/mgnuc.in:
Filter gcc output with mfiltercc, but only if mfiltercc can be found
on the $PATH. The bootstrap compiler may not have mfiltercc.
.mercury-compiler.spec.in:
Makefile:
README.MinGW:
bindist/Mmakefile:
bindist/bindist.Makefile.in:
scripts/mercury_config.in:
Mention mfiltercc in various places.
diff --git a/.mercury-compiler.spec.in b/.mercury-compiler.spec.in
index d6e0d6e..193d9a4 100644
--- a/.mercury-compiler.spec.in
+++ b/.mercury-compiler.spec.in
@@ -84,6 +84,7 @@ make install \
/usr/bin/info_to_mdb
/usr/bin/mdb
/usr/bin/mdemangle
+/usr/bin/mfiltercc
/usr/bin/mercury.bat
/usr/bin/mercury_cleanup_install
/usr/bin/mercury_config
diff --git a/Makefile b/Makefile
index 7734c22..e705fb8 100644
--- a/Makefile
+++ b/Makefile
@@ -46,7 +46,7 @@ clean:
-rm -f */*.o */*.pic_o */*.a */*.so */*.dylib
-rm -rf */Mercury/os */Mercury/pic_os */Mercury/libs
-rm -f compiler/mercury_compile profiler/mercury_profile
- -rm -f util/mdemangle util/mkinit
+ -rm -f util/mdemangle util/mfiltercc util/mkinit
cd boehm_gc; $(MMAKE_SUBDIR) clean
.PHONY: distclean
diff --git a/README.MinGW b/README.MinGW
index 9538d33..166714f 100644
--- a/README.MinGW
+++ b/README.MinGW
@@ -86,6 +86,7 @@ To build a compiler which targets MinGW from Cygwin do the following:
mercury_compile.exe (in <prefix>/lib/mercury/bin/<config>)
mercury_profile.exe (in <prefix>/lib/mercury/bin/<config>)
mdemangle.exe (in <prefix>/bin)
+ mfiltercc.exe (in <prefix>/bin)
mkinit.exe (in <prefix>/bin)
-----------------------------------------------------------------------------
diff --git a/bindist/Mmakefile b/bindist/Mmakefile
index 9a7a64d..0902203 100644
--- a/bindist/Mmakefile
+++ b/bindist/Mmakefile
@@ -22,6 +22,7 @@ LIB_FILES = conf doc html inc ints lib mdb/mdb_doc modules reconf
# Miscellaneous scripts and utilities not processed by configure
UTILS = $(INSTALL_PREFIX)/bin/mkinit$(EXT_FOR_EXE) \
$(INSTALL_PREFIX)/bin/mdemangle$(EXT_FOR_EXE) \
+ $(INSTALL_PREFIX)/bin/mfiltercc$(EXT_FOR_EXE) \
$(INSTALL_PREFIX)/bin/mtags \
$(INSTALL_PREFIX)/bin/mprof_merge_runs \
$(INSTALL_PREFIX)/bin/vpath_find
diff --git a/bindist/bindist.Makefile.in b/bindist/bindist.Makefile.in
index fa37097..a24cf61 100644
--- a/bindist/bindist.Makefile.in
+++ b/bindist/bindist.Makefile.in
@@ -41,7 +41,7 @@ EXT_FOR_EXE = @EXT_FOR_EXE@
# machine on which it is being installed.
FULLARCH = @FULLARCH@
-UTIL_PROGS = util/mkinit util/mdemangle
+UTIL_PROGS = util/mkinit util/mdemangle util/mfiltercc
UTIL_PROGFILENAMES = $(UTIL_PROGS:%=%$(EXT_FOR_EXE))
# Any miscellaneous scripts and utilities not processed by configure
diff --git a/compiler/compile_target_code.m b/compiler/compile_target_code.m
index 99c6a6b..c63227b 100644
--- a/compiler/compile_target_code.m
+++ b/compiler/compile_target_code.m
@@ -407,8 +407,9 @@ do_compile_c_file(ErrorStream, PIC, C_File, O_File, Globals, Succeeded, !IO) :-
AllCFlags,
" -c ", C_File, " ",
NameObjectFile, O_File], Command),
- invoke_system_command(Globals, ErrorStream, cmd_verbose_commands,
- Command, Succeeded, !IO).
+ get_maybe_filtercc_command(Globals, MaybeFilterCmd),
+ invoke_system_command_maybe_filter_output(Globals, ErrorStream,
+ cmd_verbose_commands, Command, MaybeFilterCmd, Succeeded, !IO).
:- pred gather_c_compiler_flags(globals::in, pic::in, string::out) is det.
@@ -917,6 +918,23 @@ gather_c_compiler_flags(Globals, PIC, AllCFlags) :-
CFLAGS, " ",
OverrideOpts], AllCFlags).
+:- pred get_maybe_filtercc_command(globals::in, maybe(string)::out) is det.
+
+get_maybe_filtercc_command(Globals, MaybeFilterCmd) :-
+ % Only gcc 4.x compiler output needs filtering at this time, but
+ % Mercury.config.bootstrap doesn't specify the version so we filter output
+ % from all versions of gcc.
+ get_c_compiler_type(Globals, C_CompilerType),
+ (
+ C_CompilerType = cc_gcc(_, _, _),
+ globals.lookup_string_option(Globals, filtercc_command, FilterCmd),
+ FilterCmd \= ""
+ ->
+ MaybeFilterCmd = yes(FilterCmd)
+ ;
+ MaybeFilterCmd = no
+ ).
+
%-----------------------------------------------------------------------------%
compile_java_files(ErrorStream, JavaFiles, Globals, Succeeded, !IO) :-
diff --git a/compiler/options.m b/compiler/options.m
index 48df16e..91699c6 100644
--- a/compiler/options.m
+++ b/compiler/options.m
@@ -878,6 +878,7 @@
; mkinit_command
; mkinit_erl_command
; demangle_command
+ ; filtercc_command
; trace_libs
; thread_libs
; shared_libs
@@ -1727,6 +1728,7 @@ option_defaults_2(link_option, [
mkinit_command - string("mkinit"),
mkinit_erl_command - string("mkinit_erl"),
demangle_command - string("mdemangle"),
+ filtercc_command - string("mfiltercc"),
trace_libs - string(""),
thread_libs - string(""),
shared_libs - string(""),
@@ -2628,6 +2630,7 @@ long_option("ranlib-flags", ranlib_flags).
long_option("mkinit-command", mkinit_command).
long_option("mkinit-erl-command", mkinit_erl_command).
long_option("demangle-command", demangle_command).
+long_option("filtercc-command", filtercc_command).
long_option("trace-libs", trace_libs).
long_option("thread-libs", thread_libs).
long_option("shared-libs", shared_libs).
@@ -5368,7 +5371,8 @@ options_help_link -->
% --create-archive-command, --create-archive-command-flags
% --create-archive-command-output-flag, --ranlib-command,
% --ranlib-flags,
- % --mkinit-command, --demangle-command, --trace-libs,
+ % --mkinit-command, --demangle-command, --filtercc-command,
+ % --trace-libs,
% --thread-libs, --shared-libs, --math-lib, --readline-libs,
% --linker-opt-separator,
% --linker-debug-flags, --shlib-linker-debug-flags,
diff --git a/scripts/mercury_config.in b/scripts/mercury_config.in
index 8aea427..7bd43ef 100644
--- a/scripts/mercury_config.in
+++ b/scripts/mercury_config.in
@@ -212,6 +212,7 @@ cp scripts/Mercury.config $output_libdir/conf || exit 1
cp scripts/Mmake.vars $output_libdir/mmake || exit 1
if [ "$input_prefix" != "$output_prefix" ]; then
cp $input_prefix/bin/mdemangle${exe_ext} \
+ $input_prefix/bin/mfiltercc${exe_ext} \
$input_prefix/bin/mkinit${exe_ext} \
$input_prefix/bin/info_to_mdb${exe_ext} $output_prefix/bin
cp $input_libdir/mmake/Mmake.rules $output_libdir/mmake
diff --git a/scripts/mgnuc.in b/scripts/mgnuc.in
index d26f94d..ae206d4 100644
--- a/scripts/mgnuc.in
+++ b/scripts/mgnuc.in
@@ -638,6 +638,17 @@ else
INVISIBLE_OPTS=""
fi
+FILTERCC=""
+case $COMPILER in gcc)
+ # Check if mfiltercc is available as we may be bootstrapping with
+ # an older compiler which did not have it.
+ if mfiltercc=`which mfiltercc`
+ then
+ FILTERCC=$mfiltercc
+ fi
+ ;;
+esac
+
ALL_CC_OPTS="$MERC_ALL_C_INCL_DIRS\
$ANSI_OPTS\
$CHECK_OPTS\
@@ -679,7 +690,13 @@ ALL_CC_OPTS="$MERC_ALL_C_INCL_DIRS\
case $verbose in true)
echo $CC $ALL_CC_OPTS "$@" $OVERRIDE_OPTS $ALL_LOCAL_C_INCL_DIRS;;
esac
-case $# in
- 0) exec $CC $ALL_CC_OPTS $OVERRIDE_OPTS ;;
- *) exec $CC $ALL_CC_OPTS "$@" $OVERRIDE_OPTS $ALL_LOCAL_C_INCL_DIRS;;
+
+# 3>&- closes fd 3 on both sides of the pipeline
+case $#,$FILTERCC in
+ 0,) exec $CC $ALL_CC_OPTS $OVERRIDE_OPTS ;;
+ 0,*) exec $CC $ALL_CC_OPTS $OVERRIDE_OPTS \
+ 2>&1 >&3 3>&- | $FILTERCC >&2 3>&- ;;
+ *,) exec $CC $ALL_CC_OPTS "$@" $OVERRIDE_OPTS $ALL_LOCAL_C_INCL_DIRS ;;
+ *,*) exec $CC $ALL_CC_OPTS "$@" $OVERRIDE_OPTS $ALL_LOCAL_C_INCL_DIRS \
+ 2>&1 >&3 3>&- | $FILTERCC >&2 3>&- ;;
esac
diff --git a/util/.cvsignore b/util/.cvsignore
index 6171425..35d108f 100644
--- a/util/.cvsignore
+++ b/util/.cvsignore
@@ -1,5 +1,6 @@
mkinit
mkinit_erl
mdemangle
+mfiltercc
info_to_mdb
pad_backslash
diff --git a/util/Mmakefile b/util/Mmakefile
index 8dc8f54..a653806 100644
--- a/util/Mmakefile
+++ b/util/Mmakefile
@@ -19,7 +19,7 @@ CFLAGS = -I$(RUNTIME_DIR) -O0
# we need -I ../runtime for "mercury_std.h", etc.
# the -O0 is to get around a stupid compiler bug in gcc 2.7.2.3 on cyclone
-PROGS=mkinit mkinit_erl mdemangle info_to_mdb
+PROGS=mkinit mkinit_erl mdemangle mfiltercc info_to_mdb
PROGFILENAMES=$(PROGS:%=%$(EXT_FOR_EXE))
SRC=$(PROGS:%=%.c)
diff --git a/util/mfiltercc.c b/util/mfiltercc.c
new file mode 100644
index 0000000..a622126
--- /dev/null
+++ b/util/mfiltercc.c
@@ -0,0 +1,72 @@
+/*
+** vim: ft=c ts=4 sw=4 et
+*/
+/*---------------------------------------------------------------------------*/
+
+/*
+** Copyright (C) 2010 The University of Melbourne.
+** This file may only be copied under the terms of the GNU General
+** Public License - see the file COPYING in the Mercury distribution.
+*/
+
+/*
+** File: mfiltercc.c
+** Author: wangp.
+**
+** This is a last ditch effort to filter out warning messages from the
+** C compiler that we cannot (yet) figure out how to silence in a better way.
+*/
+
+#include <string.h>
+#include <stdio.h>
+
+#define MAX_LINE_LENGTH 1000
+
+static int
+drop_line(const char *line, size_t len);
+
+int
+main(void)
+{
+ char buf[MAX_LINE_LENGTH];
+ size_t len;
+ int c;
+
+ do {
+ len = 0;
+ c = getchar();
+ while (c != EOF) {
+ buf[len++] = c;
+ if (c == '\n' || len >= sizeof(buf) - 1) {
+ break;
+ }
+ c = getchar();
+ }
+
+ if (len > 0) {
+ buf[len] = '\0';
+ if (!drop_line(buf, len)) {
+ printf("%s", buf);
+ }
+ }
+ } while (c != EOF);
+
+ return 0;
+}
+
+static int
+drop_line(const char *line, size_t len)
+{
+ /*
+ ** gcc 4.x produces the message (in English locales):
+ ** foo.c:42: warning: 'a' used but never defined
+ */
+ const char msg[] = " used but never defined\n";
+ const size_t msglen = sizeof(msg) - 1;
+ int skip;
+
+ skip = len - msglen;
+ return (skip > 0) && memcmp(line + skip, msg, msglen) == 0;
+}
+
+/*---------------------------------------------------------------------------*/
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list