Commit Graph

62 Commits

Author SHA1 Message Date
Fergus Henderson
8e33e43220 Don't do mode analysis if there were any type errors.
mercury_compile.pp:
	Don't do mode analysis if there were any type errors.
	We get too many spurious mode errors.
1995-06-20 11:32:35 +00:00
Fergus Henderson
a24bcac9cf Change the output to the .dep' file so that foo_init.c' does
mercury_compile.pp:
	Change the output to the `.dep' file so that `foo_init.c' does
	not depend on anything and so that the arguments passed to $(C2INIT)
	are `foo.m bar.m' rather than `foo.c bar.c'.
	Note: this will only work with the new version of mkinit.
1995-06-20 07:12:50 +00:00
Zoltan Somogyi
15b8ea11d0 Put the comment about the contents of stack slots before the initial
code_gen.pp:
	Put the comment about the contents of stack slots before the initial
	label, since this way it will be preserved by optimizations.

cse_detection.m:
	Extended the search to look for cses in if-then-elses and switches
	as well as disjunctions. Removed InstmapDelta from preds in which it
	was not being used.

det_analysis.m:
	Make the diagnosis routines more robust. The changes here avoid the
	Philip's problems with lexical.m.

jumpopt.m:
	Minor formatting changes.

livemap.m:
	Avoid duplicating livevals instructions when optimizations are
	repeated, since this can confuse some optimizations.

llds.m:
	Minor documentation change.

make_hlds.m:
	Minor formatting change.

mercury_compile.pp:
	Do not map arguments to registers if any semantic errors have been
	found.

middle_rec.m and code_aux.m:
	Apply middle recursion only if tail recursion is not possible,
	since tail recursion yields more efficient code.

opt_util.m:
	Added a predicate to recognize constant conditions in if_vals.
	Modified a predicate to make it better suited for frameopt.

optimize.pp:
	Changed the way optimizations were repeated to allow better control.
	Repeat peephole once more after frameopt, since the new frameopt
	can benefit from this.

options.m:
	Removed the --compile-to-c option, which was obsolete. Added an
	option for predicate-wide value numbering, which is off by default.
	Changed some of the default values of optimization flags to reduce
	compilation time while holding the loss of speed of generated code
	to a minimum.

peephole.m:
	Look for if_vals whose conditions are constants, and eliminate the
	if_val or turn it into a goto depending on the value of the constant.
	Generalized the condition for optimizing incr_sp/decr_sp pairs.

value_number.m:
	Added a prepass to separate primary tag tests in if-then-elses from
	the test of the secondary tag, which requires dereferencing the
	pointer.

	Added sanity check routines to test two aspects of the generated code.
	First, whether it produces the same values for the live variables as
	the original code, and second, whether it has moved any dereferences
	of a pointer before a test of the tag of that pointer. If either test
	fails, we use the old instruction sequence.

vn_debug.m:
	New messages to announce the failure of the sanity checks. They are
	enabled by default, but of course can only appear if value numbering
	is turned on (it is still off by default).

vn_flush.m:
	Threaded a list of forbidden lvals (lvals that may not be assigned to)
	through the flushing routines. When saving the old value of an lval
	that is being assigned to, we use this list to avoid modifying any of
	the values used on the right hand side of the assignment, even if the
	saving of an old value results in assignment that requires another
	save, and so on recursively.

	When the flushing of a node_lval referred to a shared vn, the uses of
	the access vns of the node_lvals were not being adjusted properly.
	Now they are.

vn_order.m:
	The ctrl_vn phase of the ordering was designed to ensure that all
	nodes that need not come before a control node come after it. However,
	nodes were created after this phase operated, causing leakage of some
	value nodes in front of control nodes. Some of these led to pointer
	dereferences before tag tests, causing bus errors. The ctrl_vn phase
	is now last to avoid this problem.

vn_table.m:
	Added an extra interface predicate to support the sanity checks in
	value_number.

vn_util.m:
	The transformation of c1-e2 into (0-e2)+c1 during vnrval simplification
	could lead to an infinite loop in the compiler if c1 was zero. A test
	for this case now prevents the loop.
