Commit Graph

31 Commits

Author SHA1 Message Date
Zoltan Somogyi
1ed891b7b1 Introduce a mechanism for extending the det and nondet stacks when needed.
Estimated hours taken: 24
Branches: main

Introduce a mechanism for extending the det and nondet stacks when needed.
The mechanism takes the form of a new grade component, .exts ("extend stacks").

While the new mechanism may be useful in its own right, it is intended mainly
to support a new implementation of minimal model tabling, which will use a
separate Mercury context for each distinct subgoal. Each context has its own
det and nondet stack. Clearly, we can't have hundreds of contexts each with
megabyte sized det stacks. The intention is that the stacks of the subgoals
will start small, and be expanded when needed.

The runtime expansion of stacks doesn't work yet, but it is unnecessarily
hard to debug without an installed compiler that understands the new grade
component, which is why this diff will be committed before that is fixed.

compiler/handle_options.m:
compiler/options.m:
runtime/mercury_grade.h:
scripts/canonical_grade.sh-subr
scripts/init_grade_options.sh-subr
scripts/parse_grade_options.sh-subr
scripts/mgnuc.in
	Handle the new grade component.

runtime/mercury_memory_zones.h:
	Add MR_ prefixes to the names of the fields of the zone structure.

	Record not just the actual size of each zone, which includes various
	kinds of buffers, but also the desired size of the zone exclusive of
	buffers.

	Format the documentation of the zone structure fields more
	comprehensibly.

runtime/mercury_memory_zones.c:
	Instead of implementing memalign if it is not provided by the operating
	system, implement a function that allows us to reallocate the returned
	area of memory.

	Provide a prototype implementation of memory zone extension. It doesn't
	work yet.

	Factor out the code for setting up redzones, since it is now needed
	in more than place.

	Convert to four space indentation.

	Make the debugging functions a bit more flexible.

runtime/mercury_wrapper.c:
	Conform to the improved interface of the debugging functions.

runtime/mercury_overflow.h:
runtime/mercury_std.h:
	Move a generally useful macro from mercury_overflow.h to mercury_std.h.

runtime/mercury_stacks.c:
	Add functions to extend the stacks.

runtime/mercury_stacks.h:
	Add the tests required to invoke the functions that extend the stacks.

	Add the macros needed by the change to compiler/llds.m.

	Convert to four space indentation.

runtime/mercury_conf.h.in:
	Prepare for the use of the posix_memalign function, which is the
	current replacement of the obsolete memalign library function.
	We don't yet use it.

runtime/mercury_context.h:
	Format the documentation of the context structure fields more
	comprehensibly.

	Put MR_ prefixes on the names of the fields of some structures
	that didn't previously have them.

	Conform to the new names of the fields of the zone structure.

runtime/mercury_context.c:
runtime/mercury_debug.c:
runtime/mercury_deep_copy.c:
runtime/mercury_engine.c:
runtime/mercury_memory_handlers.c:
library/benchmarking.m:
library/exception.m:
	Conform to the new names of the fields of the zone structure.

	In some cases, add missing MR_ prefixes to function names
	and/or convert to four space indentation.

runtime/mercury_engine.h:
	Add a new low level debug flag for debugging stack extensions.

	Format the documentation of the engine structure fields more
	comprehensibly.

	Convert to four space indentation.

runtime/mercury_conf_param.h:
	Document a new low level debug flag for debugging stack extensions.

compiler/compile_target_code.m:
compiler/handle_options.m:
compiler/options.m:
	Handle the new grade component.

compiler/llds.m:
	Add two new kinds of LLDS instructions, save_maxfr and restore_maxfr.
	These are needed because the nondet stack may be relocated between
	saving and the restoring of maxfr, and the saved maxfr may point to
	the old stack. In .exts grades, these instructions will save not a
	pointer but the offset of maxfr from the start of the nondet stack,
	since offsets are not affected by the movement of the nondet stack.

compiler/code_info.m:
	Use the new instructions where relevant. (Some more work may be
	needed on this score; the relevant places are marked with XXX.)

compiler/dupelim.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_out.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/reassign.m:
compiler/use_local_vars.m:
	Handle the new LLDS instructions.

tools/bootcheck:
	Provide a mechanism for setting the initial stack sizes for a
	bootcheck.
2005-09-13 08:25:44 +00:00
Zoltan Somogyi
eeaa5eca56 Make a step towards supporting the automatic running of compiler-provided
Estimated hours taken: 4
Branches: main

Make a step towards supporting the automatic running of compiler-provided
initialization functions at startup. The idea is that in each module that
defines a solver type which wants to keep the solver state in a global
variable, the compiler will generate a function to initialize this global
variable and put a line containing

	REQUIRED_INIT function_name

in the generated .c file. Mkinit will then see this and put a call to the named
function in the program's init_modules_required function, which (once this diff
is installed) will be called from the tail end of mercury_init.

util/mkinit.c:
	Until now, mkinit didn't open .c files unless given the -x option,
	because doing so was expensive: the list of .c (and .init) files was
	scanned five times, and opening and reading each file five times is
	excessive. This diff changes that. Each file is now opened and read
	(until a line containing only ENDINIT) just once, and the info found
	therein put into some new mkinit data structures. The five scans
	through the file list now scan through these data structures instead.
	This is now fast enough to leave -x on all the time: mkinit -x now
	takes 3-4 seconds in the compiler directory, and at most 0.15s
	in the other directories.

	Add a sixth scan through the data structures to generate calls to
	the functions named in REQUIRED_INIT lines; make bunches of these calls
	the body of the program's init_modules_required function.

runtime/mercury_array_macro.h:
	Fix indentation.

runtime/mercury_dlist.[ch]:
	Move the documentation of the exported functions from the .c file
	to the .h file.

runtime/mercury_std.h:
	Add a missing () around a macro argument.
2005-08-11 01:12:53 +00:00
Ian MacLarty
20dc2c2937 Fix seg fault bug in declarative debugger.
Estimated hours taken: 5
Branches: main

Fix seg fault bug in declarative debugger.

Allow shared libraries to be linked against using lmc.

browser/declarative_tree.m
	The will_not_call_mercury promise was a fib, since
	ML_bool_return_yes/no were exported Mercury procs.  So just return
	constants instead.

library/bool.m
	Add comment noting that the representation of bool values should
	correspond to definitions given in runtime/mercury_std.h

runtime/mercury_std.h
	Add comment noting that MR_TRUE and MR_FALSE should correspond
	with the representation of Mercury bools.

tests/debugger/declarative/Mmakefile
	Report output if the command to build the .out file fails.

tools/lmc.in
	Allow shared versions of the libraries to be linked against using
	lmc.  I needed this since the seg fault only occured when linking
	against the shared versions of the libraries.
2004-11-24 08:46:29 +00:00
Zoltan Somogyi
9c9676fac0 Fix problems with namespace cleanliness on ender.
Estimated hours taken: 0.5
Branches: main

Fix problems with namespace cleanliness on ender.

runtime/mercury_library_types.h:
runtime/mercury_signal.h:
runtime/mercury_stack_trace.h:
runtime/mercury_std.h:
trace/mercury_trace_vars.h
util/mkinit.c:
	Make sure that we include mercury_regs.h before system header files
	with functions.
2004-05-24 04:32:56 +00:00
Zoltan Somogyi
c80d143cc8 The following change is only 98% complete, not 100%.
Estimated hours taken: 120
Branches: main

The following change is only 98% complete, not 100%. I am committing it in
this state because (1) we pass many more test cases in deep profiling grade
with it than without it, and (2) the double maintanance involved in fixing
CVS conflicts is preventing me from doing the last 2%.

Get the deep profiler to work for code that sets up to catch exceptions,
which for the last year or more has included the compiler, and to get it
almost working for code that actually catching exceptions.

The basic problem is that code that throws exceptions will in general cause
several calls to "return" without executing the exit or fail port codes that
the deep profiling transformation inserted into their bodies, and this leaves
the data structure being built by the deep profiling inconsistent. The solution
uses the same approach as we have adopted for the debugger: have the code that
handles the throwing of exceptions simulate a return from each call between
the throw and the catch, updating the deep profiling data structures as needed.

This requires us to be able to walk the stack at runtime not just in debugging
grades but also in deep profiling grades. Since the debugger already has the
mechanisms required for this, we reuse them. The procedure layouts used by the
debugger were designed to have three segments: the procedure stack walk
information, the procedure id, and the execution tracing information. We now
modify this design to make the third segment contain two pointers: to the
execution tracing information (for use by the debugger), and to the procedure's
proc_static structure (for use by deep profiling). Each pointer will be null
unless the pointed-to structure is required by compile-time options.

This common use by the debugger and by deep profiling of the stack-walk
structure and the procedure id structure (which deep profiling used to
generate independently and possibly redundantly) required some rearrangement
of the compiler's version of these data structures.

To make this rearrangement simpler, this diff removes a capability that
we theoretically supported but never used: turning on stack traces without
turning on execution tracing and vice versa. After this diff, stack tracing
is enabled if and only if either execution tracing or deep profiling is
enabled.

The diff also includes improvements in the debugging infrastructure for
debugging deep profiling, which were necessary for the implementation of the
rest of the changes.

compiler/deep_profiling.m:
	The code in exception.m needs to know the locations of the variables
	that we would pass to the exit or fail port code, so it can simulate
	leaving the procedure invocation through the exception port. Without
	this information, throwing an exception leaves the deep profiling
	data structures of the procedure invocations between throw and catch
	in an inconsistent state.

	Deep_profiling.m creates these variables, but it doesn't know where
	they will be at runtime, so it records their identities; the code
	generator will allocate them stack slots and record the numbers of
	these stack slots for placement in the now expanded proc layout
	structures. Deep profiling used to generate static data structures
	separately from the HLDS, but since the code generator now needs
	access to them, we store their information in proc_infos in the HLDS.

	Instead of passing the addresses of proc_static structures to the deep
	profiling port procedures, pass the address of proc_layout structures,
	since the information about the identities of procedures are now stored
	not in the proc_static structure, but in the proc_layout structure
	that points to the proc_static structure.

compiler/hlds_pred.m:
compiler/layout.m:
	Move the definitions of the static data structures generated by deep
	profiling from layout.m to hlds_pred.m, to allow deep_profiling.m
	to store them in proc_infos.

compiler/hlds_pred.m:
compiler/rtti.m:
	Move the definition of rtti_proc_label from rtti.m to hlds_pred.m,
	since some of the new data structures in hlds_pred.m need it. Despite
	its name, the rtti_proc_label type doesn't contain any info that
	doesn't belong in the HLDS.

	Add some information to the rtti_proc_label type that is now needed
	by deep profiling, e.g. record determinisms instead of just code
	models. Record explicitly the outcome of some tests that used to be
	duplicated in more than one place in the compiler, e.g. for whether
	the procedure (as opposed to the predicate) is imported. Change some
	of the field names to be more precise about the field's meaning.

compiler/code_gen.m:
	Transmit the contents of the deep profiling data structures stored in
	the proc_info by deep_profiling.m to continuation_info.m, together
	with the layout structures created for execution tracing and the
	identities of the variables needed for handling exceptions,
	when code generation for a procedure is complete.

	After the goal that generates these variables, save them to stack
	for use by the exception handler.

compiler/hlds_goal.m:
	Add a feature to mark the goal that generates the deep profiling
	variables needed by the exception handler.

compiler/hlds_llds.m:
	Add a utility predicate for new code in code_gen.m

compiler/continuation_info.m:
	Hold the deep profiling information computed by code_gen.m for use by
	stack_layout.m.

