[m-rev.] for review: filter gcc output

Julien Fischer juliensf at csse.unimelb.edu.au
Fri Jul 9 15:38:19 AEST 2010


On Fri, 9 Jul 2010, Peter Wang wrote:

> 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.

You should also filter based on whether asm labels are being used or
not, i.e. we definitely don't need the filtering in, for example, the
hlc grades

> .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/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.

In that case, the C compiler type will just be cc_gcc(no, no, no).

> +    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
> +    ).
> +
> %-----------------------------------------------------------------------------%

...

> @@ -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)

s/void/int argc, char **argv/ since the former may be rejected by
particularly picky compilers (since it's not actually C).

> +{
> +    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;
> +}

The rest loooks fine.

Julien.
--------------------------------------------------------------------------
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