[m-dev.] diff: bootstrap problem with init files in hlc grade

Zoltan Somogyi zs at cs.mu.OZ.AU
Fri Nov 3 13:25:43 AEDT 2000


On 02-Nov-2000, Peter Ross <peter.ross at miscrit.be> wrote:
> At some stage we should generate the correct initialization functions.

This was probably finished before you posted.

I have not been able to test it properly, because this fixes a link error
and I get errors from mgnuc before that in hlc.gc due to some variables being
declared "extern static". However, it looks like a diff Fergus posted today
should fix that.

compiler/mlds_to_c.m:
	Generate the mercury__<module>__init_{type_tables,debugger} functions
	required by the _init.c files generated by the new mkinit.c.

	Make the generation of the mercury__<module>__init function
	unconditional, in order to forestall such problems in the future.
	Almost all the extra code is inside #ifs whose condition is true
	only if the old mlds_to_c.m would have emitted their code anyway,
	so in the usual case the only extra cost is a function with an empty
	body.

runtime/mercury.h:
	#include mercury_type_tables.h, since the init_type_tables function
	makes calls to MR_register_type_ctor_info.

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/mlds_to_c.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/mlds_to_c.m,v
retrieving revision 1.61
diff -u -b -r1.61 mlds_to_c.m
--- compiler/mlds_to_c.m	2000/10/31 16:56:00	1.61
+++ compiler/mlds_to_c.m	2000/11/02 11:17:09
@@ -147,7 +147,7 @@
 	{ MLDS_ModuleName = mercury_module_name_to_mlds(ModuleName) },
 	mlds_output_defns(Indent, MLDS_ModuleName, PublicTypeDefns), io__nl,
 	mlds_output_decls(Indent, MLDS_ModuleName, PublicNonTypeDefns), io__nl,
-	mlds_maybe_output_init_fn_decl(MLDS_ModuleName), io__nl,
+	mlds_output_init_fn_decls(MLDS_ModuleName), io__nl,
 	mlds_output_hdr_end(Indent, ModuleName).
 
 :- pred defn_is_public(mlds__defn).
@@ -222,6 +222,7 @@
 	%	#1. definitions of the private types,
 	% 	#2. forward-declarations of the private non-types
 	%	#3. definitions of all the non-types
+	%	#4. initialization functions
 	% in that order. 
 	% #2 is needed to allow #3 to contain forward references,
 	% which can arise for e.g. mutually recursive procedures.
@@ -242,7 +243,7 @@
 
 	mlds_output_c_defns(MLDS_ModuleName, Indent, ForeignCode), io__nl,
 	mlds_output_defns(Indent, MLDS_ModuleName, NonTypeDefns), io__nl,
