Commit Graph

150 Commits

Author SHA1 Message Date
Julien Fischer
7dccb03be1 Delete an unused variable.
util/mkinit.c:
    Delete the variable "init_suffix", which has never been used.
    (It was added in commit 04e614485, where it was merged on to the then CVS
     trunk from the deep2 branch.)
2026-02-07 15:56:32 +11:00
Julien Fischer
0f2ee70edf Support wildcard argument expansion with MSVC.
In Unix expansion of wildcard arguments is done by the shell. On Windows,
this is not the case and programs are responsible for expanding wildcard
argument themselves. When using source file mapping, we typically used
wildcards to specify the source files to map. When native Windows Mercury
compilers are used in the Windows command prompt or PowerShell, this does
not work, which is inconvenient to say the least. (In environments like
Cygwin or MSYS2, the shell does do wildcard expansion.)

Microsoft's C runtime has an optional component that programs can
link against which will do wildcard expansion on the argument vector
before main is called. Set up builds with MSVC to link against this
component when building the Mercury compiler.

scripts/parse_ml_options.sh-subr.in:
scripts/ml.in:
    Add a new option --use-msvc-setargv-extension, which causes the the
    wsetargv.obj file that enables the extension to be passed the linker.
    (MSVC seems rather picky about where this is positioned. A a result
    we do it within the ml script where have we more control over the matter.)

compiler/Mmakefile:
    Pass --use-msvc-setargv-extension to the ml script if we are using MSVC.

    Unrelated: Fix the identity of a compiler in a comment.

    Unrelated: Add an XXX about something that looks suspicious.

util/mkinit.c:
    Add a pointer to scripts/ml.in, saying that if the Windows entry
    point (currently wmain) is updated, then the script may need to
    be updated.
2026-01-06 21:45:53 +11:00
Zoltan Somogyi
7a122b004c Better document the code creating .init files.
util/mkinit.c:
    Put the central list of the places that create .init files here.

compiler/compile_target_code.m:
scripts/c2init.in:
    Point to util/mkinit.c as the repository of that central list.

    Make some predicate names more descriptive.

util/mkinit_common.h:
    Replace /* */ comments with // comments.
2025-09-12 07:29:47 +10:00
Julien Fischer
ab72f07f4f Fix mkinit option processing.
util/mkinit.c:
    The -l option does not take an argument. An incorrect edit in
    commit fcb8ffe9 meant that it was expecting one.
2022-03-26 00:20:39 +11:00
Peter Wang
594b09c547 Handle argv[0] == NULL.
On some operating systems, e.g. Linux, it is possible to enter main()
with argv[0] == NULL if the parent process calls execve() with
argv[0] == NULL, or equivalently, passing NULL for the argv parameter.

runtime/mercury_wrapper.c:
runtime/mercury_wrapper.h:
    Do not assume argc > 0 and argv[0] != NULL in MR_process_args.
    If argv[0] is NULL then set MR_progname to the empty string
    so users of MR_progname can assume it points to a valid string.

    Add a new global variable MR_progname_is_known to indicate if
    argv[0] was NULL or not.

library/io.m:
    Make io.progname return the default program name if argv[0] was
    NULL.

util/mkinit.c:
    Set MR_progname to a valid string if argv[0] is NULL.
    This is not actually necessary, since, in that case, the subsequent
    call to parse_options() would immediately exit the program
    as no file names will be found in argv.
2022-01-31 14:11:08 +11:00
Julien Fischer
43195d1eda Avoid redefining some macros.
util/mkinit.c:
    Do not define _BSD_SOURCE or _DEFAULT_SOURCE if the user
    has already done so.  (This affects compilation of extras/net
    when the C compiler is set to treat redefined macros as an error.)
2022-01-14 19:29:20 +11:00
Peter Wang
fcb8ffe9db Delete mkinit_erl program.
util/.gitignore:
util/Mmakefile:
    Don't build or install the mkinit_erl program.

util/mkinit.c:
util/mkinit_common.c:
    Remove references to mkinit_erl.c.

    Delete handling of -m option (only used by mkinit_erl).

util/mkinit_erl.c:
    Delete source file.
2020-10-27 11:10:11 +11:00
Zoltan Somogyi
f7c911ab36 Bring the style of mkinit.c up to date.
Replace /* */ with //.

Generate C code with four space indentation. The existing code intended
to do this by aligning the code on four-space boundaries in mkinit.c,
but the " at the start of each string ate one position, so the generated
code lines started in columns 4, 8, 12 etc, instead of 5, 9, 13 etc.
2020-08-15 02:57:17 +10:00
Peter Wang
ac29292e9a Delete util/getopt.h
util/getopt.h:
    Delete this file.

util/Mmakefile:
    Pass -I../getopt to the C compiler.

util/mkinit.c:
util/mkinit_erl.c:
    Include either <unistd.h> or ../getopt/getopt.h for the declaration
    of getopt(). We don't include both in case there may be conflicting
    declarations of getopt() on some system.
2019-06-10 13:30:51 +10:00
Peter Wang
bb52ce0804 Fix unintended fallthrough.
util/mkinit.c:
util/mkinit_erl.c:
    Fix unintended fallthrough in switch (harmless).
2019-06-01 16:15:36 +10:00
Peter Wang
05e9f4b2b6 Delete old code setting GC_stackbottom on AIX.
util/mkinit.c:
    Delete last reference to GC_stackbottom (which has been deprecated).
    The code to set GC_stackbottom was only left for old AIX, but is not
    required at least with AIX 7.1 on POWER, and likely hasn't been
    relevant for a long time.
2019-05-31 15:54:21 +10:00
Peter Wang
daae03f07f Delete unnecessary foreign_exported procedures.
library/io.m:
    Delete unused foreign_exported procedures.

    Add warning about using `ML_io_print_to_stream'.

runtime/mercury_init.h:
runtime/mercury_wrapper.c:
runtime/mercury_wrapper.h:
util/mkinit.c:
    Delete unused function pointer `MR_io_print_to_cur_stream'.
2016-09-28 11:10:33 +10:00
Julien Fischer
10c210dc16 Fix bug #196: binary compatibility checks in C grades do not work.
These have been broken since 2011 because GCC and clang (at least) began
optimising away the MR_grade variable we emit at the end of each generated .c
file.  The fix is to replace the MR_grade variable with an exported function
that references MR_GRADE_VAR in each generated .c file.

compiler/llds_out_file.m:
compiler/mlds_to_c.m:
util/mkinit.c:
     In each generated .c file, emit an exported function that references
     MR_GRADE_VAR.