1995-06-17 06:08:09 +00:00
Fergus Henderson
ea9c17ee54 Include the library .m files in the tags file.
compiler/Mmake:
	Include the library .m files in the tags file.

hlds.m and lots of other places:
	Change the type of the argument list of a HLDS `call' from
	`list(term)' to `list(var)'.
1995-06-06 01:22:10 +00:00
Fergus Henderson
8e3d2ebb8d Bump up the version number.
mercury_compile.pp:
	Bump up the version number.
1995-05-30 17:45:43 +00:00
Zoltan Somogyi
3f06300706 Bugfix: the optimize flag is now observed when compiling by preds.
mercury_compile:
	Bugfix: the optimize flag is now observed when compiling by preds.
	Any request for a HLDS dump now implies compiling by phases.
1995-05-29 02:06:10 +00:00
Fergus Henderson
7771d630bf Fix a minor formatting problem with the --verbose output
mercury_compile.pp:
	Fix a minor formatting problem with the --verbose output
	for --common-goal.
1995-05-28 06:06:09 +00:00
Fergus Henderson
2250fbb0fd Fix bug where `mc --link hello' did not pass -DCONSERVATIVE_GC
mercury_compile.pp, options.m:
	Fix bug where `mc --link hello' did not pass -DCONSERVATIVE_GC
	to the C compiler.
1995-05-20 13:16:46 +00:00
Fergus Henderson
0f00decc64 --gc conservative' no longer implies --tags none',
mercury_compile.pp:
	`--gc conservative' no longer implies `--tags none',
	since the conservative garbage collector now works with `--tags low'.
1995-05-15 05:22:20 +00:00
Fergus Henderson
c27d39259c Remove support for `.nl' extension.
compiler/mercury_compiler.pp:
	Remove support for `.nl' extension.
1995-05-13 06:12:20 +00:00
Fergus Henderson
4fb65ff370 Use c2init rather than mkinit.
compiler/mercury_compile.pp:
	Use c2init rather than mkinit.
1995-05-13 05:47:57 +00:00
Fergus Henderson
f7e5d837e1 A bunch of bug fixes!
code_info.m:
	Bug fix: change generate_pre_commit and generate_commit so that
	the values which need to be saved and restored are always pushed
	onto the det stack, even in nondet predicates.  The reason is
	that if the committed goal fails, curfr is not valid, so we
	can't restore the fields from the nondet stack.
	(This way may well be more efficient anyway.)

disj_gen.m, ite_gen.m:
	Handle the case when the current failure continuation is unknown
	on entry to the disjunction or nondet if-then-else by creating
	a new frame on the nondet stack.  (Originally we just aborted
	in this case; recently we "fixed" this, but it turned out that
	the fix was not correct, for the same reason as the above-mentioned
	bug in pre_commit/commit.

llds.m:
	Add succfr/1 and prevfr/1 to the rval type in llds.m,
	since they were needed by the above bug fixes.
	(This caused dozens of changes elsewhere to handle the
	new types.)
	Also fix a trivial bug that I recently introduced which
	prevented --mod-comments from working.

live_vars.m:
	Fix bug in allocation of stack slots for nondet code.
	(This is the one that caused the bug that ksiew and I found
	when writing a calculator program.)

peephole.m:
	Disable the succeed_discard() optimization, since it
	causes incorrect code to be generated.  It was replacing
	modframe(do_fail) ... succeed() with
	modframe(do_fail) ... succeed_discard() even when there were
	instructions such as mkframe() in between.

modes.m, hlds.m:
	When modechecking switches, record the binding of the switch variable
	as we enter each case, so that we get the determinism analysis
	right.

mercury_compile.pp:
	Make sure that we set the exit status to be non-zero if we
	find any errors.

typecheck.m, modes.m, undef_types.m, undef_modes.m:
	Don't invoke type-checking if there are undefined types.
	Don't invoke mode-checking if there are undefined modes.
	This avoids the problem of the compiler aborting with an
	internal error if there are undefined types/modes.
1995-05-12 13:44:58 +00:00
Zoltan Somogyi
0fe764bfba Perform arg_info only if we are generating code.
mercury_compile:
	Perform arg_info only if we are generating code.

llds:
	Handle redo and fail by outputing a branch to their labels in the
	runtime, since this is smaller than the code for the macro itself.

dupelim, options:
	Added an extra optimization pass to eliminate duplicate blocks of
	code. Reduces compiler size by half a percent.
1995-05-08 05:32:05 +00:00
Zoltan Somogyi
f86b10982e check in forgotten files.
cs_detection, passes_aux:
	check in forgotten files.

hlds, modes:
	resolve minor CVS conflicts.

mercury_compile:
	improve progress message.
1995-05-06 10:38:40 +00:00
Zoltan Somogyi
0f46c5d4e7 Merged in changes from the pass_str_branch. 1995-05-06 07:29:58 +00:00
Fergus Henderson
2302db84b1 Bump the version number to 0.2.
mercury_compile.pp:
	Bump the version number to 0.2.
1995-04-17 17:35:11 +00:00
Fergus Henderson
677b6d30bf Bug fix: if there is no grade option, don't set gc=none.
mercury_compile.pp:
	Bug fix: if there is no grade option, don't set gc=none.
1995-04-15 07:50:22 +00:00
Fergus Henderson
b11e1dbae3 Call io__progname_base rather than io__progname.
mercury_compile.pp llds.m prog_io.m:
	Call io__progname_base rather than io__progname.
1995-04-08 07:31:35 +00:00
Fergus Henderson
cea38722e4 Add copyright notices.
compiler/*.pp:
	Add copyright notices.
1995-03-30 21:42:13 +00:00
Fergus Henderson
ac4f8ba0fb Add copyright messages.
compiler/*:
	Add copyright messages.
	Change all occurences of *.nl in comments to *.m.

compiler/mercury_compile.pp:
	Change the output to the .dep files to use *.m rather than *.nl.
	(NOTE: this means that `mmake' will not work any more if you
	call your files *.nl!!!)
