[m-dev.] for review: GCC back-end: integrate with mmc

Tyson Dowd trd at cs.mu.OZ.AU
Tue Jan 16 11:59:03 AEDT 2001


On 14-Jan-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> Estimated hours taken: 12
> 
> Allow the GCC back-end and the Mercury compiler to be linked with the
> Mercury compiler (rather than the GCC back-end) defining main().
> This makes it a lot easier to integrate the GCC back-end interface
> with the rest of the Mercury implementation.
> 
> Also add support to configure for determining the location of the GCC
> source code and whether or not to enable the GCC back-end interface.
> 
> mercury/configure.in:
> 	Add option `--enable-gcc-back-end'.  Check for the gcc source
> 	code, and if it is found, enable this option by default.
> 
> mercury/Mmake.common.in:
> 	Add ENABLE_GCC_BACK_END and GCC_SRC_DIR variables.
> 
> mercury/compiler/Mmakefile:
> 	Link in the GCC back-end if ENABLE_GCC_BACK_END is set.
> 	Add code to preprocess `#if ENABLE_GCC_BACK_END ... #else
> 	... #endif' in maybe_mlds_to_gcc.pp.
> 
> mercury/compiler/maybe_mlds_to_gcc.pp:
> 	New file.  This is just a wrapper that calls mlds_to_gcc.m
> 	if the GCC back-end interface is enabled, or reports
> 	an error message, if it is not.
> 
> mercury/compiler/mercury_compile.m:
> 	If `--target asm' is enabled, call maybe_mlds_to_gcc;
> 	then invoke the assembler, and if there is any foreign code,
> 	also invoke the C compiler.
> 
> mercury/compiler/mlds_to_gcc.m:
> 	Add code to handle the case when main() is defined in Mercury
> 	rather than in GCC.  For that case, we save the MLDS in a
> 	global variable, invoke the GCC back-end, and then when it
> 	calls us back we pick up the MLDS from the global variable and
> 	do as we did before (i.e. convert the MLDS to GCC trees, etc.)
> 
> gcc/mercury/mercury-gcc.c:
> 	If we're being invoked with main() defined in Mercury,
> 	then change yyparse() so that it calls back to
> 	MC_continue_frontend() rather than mercury_main().
> 
> gcc/toplev.c:
> 	Rename main() as toplev_main().
> 
> gcc/main.c:
> 	New file.  Defines main() which calls toplev_main().
> 
> gcc/Makefile.in:
> 	Move toplev.o from $(BACKEND) to $(OBJS), and add main.o to $(BACKEND).
> 	This ensures that main() gets linked in with cc1, cc1plus, etc.,
> 	but does not get put in libbackend.a.
> 
> gcc/mercury/Make-lang.in:
> 	Add new target `mercury_back_end_libs', which is a text file
> 	that contains the list of libraries that we need to link with
> 	to resolve symbols in the GCC back-end.
> 	Also use $(BACKEND) rather than hand-coding things.
> 


> Index: mercury/compiler/mlds_to_gcc.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_gcc.m,v
> retrieving revision 1.17
> diff -u -d -r1.17 mlds_to_gcc.m
> --- mercury/compiler/mlds_to_gcc.m	2001/01/11 13:37:58	1.17
> +++ mercury/compiler/mlds_to_gcc.m	2001/01/13 18:21:02
> @@ -9,9 +9,12 @@
>  
>  % Note that this does *not* compile to GNU C -- instead it
>  % actually generates GCC's internal "Tree" representation,
> +% and then invokes the GCC back-end to compile it to assembler,
>  % without going via an external file.
> +% Code using the C interface, however, does get compiled to C;
> +% this module invokes mlds_to_c.m to do that.

This could be a bit more informative -- "Code using the C interface"
could mean anything from the user_target_code to the entire program.
Also, documenting *how* it gets compiled to C would be good (in other
words, that you generate calls to such C code and that it gets put into
a separate __c_code module).

> @@ -129,6 +327,8 @@
>  		{ ForeignMLDS = mlds(ModuleName, ForeignCode, Imports,
>  			ForeignDefns) },
>  		mlds_to_c__output_mlds(ForeignMLDS),
> +		% XXX currently the only foreign code we handle is C
> +		{ ContainsCCode = yes },
>  		{ NeedInitFn = no }
>  	),

Although it is NYI, this shoulden't be a problem.  mlds_to_c only
handles C code, and it checks for C code before it generates code.
foreign.m will turn any other code into a separate module (that will be
processed using some other translator) and replace it with C code.

> Index: gcc/mercury/mercury-gcc.c
> ===================================================================
> RCS file: /home/mercury1/repository/gcc/mercury/mercury-gcc.c,v
> retrieving revision 1.20
> diff -u -d -r1.20 mercury-gcc.c
> --- gcc/mercury/mercury-gcc.c	2001/01/08 03:02:52	1.20
> +++ gcc/mercury/mercury-gcc.c	2001/01/13 18:04:26

> @@ -651,8 +675,8 @@
>     for each function, which in turn will call rest_of_compilation(),
>     which invokes the remaining stages of the GCC back-end.  */
>  
> -int
> -yyparse (void)
> +static int
> +merc_call_mercury_compiler ()
>  {
>    const char *base_argv[] = {
>      "--target", "asm", "--target-code-only"
> @@ -700,9 +724,8 @@
>    free (argv);
>  
>    /* XXX We should set errorcount properly, but currently we don't.  */
> -  if (result != 0 && errorcount == 0) {
> -  	errorcount++;
> -  }
> +  if (result != 0 && errorcount == 0)
> +    errorcount++;
>  
>    return result;
>  }

I hate the convention without the braces.  Is that a gcc source code
convention?

Otherwise it seems OK, but I still have to review the missing files.

-- 
       Tyson Dowd           # 
                            #  Surreal humour isn't everyone's cup of fur.
     trd at cs.mu.oz.au        # 
http://www.cs.mu.oz.au/~trd #
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list