Various bug fixes and cleanups for the code in the runtime directory.

Estimated hours taken: 2

Various bug fixes and cleanups for the code in the runtime directory.

runtime/mercury_bootstrap.h:
runtime/mercury_regs.h:
runtime/mercury_stacks.h:
runtime/mercury_type_info.h:
	Move #defines that are there just for backwards compatibility
	into mercury_bootstrap.h.

runtime/process_getopt:
	Add MR_ prefixes to the names `_GETOPT_H', `no_arguments',
	and `required_argument' which are defined by mercury_getopt.h,
	to make mercury_getopt.h macro-namespace-clean.

runtime/mercury_getopt.h:
	Apply the new version of the process_getopt script.

runtime/mercury_imp.h:
	Make mercury_bootstrap the first header file that is #included,
	in case some of the macros defined in it are used in declarations
	in other header files.

runtime/mercury_memory.h:
	Delete duplicate definitions of MAX_REAL_REG, NUM_SPECIAL_REG,
	and MAX_VIRTUAL_REG -- these are all already defined in
	mercury_memory_zones.h.

runtime/mercury_memory_zones.h:
	Delete definition of NUM_SPECIAL_REG, since mercury_regorder.h
	already defines MR_NUM_SPECIAL_REG, which should be used instead
	of NUM_SPECIAL_REG.  The value of NUM_SPECIAL_REG was long
	obsolete.

runtime/mercury_regorder.h:
	Fix some bugs in the definition of MR_min_sol_hp_rec -- it was
	using `mr40', which is undefined, instead of `mr(40)'.
	Also add some comments.

runtime/mercury_regs.h:
	Fix a bug: use MR_NUM_SPECIAL_REGS instead of NUM_SPECIAL_REGS.
	Note that this bug fix unfortunately breaks backwards compatibility,
	at least for procedures with more than 32 arguments, since it
	affects the mapping from r(N) to the fake_reg array.
	However, there was no alternative, since the old mapping was
	broken: for example, the old mapping used the same fake_reg
	slot for both r(41) and MR_global_hp.

runtime/mercury_bootstrap.h:
	Change MR_GRADE_PART_0 from `redofr' to `v1', and document that
	that part of the grade is a binary compatibility version number.
	The reason for changing the grade is to ensure that the change
	in binary backwards compatibility resulting from the changes
	to runtime/mercury_regs.h will cause link errors rather
	than just random behaviour for procedures with >32 arguments.

runtime/mercury_agc_debug.c:
	Use MR_NUM_SPECIAL_REGS instead of NUM_SPECIAL_REGS.
	Also add some XXX comments, since all of the places where
	NUM_SPECIAL_REGS was used are broken anyway -- they should be
	using MAX_FAKE_REG instead of MAX_REAL_REG + NUM_SPECIAL_REG.
	But I think the current definition is put there for efficiency,
	even though it's known to be broken for procedures with >32
	arguments, so I didn't change the code to use MAX_FAKE_REG.
This commit is contained in:
Fergus Henderson
1998-11-09 14:35:40 +00:00
parent c0b84793fe
commit 779b47f4f2
11 changed files with 116 additions and 73 deletions

View File

@@ -44,7 +44,8 @@ MR_agc_dump_roots(MR_RootList roots)
** the saved registers).
*/
restore_registers();
MR_copy_regs_to_saved_regs(MAX_REAL_REG + NUM_SPECIAL_REG,
/* XXX this is unsafe -- should use MAX_FAKE_REG */
MR_copy_regs_to_saved_regs(MAX_REAL_REG + MR_NUM_SPECIAL_REG,
saved_regs);
MR_hp = MR_ENGINE(debug_heap_zone->min);
@@ -55,7 +56,8 @@ MR_agc_dump_roots(MR_RootList roots)
fflush(NULL);
fprintf(stderr, "\n");
MR_copy_saved_regs_to_regs(MAX_REAL_REG + NUM_SPECIAL_REG,
/* XXX this is unsafe -- should use MAX_FAKE_REG */
MR_copy_saved_regs_to_regs(MAX_REAL_REG + MR_NUM_SPECIAL_REG,
saved_regs);
save_registers();
roots = roots->next;
@@ -126,8 +128,9 @@ MR_agc_dump_stack_frames(MR_Internal *label, MemoryZone *heap_zone,
** registers).
*/
restore_registers();
/* XXX this is unsafe -- should use MAX_FAKE_REG */
MR_copy_regs_to_saved_regs(MAX_REAL_REG +
NUM_SPECIAL_REG, saved_regs);
MR_NUM_SPECIAL_REG, saved_regs);
MR_hp = MR_ENGINE(debug_heap_zone->min);
MR_virtual_hp = MR_ENGINE(debug_heap_zone->min);
@@ -146,8 +149,9 @@ MR_agc_dump_stack_frames(MR_Internal *label, MemoryZone *heap_zone,
printf("\n");
}
/* XXX this is unsafe -- should use MAX_FAKE_REG */
MR_copy_saved_regs_to_regs(MAX_REAL_REG +
NUM_SPECIAL_REG, saved_regs);
MR_NUM_SPECIAL_REG, saved_regs);
save_registers();
#endif /* MR_DEBUG_AGC_PRINT_VARS */

