[m-dev.] for review: fix nondet pragma c_code bug

Fergus Henderson fjh at cs.mu.OZ.AU
Sun Jan 28 21:14:12 AEDT 2001


This fixes a bug that Tom Conway reported where we were generating
invalid C code for library/table_builtin.m when it was built
with -O6 --intermodule-optimization.

----------

Estimated hours taken: 1

compiler/pragma_c_gen.m:
	Fix a bug in the LLDS back-end where the label names that we
	were generating for `nondet pragma_c' were not unique.

Workspace: /home/hg/fjh/ws-hg3/mercury
Index: compiler/pragma_c_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/pragma_c_gen.m,v
retrieving revision 1.41
diff -u -d -r1.41 pragma_c_gen.m
--- compiler/pragma_c_gen.m	2000/11/28 05:28:59	1.41
+++ compiler/pragma_c_gen.m	2001/01/28 09:32:36
@@ -44,6 +44,7 @@
 :- import_module hlds_module, hlds_pred, llds_out, trace, tree.
 :- import_module code_util.
 :- import_module options, globals.
+
 :- import_module bool, string, int, assoc_list, set, map, require, term.
 
 % The code we generate for an ordinary (model_det or model_semi) pragma_c_code
@@ -571,6 +572,14 @@
 
 make_proc_label_hash_define(ModuleInfo, PredId, ProcId,
 		ProcLabelHashDef, ProcLabelHashUndef) :-
+	ProcLabelHashDef = pragma_c_raw_code(string__append_list([
+		"#define\tMR_PROC_LABEL\t",
+		make_proc_label_string(ModuleInfo, PredId, ProcId), "\n"])),
+	ProcLabelHashUndef = pragma_c_raw_code("#undef\tMR_PROC_LABEL\n").
+
+:- func make_proc_label_string(module_info, pred_id, proc_id) = string.
+
+make_proc_label_string(ModuleInfo, PredId, ProcId) = ProcLabelString :-
 	code_util__make_entry_label(ModuleInfo, PredId, ProcId, no,
 		CodeAddr),
 	( CodeAddr = imported(ProcLabel) ->
@@ -579,10 +588,7 @@
 		llds_out__get_label(ProcLabel, yes, ProcLabelString)
 	;
 		error("unexpected code_addr in make_proc_label_hash_define")
-	),
-	ProcLabelHashDef = pragma_c_raw_code(string__append_list([
-		"#define\tMR_PROC_LABEL\t", ProcLabelString, "\n"])),
-	ProcLabelHashUndef = pragma_c_raw_code("#undef\tMR_PROC_LABEL\n").
+	).
 
 %-----------------------------------------------------------------------------%
 
@@ -617,6 +623,12 @@
 		ProcLabelDefine, ProcLabelUndef) },
 
 	%
+	% Generate a unique prefix for the C labels that we will define
+	%
+	{ ProcLabelString = make_proc_label_string(ModuleInfo,
+		PredId, ProcId) },
+
+	%
 	% Get a list of input and output arguments
 	%
 	code_info__get_pred_proc_arginfo(PredId, ProcId, ArgInfos),
@@ -712,19 +724,27 @@
 	Succeed	 = "\tMR_succeed();\n",
 	SucceedDiscard = "\tMR_succeed_discard();\n",
 
-	CallDef1 = "#define\tSUCCEED     \tgoto MR_call_success\n",
-	CallDef2 = "#define\tSUCCEED_LAST\tgoto MR_call_success_last\n",
+	CallDef1 = "#define\tSUCCEED     \tgoto MR_call_success_"
+		++ ProcLabelString ++ "\n",
+	CallDef2 = "#define\tSUCCEED_LAST\tgoto MR_call_success_last_"
+		++ ProcLabelString ++ "\n",
 	CallDef3 = "#define\tFAIL\tMR_fail()\n",
 
-	CallSuccessLabel     = "MR_call_success:\n",
-	CallLastSuccessLabel = "MR_call_success_last:\n",
+	CallSuccessLabel     = "MR_call_success_"
+		++ ProcLabelString ++ ":\n",
+	CallLastSuccessLabel = "MR_call_success_last_"
+		++ ProcLabelString ++ ":\n",
 
-	RetryDef1 = "#define\tSUCCEED     \tgoto MR_retry_success\n",
-	RetryDef2 = "#define\tSUCCEED_LAST\tgoto MR_retry_success_last\n",
+	RetryDef1 = "#define\tSUCCEED     \tgoto MR_retry_success_"
+		++ ProcLabelString ++ "\n",
+	RetryDef2 = "#define\tSUCCEED_LAST\tgoto MR_retry_success_last_"
+		++ ProcLabelString ++ "\n",
 	RetryDef3 = "#define\tFAIL\tMR_fail()\n",
 
-	RetrySuccessLabel     = "MR_retry_success:\n",
-	RetryLastSuccessLabel = "MR_retry_success_last:\n",
+	RetrySuccessLabel     = "MR_retry_success_"
+		++ ProcLabelString ++ ":\n",
+	RetryLastSuccessLabel = "MR_retry_success_last_"
+		++ ProcLabelString ++ ":\n",
 
 	Undef1 = "#undef\tSUCCEED\n",
 	Undef2 = "#undef\tSUCCEED_LAST\n",
@@ -839,12 +859,16 @@
 				"Start of the shared block"
 		]),
 
-		SharedDef1 = "#define\tSUCCEED     \tgoto MR_shared_success\n",
-		SharedDef2 = "#define\tSUCCEED_LAST\tgoto MR_shared_success_last\n",
+		SharedDef1 = "#define\tSUCCEED     \tgoto MR_shared_success_"
+			++ ProcLabelString ++ "\n",
+		SharedDef2 = "#define\tSUCCEED_LAST\tgoto MR_shared_success_last_"
+			++ ProcLabelString ++ "\n",
 		SharedDef3 = "#define\tFAIL\tMR_fail()\n",
 
-		SharedSuccessLabel     = "MR_shared_success:\n",
-		SharedLastSuccessLabel = "MR_shared_success_last:\n",
+		SharedSuccessLabel     = "MR_shared_success_"
+			++ ProcLabelString ++ ":\n",
+		SharedLastSuccessLabel = "MR_shared_success_last_"
+			++ ProcLabelString ++ ":\n",
 
 		llds_out__get_label(SharedLabel, yes, LabelStr),
 		string__format("\tMR_GOTO_LABEL(%s);\n", [s(LabelStr)],

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