mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-12 04:14:06 +00:00
Branches: main Store double-precision `float' constructor arguments in unboxed form, in high-level C grades on 32-bit platforms, i.e. `float' (and equivalent) arguments may occupy two machine words. As the C code generated by the MLDS back-end makes use of MR_Float variables and parameters, float (un)boxing may be reduced substantially in many programs. compiler/prog_data.m: Add `double_word' as a new option for constructor argument widths, only used for float arguments as yet. compiler/make_hlds_passes.m: Set constructor arguments to have `double_word' width if required, and possible. compiler/type_util.m: Add helper predicate. compiler/builtin_ops.m: compiler/c_util.m: compiler/llds.m: Add two new binary operators used by the MLDS back-end. compiler/arg_pack.m: Handle `double_word' arguments. compiler/ml_code_util.m: Deciding whether or not a float constructor argument requires boxing now depends on the width of the field. compiler/ml_global_data.m: When a float constant appears as an initialiser of a generic array element, it is now always unboxed, irrespective of --unboxed-float. compiler/ml_type_gen.m: Take double-word arguments into account when generating structure fields. compiler/ml_unify_gen.m: Handle double-word float constructor arguments in (de)constructions. In some cases we break a float argument into its two words, so generating two assignments statements or two separate rvals. Take double-word arguments into account when calculating field offsets. compiler/mlds_to_c.m: The new binary operators require no changes here. As a special case, write `MR_float_from_dword_ptr(&X)' instead of `MR_float_from_dword(X, Y)' when X, Y are consecutive words within a field. The definition of `MR_float_from_dword_ptr' is more straightforward, and gcc produces better code than if we use the more general `MR_float_from_dword'. compiler/rtti_out.m: For double-word arguments, generate MR_DuArgLocn structures with MR_arg_bits set to -1. compiler/rtti_to_mlds.m: Handle double-word arguments in field offset calculation. compiler/unify_gen.m: Partially handle double_word arguments in LLDS back-end. compiler/handle_options.m: Set --unboxed-float when targetting Java, C# and Erlang. compiler/structure_reuse.direct.choose_reuse.m: Rename a predicate. compiler/bytecode.m: compiler/equiv_type.m: compiler/equiv_type_hlds.m: compiler/llds_to_x86_64.m: compiler/mlds_to_gcc.m: compiler/mlds_to_il.m: compiler/opt_debug.m: Conform to changes. library/construct.m: library/store.m: Handle double-word constructor arguments. runtime/mercury_conf.h.in: Clarify what `MR_BOXED_FLOAT' now means. runtime/mercury_float.h: Add helper macros for converting between doubles and word/dwords. runtime/mercury_deconstruct.c: runtime/mercury_deconstruct.h: Add a macro `MR_arg_value' and a helper function to extract a constructor argument value. This replaces `MR_unpack_arg'. runtime/mercury_type_info.h: Remove `MR_unpack_arg'. Document that MR_DuArgLocn.MR_arg_bits may be -1. runtime/mercury_deconstruct_macros.h: runtime/mercury_deep_copy_body.h: runtime/mercury_ml_arg_body.h: runtime/mercury_table_type_body.h: runtime/mercury_tabling.c: runtime/mercury_type_info.c: Handle double-word constructor arguments. tests/hard_coded/Mercury.options: tests/hard_coded/Mmakefile: tests/hard_coded/lco_double.exp: tests/hard_coded/lco_double.m: tests/hard_coded/pack_args_float.exp: tests/hard_coded/pack_args_float.m: Add test cases. trace/mercury_trace_vars.c: Conform to changes.
167 lines
5.8 KiB
C
167 lines
5.8 KiB
C
/*
|
|
** vim:ts=4 sw=4 expandtab
|
|
*/
|
|
|
|
/*
|
|
** Copyright (C) 2002, 2005, 2007, 2011 The University of Melbourne.
|
|
** This file may only be copied under the terms of the GNU Library General
|
|
** Public License - see the file COPYING.LIB in the Mercury distribution.
|
|
*/
|
|
|
|
/*
|
|
** mercury_deconstruct.h
|
|
**
|
|
** This file declares utility functions for deconstructing terms,
|
|
** for use by the standard library and the debugger.
|
|
*/
|
|
|
|
#ifndef MERCURY_DECONSTRUCT_H
|
|
#define MERCURY_DECONSTRUCT_H
|
|
|
|
#include "mercury_imp.h"
|
|
#include <stdio.h>
|
|
|
|
typedef struct {
|
|
int num_extra_args;
|
|
MR_Word *arg_values;
|
|
const MR_DuArgLocn *arg_locns;
|
|
MR_TypeInfo *arg_type_infos;
|
|
MR_bool can_free_arg_type_infos;
|
|
} MR_Expand_Args_Fields;
|
|
|
|
typedef struct {
|
|
int arity;
|
|
int functor_number;
|
|
MR_ConstString functor;
|
|
MR_Expand_Args_Fields args;
|
|
} MR_Expand_Functor_Args_Info;
|
|
|
|
typedef struct {
|
|
int arity;
|
|
int functor_number;
|
|
MR_ConstString functor;
|
|
MR_Expand_Args_Fields args;
|
|
MR_bool limit_reached;
|
|
} MR_Expand_Functor_Args_Limit_Info;
|
|
|
|
typedef struct {
|
|
int arity;
|
|
int functor_number;
|
|
MR_ConstString functor_only;
|
|
} MR_Expand_Functor_Only_Info;
|
|
|
|
typedef struct {
|
|
int arity;
|
|
MR_Expand_Args_Fields args_only;
|
|
} MR_Expand_Args_Only_Info;
|
|
|
|
typedef struct {
|
|
int arity;
|
|
MR_bool chosen_index_exists;
|
|
MR_Word *chosen_value_ptr;
|
|
const MR_DuArgLocn *chosen_arg_locn;
|
|
MR_TypeInfo chosen_type_info;
|
|
} MR_Expand_Chosen_Arg_Only_Info;
|
|
|
|
/*
|
|
** MR_NONCANON_ABORT asks that deconstructions of noncanonical types should
|
|
** cause a runtime abort.
|
|
**
|
|
** MR_NONCANON_ALLOW asks that deconstructions of noncanonical types should
|
|
** return a constant that indicates this fact.
|
|
**
|
|
** MR_NONCANON_CC asks that deconstruction of noncanonical types should
|
|
** deconstruct the term as if it were canonical. Since by definition,
|
|
** noncanonical types may have more than one representation for the same value,
|
|
** this requires the caller to be in a committed choice context.
|
|
*/
|
|
|
|
typedef enum {
|
|
MR_NONCANON_ABORT,
|
|
MR_NONCANON_ALLOW,
|
|
MR_NONCANON_CC
|
|
} MR_noncanon_handling;
|
|
|
|
extern void MR_expand_functor_args(MR_TypeInfo type_info,
|
|
MR_Word *data_word_ptr, MR_noncanon_handling noncanon,
|
|
MR_Expand_Functor_Args_Info *expand_info);
|
|
|
|
extern void MR_expand_functor_args_limit(MR_TypeInfo type_info,
|
|
MR_Word *data_word_ptr, MR_noncanon_handling noncanon,
|
|
int max_arity,
|
|
MR_Expand_Functor_Args_Limit_Info *expand_info);
|
|
|
|
extern void MR_expand_functor_only(MR_TypeInfo type_info,
|
|
MR_Word *data_word_ptr, MR_noncanon_handling noncanon,
|
|
MR_Expand_Functor_Only_Info *expand_info);
|
|
|
|
extern void MR_expand_args_only(MR_TypeInfo type_info,
|
|
MR_Word *data_word_ptr, MR_noncanon_handling noncanon,
|
|
MR_Expand_Args_Only_Info *expand_info);
|
|
|
|
extern void MR_expand_chosen_arg_only(MR_TypeInfo type_info,
|
|
MR_Word *data_word_ptr, MR_noncanon_handling noncanon,
|
|
int chosen, MR_Expand_Chosen_Arg_Only_Info *expand_info);
|
|
|
|
extern void MR_expand_named_arg_only(MR_TypeInfo type_info,
|
|
MR_Word *data_word_ptr, MR_noncanon_handling noncanon,
|
|
MR_ConstString chosen_name,
|
|
MR_Expand_Chosen_Arg_Only_Info *expand_info);
|
|
|
|
/*
|
|
** MR_arg() takes the address of a term, its type, and an
|
|
** argument position (the first argument being at position 1).
|
|
** If the given term has an argument at that position, MR_arg
|
|
** returns MR_TRUE and fills in the locations pointed to by the
|
|
** argument_ptr and arg_type_info_ptr arguments with the value
|
|
** and type of the argument at the selected position.
|
|
** If it doesn't, it fails (i.e. returns MR_FALSE).
|
|
**
|
|
** You need to wrap MR_{save/restore}_transient_hp() around
|
|
** calls to this function.
|
|
*/
|
|
|
|
extern MR_bool MR_arg(MR_TypeInfo type_info, MR_Word *term, int arg_index,
|
|
MR_TypeInfo *arg_type_info_ptr, MR_Word **argument_ptr,
|
|
const MR_DuArgLocn **arg_locn_ptr,
|
|
MR_noncanon_handling noncanon);
|
|
|
|
/*
|
|
** MR_named_arg() is just like MR_arg, except the argument
|
|
** is selected by name, not by position.
|
|
**
|
|
** You need to wrap MR_{save/restore}_transient_hp() around
|
|
** calls to this function.
|
|
*/
|
|
|
|
extern MR_bool MR_named_arg(MR_TypeInfo type_info, MR_Word *term,
|
|
MR_ConstString arg_name, MR_TypeInfo *arg_type_info_ptr,
|
|
MR_Word **argument_ptr,
|
|
const MR_DuArgLocn **arg_locn_ptr,
|
|
MR_noncanon_handling noncanon);
|
|
|
|
/*
|
|
** MR_named_arg_num() takes the address of a term, its type,
|
|
** and an argument name. If the given term has an argument
|
|
** with the given name, it succeeds and returns the argument
|
|
** number (counted starting from 0) of the argument. If it
|
|
** doesn't, it fails (i.e. returns MR_FALSE).
|
|
**
|
|
** You need to wrap MR_{save/restore}_transient_hp() around
|
|
** calls to this function.
|
|
*/
|
|
|
|
extern MR_bool MR_named_arg_num(MR_TypeInfo type_info, MR_Word *term_ptr,
|
|
const char *arg_name, int *arg_num_ptr);
|
|
|
|
#define MR_arg_value(arg_ptr, arg_locn) \
|
|
( ((arg_locn) == NULL || (arg_locn)->MR_arg_bits == 0) \
|
|
? *(arg_ptr) \
|
|
: MR_arg_value_uncommon(arg_ptr, arg_locn) \
|
|
)
|
|
|
|
extern MR_Word MR_arg_value_uncommon(MR_Word *arg_ptr,
|
|
const MR_DuArgLocn *arg_locn);
|
|
|
|
#endif /* MERCURY_DECONSTRUCT_H */
|