[m-rev.] diff: fix mlds_to_il to compile the library
Peter Ross
peter.ross at miscrit.be
Tue Jul 10 22:54:51 AEST 2001
Hi,
===================================================================
Estimated hours taken: 4
Branches: main
Allow the new version of mlds_to_il to compile the library.
compiler/hlds_pred.m:
Procedures whose import status is external(interface) are exported.
compiler/mlds.m:
Add a utility predicate, mercury_module_and_package_name_to_mlds,
which allows us to set both the package name and module qualified name.
compiler/mlds_to_il.m:
Merge in the code to set the foreign language attribute correctly.
Update mangle_foreign_code_module so that it places the foreign code
language qualifier in the correct place.
library/io.m:
Move init_state into the interface as pragma export is not yet
implemented on the IL backend.
Index: compiler/hlds_pred.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/hlds_pred.m,v
retrieving revision 1.96
diff -u -r1.96 hlds_pred.m
--- compiler/hlds_pred.m 27 Jun 2001 05:04:07 -0000 1.96
+++ compiler/hlds_pred.m 10 Jul 2001 12:49:08 -0000
@@ -1101,6 +1101,9 @@
;
pred_info_is_pseudo_exported(PredInfo),
hlds_pred__in_in_unification_proc_id(ProcId)
+ ;
+ pred_info_import_status(PredInfo, ImportStatus),
+ ImportStatus = external(interface)
).
pred_info_mark_as_external(PredInfo0, PredInfo) :-
Index: compiler/mlds.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds.m,v
retrieving revision 1.57
diff -u -r1.57 mlds.m
--- compiler/mlds.m 9 Jul 2001 15:55:04 -0000 1.57
+++ compiler/mlds.m 10 Jul 2001 12:49:09 -0000
@@ -329,6 +329,14 @@
% MLDS package in which this module is defined.
:- func mercury_module_name_to_mlds(mercury_module_name) = mlds_module_name.
+% Given the name of a Mercury module, and a package name, return the
+% name of the corresponding MLDS module name in which this module is
+% defined.
+% In this case, the package is specified as the first parameter (c.f.
+% mercury_module_name_to_mlds above).
+:- func mercury_module_and_package_name_to_mlds(mercury_module_name,
+ mercury_module_name) = mlds_module_name.
+
% Given the name of a Mercury module return the fully qualified module
% name. ie For the name System.Object which is defined in the source
% package mscorlib it will return System.Object.
@@ -1463,6 +1471,9 @@
package_name :: prog_data__module_name,
module_name :: prog_data__module_name
).
+
+mercury_module_and_package_name_to_mlds(MLDS_Package, MercuryModule)
+ = name(MLDS_Package, MercuryModule).
mercury_module_name_to_mlds(MercuryModule) = name(MLDS_Package, MLDS_Package) :-
(
Index: compiler/mlds_to_il.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_il.m,v
retrieving revision 1.38
diff -u -r1.38 mlds_to_il.m
--- compiler/mlds_to_il.m 9 Jul 2001 15:55:06 -0000 1.38
+++ compiler/mlds_to_il.m 10 Jul 2001 12:49:11 -0000
@@ -185,8 +185,7 @@
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
-generate_il(MLDS, AssemblyDecls ++ [assembly(IlInfo ^ assembly_name),
- namespace(NamespaceName, ILDecls)], set__init, IO0, IO) :-
+generate_il(MLDS, ILAsm, ForeignLangs, IO0, IO) :-
mlds(MercuryModuleName, _, Imports, Defns)= transform_mlds(MLDS),
ModuleName = mercury_module_name_to_mlds(MercuryModuleName),
@@ -195,16 +194,40 @@
globals__io_lookup_bool_option(highlevel_data, HighLevelData, IO0, IO1),
globals__io_lookup_bool_option(debug_il_asm, DebugIlAsm, IO1, IO),
- IlInfo = il_info_init(ModuleName, AssemblyName, Imports,
+ IlInfo0 = il_info_init(ModuleName, AssemblyName, Imports,
il_data_rep(HighLevelData), DebugIlAsm),
- ILDecls = list__map(mlds_defn_to_ilasm_decl(IlInfo), Defns),
+ list__map_foldl(mlds_defn_to_ilasm_decl, Defns, ILDecls,
+ IlInfo0, IlInfo),
+
+ ForeignLangs = IlInfo ^ file_foreign_langs,
ClassName = mlds_module_name_to_class_name(ModuleName),
ClassName = structured_name(_, NamespaceName),
- generate_extern_assembly(Imports, AssemblyDecls).
-
+ % Make this module an assembly unless it is in the standard
+ % library. Standard library modules all go in the one
+ % assembly in a separate step during the build (using
+ % AL.EXE).
+ (
+ PackageName = mlds_module_name_to_package_name(ModuleName),
+ PackageName = qualified(unqualified("mercury"), _)
+ ->
+ ThisAssembly = [],
+ AssemblerRefs = Imports
+ ;
+ ThisAssembly = [assembly(AssemblyName)],
+ % If not in the library, but we have foreign code,
+ % declare the foreign module as an assembly we
+ % reference
+ list__map(mangle_foreign_code_module(ModuleName),
+ set__to_sorted_list(ForeignLangs),
+ ForeignCodeAssemblerRefs),
+ AssemblerRefs = list__append(ForeignCodeAssemblerRefs, Imports)
+ ),
+ generate_extern_assembly(AssemblerRefs, ExternAssemblies),
+ Namespace = [namespace(NamespaceName, ILDecls)],
+ ILAsm = list__condense([ThisAssembly, ExternAssemblies, Namespace]).
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
@@ -415,21 +438,19 @@
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
-:- func mlds_defn_to_ilasm_decl(il_info, mlds__defn) = ilasm__decl.
+:- pred mlds_defn_to_ilasm_decl(mlds__defn::in, ilasm__decl::out,
+ il_info::in, il_info::out) is det.
-mlds_defn_to_ilasm_decl(_, defn(_Name, _Context, _Flags, data(_Type, _Init)))
- = _ :- sorry(this_file, "top level data definition!").
-mlds_defn_to_ilasm_decl(_, defn(_Name, _Context, _Flags,
- function(_MaybePredProcId, _Params, _MaybeStmts)))
- = _ :- sorry(this_file, "top level function definition!").
-mlds_defn_to_ilasm_decl(Info0, defn(Name, _Context, Flags, class(ClassDefn)))
- = class(
- decl_flags_to_classattrs(Flags),
- EntityName,
- Extends,
- Interfaces,
- MethodDecls
- ) :-
+mlds_defn_to_ilasm_decl(defn(_Name, _Context, _Flags, data(_Type, _Init)),
+ _Decl, Info, Info) :-
+ sorry(this_file, "top level data definition!").
+mlds_defn_to_ilasm_decl(defn(_Name, _Context, _Flags,
+ function(_MaybePredProcId, _Params, _MaybeStmts)),
+ _Decl, Info, Info) :-
+ sorry(this_file, "top level function definition!").
+mlds_defn_to_ilasm_decl(defn(Name, _Context, Flags, class(ClassDefn)),
+ Decl, Info0, Info) :-
+ il_info_new_class(Info0, Info1),
EntityName = entity_name_to_ilds_id(Name),
ClassDefn = class_defn(_Kind, _Imports, Inherits, Implements,
Ctors, Members),
@@ -439,7 +460,7 @@
; Inherits = [Parent0 | Rest],
( Rest = [] ->
Parent = mlds_type_to_ilds_class_name(
- Info0 ^ il_data_rep, Parent0),
+ Info1 ^ il_data_rep, Parent0),
Extends = extends(Parent)
;
error(this_file ++
@@ -450,21 +471,21 @@
Interfaces = implements(
list__map(interface_id_to_class_name, Implements)),
- ClassName = class_name(Info0 ^ module_name, EntityName),
+ ClassName = class_name(Info1 ^ module_name, EntityName),
list__map_foldl(generate_method(ClassName, no), Members,
- MethodsAndFields, Info0, Info1),
+ MethodsAndFields, Info1, Info2),
list__map_foldl(generate_method(ClassName, yes(Parent)), Ctors,
- IlCtors, Info1, Info),
+ IlCtors, Info2, Info3),
MethodsAndFieldsAndCtors = IlCtors ++ MethodsAndFields,
% XXX Maybe it would be better to just check to see
% whether or not there are any init instructions than
% explicitly checking for the name mercury_code.
( EntityName = "mercury_code" ->
- Imports = Info ^ imports,
- InitInstrs = list__condense(tree__flatten(Info ^ init_instrs)),
+ Imports = Info3 ^ imports,
+ InitInstrs = list__condense(tree__flatten(Info3 ^ init_instrs)),
AllocInstrs = list__condense(
- tree__flatten(Info ^ alloc_instrs)),
+ tree__flatten(Info3 ^ alloc_instrs)),
% Generate a field that records whether we have
% finished RTTI initialization.
@@ -474,13 +495,16 @@
% Generate a class constructor.
make_class_constructor_classdecl(AllocDoneFieldRef,
Imports, AllocInstrs, InitInstrs, CCtor,
- Info, _InfoX),
+ Info3, Info),
% The declarations in this class.
MethodDecls = [AllocDoneField, CCtor | MethodsAndFieldsAndCtors]
;
- MethodDecls = MethodsAndFieldsAndCtors
- ).
+ MethodDecls = MethodsAndFieldsAndCtors,
+ Info = Info3
+ ),
+ Decl = class(decl_flags_to_classattrs(Flags), EntityName, Extends,
+ Interfaces, MethodDecls).
class_name(Module, Name) = structured_name(Assembly, ClassName ++ [Name]) :-
ClassName = sym_name_to_list(mlds_module_name_to_sym_name(Module)),
@@ -1254,7 +1278,10 @@
Instrs) -->
il_info_get_module_name(ModuleName),
( no =^ method_foreign_lang ->
+ =(Info),
^ method_foreign_lang := yes(Lang),
+ ^ file_foreign_langs :=
+ set__insert(Info ^ file_foreign_langs, Lang),
{ mangle_foreign_code_module(ModuleName, Lang,
OutlineLangModuleName) },
{ ClassName = mlds_module_name_to_class_name(
@@ -1303,7 +1330,11 @@
il_info_get_module_name(ModuleName),
( no =^ method_foreign_lang ->
% XXX we hardcode managed C++ here
+ =(Info),
^ method_foreign_lang := yes(managed_cplusplus),
+ ^ file_foreign_langs :=
+ set__insert(Info ^ file_foreign_langs,
+ managed_cplusplus),
{ mangle_dataname_module(no, ModuleName, NewModuleName) },
{ ClassName = mlds_module_name_to_class_name(NewModuleName) },
signature(_, RetType, Params) =^ signature,
@@ -2409,22 +2440,47 @@
mangle_foreign_code_module(ModuleName0, Lang, ModuleName) :-
LangStr = globals__simple_foreign_language_string(Lang),
+ PackageName0 = mlds_module_name_to_package_name(ModuleName0),
+ (
+ PackageName0 = qualified(Q, M0),
+ M = string__format("%s__%s_code", [s(M0), s(LangStr)]),
+ PackageName = qualified(Q, M)
+ ;
+ PackageName0 = unqualified(M0),
+ M = string__format("%s__%s_code", [s(M0), s(LangStr)]),
+ PackageName = unqualified(M)
+ ),
SymName0 = mlds_module_name_to_sym_name(ModuleName0),
- ( SymName0 = qualified(SymName1, Name) ->
+ % Check to see whether or not the name has already been
+ % qualified with a mercury_code. If not qualify it.
+ ( SymName0 = qualified(SymName1, "mercury_code") ->
(
- SymName1 = qualified(Q, M0),
- M = string__format("%s__%s_code", [s(M0), s(LangStr)]),
- SymName = qualified(Q, M)
+ SymName1 = qualified(SQ, SM0),
+ SM = string__format("%s__%s_code",
+ [s(SM0), s(LangStr)]),
+ SymName2 = qualified(SQ, SM)
;
- SymName1 = unqualified(M0),
- M = string__format("%s__%s_code", [s(M0), s(LangStr)]),
- SymName = unqualified(M)
+ SymName1 = unqualified(SM0),
+ SM = string__format("%s__%s_code",
+ [s(SM0), s(LangStr)]),
+ SymName2 = unqualified(SM)
),
- ModuleName = mercury_module_name_to_mlds(
- qualified(SymName, Name))
+ SymName = qualified(SymName2, "mercury_code")
;
- error("should never occur.")
- ).
+ (
+ SymName0 = qualified(SQ, SM0),
+ SM = string__format("%s__%s_code",
+ [s(SM0), s(LangStr)]),
+ SymName = qualified(qualified(SQ, SM), "mercury_code")
+ ;
+ SymName0 = unqualified(SM0),
+ SM = string__format("%s__%s_code",
+ [s(SM0), s(LangStr)]),
+ SymName = qualified(unqualified(SM), "mercury_code")
+ )
+ ),
+ ModuleName = mercury_module_and_package_name_to_mlds(
+ PackageName, SymName).
% When generating references to RTTI, we need to mangle the
% module name if the RTTI is defined in C code by hand.
@@ -3109,10 +3165,20 @@
DefaultSignature = signature(call_conv(no, default), void, []),
MethodName = id("").
+:- pred il_info_new_class(il_info::in, il_info::out) is det.
+
+il_info_new_class -->
+ ^ alloc_instrs := empty,
+ ^ init_instrs := empty,
+ ^ classdecls := [],
+ ^ has_main := no,
+ ^ class_foreign_langs := set__init.
+
% reset the il_info for processing a new method
:- pred il_info_new_method(arguments_map, signature, member_name,
il_info, il_info).
:- mode il_info_new_method(in, in, in, in, out) is det.
+
il_info_new_method(ILArgs, ILSignature, MethodName) -->
=(Info),
Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.225
diff -u -r1.225 io.m
--- library/io.m 27 Jun 2001 05:04:38 -0000 1.225
+++ library/io.m 10 Jul 2001 12:49:13 -0000
@@ -2832,8 +2832,14 @@
% miscellaneous predicates
+:- interface.
+
+ % XXX Since on the IL backend pragma export is NYI, this
+ % predicate must be placed in the interface.
:- pred io__init_state(io__state, io__state).
:- mode io__init_state(di, uo) is det.
+
+:- implementation.
% for use by the Mercury runtime
:- pragma export(io__init_state(di, uo), "ML_io_init_state").
--------------------------------------------------------------------------
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