compiler/layout.m:
compiler/layout_out.m:
	Update the definitions of the data structures describing procedure
	layouts, and the code writing them out, to reflect the use of some
	parts of procedure layouts by deep profiling as well as debugging.

	Change the layout structures generated by deep profiling to use
	rtti_proc_labels, which are backend independent, instead of
	proc_labels, which are specific to the LLDS backend.

	Conform to the changes in runtime/mercury_stack_layout.h.

compiler/stack_layout.m:
	Generate the updated version of proc_layout structures.

compiler/mercury_compile.m:
compiler/global_data.m:
	Conform to the fact that deep profiling no longer generates layout
	structures separate from proc_infos.

compiler/llds_out.m:
	Register proc_layout structures instead of proc_static structures
	for use by runtime/mercury_deep_profiling.c.

compiler/options.m:
compiler/handle_options.m:
	Rename the require_tracing option as exec_trace, since this more
	directly reflects its meaning.

	Instead of having --debug set both require_tracing and stack_trace,
	make it set (be the user-visible name of) just exec_trace;
	the value of stack_trace is implied.

	Turn off the specialization of deep profiling for self-tail-recursive
	procedures for now. Due to the changes made by this diff in the data
	structures involved in debugging, it cannot be debugged until this
	change has been installed. Handling the full language is more important
	than a specialization that reduces only stack space overheads, not
	runtime overheads.

compiler/compile_target_code.m:
	Conform to the changes in options.m and runtime/mercury_grade.h.

compiler/hlds_data.m:
	Replace the deep_profiling_proc_static cons_id, and its associated tag,
	to deep_profiling_proc_layout, since we now generate addresses of proc
	layout structures, not of proc_static structures.

compiler/code_util.m:
	Simplify some code based on the new info in rtti_proc_labels.

compiler/bytecode_gen.m:
compiler/dependency_graph.m:
compiler/higher_order.m:
compiler/hlds_out.m:
compiler/mercury_to_mercury.m:
compiler/ml_code_util.m:
compiler/ml_unify_gen.m:
compiler/opt_debug.m:
compiler/proc_label.m:
compiler/prog_rep.m:
compiler/rl_exprn.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/saved_vars.m:
compiler/switch_util.m:
compiler/unify_gen.m:
	Minor changes to conform to the change from deep_profiling_proc_static
	to deep_profiling_proc_layout, to the change in the structure of
	rtti_proc_labels, to the changes in types of layout.m, and/or to the
	new goal feature.

deep_profiler/measurements.m:
	Reserve space for exception counts.

deep_profiler/html_format.m:
	Add a column for exception counts.

deep_profiler/profile.m:
deep_profiler/read_profile.m:
	Rename the data structures referring to compiler generated unify,
	compare and index predicates to avoid misleading names: they are
	not the only compiler generated predicates.

deep_profiler/read_profile.m:
runtime/mercury_deep_profiling.c:
	Update the string that identifies deep profiling data files.
	This is necessary because the format has changed: it now includes
	information about exception port counts.

library/exception.m:
	In deep profiling grades, execute the exception port code for every
	procedure invocation between a throw and a catch, using the procedure
	layout structures now generated by the compiler for every procedure.
	Rename the function involved to reflect its new, more general purpose.

	Update the definitions of the hand-written proc_static and proc_layout
	structures for the procedures implemented via hand-written C code.

	Indent C preprocessor directives and foreign_procs according to our
	coding standards.

library/profiling_builtin.m:
	Change the parameters of the call port code procedures from proc_static
	to proc_layout. Reach the proc_static structure from the proc_layout
	structure when needed. Include the proc_layout structure in any
	messages from assertion failures.

	Add some conditionally compiled debugging code.

	Give some variables better names.

runtime/mercury_type_info.h:
runtime/mercury_builtin_types.c:
	Move the macros required to create the proc_static structures
	of unify and compare predicates from mercury_type_info.h
	to mercury_builtin_types.c, since the latter is the only file
	that needs them.

	Use the same macros for creating the proc_static structures
	of hand-written unify, compare and compare_reprentation predicates
	as for user defined predicates. This required changing their naming
	scheme.

runtime/mercury_unify_compare_body.h:
	Conform to the new naming scheme.

runtime/mercury_ho_call.c:
	Provide the mechanism for mercury_unify_compare_body.h to conform
	to the new naming scheme.

	Remove the definitions of the proc_static structures for
	hand-written unify, compare and compare_reprentation predicates,
	since these now have to be defined together with the corresponding
	proc_layout structures in mercury_builtin_types.c.

runtime/mercury_builtin_types.[ch]:
	Update the definitions of the hand-written proc_static and proc_layout
	structures for the procedures implemented via hand-written C code,
	and add the required declarations first.

	Handle deep profiling of compare_representation as well as unify
	and compare predicates on builtin types.

	Handle deep profiling of compare_representation on user-defined types,
	since this is done entirely in the runtime, not by compiler generated
	predicates.

runtime/mercury_builtin_types_proc_layouts.h:
	New header file containing the declarations of the proc layout
	structures of the unify, compare and index predicates of builtin types.
	Logically, these declarations belong in mercury_builtin_types.h,
	but putting them there causes problems for the linker; the details
	are explained in the file itself.

runtime/Mmakefile:
	Add the new header file.

runtime/mercury_minimal_model.[ch]:
	Update the definitions of the hand-written proc_static and proc_layout
	structures for the procedures implemented via hand-written C code,
	and add the required declarations first.

runtime/mercury_grade.h:
	Replace the MR_REQUIRE_TRACING grade option with MR_EXEC_TRACING.
	Besides being better named, the MR_EXEC_TRACING option implies
	MR_STACK_TRACE.

	Besides the overall binary compatibility version number, add subsidiary
	version numbers for binary compatibility in deep profiling and
	debugging grades. These will make it easier to bootstrap changes
	(such as this) that affect binary compatibility only in such grades.

runtime/mercury_trace_base.c:
trace/mercury_trace.c:
	Conform to the new names of the configuration parameters.

runtime/mercury_hand_compare_body.h:
runtime/mercury_hand_unify_body.h:
runtime/mercury_hand_unify_compare_body.h:
runtime/mercury_ho_call.c:
tools/make_port_code:
	Pass proc_layout structures instead of proc_static structures
	to deep profiling port routines.

runtime/mercury_conf_param.h:
	Make MR_DEEP_PROFILING as well as MR_EXEC_TRACING imply MR_STACK_TRACE,
	since deep profiling now needs stack tracing. (MR_STACK_TRACE needs
	to be set in this file, because tests in this file depend on knowing
	its value, and this file is among the first files included (in this
	case indirectly) in mercury_imp.h.)

	Document the macros controlling the debugging of deep profiling.

	Enable printing of label names when the relevant deep profiling
	debugging macro is set.

runtime/mercury_debug.c:
runtime/mercury_deep_rec_depth_actions.h:
runtime/mercury_deep_rec_depth_body.h:
runtime/mercury_exception_catch_body.h:
	Get to proc_statics via proc_layouts.

runtime/mercury_deep_call_port_body.c:
runtime/mercury_deep_leave_port_body.c:
	Get to proc_statics via proc_layouts.

	Allow the debugger to disable deep profiling in Mercury code that is
	part of the debugger, not of the user program being executed.

	Add some more assertions.

