[m-rev.] for review: support initialise declarations in the hl* grades
Julien Fischer
juliensf at cs.mu.OZ.AU
Thu Sep 1 14:21:15 AEST 2005
For review by Ralph. (This is still pending a bootcheck.)
Estimated hours taken: 1.5
Branches: main
Implement initialise declarations for the high-level C backend.
compiler/mlds.m:
Add a slot to the MLDS to hold the name of module intialisation
predicates.
XXX We should use a higher level representation of the names
here in case we need to treat them differently in the other
target languages.
compiler/mlds_to_c.m:
Output the necessary INIT and REQUIRED_INIT comments.
compiler/mercury_compile.m:
compiler/ml_code_gen.m:
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
Handle the extra field in the MLDS.
compiler/mlds_to_il.m:
compiler/mlds_to_ilasm.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
compiler/mlds_to_gcc.m:
Handle the extra field in the MLDS. We don't
yet support initialise declarations on these backends.
Julien.
Index: mercury_compile.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mercury_compile.m,v
retrieving revision 1.342
diff -u -r1.342 mercury_compile.m
--- mercury_compile.m 29 Aug 2005 03:22:20 -0000 1.342
+++ mercury_compile.m 31 Aug 2005 16:14:22 -0000
@@ -1649,7 +1649,7 @@
mercury_compile__mlds_has_main(MLDS) =
(
- MLDS = mlds(_, _, _, Defns),
+ MLDS = mlds(_, _, _, Defns, _),
defns_contain_main(Defns)
->
has_main
@@ -4479,9 +4479,9 @@
list__condense([TypeCtorRtti, TypeClassInfoRtti,
NewTypeClassInfoRttiData, AditiProcInfoRtti], RttiData),
RttiDefns = rtti_data_list_to_mlds(HLDS, RttiData),
- MLDS0 = mlds(ModuleName, ForeignCode, Imports, Defns0),
+ MLDS0 = mlds(ModuleName, ForeignCode, Imports, Defns0, InitPreds),
list__append(RttiDefns, Defns0, Defns),
- MLDS = mlds(ModuleName, ForeignCode, Imports, Defns).
+ MLDS = mlds(ModuleName, ForeignCode, Imports, Defns, InitPreds).
% The `--high-level-C' MLDS output pass
Index: ml_code_gen.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_code_gen.m,v
retrieving revision 1.153
diff -u -r1.153 ml_code_gen.m
--- ml_code_gen.m 30 Aug 2005 04:11:54 -0000 1.153
+++ ml_code_gen.m 31 Aug 2005 15:54:49 -0000
@@ -823,7 +823,8 @@
ml_gen_foreign_code(ModuleInfo, ForeignCode, !IO),
ml_gen_imports(ModuleInfo, Imports),
ml_gen_defns(ModuleInfo, Defns, !IO),
- MLDS = mlds(ModuleName, ForeignCode, Imports, Defns).
+ module_info_user_init_pred_c_names(ModuleInfo, InitPreds),
+ MLDS = mlds(ModuleName, ForeignCode, Imports, Defns, InitPreds).
:- pred ml_gen_foreign_code(module_info::in,
map(foreign_language, mlds__foreign_code)::out,
Index: ml_elim_nested.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_elim_nested.m,v
retrieving revision 1.70
diff -u -r1.70 ml_elim_nested.m
--- ml_elim_nested.m 22 Mar 2005 06:40:09 -0000 1.70
+++ ml_elim_nested.m 31 Aug 2005 15:55:45 -0000
@@ -480,7 +480,7 @@
%
ml_elim_nested(Action, MLDS0, MLDS, !IO) :-
globals__io_get_globals(Globals, !IO),
- MLDS0 = mlds(ModuleName, ForeignCode, Imports, Defns0),
+ MLDS0 = mlds(ModuleName, ForeignCode, Imports, Defns0, InitPreds),
MLDS_ModuleName = mercury_module_name_to_mlds(ModuleName),
OuterVars = [],
DefnsList = list__map(
@@ -494,7 +494,7 @@
% So we need to check for and eliminate any duplicate definitions
% of constants.
Defns = list__remove_dups(Defns1),
- MLDS = mlds(ModuleName, ForeignCode, Imports, Defns).
+ MLDS = mlds(ModuleName, ForeignCode, Imports, Defns, InitPreds).
% Either eliminated nested functions:
% Hoist out any nested function occurring in a single mlds__defn.
Index: ml_optimize.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_optimize.m,v
retrieving revision 1.30
diff -u -r1.30 ml_optimize.m
--- ml_optimize.m 22 Mar 2005 06:40:09 -0000 1.30
+++ ml_optimize.m 31 Aug 2005 15:56:25 -0000
@@ -70,10 +70,10 @@
optimize(MLDS0, MLDS, !IO) :-
globals__io_get_globals(Globals, !IO),
- MLDS0 = mlds(ModuleName, ForeignCode, Imports, Defns0),
+ MLDS0 = mlds(ModuleName, ForeignCode, Imports, Defns0, InitPreds),
Defns = optimize_in_defns(Defns0, Globals,
mercury_module_name_to_mlds(ModuleName)),
- MLDS = mlds(ModuleName, ForeignCode, Imports, Defns).
+ MLDS = mlds(ModuleName, ForeignCode, Imports, Defns, InitPreds).
:- func optimize_in_defns(mlds__defns, globals, mlds_module_name)
= mlds__defns.
Index: ml_tailcall.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/ml_tailcall.m,v
retrieving revision 1.26
diff -u -r1.26 ml_tailcall.m
--- ml_tailcall.m 8 Aug 2005 02:33:10 -0000 1.26
+++ ml_tailcall.m 31 Aug 2005 15:57:27 -0000
@@ -90,9 +90,9 @@
:- import_module string.
ml_mark_tailcalls(MLDS0, MLDS, !IO) :-
- MLDS0 = mlds(ModuleName, ForeignCode, Imports, Defns0),
+ MLDS0 = mlds(ModuleName, ForeignCode, Imports, Defns0, InitPreds),
Defns = mark_tailcalls_in_defns(Defns0),
- MLDS = mlds(ModuleName, ForeignCode, Imports, Defns).
+ MLDS = mlds(ModuleName, ForeignCode, Imports, Defns, InitPreds).
%-----------------------------------------------------------------------------%
@@ -581,7 +581,7 @@
:- pred nontailcall_in_mlds(mlds::in, tailcall_warning::out) is nondet.
nontailcall_in_mlds(MLDS, Warning) :-
- MLDS = mlds(ModuleName, _ForeignCode, _Imports, Defns),
+ MLDS = mlds(ModuleName, _ForeignCode, _Imports, Defns, _InitPreds),
MLDS_ModuleName = mercury_module_name_to_mlds(ModuleName),
nontailcall_in_defns(MLDS_ModuleName, Defns, Warning).
Index: mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.120
diff -u -r1.120 mlds.m
--- mlds.m 24 Mar 2005 13:33:33 -0000 1.120
+++ mlds.m 31 Aug 2005 15:57:59 -0000
@@ -370,7 +370,12 @@
toplevel_imports :: mlds__imports,
% Definitions of code and data
- defns :: mlds__defns
+ defns :: mlds__defns,
+
+ % The names of init preds.
+ % XXX This only works for the C backend, because
+ % pragma export doesn't work for the other backends.
+ init_preds :: list(string)
).
:- func mlds__get_module_name(mlds) = mercury_module_name.
@@ -1755,7 +1760,7 @@
%-----------------------------------------------------------------------------%
-mlds__get_module_name(mlds(ModuleName, _, _, _)) = ModuleName.
+mlds__get_module_name(mlds(ModuleName, _, _, _, _)) = ModuleName.
%-----------------------------------------------------------------------------%
Index: mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.171
diff -u -r1.171 mlds_to_c.m
--- mlds_to_c.m 22 Mar 2005 06:40:11 -0000 1.171
+++ mlds_to_c.m 31 Aug 2005 16:26:56 -0000
@@ -150,7 +150,7 @@
:- pred mlds_output_hdr_file(indent::in, mlds::in, io::di, io::uo) is det.
mlds_output_hdr_file(Indent, MLDS, !IO) :-
- MLDS = mlds(ModuleName, AllForeignCode, Imports, Defns),
+ MLDS = mlds(ModuleName, AllForeignCode, Imports, Defns, _InitPreds),
mlds_output_hdr_start(Indent, ModuleName, !IO),
io__nl(!IO),
mlds_output_hdr_imports(Indent, Imports, !IO),
@@ -255,11 +255,11 @@
io::di, io::uo) is det.
mlds_output_src_file(Indent, MLDS, MaybeRLFile, !IO) :-
- MLDS = mlds(ModuleName, AllForeignCode, Imports, Defns),
+ MLDS = mlds(ModuleName, AllForeignCode, Imports, Defns, InitPreds),
% Get the foreign code for C
ForeignCode = mlds_get_c_foreign_code(AllForeignCode),
- mlds_output_src_start(Indent, ModuleName, ForeignCode, !IO),
+ mlds_output_src_start(Indent, ModuleName, ForeignCode, InitPreds, !IO),
io__nl(!IO),
mlds_output_src_imports(Indent, Imports, !IO),
io__nl(!IO),
@@ -354,9 +354,9 @@
io__write_string("#include ""mercury.h""\n", !IO).
:- pred mlds_output_src_start(indent::in, mercury_module_name::in,
- mlds__foreign_code::in, io::di, io::uo) is det.
+ mlds__foreign_code::in, list(string)::in, io::di, io::uo) is det.
-mlds_output_src_start(Indent, ModuleName, ForeignCode, !IO) :-
+mlds_output_src_start(Indent, ModuleName, ForeignCode, InitPreds, !IO) :-
mlds_output_auto_gen_comment(ModuleName, !IO),
mlds_indent(Indent, !IO),
io__write_string("/* :- module ", !IO),
@@ -366,6 +366,7 @@
io__write_string("/* :- implementation. */\n", !IO),
mlds_output_src_bootstrap_defines(!IO),
io__nl(!IO),
+ mlds_output_init_comment(ModuleName, InitPreds, !IO),
mlds_output_src_import(Indent,
mercury_import(
@@ -385,8 +386,31 @@
mercury_module_name_to_mlds(ModuleName)), !IO)
),
io__nl(!IO).
+
+ % Output a comment to tell mkinit what functions to
+ % call from <module>_init.c.
+ %
+:- pred mlds_output_init_comment(mercury_module_name::in,
+ list(string)::in, io::di, io::uo) is det.
+
+mlds_output_init_comment(ModuleName, UserInitPredCNames, !IO) :-
+ io__write_string("/*\n", !IO),
+ io__write_string("INIT ", !IO),
+ output_init_name(ModuleName, !IO),
+ io__write_string("init\n", !IO),
+ list__foldl(mlds_output_required_user_init_comment,
+ UserInitPredCNames, !IO),
+ io__write_string("ENDINIT\n", !IO),
+ io__write_string("*/\n\n", !IO).
- %
+:- pred mlds_output_required_user_init_comment(string::in, io::di, io::uo)
+ is det.
+
+mlds_output_required_user_init_comment(CName, !IO) :-
+ io__write_string("REQUIRED_INIT ", !IO),
+ io__write_string(CName, !IO),
+ io__nl(!IO).
+
% Output any #defines which are required to bootstrap in the hlc
% grade.
%
Index: mlds_to_gcc.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_gcc.m,v
retrieving revision 1.104
diff -u -r1.104 mlds_to_gcc.m
--- mlds_to_gcc.m 22 Mar 2005 06:40:11 -0000 1.104
+++ mlds_to_gcc.m 31 Aug 2005 16:16:51 -0000
@@ -245,7 +245,9 @@
).
mlds_to_gcc__compile_to_asm(MLDS, MaybeRLFile, ContainsCCode) -->
- { MLDS = mlds(ModuleName, AllForeignCode, Imports, Defns0) },
+ % XXX We need to handle initialise declarations properly here.
+ { MLDS = mlds(ModuleName, AllForeignCode, Imports, Defns0,
+ InitPreds) },
%
% Handle output of any foreign code (C, Ada, Fortran, etc.)
@@ -298,7 +300,7 @@
% them from the asm file!) and pass that to mlds_to_c.m
% to create the .mih file, and if necessary the .c file.
{ ForeignMLDS = mlds(ModuleName, AllForeignCode, Imports,
- list__map(make_public, ForeignDefns)) },
+ list__map(make_public, ForeignDefns), InitPreds) },
mlds_to_c__output_c_file(ForeignMLDS, MaybeRLFile, "")
),
%
Index: mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.148
diff -u -r1.148 mlds_to_il.m
--- mlds_to_il.m 24 Mar 2005 02:00:30 -0000 1.148
+++ mlds_to_il.m 31 Aug 2005 16:11:08 -0000
@@ -272,7 +272,8 @@
generate_il(MLDS, Version, ILAsm, ForeignLangs, !IO) :-
- mlds(MercuryModuleName, ForeignCode, Imports, Defns) =
+ % XXX initialise declarations NYI for IL backend
+ mlds(MercuryModuleName, ForeignCode, Imports, Defns, _) =
transform_mlds(MLDS),
ModuleName = mercury_module_name_to_mlds(MercuryModuleName),
Index: mlds_to_ilasm.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_ilasm.m,v
retrieving revision 1.26
diff -u -r1.26 mlds_to_ilasm.m
--- mlds_to_ilasm.m 22 Mar 2005 06:40:12 -0000 1.26
+++ mlds_to_ilasm.m 31 Aug 2005 16:11:59 -0000
@@ -123,7 +123,7 @@
io::di, io::uo) is det.
output_assembler(MLDS, ForeignLangs, !IO) :-
- MLDS = mlds(ModuleName, _ForeignCode, _Imports, _Defns),
+ MLDS = mlds(ModuleName, _ForeignCode, _Imports, _Defns, _InitPreds),
output_src_start(ModuleName, !IO),
io__nl(!IO),
Index: mlds_to_java.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_java.m,v
retrieving revision 1.66
diff -u -r1.66 mlds_to_java.m
--- mlds_to_java.m 22 Mar 2005 06:40:12 -0000 1.66
+++ mlds_to_java.m 31 Aug 2005 16:12:33 -0000
@@ -417,7 +417,7 @@
%
% Run further transformations on the MLDS.
%
- MLDS = mlds(ModuleName, AllForeignCode, Imports, Defns0),
+ MLDS = mlds(ModuleName, AllForeignCode, Imports, Defns0, _InitPreds),
MLDS_ModuleName = mercury_module_name_to_mlds(ModuleName),
%
% Find and build list of all methods which would have their addresses
Index: mlds_to_managed.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_managed.m,v
retrieving revision 1.19
diff -u -r1.19 mlds_to_managed.m
--- mlds_to_managed.m 23 Mar 2005 00:46:17 -0000 1.19
+++ mlds_to_managed.m 31 Aug 2005 16:13:20 -0000
@@ -72,7 +72,7 @@
:- import_module term.
output_managed_code(Lang, MLDS, !IO) :-
- MLDS = mlds(ModuleName, _ForeignCode, _Imports, _Defns),
+ MLDS = mlds(ModuleName, _ForeignCode, _Imports, _Defns, _InitPred),
output_src_start(ModuleName, !IO),
io__nl(!IO),
generate_code(Lang, MLDS, !IO),
@@ -104,7 +104,7 @@
io::di, io::uo) is det.
generate_code(Lang, MLDS, !IO) :-
- MLDS = mlds(ModuleName, AllForeignCode, Imports, Defns),
+ MLDS = mlds(ModuleName, AllForeignCode, Imports, Defns, _InitPreds),
ClassName = class_name(mercury_module_name_to_mlds(ModuleName),
wrapper_class_name),
io__nl(!IO),
--------------------------------------------------------------------------
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