[m-dev.] diff: pragma c_code fix

Peter Ross peter.ross at miscrit.be
Thu Nov 9 23:12:08 AEDT 2000


Hi,


===================================================================


Estimated hours taken: 1

mercury/compiler/llds_out.m:
    Output any `pragma c_code' first for the LLDS backend.  This is
    because variables may be defined in a `pragma c_code' and we want
    the definition to appear before any use of the variable.  Also
    output the `pragma c_code' fragments in the same order they appear
    in the source file, as this is the more intuitive behaviour.

tests/hard_coded/Mmakefile:
tests/hard_coded/pragma_c_code_order.exp:
tests/hard_coded/pragma_c_code_order.m:
    A test case for the above.

Index: mercury//compiler/llds_out.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/llds_out.m,v
retrieving revision 1.162
diff -u -r1.162 llds_out.m
--- mercury//compiler/llds_out.m	2000/11/01 05:11:56	1.162
+++ mercury//compiler/llds_out.m	2000/11/09 10:27:31
@@ -491,9 +491,9 @@
 			DeclSet1, DeclSet2),
 		output_comp_gen_c_var_list(Vars, DeclSet2, DeclSet3),
 		output_comp_gen_c_data_list(Datas, DeclSet3, DeclSet4),
+		output_user_foreign_code_list(UserForeignCode),
 		output_comp_gen_c_module_list(Modules, StackLayoutLabels,
 			DeclSet4, _DeclSet),
-		output_user_foreign_code_list(UserForeignCode),
 		output_exported_c_functions(Exports),
 
 		( { SplitFiles = yes(_) } ->
@@ -991,8 +991,10 @@
 
 output_user_foreign_code_list([]) --> [].
 output_user_foreign_code_list([UserForeignCode | UserCCodes]) -->
-	output_user_foreign_code(UserForeignCode),
-	output_user_foreign_code_list(UserCCodes).
+	output_user_foreign_code_list(UserCCodes),
+		% This list is in reverse declared order and we want to
+		% output in the declared order.
+	output_user_foreign_code(UserForeignCode).
 
 :- pred output_user_foreign_code(user_foreign_code::in,
 	io__state::di, io__state::uo) is det.
Index: tests//hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.96
diff -u -r1.96 Mmakefile
--- tests//hard_coded/Mmakefile	2000/10/27 06:42:59	1.96
+++ tests//hard_coded/Mmakefile	2000/11/09 10:26:14
@@ -79,6 +79,7 @@
 	nondet_ctrl_vn \
 	nullary_ho_func \
 	pragma_c_code \
+	pragma_c_code_order \
 	pragma_inline \
 	pragma_import \
 	pragma_export \
Index: tests//hard_coded/pragma_c_code_order.exp
===================================================================
RCS file: pragma_c_code_order.exp
diff -N pragma_c_code_order.exp
--- /dev/null	Sat Aug  7 21:45:41 1999
+++ pragma_c_code_order.exp	Thu Nov  9 21:26:14 2000
@@ -0,0 +1 @@
+30
Index: tests//hard_coded/pragma_c_code_order.m
===================================================================
RCS file: pragma_c_code_order.m
diff -N pragma_c_code_order.m
--- /dev/null	Sat Aug  7 21:45:41 1999
+++ pragma_c_code_order.m	Thu Nov  9 21:26:14 2000
@@ -0,0 +1,33 @@
+% Ensure that the pragma c_code sections are output in the same order
+% they are declared in and that they appear in the generated source file
+% before any variables defined in the c_code can be used.
+:- module pragma_c_code_order.
+
+:- interface.
+
+:- import_module io.
+
+:- pred main(io__state::di, io__state::uo) is det.
+
+:- implementation.
+
+main -->
+	io__write_int(p),
+	io__nl.
+
+:- pragma c_header_code("
+#define INTEGER	10
+").
+
+:- pragma c_code("
+#define INTEGER2 20
+").
+
+:- pragma c_code("
+static int global = INTEGER + INTEGER2;
+").
+
+:- func p = int.
+:- pragma c_code(p = (X::out), "{
+	X = global;
+}").
--------------------------------------------------------------------------
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