runtime/mercury_engine.[ch]:
	Add a new debugging flag that controls at runtime whether we generate
	a human readable Deep.debug equivalent to the binary Deep.data files.
	(We already had a mechanism for controlling this at compile time,
	but this isn't flexible enough.)

runtime/mercury_wrapper.c:
	Allow this new debugging flag to be set from MERCURY_OPTIONS.

runtime/mercury_deep_profiling.[ch]:
	Respect this new debugging flag.

	Update the hand-written proc_static structures representing the runtime
	system.

	Print out addresses of proc_layout as well as proc_static structures
	when assertions fail.

	Add a field to the measurement structure for exception port counts,
	and write out this field with the other port counts.

	Remove procedure id information from proc_static structures,
	deep profiling now uses the procedure id in the proc_layout structure.

	Add to proc_static structures fields that specify where, if anywhere,
	the variables needed by exception.m to executed the exception port code
	are in the procedure's stack frame.

	Define a global flag that allows the debugger to disable deep
	profiling in Mercury code that is part of the debugger, not of the
	user program being executed.

	Increase type safety by providing two versions of the function
	for registering proc_layouts, one for the proc_layout structures
	of user-defined predicates and one for unify, compare and index
	predicates.

	Fix a bug that occurs only if MR_DEEP_PROFILING_EXPLICIT_CALL_COUNTS is
	defined (which it usually isn't): the initial call count was wrong.

runtime/mercury_deep_profiling_hand.h:
	Fix a bug: the handwritten code saving deep profiling variables was
	saving them in slots that didn't belong to the relevant stack frame.

	Update to conform to the modified definitions of proc_static structures
	and the fact that we now reach them via proc_layout structures.

runtime/mercury_exception_catch_body.h:
runtime/mercury_stacks.h:
	Fix the other side of the bug in mercury_deep_profiling_hand.h
	by reserving the right number of stack slots in the stack frames
	of the various modes of exception__catch. Make it harder to make
	the same bug in the future by getting the needed info from the
	place in mercury_stacks.h that defines the structure of the relevant
	stack frame.

runtime/mercury_proc_id.h:
	Rename the procedure id structure fields referring to compiler
	generated unify, compare and index predicates: they are not the only
	compiler-generated predicates.

runtime/mercury_stack_layout.h:
	Change procedure layout structures to allow them to be used for deep
	profiling as well as for debugging, as described in the prologue above.

	We don't need the capability to support label layout structures with
	links to misnamed proc layout structures, and supporting it is
	inconvenient, so delete the capability.

runtime/mercury_debug.c:
runtime/mercury_deep_profiling_hand.h:
runtime/mercury_layout_util.c:
runtime/mercury_ml_expand_body.h:
runtime/mercury_stack_trace.c:
runtime/mercury_types.h:
trace/mercury_trace_external.c:
	Conform to the new names of the procedure id structure fields.

runtime/mercury_std.h:
	Add some more arities for MR_PASTE for use in some of the modified
	modules in the runtime.

trace/mercury_trace_internal.c:
	Disable deep profiling actions in Mercury code that is part of the
	debugger, not of the program being debugged.

scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
	Make changes parallel to the ones in runtime/mercury_grade.h: delete
	--stack-trace as an independent option, and make --debug set its
	own option, not --require-tracing.

scripts/canonical_grade.sh-subr:
scripts/final_grade_options.sh-subr:
scripts/c2init.in:
scripts/mgnuc.in:
scripts/ml.in:
	Conform to the changes in grade options for debugging and for deep
	profiling.

tools/bootcheck:
	If Mmake.stage.{browser,deep,library,runtime,trace}.params exist,
	copy them to become the file Mmake.$dir.params in stage2/$dir
	(where dir is derived from the name of the original file in the obvious
	way). This allows more flexibility in the creation of the stage2;
	for example, it allows some directories (e.g. runtime or library)
	to be compiled with more debugging than other directories (e.g.
	compiler). This may be required because compiling all directories
	with lots of debugging may cause the linker to thrash.

	Add an option, --disable-debug-libs, that clobbers the libraries
	that should be linked in only in debugging grades.

	To conserve disk space, remove Deep.data files created by the bootcheck
	by default. Add an option, --keep-deep-data, to preserve these files.

	Use a consistent mechanism (test -f) for testing the existence of
	all files whose existence is tested.

	When recording modification times, record the modification times
	of some more files.

tests/hard_coded/Mmakefile:
	In deep profiling grades, disable the test cases that we don't now
	pass in such grades, and document the reasons for their failure.

	Fix the misclassification of the write_binary test case.
2004-05-19 04:00:01 +00:00
Zoltan Somogyi
86bfabfeb8 Move the definition of MR_VARIABLE_SIZED from mercury_std.h to
Estimated hours taken: 0.2
Branches: main

runtime/mercury_std.h:
runtime/mercury_types.h:
	Move the definition of MR_VARIABLE_SIZED from mercury_std.h to
	mercury_types.h, and avoid the #include of mercury_std.h in
	mercury_types.h that caused problems from the configure script.
2003-06-17 09:42:31 +00:00
Simon Taylor
8c0564c2cd Fix bugs in the handling of signals with `mmc --make'.
Estimated hours taken: 1.5
Branches: main, release

Fix bugs in the handling of signals with `mmc --make'.

compiler/process_util.m:
	Reset the signal handlers in the child to the defaults
	so that SIGTERM is not ignored.

	Don't infinitely loop if the child ignores SIGTERM.

runtime/mercury_signal.{c,h}:
	Add a function MR_init_signal_action() which initializes a
	MR_signal_action suitable for passing to MR_set_signal_action().

runtime/mercury_std.h:
	Fix a #include in the wrong place which caused MR_is_eintr
	to always fail.
2002-11-21 06:31:20 +00:00
Simon Taylor
f7e5c7c62e Only refer to EINTR if it is defined.
Estimated hours taken: 1
Branches: main

Only refer to EINTR if it is defined.

runtime/mercury_std.h:
	Add a macro MR_is_eintr which tests whether its
	argument is EINTR, or returns false if EINTR
	not undefined.

trace/mercury_trace_internal.c:
compiler/process_util.m:
	Use MR_is_eintr.
2002-11-09 13:18:40 +00:00
Fergus Henderson
315c69eee3 Use regparm(2) instead of regparm(3), since regparm(3) can inhibit
Estimated hours taken: 0.25
Branches: main

runtime/mercury_std.h:
	Use regparm(2) instead of regparm(3), since regparm(3) can inhibit
	GCC's tail recursion optimization.
2002-10-14 03:19:58 +00:00
Fergus Henderson
c47975f620 Use int' rather than char' for MR_bool, since GCC has trouble
Estimated hours taken: 1
Branches: main

Use `int' rather than `char' for MR_bool, since GCC has trouble
with tail call optimization for functions that return `char'
(see <http://gcc.gnu.org/ml/gcc/2002-09/msg00632.html>).

mercury/runtime/mercury_std.h:
mercury/compiler/mlds_to_gcc.m:
	Change definition of MR_bool to use int rather than char.

mercury/runtime/mercury_std.h:
	Add a new typedef MR_small_bool, which is defined as char,
	for use when you need to optimize space.  Currently not used.

mercury/runtime/mercury_grade.h:
	Increment binary compatibility version.
	This is needed due to the change in the size of MR_bool.

gcc/mercury/mercury-gcc.c:
	Define boolean_type to have the same size as int, rather than
	default to the smallest possible size (one byte).
2002-09-16 19:03:56 +00:00
Zoltan Somogyi
bac4b47f2a Harmonize the treatment of the builtin types by the runtime system across
Estimated hours taken: 36
Branches: main

Harmonize the treatment of the builtin types by the runtime system across
the MLDS and LLDS C backends. (Their treatment by the .NET and Java backends
is unchanged, at least for now.)

Previously, the RTTI data structures and unify and compare predicates for the
builtin types were defined in runtime/mercury.c for the MLDS backend but in
library/{builtin,private_builtin,type_desc}.m for the LLDS backend. This
make several kinds of maintenance difficult, and more likely to be forgotten.
The two backends also had their generic unify/compare code in different modules
(mercury.c and mercuy_ho_call.c) and used distinct macros for defining RTTI
data structures. This change fixes those problems by defining a consistent
set of macros (with backend-specific implementations but backend-independent
semantics), concentrating the definitions of all the RTTI structures and of all
the unify and compare predicates for builtin types in a new module in the
runtime, mercury_builtin_types.[ch], and concentrating all the generic
unify/compare predicates in mercury_ho_call.[ch].

This change also makes the runtime use consistently module qualified names
for the RTTI data structures for the builtin types. Since they are not module
qualified by the Mercury compiler, we module qualify them by macros that map
the mmc-generated names to the ones expected by the runtime system. This makes
it easier to use the same macros in LLDS and MLDS grades.

runtime/mercury_builtin_types.[ch]:
	New module to contain all the C code for the implementation of
	unify and compare predicates for the builtin types. Its contents
	comes from mercury.c in the runtime (for the MLDS C backend) and
	builtin.m, private_builtin.m and type_desc.m in the library (for the
	LLDS C backend).

	The unify/compare predicates for tuples now report errors. This is
	necessary because the tuple is a variable arity constructor. Their
	previous implementations for the MLDS backend relied on only being
	called from the generic unify/compare routines with a nonstandard
	interface, being passed a typeinfo for the tuple type, rather than
	the typeinfos for the arguments of the type constructor. This worked
	because we don't currently specialize unifies/compares of tuple types,
	but was a potential problem if we ever started to do such
	specialization. The fix is to handle tuples in the generic
	unify/compare routines, just as in the LLDS backend.

runtime/mercury_ho_call.c:
	Move the generic unify/compare routines for the MLDS backend here
	from mercury.c.

	Conform to the coding standard wrt indentation.

runtime/mercury_ho_call.h:
	Declare the generic unify/compare routines for both backends.

	Delete a typedef that now needs to be in mercury_types.h to avoid
	circular dependencies.

runtime/mercury_type_info.h:
	Use the same macros for defining type_ctor_info structures for the MLDS
	and LLDS backends.

	This required moving the definitions of MR_UnifyFunc_N and
	MR_CompareFunc_N here from mercury.c.

runtime/mercury_hlc_types.h:
	A new file containing definitions of types needed by the MLDS C
	backend. These definitions used to be in mercury.h, but now they are
	needed in mercury_type_info.h, a header file that doesn't and shouldn't
	include mercury.h. They can't easily be put in mercury_types.h because
	they depend on mercury_std.h, and we are not allowed to include
	mercury_std.h in mercury_types.h.

runtime/mercury.h:
	Delete the definitions of the C types representing type_info and
	pseudo_type_infos, since these are now in mercury_type_info.h.
	#include mercury_type_info.h.

	Delete the definitions now in mercury_hlc_types.h.

runtime/mercury.c:
	Delete the definitions of the C types representing unify and compare
	predicates, since these are now in mercury_type_info.h.

runtime/mercury_bootstrap.h:
	Module qualify the RTTI data structures of the builtin types, since
	it makes it easier to use the same macros to define RTTI structures
	in the LLDS and MLDS backend. (Previously, mercury_bootstrap.h had
	macros to delete such module qualification for the variable arity
	types.)

runtime/mercury_types.h:
	Move some type definitions from mercury_ho_call.h and
	mercury_deep_profiling.h to mercury_types.h to prevent problems
	with circular dependencies between header files.

runtime/mercury_debug.h:
	Delete a #include to prevent a circular dependency.

runtime/mercury_profiling_builtin.[ch]:
	A new module containing the {call,exit,redo,fail} port predicates
	for deep profiling, moved here from library/profiling_builtin.m.
	They are referred to by the implementations of the unify and compare
	predicates of builtin types, and thus they need to be in the runtime
	directory to avoid references from the runtime to the library.

runtime/Mmakefile:
	Add the new files.

tools/make_port_code:
	A script to generate runtime/mercury_profiling_builtin.[ch] fully
	automatically.

library/array.m:
	Use the new backend-independent macros to reduce the amount of code
	that was duplicated for the two backends.

library/builtin.m:
library/private_builtin.m:
library/type_desc.m:
	Delete RTTI structures and unify and compare predicates
	that are now in runtime/mercury_builtin_types.c.

library/profiling_builtin.m:
	Replace the definitions of the predicates implementing the
	{call,exit,redo,fail} port predicates with external declarations.

trace/mercury_trace_vars.c:
	Use a now backend-independent macro to refer to a type_ctor_info.

trace/Mmakefile:
	Do not define MERCURY_BOOTSTRAP_H, since mercury_bootstrap.h now
	contains some definitions needed by code in the trace directory.
	Replace it with MR_NO_BACKWARDS_COMPAT.

util/mkinit.c:
	Module qualify the references to the RTTI structures of builtin types,
	since the generated _init.c files don't include mercury_bootstrap.h.
	Note that after this change has bootstrapped, we should be able to
	delete those references, since they were only needed to give the
	runtime access to the addresses of RTTI structures that used to be
	defined in the library, but are now defined in the runtime.
2002-08-09 05:26:56 +00:00
Simon Taylor
b7c4a317e9 Add MR_ prefixes to the remaining non-prefixed symbols.
Estimated hours taken: 4
Branches: main

Add MR_ prefixes to the remaining non-prefixed symbols.

This change will require all workspaces to be updated
The compiler will start generating references to MR_TRUE,
MR_bool, etc., which are not defined in the old runtime
header files.

runtime/mercury_std.h:
	Add MR_ prefixes to bool, TRUE, FALSE, max, min,
	streq, strdiff, strtest, strntest, strneq, strndiff,
	strntest, NO_RETURN.

	Delete a commented out definition of `reg'.

runtime/mercury_tags.h:
	Add an MR_ prefix to TAGBITS.

configure.in:
runtime/mercury_goto.h:
runtime/machdeps/i386_regs.h/mercury_goto.h:
	Add an MR_ prefix to PIC.

runtime/mercury_conf_param.h:
	Allow non-prefixed PIC and HIGHTAGS to be defined on
	the command line.

runtime/mercury_bootstrap.h:
	Add backwards compatibility definitions.

RESERVED_MACRO_NAMES:
	Remove the renamed macros.

compiler/export.m:
compiler/ml_code_gen.m:
	Use MR_bool rather than MR_Bool (MR_Bool is
	meant to be for references to the Mercury type
	bool__bool).

runtime/mercury_types.h:
	Add a comment the MR_Bool is for references to
	bool__bool.

*/*.c:
*/*.h:
*/*.m:
	Add MR_ prefixes.
2002-02-18 07:01:33 +00:00
Fergus Henderson
b5b81c7af7 Fix a bug reported by Michael Cameron <Michael.Cameron@general.monash.edu.au>,
Estimated hours taken: 2
Branches: main

Fix a bug reported by Michael Cameron <Michael.Cameron@general.monash.edu.au>,
where we were not handling inline functions correctly for C99.

runtime/mercury_std.h:
	- Document the MR_INLINE and MR_EXTERN_INLINE macros.
	- Fix a bug where MR_EXTERN_INLINE was defined wrongly for C99.
	- Add MR_OUTLINE_DEFN(), for providing out-of-line definitions
	  of inline functions declared with MR_EXTERN_INLINE; previously
	  this was done in a non-portable way that worked with GCC but
	  didn't work with C99.
	- Add MR_STATIC_INLINE, for inline functions used only within a
	  single translation unit -- currently not used, but should be
	  there for completeness.

runtime/mercury.c:
	Use MR_OUTLINE_DEFN() rather than #ifdef __GNUC__.
2001-12-27 13:17:12 +00:00
Fergus Henderson
cd7cb34aac Fix a conflict with `bool' that broke the GCC back-end in grade hlc.gc.
Estimated hours taken: 1
Branches: main

Fix a conflict with `bool' that broke the GCC back-end in grade hlc.gc.
This showed up after I updated it to use GCC 3.0 sources.

(N.B. A better solution might be to rename our `bool' as something
else, e.g. `MR_bool'.)

runtime/mercury_std.h:
	If IN_GCC is defined, #include the GCC header files "config.h"
	and "system.h" before checking whether bool is defined.
	This is needed to ensure that we get consistenty get GCC's definition
	of `bool'.

compiler/gcc.m:
	Don't include "config.h" and "system.h", since they're already included
	by mercury_std.h, and because these header files can't be included twice.
2001-07-26 14:49:03 +00:00
Zoltan Somogyi
04e614485d Implement deep profiling; merge the changes on the deep2 branch back
Estimated hours taken: 500
Branches: main

Implement deep profiling; merge the changes on the deep2 branch back
onto the trunk.

The main documentation on the general architecture of the deep profiler
is the deep profiling paper.

doc/user_guide.texi:
	Document how to use the deep profiler.

deep_profiler:
deep_profiler/Mmakefile:
	A new directory holding the deep profiler and its mmakefile.

Mmakefile:
	Add targets for the new directory.

	Add support for removing inappropriate files from directories.

deep_profiler/interface.m:
	The deep profiler consists of two programs: mdprof_cgi.m, which acts
	as a CGI "script", and mdprof_server.m, which implements the server
	process that the CGI script talks to. Interface.m defines the
	interface between them.

script/mdprof.in:
	A shell script template. ../configure uses it to generate mdprof,
	which is a wrapper around mdprof_cgi that tells it how to find
	mdprof_server.

deep_profiler/mdprof_cgi.m:
	The CGI "script" program.

deep_profiler/mdprof_server.m:
	The top level predicates of the server.

deep_profiler/profile.m:
	The main data structures of the server and their operations.

deep_profiler/read_profile.m:
	Code for reading in profiling data files.

deep_profiler/startup.m:
	Code for post-processing the information in profiling data files,
	propagating costs from procedures to their ancestors and performing
	various kinds of summaries.

deep_profiler/server.m:
	Code for responding to requests from the CGI script.

deep_profiler/cliques.m:
	Code to find cliques in graphs.

deep_profiler/array_util.m:
deep_profiler/util.m:
	Utility predicates.

deep_profiler/dense_bitset.m:
	An implementation of (part of) the set ADT with dense bit vectors.

deep_profiler/measurements.m:
	Operations on profiling measurements.

deep_profiler/timeout.m:
	An implementation of a timeout facility.

deep_profiler/conf.m:
	Functions that depend on autoconfigured settings.

configure.in:
	Find out what command to use to find the name of the local host.

	Install deep profiling versions of the standard library along with the
	other profiling versions.

runtime/mercury_conf.h.in:
	Add some macros for deep_profiler/conf.m to use.

library/profiling_builtin.m:
runtime/mercury_deep_call_port_body.h:
runtime/mercury_deep_leave_port_body.h:
runtime/mercury_deep_redo_port_body.h:
	A new library module that implements deep profiling primitives.
	Some of these primitives have many versions, whose common code is
	factor is factored out in three new include files in the runtime.

compiler/deep_profiling.m:
	New module to perform the program transformations described in the
	paper.

compiler/notes/compiler_design.html:
	Document the new compiler module.

compiler/mercury_compiler.m:
	Invoke the new module in deep profiling grades. Allow global static
	data to be generated by deep_profiling.m.

compiler/options.m:
	Add options to turn on deep profiling and (for benchmarking purposes)
	control its implementation.

	Add an optiooption disable tailcall optimization in the LLDS backend,
	to help benchmarking deep profiling.

compiler/jumpopt.m:
compiler/optimize.m:
	Obey the option to disable tailcalls.

compiler/handle_options.m:
	Handle the implications of deep profiling.

compiler/modules.m:
	In deep profiling grades, automatically import profiling_builtin.m.

compiler/prog_util.m:
doc/Makefile:
library/library.m:
	Handle the new builtin module.

compiler/export.m:
	In deep profiling grades, wrap deep profiling code around exported
	procedures to handle the "unscheduled call" aspects of callbacks to
	Mercury from the foreign language.

compiler/higher_order.m:
profiler/demangle.m:
util/demangle.c:
	When creating a name for a higher-order-specialized predicate, include
	the mode number in the name.

compiler/add_trail_ops.m:
compiler/type_util.m:
	Move c_pointer_type from add_trail_ops to type_util, so it can also be
	used by deep_profiling.m.

compiler/hlds_goal.m:
	Add a new goal feature that marks a tail call, for use by
	deep_profiling.m.

compiler/hlds_pred.m:
	Add a new field to proc_info structures for use by deep_profiling.m.

	Add a mechanism for getting proc_ids for procedure clones.

	Remove next_proc_id, an obsolete and unused predicate.

compiler/hlds_data.m:
	Add a new cons_id to refer to the proc_static structure of a procedure.

compiler/bytecode_gen.m:
compiler/code_util.m:
compiler/dependency_graph.m:
compiler/hlds_out.m:
compiler/mercury_to_mercury.m:
compiler/ml_unify_gen.m:
compiler/opt_debug.m:
compiler/prog_rep.m:
compiler/rl_exprn.m:
compiler/switch_util.m:
compiler/unify_gen.m:
	Trivial changes to handle the new cons_id, goal feature and/or
	proc_info argument.

compiler/rtti.m:
	Add a utility predicate for extracting pred_id and proc_id from an
	rtti_proc_label, for use by hlds_out.m

compiler/layout.m:
compiler/layout_out.m:
compiler/llds.m:
compiler/llds_common.m:
	Add support for proc_static and call_site_static structures.

compiler/layout_out.m:
compiler/llds_out.m:
	Add code for the output of proc_static structures.

compiler/code_util.m:
	Make code_util__make_proc_label_from_rtti a function, and export it.

util/mkinit.c:
compiler/llds_out.m:
compiler/layout.m:
compiler/modules.m:
	Add support for a fourth per-module C function, for writing out
	proc_static structures (and the call_site_static structures they
	contains).

	Since proc_static structures can be referred to from LLDS code (and not
	just from other static structures and compiler-generated C code),
	reorganize the declarations of static structures slightly.

	Change the schema for the name of the first per-module C function
	slightly, to make it the addition of the fourth function easier.
	The scheme now is:

		mercury__<modulename>__init
		mercury__<modulename>__init_type_tables
		mercury__<modulename>__init_debugger
		mercury__<modulename>__write_out_proc_statics

	Improve formatting of the generated C code.

library/*.m:
runtime/mercury.c:
runtime/mercury_context.c:
runtime/mercury_engine.c:
runtime/mercury_ho_call.c:
runtime/mercury_tabling.c:
runtime/mercury_trace_base.c:
runtime/mercury_wrapper.c:
trace/mercrury_trace.[ch]:
trace/mercrury_trace_declarative.c:
trace/mercrury_trace_external.c:
trace/mercrury_trace_internal.c:
	Conform to the new scheme for initialization functions for hand-written
	modules.

compiler/mercury_compile.m:
library/benchmarking.m:
runtime/mercury_conf_param.h:
runtime/mercury.h:
runtime/mercury_engine.c:
runtime/mercury_goto.c:
runtime/mercury_grade.h:
runtime/mercury_ho_call.c:
runtime/mercury_label.[ch]:
runtime/mercury_prof.[ch]:
	Add an MR_MPROF_ prefix in front of the C macros used to control the
	old profiler.

compiler/handle_options.m:
runtime/mercury_grade.h:
scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/parse_grade_options.sh-subr:
	Make deep profiling completely separate from the old profiling system,
	by making the deep profiling grade independent of MR_MPROF_PROFILE_TIME
	and the compiler option --profile-time.

library/array.m:
library/builtin.m:
library/std_util.m:
runtime/mercury_hand_unify_body.h:
runtime/mercury_hand_compare_body.h:
	In deep profiling grades, wrap the deep profiling call, exit, fail
	and redo codes around the bodies of hand-written unification
	and comparison procedures.

	Make the reporting of array bounds violations switchable between
	making them fatal errors, as we currently, and reporting them by
	throwing an exception. Throwing an exception makes debugging code
	using arrays easier, but since exceptions aren't (yet) propagated
	across engine boundaries, we keep the old behaviour as the default;
	the new behaviour is for implementors.

runtime/mercury_deep_profiling_hand.h:
	New file that defines macros for use in Mercury predicates whose
	definition is in hand-written C code.

library/exception.m:
runtime/mercury_exception_catch_body.h:
runtime/mercury_stacks.h:
	In deep profiling grades, wrap the deep profiling call, exit, fail
	and redo codes around the bodies of the various modes of builtin_catch.

	Provide a function that C code can use to throw exceptions.

library/benchmarking.m:
library/exception.m:
library/gc.m:
library/std_util.m:
runtime/mercury_context.[ch]:
runtime/mercury_engine.[ch]:
runtime/mercury_debug.c:
runtime/mercury_deep_copy.c:
runtime/mercury_overflow.h:
runtime/mercury_regs.h:
runtime/mercury_stacks.h:
runtime/mercury_thread.c:
runtime/mercury_wrapper.c:
	Add prefixes to the names of the fields in the engine and context
	structures, to make code using them easier to understand and modify.

runtime/mercury_deep_profiling.[ch]:
	New module containing support functions for deep profiling and
	functions for writing out a deep profiling data file at the end of
	execution.

runtime/mercury_debug.[ch]:
	Add support for debugging deep profiling.

	Add support for watching the value at a given address.

	Make the buffered/unbuffered nature of debugging output controllable
	via the -du option.

	Print register contents only if -dr is specified.

runtime/mercury_goto.h:
runtime/mercury_std.h:
	Use the macros in mercury_std.h instead of defining local variants.

runtime/mercury_goto.h:
runtime/mercury_stack_layout.h:
runtime/mercury_stack_trace.c:
runtime/mercury_tabling.c:
trace/mercury_trace.c:
trace/mercury_trace_declarative.c:
trace/mercury_trace_external.c:
trace/mercury_trace_vars.c:
	Standardize some of the macro names with those used in the debugger
	paper.

runtime/mercury_heap.h:
	Add support for memory profiling with the deep profiler.

runtime/mercury_prof.[ch]:
runtime/mercury_prof_time.[ch]:
	Move the functionality that both the old profiler and the deep profiler
	need into the new module mercury_prof_time. Leave mercury_prof
	containing stuff that is only relevant to the old profiler.

runtime/mercury_prof.[ch]:
runtime/mercury_strerror.[ch]:
	Move the definition of strerror from mercury_prof to its own file.

runtime/mercury_wrapper.[ch]:
	Add support for deep profiling.

	Add suppory for controlling whether debugging output is buffered or
	not.

	Add support for watching the value at a given address.

runtime/Mmakefile:
	Mention all the added files.

scripts/mgnuc.in:
	Add an option for turning on deep profiling.

	Add options for controlling the details of deep profiling. These
	are not documented because they are intended only for benchmarking
	the deep profiler itself, for the paper; they are not for general use.

tools/bootcheck:
	Compile the deep_profiler directory as well as the other directories
	containing Mercury code.

	Turn off the creation of deep profiling data files during bootcheck,
	since all but one of these in each directory will be overwritten
	anyway.

	Add support for turning on --keep-objs by default in a workspace.

tools/speedtest:
	Preserve any deep profiling data files created by the tests.

trace/mercury_trace.c:
	Trap attempts to perform retries in deep profiling grades, since they
	would lead to core dumps otherwise.

util/Mmakefile:
	Avoid compile-time warnings when compiling getopt.

tests/*/Mmakefile:
tests/*/*/Mmakefile:
	In deep profiling grades, switch off the tests that test features
	that don't work with deep profiling, either by design or because
	the combination hasn't been implemented yet.
2001-05-31 06:00:27 +00:00
Fergus Henderson
499ffadbc3 Connect the Mercury compiler to the GCC back-end.
Estimated hours taken: 120

Connect the Mercury compiler to the GCC back-end.
These changes give us a version of the Mercury compiler which
compiles to assembler without going via any intermediate files.
This version generates GCC's `tree' data type, and then calls functions
in the GCC middle-end to convert that to GCC's RTL (Register Transfer
Language) and to invoke the rest of the GCC middle-end and back-end
to compile it to assembler.

RATIONALE

The main advantage is improved compilation speed.

(The improvement is not huge, since the current front-end is so slow,
but improving the speed of the back-end increases the incentive to
improve the speed of the front-end, since it means that any increases
in the speed of the front-end will get bigger overall speedups.)

Another advantage is that it gives us more opportunity to give the GCC
back-end information about how to optimize the code that we generate.
For example:
	- We can tell GCC when it is safe to treat function calls
	  as tail calls.  (The gcc back-end already has some support
	  for doing tail calls.  But its check to determine when
	  it is safe to do them is much too conservative for Mercury.
	  I've been working on extending the gcc back-end infrastructure
	  so that front ends can tell the gcc back-end when it is safe.)
	- We can use `__builtin_{set,long}jmp' rather than ordinary
	  `{set,long}jmp'.  (We can also do this for the C back-end,
	  as it happens, since those are supported in GNU C too, but
	  I wouldn't have found out about it if not for doing this
	  back-end.)  Or we can use gcc's exception handling;
          the gcc developers have told me that using exception
	  handling may be more efficient on some platforms.
	- We can mark GC_malloc as an allocation function,
	  so that GCC knows that stuff allocated with it won't
	  alias other pointers.
	- In general we could give GCC more information about aliasing.
	  I haven't investigated this much yet, but I think the GCC
	  back-end has support for keeping track of alias sets and
	  recording which set each pointer points to and which sets
	  may be subsets of which other sets.

