Files
mercury/compiler/code_model.m
Simon Taylor 42025cecfc Allow Aditi to call Mercury. At the moment, this involves Aditi
Estimated hours taken: 200
Branches: main

Allow Aditi to call Mercury.  At the moment, this involves Aditi
loading a shared library containing the user's code.

runtime/mercury_aditi.h:
	Define a structure MR_Aditi_Proc_Info used to describe
	a procedure called by Aditi.  Aditi will use dlsym() to
	look up these structures in the shared library supplied
	by the user.

compiler/rtti.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/ml_code_util.m:
compiler/mlds_to_gcc.m:
compiler/opt_debug.m:
	Add an aditi_proc_info alternative to the rtti_data type,
	which corresponds to an MR_AditiProcInfo structure in
	the generated code.

	In the rtti_proc_label type, record the determinism rather
	than the code_model for use by Aditi.

compiler/options.m:
doc/user_guide.texi:
	Add an option `--aditi-calls-mercury'.
	This is needed for the Aditi tests, which currently don't
	handle loading the shared libraries for user defined code.

	Move `--aditi' into the compilation model options section.

compiler/rl.m:
	Sort the constructors for d.u. types when creating an Aditi
	type declaration to make it easier to find a particular
	constructor.

compiler/code_model.m:
compiler/stack_layout.m:
	Move represent_determinism into code_model.m, for use
	by rtti_to_mlds.m.

compiler/rl_exprn.m:
compiler/rl_file.pp:
compiler/rl_out.pp:
compiler/hlds_module.m:
compiler/mercury_compile.m:
	Create the procedures for each top-down Mercury goal which
	needs to be called from Aditi.
	Each created procedure has one input and one output argument,
	both of which will have a `{}/N' type.

	Allow nondet join conditions.

compiler/rl_exprn.m:
	Use record syntax.

compiler/rl_out.pp:
	Minor changes to the support for memoing.

runtime/Mmakefile:
runtime/mercury_imp.h:
runtime/mercury.h:
	Add mercury_aditi.h.

runtime/mercury_stack_layout.m:
	Add a comment about the duplication between MR_DETISM_*
	and code_model.represent_determinism.

tests/valid/Mmakefile:
tests/valid/Mercury.options:
tests/valid/aditi_calls_mercury.m:
	Test case.

	Also, enable the Aditi tests in hlc grades.
2004-10-20 09:45:11 +00:00

100 lines
3.8 KiB
Mathematica

%-----------------------------------------------------------------------------%
% Copyright (C) 2000, 2003-2004 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 hlds__code_model.
% This module defines the `code_model' data type, and associated procedures.
% The `code_model' type is a simplified version of the `determinism' type
% that is defined in prog_data.m. It ignores most of the distinctions in
% the determinism type and keeps only the distinctions that are important
% for code generation.
% We define this in a different module than the `determinism' type because
% it is only used by some of the different back-ends, not all of them.
% It is used by the MLDS, LLDS, and bytecode back-ends, but not by the
% Aditi-RL back-end.
%-----------------------------------------------------------------------------%
:- interface.
:- import_module hlds__hlds_goal.
:- import_module hlds__hlds_pred.
:- import_module parse_tree__prog_data.
:- type code_model
---> model_det % functional & total
; model_semi % just functional
; model_non. % not functional
:- pred determinism_to_code_model(determinism, code_model).
:- mode determinism_to_code_model(in, out) is det.
:- mode determinism_to_code_model(out, in) is multi.
:- pred proc_info_interface_code_model(proc_info::in, code_model::out) is det.
:- pred goal_info_get_code_model(hlds_goal_info::in, code_model::out) is det.
% Construct a representation of the interface determinism of a
% procedure. The code we have chosen is not sequential; instead
% it encodes the various properties of each determinism.
% This must match the encoding of MR_Determinism in
% mercury_stack_layout.h.
%
% The 8 bit is set iff the context is first_solution.
% The 4 bit is set iff the min number of solutions is more than zero.
% The 2 bit is set iff the max number of solutions is more than zero.
% The 1 bit is set iff the max number of solutions is more than one.
:- func represent_determinism(determinism) = int.
%-----------------------------------------------------------------------------%
:- implementation.
:- import_module int.
determinism_to_code_model(det, model_det).
determinism_to_code_model(semidet, model_semi).
determinism_to_code_model(nondet, model_non).
determinism_to_code_model(multidet, model_non).
determinism_to_code_model(cc_nondet, model_semi).
determinism_to_code_model(cc_multidet, model_det).
determinism_to_code_model(erroneous, model_det).
determinism_to_code_model(failure, model_semi).
proc_info_interface_code_model(ProcInfo, CodeModel) :-
proc_info_interface_determinism(ProcInfo, Determinism),
determinism_to_code_model(Determinism, CodeModel).
goal_info_get_code_model(GoalInfo, CodeModel) :-
goal_info_get_determinism(GoalInfo, Determinism),
determinism_to_code_model(Determinism, CodeModel).
represent_determinism(det) = max_more_than_zero \/ min_more_than_zero.
represent_determinism(semidet) = max_more_than_zero.
represent_determinism(nondet) = max_more_than_one.
represent_determinism(multidet) = max_more_than_one \/ min_more_than_zero.
represent_determinism(erroneous) = min_more_than_zero.
represent_determinism(failure) = 0.
represent_determinism(cc_nondet) =
represent_determinism(nondet) \/ first_solution.
represent_determinism(cc_multidet) =
represent_determinism(multidet) \/ first_solution.
:- func first_solution = int.
first_solution = 8.
:- func min_more_than_zero = int.
min_more_than_zero = 4.
:- func max_more_than_zero = int.
max_more_than_zero = 2.
:- func max_more_than_one = int.
max_more_than_one = 3.
%-----------------------------------------------------------------------------%