1995-03-30 21:03:41 +00:00
Thomas Conway
1fd52bc3a5 Fix an overly conservative sanity check.
code_exprn.m
code_info.m:
	Fix an overly conservative sanity check.

mercury_compile.pp
typecheck.m:
	Fix type errors due to the changed implementation of map.
	Possibly these bits of code should be removed or something
	so that map is properly abstract.
1995-03-22 11:40:54 +00:00
Fergus Henderson
72947699b9 Associate a term__context with every goal:
prog_io.m:
	Associate a term__context with every goal:
	rename the type `goal' as `goal_expr' and add
	`:- type goal == pair(goal_expr, term__context)'.

make_hlds.m, negation.m, mercury_to_mercury.m, mercury_to_goedel.m:
	Change to handle new representation of goals.

modes.m, typecheck.m:
	Use the term__context from the goals, since the above changes
	make it meaningful now.

implication.m, make_hlds.m, mercury_compile.pp:
	Fold the implication transformation into the make_hlds pass.

Net result: better error messages, but compilation time is worse.
1995-03-19 11:13:50 +00:00
Fergus Henderson
90a4f4ea05 Fix type in output to .dep file.
mercury_compile.pp:
	Fix type in output to .dep file.
	Make sure `clean_progs' rule in the .dep file removes
	the SICStus and NU-prolog executables too.
1995-03-18 10:39:37 +00:00
Fergus Henderson
5a585d192a Handle .m' files as well as .nl'.
mercury_compile.pp:
	Handle `.m' files as well as `.nl'.
	Add rules for Sicstus Prolog in the automatically generated `.dep'
	files.
	Don't output the `.d' files for library modules when generating
	the `.dep' files.
	Fix bug: missing space after the -DTAGBITS=n option.
1995-03-13 12:36:26 +00:00
Fergus Henderson
7b37d28532 If we get a syntax error, set the exit status to something non-zero,
mercury_compile.pp:
	If we get a syntax error, set the exit status to something non-zero,
	so that we don't try to continue with linking.
1995-03-08 06:57:04 +00:00
Fergus Henderson
89360cdf4c Use mkdir -p.
Makefile.common:
	Use mkdir -p.

	Add mmake.sh.

	Change the tags rule so that it gets the .pp files first.

	Change the name of the compiler target from comp to mercury_compile.

	Remove the rules for test.exe since they duplicate the auto-generated
	ones in test.dep (which call the target `test' not `test.exe').

	Remove the `code_gen' target.  (Tom, if you need it, put it in
	Makefile.params.)

	Hack around with the installation rules (still in a state of flux).

options.nl:
	Disable the --mod-comments option by default.

llds.nl:
	Only output the gc livevals comment if --mod-comments is enabled.

mercury_compile.nl, prog_io.nl:
	Handle `file not found' errors more cleanly.
	When making the dependencies, assume that any files not found
	are library files, so don't put them in the dependencies.

