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

Fergus Henderson fjh at cs.mu.OZ.AU
Mon Jan 15 13:09:41 AEDT 2001


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.

	For --target asm, don't include the dependencies on .h files
	that we normally include for --high-level-code.

compiler/modules.m:
scripts/Mmake.vars.in:
	Define the $(<foo>.ss) variables to reflect the fact that
	the compiler puts the .s files in the Mercury/ss subdirectory
	if --use-subdirs is enabled.  Previously it assumed that
	the .s files always go in the current directory.

scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
scripts/final_grade_options.sh-subr:
	Handle `--target asm'.

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.
@@ -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"
 	]),
 
Index: scripts/final_grade_options.sh-subr
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/final_grade_options.sh-subr,v
retrieving revision 1.5
diff -u -d -r1.5 final_grade_options.sh-subr
--- scripts/final_grade_options.sh-subr	2000/09/06 05:21:25	1.5
+++ scripts/final_grade_options.sh-subr	2001/01/08 18:51:15
@@ -39,9 +39,9 @@
 esac
 
 #
-# IL implies --high-level-code
+# --target asm or IL implies --high-level-code
 #
-case $target in il)
+case $target in asm|il)
 	highlevel_code=true ;;
 esac
 
Index: scripts/init_grade_options.sh-subr
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/init_grade_options.sh-subr,v
retrieving revision 1.12
diff -u -d -r1.12 init_grade_options.sh-subr
--- scripts/init_grade_options.sh-subr	2000/09/06 05:21:26	1.12
+++ scripts/init_grade_options.sh-subr	2001/01/08 18:47:40
@@ -23,7 +23,7 @@
 grade_usage="\
 Grade options:
 	-s <grade>, --grade <grade>
-	--target {il, c}
+	--target {il, c, asm}
 	--il
 	--asm-labels
 	--gcc-non-local-gotos
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
@@ -79,6 +84,7 @@
 	use_subdirs=${MMAKE_USE_SUBDIRS=no}
 fi
 warn_undefined_vars=true
+target_asm=${MMAKE_TARGET_ASM=default}
 
 while [ $# -gt 0 ]; do
 	case "$1" in
@@ -94,6 +100,20 @@
 			use_subdirs=no
 			shift
 			;;
+		--target)
+			case "$2" in
+				asm)	target_asm=yes ;;
+				c|il)	target_asm=no ;;
+				*)	echo "$0: invalid argument to" \
+						"\`--target' option" 1>&2
+					exit 1 ;;
+			esac
+			shift; shift
+			;;
+		--no-use-subdirs)
+			use_subdirs=no
+			shift
+			;;
 		-s|--save-makefile)
 			save_makefile=true
 			MMAKE="$MMAKE $1"
@@ -210,6 +230,12 @@
 	esac
 fi
 
+case $target_asm in
+	yes)		set_target_asm="TARGET_ASM=yes" ;;
+	no)		set_target_asm="TARGET_ASM=no" ;;
+	default)	set_target_asm="" ;;
+esac
+
 MMAKE_MAKE_CMD="${MMAKE_MAKE} -f $tmp -r"
 
 # Enable checking for undefined variables -- but not when making the
@@ -247,7 +273,7 @@
 	echo MERCURY_DEFAULT_GRADE=$MERCURY_DEFAULT_GRADE
 	echo export MERCURY_DEFAULT_GRADE
 	echo cat ${MMAKE_VARS} $dvs $ds $mmake $deps ${MMAKE_RULES} ">>" $tmp
-	echo ${MMAKE_MAKE} ${MMAKE_MAKE_OPTS} -f $tmp -r "$@"
+	echo ${MMAKE_MAKE} ${MMAKE_MAKE_OPTS} -f $tmp -r ${set_target_asm} "$@"
 fi
 export MMAKE
 export MMAKE_MAKE_CMD
@@ -258,6 +284,6 @@
 case $# in
 	# Note that we can't use `exec' here, because if we did that,
 	# that `trap' code which removes $tmp would never get executed.
