Files
mercury/compiler/goal_store.m
Fergus Henderson 7597790760 Use sub-modules to structure the modules in the Mercury compiler directory.
The main aim of this change is to make the overall, high-level structure
of the compiler clearer, and to encourage better encapsulation of the
major components.

compiler/libs.m:
compiler/backend_libs.m:
compiler/parse_tree.m:
compiler/hlds.m:
compiler/check_hlds.m:
compiler/transform_hlds.m:
compiler/bytecode_backend.m:
compiler/aditi_backend.m:
compiler/ml_backend.m:
compiler/ll_backend.m:
compiler/top_level.m:
	New files.  One module for each of the major components of the
	Mercury compiler.  These modules contain (as separate sub-modules)
	all the other modules in the Mercury compiler, except gcc.m and
	mlds_to_gcc.m.

Mmakefile:
compiler/Mmakefile:
	Handle the fact that the top-level module is now `top_level',
	not `mercury_compile' (since `mercury_compile' is a sub-module
	of `top_level').

compiler/Mmakefile:
	Update settings of *FLAGS-<modulename> to use the appropriate
	nested module names.

compiler/recompilation_check.m:
compiler/recompilation_version.m:
compiler/recompilation_usage.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
compiler/recompilation.version.m:
	Convert the `recompilation_*' modules into sub-modules of the
	`recompilation' module.

compiler/*.m:
compiler/*.pp:
	Module-qualify the module names in `:- module', `:- import_module',
	and `:- use_module' declarations.

compiler/base_type_info.m:
compiler/base_type_layout.m:
	Deleted these unused empty modules.

compiler/prog_data.m:
compiler/globals.m:
	Move the `foreign_language' type from prog_data to globals.

compiler/mlds.m:
compiler/ml_util.m:
compiler/mlds_to_il.m:
	Import `globals', for `foreign_language'.

Mmake.common.in:
trace/Mmakefile:
runtime/Mmakefile:
	Rename the %.check.c targets as %.check_hdr.c,
	to avoid conflicts with compiler/recompilation.check.c.
2002-03-20 12:37:56 +00:00

120 lines
4.0 KiB
Mathematica

%-----------------------------------------------------------------------------%
% Copyright (C) 2000 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.
%-----------------------------------------------------------------------------%
%
% Module: goal_store
% Main authors: petdr
%
% Define a type goal_store(Key) which allows a hlds_goal to be stored in a
% dictionary like structure. However there some operations on this
% dictionary which are specific to hlds_goals.
%
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- module transform_hlds__goal_store.
:- interface.
:- import_module hlds__hlds_goal, hlds__hlds_module, hlds__hlds_pred.
:- import_module hlds__instmap.
:- import_module bool, set, std_util.
%-----------------------------------------------------------------------------%
:- type goal == pair(hlds_goal, instmap).
:- type goal_store(T).
:- pred goal_store__init(goal_store(T)::out) is det.
:- func goal_store__init = goal_store(T).
:- pred goal_store__det_insert(goal_store(T)::in, T::in, goal::in,
goal_store(T)::out) is det.
:- pred goal_store__lookup(goal_store(T)::in, T::in, goal::out) is det.
:- pred goal_store__member(goal_store(T)::in, T::out, goal::out) is nondet.
:- pred goal_store__all_ancestors(goal_store(T)::in, T::in, vartypes::in,
module_info::in, bool::in, set(T)::out) is det.
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module hlds__goal_util.
:- import_module int, list, map, require.
:- type goal_store(T) == map__map(T, goal).
%-----------------------------------------------------------------------------%
goal_store__init(GS) :-
map__init(GS).
goal_store__init = GS :-
goal_store__init(GS).
goal_store__det_insert(GS0, Id, Goal, GS) :-
map__det_insert(GS0, Id, Goal, GS).
goal_store__lookup(GS, Id, Goal) :-
map__lookup(GS, Id, Goal).
goal_store__member(GoalStore, Key, Goal) :-
map__member(GoalStore, Key, Goal).
goal_store__all_ancestors(GoalStore, StartId, VarTypes, ModuleInfo, FullyStrict,
AncestorIds) :-
AncestorIds = ancestors_2(GoalStore, [StartId], set__init,
VarTypes, ModuleInfo, FullyStrict).
:- func ancestors_2(goal_store(T), list(T), set(T), vartypes, module_info,
bool) = set(T).
ancestors_2(_GoalStore, [], _VisitedIds, _VarTypes, _ModuleInfo, _FullyStrict)
= set__init.
ancestors_2(GoalStore, [Id|Ids], VisitedIds, VarTypes, ModuleInfo, FullyStrict)
= AncestorIds :-
(
set__member(Id, VisitedIds)
->
AncestorIds = ancestors_2(GoalStore, Ids, VisitedIds,
VarTypes, ModuleInfo, FullyStrict)
;
Ancestors = direct_ancestors(GoalStore, Id, VarTypes,
ModuleInfo, FullyStrict),
AncestorIds = set__list_to_set(Ancestors) `union`
ancestors_2(GoalStore, Ancestors `append` Ids,
set__insert(VisitedIds, Id),
VarTypes, ModuleInfo, FullyStrict)
).
:- func direct_ancestors(goal_store(T), T, vartypes, module_info, bool)
= list(T).
direct_ancestors(GoalStore, StartId, VarTypes, ModuleInfo, FullyStrict)
= Ancestors :-
solutions(direct_ancestor(GoalStore, StartId, VarTypes,
ModuleInfo, FullyStrict), Ancestors).
:- pred direct_ancestor(goal_store(T)::in, T::in, vartypes::in,
module_info::in, bool::in, T::out) is nondet.
direct_ancestor(GoalStore, StartId, VarTypes, ModuleInfo, FullyStrict,
EarlierId) :-
goal_store__lookup(GoalStore, StartId, LaterGoal - LaterInstMap),
goal_store__member(GoalStore, EarlierId, EarlierGoal - EarlierInstMap),
compare((<), EarlierId, StartId),
not goal_util__can_reorder_goals(ModuleInfo, VarTypes, FullyStrict,
EarlierInstMap, EarlierGoal,
LaterInstMap, LaterGoal).
%-----------------------------------------------------------------------------%
%-----------------------------------------------------------------------------%