[m-rev.] for review: fix compiler exit status handling

Simon Taylor stayl at cs.mu.OZ.AU
Sat Jun 22 03:06:25 AEST 2002


Estimated hours taken: 0.5
Branches: main

Clean up the handling of the exit status in the compiler.
This doesn't fix any known bugs, but may prevent new ones.

compiler/passes_aux.m:
	Don't set the exit status to 1 if a system command fails. That
	should be done by a caller if the failed command means that the
	compilation as a whole fails.

	Add a predicate maybe_set_exit_status to set the exit status
	to 1 if the boolean argument representing the success or failure
	of a command is `no'.
	
compiler/compile_target_code.m:
	Don't set the exit status if a compilation fails -- leave
	that the mercury_compile.m.

compiler/mercury_compile.m:
	Call maybe_set_exit_status to check the result of target
	code compilations.

Index: compile_target_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.14
diff -u -u -r1.14 compile_target_code.m
--- compile_target_code.m	21 Jun 2002 17:04:45 -0000	1.14
+++ compile_target_code.m	21 Jun 2002 17:04:49 -0000
@@ -688,7 +688,6 @@
 		io__nl(ErrorStream),
 		io__write_string(ErrorStream, io__error_message(Error)),
 		io__nl(ErrorStream),
-		io__set_exit_status(1),
 		{ Succeeded = no }
 	)
     ).
@@ -1065,8 +1064,7 @@
 		io__write_string(ProgName),
 		io__write_string(": can't open `"),
 		io__write_string(NumChunksFileName),
-		io__write_string("' for output\n"),
-		io__set_exit_status(1)
+		io__write_string("' for output\n")
 	).
 
 read_num_split_c_files(ModuleName, MaybeNumChunks) -->
Index: mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.255
diff -u -u -r1.255 mercury_compile.m
--- mercury_compile.m	21 Jun 2002 17:04:45 -0000	1.255
+++ mercury_compile.m	21 Jun 2002 17:04:49 -0000
@@ -222,7 +222,8 @@
 		( { ExitStatus = 0 } ->
 			( { Link = yes } ->
 				compile_target_code__link_module_list(
-					ModulesToLink, _Succeeded)
+					ModulesToLink, Succeeded),
+				maybe_set_exit_status(Succeeded)
 			;
 				[]
 			)
@@ -383,7 +384,8 @@
 		( { Result = ok, TargetCodeOnly = no } ->
 			io__output_stream(OutputStream),
 			compile_target_code__assemble(OutputStream,
-				non_pic, ModuleName, _AssembleOK)
+				non_pic, ModuleName, AssembleOK),
+			maybe_set_exit_status(AssembleOK)
 		;
 			[]
 		)
@@ -1146,7 +1148,8 @@
 				mercury_compile__mlds_to_il_assembler(MLDS),
 				io__output_stream(OutputStream),
 				compile_target_code__il_assemble(OutputStream,
-					ModuleName, HasMain, _Succeeded)
+					ModuleName, HasMain, Succeeded),
+				maybe_set_exit_status(Succeeded)
 			)
 		    ; { Target = java } ->
 			{ HLDS = HLDS50 },
@@ -1157,7 +1160,8 @@
 			;
 				io__output_stream(OutputStream),
 				compile_target_code__compile_java_file(
-					OutputStream, ModuleName, _Succeeded)
+					OutputStream, ModuleName, Succeeded),
+				maybe_set_exit_status(Succeeded)
 			)
 		    ; { Target = asm } ->
 		    	% compile directly to assembler using the gcc back-end
@@ -1192,7 +1196,8 @@
 					compile_target_code__compile_c_file(
 						OutputStream, non_pic,
 						CCode_C_File, CCode_O_File,
-						_CompileOK),
+						CompileOK),
+					maybe_set_exit_status(CompileOK),
 					% add this object file to the list
 					% of extra object files to link in
 					globals__io_lookup_accumulating_option(
@@ -1220,7 +1225,8 @@
 				io__output_stream(OutputStream),
 				compile_target_code__compile_c_file(
 					OutputStream, non_pic, C_File, O_File,
-					_CompileOK)
+					CompileOK),
+				maybe_set_exit_status(CompileOK)
 			)
 		    ;
 			mercury_compile__backend_pass(HLDS50, HLDS,
@@ -3259,6 +3265,7 @@
 		io__output_stream(OutputStream),
 		mercury_compile__c_to_obj(OutputStream,
 			ModuleName, NumChunks, CompileOK),
+		maybe_set_exit_status(CompileOK),
 		{ bool__not(CompileOK, CompileErrors) }
 	;
 		{ CompileErrors = no }
Index: passes_aux.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/passes_aux.m,v
retrieving revision 1.47
diff -u -u -r1.47 passes_aux.m
--- passes_aux.m	21 Jun 2002 17:04:47 -0000	1.47
+++ passes_aux.m	21 Jun 2002 17:04:49 -0000
@@ -207,6 +207,9 @@
 	% environment.
 :- pred make_command_string(string::in, quote_char::in, string::out) is det.
 
+	% If the bool is `no' set the exit status to 1.
+:- pred maybe_set_exit_status(bool::in, io__state::di, io__state::uo) is det.
+
 %-----------------------------------------------------------------------------%
 
 :- implementation.
@@ -450,6 +453,9 @@
 		State9 = State2
 	).
 
+maybe_set_exit_status(yes) --> [].
+maybe_set_exit_status(no) --> io__set_exit_status(1).
+
 invoke_shell_command(ErrorStream, Verbosity, Command0, Succeeded) -->
 	{ make_command_string(Command0, forward, Command) },
 	invoke_system_command(ErrorStream, Verbosity, Command, Succeeded).
@@ -488,7 +494,6 @@
 		( { Status = 0 } ->
 			{ Succeeded = yes }
 		;
-			io__set_exit_status(1),
 			% The command should have produced output
 			% describing the error.
 			{ Succeeded = no }
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list