View File

@@ -7,7 +7,11 @@
/*
** mercury_bootstrap.h
**
** Temporary definitions only needed for bootstrapping.
** Temporary definitions only needed for bootstrapping and/or
** for backwards compatibility. All of the definitions here
** will go away eventually, so don't use them!
**
** This file should contain MACROS ONLY -- see mercury_imp.h for why.
*/
#ifndef MERCURY_BOOTSTRAP_H
@@ -15,4 +19,25 @@
#define NONDET_FIXED_SIZE MR_NONDET_FIXED_SIZE
#define succip MR_succip
#define hp MR_hp
#define sp MR_sp
#define curfr MR_curfr
#define maxfr MR_maxfr
#define TYPELAYOUT_UNASSIGNED_VALUE (MR_TYPELAYOUT_UNASSIGNED_VALUE)
#define TYPELAYOUT_UNUSED_VALUE (MR_TYPELAYOUT_UNUSED_VALUE)
#define TYPELAYOUT_STRING_VALUE (MR_TYPELAYOUT_STRING_VALUE)
#define TYPELAYOUT_FLOAT_VALUE (MR_TYPELAYOUT_FLOAT_VALUE)
#define TYPELAYOUT_INT_VALUE (MR_TYPELAYOUT_INT_VALUE)
#define TYPELAYOUT_CHARACTER_VALUE (MR_TYPELAYOUT_CHARACTER_VALUE)
#define TYPELAYOUT_UNIV_VALUE (MR_TYPELAYOUT_UNIV_VALUE)
#define TYPELAYOUT_PREDICATE_VALUE (MR_TYPELAYOUT_PREDICATE_VALUE)
#define TYPELAYOUT_VOID_VALUE (MR_TYPELAYOUT_VOID_VALUE)
#define TYPELAYOUT_ARRAY_VALUE (MR_TYPELAYOUT_ARRAY_VALUE)
#define TYPELAYOUT_TYPEINFO_VALUE (MR_TYPELAYOUT_TYPEINFO_VALUE)
#define TYPELAYOUT_C_POINTER_VALUE (MR_TYPELAYOUT_C_POINTER_VALUE)
#define framevar(n) MR_framevar((n) + 1)
#endif /* MERCURY_BOOTSTRAP_H */

View File

@@ -19,8 +19,8 @@
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef _GETOPT_H
#define _GETOPT_H 1
#ifndef MERCURY_GETOPT_H
#define MERCURY_GETOPT_H 1
#ifdef __cplusplus
extern "C" {
@@ -63,8 +63,8 @@ extern int MR_optopt;
zero.
The field `has_arg' is:
no_argument (or 0) if the MR_option does not take an argument,
required_argument (or 1) if the MR_option requires an argument,
MR_no_argument (or 0) if the MR_option does not take an argument,
MR_required_argument (or 1) if the MR_option requires an argument,
MR_optional_argument (or 2) if the MR_option takes an MR_optional argument.
If the field `flag' is not NULL, it points to a variable that is set
@@ -94,8 +94,8 @@ struct MR_option
/* Names for the values of the `has_arg' field of `struct MR_option'. */
#define no_argument 0
#define required_argument 1
#define MR_no_argument 0
#define MR_required_argument 1
#define MR_optional_argument 2
#if defined (__STDC__) && __STDC__
@@ -130,4 +130,4 @@ extern int MR__getopt_internal ();
}
#endif
#endif /* _GETOPT_H */
#endif /* MERCURY_GETOPT_H */

View File