modes.nl:
	Resolve type ambiguity introduced by change to prog_io.nl.

Mmake.rules Mmake.vars:
	Split Makefile.mercury into two halves for use by mmake.
	NOTE: I haven't removed Makefile.mercury yet, so any changes
	need to be made in both places!
1995-03-07 14:38:42 +00:00
Fergus Henderson
14cc06dcc4 Fix bug in my previous change to the .dep output.
mercury_compile.pp:
	Fix bug in my previous change to the .dep output.
1995-03-07 04:15:12 +00:00
Fergus Henderson
232fd2d22d Change the default grade from fast' to asm_fast.gc'.
Makefile.mercury:
	Change the default grade from `fast' to `asm_fast.gc'.

Makefile.common, mercury_compile.pp:
	Change the rules in the generated .dep makefiles so that
	the NU-Prolog executable is called `<module>.nu', not `<module>'.
	Add new rules for creating `<module>' and `<module>_init.c'
	using mc and mod2init.

mercury_compile.pp:
	Fix a couple of bugs in the option handling: firstly `--gc
	conservative' should imply `--tags none', and secondly the
	CONSERVATIVE_GC, TAGBITS, and HIGHTAGS #defines were not
	being passed to gcc.
1995-03-06 16:40:12 +00:00
Fergus Henderson
2a9e6d9dee Add io__{get,set}_exit_status.
io.nl, io.nu.nl:
	Add io__{get,set}_exit_status.
	Change documentation to refer to main/2 rather than main_predicate/3.

mercury_compile.pp:
	Implement the --link option.
	Improve error reporting, and try to return a non-zero exit
	status if something goes wrong.

hlds_out.nl:
	Print out the variable number for each variable.

Makefile.common:
	Change the default grade to asm_fast.gc.
	Enable followcode, followvars, and optimization.
	Change the name of the library to `libmercury.{a,so}'.

Makefile.mercury:
	Define MCG in terms of MC.
1995-03-04 19:19:18 +00:00
Fergus Henderson
adbfa4acad Pass the --asm-labels options through to the C compiler.
mercury_compile.pp:
	Pass the --asm-labels options through to the C compiler.
	Ensure --gc conservative implies --tags none.
1995-03-01 02:50:24 +00:00
Fergus Henderson
c93c271e6b Ensure that the module name output in the `:- module' declaration
mercury_compile.pp:
	Ensure that the module name output in the `:- module' declaration
	in .int files doesn't contain a directory name.
1995-02-11 09:20:06 +00:00
Fergus Henderson
22c6aff06b Fix bug with hlds-dumping: stage 6 got dumped twice, and stage 10
mercury_compile.pp:
	Fix bug with hlds-dumping: stage 6 got dumped twice, and stage 10
	didn't get dumped at all.
	Fix old bug where compiling files in directories other than
	the current directory would give you a `warning: incorrect module
	name' message.
1995-02-11 08:30:18 +00:00
Tyson Dowd
aee3e959c8 Add rules for making .mod into .h. Define MOD2H and MOD2H flags,
Makefile, Makefile.mercury:
	Add rules for making .mod into .h. Define MOD2H and MOD2H flags,
	(mod2h not included yet).

code_gen.nl, code_info.nl, garbage_out.nl, hlds.nl, io.nl, llds.nl,
make_hlds.nl, mercury_compile.nl, mercury_compile.pp shapes.nl:
	Various changes to facilitate shape information gathering, and
	garbage information output.
1995-02-10 06:52:39 +00:00
Fergus Henderson
5f967aa2a6 Define main/2 as well as main_predicate/3 (which is obsolete).
mercury_compile.pp:
	Define main/2 as well as main_predicate/3 (which is obsolete).