Another advantage is that it provides a demonstration of how to
compile logic languages or functional languages using the GNU C
back-end.  This may be useful to researchers or open-source developers
who are working on other languages.

It is also good public relations, because it removes one more
barrier towards acceptance of Mercury.  Some people want a language
implementation that has a "native code compiler", and don't want one
that compiles via C.  These people may be more willing to consider
Mercury now.

gcc/mercury:
	New directory.
	This contains the C side of the Mercury <-> GCC interface.

gcc/mercury/Make-lang.in:
gcc/mercury/config-lang.in:
gcc/mercury/lang-specs.h:
	Makefile/configure/specs fragments (respectively)
	that are required by GCC.

gcc/mercury/lang-options.h:
	Documents the Mercury-specific gcc options,
	in particular the `--mmc-flag=' option.

gcc/mercury/mercury-gcc.c:
gcc/mercury/mercury-gcc.h:
	This is the "meat" on the C side of the Mercury <-> GCC interface.
	These files provide the C code that GCC requires of each
	language front-end.  They also define some routines for
	building parts of the GCC `tree' data structure that are
	used by the Mercury compiler.

gcc/mercury/Makefile:
	A Makefile which just runs `make mercury' in the parent directory.
	Just for convenience.

gcc/mercury/README:
gcc/mercury/ChangeLog:
	Some (very basic) documentation.

gcc/mercury/test.m:
	A sample Mercury module, to serve as a simple test case.

gcc/mercury/testmercury.c:
	C driver program for the test Mercury module.

mercury/compiler/gcc.m:
	New file.  This is an interface to the tree data structure defined
	in gcc/tree.h, and to functions for manipulating that data structure
	which are defined in gcc/mercury/mercury-gcc.c and in other parts
	of the GCC back-end.  It's almost entirely composed of simple
	pragma c_code routines that each just call a single C function.

mercury/compiler/mlds_to_gcc.m:
	New file.  This converts the MLDS into the gcc tree representation
	whose interface is in gcc.m, using the routines defined in gcc.m.
	This is the "meat" on the Mercury side of the Mercury <=> GCC interface.

mercury/compiler/globals.m:
	Define new target `asm', for compiling directly to assembler
	(without any intermediate files), via the gcc back-end.