@@ -19,6 +19,12 @@
#ifndef MERCURY_IMP_H
#define MERCURY_IMP_H
/*
** mercury_bootstrap.h should come first, since may defines macros
** used in other header files.
*/
#include "mercury_bootstrap.h"
/*
** The #include of "mercury_conf.h" must come before the `#ifdef USE_DLLS',
** because mercury_conf.h defines the USE_DLLS macro.
@@ -74,8 +80,6 @@
#include "mercury_tabling.h"
#include "mercury_bootstrap.h"
#include "mercury_grade.h"
#endif /* not MERCURY_IMP_H */

View File

@@ -26,15 +26,6 @@
#include "mercury_std.h" /* for bool */
/* these cannot be changed without lots of modifications elsewhere */
#define MAX_REAL_REG 32 /* r1 .. r32 */
#define NUM_SPECIAL_REG 5 /* succip, sp, hp, maxfr, curfr */
/* this can be changed at will, including by -D options to the C compiler */
#ifndef MAX_VIRTUAL_REG
#define MAX_VIRTUAL_REG 1024
#endif
#ifdef MR_LOWLEVEL_DEBUG
extern MemoryZone *dumpstack_zone;
extern int dumpindex;

View File

@@ -28,7 +28,6 @@
/* these cannot be changed without lots of modifications elsewhere */
#define MAX_REAL_REG 32 /* r1 .. r32 */
#define NUM_SPECIAL_REG 5 /* succip, sp, hp, maxfr, curfr */
/* this can be changed at will, including by -D options to the C compiler */
#ifndef MAX_VIRTUAL_REG
@@ -37,8 +36,8 @@
/* allocate enough fake_regs to hold both the special regs */
/* and all the virtual registers */
#define MAX_FAKE_REG (NUM_SPECIAL_REG + MAX_VIRTUAL_REG)
/* mr0 .. mr36, mr(37) ... mr(1028) */
#define MAX_FAKE_REG (MR_NUM_SPECIAL_REG + MAX_VIRTUAL_REG)
/* mr0 .. mr37, mr(38) ... mr(1000) ... */
/* used to lookup the fake_reg for a given real reg */
extern Word virtual_reg_map[MAX_REAL_REG];

View File