-	0) ${MMAKE_MAKE} ${MMAKE_MAKE_OPTS} -f $tmp -r ;;
-	*) ${MMAKE_MAKE} ${MMAKE_MAKE_OPTS} -f $tmp -r "$@" ;;
+	0) ${MMAKE_MAKE} ${MMAKE_MAKE_OPTS} -f $tmp -r ${set_target_asm} ;;
+	*) ${MMAKE_MAKE} ${MMAKE_MAKE_OPTS} -f $tmp -r ${set_target_asm} "$@" ;;
 esac
Index: scripts/Mmake.rules
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/Mmake.rules,v
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
 
 # .NET back-end
Index: scripts/Mmake.vars.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/Mmake.vars.in,v
retrieving revision 1.38
diff -u -d -r1.38 Mmake.vars.in
--- scripts/Mmake.vars.in	2001/01/01 04:04:05	1.38
+++ scripts/Mmake.vars.in	2001/01/15 02:08:01
@@ -47,7 +47,17 @@
 GRADE		= $(DEFAULT_GRADE)
 GRADESTRING	= $(shell $(MCOGS) $(ALL_GRADEFLAGS))
 
-ALL_GRADEFLAGS  = $(GRADEFLAGS) $(EXTRA_GRADEFLAGS) $(TARGET_GRADEFLAGS)
+# This may be overridden on the command line
+TARGET_ASM	= no
+
+ifeq ($(TARGET_ASM),yes)
+ASM_OPT  = --target asm
+else
+ASM_OPT  =
+endif
+
+ALL_GRADEFLAGS  = $(USUAL_GRADEFLAGS) $(ASM_OPT)
+USUAL_GRADEFLAGS = $(GRADEFLAGS) $(EXTRA_GRADEFLAGS) $(TARGET_GRADEFLAGS)
 GRADEFLAGS	= --grade $(GRADE)
 EXTRA_GRADEFLAGS =
 
@@ -404,6 +414,7 @@
 optdates_subdir=$(SUBDIR)optdates/
 trans_opt_dates_subdir=$(SUBDIR)trans_opt_dates/
 cs_subdir=$(SUBDIR)cs/
+ss_subdir=$(SUBDIR)cs/
 os_subdir=$(SUBDIR)os/
 rlos_subdir=$(SUBDIR)rlos/
 ils_subdir=$(SUBDIR)ils/
@@ -429,6 +440,7 @@
 optdates_subdir=
 trans_opt_dates_subdir=
 cs_subdir=
+ss_subdir=
 os_subdir=
 rlos_subdir=
 ils_subdir=
Index: scripts/parse_grade_options.sh-subr
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/parse_grade_options.sh-subr,v
retrieving revision 1.17
diff -u -d -r1.17 parse_grade_options.sh-subr
--- scripts/parse_grade_options.sh-subr	2000/09/06 05:21:26	1.17
+++ scripts/parse_grade_options.sh-subr	2001/01/08 18:49:39
@@ -22,6 +22,8 @@
 	--target)
 		shift
 		case "$1" in
+			asm)
+				target=asm ;;
 			c|C)
 				target=c ;;
 			il|IL)
@@ -33,7 +35,7 @@
 		esac
 		;;
 
-	--il|--IL)
+	--il|--IL|--il-only|--IL-only)
 		target=il ;;
 
 	--high-level-code|-H)
@@ -207,7 +209,6 @@
 					highlevel_data=false
 					;;
 				hl)
-					target=c
 					asm_labels=false
 					non_local_gotos=false
 					global_regs=false
@@ -216,7 +217,6 @@
 					highlevel_data=true
 					;;
 				hlc)
-					target=c
 					asm_labels=false
 					non_local_gotos=false
 					global_regs=false
@@ -225,7 +225,6 @@
 					highlevel_data=false
 					;;
 				hl_nest)
-					target=c
 					asm_labels=false
 					non_local_gotos=false
 					global_regs=false
@@ -234,7 +233,6 @@
 					highlevel_data=true
 					;;
 				hlc_nest)
-					target=c
 					asm_labels=false
 					non_local_gotos=false
 					global_regs=false
-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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