mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-19 19:33:46 +00:00
The prog_data.m module is imported by most modules of the compiler; by
359 modules out of 488, to be exact. Yet it has many parts that most of
those 359 modules don't need. This diff puts those parts into four new
modules. The number of imports of these modules:
348 modules import prog_data.m
84 modules import prog_data_foreign.m
62 modules import prog_data_pragma.m
12 modules import prog_data_event.m
5 modules import prog_data_used_modules.m
compiler/prog_data_event.m:
compiler/prog_data_foreign.m:
compiler/prog_data_pragma.m:
compiler/prog_data_used_modules.m:
New modules. They contain the parts of the parse tree that deal
respectively with the specification of events and event sets,
interfacing to foreign languages, pragmas, and the sets of used
(i.e. not unused) modules.
compiler/prog_data.m:
Delete the stuff that is now in the new modules. Put the remaining parts
of the module into a logical order.
compiler/parse_tree.m:
compiler/notes/compiler_design.html:
Include and document the new modules.
compiler/globals.m:
Move a type here from prog_data.m, since this is where it belongs.
compiler/add_foreign_proc.m:
compiler/add_mutable_aux_preds.m:
compiler/add_pragma.m:
compiler/add_solver.m:
compiler/add_trail_ops.m:
compiler/call_gen.m:
compiler/code_gen.m:
compiler/code_loc_dep.m:
compiler/comp_unit_interface.m:
compiler/compile_target_code.m:
compiler/complexity.m:
compiler/continuation_info.m:
compiler/coverage_profiling.m:
compiler/ctgc.datastruct.m:
compiler/ctgc.livedata.m:
compiler/ctgc.selector.m:
compiler/deep_profiling.m:
compiler/dep_par_conj.m:
compiler/deps_map.m:
compiler/det_analysis.m:
compiler/det_report.m:
compiler/elds_to_erlang.m:
compiler/equiv_type.m:
compiler/erl_call_gen.m:
compiler/exception_analysis.m:
compiler/export.m:
compiler/fact_table.m:
compiler/foreign.m:
compiler/frameopt.m:
compiler/get_dependencies.m:
compiler/goal_form.m:
compiler/goal_util.m:
compiler/granularity.m:
compiler/hlds_goal.m:
compiler/hlds_module.m:
compiler/hlds_out_goal.m:
compiler/hlds_out_module.m:
compiler/hlds_out_pred.m:
compiler/hlds_pred.m:
compiler/inlining.m:
compiler/intermod.m:
compiler/ite_gen.m:
compiler/item_util.m:
compiler/jumpopt.m:
compiler/layout.m:
compiler/layout_out.m:
compiler/live_vars.m:
compiler/livemap.m:
compiler/llds.m:
compiler/llds_out_file.m:
compiler/llds_out_global.m:
compiler/llds_out_instr.m:
compiler/make.dependencies.m:
compiler/make.module_dep_file.m:
compiler/make_hlds.m:
compiler/make_hlds_warn.m:
compiler/mark_tail_calls.m:
compiler/mercury_compile_llds_back_end.m:
compiler/mercury_compile_main.m:
compiler/ml_call_gen.m:
compiler/ml_code_gen.m:
compiler/ml_code_util.m:
compiler/ml_foreign_proc_gen.m:
compiler/ml_proc_gen.m:
compiler/ml_tailcall.m:
compiler/ml_unify_gen.m:
compiler/mlds.m:
compiler/mlds_to_c.m:
compiler/mlds_to_cs.m:
compiler/mlds_to_java.m:
compiler/modecheck_goal.m:
compiler/module_imports.m:
compiler/module_qual.m:
compiler/module_qual.qualify_items.m:
compiler/modules.m:
compiler/opt_debug.m:
compiler/par_conj_gen.m:
compiler/parse_pragma.m:
compiler/parse_tree_out_info.m:
compiler/parse_tree_out_pragma.m:
compiler/pd_cost.m:
compiler/polymorphism.m:
compiler/pragma_c_gen.m:
compiler/proc_gen.m:
compiler/prog_ctgc.m:
compiler/prog_event.m:
compiler/prog_foreign.m:
compiler/prog_item.m:
compiler/prog_out.m:
compiler/prog_util.m:
compiler/purity.m:
compiler/rbmm.points_to_analysis.m:
compiler/rbmm.points_to_graph.m:
compiler/simplify_goal_call.m:
compiler/simplify_goal_scope.m:
compiler/simplify_proc.m:
compiler/smm_common.m:
compiler/stack_layout.m:
compiler/structure_reuse.analysis.m:
compiler/structure_reuse.direct.choose_reuse.m:
compiler/structure_reuse.direct.detect_garbage.m:
compiler/structure_reuse.domain.m:
compiler/structure_reuse.indirect.m:
compiler/structure_sharing.analysis.m:
compiler/structure_sharing.domain.m:
compiler/table_gen.m:
compiler/tabling_analysis.m:
compiler/term_constr_build.m:
compiler/term_constr_initial.m:
compiler/term_constr_main.m:
compiler/term_constr_main_types.m:
compiler/term_constr_pass2.m:
compiler/term_constr_util.m:
compiler/term_errors.m:
compiler/term_pass1.m:
compiler/term_pass2.m:
compiler/term_traversal.m:
compiler/term_util.m:
compiler/termination.m:
compiler/trace_gen.m:
compiler/trailing_analysis.m:
compiler/type_constraints.m:
compiler/typecheck.m:
compiler/unique_modes.m:
compiler/unused_args.m:
compiler/unused_imports.m:
compiler/use_local_vars.m:
compiler/write_deps_file.m:
Conform to the changes above.
207 lines
7.4 KiB
Mathematica
207 lines
7.4 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% vim: ft=mercury ts=4 sw=4 et
|
|
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 2006, 2009, 2012 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: ctgc.datastruct.m.
|
|
% Main author: nancy.
|
|
%
|
|
% Definition of predicates and functions for the manipulation of
|
|
% datastructures.
|
|
%
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module transform_hlds.ctgc.datastruct.
|
|
:- interface.
|
|
|
|
:- import_module hlds.
|
|
:- import_module hlds.hlds_module.
|
|
:- import_module hlds.hlds_pred.
|
|
:- import_module parse_tree.
|
|
:- import_module parse_tree.prog_data.
|
|
:- import_module parse_tree.prog_data_pragma.
|
|
|
|
:- import_module list.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
% Create an initial top-datastruct of the given variable.
|
|
%
|
|
:- func datastruct_init(prog_var) = datastruct.
|
|
:- func datastruct_init_with_selector(prog_var, selector) = datastruct.
|
|
:- func datastruct_init_with_pos(prog_var, cons_id, int) = datastruct.
|
|
|
|
% Verify whether the given datastructs are identical.
|
|
%
|
|
:- pred datastruct_equal(datastruct::in, datastruct::in) is semidet.
|
|
|
|
% Check whether the two given datastructs are related to the
|
|
% same variable or not.
|
|
%
|
|
:- pred datastruct_same_vars(datastruct::in, datastruct::in) is semidet.
|
|
|
|
% Verify whether the datastructure represents a top cell, i.e. where
|
|
% the selector path is an empty path.
|
|
%
|
|
:- pred datastruct_refers_to_topcell(datastruct::in) is semidet.
|
|
|
|
% Select a subterm of the given datastructure using the specified selector.
|
|
% It is assumed that the selector is a valid selector for that
|
|
% datastructure.
|
|
%
|
|
:- func datastruct_termshift(module_info, proc_info, selector, datastruct)
|
|
= datastruct.
|
|
|
|
% Normalize the representation of the datastructure.
|
|
% (proc_info is needed to obtain the type of the variable of the
|
|
% datastructure).
|
|
% The selector of a datastruct is normalized
|
|
% iff none of the term nodes met on the path to the actual selected
|
|
% term by the selector has the same type as the selected node.
|
|
%
|
|
:- func normalize_datastruct(module_info, proc_info, datastruct) = datastruct.
|
|
|
|
:- pred datastruct_subsumed_by_return_selector(module_info::in, proc_info::in,
|
|
datastruct::in, datastruct::in, selector::out) is semidet.
|
|
|
|
:- pred datastruct_subsumed_by(module_info::in, proc_info::in,
|
|
datastruct::in, datastruct::in) is semidet.
|
|
|
|
:- pred datastruct_subsumed_by_list(module_info::in, proc_info::in,
|
|
datastruct::in, list(datastruct)::in) is semidet.
|
|
|
|
:- pred datastructs_subsumed_by_list(module_info::in, proc_info::in,
|
|
list(datastruct)::in, list(datastruct)::in) is semidet.
|
|
|
|
:- pred datastructs_that_are_subsumed_by_list(module_info::in, proc_info::in,
|
|
list(datastruct)::in, list(datastruct)::in, list(datastruct)::out) is det.
|
|
|
|
:- func datastruct_lists_least_upper_bound(module_info, proc_info,
|
|
list(datastruct), list(datastruct)) = list(datastruct).
|
|
|
|
:- pred datastruct_apply_widening(module_info::in, proc_info::in,
|
|
datastruct::in, datastruct::out) is det.
|
|
|
|
:- func datastructs_project(list(prog_var),
|
|
list(datastruct)) = list(datastruct).
|
|
|
|
:- func datastructs_vars(list(datastruct)) = list(prog_var).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- implementation.
|
|
|
|
:- import_module hlds.vartypes.
|
|
:- import_module transform_hlds.ctgc.selector.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
datastruct_init(V) = datastruct_init_with_selector(V, []).
|
|
|
|
datastruct_init_with_selector(V, Sel) = selected_cel(V, Sel).
|
|
|
|
datastruct_init_with_pos(V, ConsId, Int)
|
|
= datastruct_init_with_selector(V, selector_init(ConsId, Int)).
|
|
|
|
datastruct_equal(D1, D2) :- D1 = D2.
|
|
|
|
datastruct_same_vars(D1, D2) :-
|
|
D1 ^ sc_var = D2 ^ sc_var.
|
|
|
|
datastruct_refers_to_topcell(Data):-
|
|
DSel = Data ^ sc_selector,
|
|
DSel = [].
|
|
|
|
datastruct_termshift(ModuleInfo, ProcInfo, Sel, Data0) = Data :-
|
|
(
|
|
Sel = [],
|
|
Data = Data0
|
|
;
|
|
Sel = [_ | _],
|
|
Data0 = selected_cel(Var, DSel),
|
|
selector_termshift(DSel, Sel, NewSel0),
|
|
|
|
% Keep datastruct seletors normalized.
|
|
proc_info_get_vartypes(ProcInfo, VarTypes),
|
|
lookup_var_type(VarTypes, Var, Type),
|
|
normalize_selector_with_type_information(ModuleInfo, Type,
|
|
NewSel0, NewSel),
|
|
|
|
Data = selected_cel(Var, NewSel)
|
|
).
|
|
|
|
normalize_datastruct(ModuleInfo, ProcInfo, Data0) = Data :-
|
|
Data0 = selected_cel(Var, DSel0),
|
|
proc_info_get_vartypes(ProcInfo, VarTypes),
|
|
lookup_var_type(VarTypes, Var, Type),
|
|
normalize_selector_with_type_information(ModuleInfo, Type, DSel0, DSel),
|
|
Data = selected_cel(Var, DSel).
|
|
|
|
datastruct_subsumed_by_return_selector(ModuleInfo, ProcInfo, Data1, Data2,
|
|
Extension) :-
|
|
Data1 = selected_cel(Var, Sel1),
|
|
Data2 = selected_cel(Var, Sel2),
|
|
proc_info_get_vartypes(ProcInfo, VarTypes),
|
|
lookup_var_type(VarTypes, Var, Type),
|
|
selector_subsumed_by(ModuleInfo, already_normalized,
|
|
Sel1, Sel2, Type, Extension).
|
|
|
|
datastruct_subsumed_by(ModuleInfo, ProcInfo, Data1, Data2) :-
|
|
datastruct_subsumed_by_return_selector(ModuleInfo, ProcInfo, Data1, Data2,
|
|
_).
|
|
|
|
datastruct_subsumed_by_list(ModuleInfo, ProcInfo, Data0, [Data | Rest]):-
|
|
(
|
|
datastruct_subsumed_by(ModuleInfo, ProcInfo, Data0, Data)
|
|
;
|
|
datastruct_subsumed_by_list(ModuleInfo, ProcInfo, Data0, Rest)
|
|
).
|
|
|
|
datastructs_subsumed_by_list(ModuleInfo, ProcInfo, PerhapsSubsumedData,
|
|
Data) :-
|
|
all [X] (
|
|
list.member(X, PerhapsSubsumedData)
|
|
=>
|
|
datastructs_subsume_datastruct(ModuleInfo, ProcInfo, Data, X)
|
|
).
|
|
|
|
datastructs_that_are_subsumed_by_list(ModuleInfo, ProcInfo,
|
|
PerhapsSubsumedData, Datastructs, SubsumedData) :-
|
|
list.filter(
|
|
datastructs_subsume_datastruct(ModuleInfo, ProcInfo, Datastructs),
|
|
PerhapsSubsumedData, SubsumedData).
|
|
|
|
:- pred datastructs_subsume_datastruct(module_info::in, proc_info::in,
|
|
list(datastruct)::in, datastruct::in) is semidet.
|
|
|
|
datastructs_subsume_datastruct(ModuleInfo, ProcInfo, Datastructs, Data):-
|
|
datastruct_subsumed_by_list(ModuleInfo, ProcInfo, Data, Datastructs).
|
|
|
|
datastruct_apply_widening(ModuleInfo, ProcInfo, Data0, Data) :-
|
|
Data0 = selected_cel(Var, Sel0),
|
|
proc_info_get_vartypes(ProcInfo, VarTypes),
|
|
lookup_var_type(VarTypes, Var, Type),
|
|
selector_apply_widening(ModuleInfo, Type, Sel0, Sel),
|
|
Data = selected_cel(Var, Sel).
|
|
|
|
datastruct_lists_least_upper_bound(ModuleInfo, ProcInfo, Data1, Data2)
|
|
= Data :-
|
|
list.filter(
|
|
datastructs_subsume_datastruct(ModuleInfo, ProcInfo, Data1),
|
|
Data2, _SubsumedData, NotSubsumedData),
|
|
Data = list.append(NotSubsumedData, Data1).
|
|
|
|
datastructs_project(Vars, DataIn) =
|
|
list.filter(
|
|
(pred(Data::in) is semidet :- list.member(Data ^ sc_var, Vars)),
|
|
DataIn).
|
|
|
|
datastructs_vars(Data) = list.map(func(X) = X ^ sc_var, Data).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
:- end_module transform_hlds.ctgc.datastruct.
|
|
%-----------------------------------------------------------------------------%
|