@@ -23,17 +23,20 @@
#define MERCURY_REGORDER_H
/*
** If we are using an engine base register, then shift all
** the machine registers across by 1, and allocate mr0 to
** MR_engine_base
*/
#if defined(MR_THREAD_SAFE) && NUM_REAL_REGS > 0
/*
** r1 .. r32: the general-purpose Mercury registers.
**
** If you modify the r<N> to mr<N> mapping, make sure that you update
** the definition of MR_VIRTUAL_REG_MAP_BODY below and BOTH copies of
** the definitions of r1-r32.
*/
#if defined(MR_THREAD_SAFE) && NUM_REAL_REGS > 0
/*
** If we are using an engine base register, then shift all
** the machine registers across by 1, and allocate mr0 to
** MR_engine_base
*/
#define r1 count_usage(R_RN(1), mr3)
#define r2 count_usage(R_RN(2), mr4)
#define r3 count_usage(R_RN(3), mr5)
@@ -70,22 +73,32 @@
/* Keep this in sync with the actual defintions below */
#define MR_real_reg_number_sp MR_real_reg_number_mr1
#define MR_engine_base LVALUE_CAST(Word *, count_usage(MR_SP_RN, mr0))
/*
** The special-purpose Mercury registers:
** hp, sp, succip, etc.
**
** If you modify the following block, make sure that you update
** the definitions of MR_NUM_SPECIAL_REG, MR_MAX_SPECIAL_REG_MR,
** and MR_saved_*.
*/
/*
** first, the "very special" registers -- these may go in real machine regs
*/
#define MR_engine_base LVALUE_CAST(Word *, count_usage(MR_SP_RN, mr0))
#define MR_succip LVALUE_CAST(Code *, count_usage(MR_SI_RN, mr2))
#define MR_hp LVALUE_CAST(Word *, count_usage(MR_HP_RN, mr6))
#define MR_sp LVALUE_CAST(Word *, count_usage(MR_SP_RN, mr1))
#define MR_curfr LVALUE_CAST(Word *, count_usage(MR_CF_RN, mr9))
#define MR_maxfr LVALUE_CAST(Word *, count_usage(MR_MF_RN, mr10))
/*
** next, the remainder of the special registers -- these go in the
** fake_reg array, or in some cases in ordinary global variables.
*/
#define MR_sol_hp LVALUE_CAST(Word *, count_usage(MR_SOL_HP_RN, mr(38)))
#define MR_min_hp_rec LVALUE_CAST(Word *, count_usage(MR_MIN_HP_REC, mr(39)))
#define MR_min_sol_hp_rec LVALUE_CAST(Word *, \
count_usage(MR_MIN_HP_REC, mr40))
count_usage(MR_MIN_HP_REC, mr(40)))
#define MR_global_hp LVALUE_CAST(Word *, \
count_usage(MR_GLOBAL_HP_RN, mr(41)))
@@ -93,10 +106,17 @@
#define MR_ticket_counter \
count_usage(MR_TICKET_COUNTER_RN, MR_ticket_counter_var)
/* the number of special, non rN registers */
/*
** the number of "very special" registers, i.e. special registers that can
** be allocated in real machine registers:
** MR_engine_base, MR_succip, MR_hp, MR_sp, MR_curfr, MR_maxfr
*/
#define MR_NUM_VERY_SPECIAL_REG 6
/* the number of special-purpose Mercury registers */
#define MR_NUM_SPECIAL_REG 12
/* the maximum mrN number of special, non rN registers */
/* the maximum mrN number of special registers */
#define MR_MAX_SPECIAL_REG_MR 41
/*
@@ -152,6 +172,11 @@
#else /* !MR_THREAD_SAFE or NUM_REAL_REGS == 0 */
/*
** If you modify the r<N> to mr<N> mapping, make sure that you update
** the definition of MR_VIRTUAL_REG_MAP_BODY below and BOTH copies of
** the definitions of r1-r32.
*/
#define r1 count_usage(R_RN(1), mr2)
#define r2 count_usage(R_RN(2), mr3)
#define r3 count_usage(R_RN(3), mr4)
@@ -185,29 +210,48 @@
#define r31 count_usage(R_RN(31), mr35)
#define r32 count_usage(R_RN(32), mr36)
/* Keep this in sync with the actual defintions below */
#define MR_real_reg_number_sp MR_real_reg_number_mr0
/*
** The special-purpose Mercury registers:
** hp, sp, succip, etc.
**
** If you modify the following block, make sure that you update
** the definitions of MR_NUM_SPECIAL_REG, MR_MAX_SPECIAL_REG_MR,
** and MR_saved_*.
*/
#define MR_real_reg_number_sp MR_real_reg_number_mr0
/*
** first, the "very special" registers -- these may go in real machine regs
*/
#define MR_succip LVALUE_CAST(Code *, count_usage(MR_SI_RN, mr1))
#define MR_hp LVALUE_CAST(Word *, count_usage(MR_HP_RN, mr5))
#define MR_sp LVALUE_CAST(Word *, count_usage(MR_SP_RN, mr0))
#define MR_curfr LVALUE_CAST(Word *, count_usage(MR_CF_RN, mr8))
#define MR_maxfr LVALUE_CAST(Word *, count_usage(MR_MF_RN, mr9))
/*
** next, the remainder of the special registers -- these go in the
** fake_reg array, or in some cases in ordinary global variables.
*/
#define MR_sol_hp LVALUE_CAST(Word *, count_usage(MR_SOL_HP_RN, mr(37)))
#define MR_min_hp_rec LVALUE_CAST(Word *, count_usage(MR_MIN_HP_REC, mr(38)))
#define MR_min_sol_hp_rec LVALUE_CAST(Word *, \
count_usage(MR_MIN_HP_REC, mr39))
count_usage(MR_MIN_HP_REC, mr(39)))
#define MR_global_hp LVALUE_CAST(Word *, \
count_usage(MR_GLOBAL_HP_RN, mr(40)))
#define MR_trail_ptr count_usage(MR_TRAIL_PTR_RN, MR_trail_ptr_var)
#define MR_ticket_counter \
count_usage(MR_TICKET_COUNTER_RN, MR_ticket_counter_var)
/* the number of special, non rN registers */
/*
** the number of "very special" registers, i.e. special registers that can
** be allocated in real machine registers:
** MR_succip, MR_hp, MR_sp, MR_curfr, MR_maxfr
*/
#define MR_NUM_VERY_SPECIAL_REG 5
/* the number of special registers */
#define MR_NUM_SPECIAL_REG 11
/* the maximum mrN number of special, non rN registers */
@@ -266,11 +310,4 @@
#endif
/* for backwards compatibility */
#define succip MR_succip
#define hp MR_hp
#define sp MR_sp
#define curfr MR_curfr
#define maxfr MR_maxfr
#endif /* not MERCURY_REGORDER_H */

View File