2016-07-17 20:48:39 +10:00
Julien Fischer
94535ec121 Fix spelling and formatting throughout the system.
configure.ac:
browser/*.m:
compiler/*.m:
deep_profiler/*.m:
library/*.m:
ssdb/*.m:
runtime/mercury_conf.h.in:
runtime/*.[ch]:
scripts/Mmake.vars.in:
trace/*.[ch]:
util/*.c:
	Fix spelling and doubled-up words.

	Delete trailing whitespace.

	Convert tabs into spaces (where appropriate).
2015-12-02 18:46:14 +11:00
Paul Bone
eed9cc75bd Make changes required to upgrade to Boehm GC 7.4.2
GC_stackbottom, GC_gc_no and GC_dont_gc are now deprecated.  These changes
use new options in the API where possible.

Update scripts to copy the boehm_gc and libatomic_ops directories correctly.

Pass Boehm GC the correct flags for thread support

Update documentation regarding the version of Boehm GC.

runtime/mercury_wrapper.c:
    Don't use the deprecated GC_dont_gc variable.

library/benchmarking.m:
    Use GC_get_stackbottom() to get the bottom of stack and GC_get_gc_no()
    to get the number of collections so far.

util/mkinit.c:
    Do not explicitly set GC_stackbottom anymore, except on AIX where it
    cannot be found automatically.

scripts/prepare_install_dir.in:
tools/bootcheck:
tools/build_srcdist:
    Add some missing files present in Boehm GC 7.4.2 that wern't present
    earlier and remove some old ones.

    Coby and link the libatomic_ops directory correctly.

.README.in:
bindist/bindist.README:
    Update documentation regarding the version of Boehm GC.

configure.ac:
    Something in Boehm GC's build system has changed and we must now pass
    -DGC_THREADS whenever building threadsafe versions of BOehm GC.  This is now
    done using the BOEHM_MISC_CFLAGS_FOR_THREADS autoconf variable, which has
    been renamed to BOEHM_CFLAGS_FOR_THREADS now that it is more generally used.

    Boehm GC no longer (or perhaps never did) require developers to specify the
    type of threading to use, eg -DGC_LINUX_THREADS rather than -DGC_THREADS.
    With the exception of win32-pthreads.  We now pass -DGC_THREADS whereever
    possible.

Mmake.common.in:
    Rename BOEHM_MISC_CFLAGS_FOR_THREADS.
2015-10-01 10:26:46 +10:00
Julien Fischer
e6b669a933 Fix bug #379: warnings about deprecated feature macros with glibc 2.20.
glibc version 2.20 will emit a warning if the macros _BSD_SOURCE or
_SVID_SOURCE are defined.  (They have been deprecated in favour of the macro
_DEFAULT_SOURCE).  The C files generated by mkinit define _BSD_SOURCE,
consequently causing a warning to be emitted by the preprocessor every time you
build an executable on systems with the affected version of glibc.

Also defining _DEFAULT_SOURCE will disable the warning.

util/mkinit.c:
	Define _DEFAULT_SOURCE in order to suppress the warning described
        above.
2015-02-19 11:39:34 +11:00
Zoltan Somogyi
cd72d000a8 Remove support for the MPS garbage collector.
As Tomas By's recent emails suggest, this support is doing more harm than good,
by falsely implying to people that MPS is a viable alternative to the Boehm
collector. The MPS collector was only ever experimental, and never performed
as well as Boehm. MPS isn't even in the git repository on git hub. It was
stored in a separate CVS repository on mundula, and (as far as I know)
wasn't carried over to github. The code of MPS was last touched a long time
ago; I would be surprised if it worked on today's systems without changes.

Mmake.common.in:
Mmake.workspace:
RESERVED_MACRO_NAMES:
boehm_gc/Mmakefile:
compiler/add_pragma.m:
compiler/compile_target_code.m:
compiler/globals.m:
compiler/handle_options.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c.m:
compiler/options.m:
compiler/peephole.m:
doc/user_guide.texi:
library/benchmarking.m:
runtime/Mmakefile.m:
runtime/mercury.h:
runtime/mercury_conf_param.h:
runtime/mercury_grade.h:
runtime/mercury_heap.h:
runtime/mercury_init.h:
runtime/mercury_memory.h:
runtime/mercury_wrapper.[ch]:
scripts/canonical_grade.sh-subr:
scripts/init_grade_options.sh-subr:
scripts/mgnuc.in:
scripts/ml.in:
scripts/parse_grade_options.sh-subr:
util/mkinit.c:
    Remove all references to MPS.
2014-08-05 15:45:33 +02:00
Peter Wang
06647ff390 Implement unify/compare of tuples in Mercury.
The hand-written C unify and compare predicates for tuples did not preserve
deep profiler invariants correctly across the recursive unify/compare of
tuple arguments.  I tried to do so, and failed.  Instead, implement the
predicates in Mercury so the compiler can perform the deep profiling
transformation on them.  Bug #3.

A micro-benchmark on my machine is about twice as fast in asm_fast.gc
after this patch, and about the same in hlc.gc.  The change to the
high-level C backend is only to reduce code duplication.

library/library.m:
	Add foreign-exported predicates to take the place of `io.init_state'
	and `io.finalize_state' as overall initialization/finalization
	predicates.

library/builtin.m:
	Add `unify_tuple', `compare_tuple', `compare_rep_tuple' predicates.

	Add initializer which sets `MR_special_pred_hooks' to point to those
	predicates.

	Delete unused predicates `call_rtti_generic_unify',
	`call_rtti_generic_compare'.

	Reorder some code.

library/io.m:
	Add `io.finalize_state' to hidden interface.

	Delete foreign exports for `io.init_state' and `io.finalize_state'.

	Reorder some code.

runtime/mercury_ho_call.c:
runtime/mercury_ho_call.h:
	Add a global variable `MR_special_pred_hooks' for the library to
	set up during initialisation.

	Add `tailcall' macros for use by `mercury_unify_compare_body.h'.
	Rename `tailcall_user_pred' to `tailcall_tci_pred'.

	Call the new unify/compare predicates in the high-level C
	backend via `MR_special_pred_hooks'.

	Delete `unify_tuples' and `compare_tuples' for the high-level C
	and call the Mercury predicates set in `MR_special_pred_hooks'.

runtime/mercury_unify_compare_body.h:
	Delete the unify and compare code for tuples in the low-level C
	backend.  Jump to the Mercury predicates set in
	`MR_special_pred_hooks' instead.

	Add some comments.

compiler/elds_to_erlang.m:
runtime/mercury_init.h:
runtime/mercury_wrapper.c:
util/mkinit.c:
	Conform to the library initializer/finalizer change.

tests/hard_coded/Mmakefile:
tests/hard_coded/tuple_test2.exp
tests/hard_coded/tuple_test2.m:
	Add test case.

NEWS:
	Announce the change.
2014-07-10 13:24:05 +10:00
Julien Fischer
6851f943ec Avoid C compiler warnings that occur when using clang with -Wall.
Except where noted otherwise below most of these warnings relate to implicit
conversions between 64- and 32-bit integers or the signedness of integers
differing in spots.

library/construct.m:
	Delete an unused local variable in the implementation of get_functor_lex.

library/bitmap.m:
	The function MR_bitmap_cmp returns an MR_Integer not an int.

library/thread.semaphore.m:
	Change the count field of the ML_SEMAPHORE_STRUCT structure into
	an MR_Integer (which is what gets passed in).

trace/mercury_trace_declarative.c:
	Avoid a warning about fprintf being called where its second argument
	is not a string literal.  (In this case it can be replaced by a call
	to fputs.)

library/io.m:
mdbcomp/rtti_access.m:
trace/mercury_trace.c:
trace/mercury_trace_cmd_breakpoint.c:
trace/mercury_trace_cmd_help.c:
trace/mercury_trace_completion.m:
trace/mercury_trace_declarative.[ch]:
trace/mercury_trace_external.c:
trace/mercury_trace_internal.c:
trace/mercury_trace_source.c:
trace/mercury_trace_tables.c:
trace/mercury_trace_vars.c:
util/info_to_mdb.c:
util/mfiltercc.c:
util/mdemangle.c:
util/mkinit.c:
util/mkinit_erl.c:
util/mkinit_common.h:
util/mkinit_common.c:
	As above.
2014-03-31 00:31:36 +11:00
Julien Fischer
e9d90b2891 Avoid warnings from clang in the runtime and util directories.
runtime/mercury_stack_trace.c:
	In the function MR_dump_stack_from_layout_clique initialise the variable
	lines_dumped_so_far.  (This appears to be an actual bug.)

runtime/mercury_prof.c:
	Only define the static global in_profiling_code if either of call count
	profiling or time profiling is enabled.

runtime/mercury_context.c:
runtime/mercury_deconstruct.c:
runtime/mercury_deep_profiling.c:
	Only define some local variables in grades that require them.

runtime/mercury_float.c:
runtime/mercury_deep_copy_body.h:
runtime/mercury_construct.c:
runtime/mercury_memory_zones.c:
runtime/mercury_stm.c:
runtime/mercury_trace_base.c:
runtime/mercury_type_info.c:
	Delete unused local variables.

util/mdemangle.c:
	Delete an unused static global variable.

	Use fputs in place of fprintf in a couple of places in order
	to avoid warnings about format strings that are not string literals.

	Delete an unused function.

util/mkinit.c:
util/mkinit_erl.c:
	Delete unused local variables.
2014-03-20 17:01:15 +11:00
Paul Bone
428d5a1cc2 Move the sbrk profiling code into the mercury_main() function.
The mercury_main() function is used in both standalone and library builds of
Mercury code.  However the main function where the code was was only used in
standalone programs.  The Mercury compiler is built as a library and
usually liked with main.c in the root directory, this is done so that it can
be used with GCC for the GCC backend.  I have moved the sbrk profiling code
into mercury_main so that it will be executed by the compiler.  I used this
to generate memory usage information in my thesis.

util/mkinit.c:
    As above.
2012-11-11 01:42:00 +00:00
Julien Fischer
f6dd75cc54 Make it possible to initialise the Mercury runtime using an external interface
Branches: main

Make it possible to initialise the Mercury runtime using an external interface
without providing the address of the base of the stack.
This should work on most systems and can be useful when the top-level of a
program is not written in C or C++.
(In principle, this probably always worked, so the main change here is to
document it.)

util/mkinit.c:
	If mercury_init's stackbottom argument is NULL then don't
	set GC_stackbottom.

doc/user_guide.texi:
	Extend the description of the mercury_init function in the
	standalone-interfaces section to include the above.
2012-01-11 04:58:12 +00:00
Julien Fischer
c8b3fd0d02 Don't call the GC before it has been initialised.
Branches: main, 11.07

util/mkinit.c:
	Don't call the GC before it has been initialised.
2011-12-17 04:11:04 +00:00
Julien Fischer
608df4f718 Fix handling of Unicode command-line arguments on Windows with either MinGW or
Branches: main, 11.07

Fix handling of Unicode command-line arguments on Windows with either MinGW or
MSVC.  (For other compilers on Windows, Unicode command-line arguments are not
currently supported.)

The existing approach using GetCommandLineW and CommandLineToArgW caused the
command-line to be parsed in a weird way, e.g. for

   c:\> "C:\ws"\foo.exe

argv[0] was split in two:

   ["c:\ws", "\foo.exe"]


util/mkinit.c:
	Use wmain instead of main with MSVC; this gives us direct access
	to the wide version of the argument vector.

	Use __wgetmainargs to get the wide version of the command-line
	arguments with MinGW.  MinGW doesn't support wmain so we can't
	use that.

	Don't include shellapi.h on Windows, it's no longer required.


compiler/compile_target_code.m:
	Use the wide entry point to the C runtime with MSVC so that
	wmain is invoke isntead of main.
2011-12-16 03:38:20 +00:00
Peter Wang
f205ce9425 Support Unicode characters in command line arguments on Windows.
Branches: main, 11.07

Support Unicode characters in command line arguments on Windows.

util/mkinit.c:
	Retrieve the array of wide-character command-line argument
	strings with GetCommandLineW and CommandLineToArgvW.

	Convert the strings to UTF-8.

	Pass the array of UTF-8 argument strings to mercury_main as usual.
2011-12-14 05:12:42 +00:00
Paul Bone
a885ef1910 Add support for tracking the number, and amount of memory consumed by memory
zones.  The current and maximum values are tracked.  This support is only
compiled in if the MR_PROFILE_ZONES C macro is defined when building the
runtime system.

runtime/mercury_memory_zones.[ch]:
    As above.

runtime/mercury_wrapper.c:
    Print out the zone profiling data as the runtime is exiting.

util/mkinit.c:
    Add support for measuring the top of heap before and after executing
    mercury_main and writing out this difference.  This support is only enabled
    if the MR_PROFILE_SBRK macro is defined when compiling an application.
2011-11-23 10:53:01 +00:00
Julien Fischer
6a8844236b Protect a reference to GC_stackbottom with #ifdef MR_BOEHM_GC.
Branches: main

util/mkinit.c:
	Protect a reference to GC_stackbottom with #ifdef MR_BOEHM_GC.

library/bag.m:
	Fix some inconsistent indentation.
2011-06-08 04:19:58 +00:00
Paul Bone
322feaf217 Add more threadscope instrumentation.
This change introduces instrumentation that tracks sparks as well as parallel
conjunctions and their conjuncts.  This should hopefully give us more
information to diagnose runtime performance issues.

As of this date the ThreadScope program hasn't been updated to read or
understand these new events.

runtime/mercury_threadscope.[ch]:
    Added a function and types to register all the threadscope strings from an
    array.

    Add functions to post the new events (see below).

runtime/mercury_threadscope.c:
    Added support for 5 new threadscope events.
        Registering a string so that other messages may refer to a constant
        string.

        Marking the beginning and ends of parallel conjunctions.

        Creating a spark for a parallel conjunct.

        Finishing a parallel conjunct.

    Re-arranged event IDs, I've started allocating IDs from 38 onwards for
    general purposes and 100 onwards for mercury specific events after talking
    with Duncan Coutts.

    Trimmed excess whitespace from the end of lines.

runtime/mercury_context.h:
    Post a beginning parallel conjunction message when the sync term for the
    parallel conjunction is initialized.

    Post an event when creating a spark for a parallel conjunction.

    Add a MR_spark_id field to the MR_Spark structure, these identify sparks to
    threadscope.

runtime/mercury_context.c:
    Post threadscope messages when a spark is about to be executed.

    Post a threadscope event when a parallel conjunct is completed.

    Add a missing memory barrier.

runtime/mercury_wrapper.[ch]:
    Create a global function pointer for the code that registers strings in the
    threadscope string table, this is filled in by mkinit.

    Call this function pointer immediatly after setting up threadscope.

runtime/mercury_wsdeque.[ch]:
    Modify MR_wsdeque_pop_bottom to return the spark pointer (which points onto
    the queue) rather then returning a result through a pointer and bool if the
    operation was successful.  This pointer is safe to dereference until
    MR_wsdeque_push_bottom is used.

runtime/mercury_wsdeque.c:
    Corrected a code comment.

runtime/mercury_engine.h:
    Documented some of the fields of the engine structure that hadn't been
    documented.

    Add a next spark ID field to the engine structure.

    Change the type of the engine ID field to MR_uint_least16_t

compiler/llds.m:
    Add a third field to the init_sync_term instruction that stores the index
    into the threadscope string table of the static conjunction ID.

    Add a field to the c_file structure containing the threadscope string
    table.

compiler/layout.m:
    Added a new layout array name for the threadscope string table.

compiler/layout_out.m:
    Implement code to write out the threadscope string table.

compiler/llds_out_file.m:
    Write out the threadscope string table when writing out the c_file.

compiler/par_conj_gen.m:
    Create strings that statically identify parallel conjunctions for each
    init_sync_term LLDS instruction.  These strings are added to a table in the
    !CodeInfo and the index of the string is added to the init_sync_term
    instruction.

    Add an extra instruction after a parallel conjunction to post the message
    that the parallel conjunction has completed.

compiler/global_data.m:
    Add fields to the global data structure to represent the threadscope string
    table and its current size.

    Add predicates to update and retrieve the table.

    Handle merging of threadscope string tables in global data by allowing the
    references to the strings to be remapped.

    Refactored remapping code so that a caller such as proc_gen only needs to
    call one remapping predicate after merging global data..

compiler/code_info.m:
    Add a table of strings for use with threadscope to the code_info_persistent
    type.

    Modify the code_info_init to initialise the threadscope string table fields.

    Add a predicate to get the string table and another to update it.

compiler/proc_gen.m:
    Build the containing goal map before code generation for procedures with
    parallel conjunctions in a parallel grade.  par_conj_gen.m depends on this.

    Conform to changes in code_info.m and global_data.m

compiler/llds_out_instr.m:
    Write out the extra parameter in the init_sync_term instruction.

compiler/dupelim.m:
compiler/dupproc.m:
compiler/exprn_aux.m:
compiler/global_data.m:
compiler/jumpopt.m:
compiler/livemap.m:
compiler/llds_to_x86_64.m:
compiler/mercury_compile_llds_back_end.m:
compiler/middle_rec.m:
compiler/opt_debug.m:
compiler/opt_util.m:
compiler/peephole.m:
compiler/reassign.m:
compiler/use_local_vars.m:
    Conform to changes in llds.m

compiler/opt_debug.m:
    Conform to changes in layout.m

compiler/mercury_compile_llds_back_end.m:
    Fix some trailing whitespace.

util/mkinit.c:
    Build an initialisation function that registers all the strings in
    threadscope string tables.

    Correct the layout of a comment.
2011-03-25 03:13:42 +00:00
Paul Bone
e0e251ccbf Correct the prefixes on the symbol and macro names provided by HGC.
runtime/mercury_expanding_array.h:
runtime/mercury_hgc.c:
runtime/mercury_hgc.h:
    As above.

runtime/mercury_init.h:
runtime/mercury_memory_zones.c:
runtime/mercury_wrapper.c:
util/mkinit.c:
    Conform to changes in mercury_hgc.h
2010-02-13 07:29:10 +00:00
Paul Bone
df2349838f Introduce Ralph's History based Garbage Collector (HGC).
This change set creates a new value 'hgc' for the garbage collector grade
component.  This enables a new garbage collector included with the runtime
system.  Note that this garbage collector is experimental and this grade does
not work yet.

This change set represents work done by both myself and Ralph Becket.

runtime/mercury_hgc.c:
runtime/mercury_hgc.h:
    Include the new garbage collector.

runtime/mercury_expanding_array.h:
    This new header file provides a template for a type safe expanding array,
    it is used by HGC.

runtime/Mmakefile:
    Include the new modules in the runtime directory mercury_hgc.[ch] and
    mercury_expanding_array.h.

    Sort the lists of source files and header files.

compiler/globals.m:
    Include 'hgc' in the options for which garbage collector to use.

compiler/handle_options.m:
    Handle the new 'hgc' value for the garbage collector type.

compiler/options.m:
    Print out information about the new 'hgc' option in the --help text of the
    compiler.

compiler/compile_target_code.m:
    Pass the -DMR_HGC option to the C compiler for hgc grades.

compiler/add_pragma.m:
compiler/mercury_compile_mlds_back_end.m:
compiler/mlds_to_c.m:
compiler/peephole.m:
    Conform to changes in globals.m.

library/benchmarking.m:
    Fix a use of MR_CONSERVATIVE_GC that should have been MR_BOEHM_GC.

robdd/bryant.h:
    Include the mercury_hgc.h header file when MR_HGC is defined.

runtime/mercury_init.h:
runtime/mercury_heap.h:
    Include mercury_hgc.h when MR_HGC is defined.

runtime/mercury_memory_zones.c:
    Use mercury_hgc_add_roots_range when appropriate.

runtime/mercury_wrapper.c:
    Include initialisation code for HGC.

util/mkinit.c:
    Include a call to mercury_hgc_set_stack_bot in init files in the HGC grade.

runtime/mercury_conf_param.h:
runtime/mercury_grade.h:
scripts/canonical_grade.sh-subr
scripts/init_grade_options.sh-subr
scripts/mgnuc.in
scripts/ml.in
scripts/parse_grade_options.sh-subr
    Add the new hgc value for the garbage collector grade component.
2010-02-11 04:36:11 +00:00
Zoltan Somogyi
4083906e33 MERCURY_OPTIONS is a crude way to give options to Mercury programs, since it
Estimated hours taken: 1
Branches: main

MERCURY_OPTIONS is a crude way to give options to Mercury programs, since it
applies to all Mercury programs, even though we often want to give options to
only one specific Mercury program. (For example, we may want to give it only
to a test program's executable, and not to the invocation of the compiler
that generates it.) This diff makes the runtime system, when executing a
program named "progname", look for and process the environment variable
whose name is "MERCURY_OPTIONS-progname". This allows options to be given
at runtime to only one specific program.

runtime/mercury_wrapper.c:
	Make the change described above.

runtime/mercury_wrapper.h:
	Fix some obsolete documentation, and add some up-to-date documentation.

doc/user_guide.texi:
	Document the change.

util/mkinit.c:
	Fix indentation.
2008-05-21 02:48:59 +00:00
Zoltan Somogyi
2dc982cfe4 Make a representation of the program available to the deep profiler.
Estimated hours taken: 50
Branches: main

Make a representation of the program available to the deep profiler. We do
this by letting the user request, via the option "--deep-procrep-file"
in MERCURY_OPTIONS, that when the Deep.data file is written, a Deep.procrep
file should be written alongside it.

The intended use of this information is the discovery of profitable
parallelism. When a conjunction contains two expensive calls, e.g. p(...) and
q(...) connected by some shared variables, the potential gain from executing
them in parallel is limited by how early p produces those variables and how
late q consumes them, and knowing this requires access to the code of p and q.

Since the debugger and the deep profiler both need access to program
representations, put the relevant data structures and the operations on them
in mdbcomp. The data structures are significantly expanded, since the deep
profiler deals with the whole program, while the debugger was interested only
in one procedure at a time.

The layout structures have to change as well. In a previous change, I changed
proc layout structures to make room for the procedure representation even in
non-debugging grades, but this isn't enough, since the procedure representation
refers to the module's string table. This diff therefore makes some parts of
the module layout structure, including of course the string table, also
available in non-debugging grades.

configure.in:
	Check whether the installed compiler can process switches on foreign
	enums correctly, since this diff depends on that.

runtime/mercury_stack_layout.[ch]:
runtime/mercury_types.h:
	Add a new structure, MR_ModuleCommonLayout, that holds the part of
	the module layout that is common to deep profiling and debugging.

runtime/mercury_deep_profiling.[ch]:
	The old "deep profiling token" enum type was error prone, since at
	each point in the data file, only a subset was applicable. This diff
	breaks up the this enum into several enums, each consisting of the
	choice applicable at a given point.

	This also allows some of the resulting enums to be used in procrep
	files.

	Rename some enums and functions to avoid ambiguities, and in one case
	to conform to our naming scheme.

	Make write_out_proc_statics take a second argument. This is a FILE *
	that (if not NULL) asks write_out_proc_statics to write the
	representation of the current module to specified stream.

	These module representations go into the middle part of the program
	representation file. Add functions to write out the prologue and
	epilogue of this file.

	Write out procedure representations if this is requested.

	Factor out some code that is now used in more than one place.

runtime/mercury_deep_profiling_hand.h:
	Conform to the changes to mercury_deep_profiling.h.

runtime/mercury_builtin_types.c:
	Pass the extra argument in the argument lists of invocations of
	write_out_proc_statics.

runtime/mercury_trace_base.[ch]:
	Conform to the name change from proc_rep to proc_defn_rep in mdbcomp.

runtime/mercury_grade.h:
	Due to the change to layout structures, increment the binary
	compatibility version numbers for both debug and deep profiling grades.

runtime/mercury_wrapper.[ch]:
	Provide two new MERCURY_OPTION options. The first --deep-procrep-file,
	allows the user to ask for the program representation to be generated.
	The second, --deep-random-write, allows tools/bootcheck to request that
	only a fraction of all program invocations should generate any deep
	profiling output.

	The first option will be documented once it is tested much more fully.
	The second option is deliberately not documented.

	Update the type of the variable that holds the address of the
	(mkinit-generated) write_out_proc_statics function to accept the second
	argument.

util/mkinit.c:
	Pass the extra argument in the argument list of write_out_proc_statics.

mdbcomp/program_representation.m:
	Extend the existing data structures for representing a procedure body
	to represent a procedure (complete with name), a module and a program.
	The name is implemented as string_proc_label, a form of proc_label that
	can be written out to files. This replaces the old proc_id type the
	deep profiler.

	Extend the representation of switches to record the identity of the
	variable being switched on, and the cons_ids of the arms. Without the
	former, we cannot be sure when a variable is first used, and the latter
	is needed for meaningful prettyprinting of procedure bodies.

	Add code for reading in files of bytecodes, and for making sense of the
	bytecodes themselves. (It is this code that uses foreign enums.)

mdbcomp/prim_data.m:
	Note the relationship of proc_label with string_proc_label.

mdbcomp/rtti_access.m:
	Add the access operations needed to find module string tables with the
	new organization of layout structures.

	Provide operations on bytecodes and string tables generally.

trace/mercury_trace_cmd_browsing.c:
	Conform to the change to mdbcomp/program_representation.m.

compiler/layout.m:
	Add support for a MR_ModuleCommonLayout.

	Rename some function symbols to avoid ambiguities.

compiler/layout_out.m:
	Handle the new structure.

compiler/stack_layout.m:
	Generate the new structure and the procedure representation bytecode
	in deep profiling grades.

compiler/llds_out.m:
	Generate the code required to write out the prologue and epilogue
	of program representation files.

	Pass the extra argument in the argument lists of invocations of
	write_out_proc_statics that tells those invocations to write out
	the module representations between the prologue and the epilogue.

compiler/prog_rep.m:
	When generating bytecodes, include the new information for switches.

compiler/continuation_info.m:
	Replace a bool with a more expressive type.

compiler/proc_rep.m:
	Conform to the change to continuation_info.m.

compiler/opt_debug.m:
	Conform to the change to layout.m.

deep_profiler/mdprof_procrep.m:
	A new test program to test the reading of program representations.

deep_profiler/DEEP_FLAGS.in:
deep_profiler/Mmakefile:
	Copy the contents of the mdbcomp module to this directory on demand,
	instead of linking to it. This is necessary now that the deep profiler
	depends directly on mdbcomp even if it is compiled in a non-debugging
	grade.

	The arrangements for doing this were copied from the slice directory,
	which has long done the same.

	Avoid a duplicate include of Mmake.deep.params.

	Add the new test program to the list of programs in this directory.

Mmakefile:
	Go through deep_profiler/Mmakefile when deciding whether to do "mmake
	depend" in the deep_profiler directory. The old actions won't work
	correctly now that we need to copy some files from mdbcomp before we
	can run "mmake depend".

deep_profiler/profile.m:
	Remove the code that was moved (in cleaned-up form) to mdbcomp.

deep_profiler/dump.m:
deep_profiler/profile.m:
	Conform to the changes above.

browser/declarative_execution.m:
browser/declarative_tree.m:
	Conform to the changes in mdbcomp.

doc/user_guide.texi:
	Add commented out documentation of the two new options.

slice/Mmakefile:
	Fix formatting, and a bug.

library/exception.m:
library/par_builtin.m:
library/thread.m:
library/thread.semaphore.m:
	Update all the handwritten modules to pass the extra argument now
	required by write_out_proc_statics.

tests/debugger/declarative/dependency.exp:
	Conform to the change from proc_rep to proc_defn_rep.

tools/bootcheck:
	Write out deep profiling data only from every 25th invocation, since
	otherwise the time for a bootcheck takes six times as long in deep
	profiling grades than in asm_fast.gc.

	However, do test the ability to write out program representations.

	Use the mkinit from the workspace, not the installed one.

	Don't disable line wrapping.
2007-09-12 06:21:20 +00:00
Peter Ross
16f040e706 Allow mkinit_erl accept the -f flag as well.
Estimated hours taken: 1
Branches: main

Allow mkinit_erl accept the -f flag as well.

util/mkinit_erl.c:
	Accept the -f flag.

util/mkinit.c:
util/mkinit_common.c:
util/mkinit_common.h:
	Move the process_file_list_file into mkinit_common.c.
2007-06-18 05:41:31 +00:00
Peter Ross
a96327951d Windows has a limit on the command line length.
Estimated hours taken: 4
Branches: main

Windows has a limit on the command line length.  Allow mkinit
to be passed a list of files to be processed in a file via
-f to avoid this limit.

compiler/compile_target_code.m:
	Use the -f option to avoid overflowing the windows
	command line.

util/mkinit.c:
	Add code to handle the -f option.
2007-06-14 11:51:33 +00:00
Peter Wang
ac796041e5 Support :- initialise and :- finalise predicates in the Erlang backend.
Estimated hours taken: 12
Branches: main

Support :- initialise and :- finalise predicates in the Erlang backend.

compiler/compile_target_code.m:
	Refactor the code relating to running mkinit to generate .init and
	_init.c files, and compiling _init.c files.

	Generalise the code so that it can call mkinit_erl with the right
	options.

compiler/dead_proc_elim.m:
	Add initialisation and finalisation predicates to the queue at the
	start of the pass so that they won't be eliminated.  For the C
	backends we implicitly :- foreign_export init and final preds so they
	would never be eliminated, but we don't do that in the Erlang
	backend.

compiler/elds.m:
	Extend the ELDS to hold pred_proc_ids of init/final preds.

compiler/erl_code_gen.m:
compiler/mercury_compile.m:
	Conform to change in ELDS.

compiler/elds_to_erlang.m:
	Output mercury__required_init and mercury__required_final functions
	which call user initialisation and finalisation predicates, if any.

	Write out -export annotations for those functions.

	Write out REQUIRED_INIT and REQUIRED_FINAL directives for those
	functions.

compiler/hlds_module.m:
compiler/make_hlds_passes.m:
	Remember the arity of init/final preds in the HLDS, not just the
	sym_name.

	Add predicates to return the pred_proc_ids of init/final preds.

	Delete module_info_user_init_pred_c_name and
	module_info_user_final_pred_c_name as they are unused.

compiler/make.program_target.m:
	Call make_erlang_program_init_file and make_erlang_library_init_file
	when building an Erlang executable or library, respectively.

	Install a .init file when installing an Erlang library.

	Conform to changes in compile_target_code.m.

compiler/modules.m:
	In module_name_to_file_name, treat extensions specially if they end
	".erl" and ".beam", not only if they are exactly those strings.  This
	is because we may pass "_init.erl" or "_init.beam" as the extension.

compiler/options.m:
	Add an option `--mkinit-erl-command'.

util/Mmakefile:
util/.cvsignore:
util/mkinit_erl.c:
	Add `mkinit_erl' program which is a modified version of `mkinit'.

util/mkinit.c:
util/mkinit_common.c:
util/mkinit_common.h:
	Factor out code common to mkinit and mkinit_erl into mkinit_common.c
	and mkinit_common.h.

tests/hard_coded/Mmakefile:
	Fix misspellings of "MERCURY_SUPPRESS_STACK_TRACE".

tests/hard_coded/impure_init_and_final.m:
	Add Erlang foreign proc.
2007-06-08 00:47:52 +00:00
Julien Fischer
94b0a40b2c Improve support for calling procedures in Mercury libraries from
Estimated hours taken: 20
Branches: main

Improve support for calling procedures in Mercury libraries from
applications written in foreign languages, i.e where the program entry point
is not the Mercury predicate main/2.  The main trick is to ensure that the
necessary runtime initialisation is done before any Mercury procedures are
called (or at least to provide the mechanism to do such initialisation,
ensuring that it is done is the programmer's responsibility.)

We currently support this sort of thing via the compiler's `--no-main'
option.  This diff adds a more user friendly mechanism (at least on the
Mercury side.)  In particular, we no longer require that one of the Mercury
libraries define a main/2 predicate.  (Note: the existing behaviour of
--no-main is unchanged.)

For the set of Mercury libraries that we wish to use from a foreign
application we create a standalone interface.  A standalone interface is a
cut-down version of the _init.c file that would be created for a Mercury
executable that uses the same set of libraries.  (Which libraries to include
in the interface can be specified via the usual mechanisms, e.g. the --ml
option.)

The standalone interface has two parts: an object file that contains the
cut-down version of the _init.c file, and a header file that contains the
declarations for the functions that initialise and shut down the Mercury
runtime.  This header file is compatible with both C and C++.

compiler/options.m:
	Add a new option `--generate-standalone-interface' that causes the
	compiler to generate a header/object pair that can be used to
	intialise/shut down the Mercury runtime from a foreign application.
	The basename of the header/object pair is given as an argument to this
	option.

compiler/mercury_compile.m:
	Create the standalone interface if invoked with
	`--generate-standalone-interface'.

	Emit an error message if `--generate-standalone-interface' is
	specified with `--target java' or `--target il'.  We don't
	currently support that.

compiler/compile_target_code.m:
	Add code to implement the `--generate-standalone-interface' option.

	Fix a typo: s/Serarator/Separator/.

	Fix an overlong line.

compiler/handle_options.m:
	Emit an error message if `--generate-standalone-interface' and
	`--extra-inits' are specified together.

compiler/passes_aux.m:
	Fix some broken indentation.

util/mkinit.c:
	Add a new mode of operation that generates standalone interfaces.
	The principle differences between a standalone interface and a
	_init.c file are that the former sets the program entry point to
	MR_dummy_main and does not create a main function.

	The new `-s' option tells mkinit to create a standalone interface.
	(Note that `-s' implies `-l'.)

	Add a comment pointing to various places that may need to updated if
	mkinit.c is changed.

runtime/mercury_wrapper.{h,c}:
	Add a new procedure MR_dummy_main for use with standalone
	interfaces.  Any attempt to call main/2 through the usual entry
	point when operating in standalone mode will cause a runtime abort.
2007-02-09 04:05:18 +00:00
Zoltan Somogyi
1ed9e4e04c A program to help reformat C header files containing multi-line macro
Estimated hours taken: 0.2
Branches: main

util/pad_backslash.c:
	A program to help reformat C header files containing multi-line macro
	definitions. It is not installed or even by compiled by default, so
	it should have no impact on anyone, but will be available to
	developers.
2006-10-10 08:26:05 +00:00
Zoltan Somogyi
997b5a1c8c Implement the trace goal construct for the hlc grades.
Estimated hours taken: 5
Branches: main

Implement the trace goal construct for the hlc grades.

compiler/mlds.m:
	Extend the MLDS in a similar way to how the previous diff extended
	the LLDS. This means extending lvals to allow references to global
	variables representing the initial snapshots of environment variables,
	and recording the set of environment variables referred to by each
	definition.

compiler/mlds_to_c.m:
	Handle the extensions to the MLDS.

compiler/llds_out.m:
util/mkinit.c:
	Note that mlds_to_c.m now also depends on the naming scheme for the
	global variables representing environment variables.

compiler/ml_code_gen.m:
	When generating code for a procedure, remember the set of environment
	variables it refers to.

	When generating code for the special form of call_foreign_proc created
	by the transformation of trace goals with runtime conditions by
	simplify.m, generate the appropriate boolean expression involving
	references to environment variables.

compiler/ml_code_util.m:
	Provide storage space for recording the set of environment variables
	used in functions.

compiler/mlds_to_il.m:
compiler/mlds_to_gcc.m:
compiler/mlds_to_java.m:
compiler/mlds_to_managed.m:
	Abort if asked to translate functions that include references to
	environment variables, since this is preferable to silently doing
	the wrong thing.

compiler/*.m:
	Misc changes required to conform to the change to the MLDS.
2006-07-31 03:13:53 +00:00
Zoltan Somogyi
9d23d8e2e7 Implement the trace goal construct we discussed, for now for the LLDS backends
Estimated hours taken: 70
Branches: main

Implement the trace goal construct we discussed, for now for the LLDS backends
only.

Since the syntax of trace goals is non-trivial, useful feedback on syntax
errors inside trace goal attributes is essential. With the previous setup, this
wasn't possible, since the code that turned terms into parse tree goals turned
*all* terms into goals; it couldn't recognize any errors, sweeping them under
the rug as calls. This diff changes that. Now, if this code recognizes a
keyword that indicates a particular construct, it insists on the rest of the
code following the syntax required for that construct, and returns error
messages if it doesn't.

We handle the trace goal attributes that specify state variables to be threaded
through the trace goal (either the I/O state or a mutable variable) in
add_clause.m, at the point at which we transform the list of items to the HLDS.
We handle the compile-time condition on trace goals in the invocation of
simplify at the end of semantics analysis, by eliminating the goal if the
compile-time condition isn't met. We handle run-time conditions on trace goals
partially in the same invocation of simplify: we transform trace goals with
runtime conditions into an if-then-else with the trace goal as the then part
and `true' as the else part, the condition being a foreign_proc that is handled
specially by the code generator, that special handling being to replace
the actual code of the foreign_proc (which is a dummy) with the evaluation of
the runtime condition.

Since these changes require significant changes to some of our key data
structures, I took the liberty of doing some renaming of function symbols
at the same time to avoid using ambiguities with respect to language keywords.

library/ops.m:
	Add "trace" as an operator.

compiler/prog_data.m:
	Define data types to represent the various attributes of trace goals.

	Rename some function symbols to avoid ambiguities.

compiler/prog_item.m:
	Extend the parse tree representation of goals with a trace goal.

compiler/mercury_to_mercury.m:
	Output the new kind of goal and its components.

compiler/hlds_goal.m:
	Extend the HLDS representation of scopes with a scope_reason
	representing trace goals.

	Add a mechanism (an extra argument in foreign_procs) to allow
	the representation of goals that evaluate runtime trace conditions.

	Since this requires modifying all code that traverses the HLDS,
	do some renames that were long overdue: rename not as negation,
	rename call as plain_call, and rename foreign_proc as
	call_foreign_proc. These renames all avoid using language keywords
	as function symbols.

	Change the way we record goals' purities. Instead of optional features
	to indicate impure or semipure, which is error-prone, use a plain
	field in the goal_info, accessed in the usual way.

	Add a way to represent that a goal contains a trace goal, and should
	therefore be treated as if it were impure when considering whether to
	optimize it away.

	Reformat some comments describing function symbols.

compiler/hlds_out.m:
	Output the new construct in the HLDS.

compiler/prog_io_util.m:
	Generalize the maybe[123] types to allow the representation of more
	than one error message. Add functions to extract the error messages.
	Add a maybe4 type. Rename the function symbols of these types to
	avoid massive ambiguity.

	Change the order of some predicates to bring related predicates
	next to each other.

compiler/prog_io.m:
compiler/prog_io_dcg.m:
compiler/prog_io_goal.m:
compiler/prog_io_pragma.m:
	Rework these modules almost completely to find and accumulate syntax
	errors as terms are being parsed. In some cases, this allowed us to
	replace "XXX this is a hack" markers with meaningful error-reporting
	code.

	In prog_io_goal.m, add code for parsing trace goals.

	In a bunch of places, update obsolete coding practices, such as using
	nested chains of closures instead of simple sequential code, and
	using A0 and A to refer to values of different types (terms and goals
	respectively). Use more meaningful variable names.

	Break up some too-large predicates.

compiler/superhomogeneous.m:
	Find and accumulate syntax errors as terms are being parsed.

compiler/add_clause.m:
	Add code to transform trace goals from the parse tree to the HLDS.
	This is where the IO state and mutable variable attributes of trace
	goals are handled.

	Eliminate the practice of using the naming scheme Body0 and Body
	to refer to values of different types (prog_item.goal and hlds_goal
	respectively).

	Use error_util for some error messages.

library/private_builtin.m:
	Add the predicates referred to by the transformation in add_clause.m.

compiler/goal_util.m:
	Rename a predicate to avoid ambiguity.

compiler/typecheck.m:
	Do not print error messages about missing clauses if some errors have
	been detected previously.

compiler/purity.m:
	Instead of just computing purity, compute (and record) also whether
	a goal contains a trace goal. However, treat trace goals as pure.

compiler/mode_info.m:
	Add trace goals as a reason for locking variables.

	Rename some function symbols to avoid ambiguity.

compiler/modes.m:
	When analyzing trace goal scopes, lock the scope's nonlocal variables
	to prevent them from being further instantiated.

compiler/det_analysis.m:
	Insist on the code in trace goal scopes being det or cc_multi.

compiler/det_report.m:
	Generate the error message if the code in a trace goal scope isn't det
	or cc_multi.

compiler/simplify.m:
	At the end of the front end, eliminate trace goal scopes if their
	compile-time condition is false. Transform trace goals with runtime
	conditions as described at the top.

	Treat goals that contain trace goals as if they were impure when
	considering whether to optimize them away.

compiler/mercury_compile.m:
	Tell simplify when it is being invoked at the end of the front end.

	Rename a predicate to avoid ambiguity.

compiler/trace_params.m:
	Provide the predicates simplify.m need to be able to evaluate the trace
	goal conditions regarding trace levels.

compiler/trace.m:
compiler/trace_gen.m:
	Rename the trace module as trace_gen, since "trace" is now an operator.

	Rename some predicates exported by the module, now that it is no longer
	possible to preface calls with "trace." as a module qualifier.

compiler/notes/compiler_design.html:
	Document this name change.

compiler/options.m:
	Rename the trace option as trace_level internally, since "trace"
	is now an operator. The user-visible name remains the same.

	Add the new --trace-flag option.

	Delete an obsolete option.

compiler/handle_options.m:
	Rename the function symbols of the grade_component type,
	since "trace" is now an operator.

compiler/llds.m:
	Extend the LLDS with a mechanism to refer to C global variables.
	For now, these are used to refer to C globals that will be created
	by mkinit to represent the initial values of the environment variables
	referred to by trace goals.

compiler/commit_gen.m:
	Check that no trace goal with a runtime condition survives to code
	generation; they should have been transformed by simplify.m.

compiler/code_gen.m:
	Tell commit_gen.m what kind of scope it is generating code for.

compiler/pragma_c_gen.m:
	Generate code for runtime conditions when handling the foreign_procs
	created by simplify.m.

compiler/code_info.m:
	Allow pragma_c_gen.m to record what environment variables it has
	generated references to.

compiler/proc_gen.m:
	Record the set of environment variables a procedure refers to
	in the LLDS procedure header, for efficient access by llds_out.m.

compiler/llds_out.m:
	Handle the new LLDS construct, and tell mkinit which environment
	variables need C globals created for them.

compiler/pd_util.m:
	Rename some predicates to avoid ambiguity.

compiler/*.m:
	Conform to the changes above, mainly the renames of function symbols
	and predicates, the changed signatures of some predicates, and the new
	handling of purity.

util/mkinit.c:
	Generate the definitions and the initializations of any C globals
	representing the initial status (set or not set) of environment
	variables needed by trace goals.

library/assoc_list.m:
	Add some predicates that are useful in prog_io*.m.

library/term_io.m:
	Minor cleanup.

tests/hard_coded/trace_goal_{1,2}.{m,exp}:
	New test cases to test the new construct, identical except for whether
	the trace goal is enabled at compile time.

tests/hard_coded/trace_goal_env_{1,2}.{m,exp}:
	New test cases to test the new construct, identical except for whether
	the trace goal is enabled at run time.

tests/hard_coded/Mercury.options:
tests/hard_coded/Mmakefile:
	Enable the new test cases.

tests/invalid/*.err_exp:
	Update the expected output for the new versions of the error messages
	now being generated.
2006-07-27 05:03:54 +00:00
Julien Fischer
a2de6b0516 Fix a buglet that broke the nightly builds on ceres.
Estimated hours taken: 0
Branches: main, release

Fix a buglet that broke the nightly builds on ceres.

util/mkinit.c:
	Shift the variable declarations in main to the beginning of the block.
2006-05-17 14:42:31 +00:00
Julien Fischer
4e715901ba Fix the bug with initialisers/finalisers in libraries not being called ( and
Estimated hours taken: 7
Branches: main, release

Fix the bug with initialisers/finalisers in libraries not being called ( and
as consequence also fixes the bug with mutables not being given their correct
initial value).  The problem was that the directives necessary to call them
were not being included in the libraries' .init file.

The fix is to add a new mode of operation to mkinit that given a list of
.c files that make up some Mercury library, constructs the .init file for
that library.  In particular, it now constructs the .init file so that
it contains any REQUIRED_{INIT,FINAL} directives needed by the library.
The new mode of operation is invoked when mkinit is given the `-k' option.

Changes to the build systems to use the new mode of operation will be committed
after the changes to mkinit have bootchecked.

util/mkinit.c:
	Add a new mode of operation, `-k'.  When invoked with this
	option mkinit will read a list of .c files and emit a sequence of
	INIT, REQUIRED_INIT and REQUIRED_FINAL directives to stdout,
	corresponding to INIT, REQUIRED_INIT and REQUIRED_FINAL comments
	in the .c files.
2006-05-17 07:52:50 +00:00
Julien Fischer
1f5a7858a7 Delete some left over Aditi stuff.
Estimated hours taken: 0.1
Branches: main, release

util/mkinit.c:
	Delete some left over Aditi stuff.
2006-05-05 07:49:29 +00:00
Julien Fischer
9d8ca0ad37 Remove residual parts of the Aditi backend that weren't deleted the other day.
Estimated hours taken: 1.5
Branches: main

Remove residual parts of the Aditi backend that weren't deleted the other day.

configure.in:
Mmake.common.in:
	Remove support for enabling the Aditi backend.

runtime/mercury_aditi.h:
	Remove this file.

runtime/Mmakefile:
runtime/mercury.h:
runtime/mercury_imp.h:
runtime/mercury_ho_call.[ch]:
runtime/mercury_wrapper.[ch]:
	Delete support for Aditi in the runtime.

scripts/Mmake.rules:
scripts/Mmake.vars.in:
scripts/c2init.in:
scripts/parse_ml_options.sh-subr.in:
	Remove mmake support for building .rlo files, etc.

util/mkinit.c:
	Remove Aditi specific code.

compiler/bytecode_data.m:
compiler/closure_analysis.m:
compiler/code_model.m:
compiler/compile_target_code.m:
compiler/det_analysis.m:
compiler/handle_options.m:
compiler/hlds_goal.m:
compiler/hlds_module.m:
compiler/make.dependencies.m:
compiler/make.m:
compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/make.util.m:
compiler/make_hlds_error.m:
compiler/make_hlds_passes.m:
compiler/mercury_to_mercury.m:
compiler/mlds_to_gcc.m:
compiler/modecheck_call.m:
compiler/modules.m:
compiler/opt_debug.m:
compiler/options.m:
compiler/prog_data.m:
compiler/prog_foreign.m:
compiler/prog_mode.m:
compiler/prog_type.m:
compiler/rtti.m:
compiler/rtti_out.m:
compiler/rtti_to_mlds.m:
compiler/term_errors.m:
compiler/unify_proc.m:
mdbcomp/prim_data.m:
	Remove residual support for Aditi.

library/ops.m:
	Remove the 'aditi_bottom_up' and 'aditi_top_down' operators from the
	ops table.

doc/reference_manual.texi:
doc/user_guide.texi:
	Delete the sections on the Aditi interface.

extras/aditi/*:
	Delete this.
2006-02-24 07:11:21 +00:00
Julien Fischer
570f2aa3c5 Update the documentation to reflect the fact that mlds_to_c.m
Estimated hours taken: 0.4
Branches: main

util/mkinit.c:
	Update the documentation to reflect the fact that mlds_to_c.m
	also generates ENDINIT comments.

	Fix a typo.

README.MinGW:
library/io.m:
library/store.m:
runtime/mercury.h:
runtime/mercry_wrapper.c:
runtime/mercury_goto.h:
	Fix some typos.
2005-10-11 04:45:52 +00:00
Zoltan Somogyi
e9eea1bbbd Fix a bug: stop reading .c files when reaching a line containing
Estimated hours taken: 0.5
Branches: main

util/mkinit.c:
	Fix a bug: stop reading .c files when reaching a line containing
	"ENDINIT", instead of looking for the string "ENDINIT " with the space
	at the end, which llds_out.m doesn't put there. This reduces the amount
	of code mkinit has to scan when the compiler is compiled with debugging
	enabled from 200 Mb (which takes more than a minute) to 110 Kb.

	If CHECK_GET_LINE is defined, copy the lines read to a file named
	".check_get_line". This facility is what I used to find the bug.

	Delete an unused function.
2005-10-04 23:48:34 +00:00
Julien Fischer
29c44a3e93 Add the initial stage of finalise declarations.
Estimated hours taken: 2
Branches: main

Add the initial stage of finalise declarations.  These are a counterpart
to the recently added intialise declarations; they allow the user to specify
predicates that are to be run after main/2 exits.

util/mkinit.c:
	Add support for `REQUIRED_FINAL' directives.  These are similar to
	`REQUIRED_INIT' directives except that the specified functions are
	run after main/2.  Any functions specified using this directive are
	gathered into bunches and called from the final_module_required
	function.

runtime/mercury_wrapper.h:
runtime/mercury_wrapper.c:
	Export a new global that points to the final_module_required function
	for the program.
2005-09-28 06:00:58 +00:00
Zoltan Somogyi
99293279e6 This is step 1 of eliminating the arguments of the type_ctor_info, type_info,
Estimated hours taken: 8
Branches: main

This is step 1 of eliminating the arguments of the type_ctor_info, type_info,
base_typeclass_info and typeclass_info type constructors. This step doesn't
delete those arity-1 type constructors yet; that will be done in step 2.
This delay due to bootstrapping issues: installed compilers still generate
references to those type constructors. However, after this change, compilers
will instead generate references to arity-0 versions of those types named
zero_type_ctor_info, zero_type_info, zero_base_typeclass_info and
zero_typeclass_info.

library/private_builtin.m:
	Add the new type constructors.

	For each predicate that operates on the old arity-1 type constructors,
	add a version that operates on the new type arity-0 onstructors,
	and whose implementation is identical.

runtime/mercury_builtin_types.m:
	Add the unify and compare predicates of the new type constructors.

runtime/mercury_wrapper.[ch]:
runtime/mercury_init.h:
util/mkinit.c:
	Change the C type of the variable that holds the types of type_infos
	and pseudo_type_infos, since their representation is now simpler
	(no dummy argument).

trace/mercury_trace_vars.c:
	Modify data structures that recognize the four old types to recognize
	their new variants as well.

compiler/higher_order.m:
compiler/polymorphism.m:
	Generate references to the new versions of predicates that manipulate
	type_infos and typeclass_infos.

compiler/hlds_pred.m:
compiler/ml_code_util.m:
compiler/type_ctor_info.m:
	Modify predicates that recognize the four old types to recognize their
	new variants as well.

compiler/type_util.m:
	Modify the predicates that construct the types of type_infos
	to create references to the new arity-0 type constructors.

	Modify predicates that recognize the four old types to recognize their
	new variants as well.

	Delete the predicate whose job was to replace the dummy arguments
	of the arity-1 type constructors with the void type, since it is not
	needed anymore.

	Delete the unused predicate cell_type_name.

compiler/stack_layout.m:
	Fix comment.

compiler/size_prof.m:
	Conform to the changes in type_util.

compiler/pseudo_type_info.m:
	Conform to the changes in type_util.

	Convert to four-space indentation.
2005-09-19 07:26:38 +00:00
Simon Taylor
72050b3688 Remove an unnecessary Aditi #include.
Estimated hours taken: 0.1
Branches: main

util/mkinit.c:
	Remove an unnecessary Aditi #include.
2005-09-12 15:15:16 +00:00
Ralph Becket
88b75863dc Add support for initialisation predicates to be called before main/2 is
Estimated hours taken: 16
Branches: main

Add support for initialisation predicates to be called before main/2 is
invoked.  The new directive is `:- initialise initpredname.'

NEWS:
	Mention the new functionality.

compiler/export.m:
	`:- pragma export' also adds a C function declaration in the
	generated C wrapper code to avoid C compiler warnings about
	missing declarations.

compiler/hlds_module.m:
	Added a new user_init_preds field to the module_info to
	record the preds named in `initialise' directives.
	Added predicates to access and update the new field.
	The exported names are generated automatically.

compiler/llds.m:
	Added a new field cfile_num_user_inits to c_file structure.

compiler/llds_out.m:
	Add code to include the `REQUIRED_INIT initpredexportname' lines
	in the comment section of the generated C that is recognised
	by mkinit.

compiler/make_hlds_passes.m:
	Handle the new `initialise' directives.

compiler/mercury_compile.m:
	Make sure the list of user defined init pred export names is passed to
	the C code construction preds.

compiler/mercury_to_mercury.m:
	Handle the output of `initialise' directives.

compiler/module_qual.m:
compiler/modules.m:
compiler/recompilation.check.m:
compiler/recompilation.version.m:
	Handle the new `initialise' item.

compiler/prog_data.m:
	Add a new `initialise(sym_name)' item.

compiler/prog_io.m:
	Add code to parse `initialise' directives.

compiler/prog_mode.m:
	Add di_mode pred and func.

compiler/transform_llds.m:
	Handle the extra field in c_file.

doc/reference_manual.texi:
	Update the operator table in the reference manual.
	Document the new `initialise' directive.

library/list.m:
	Added index[01]_of_first_occurrence preds and
	det_index[01]_of_first_occurrence funcs.  I've often
	had a need for these and they are used in looking up
	initprednames in the new module_info field.

library/ops.m:
	Add `initialise' as a prefix operator.

runtime/mercury_wrapper.c:
runtime/mercury_wrapper.h:
	Add a new exported variable, MR_address_of_init_modules_required.
	Call the function pointed to by this variable at the right point
	during module initialisation.

test/hard_coded/Mmakefile:
test/hard_coded/initialise_decl.exp:
test/hard_coded/initialise_decl.m:
test/invalid/Mmakefile:
test/invalid/bad_initialise_decl.err_exp:
test/invalid/bad_initialise_decl.m:
	Added test cases.

util/mkinit.c:
	Now always checks C files for extra inits (previously you had to
	explicitly supply the -x flag).
2005-08-29 03:22:32 +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