mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-16 22:35:41 +00:00
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.
90 lines
3.2 KiB
Mathematica
90 lines
3.2 KiB
Mathematica
%-----------------------------------------------------------------------------%
|
|
% Copyright (C) 2001 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: wrap_blocks.m
|
|
%
|
|
% Author: zs.
|
|
%
|
|
% The optimizations in use_local_vars.m insert into
|
|
% instruction sequences references to temporary variables whose values
|
|
% need be preserved only within an extended basic block. The wrap_blocks pass
|
|
% looks for references to temporaries and introduces block instructions
|
|
% whenever it sees them. These block instructions go from the first reference
|
|
% to a temporary to the end of its extended basic block.
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
|
|
:- module ll_backend__wrap_blocks.
|
|
|
|
:- interface.
|
|
|
|
:- import_module ll_backend__llds.
|
|
:- import_module list.
|
|
|
|
:- pred wrap_blocks(list(instruction)::in, list(instruction)::out)
|
|
is det.
|
|
|
|
:- implementation.
|
|
|
|
:- import_module ll_backend__opt_util.
|
|
:- import_module bool, int, std_util, require.
|
|
|
|
wrap_blocks(Instrs0, Instrs) :-
|
|
wrap_instrs(Instrs0, 0, 0, [], Instrs).
|
|
|
|
% R is the number of the highest numbered tempr variable seen so far;
|
|
% R = 0 means we haven't seen any temp variables. Similarly, F is the
|
|
% highest numbered tempf variable seen so far. RevSofar is a
|
|
% reversed list of instructions starting with the first instruction
|
|
% in this block that accesses a temp variable. Invariant: RevSofar
|
|
% is always empty if R = 0 and F = 0.
|
|
|
|
:- pred wrap_instrs(list(instruction)::in, int::in, int::in,
|
|
list(instruction)::in, list(instruction)::out) is det.
|
|
|
|
wrap_instrs([], R, F, RevSofar, []) :-
|
|
( RevSofar = [_|_] ->
|
|
error("procedure ends with fallthrough")
|
|
; ( R > 0 ; F > 0 ) ->
|
|
error("procedure ends without closing block")
|
|
;
|
|
true
|
|
).
|
|
wrap_instrs([Instr0 | Instrs0], R0, F0, RevSofar, Instrs) :-
|
|
Instr0 = Uinstr0 - _Comment0,
|
|
opt_util__count_temps_instr(Uinstr0, R0, R1, F0, F1),
|
|
( ( R1 > 0 ; F1 > 0) ->
|
|
% We must close the block before a label, since you can jump
|
|
% to a label from other blocks.
|
|
%
|
|
% Call instructions cannot fall through, but they cannot refer
|
|
% to the temp variables declared by the block either, so we
|
|
% close the block either just before or just after the call
|
|
% instruction. We close the block before the call instruction,
|
|
% because including it in the block causes the test case
|
|
% debugger/all_solutions to fail.
|
|
|
|
( ( Uinstr0 = label(_) ; Uinstr0 = call(_, _, _, _, _, _) ) ->
|
|
list__reverse(RevSofar, BlockInstrs),
|
|
wrap_instrs(Instrs0, 0, 0, [], Instrs1),
|
|
Instrs = [block(R1, F1, BlockInstrs) - "", Instr0
|
|
| Instrs1]
|
|
; opt_util__can_instr_fall_through(Uinstr0, no) ->
|
|
list__reverse([Instr0 | RevSofar], BlockInstrs),
|
|
wrap_instrs(Instrs0, 0, 0, [], Instrs1),
|
|
Instrs = [block(R1, F1, BlockInstrs) - "" | Instrs1]
|
|
;
|
|
wrap_instrs(Instrs0, R1, F1,
|
|
[Instr0 | RevSofar], Instrs)
|
|
)
|
|
;
|
|
wrap_instrs(Instrs0, 0, 0, [], Instrs1),
|
|
Instrs = [Instr0 | Instrs1]
|
|
).
|
|
|
|
%-----------------------------------------------------------------------------%
|
|
%-----------------------------------------------------------------------------%
|