-	mlds_maybe_output_init_fn_defn(MLDS_ModuleName, NonTypeDefns), io__nl,
+	mlds_output_init_fn_defns(MLDS_ModuleName, NonTypeDefns, Defns), io__nl,
 	mlds_output_src_end(Indent, ModuleName).
 
 :- pred mlds_output_hdr_start(indent, mercury_module_name,
@@ -320,55 +321,47 @@
 	% MR_init_entry(<function>) for each function defined in the
 	% module.
 	%
-:- pred mlds_maybe_output_init_fn_decl(mlds_module_name::in,
+:- pred mlds_output_init_fn_decls(mlds_module_name::in,
 		io__state::di, io__state::uo) is det.
 
-mlds_maybe_output_init_fn_decl(ModuleName) -->
-	io_get_globals(Globals),
-	(
-		{ output_init_fn(Globals) }
-	->
-		output_init_fn_name(ModuleName),
-		io__write_string(";\n")
-	;
-		[]
-	).
+mlds_output_init_fn_decls(ModuleName) -->
+	output_init_fn_name(ModuleName, ""),
+	io__write_string(";\n"),
+	output_init_fn_name(ModuleName, "_type_tables"),
+	io__write_string(";\n"),
+	output_init_fn_name(ModuleName, "_debugger"),
+	io__write_string(";\n").
 
-:- pred mlds_maybe_output_init_fn_defn(mlds_module_name::in, mlds__defns::in,
-		io__state::di, io__state::uo) is det.
+:- pred mlds_output_init_fn_defns(mlds_module_name::in, mlds__defns::in,
+		mlds__defns::in, io__state::di, io__state::uo) is det.
 
-mlds_maybe_output_init_fn_defn(ModuleName, Defns) -->
-	io_get_globals(Globals),
-	(
-		{ output_init_fn(Globals) }
-	->
-		output_init_fn_name(ModuleName),
+mlds_output_init_fn_defns(ModuleName, NonTypeDefns, Defns) -->
+	output_init_fn_name(ModuleName, ""),
 		io__write_string("\n{\n"),
 		io__write_strings(["\tstatic int initialised = 0;\n",
 				"\tif (initialised) return;\n",
 				"\tinitialised = 1;\n\n"]),
-		mlds_output_init_fn_2(ModuleName, Defns),
-		io__write_string("\n}\n")
-	;
-		[]
-	).
+	mlds_output_init_main_fn(ModuleName, NonTypeDefns),
+	io__write_string("\n}\n"),
 
-	%
-	% Do we need an init function?
-	%
-:- pred output_init_fn(globals::in) is semidet.
+	output_init_fn_name(ModuleName, "_type_tables"),
+	io__write_string("\n{\n"),
+	io__write_strings(["\tstatic int initialised = 0;\n",
+			"\tif (initialised) return;\n",
+			"\tinitialised = 1;\n\n"]),
+	mlds_output_init_type_table_fn(ModuleName, Defns),
+	io__write_string("\n}\n"),
 
-output_init_fn(Globals) :-
-	( Option = profile_calls
-	; Option = profile_time
-	; Option = profile_memory
-	),
-	globals__lookup_bool_option(Globals, Option, yes).
+	output_init_fn_name(ModuleName, "_debugger"),
+	io__write_string("\n{\n"),
+	io__write_string(
+	    "\tMR_fatal_error(""debugger initialization in MLDS grade"");\n"),
+	io__write_string("\n}\n").
 	
-:- pred output_init_fn_name(mlds_module_name::in,
+:- pred output_init_fn_name(mlds_module_name::in, string::in,
 		io__state::di, io__state::uo) is det.
 
-output_init_fn_name(ModuleName) -->
+output_init_fn_name(ModuleName, Suffix) -->
 		% Here we ensure that we only get one "mercury__" at the
 		% start of the function name.
 	{ prog_out__sym_name_to_string(
@@ -384,16 +377,18 @@
 	},
 	io__write_string("void "),
 	io__write_string(ModuleNameString),
-	io__write_string("__init(void)").
+	io__write_string("__init"),
+	io__write_string(Suffix),
+	io__write_string("(void)").
 
-:- pred mlds_output_init_fn_2(mlds_module_name::in, mlds__defns::in,
+:- pred mlds_output_init_main_fn(mlds_module_name::in, mlds__defns::in,
 		io__state::di, io__state::uo) is det.
 
-mlds_output_init_fn_2(_ModuleName, []) --> [].
-mlds_output_init_fn_2(ModuleName, [Defn | Defns]) --> 
+mlds_output_init_main_fn(_ModuleName, []) --> [].
+mlds_output_init_main_fn(ModuleName, [Defn | Defns]) --> 
 	{ Defn = mlds__defn(EntityName, _Context, _Flags, _EntityDefn) },
 	(
-		{ EntityName = function(_, _, _, _) }
+		{ EntityName = mlds__function(_, _, _, _) }
 	->
 		{ QualName = qual(ModuleName, EntityName) },
 		io__write_string("\tMR_init_entry("),
@@ -401,8 +396,28 @@
 		io__write_string(");\n")
 	;
 		[]
+	),
+	mlds_output_init_main_fn(ModuleName, Defns).
+
+:- pred mlds_output_init_type_table_fn(mlds_module_name::in, mlds__defns::in,
+		io__state::di, io__state::uo) is det.
+
+mlds_output_init_type_table_fn(_ModuleName, []) --> [].
+mlds_output_init_type_table_fn(ModuleName, [Defn | Defns]) --> 
+	{ Defn = mlds__defn(EntityName, _Context, _Flags, EntityDefn) },
+	(
+		{ EntityDefn = mlds__data(Type, _) },
+		{ Type = mlds__rtti_type(RttiName) },
+		{ RttiName = type_ctor_info }
+	->
+		{ QualName = qual(ModuleName, EntityName) },
+		io__write_string("\tMR_register_type_ctor_info(&"),
+		mlds_output_fully_qualified_name(QualName),
+		io__write_string(");\n")
+	;
+		[]
 	),
-	mlds_output_init_fn_2(ModuleName, Defns).
+	mlds_output_init_type_table_fn(ModuleName, Defns).
 
 %-----------------------------------------------------------------------------%
 %
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
cvs diff: Diffing profiler
cvs diff: Diffing robdd
cvs diff: Diffing runtime
Index: runtime/mercury.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury.h,v
retrieving revision 1.22
diff -u -b -r1.22 mercury.h
--- runtime/mercury.h	2000/10/23 15:08:31	1.22
+++ runtime/mercury.h	2000/11/02 22:51:32
@@ -29,6 +29,7 @@
 #include "mercury_ho_call.h"	/* for the `MR_Closure' type */
 #include "mercury_bootstrap.h"
 #include "mercury_memory.h"	/* for memory allocation routines */
+#include "mercury_type_tables.h"	/* for MR_register_type_ctor_info */
 
 #ifdef CONSERVATIVE_GC
   #include "gc.h"
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
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
cvs diff: Diffing trace
cvs diff: Diffing trial
cvs diff: Diffing util
--------------------------------------------------------------------------
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