1995-02-07 07:22:15 +00:00
Jane Anna Langley
d8a404f511 Updated common.nl, to (hopefully!) fix the problem that the
elimination was leaving eliminated variables in the hlds__goal_info
structure.  The call to common.nl has been moved back again so that it
comes after switch detection.  Maybe it will settle down there for a
while!
1995-02-07 04:53:31 +00:00
Jane Anna Langley
4a16ec6a9a Moved common subexpression optimisation back before switch detection
on Tom's advice.
1995-02-05 22:47:12 +00:00
Jane Anna Langley
f3c87277f1 1. Fixed common.nl, like it actually works now. Wow!
2.	Moved common subexpression evaluation so that it occurs
	after switch detection.
3.	Made common subexpression optimisation "on" by default.
1995-02-03 05:26:48 +00:00
Tyson Dowd
d77adf4951 A new module to handle the output of the garbage collection
garbage_out.*:
	A new module to handle the output of the garbage collection
	information, presently it generates and puts the continuation
	table into a .garb file.

Makefile, Makefile.mercury:
	Rule for creating .garb files, and new dependencies for
	targets.

io.nl, io.nu.nl:
	Added io__read_anything/3 and io__read_anything/4.

mercury_compile.pp, options.nl:
	Added option support for garbage collection, `--gc accurate'
	switches on .garb file output, but code-generation must
	also be on.

shapes.nl:
	Cosmetic changes.
1995-02-01 05:12:38 +00:00
Jane Anna Langley
527f7d6fc7 Added common.nl a module intended to do some common subexpression
optimisation.  It doesn't appear to be doing that yet but nor does
it appear to be doing any harm :-)

It can be switched out in any case with the --no-common-subexpression option
1995-01-31 06:03:30 +00:00
Thomas Conway
a6409d7a10 Added more stuff needed for the call_graph.
graph.nl:
	Added more stuff needed for the call_graph.

mercury_to_mercury.nl:
	added a version of the predicate for outputing
	mode declarations that leaves off the ':-' and '\n'

options.nl:
	added the option -C for generating a call graph in the
	file <module>.call_graph
1995-01-27 01:12:01 +00:00
Fergus Henderson
040cea9728 Add char__is_{hex,octal,binary}_digit.
char.nl:
	Add char__is_{hex,octal,binary}_digit.

string.nl:
	Add declaration and stub implementation for
	string__base_string_to_int.

io.nl, io.nu.nl:
	Implement io__putback_char (not very efficiently).

mercury_builtin.nl:
	Add a declaration for cut.

mercury_compile.pp:
	Suppress singleton variable warning.

prog_io.nl:
	In DCG expansion, when appending unifications to disjunctions
	propagate them into each disjunct, so that we don't stuff up
	switch detection.
1995-01-24 10:21:14 +00:00
Tyson Dowd
31dfac230c New module to handle shape information collection.
shapes:
	New module to handle shape information collection.

call_gen, code_gen, code_info, hlds, mercury_compile:
	Modifications to call the shapes module, and keep a shape
	table in the module_info structure.
1995-01-23 03:18:36 +00:00
Zoltan Somogyi
c69207303c Added back an old garbage collection point.
mercury_compile:
	Added back an old garbage collection point.

optimize:
	Added some new garbage collection points, and made the file into .pp.

value_number, vn_util, opt_debug:
	Changed the way access vns are counted. Pushed noop vnlvals towards
	the front of the flush order; this can improve the speed of the
	generated code.

middle_rec:
	Clarified a bit of code.
1995-01-21 11:20:24 +00:00
Zoltan Somogyi
4e0d9a8367 Value numbering should now work with code that allocates memory.
value_number, vn_util:
	Value numbering should now work with code that allocates memory.

frameopt:
	Create a stack frame before an if_val if both continuations need one.

optimize, mercury_compile:
	-V now prints a message for each optimization pass for each proc.

llds, call_gen, code_gen, middle_rec etc:
	Change livevals/2 back into livevals1.

jumpopt:
	Rename instmap to instrmap at fjh's request.
1995-01-20 11:53:20 +00:00
Fergus Henderson
4ce6ed350f Output some more variable definitions in the .dep files.
mercury_compile.pp:
	Output some more variable definitions in the .dep files.
1995-01-18 12:48:01 +00:00
Fergus Henderson
c13d2bf5a9 Add a mark_hp instruction.
llds.nl:
	Add a mark_hp instruction.

frame_opt.nl, middle_rec.nl, opt_util.nl, opt_debug.nl:
	Handle mark_hp instructions.

code_info.nl:
	Use mark_hp and restore_hp instructions rather than assignments
	to/from hp.

- - - - - - - - - - - - - - - - - - - - - - - - -

llds.nl:
	Tidy up the output of the GC info a little.

- - - - - - - - - - - - - - - - - - - - - - - - -

mercury_compile.nl:
	Print more memory usage statistics.
1995-01-17 20:27:54 +00:00
Fergus Henderson
e0f35740c7 Don't invoke the polymorphism pass unless the user actually
mercury_compile.pp:
	Don't invoke the polymorphism pass unless the user actually
	asked for it (with the -p or --polymorphism option).
1995-01-16 14:37:19 +00:00
Fergus Henderson
aabd98b210 Add a -p' or --polymorphism' option to enable the polymorphism.nl
mercury_compile.nl, options.nl:
	Add a `-p' or `--polymorphism' option to enable the polymorphism.nl
	pass.
