mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-16 14:25:56 +00:00
Estimated hours taken: 16 Branches: main The file modules.m contains lots of different kinds of functionality. While much of it belongs together, much of it does not. This diff moves most of the functionality that does not belong with the rest to several new modules: libs.file_util parse_tree.deps_map parse_tree.file_names parse_tree.module_cmds parse_tree.module_imports parse_tree.read_module parse_tree.write_deps_file To make them coherent, move some predicates from hlds.passes_aux, parse_tree.prog_io and parse_tree.prog_out to the new modules, making them more accessible, reducing the required access from the hlds package to parse_tree, or from the parse_tree package to libs. In the same spirit, this diff also moves some simple predicates and functions dealing with sym_names from prog_util.m to mdbcomp/prim_data.m. This allows several modules to avoid depending on parse_tree.prog_util. Rename some of the moved predicates and function symbols where this avoids ambiguity. (There were several that differed from other predicates or function symbols only in arity.) Replace several uses of bools with purpose-specific types. This makes some of the code significantly easier to read. This diff moves modules.m from being by far the largest module, to being only the seventh largest, from 8900+ lines to just 4200+. It also reduces the number of modules that import parse_tree.modules considerably; most modules that imported it now import only one or two of the new modules instead. Despite the size of the diff, there should be no algorithmic changes. compiler/modules.m: compiler/passes_aux.m: compiler/prog_io.m: compiler/prog_out.m: Delete the moved functionality. compiler/file_util.m: New module in the libs package. Its predicates search for files and do simple error or progress reporting. compiler/file_names.m: New module in the parse_tree package. It contains predicates for converting module names to file names. compiler/module_cmds.m: New module in the parse_tree package. Its predicates handle the commands for manipulating interface files of various kinds. compiler/module_import.m: New module in the parse_tree package. It contains the module_imports type and its access predicates, and the predicates that compute various sorts of direct dependencies (those caused by imports) between modules. compiler/deps_map.m: New module in the parse_tree package. It contains the data structure for recording indirect dependencies between modules, and the predicates for creating it. compiler/read_module.m: New module in the parse_tree package. Its job is reading in modules, both human-written and machine-written (such as interface and optimization files). compiler/write_deps_file.m: New module in the parse_tree package. Its job is writing out makefile fragments. compiler/libs.m: compiler/parse_tree.m: Include the new modules. compiler/notes/compiler_design.m: Document the new modules. mdbcomp/prim_data.m: compiler/prog_util.m: Move the predicates that operate on nothing but sym_names from prog_util to prim_data. Move get_ancestors from modules to prim_data. compiler/prog_item.m: Move stuff that looks for foreign code in a list of items here from modules.m. compiler/source_file_map.m: Note why this module needs to be in the parse_tree package. compiler/add_pred.m: compiler/add_special_pred.m: compiler/analysis.file.m: compiler/analysis.m: compiler/assertion.m: compiler/check_typeclass.m: compiler/compile_target_code.m: compiler/cse_detection.m: compiler/det_analysis.m: compiler/elds_to_erlang.m: compiler/exception_analysis.m: compiler/export.m: compiler/fact_table.m: compiler/higher_order.m: compiler/hlds_module.m: compiler/hlds_pred.m: compiler/intermod.m: compiler/llds_out.m: compiler/make.dependencies.m: compiler/make.m: compiler/make.module_dep_file.m: compiler/make.module_target.m: compiler/make.program_target.m: compiler/make.util.m: compiler/make_hlds_passes.m: compiler/maybe_mlds_to_gcc.pp: compiler/mercury_compile.m: compiler/mlds.m: compiler/mlds_to_c.m: compiler/mlds_to_gcc.m: compiler/mlds_to_ilasm.m: compiler/mlds_to_java.m: compiler/mmc_analysis.m: compiler/mode_constraints.m: compiler/mode_debug.m: compiler/modes.m: compiler/module_qual.m: compiler/optimize.m: compiler/passes_aux.m: compiler/proc_gen.m: compiler/prog_foreign.m: compiler/prog_io.m: compiler/prog_io_util.m: compiler/prog_mutable.m: compiler/prog_out.m: compiler/pseudo_type_info.m: compiler/purity.m: compiler/recompilation.check.m: compiler/recompilation.usage.m: compiler/simplify.m: compiler/structure_reuse.analysis.m: compiler/structure_reuse.direct.detect_garbage.m: compiler/structure_reuse.direct.m: compiler/structure_sharing.analysis.m: compiler/tabling_analysis.m: compiler/term_constr_main.m: compiler/termination.m: compiler/trailing_analysis.m: compiler/trans_opt.m: compiler/type_util.m: compiler/typecheck.m: compiler/typecheck_info.m: compiler/unify_proc.m: compiler/unused_args.m: compiler/unused_imports.m: compiler/xml_documentation.m: Minor changes to conform to the changes above.
166 lines
5.9 KiB
Mathematica
166 lines
5.9 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 2003-2006, 2008 The University of Melbourne.
|
|
% This file may only be copied under the terms of the GNU General
|
|
% Public License - see the file COPYING in the Mercury distribution.
|
|
%-----------------------------------------------------------------------------%
|
|
%
|
|
% File: mmc_analysis.m.
|
|
% Main author: stayl.
|
|
%
|
|
% Specify Mercury compiler analyses to be used with the inter-module analysis
|
|
% framework.
|
|
%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module transform_hlds.mmc_analysis.
|
|
:- interface.
|
|
|
|
:- import_module analysis.
|
|
:- import_module hlds.hlds_module.
|
|
:- import_module hlds.hlds_pred.
|
|
:- import_module mdbcomp.prim_data.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- type mmc
|
|
---> mmc.
|
|
|
|
:- instance compiler(mmc).
|
|
|
|
:- pred module_name_func_id(module_info::in, pred_proc_id::in,
|
|
module_name::out, func_id::out) is det.
|
|
|
|
:- pred module_name_func_id_from_pred_info(pred_info::in, proc_id::in,
|
|
module_name::out, func_id::out) is det.
|
|
|
|
:- pred func_id_to_ppid(module_info::in, module_name::in,
|
|
func_id::in, pred_proc_id::out) is det.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module hlds.pred_table.
|
|
:- import_module libs.compiler_util.
|
|
:- import_module libs.file_util.
|
|
:- import_module libs.globals.
|
|
:- import_module libs.options.
|
|
:- import_module parse_tree.file_names.
|
|
:- import_module parse_tree.prog_data.
|
|
:- import_module parse_tree.prog_io.
|
|
:- import_module transform_hlds.ctgc.
|
|
:- import_module transform_hlds.ctgc.structure_sharing.
|
|
:- import_module transform_hlds.ctgc.structure_sharing.analysis.
|
|
:- import_module transform_hlds.ctgc.structure_reuse.
|
|
:- import_module transform_hlds.ctgc.structure_reuse.analysis.
|
|
:- import_module transform_hlds.exception_analysis.
|
|
:- import_module transform_hlds.tabling_analysis.
|
|
:- import_module transform_hlds.trailing_analysis.
|
|
:- import_module transform_hlds.unused_args.
|
|
|
|
:- import_module bool.
|
|
:- import_module list.
|
|
:- import_module maybe.
|
|
:- import_module string.
|
|
:- import_module io.
|
|
:- import_module unit.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- instance compiler(mmc) where [
|
|
compiler_name(mmc) = "mmc",
|
|
|
|
analyses(mmc, "mm_tabling_analysis") =
|
|
'new analysis_type'(
|
|
unit1 : unit(any_call),
|
|
unit1 : unit(mm_tabling_analysis_answer)),
|
|
|
|
analyses(mmc, "trail_usage") =
|
|
'new analysis_type'(
|
|
unit1 : unit(any_call),
|
|
unit1 : unit(trailing_analysis_answer)),
|
|
|
|
analyses(mmc, "exception_analysis") =
|
|
'new analysis_type'(
|
|
unit1 : unit(any_call),
|
|
unit1 : unit(exception_analysis_answer)),
|
|
|
|
analyses(mmc, "unused_args") =
|
|
'new analysis_type'(
|
|
unit1 : unit(unused_args_call),
|
|
unit1 : unit(unused_args_answer)),
|
|
|
|
analyses(mmc, "structure_sharing") =
|
|
'new analysis_type'(
|
|
unit1 : unit(structure_sharing_call),
|
|
unit1 : unit(structure_sharing_answer)),
|
|
|
|
analyses(mmc, "structure_reuse") =
|
|
'new analysis_type'(
|
|
unit1 : unit(structure_reuse_call),
|
|
unit1 : unit(structure_reuse_answer)),
|
|
|
|
module_name_to_read_file_name(mmc, ModuleName, Ext, FileName, !IO) :-
|
|
mmc_module_name_to_read_file_name(ModuleName, Ext, FileName, !IO),
|
|
|
|
module_name_to_write_file_name(mmc, ModuleName, Ext, FileName, !IO) :-
|
|
mmc_module_name_to_write_file_name(ModuleName, Ext, FileName, !IO)
|
|
].
|
|
|
|
:- pred mmc_module_name_to_read_file_name(module_name::in, string::in,
|
|
maybe_error(string)::out, io::di, io::uo) is det.
|
|
|
|
mmc_module_name_to_read_file_name(ModuleName, Ext, MaybeFileName, !IO) :-
|
|
module_name_to_search_file_name(ModuleName, Ext, FileName0, !IO),
|
|
globals.io_lookup_accumulating_option(intermod_directories, Dirs, !IO),
|
|
search_for_file(Dirs, FileName0, MaybeFileName, !IO),
|
|
(
|
|
MaybeFileName = ok(_),
|
|
% `search_for_file' actually opens the file.
|
|
io.seen(!IO)
|
|
;
|
|
MaybeFileName = error(_)
|
|
).
|
|
|
|
:- pred mmc_module_name_to_write_file_name(module_name::in, string::in,
|
|
string::out, io::di, io::uo) is det.
|
|
|
|
mmc_module_name_to_write_file_name(ModuleName, Ext, FileName, !IO) :-
|
|
module_name_to_file_name(ModuleName, Ext, do_create_dirs, FileName, !IO).
|
|
|
|
module_name_func_id(ModuleInfo, proc(PredId, ProcId), PredModule, FuncId) :-
|
|
module_info_pred_info(ModuleInfo, PredId, PredInfo),
|
|
module_name_func_id_from_pred_info(PredInfo, ProcId, PredModule, FuncId).
|
|
|
|
module_name_func_id_from_pred_info(PredInfo, ProcId, PredModule, FuncId) :-
|
|
PredModule = pred_info_module(PredInfo),
|
|
PredName = pred_info_name(PredInfo),
|
|
PredOrFunc = pred_info_is_pred_or_func(PredInfo),
|
|
PredArity = pred_info_orig_arity(PredInfo),
|
|
FuncId = func_id(PredOrFunc, PredName, PredArity, ProcId).
|
|
|
|
func_id_to_ppid(ModuleInfo, ModuleName, FuncId, PPId) :-
|
|
FuncId = func_id(PredOrFunc, FuncName, Arity, ProcId),
|
|
module_info_get_predicate_table(ModuleInfo, PredTable),
|
|
(
|
|
predicate_table_search_pf_m_n_a(PredTable, is_fully_qualified,
|
|
PredOrFunc, ModuleName, FuncName, Arity, PredIds),
|
|
PredIds = [PredId]
|
|
->
|
|
PPId = proc(PredId, ProcId)
|
|
;
|
|
unexpected(this_file, "func_id_to_ppid: more than one predicate")
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- func this_file = string.
|
|
|
|
this_file = "mmc_analysis.m".
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|