mercury/compiler/handle_options.m:
	`--target asm' implies `--high-level-code'.

mercury/compiler/mercury_compile.m:
	Handle `--target asm' by invoking mlds_to_gcc.m.

mercury/main.c:
	New file, containing main() that calls mercury_main().

mercury/compiler/Mmakefile:
	Add C2INITFLAGS=--library, so that we can link `libmercury_compile.a'
	as a library without main().  For the mercury_compile executable,
	get main by linking in ../main.o.

	Add `libmmc' target, for building libmercury_compile.a and
	mercury_compile_init.a.

	Add the appropriate `-D' and `-I' options to CFLAGS-gcc so that we
	can compile gcc.m.

mercury/runtime/mercury.c:
	Define out-of-line copies of MR_box_float() and MR_unbox_float(),
	so that the new `--target asm' back-end can generate calls to them.

mercury/runtime/mercury.h:
mercury/runtime/mercury_heap.h:
	Add comments warning about code duplication between
	the inline and out-of-line versions of various functions.

mercury/Makefile:
mercury/Mmakefile:
	Add `libmmc' target, for use by gcc/mercury/Make-lang.in.

mercury/runtime/mercury_std.h:
	When IN_GCC is defined, use safe_ctype.h rather than
	ctype.h, since the latter conflicts with the GCC headers.

	Comment out the definition of the `reg' macro, since
	that too conflicts with the GCC headers.

mercury/runtime/mercury_dlist.c:
mercury/runtime/mercury_hash_table.c:
mercury/runtime/mercury_stacks.h:
	Delete unnecessary uses of the `reg' macro.
2001-01-10 10:57:25 +00:00
Fergus Henderson
e05f2a4780 Add support for using a different C calling convention for the
Estimated hours taken: 16

Add support for using a different C calling convention for the
C functions generated by the MLDS back-end, if you're on x86
and you define MR_USE_REGPARM.  The code do to this uses GNU C's
function attributes extension; it will only work if you have
the latest snapshot versions of gcc.  So MR_USE_REGPARM is
not enabled by default.

compiler/ml_call_gen.m:
	For higher-order calls and class method calls, assign the
	function pointer to a local variable.  This is needed for
	current versions of gcc, since gcc doesn't support function
	attributes on function types in function pointer type casts.

compiler/mlds_to_c.m:
	Output "MR_CALL" in function declarations.
	Also output a reference to MR_GRADE_VAR, like we do for the
	LLDS back-end.

runtime/mercury_std.h:
	Define MR_CALL.  This is a macro that can expand to some
	implementation-specific C extension to specify the
	calling convention used for the MLDS back-end.
	E.g. for gcc, on x86, if MR_USE_REGPARM is defined it
	expands to `__attribute__((__regparm__(3), __stdcall__))'.

runtime/mercury_conf_param.h:
	Document MR_USE_REGPARM.

runtime/mercury_grade.h:
	Encode the setting of MR_USE_REGPARM in the mangled grade name.

runtime/mercury_types.h:
runtime/mercury.h:
runtime/mercury.c:
runtime/mercury_wrapper.h:
runtime/mercury_wrapper.c:
util/mkinit.c:
library/array.m:
library/builtin.m:
library/exception.m:
	Use MR_CALL for functions that should have the
	Mercury calling convention.

runtime/mercury_types.h:
runtime/mercury.h:
	Move the definition of MR_Cont and MR_NestedCont from
	mercury_types.h to mercury.h.  This was needed to avoid a
	cyclic header dependency problem and is also a good idea
	anyway, since MR_Cont and MR_NestedCont are specific to the
	MLDS back-end.
2000-12-03 02:23:03 +00:00
Zoltan Somogyi
090552c993 Make everything in the runtime use MR_ prefixes, and make the compiler
Estimated hours taken: 10

Make everything in the runtime use MR_ prefixes, and make the compiler
bootstrap with -DMR_NO_BACKWARDS_COMPAT.

runtime/mercury_*.[ch]
	Add MR_ prefixes to all functions, global variables and almost all
	macros that could pollute the namespace. The (intentional) exceptions
	are

	1. some function, variable, type and label names that already start
	   with MR_, mercury_, Mercury or _entry;
	2. some standard C macros in mercury_std.h;
	3. the macros used in autoconfiguration (since they are used in scripts
	   as well as the runtime, the MR_ prefix may not be appropriate for
	   those).

	In some cases, I deleted things instead of adding prefixes
	if the "things" were obsolete and not user visible.

runtime/mercury_bootstrap.h:
	Provide MR_-less forms of the macros for bootstrapping and for
	backward compatibility for user code.

runtime/mercury_debug.[ch]:
	Add a FILE * parameter to a function that needs it.

compiler/code_info.m:
compiler/export.m:
compiler/fact_table.m:
compiler/llds.m:
compiler/llds_out.m:
compiler/pragma_c_gen.m:
compiler/trace.m:
	Add MR_ prefixes to the C code generated by the compiler.

library/*.m:
	Add MR_ prefixes to handwritten code.

trace/mercury_trace_*.c:
util/mkinit.c:
	Add MR_ prefixes as necessary.

extras/concurrency/semaphore.m:
	Add MR_ prefixes as necessary.
2000-11-23 02:01:11 +00:00
Fergus Henderson
24ef39876c Reorganize some code in the runtime.
Estimated hours taken: 2

Reorganize some code in the runtime.

These changes were motivated in part by the desire to keep the runtime
for the MLDS back-end as well separated from the complications of the
current LLDS back-end as possible.

runtime/mercury_std.h:
runtime/mercury_misc.h:
	Move the definition of NO_RETURN from miscury_misc.h
	to mercury_std.h, since it's better to define all the
	compiler-dependent macros like this in one spot.

runtime/Mmakefile:
runtime/mercury_misc.h:
runtime/mercury_misc.c:
runtime/mercury_debug.h:
runtime/mercury_debug.c:
	Move the debugging stuff from mercury_misc.{h,c}
	to mercury_debug.{h,c}.  Note that mercury_debug.c
	is a new file.

runtime/mercury_misc.h:
runtime/mercury_misc.c:
runtime/mercury_reg_workarounds.h:
runtime/mercury_reg_workarounds.c:
	Move MR_memcpy() from mercury_misc.{h,c} to
	mercury_reg_workarounds.{h,c}.

runtime/mercury_stack_trace.c:
runtime/mercury_array_macros.h:
runtime/mercury_tabling.h:
	Add/remove/modify the #include directives
	to reflect the above-mentioned changes.
2000-05-08 14:01:02 +00:00
Fergus Henderson
a1b02cfc47 More fixes for the MLDS back-end.
Estimated hours taken: 8

More fixes for the MLDS back-end.

compiler/ml_code_gen.m:
library/private_builtin.m:
runtime/mercury.h:
	Don't treat unsafe_type_cast as an inline builtin, since the
	code generated for it as an inline builtin is not type-correct.
	Instead, declare `unsafe_type_cast/2' as external in
	library/private_builtin.m, so that the generated code
	for this module does not try to declare or define it.
	And in runtime/mercury.h, define unsafe_type_cast/2 as a
	macro / inline function.

library/private_builtin.m:
	Fix a bug in my previous change: add a missing cast.