1995-01-14 18:43:31 +00:00
Fergus Henderson
48e3dea925 Fix some bugs:
polymorphism.nl:
	Fix some bugs:
		- I had forgotten to update the argmodes of the modified
		  procedures
		- I was updating the argtypes and attempting to use there
		  old value.  I fixed this by splitting the algorithm
		  into two passes.
		- to compute the types of the arguments to a call,
		  apply the type mapping from the _caller_ not the callee.
	Also improve efficiency in a couple of places.

hlds.nl:
	Add some new access predicates required by polymorphism.nl.

list.nl:
	Add a new predicate list__duplicate, which is used by polymorphism.nl.

typecheck.nl, type_util.nl:
	Move the type_unify routines from typecheck.nl into type_util.nl,
	since they're also needed by polymorphism.nl.

term.nl:
	Export term__apply_rec_substitution_to_list, since it's needed
	by polymorphism.nl.

- - - - - - - - - - - - - - - - - - - - - - - - -

mode_util.nl, type_util.nl:
	Move some routines from mode_util.nl to type_util.nl, where they
	really belong.

- - - - - - - - - - - - - - - - - - - - - - - - -

make_hlds.nl, code_util.nl, typecheck.nl:
	Mark builtin predicates as "external" in make_hlds.nl,
	rather than checking for them as a special case in typecheck.nl.

- - - - - - - - - - - - - - - - - - - - - - - - -

prog_io.nl, hlds.nl, typecheck.nl:
	For documentation purposes, define equivalent types `tvar',
	`tvarset', `tsubst' for type variables, type varsets, and
	type substitutions.

- - - - - - - - - - - - - - - - - - - - - - - - -

mercury_compile.pp, options.nl:
	Change the handling of the --dump-hlds option so that you can
	now dump the HLDS after any of the 12 HLDS transformation passes.

- - - - - - - - - - - - - - - - - - - - - - - - -

make_hlds.nl:
	Report an error if there are clauses for an imported predicate.

- - - - - - - - - - - - - - - - - - - - - - - - -

io.nu.nl:
	Add a new predicate r/1 which is like run/1 except that
	you pass it a string rather than a list of atoms.
	So now you can do
		$ mercury_compile.debug
		Mercury Interpreter 0.1
		NU-Prolog 1.6.4
		1?- r("mc -options blah blah blah").
1995-01-14 11:59:51 +00:00
Thomas Conway
8755f26838 changed call/2 to call/3 to include gc information about
llds.nl:
	changed call/2 to call/3 to include gc information about
	what registers and stack locations are live, and what their
	`shape numbers' are. Currently all the shape numbers are -1
	because the shape table stuff hasn't been implemented.

*	The changes made are only cosmetic as far as everything else
*	is concerned.

*.nl, etc:
	changes related to the above.
1995-01-10 15:04:41 +00:00