mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-13 12:53:53 +00:00
When we create augmented compilation units, the item blocks in that
augmented unit come from five sources:
- the original raw compilation unit, containing the source code of a module;
- the interface files of the modules directly imported by that module;
- the interface files of the modules indirectly imported by that module;
- the optimization files needed by that module; and
- the interface files needed by those optimization files.
Change the representation of augmented compilation units so that instead of
containing one list of item blocks, each of which had a general section type,
it now has five lists of item blocks, one for each category above, with
a section type specialized to the category.
After this change, the compiler can process just the item blocks it wants
to process, instead of having to process all the item blocks, all the while
filtering out the irrelevant blocks. This filtering used to be order dependent,
with the ams_transitively_imported section marker, which derived from the old
md_transitively_imported module_defn, marking the dividing line between
the first and second categories on the one hand and the third, fourth and fifth
categories on the other hand. That marker is now gone, and the item blocks
in each category have no need to be in a specific order.
compiler/prog_item.m:
Make the above change in the representation of the augmented compilation
unit.
compiler/module_imports.m:
Instead of recording one list of item blocks for the augmented compilation
unit being built, record five.
compiler/modules.m:
Instead of always adding new item blocks to the one list, add it to the
relevant list. For modules.m, this will be one of the three item block
lists for interface files.
Provide a mechanism for getting back the augmented compilation unit
whole, once its building has finished.
compiler/intermod.m:
compiler/trans_opt.m:
Instead of always adding new item blocks to the one list, add it to the
relevant list. For intermod.m and trans_opt, this will be the item block
list for optimization files.
compiler/status.m:
Change the section types to account for the new kinds of sections
in augmented compilation units (from source, interface and optimization
files respectively).
Besides recording which module the item blocks in interface and
optimization sections came from, record the int_file_kind or opt_file_kind
as well. The compiler does not use this extra information (yet); I am
adding it so that I can look for further invariants.
compiler/file_kind.m:
A new module carved out of prog_item.m, containing the types that define
kinds of source, interface and optimization files, and the predicates that
operate on them. This needs to be a new module, because (a) status.m now
needs access to file kinds, (b) status.m should not import prog_item.m,
since that would lead to circular imports, and (c) the file kinds
don't belong with statuses.
compiler/parse_tree.m:
compiler/notes/compiler_design.html:
Mention the new module.
compiler/equiv_type.m:
Conform to the changes above.
Replace the eqv_type_location type with the maybe_record_sym_name_use type,
since the location (in this module's interface, in this module's
implementation, in some other module) matters only for recording the uses
of sym_names.
compiler/make_hlds_passes.m:
Process all five lists of item blocks in each of the three passes.
Note cases where this may not be needed.
compiler/module_qual.m:
Conform to the changes above. Module qualify only the items in this
module, not the items we got from other modules.
compiler/comp_unit_interface.m:
compiler/deps_map.m:
compiler/hlds_module.m:
compiler/make.module_dep_file.m:
compiler/mercury_compile.m:
compiler/mercury_to_mercury.m:
compiler/split_parse_tree_src.m:
compiler/write_deps_file.m:
compiler/write_module_interface_files.m:
Conform to the changes above.
100 lines
2.9 KiB
Mathematica
100 lines
2.9 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 2015-2011 The Mercury team.
|
|
% This file may only be copied under the terms of the GNU General
|
|
% Public License - see the file COPYING in the Mercury distribution.
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% File: file_kind.m.
|
|
% Main author: zs.
|
|
%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module parse_tree.file_kind.
|
|
:- interface.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% The different kinds of files that the frontend of the Mercury compiler
|
|
% deals with:
|
|
%
|
|
% - source files,
|
|
% - automatically generated interface files, and
|
|
% - automatically generated optimization files.
|
|
%
|
|
|
|
:- type file_kind
|
|
---> fk_src
|
|
; fk_int(int_file_kind)
|
|
; fk_opt(opt_file_kind).
|
|
|
|
:- type int_or_opt_file_kind
|
|
---> iofk_int(int_file_kind)
|
|
; iofk_opt(opt_file_kind).
|
|
|
|
:- type src_file_kind
|
|
---> sfk_src.
|
|
|
|
:- type int_file_kind
|
|
---> ifk_int0
|
|
; ifk_int3
|
|
; ifk_int2
|
|
; ifk_int.
|
|
|
|
:- type opt_file_kind
|
|
---> ofk_opt
|
|
; ofk_trans_opt.
|
|
|
|
:- func file_kind_to_extension(file_kind) = string.
|
|
:- func int_file_kind_to_extension(int_file_kind) = string.
|
|
:- func opt_file_kind_to_extension(opt_file_kind) = string.
|
|
|
|
:- pred extension_to_file_kind(string::in, file_kind::out) is semidet.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
file_kind_to_extension(fk_src) = ".m".
|
|
file_kind_to_extension(fk_int(IntFileKind)) =
|
|
int_file_kind_to_extension(IntFileKind).
|
|
file_kind_to_extension(fk_opt(OptFileKind)) =
|
|
opt_file_kind_to_extension(OptFileKind).
|
|
|
|
int_file_kind_to_extension(ifk_int0) = ".int0".
|
|
int_file_kind_to_extension(ifk_int2) = ".int2".
|
|
int_file_kind_to_extension(ifk_int3) = ".int3".
|
|
int_file_kind_to_extension(ifk_int) = ".int".
|
|
|
|
opt_file_kind_to_extension(ofk_opt) = ".opt".
|
|
opt_file_kind_to_extension(ofk_trans_opt) = ".trans_opt".
|
|
|
|
extension_to_file_kind(Extension, FileKind) :-
|
|
(
|
|
Extension = ".m",
|
|
FileKind = fk_src
|
|
;
|
|
Extension = ".int0",
|
|
FileKind = fk_int(ifk_int0)
|
|
;
|
|
Extension = ".int3",
|
|
FileKind = fk_int(ifk_int3)
|
|
;
|
|
Extension = ".int2",
|
|
FileKind = fk_int(ifk_int2)
|
|
;
|
|
Extension = ".int",
|
|
FileKind = fk_int(ifk_int)
|
|
;
|
|
Extension = ".opt",
|
|
FileKind = fk_opt(ofk_opt)
|
|
;
|
|
Extension = ".trans_opt",
|
|
FileKind = fk_opt(ofk_trans_opt)
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
:- end_module parse_tree.file_kind.
|
|
%-----------------------------------------------------------------------------%
|