runtime/mercury_type_info.h:
	Declare the constants mercury_data___type_ctor_info_{pred,func}_0;
	used by the MR_TYPE_CTOR_INFO_HO_{FUNC,PRED} macros.
	Add some conditional code so that those macros do the right
	thing for the MLDS back-end.

runtime/mercury_deep_copy.c:
runtime/mercury_tabling.c:
library/std_util.m:
	Delete the now unnecessary declarations of
	mercury_data___type_ctor_info_{pred,func}_0;
	these are now declared in runtime/mercury_type_info.h.

library/std_util.m:
	Delete the redundant definitions of the MR_TYPE_CTOR_INFO_*()
	macros; these were defined identically in runtime/mercury_type_info.h.
	Also use MR_TYPE_CTOR_INFO_HO_{FUNC,PRED} rather than hard-coding
	their definitions.

runtime/mercury.h:
runtime/mercury.c:
	Update to reflect recent RTTI changes.
	In particular, use MR_TypeCtorInfo rather than MR_BaseTypeInfo,
	and delete the code for the index/2 predicate.

runtime/mercury_std.h:
runtime/mercury.h:
	Move the definition of MR_INLINE and MR_EXTERN_INLINE
	from mercury.h to mercury_std.h, since they're used in
	mercury_heap.h.

runtime/mercury.c:
	Wrap `#ifdef MR_HIGHLEVEL_CODE' around the whole of this file,
	so that it does the right thing in LLDS-based grades.

runtime/mercury_heap.h:
runtime/mercury_imp.h:
runtime/mercury_deep_copy.h:
runtime/mercury_layout_util.h:
	Add some missing `#include' directives.

runtime/Mmakefile:
	Add mercury.c and mercury.h to the respective file lists.
	Split the HDRS variable into HDRS and BODY_HDRS, so that
	`mmake check_headers' does not assume that *_body.h
	will be syntactically correct.
2000-05-05 10:14:50 +00:00
Fergus Henderson
87324b814c Improve the static type checking and readability of
Estimated hours taken: 1.5

Improve the static type checking and readability of
some of the macros that we define, by using a new
MR_CHECK_EXPR_TYPE() macro.

runtime/mercury_std.h:
	Define the MR_CHECK_EXPR_TYPE() macro.

runtime/mercury_type_info.h:
library/std_util.m:
	Make use of it.

library/std_util.m:
	Add a few comments, and reorder some macro definitions
	do improve readability.  Delete an incorrect XXX comment.

runtime/mercury_make_type_info_body.h:
	Add a type cast, where we were using an MR_TypeInfo
	as an MR_PseudoTypeInfo.

runtime/mercury_type_info.c:
	Ensure that the parameter that we pass to
	MR_TYPE_VARIABLE_IS_UNIV_QUANT() has type
	`MR_PseudoTypeInfo', rather than `Unsigned'.
2000-04-02 06:37:22 +00:00
Zoltan Somogyi
4ccc3b32ac Cleanup of the type_ctor_infos and their components, to achieve two goals.
Estimated hours taken: 65

Cleanup of the type_ctor_infos and their components, to achieve two goals.
First, the new data structure is defined in strongly typed C, with only
two unions, whereas the old data structure was defined by a bunch of macros
that used casts all over the place. The new design should therefore make it
significantly easier to debug code that uses RTTI, and to get it right in
the first place. Second, the new data structures are logically organized,
whereas the old ones had several bad features (such as fixed fields coming
after variable-length arrays in "structures") required by backward
compatibility.

For the time being, the runtime system will be able to handle type_ctor_infos
using both the old and the new data structures, which are distinguished by
the type_ctor_info's version number.

To minimize the disruption caused by such bootstrapping, this change also
incorporates an improvement in the RTTI: for most pseudo_type_infos included
in the RTTI, it records information that allows the runtime system to tell
whether the pseudo_type_info is ground or not; if it is, then the runtime
need not scan the pseudo_type_info looking for type parameters to expand.
Based on statistics I have gathered, this will eliminate between half and two
thirds of all such scans when we do unification and comparison by RTTI.

This change does not impact the structures of typeinfos, base_typeclass_infos
or typeclass_infos.

runtime/mercury_type_info.h:
	Define the C types for the new type_ctor_info components.

	Update the C type for type_ctor_infos themselves, and the macros
	that act on it.

	Centralize the list of files that depend on type info representation
	here.

	Make the names of the two macros that give the number of (all kinds of)
	type info vars and the number of existential type info vars consistent.

runtime/mercury_std.h:
	Change a comment to refer to one of these renamed macros by its new
	name.

compiler/rtti.m:
compiler/rtti_out.m:
	New files: rtti.m defines new types that allow us to construct
	Mercury representations of the C structures we want to emit,
	and rtti_out.m converts those representations to C definitions.
	These files are intended to be independent of whether the backend
	is LLDS or MLDS. At the moment, there are several vestiges that
	tie them to LLDS, mostly due to (a) the lack of a shared common
	infrastructure between llds_out.m and mlds_to_c.m, and (b)
	the continued use of the old representation of (pseudo-) typeinfos
	as rvals. These concerns will be addressed in a future change.

compiler/llds.m:
	Update the definition of the comp_gen_c_data and data_addr types
	to account for the new RTTI structures.

compiler/llds_out.m:
	Update the code to output comp_gen_c_data and data_addr values
	to account for the new RTTI structures.

	Make some parts of the code more modular, so that rtti_out.m
	can use what used to be selected parts of predicates.

	Export several predicates for use by rtti_out.m. Some of these
	should later be moved to a file for infrastructure shared by
	llds_out.m and mlds_to_*.m. Others should be made internal again
	when the representation of typeinfos is made independent of the LLDS.

	Rename some predicates to better reflect their purpose.

compiler/base_type_layout.m:
compiler/base_type_info.m:
	These files are obsoleted by this change. They remain in CVS, but
	are no longer used. All of base_type_info.m has been moved into
	type_ctor_info.m, and so have the parts of base_type_layout.m
	that create the functors and layout structures inside type_ctor_infos;
	the remaining part of base_type_layout.m is now in pseudo_type_info.m.

compiler/pseudo_type_info.m:
	New file containing the code to create pseudo_type_infos from
	base_type_layout.m, slightly updated for the new compiler structure.

compiler/type_ctor_info.m:
        New module: almost total rewrite of the base_type_info.m and the
	relevant part of base_type_layout.m for the new data structure.

	Do not invoke base_typeclass_info.m, since the structures it creates
	are not parts of the type_ctor_infos.

compiler/ml_base_type_info.m:
	Comment out obsolete unfinished code. It should be replaced by
	calls to type_ctor_info, once type_ctor_info's dependence on LLDS
	has been eliminated.

compiler/hlds_module.m:
	Rename the data structure from which type_ctor_infos are generated.
	Delete the data structure from which type_ctor_layouts were generated,
	since it is redundant.

	Switch to using field names.

compiler/make_tags.m:
compiler/hlds_data.m:
	make_tags.m had code that duplicated much of the the functionality
	of an existing predicate in hlds_data.m. This change moves that
	predicate to hlds_data where it belongs, and gives it an appropriate
	name.

compiler/mercury_compile.m:
	Do not invoke the predicates that used to be in base_type_layouts
	directly; let type_ctor_info do it for the types for which it is
	appropriate.

	Do invoke base_typeclass_info directly.

compiler/dead_proc_elim.m:
compiler/llds_common.m:
compiler/opt_debug.m:
compiler/stack_layout.m:
compiler/unify_gen.m:
	Trivial changes to conform to the changes in the representation of
	compiler-generated C data.

compiler/notes/compiler_design.html:
	Updates to reflect the new files.

runtime/mercury_deep_copy_body.h:
runtime/mercury_tabling.c:
runtime/mercury_type_info.c:
	Provide alternate implementations of functionality that used the
	old functors and layout structures, to use the new ones instead
	if the relevant type_ctor_info's version number calls for it.
	In many cases, doing this cleanly required reducing the scopes of
	variables.

runtime/mercury_tabling.[ch]:
	Note where additional work on tabling of typeclass infos is needed,
	but do not do the work yet, since it would conflict with DJ's coming
	change.

library/std_util.m:
	Provide alternate implementations of functionality that used the
	old functors and layout structures, to use the new ones instead
	if the relevant type_ctor_info's version number calls for it.
	In many cases, doing this cleanly required reducing the scopes of
	variables.

	The predicates get_functor and construct take an integer argument
	that identifies a functor of a du type. The integer used to be
	the functor's ordinal number in the type definition, but this
	was not documented. It is now the functor's position in the list
	of the type's functors sorted first on name and then on arity.
	This functionality is potentially more useful, since io__read
	could do binary instead of linear search when looking for a given
	functor. This is an incompatibility, but a very minor one.

	Add a new predicate, get_functor_ordinal, to provide a way
	to convert lexicographic position into ordinal position.
	This is not used yet.

	Rename the two different kinds of variables named "info" so that
	one can tell them apart.

tests/hard_coded/construct.exp:
	Update the expected output of this test based on the new definition
	of the meaning of functor numbers in the get_functor and construct
	predicates in std_util.

tests/hard_coded/deep_copy.{m,exp}:
	Add some code to test the "type contains var" bit vector in du
	functor descriptions.

tests/hard_coded/existential_rtti.{m,exp}:
	Make the test case print out results as it goes along, to make it
	easier which subtask a core dump is coming from. Update the expected
	output accordingly.
2000-03-10 13:38:21 +00:00
Zoltan Somogyi
26caad3050 Remove type_ctor_layouts and type_ctor_functors where not needed.
Estimated hours taken: 8, plus about 12 hours by Tyson.

Remove type_ctor_layouts and type_ctor_functors where not needed.
Simplify type_ctor_layouts by removing code that generates (and
documentations for) particularly representations that are no longer used
now that we use type_ctor_reps.

Several files also had miscellaneous cleanups and documentation fixes,
the most important being the move of the type_ctor_info structures
for preds/funcs from runtime/mercury_type_info.c to library/builtin.m.

compiler/base_type_layout.m:
        Simplify documentation.

        Remove references to representations in type_ctor_layouts that
        are no longer used.compiler/base_type_layout.m:

compiler/base_type_info.m:
	Keep base_type_info__type_ctor_rep_to_int in sync with
	MR_TypeCtorRepresentation.

runtime/mercury_grade.h:
runtime/mercury_cpp.h:
	Move the definitions of MR_STRINGIFY and MR_PASTEn to the new file
	mercury_cpp.h. Add MR_PASTEn for several new values of n, for use by
	mercury_type_info.h.

runtime/mercury_type_info.h:
	Define macros for creating type_ctor_info structures for builtin types.
	These have NULL layout and functor fields.

	Remove several obsolete macros.

runtime/mercury_layout_util.c:
	Use the new macros for defining a dummy type_ctor_info.

runtime/mercury_deep_copy_body.h:
runtime/mercury_tabling.c:
	Modify the implementation of some RTTI functions to use the layout
	and functors structures only if they are defined.

runtime/mercury_type_info.c:
	Modify MR_collapse_equivalences to use the type_ctor_rep, not the
	functors indicator, to check for equivalence, since the latter is
	not guaranteed to be present.

	Move the type_ctor_info structure for preds/funcs to builtin.m.

library/array.m:
	Use these macros to define the type_ctor_info structure for array.

library/builtin.m:
	Use these macros to define the type_ctor_info structure for int,
	float, character, string, saved succip etc values, and for preds
	and funcs.

library/private_builtin.m:
	Use these macros to define the type_ctor_info structure for type_infos,
	type_ctor_infos, typeclass_infos and base_typeclass_infos.

	Move a c_header_code to the section that needs it.

