[m-dev.] for review: register type_ctor_infos, part 2
Zoltan Somogyi
zs at cs.mu.OZ.AU
Mon Oct 30 16:45:25 AEDT 2000
For review by anyone.
This is part 2 of a change that provides a register of all the types defined
in the program.
util/mkinit.c:
After part 1 of this change, each compiler-generated module has three
initialization functions: the old one (to register label addresses
etc), one to register type_ctor_infos, and one to register module
layouts for the debugger. However, only the first was invoked from
the mkinit generated <mainmodule>_init.c file.
This change invokes the other two as well. One complication is that
hand-written "modules" do not have the two new kinds of initialization
functions, so only their first initialization function should be
called. We do this by requiring those "modules" to have one of two
specific forms: an initial prefix of either sys_init or
mercury_sys_init.
scripts/c2init.in:
Rerrange the mechanism we use to allow the overriding of the locations
of the init files to be passed to mkinit. The previous mechanism used
a single environment variable, MERCURY_MOD_LIB_MODS, to hold the names
of these init files. While the default setting of this variable was
conditional on whether the --trace option was given to c2init
(including the init file for the browser only with --trace),
there was no way to override the default value in a similarly
conditional manner. This is now a problem, because including the
browser init file in the list of init files passed to mkinit will
cause mkinit to emit code that causes the browser's modules to be
linked in, without also linking in the libraries (e.g. -ldl) on which
the browser depends. The reason why this hasn't bitten us earlier
is that the code that drags in the browser was #ifdef'ed out
in the first initialization function; the reason why it would
bite us now is that it is *not* #ifdef'ed out in the second
initialization function (the one that register type_ctor_infos).
The new mechanism uses two environment variables, MERCURY_MOD_LIB_MODS
and MERCURY_TRACE_LIB_MODS, with the first normally containing
the filenames of the init files of the runtime and library directories
and the second the filename of the init file of the browser directory.
The value of the second environment variable is passed to mkinit
only if c2init is invoked with the --trace flag.
There is also a new environment variable MERCURY_TRACE_LIB_DIR,
which has a role parallel to MERCURY_MOD_LIB_DIR.
compiler/Mmakefile:
profiler/Mmakefile:
tools/bootcheck:
Specify the filename of the browser init file in
MERCURY_TRACE_LIB_MODS.
library/array.m:
library/builtin.m:
library/private_builtin.m:
library/std_util.m:
Add code to initialization functions to register the type_ctor_infos
of hand-defined types.
Note that this code is in the usual initialization function, the one
called by do_init_modules(). Putting this code in a separate
initialization function that is called by do_init_modules_type_tables()
would require complicating mkinit.c considerably.
runtime/mercury_wrapper.c:
Make do_init_modules_type_tables() call do_init_modules(), so that
calling do_init_modules_type_tables() guarantees the registration
of all the type_ctor_infos in the program, including the hand-defined
ones.
runtime/mercury_context.c:
Make the name of the handwritten module follow the convention now
required by mkinit.
Zoltan.
cvs diff: Diffing .
cvs diff: Diffing bindist
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing browser
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
Index: compiler/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/Mmakefile,v
retrieving revision 1.32
diff -u -b -r1.32 Mmakefile
--- compiler/Mmakefile 2000/09/29 10:58:13 1.32
+++ compiler/Mmakefile 2000/10/13 13:50:32
@@ -38,7 +38,8 @@
MCG = $(M_ENV) $(SMC) --compile-to-c
MCS = $(M_ENV) $(SMC) --split-c-files -c --cflags "$(ALL_CFLAGS)"
MGNUC = $(M_ENV) $(SCRIPTS_DIR)/mgnuc
-C2INIT = MERCURY_MOD_LIB_MODS="$(BROWSER_DIR)/$(BROWSER_LIB_NAME).init $(LIBRARY_DIR)/$(STD_LIB_NAME).init $(RUNTIME_DIR)/$(RT_LIB_NAME).init" \
+C2INIT = MERCURY_MOD_LIB_MODS="$(LIBRARY_DIR)/$(STD_LIB_NAME).init $(RUNTIME_DIR)/$(RT_LIB_NAME).init" \
+ MERCURY_TRACE_LIB_MODS="$(BROWSER_DIR)/$(BROWSER_LIB_NAME).init" \
MERCURY_MKINIT=$(UTIL_DIR)/mkinit $(SCRIPTS_DIR)/c2init
ML = MERCURY_C_LIB_DIR=. $(SCRIPTS_DIR)/ml
MLFLAGS = --mercury-libs none
cvs diff: Diffing compiler/notes
cvs diff: Diffing debian
cvs diff: Diffing doc
cvs diff: Diffing extras
cvs diff: Diffing extras/aditi
cvs diff: Diffing extras/cgi
cvs diff: Diffing extras/complex_numbers
cvs diff: Diffing extras/complex_numbers/samples
cvs diff: Diffing extras/complex_numbers/tests
cvs diff: Diffing extras/concurrency
cvs diff: Diffing extras/curses
cvs diff: Diffing extras/curses/sample
cvs diff: Diffing extras/dynamic_linking
cvs diff: Diffing extras/graphics
cvs diff: Diffing extras/graphics/mercury_opengl
cvs diff: Diffing extras/graphics/mercury_tcltk
cvs diff: Diffing extras/graphics/samples
cvs diff: Diffing extras/graphics/samples/calc
cvs diff: Diffing extras/graphics/samples/maze
cvs diff: Diffing extras/graphics/samples/pent
cvs diff: Diffing extras/lazy_evaluation
cvs diff: Diffing extras/logged_output
cvs diff: Diffing extras/moose
cvs diff: Diffing extras/moose/samples
cvs diff: Diffing extras/morphine
cvs diff: Diffing extras/morphine/non-regression-tests
cvs diff: Diffing extras/morphine/scripts
cvs diff: Diffing extras/morphine/source
cvs diff: Diffing extras/odbc
cvs diff: Diffing extras/posix
cvs diff: Diffing extras/references
cvs diff: Diffing extras/references/samples
cvs diff: Diffing extras/references/tests
cvs diff: Diffing extras/trailed_update
cvs diff: Diffing extras/trailed_update/samples
cvs diff: Diffing extras/trailed_update/tests
cvs diff: Diffing extras/xml
cvs diff: Diffing library
Index: library/array.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/array.m,v
retrieving revision 1.74
diff -u -b -r1.74 array.m
--- library/array.m 2000/10/16 01:33:41 1.74
+++ library/array.m 2000/10/16 02:29:18
@@ -314,6 +314,8 @@
MR_INIT_TYPE_CTOR_INFO(
mercury_data_array__type_ctor_info_array_1,
array__array_1_0);
+ MR_register_type_ctor_info(
+ &mercury_data_array__type_ctor_info_array_1);
}
#endif /* ! MR_HIGHLEVEL_CODE */
Index: library/builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/builtin.m,v
retrieving revision 1.41
diff -u -b -r1.41 builtin.m
--- library/builtin.m 2000/10/23 15:08:23 1.41
+++ library/builtin.m 2000/10/27 08:07:43
@@ -340,6 +340,23 @@
mercury_data___type_ctor_info_tuple_0, _tuple_);
MR_INIT_TYPE_CTOR_INFO_WITH_PRED(
mercury_data___type_ctor_info_void_0, mercury__unused_0_0);
+
+ MR_register_type_ctor_info(
+ &mercury_data___type_ctor_info_int_0);
+ MR_register_type_ctor_info(
+ &mercury_data___type_ctor_info_float_0);
+ MR_register_type_ctor_info(
+ &mercury_data___type_ctor_info_character_0);
+ MR_register_type_ctor_info(
+ &mercury_data___type_ctor_info_string_0);
+ MR_register_type_ctor_info(
+ &mercury_data___type_ctor_info_pred_0);
+ MR_register_type_ctor_info(
+ &mercury_data___type_ctor_info_func_0);
+ MR_register_type_ctor_info(
+ &mercury_data___type_ctor_info_tuple_0);
+ MR_register_type_ctor_info(
+ &mercury_data___type_ctor_info_void_0);
}
#endif /* ! HIGHLEVEL_CODE */
@@ -509,9 +526,13 @@
/* duplicate declaration to suppress gcc -Wmissing-decl warning */
void sys_init_unify_c_pointer_module(void) {
unify_c_pointer_module();
+
MR_INIT_TYPE_CTOR_INFO(
mercury_data_builtin__type_ctor_info_c_pointer_0,
builtin__c_pointer_0_0);
+
+ MR_register_type_ctor_info(
+ &mercury_data_builtin__type_ctor_info_c_pointer_0);
}
#endif /* ! MR_HIGHLEVEL_CODE */
Index: library/private_builtin.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/private_builtin.m,v
retrieving revision 1.56
diff -u -b -r1.56 private_builtin.m
--- library/private_builtin.m 2000/09/20 12:12:36 1.56
+++ library/private_builtin.m 2000/10/14 10:06:24
@@ -419,6 +419,15 @@
MR_INIT_TYPE_CTOR_INFO(
mercury_data_private_builtin__type_ctor_info_typeclass_info_1,
private_builtin__typeclass_info_1_0);
+
+ MR_register_type_ctor_info(
+ &mercury_data_private_builtin__type_ctor_info_type_ctor_info_1);
+ MR_register_type_ctor_info(
+ &mercury_data_private_builtin__type_ctor_info_type_info_1);
+ MR_register_type_ctor_info(
+ &mercury_data_private_builtin__type_ctor_info_base_typeclass_info_1);
+ MR_register_type_ctor_info(
+ &mercury_data_private_builtin__type_ctor_info_typeclass_info_1);
}
#endif /* ! MR_HIGHLEVEL_CODE */
Index: library/std_util.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/std_util.m,v
retrieving revision 1.202
diff -u -b -r1.202 std_util.m
--- library/std_util.m 2000/10/16 01:33:47 1.202
+++ library/std_util.m 2000/10/16 02:29:20
@@ -1240,10 +1240,17 @@
void sys_init_unify_univ_module(void) {
unify_univ_module();
- MR_INIT_TYPE_CTOR_INFO(mercury_data_std_util__type_ctor_info_univ_0,
+ MR_INIT_TYPE_CTOR_INFO(
+ mercury_data_std_util__type_ctor_info_univ_0,
std_util__univ_0_0);
- MR_INIT_TYPE_CTOR_INFO(mercury_data_std_util__type_ctor_info_type_desc_0,
+ MR_INIT_TYPE_CTOR_INFO(
+ mercury_data_std_util__type_ctor_info_type_desc_0,
std_util__type_desc_0_0);
+
+ MR_register_type_ctor_info(
+ &mercury_data_std_util__type_ctor_info_univ_0);
+ MR_register_type_ctor_info(
+ &mercury_data_std_util__type_ctor_info_type_desc_0);
}
#endif /* ! MR_HIGHLEVEL_CODE */
cvs diff: Diffing profiler
Index: profiler/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/profiler/Mmakefile,v
retrieving revision 1.17
diff -u -b -r1.17 Mmakefile
--- profiler/Mmakefile 2000/09/22 08:23:45 1.17
+++ profiler/Mmakefile 2000/10/14 03:49:36
@@ -36,7 +36,8 @@
MCG = $(M_ENV) $(MC) --compile-to-c
MCS = $(M_ENV) $(MC) --split-c-files -c --cflags "$(ALL_CFLAGS)"
MGNUC = $(M_ENV) $(SCRIPTS_DIR)/mgnuc
-C2INIT = MERCURY_MOD_LIB_MODS="$(BROWSER_DIR)/$(BROWSER_LIB_NAME).init $(LIBRARY_DIR)/$(STD_LIB_NAME).init $(RUNTIME_DIR)/$(RT_LIB_NAME).init" \
+C2INIT = MERCURY_MOD_LIB_MODS="$(LIBRARY_DIR)/$(STD_LIB_NAME).init $(RUNTIME_DIR)/$(RT_LIB_NAME).init" \
+ MERCURY_TRACE_LIB_MODS="$(BROWSER_DIR)/$(BROWSER_LIB_NAME).init" \
MERCURY_MKINIT=$(UTIL_DIR)/mkinit $(SCRIPTS_DIR)/c2init
ML = MERCURY_C_LIB_DIR=. $(SCRIPTS_DIR)/ml
MLFLAGS = --mercury-libs none
cvs diff: Diffing robdd
cvs diff: Diffing runtime
Index: runtime/mercury_context.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_context.c,v
retrieving revision 1.25
diff -u -b -r1.25 mercury_context.c
--- runtime/mercury_context.c 2000/10/16 01:33:55 1.25
+++ runtime/mercury_context.c 2000/10/16 02:29:26
@@ -1,5 +1,5 @@
/*
-INIT mercury_scheduler_wrapper
+INIT mercury_sys_init_scheduler_wrapper
ENDINIT
*/
/*
@@ -370,7 +370,7 @@
END_MODULE
-void mercury_scheduler_wrapper(void); /* suppress gcc warning */
-void mercury_scheduler_wrapper(void) {
+void mercury_sys_init_scheduler_wrapper(void); /* suppress gcc warning */
+void mercury_sys_init_scheduler_wrapper(void) {
scheduler_module();
}
Index: runtime/mercury_wrapper.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.74
diff -u -b -r1.74 mercury_wrapper.c
--- runtime/mercury_wrapper.c 2000/10/22 06:58:53 1.74
+++ runtime/mercury_wrapper.c 2000/10/27 08:07:45
@@ -437,6 +437,14 @@
if (! done) {
(*address_of_init_modules_type_tables)();
done = TRUE;
+
+ /*
+ ** Some system-defined types have the code to register
+ ** their type_ctor_infos in the initialization function
+ ** invoked by do_init_modules.
+ */
+
+ do_init_modules();
}
}
cvs diff: Diffing runtime/GETOPT
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/diff
cvs diff: Diffing samples/muz
cvs diff: Diffing samples/rot13
cvs diff: Diffing samples/solutions
cvs diff: Diffing samples/tests
cvs diff: Diffing samples/tests/c_interface
cvs diff: Diffing samples/tests/c_interface/c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/tests/c_interface/mercury_calls_c
cvs diff: Diffing samples/tests/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/tests/c_interface/mercury_calls_fortran
cvs diff: Diffing samples/tests/c_interface/simpler_c_calls_mercury
cvs diff: Diffing samples/tests/c_interface/simpler_cplusplus_calls_mercury
cvs diff: Diffing samples/tests/diff
cvs diff: Diffing samples/tests/muz
cvs diff: Diffing samples/tests/rot13
cvs diff: Diffing samples/tests/solutions
cvs diff: Diffing samples/tests/toplevel
cvs diff: Diffing scripts
Index: scripts/c2init.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/c2init.in,v
retrieving revision 1.28
diff -u -b -r1.28 c2init.in
--- scripts/c2init.in 2000/05/12 05:13:33 1.28
+++ scripts/c2init.in 2000/10/14 03:46:02
@@ -21,6 +21,7 @@
BROWSER_LIB_NAME=mer_browser
MERCURY_MOD_LIB_DIR=${MERCURY_MOD_LIB_DIR=@LIBDIR@/modules}
+MERCURY_TRACE_LIB_DIR=${MERCURY_TRACE_LIB_DIR=@LIBDIR@/modules}
MKINIT=${MERCURY_MKINIT=mkinit}
# maximum number of calls to put in a single function
@@ -81,7 +82,8 @@
$grade_usage
Environment variables:
- MERCURY_MOD_LIB_DIR, MERCURY_MOD_LIB_MODS, MERCURY_MKINIT.
+ MERCURY_MOD_LIB_DIR, MERCURY_MOD_LIB_MODS,
+ MERCURY_TRACE_LIB_DIR, MERCURY_TRACE_LIB_MODS, MERCURY_MKINIT.
"
while true; do
@@ -138,6 +140,8 @@
shift
done
+set -x
+
# include the file `final_grade_options.sh-subr'
@FINAL_GRADE_OPTIONS@
@@ -151,30 +155,31 @@
init_opt="-i" ;;
esac
+MERCURY_MOD_LIB_MODS=${MERCURY_MOD_LIB_MODS="\
+ $MERCURY_MOD_LIB_DIR/$RT_LIB_NAME.init \
+ $MERCURY_MOD_LIB_DIR/$STD_LIB_NAME.init"}
+
+MERCURY_TRACE_LIB_MODS=${MERCURY_TRACE_LIB_MODS="\
+ $MERCURY_TRACE_LIB_DIR/$BROWSER_LIB_NAME.init"}
+
case "$trace_opt" in
-t)
init_opt="-i"
- MERCURY_MOD_LIB_MODS=${MERCURY_MOD_LIB_MODS="\
- $MERCURY_MOD_LIB_DIR/$RT_LIB_NAME.init \
- $MERCURY_MOD_LIB_DIR/$STD_LIB_NAME.init \
- $MERCURY_MOD_LIB_DIR/$BROWSER_LIB_NAME.init \
- "}
+ MERCURY_ALL_LIB_MODS="$MERCURY_MOD_LIB_MODS\
+ $MERCURY_TRACE_LIB_MODS"
;;
*)
- MERCURY_MOD_LIB_MODS=${MERCURY_MOD_LIB_MODS="\
- $MERCURY_MOD_LIB_DIR/$RT_LIB_NAME.init \
- $MERCURY_MOD_LIB_DIR/$STD_LIB_NAME.init \
- "}
+ MERCURY_ALL_LIB_MODS="$MERCURY_MOD_LIB_MODS"
;;
esac
case $# in
0) exec $MKINIT $aditi_opt -c"$maxcalls" $init_opt $trace_opt \
$library_opt $defentry_opt $extra_inits_opt \
- $extra_init_dirs $EXTRA_INIT_FILES $MERCURY_MOD_LIB_MODS
+ $extra_init_dirs $EXTRA_INIT_FILES $MERCURY_ALL_LIB_MODS
;;
*) exec $MKINIT $aditi_opt -c"$maxcalls" $init_opt $trace_opt \
$library_opt $defentry_opt $extra_inits_opt \
- $extra_init_dirs "$@" $EXTRA_INIT_FILES $MERCURY_MOD_LIB_MODS
+ $extra_init_dirs "$@" $EXTRA_INIT_FILES $MERCURY_ALL_LIB_MODS
;;
esac
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/debugger
cvs diff: Diffing tests/debugger/declarative
cvs diff: Diffing tests/dppd
cvs diff: Diffing tests/general
cvs diff: Diffing tests/general/accumulator
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/hard_coded/exceptions
cvs diff: Diffing tests/hard_coded/purity
cvs diff: Diffing tests/hard_coded/sub-modules
cvs diff: Diffing tests/hard_coded/typeclasses
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/invalid/purity
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/tabling
cvs diff: Diffing tests/term
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
Index: tools/bootcheck
===================================================================
RCS file: /home/mercury1/repository/mercury/tools/bootcheck,v
retrieving revision 1.101
diff -u -b -r1.101 bootcheck
--- tools/bootcheck 2000/08/11 14:07:52 1.101
+++ tools/bootcheck 2000/10/14 07:55:23
@@ -775,10 +775,12 @@
export MMAKE_DIR
MERCURY_MOD_LIB_MODS="
- $root/${stage2_insert}browser/$BROWSER_LIB_NAME.init
$root/${stage2_insert}library/$STD_LIB_NAME.init
$root/${stage2_insert}runtime/$RT_LIB_NAME.init"
export MERCURY_MOD_LIB_MODS
+ MERCURY_TRACE_LIB_MODS="
+ $root/${stage2_insert}browser/$BROWSER_LIB_NAME.init"
+ export MERCURY_TRACE_LIB_MODS
# for mkinit, mmc, mgnuc, ml etc
PATH=$root/${stage2_insert}util:$root/${stage2_insert}scripts:$PATH
cvs diff: Diffing trace
cvs diff: Diffing trax
cvs diff: Diffing trial
cvs diff: Diffing util
Index: util/mkinit.c
===================================================================
RCS file: /home/mercury1/repository/mercury/util/mkinit.c,v
retrieving revision 1.66
diff -u -b -r1.66 mkinit.c
--- util/mkinit.c 2000/09/06 11:04:44 1.66
+++ util/mkinit.c 2000/10/14 10:35:50
@@ -43,7 +43,7 @@
typedef struct String_List_struct {
char *data;
struct String_List_struct *next;
- } String_List;
+} String_List;
/* --- global variables --- */
@@ -61,7 +61,6 @@
static bool need_initialization_code = FALSE;
static bool need_tracing = FALSE;
-static int num_modules = 0;
static int num_errors = 0;
/* List of directories to search for init files */
@@ -100,10 +99,10 @@
" GC_INIT();\n"
"}\n"
"#endif\n"
- "\n"
;
static const char aditi_header[] =
+ "\n"
"/*\n"
"** MR_do_load_aditi_rl_code() uploads all the Aditi-RL code\n"
"** for the program to a database to which the program currently\n"
@@ -111,7 +110,6 @@
"** aditi2/src/api/aditi_err.h in the Aditi sources.\n"
"*/\n"
"static int MR_do_load_aditi_rl_code(void);\n"
- "\n"
;
static const char mercury_funcs[] =
@@ -167,6 +165,8 @@
"\n"
" address_of_mercury_init_io = mercury_init_io;\n"
" address_of_init_modules = init_modules;\n"
+ " address_of_init_modules_type_tables = init_modules_type_tables;\n"
+ " address_of_init_modules_debugger = init_modules_debugger;\n"
" MR_address_of_do_load_aditi_rl_code = %s;\n"
"#ifdef CONSERVATIVE_GC\n"
" address_of_init_gc = init_gc;\n"
@@ -260,14 +260,24 @@
static char *find_init_file(const char *basename);
static bool file_exists(const char *filename);
static void output_headers(void);
-static void output_sub_init_functions(void);
-static void output_main_init_function(void);
+static int output_sub_init_functions(const char *suffix,
+ bool wrap_func_in_ifdef, bool only_full_module);
+static void output_main_init_function(const char *suffix,
+ bool wrap_body_in_ifdef, int filebunches);
static void output_aditi_load_function(void);
static void output_main(void);
-static void process_file(const char *filename);
-static void process_c_file(const char *filename);
-static void process_init_file(const char *filename);
-static void output_init_function(const char *func_name);
+static void process_file(const char *filename, int *filebunches_ptr,
+ int *cur_bunch_ptr, const char *suffix,
+ bool only_full_module);
+static void process_c_file(const char *filename, int *filebunches_ptr,
+ int *cur_bunch_ptr, const char *suffix,
+ bool only_full_module);
+static void process_init_file(const char *filename, int *filebunches_ptr,
+ int *cur_bunch_ptr, const char *suffix,
+ bool only_full_module);
+static void output_init_function(const char *func_name,
+ int *filebunches_ptr, int *cur_bunch_ptr,
+ const char *suffix, bool only_full_module);
static void add_rl_data(char *data);
static int getline(FILE *file, char *line, int line_max);
static void *checked_malloc(size_t size);
@@ -305,16 +315,25 @@
int
main(int argc, char **argv)
{
+ int filebunches;
progname = argv[0];
parse_options(argc, argv);
do_path_search();
-
output_headers();
- output_sub_init_functions();
- output_main_init_function();
+ filebunches = output_sub_init_functions("",
+ ! need_initialization_code, FALSE);
+ output_main_init_function("",
+ ! need_initialization_code, filebunches);
+
+ filebunches = output_sub_init_functions("_type_tables", FALSE, TRUE);
+ output_main_init_function("_type_tables", FALSE, filebunches);
+
+ filebunches = output_sub_init_functions("_debugger", TRUE, TRUE);
+ output_main_init_function("_debugger", TRUE, filebunches);
+
if (aditi) {
output_aditi_load_function();
}
@@ -337,7 +356,9 @@
parse_options(int argc, char *argv[])
{
int c;
+ int i;
String_List *tmp_slist;
+
while ((c = getopt(argc, argv, "ac:iI:ltw:x")) != EOF) {
switch (c) {
case 'a':
@@ -389,10 +410,27 @@
usage();
}
}
+
num_files = argc - optind;
- if (num_files <= 0)
+ if (num_files <= 0) {
usage();
+ }
+
+ files = argv + optind;
+
+#if 0
+ if (need_tracing) {
+ files = (char **) checked_malloc((num_files + 1)
+ * sizeof(char *));
+ for (i = 0; i < num_files; i++) {
+ files[i] = argv[optind + i];
+ }
+ strcpy(files[num_files], "mer_browser.init");
+ num_files++;
+ } else {
files = argv + optind;
+ }
+#endif
}
static void
@@ -505,45 +543,54 @@
}
}
-static void
-output_sub_init_functions(void)
+static int
+output_sub_init_functions(const char *suffix, bool wrap_func_in_ifdef,
+ bool only_full_module)
{
int filenum;
+ int filebunches;
+ int cur_bunch;
- if (! need_initialization_code) {
+ if (wrap_func_in_ifdef) {
fputs(if_need_to_init, stdout);
}
- fputs("static void init_modules_0(void)\n", stdout);
+ printf("static void init_modules%s_0(void)\n", suffix);
fputs("{\n", stdout);
+ filebunches = 0;
+ cur_bunch = 0;
for (filenum = 0; filenum < num_files; filenum++) {
- process_file(files[filenum]);
+ process_file(files[filenum], &filebunches, &cur_bunch,
+ suffix, only_full_module);
}
fputs("}\n", stdout);
- if (! need_initialization_code) {
+ if (wrap_func_in_ifdef) {
fputs("\n#endif\n", stdout);
}
+
+ return filebunches;
}
static void
-output_main_init_function(void)
+output_main_init_function(const char *suffix, bool wrap_body_in_ifdef,
+ int filebunches)
{
int i;
- fputs("\nstatic void init_modules(void)\n", stdout);
+ printf("\n\nstatic void init_modules%s(void)\n", suffix);
fputs("{\n", stdout);
- if (! need_initialization_code) {
+ if (wrap_body_in_ifdef) {
fputs(if_need_to_init, stdout);
}
- for (i = 0; i <= num_modules; i++) {
- printf("\tinit_modules_%d();\n", i);
+ for (i = 0; i <= filebunches; i++) {
+ printf("\tinit_modules%s_%d();\n", suffix, i);
}
- if (! need_initialization_code) {
+ if (wrap_body_in_ifdef) {
fputs("\n#endif\n", stdout);
}
@@ -572,17 +619,21 @@
/*---------------------------------------------------------------------------*/
static void
-process_file(const char *filename)
+process_file(const char *filename, int *filebunches_ptr, int *cur_bunch_ptr,
+ const char *suffix, bool only_full_module)
{
int len = strlen(filename);
if (len >= 2 && strcmp(filename + len - 2, ".c") == 0) {
if (c_files_contain_extra_inits) {
- process_init_file(filename);
+ process_init_file(filename, filebunches_ptr,
+ cur_bunch_ptr, suffix, only_full_module);
} else {
- process_c_file(filename);
+ process_c_file(filename, filebunches_ptr,
+ cur_bunch_ptr, suffix, only_full_module);
}
} else if (len >= 5 && strcmp(filename + len - 5, ".init") == 0) {
- process_init_file(filename);
+ process_init_file(filename, filebunches_ptr,
+ cur_bunch_ptr, suffix, only_full_module);
} else {
fprintf(stderr,
"%s: filename `%s' must end in `.c' or `.init'\n",
@@ -592,7 +643,8 @@
}
static void
-process_c_file(const char *filename)
+process_c_file(const char *filename, int *filebunches_ptr, int *cur_bunch_ptr,
+ const char *suffix, bool only_full_module)
{
char func_name[1000];
char *position;
@@ -629,6 +681,7 @@
exit(1);
}
}
+
strcpy(func_name, "mercury");
while ((position = strchr(filename, '.')) != NULL) {
strcat(func_name, "__");
@@ -645,7 +698,8 @@
*/
strcat(func_name, "__init");
- output_init_function(func_name);
+ output_init_function(func_name, filebunches_ptr, cur_bunch_ptr,
+ suffix, only_full_module);
if (aditi) {
char *rl_data_name;
@@ -661,12 +715,12 @@
strncat(rl_data_name, func_name + mercury_len,
module_name_size);
add_rl_data(rl_data_name);
-
}
}
static void
-process_init_file(const char *filename)
+process_init_file(const char *filename, int *filebunches_ptr,
+ int *cur_bunch_ptr, const char *suffix, bool only_full_module)
{
const char * const init_str = "INIT ";
const char * const endinit_str = "ENDINIT ";
@@ -697,7 +751,8 @@
}
line[j] = '\0';
- output_init_function(line + init_strlen);
+ output_init_function(line + init_strlen, filebunches_ptr,
+ cur_bunch_ptr, suffix, only_full_module);
} else if (aditi
&& strncmp(line, aditi_init_str, aditi_init_strlen) == 0) {
int j;
@@ -721,24 +776,45 @@
fclose(cfile);
}
+#define SYS_PREFIX_1 "sys_init"
+#define SYS_PREFIX_2 "mercury_sys_init"
+
+#define matches_prefix(s, prefix) \
+ (strncmp((s), (prefix), sizeof(prefix)-1) == 0)
+
static void
-output_init_function(const char *func_name)
+output_init_function(const char *func_name, int *filebunches_ptr,
+ int *cur_bunch_ptr, const char *suffix, bool only_full_module)
{
- static int num_calls = 0;
+ if (only_full_module) {
+ if (matches_prefix(func_name, SYS_PREFIX_1)
+ || matches_prefix(func_name, SYS_PREFIX_2))
+ {
+ /*
+ ** This is a handwritten "module" which has only
+ ** one handwritten initialization function; it does not
+ ** have separate initialization functions to register
+ ** type_ctor_infos or module layouts.
+ */
+
+ return;
+ }
+ }
- if (num_calls >= maxcalls) {
+ if (*cur_bunch_ptr >= maxcalls) {
printf("}\n\n");
- num_modules++;
- num_calls = 0;
- printf("static void init_modules_%d(void)\n", num_modules);
+ (*filebunches_ptr)++;
+ *cur_bunch_ptr = 0;
+ printf("static void init_modules%s_%d(void)\n",
+ suffix, *filebunches_ptr);
printf("{\n");
}
- num_calls++;
+ (*cur_bunch_ptr)++;
- printf("\t{ extern void %s(void);\n", func_name);
- printf("\t %s(); }\n", func_name);
+ printf("\t{ extern void %s%s(void);\n", func_name, suffix);
+ printf("\t %s%s(); }\n", func_name, suffix);
}
/*---------------------------------------------------------------------------*/
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list