[m-dev.] for review: GCC back-end: add Mmake support

Tyson Dowd trd at cs.mu.OZ.AU
Tue Jan 16 14:34:01 AEDT 2001


On 15-Jan-2001, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> Estimated hours taken: 6
> 
> Add Mmake support for `--target asm'.
> 
> Note that we do not yet handle the case where the module
> contains C code automatically; for that case, the compiler
> will generate an extra C file, and the corresponding object
> file must be linked into the final executable or library,
> but we don't do that automatically.  To make it work, the
> user must manually set the MLOBJS variable.
> 
> scripts/mmake.in:
> 	Accept the `--target' option.  If `--target asm' is specified,
> 	pass TARGET_ASM=yes to make.
> 
> scripts/Mmake.vars.in:
> 	If TARGET_ASM=yes, include `--target asm' in $(ALL_GRADEFLAGS).
> 	This is needed since `--target-asm' implies `--high-level-code',
> 	which affects the grade.
> 
> scripts/Mmake.rules:
> 	If TARGET_ASM=yes, define rules for building `.s' and `.pic_s'
> 	files (using the `--target asm' option) and for building `.o'
> 	and `.pic_o' files from `.s' and `.pic_s' files.
> 
> compiler/modules.m:
> 	In the generated `.dep' files, if TARGET_ASM=yes,
> 	define $(<foo>.maybe_cs) to be $(<foo>.ss).
> 	This ensures that we build all the .s files before trying
> 	to build the .o files, thus catching errors sooner,
> 	similar to the way that the existing code builds all the .c
> 	files before trying to build the .o files.


> Workspace: /home/hg/fjh/gcc-cvs/gcc/mercury
> Index: compiler/modules.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
> retrieving revision 1.141
> diff -u -d -r1.141 modules.m
> --- compiler/modules.m	2000/12/09 11:03:05	1.141
> +++ compiler/modules.m	2001/01/15 01:27:43
> @@ -1793,9 +1793,11 @@
>  		),
>  
>  		globals__io_lookup_bool_option(highlevel_code, HighLevelCode),
> -		( { HighLevelCode = yes } ->
> +		globals__io_get_target(CompilationTarget),
> +		( { HighLevelCode = yes, CompilationTarget = c } ->
>  			%
> -			% For --high-level-code, we need to make sure that we
> +			% For --high-level-code with --target c,
> +			% we need to make sure that we
>  			% generate the header files for imported modules
>  			% before compiling the C files, since the generated C
>  			% files #include those header files.

This was beginning to bug me with the IL backend -- whenever a new .d
file was generated it demanded a .h file.  Changing back and forth
between asm_fast.gc and ilc meant that I kept needing to run mmake
depend.  

Perhaps this (the fragment above) would be a suitable change for the
release branch too?

> @@ -2706,7 +2708,8 @@
>  
>  	io__write_string(DepStream, MakeVarName),
>  	io__write_string(DepStream, ".ss = "),
> -	write_compact_dependencies_list(Modules, "", ".s", Basis, DepStream),
> +	write_compact_dependencies_list(Modules, "$(ss_subdir)", ".s",
> +					Basis, DepStream),
>  	io__write_string(DepStream, "\n"),
>  
>  	io__write_string(DepStream, MakeVarName),
> @@ -2882,10 +2885,14 @@
>  	%
>  	module_name_to_file_name(SourceModuleName, "", no, ExeFileName),
>  	io__write_strings(DepStream, [
> -		"ifeq ($(RM_C),:)\n",
> -		MakeVarName, ".maybe_cs=$(", MakeVarName, ".cs)\n",
> +		"ifeq ($(TARGET_ASM),yes)\n",
> +		MakeVarName, ".maybe_cs=$(", MakeVarName, ".ss)\n",
>  		"else\n",
> +		"  ifeq ($(RM_C),:)\n",
> +		MakeVarName, ".maybe_cs=$(", MakeVarName, ".cs)\n",
> +		"  else\n",
>  		MakeVarName, ".maybe_cs=\n",
> +		"  endif\n\n",
>  		"endif\n\n"
>  	]),

.maybe_cs seems to be a misleading name in this case.

I can't think of a better one at the moment, so perhaps just document
it?  I had to re-read the log message to be sure this wasn't a cut and
paste error.

> Index: scripts/mmake.in
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/scripts/mmake.in,v
> retrieving revision 1.30
> diff -u -d -r1.30 mmake.in
> --- scripts/mmake.in	1999/10/11 05:47:12	1.30
> +++ scripts/mmake.in	2001/01/14 13:04:38
> @@ -24,6 +24,11 @@
>  		rather than in the current directory.
>  		(If the current directory already contains a \`Mercury'
>  		subdirectory, then this option is the default.)
> +	--target asm:
> +		Compile directly to assembler, rather than going via C.
> +	--target c:
> +		Compile via C, rather than going directly to assembler.
> +		This is the default.
>  	-s, --save-makefile:
>  		Save the generated makefile to \`Mmake.makefile'.
>  		This is useful for tracking down syntax errors in

--target il doesn't seem to be documented here, but you handle it
below...

> retrieving revision 1.86
> diff -u -d -r1.86 Mmake.rules
> --- scripts/Mmake.rules	2001/01/01 04:04:05	1.86
> +++ scripts/Mmake.rules	2001/01/15 02:06:18
> @@ -168,6 +168,25 @@
>  # duplicated in compiler/modules.m.
>  #
>  
> +ifeq ($(TARGET_ASM),yes)
> +
> +# `--target asm' back-end
> +$(ss_subdir)%.s : %.m
> +	$(MCG) $(ALL_GRADEFLAGS) --target-code-only $(ALL_MCGFLAGS) \
> +		$< > $*.err 2>&1
> +
> +$(ss_subdir)%.pic_s : %.m
> +	$(MCG) $(ALL_GRADEFLAGS) --target-code-only $(ALL_MCGFLAGS) \
> +		--cflags "$(CFLAGS_FOR_PIC)" $< > $*.err 2>&1
> +
> +$(os_subdir)%.$O : $(ss_subdir)%.s
> +	$(AS) $< $(OBJFILE_OPT)$@
> +
> +$(os_subdir)%.pic_o : $(ss_subdir)%.pic_s
> +	$(AS) $< $(OBJFILE_OPT)$@
> +
> +endif
> +
>  # C back-end
>  $(cs_subdir)%.c : %.m
>  	rm -f $(cs_subdir)$*.c
> @@ -175,7 +194,7 @@
>  
>  # Aditi-RL back-end
>  $(rlos_subdir)%.rlo : %.m
> -	rm -f $(rlos_subdir)$*.c
> +	rm -f $(rlos_subdir)$*.rlo
>  	$(MCG) $(ALL_GRADEFLAGS) $(ALL_MCGFLAGS) --aditi-only $< > $*.err 2>&1
>  

You didn't mention this change in your log message.  I seem to remember
that we found this bug together while working on the Mmake support for
.NET.

Apart from this the change looks fine.

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