library/std_util.m:
	Use the new macros to define the type_ctor_info structure for univ
	and for std_util's own type_info type.

	Modify the implementations of some RTTI predicates to use the
	layout and functors structures only if they are defined.
2000-01-19 09:45:23 +00:00
Fergus Henderson
88a513b580 Reorganize the routines for allocating and deallocating memory:
Estimated hours taken: 8

Reorganize the routines for allocating and deallocating memory:

runtime/mercury_std.h:
runtime/mercury_misc.c:
runtime/mercury_memory.h:
runtime/mercury_memory.c:
	- Put the routines in the proper place.
		Previously the declarations and definitions of the memory
		allocation/deallocation routines were spread amoungst
		all four of these files; I moved the ones in mercury_std.h
		and mercury_misc.c so that they are now all defined
		in mercury_memory.{h,c}
	- Avoid unnecessary duplication
		The following routines did exactly the same thing,
		modulo bugs(!):
			allocate_bytes()	and newmem()
			deallocate_bytes()	and oldmem()
			make()			and allocate_object()
			make_many()		and allocate_array()
	- Use appropriate names.
		I added `MR_' prefixes, and ensured that macros that are not
		function-like macros use all uppercase.  I also used a more
		consistent naming scheme.
		Previously the names used were
			(1) checked_malloc, checked_realloc
			(2a) allocate_bytes, deallocate_bytes, reallocate_bytes,
				allocate_object, allocate_array, resize_array
			(2b) newmem, oldmem, resizemem,
				make, make_many, resize_many
		The new names are
			(1) MR_malloc, MR_free, MR_realloc,
				MR_NEW, MR_NEW_ARRAY, MR_RESIZE_ARRAY
			(2) MR_GC_malloc, MR_GC_free, MR_GC_realloc,
				MR_GC_NEW, MR_GC_NEW_ARRAY, MR_GC_RESIZE_ARRAY

runtime/*.[ch]:
trace/*.[ch]:
library/array.m:
library/benchmarking.m:
library/io.m:
library/std_util.m:
extras/odbc/odbc.m:
extras/aditi/aditi.m:
	Use the new names.
1999-10-18 15:47:39 +00:00
Fergus Henderson
8e8a921f16 Fix some problems caused by the recently added autoconf tests for
Estimated hours taken: 2

Fix some problems caused by the recently added autoconf tests for
determining how to handle variable-sized arrays.

runtime/mercury_conf_param.h:
runtime/mercury_std.h:
	Change the definition of MR_VARIABLE_SIZED so that it uses
	compile-time checks rather than autoconf-based configuration.
	Using autoconf-based configuration for compiler-dependent
	properties breaks the instructions for using compilers other
	than gcc in the Mercury User's Guide; in particular, with the
	autoconf approach, if you had installed Mercury using GNU C
	(or if you were using a binary distribution that was configured
	with GNU C), and then you set the environment variable
	MERCURY_C_COMPILER to point to a C compiler that doesn't
	support GNU-style variable-length arrays (e.g. lcc), then you
	would get compile errors.

	Also move the definition of MR_VARIABLE_SIZED from
	mercury_conf_param.h to mercury_std.h (it never belonged
	in the former location, IMHO, since it was only ever
	a definition that _used_ configuration parameters rather
	than being a configuration parameter itself).

configure.in:
runtime/mercury_conf.h.in:
	Delete the configuration tests and configuration macros for
	variable-sized arrays, since the above change means these are
	no longer needed.

runtime/mercury_stack_layout.h:
	Include mercury_std.h rather than mercury_conf_param.h
	for MR_VARIABLE_SIZED.
1999-04-22 06:14:00 +00:00
Zoltan Somogyi
8a0ceb49aa This checkin has several major purposes, set out in the sections below,
Estimated hours taken: 240

This checkin has several major purposes, set out in the sections below,
all connected with the implementation of the new debugger command set.

DOCUMENT NEW DEBUG COMMAND SET

doc/user_guide.texi:
	Add a new section on the debugger. The description of the commands
	is complete, but some of the background sections, and the section
	about how to build debuggable executables, are not yet done.

	Update the documentation of the tracing options.

doc/generate_mdb_doc:
	A new shell script that automatically converts some of the new
	sections of the user guide into the online documentation of the
	debugger.

doc/mdb_categories:
	The fixed initial part of the online documentation.

doc/Mmakefile:
	Add rules for creating mdb_doc, the file that is the online
	documentation of the debugger, and for installing it together
	with mdbrc.

Mmake.common.in:
	Define INSTALL_DOC_DIR for doc/Mmakefile.

scripts/mdbrc.in:
	A debugger command script that reads in the online documentation
	and then defines some standard aliases.

configure.in:
	Define the variable that scripts/mdb.in and scripts/mdbrc.in use
	to find the right files, and get configure to perform the
	substitutions.

configure.in:
scripts/mdb:
scripts/mdb.in:
	Replace mdb with mdb.in. Mdb is now created during configuration
	from mdb.in, filling in the name of the file that contains the default
	debugger initialization commands.

util/info_to_mdb.c:
	A program that does most of the work involved in automatically
	converting user guide sections into online documentation.
	(This couldn't easily be written in sh, because sh's read
	command has no notion of pushback.)

util/Mmakefile:
	Add info_to_mdb to the list of targets.

tools/bootcheck:
	Make sure that the tests in tests/debugger are executed with an
	initialization setup that is equivalent to what users will see
	by default.

REORGANIZE TRACING OPTIONS

compiler/globals.m:
compiler/handle_options.m:
compiler/options.m:
compiler/trace.m:
	Reorganize the handling of trace levels around the new options
	--trace-internal, --trace-redo, and --trace-return.

compiler/*.m:
	Use the new ways of getting at trace levels.

tests/hard_coded/typeclasses/Mmakefile:
	s/--trace all/--trace deep/

SUPPORT RETRY

compiler/trace.m:
	After every call to MR_trace(), emit code that checks whether it
	should jump away, and if yes, performs the jump. This is used to
	implement retry. (The debugger cannot execute the jump itself
	because it is in the wrong C stack frame.)

compiler/llds.m:
compiler/continuation_info.m:
compiler/stack_layout.m:
	Modify the data structures that record information about live
	value at program points, to record the identity of each variable.
	This is necessary for the implementation of the restart command,
	since we do not want to confuse two distinct variables just because
	they have the same name. For example, a variable whose name is X
	and number is 5 is now recorded in the name array as "5:X".

	Clean up the data structure a bit, so that we don't have to store
	dummy names for values that are not variables.

compiler/*.m:
	Minor changes to conform to the data structure changes.

runtime/mercury_stack_layout.h:
	Redefine an existing macro to strip away the initial number: prefix
	from the "name" of a variable (keeping its original function on
	changed data), and add a new one to access the raw unstripped data.

runtime/mercury_init.h:
runtime/mercury_wrapper.h:
	Update the prototype of MR_trace_{fake,real}, and the type of the
	global that points to them.

runtime/mercury_layout_util.h:
	Add an extra function, MR_get_register_number, for use by retry.

USE FIXED STACK SLOTS FOR TRACE INFO

compiler/code_gen.m:
compiler/code_info.m:
compiler/live_vars.m:
compiler/trace.m:
	If execution tracing is enabled, reserve the first few stack slots
	to hold the event number of the call event, the call number, the
	call depth, the redo layout structure address (if generating redo
	events) and the from_full flag at the time of call (if we are doing
	shallow tracing). By allocating the first four of these to fixed stack
	slots, the debugger knows where to look for them without having
	to be told. It finds out the location of the fifth, if needed,
	from a new slot in the proc layout structure. (It is not possible
	to allocate all five to fixed stack slots without wasting stack space
	in some cases.)

compiler/trace.m:
	Remove from the call to MR_trace the parameters that are now in fixed
	stack slots, since MR_trace can now look them up itself.

compiler/continuation_info.m:
compiler/stack_layout.m:
	Add an extra field to the proc_layout_info. If the module is shallow
	traced, this field says which stack slot holds the saved value of
	MR_from_full. If it is not shallow traced, this field says that
	there is no such stack slot.

runtime/mercury_stack_layout.h:
	Add macros for accessing the fixed stack slots holding the event
	number of the call event, the call number, the call depth, and,
	at a redo event, the redo layout structure address.

	Support the new field in proc layouts that gives the location of the
	from-full flag (if any).

runtime/mercury_trace_base.[ch]:
trace/mercury_trace.[ch]:
	Remove the call number and call depth arguments from MR_trace
	and its avatars, since this info is now in fixed stack slots
	in every procedure that can call MR_trace. This should reduce
	the size of the executable significantly, since there are lots
	of calls to MR_trace.

runtime/mercury_init.h:
runtime/mercury_wrapper.h:
	Update the prototype of MR_trace_{fake,real}, and the type of the
	global that points to them.

START NUMBERING FRAMEVARS FROM ONE

compiler/code_info.m:
compiler/live_vars.m:
compiler/llds_out.m:
compiler/trace.m:
	Start numbering framevars from 1 internally to the compiler;
	the runtime already starts from 1. This simplifies several tasks.

ADD REDO EVENTS

compiler/trace.m:
compiler/code_gen.m:
	Before the code that executes "succeed()", emit code to push a
	a temp nondet frame whose redoip points to a label in the runtime
	that calls MR_trace for a REDO event and then fails, provided
	--trace-redo is set.

compiler/llds.m:
	Add a new code address constant, do_trace_redo_fail, which stands
	for the address in the trace system to which calls MR_trace for
	the redo event and then fails.

compiler/trace.m:
compiler/llds_out.m:
	Provided we are doing redo tracing, fill in the slot that holds
	the layout information for the REDO event.

compiler/*.m:
	Minor changes to conform to handle the new code address constant.

browser/debugger_interface.m:
	Add redo to trace_port_type.

runtime/mercury_trace_base.[ch]:
	Add a C module containing the code that calls MR_trace for REDO
	events.

ENSURE THAT INPUT ARGUMENTS ARE ALWAYS VISIBLE

compiler/trace.m:
	When generating the set of live variables at internal ports,
	the variables that are in the pre-death set of the goal into which
	we are entering may not be available. However, the variables in the
	pre-death set that are also in the resume vars set will be available,
	so now include info about them in the layout structure for the event.
	Since with tracing the non-clobbered input args are in all resume vars
	sets, this ensures that these input args will be available from all
	internal events.

compiler/code_info.m:
	Export a previously internal predicate (current_resume_point_vars)
	to make this possible.

BUG FIX: WANT RETURN LAYOUTS

compiler/globals.m:
compiler/call_gen.m:
compiler/code_info.m:
compiler/mercury_compile.m:
	Add a new pred globals__want_return_layouts, which says whether the
	compiler should generate layout structures for call returns. This pred
	centralizes the several previous copies of the test. One of those
	copies (the one in call_gen) was faulty, leading to a bug: in the
	presence of execution tracing but the absence of accurate gc,
	information about the variables that are live at the call return
	wasn't being gathered properly.

BUG FIX: #include mercury_trace_base.h

compiler/llds_out.m:
	#include mercury_trace_base.h, not mercury_trace.h, since now
	mercury_trace_base.h defines everything directly accessible from
	modules compiled with tracing.

RECAST MERCURY_TRACE_UTIL AS MERCURY_LAYOUT_UTIL

runtime/mercury_trace_util.[ch]:
runtime/mercury_layout_util.[ch]:
	Rename this module from trace_util to layout_util, since it is also
	used by the native garbage collector. Remove "trace" from the names
	of functions.

	Get rid of the global variable MR_saved_regs, and instead thread
	a pointer to this data structure through the relevant functions
	as an extra argument.

	Add a lot more documentation in the header file.

runtime/Mmakefile:
	Reflect the module rename.

runtime/*.c:
	Refer to the new module.

DELETE EASY-TO-MISUSE MACROS

runtime/mercury_stacks.h:
	Delete the based_framevar and based_detstackvar macros, since their
	continued use can lead to off-by-one errors, and the saved_framevar
	and saved_detstackvar macros, since they are no longer used.

runtime/*.c
	Update any references to any macros removed from mercury_stacks.h.

MISC RUNTIME CHANGES

runtime/mercury_trace_base.[ch]:
trace/mercury_trace*.[ch]:
	Make typedef'd names conform to the naming convention.

	Make MR_trace_call_{seqno,depth} consistently Unsigned, rather than
	sometimes Word and sometimes Unsigned.

FIX BUG: MAKE THE DEBUGGER PRINT TO STDOUT, NOT THE CURRENT STREAM

library/io.m:
	Export to C code the predicates that return the identities and types
	of stdin, stdout and stderr, as well as io__print/[34].

library/std_util.m:
	Export to C code a predicate that returns the type_info for the
	type stdutil:type_info. This type_info is required if C code
	wants to invoke make_permanent on any type_info structure,
	as the debugger does.

runtime/mercury_init.h:
	Add extern declarations for the C functions now exported from io.m.

runtime/mercury_wrapper.[ch]:
	Add new global variables to hold the addresses of these C functions.

runtime/mercury_layout_util.c:
	Use indirect calls through these global variables to print Mercury
	values, instead of lower-level code.

util/mkinit.c:
	Assign the addresses of the functions exported from io.m to the
	global variables defined in mercury_wrapper.h.

BUG FIX: STACK TRACE FUNCTIONS DEPEND ON THE LABEL TABLE

runtime/mercury_stack_trace.c:
	On entry to any of the functions exported from this module,
	ensure that the label table is loaded by calling do_init_modules.
	Without a filled-in label table, the stack trace will not be able to
	find any stack layout info.

BUG FIX: REMOVE BROWSER/*.C

configure.in:
	When removing .c files generated by the C compiler, remove those
	in the browser directory as well as the compiler, library and
	profiler directories.

IMPLEMENT NEW DEBUGGER COMMAND SET

runtime/mercury_stack_trace.[ch]:
	Factor out the code that prints the id of a procedure into a function
	of its own, so that it can also be used from the debugger, ensuring
	appearance commonality.

	Add more documentation in the header file.

trace/mercury_trace_internal.c:
	Implement the proposed command set. Command names are now words,
	and several commands now have options allowing the user to override
	the default print level or strictness of the command, or the
	invocation conditions or action of a break point. Allows control
	over command echoing and the scrolling of sequences of event reports.
	Supports aliases, command file sourcing etc. Implements the retry
	command, using the info in the fixed stack slots.

trace/mercury_trace.[ch]:
	Extend the trace controls to support the new functionalities
	required by the new debugger language, which are print levels,
	variable-strictness commands, a more flexible finish command,
	and the retry command.

	Pass the command structure to MR_trace_event_report, since
	the user can now forcibly terminate the scrolling of reports.

trace/mercury_trace_alias.[ch]:
	New module to manage aliases for the debugger.

trace/mercury_trace_help.[ch]:
	New module to interface to browser/help.m.

trace/mercury_trace_spy.[ch]:
	New module to manage break points. The test of whether an event
	matches a break point is now much more efficient than before.
	The new module also allows several breakpoints with different
	actions and different invocation conditions (e.g. all ports,
	entry port, interface ports or specific (possibly internal) port)
	to be defined on the same procedure.

trace/mercury_trace_tables.[ch]:
	New module to manage a table of the debuggable modules, in which
	each such module is linked to the list of the layouts of all the
	procedures defined in that module. This information allows the
	debugger to turn the name of a predicate/function (possibly together
	with its arity and mode number) into the procedure layout structure
	required by the spy point module. Eventually it may also be useful
	in supplying lists of identifiers for command line completion.

	Modules for which no stack layout information is available will
	not be included in the table, since do_init_modules will not
	register any labels for them in the label table.

trace/Mmakefile:
	Mention the new files.

runtime/mercury_array_macros.h:
	A new file holding macros that can be useful in more than one module.

runtime/Mmakefile:
	Mention the new file.

runtime/mercury_conf.h.in:
	Mention a new configuration macro, MR_CANNOT_USE_STRUCTURE_ASSIGNMENT,
	used by runtime/mercury_array_macros.h.

configure.in:
	Find out whether we need to define MR_CANNOT_USE_STRUCTURE_ASSIGNMENT.

ADD TRACE DEPTH HISTOGRAMS

runtime/mercury_conf_param.h:
	Document MR_TRACE_HISTOGRAM.

runtime/mercury_trace_base.[ch]:
	Define the data structures for the histogram, and print the histogram
	when a traced program exits if MR_TRACE_HISTOGRAM is set.

trace/mercury_trace.[ch]:
	If MR_TRACE_HISTOGRAM is defined, record a count of the number of
	events at each depth. This information can help us evaluate space-time
	tradeoffs.

FACTOR OUT SHELL CODE HANDLING GRADE IMPLICATIONS

scripts/final_grade_options.sh-subr:
	A new file to contain any code that implements implications between
	grade flags; currently implements the implication debug -> use trail.

scripts/mgnuc.in:
scripts/ml.in:
	Replace the code that is now in final_grade_options.sh-subr with
	an inclusion of final_grade_options.sh-subr.

configure.in:
	Handle final_grade_options.sh-subr as {init,parse}_grade_options.sh-subr
	are handled.

SIMPLIFY THE MAINTAINANCE OF CONSISTENCY BETWEEN DEBUGGER CODE AND DOCUMENTATION

doc/Mmakefile:
	Add rules for creating mdb_command_list, a C code fragment
	that can included manually in trace/mercury_trace_internal.c
	to supply the list of valid commands, and mdb_command_test.inp,
	which is a list of invalid invocations of debugger commands,
	which tests whether the help message for such invocations
	can be located as expected.

doc/generate_mdb_command_list:
doc/generate_mdb_command_test:
	Awk scripts to create mdb_command_list and mdb_command_test.inp
	respectively from mdb_doc.

tools/bootcheck:
	Copy mdb_command_test.inp from doc to tests/debugger.

tests/debugger/Mmakefile:
	Add a new test that checks whether we get an internal error, unable
	to locate the right help node, for each invalid command invocation in
	mdb_command_test.inp.

UPDATE TEST CASES

tests/debugger/Mmakefile:
	Reenable queens. Conform to the new set of options.

tests/debugger/*.inp:
tests/debugger/*.exp:
	Update the inputs and expected outputs of the debugger test cases
	to use the new command set and output formats.
1998-10-16 06:20:28 +00:00
Tyson Dowd
ff373c79f1 Fix a cut and paste error - MR_isalnum should be defined as
Estimated hours taken: 0.2

runtime/mercury_std.h:
	Fix a cut and paste error - MR_isalnum should be defined as
	isalnum, not isdigit.
1998-07-28 04:51:41 +00:00
Fergus Henderson
e762cf7ed1 Fix a portability problem: mkinit.c and mdemangle.c were not casting
Estimated hours taken: 0.75

Fix a portability problem: mkinit.c and mdemangle.c were not casting
the arguments of isdigit() and isalnum() to unsigned char.

runtime/mercury_trace_internal.c:
runtime/mercury_std.h:
	Move the definitions of MR_isdigit() and MR_isspace()
	from mercury_trace_internal.c to mercury_std.h.
	Add a similar definition for MR_isalnum().

runtime/mercury_wrapper.c:
	Use MR_isspace() rather than doing the casts manually.

util/mkinit.c:
util/mdemangle.c:
	Use the MR_ versions of isdigit() and isalnum().

util/mkinit.c:
	Change the type of a variable from `int' to `size_t' to
	avoid a compiler warning about "comparison between signed
	and unsigned".