@@ -69,7 +69,7 @@
** MR_succip, MR_hp, MR_sp, MR_curfr, MR_maxfr and
** r1, ..., r32, r(33), ..., r(MAX_VIRTUAL_REG)
**
** to the set mr0..mr36, mr(37), mr(38), ..., mr(MAX_FAKE_REG-1)
** to the set mr0..mr37, mr(38), mr(39), ..., mr(MAX_FAKE_REG-1)
** which were provided by the hardware abstraction layer.
** It also provides MR_virtual_r(), MR_virtual_succip, MR_virtual_hp, etc.,
** which are similar to mr<N>, MR_succip, MR_hp, etc. except that they
@@ -114,9 +114,9 @@
** Extra stuff for the hardware abstraction layer
*/
/* The machdeps header defines mr0 .. mr36; now define mr(n) for n > 36 */
/* The machdeps header defines mr0 .. mr37; now define mr(n) for n > 37 */
#define mr(n) LVALUE_SEQ(MR_assert((n) >= MAX_REAL_REG + NUM_SPECIAL_REG && \
#define mr(n) LVALUE_SEQ(MR_assert((n) > 37 && \
(n) < MAX_FAKE_REG),\
MR_fake_reg[n])
@@ -182,7 +182,7 @@
/* mercury_regorder.h defines r1 .. r32; now define r(n) for n > 32 */
#define r(n) mr((n) + NUM_SPECIAL_REG - 1)
#define r(n) mr((n) + MR_NUM_SPECIAL_REG - 1)
/*
** saved_reg(save_area, n) accesses the underlying slot in save_area
@@ -190,7 +190,7 @@
*/
#define saved_reg(save_area, n) \
LVALUE_COND((n) > MAX_REAL_REG, \
save_area[(n) + NUM_SPECIAL_REG - 1], \
save_area[(n) + MR_NUM_SPECIAL_REG - 1], \
save_area[virtual_reg_map[(n) - 1]])
/* virtual_reg(n) accesses the underlying fake_reg for register n */

View File

@@ -123,7 +123,6 @@
#define curprednm bt_prednm(MR_curfr)
#define MR_framevar(n) MR_based_framevar(MR_curfr, n)
#define framevar(n) MR_framevar((n) + 1)
/* DEFINITIONS FOR MANIPULATING THE NONDET STACK */

View File

@@ -234,25 +234,6 @@
**
*/
/*
** Defintions for backwards compatibility.
** These will go away eventually.
*/
#define TYPELAYOUT_UNASSIGNED_VALUE (MR_TYPELAYOUT_UNASSIGNED_VALUE)
#define TYPELAYOUT_UNUSED_VALUE (MR_TYPELAYOUT_UNUSED_VALUE)
#define TYPELAYOUT_STRING_VALUE (MR_TYPELAYOUT_STRING_VALUE)
#define TYPELAYOUT_FLOAT_VALUE (MR_TYPELAYOUT_FLOAT_VALUE)
#define TYPELAYOUT_INT_VALUE (MR_TYPELAYOUT_INT_VALUE)
#define TYPELAYOUT_CHARACTER_VALUE (MR_TYPELAYOUT_CHARACTER_VALUE)
#define TYPELAYOUT_UNIV_VALUE (MR_TYPELAYOUT_UNIV_VALUE)
#define TYPELAYOUT_PREDICATE_VALUE (MR_TYPELAYOUT_PREDICATE_VALUE)
#define TYPELAYOUT_VOID_VALUE (MR_TYPELAYOUT_VOID_VALUE)
#define TYPELAYOUT_ARRAY_VALUE (MR_TYPELAYOUT_ARRAY_VALUE)
#define TYPELAYOUT_TYPEINFO_VALUE (MR_TYPELAYOUT_TYPEINFO_VALUE)
#define TYPELAYOUT_C_POINTER_VALUE (MR_TYPELAYOUT_C_POINTER_VALUE)
enum MR_TypeLayoutValue {
MR_TYPELAYOUT_UNASSIGNED_VALUE,
MR_TYPELAYOUT_UNUSED_VALUE,

View File

@@ -15,6 +15,9 @@ do
g/\<optopt/s//MR_optopt/g
g/\<option/s//MR_option/g
g/\<_getopt/s//MR__getopt/g
g/\<_GETOPT/s//MERCURY_GETOPT/g
g/no_argument/s//MR_no_argument/g
g/required_argument/s//MR_required_argument/g
g/#ifndef/s/ELIDE_CODE/XXXELIDE_CODEXXX/
w
q