1998-07-27 18:04:32 +00:00
Fergus Henderson
c315607690 Clean up the handling of configuration macros in the runtime.
Estimated hours taken: 4

Clean up the handling of configuration macros in the runtime.

runtime/mercury_conf.h.in:
runtime/mercury_conf_param.h:
	Move the code to set configuration parameters based on
	the values of other configuration parameters from
	mercury_conf.h.in to a new file mercury_conf_param.h,
	because otherwise autoconf munges the code in undesirable ways
	(it replaces all `#undef <foo>' statements with `/* #undef <foo> */').

runtime/mercury_conf.h.in:
runtime/mercury_conf_param.h:
runtime/*.h:
runtime/*.c:
	Use more meaningful names, starting with the usual `MR_' prefix,
	for various configuration parameters:
		- replace the existing configuration macros SPEED with
		  three new macros MR_CHECK_OVERFLOW, MR_LOWLEVEL_DEBUG,
		  and MR_DEBUG_NONDET_STACK;
		- rename DEBUG_GOTOS as MR_DEBUG_GOTOS, and make it
		  implied by MR_LOWLEVEL_DEBUG;
		- rename DEBUG_LABELS as MR_CHOOSE_ENTRY_POINT.

	(But there are still many configuration parameters that don't
	start with `MR_', I'm afraid.)

runtime/CFLAGSFILE:
runtime/mercury_conf_param.h:
	Removed CFLAGSFILE.  The documentation there was had rotted badly.
	I moved most of it to mercury_conf_param.h where hopefully
	it will stand a better chance of being kept up-to-date.
	I added documentation for the configuration parameters added in
	the last year or so.  The documentation here now covers
	every configuration parameter that we use; please keep it that way!

runtime/mercury_debug.h:
	Fix a bug: there was a misplaced "#endif".

runtime/mercury_stack_trace.c:
	Fix yet another misspelling of "deterministic".
1998-03-16 12:23:40 +00:00
Tyson Dowd
bd19208eb9 Remove old .h files.
Estimated hours taken: 1

runtime/*.h:
runtime/*.c:
runtime/mercury_conf.h.in:
	Remove old .h files.
	Update #includes to refer to mercury_*.h
	Update #ifdef MODULE_H to be #ifdef MERCURY_MODULE_H
1997-11-23 07:21:53 +00:00
Tyson Dowd
7ce7d489a2 Cleaned up runtime directory.
Estimated hours taken: 2

Cleaned up runtime directory.

runtime/*.c:
	- Renamed all .c files as mercury_*.c
	  Some have been renamed to make their purpose clearer.
	  	call.mod -> mercury_ho_call.c

runtime/*.h:
	- Moved contents of .h files to mercury_*.h
	- *.h now contain #include mercury_*.h. They be removed later.
	- Updated references to conf.h -> mercury_conf.h

runtime/conf.h.in:
	- Renamed conf.h.in as mercury_conf.h.in.
	  Didn't leave a forwarding header for this one, as conf.h was
	  never part of the repository anyway.

runtime/Mmakefile:
	- Convert lists to one-per-line lists.
	- Add mercury_accurate_gc.h to HDRS.
	- Remove all .mod files
	- Make sure runtime.init uses the ORIG_CS not MOD_CS.
	- Fix the rules for "clean_o" and "clean_mod_c", which used
	  wildcards like "*.o" to remove files.  The one that removed
	  all .c files corresponding with *.mod, instead of using MOD_CS
	  was particularly vicious.
	- Cope with the file renamings.

configure.in:
	- Cope with the file renamings.
1997-11-20 02:04:40 +00:00