[m-rev.] for review: fix header file problems

Simon Taylor stayl at cs.mu.OZ.AU
Thu May 30 15:42:46 AEST 2002


On 30-May-2002, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> Given that we already rely to some degree on file names containing
> multiple extensions (e.g. *.c.tmp), I'd be tempted to go for `.m.h'
> rather than `.mh'.

At the moment, none of the file names containing multiple extensions
appear in `make' rules. To keep things simple, I'll stick with the
single extension.
 
> On 29-May-2002, Simon Taylor <stayl at cs.mu.OZ.AU> wrote:
> > 
> > @@ -583,8 +612,12 @@
> >  			"extern ""C"" {\n",
> >  			"#endif\n",
> >  			"\n",
> > +			"#ifdef MR_HIGHLEVEL_CODE\n",
> > +			"#include ""mercury.h""\n",
> > +			"#else\n",
> >  			"#ifndef MERCURY_HDR_EXCLUDE_IMP_H\n",
> >  			"#include ""mercury_imp.h""\n",
> > +			"#endif\n",
> >  			"#endif\n",
> >  			"#ifdef MR_DEEP_PROFILING\n",
> >  			"#include ""mercury_deep_profiling.h""\n",
> 
> The generated code here should conform to our indentation guidelines.

Fixed.
 
> > +++ compiler/make.module_target.m	18 May 2002 17:53:20 -0000
> > -		    %
> > -		    % When compiling to low-level C, we only generate a
> > -		    % header file if the module contains `:- pragma export'
> > -		    % declarations.
> > -		    %
> > +	    { ( CompilationTarget = c ; CompilationTarget = asm ) ->
> > +	    	PragmaExportModuleNames =
> > +			list__filter_map(
> > +			    (func(MImports) =
> > +			    		MImports ^ module_name is semidet :-
> > +				contains_foreign_export =
> > +				    MImports ^ contains_foreign_export
> > +			    ), ModuleImportsList),
> > +	    	HeaderTargets =
> > +			make_target_list(PragmaExportModuleNames, c_header(mh))
> > +			++ HeaderTargets0
> 
> There should be a comment here explaining this code,
> e.g. something similar to the comment that was deleted.

Done.
 
> > +:- type mercury_mlds_import_type
> > +	--->	import_interface	% Import the user-visible interface
> > +					% to the target code (the prototypes
> > +					% for the `:- pragma export'
> > +					% declarations).
> > +
> > +	;	import_implementation.	% Import the implementation part
> > +					% of the target code.
> 
> The names `import_interface' and `import_implementation' are
> a bit misleading, IMHO.
> 
> `import_implementation' doesn't import the implementation part
> of the target code.  The implementation part would be the `.c' file!
> 
> I think it would be better to distinguish between the user-visible interface
> section and the (Mercury-)compiler-visible interface section.
> 
> E.g.
> 
> 	:- type mercury_mlds_import_type
> 		---> user_visible_interface.
> 		;    compiler_visible_interface.

Yes, that's much better.

> Also, it's not clear what is supposed to happen for target languages
> that don't support multiple interfaces like this.  Some comments about
> that might be helpful for people developing new back-ends.

Done.
 
> >  % Currently an import just gives the name of the package to be imported.
> >  % This might perhaps need to be expanded to cater to different kinds of
> >  % imports, e.g. imports with wild-cards ("import java.lang.*").
> >  :- type mlds__import
> > -	--->	mercury_import(
> > +	--->
> > +		% Import the user-visible interface of the target code
> > +		% for the module (e.g. for C, the function prototypes for
> > +		% predicates and functions with `:- pragma export'
> > +		% declarations, which are contained in the `.mh' file).
> > +		mercury_import(
> > +			mercury_mlds_import_type :: mercury_mlds_import_type,
> 
> This comment is wrong; the kind of import will depend on the value
> of the first field.

Fixed.

Simon.

diff -u compiler/export.m compiler/export.m
--- compiler/export.m
+++ compiler/export.m
@@ -615,9 +615,9 @@
 			"#ifdef MR_HIGHLEVEL_CODE\n",
 			"#include ""mercury.h""\n",
 			"#else\n",
-			"#ifndef MERCURY_HDR_EXCLUDE_IMP_H\n",
-			"#include ""mercury_imp.h""\n",
-			"#endif\n",
+			"  #ifndef MERCURY_HDR_EXCLUDE_IMP_H\n",
+			"  #include ""mercury_imp.h""\n",
+			"  #endif\n",
 			"#endif\n",
 			"#ifdef MR_DEEP_PROFILING\n",
 			"#include ""mercury_deep_profiling.h""\n",
diff -u compiler/make.module_target.m compiler/make.module_target.m
--- compiler/make.module_target.m
+++ compiler/make.module_target.m
@@ -523,7 +523,12 @@
 	    	{ CompilationTarget = java },
 		{ HeaderTargets0 = [] }
 	    ),
+
 	    { ( CompilationTarget = c ; CompilationTarget = asm ) ->
+		    %
+		    % We only generate a `.mh' file if the module contains
+		    % `:- pragma export' declarations.
+		    %
 	    	PragmaExportModuleNames =
 			list__filter_map(
 			    (func(MImports) =
diff -u compiler/ml_code_gen.m compiler/ml_code_gen.m
--- compiler/ml_code_gen.m
+++ compiler/ml_code_gen.m
@@ -858,7 +858,7 @@
 	globals__get_target(Globals, Target),
 	module_info_get_all_deps(ModuleInfo, AllImports),
 	P = (func(Name) = mercury_import(
-				import_implementation,
+				compiler_visible_interface,
 				mercury_module_name_to_mlds(Name))),
 
 		% For every foreign type determine the import needed to
diff -u compiler/mlds.m compiler/mlds.m
--- compiler/mlds.m
+++ compiler/mlds.m
@@ -324,25 +324,23 @@
 
 :- type mlds__imports == list(mlds__import).
 
+	% For the C backend, we generate a `.mh' file containing the
+	% prototypes for C functions generated for `:- pragma export'
+	% declarations, and a `.mih' file containing the prototypes
+	% for the C functions generated by the compiler which should
+	% not be visible to the user.
+	%
+	% For languages which don't support multiple interfaces, it's
+	% probably OK to put everything in the compiler-visible interface.
 :- type mercury_mlds_import_type
-	--->	import_interface	% Import the user-visible interface
-					% to the target code (the prototypes
-					% for the `:- pragma export'
-					% declarations).
-
-	;	import_implementation.	% Import the implementation part
-					% of the target code.
+	--->	user_visible_interface
+	;	compiler_visible_interface.
 
 % Currently an import just gives the name of the package to be imported.
 % This might perhaps need to be expanded to cater to different kinds of
 % imports, e.g. imports with wild-cards ("import java.lang.*").
 :- type mlds__import
-	--->
-		% Import the user-visible interface of the target code
-		% for the module (e.g. for C, the function prototypes for
-		% predicates and functions with `:- pragma export'
-		% declarations, which are contained in the `.mh' file).
-		mercury_import(
+	--->	mercury_import(
 			mercury_mlds_import_type :: mercury_mlds_import_type,
 			import_name		:: mlds_module_name
 		)
diff -u compiler/mlds_to_c.m compiler/mlds_to_c.m
--- compiler/mlds_to_c.m
+++ compiler/mlds_to_c.m
@@ -171,8 +171,8 @@
 	{
 		Import = mercury_import(ImportType, ImportName),
 		ModuleName0 = mlds_module_name_to_sym_name(ImportName),
-		( ImportType = import_interface, HeaderExt = ".mh"
-		; ImportType = import_implementation, HeaderExt = ".mih"
+		( ImportType = user_visible_interface, HeaderExt = ".mh"
+		; ImportType = compiler_visible_interface, HeaderExt = ".mih"
 		),
 
 		% Strip off the "mercury" qualifier for standard
@@ -318,12 +318,12 @@
 	;
 		mlds_output_src_import(Indent,
 			mercury_import(
-			import_interface,
+			user_visible_interface,
 			mercury_module_name_to_mlds(ModuleName)))
 	),
 	mlds_output_src_import(Indent,
 		mercury_import(
-			import_implementation,
+			compiler_visible_interface,
 			mercury_module_name_to_mlds(ModuleName))),
 	io__nl.
 
@@ -586,7 +586,7 @@
 	    	{ ForeignImport = foreign_import_module(Lang, Import, _) },
 		( { Lang = c } ->
 			mlds_output_src_import(Indent,
-				mercury_import(import_interface,
+				mercury_import(user_visible_interface,
 					mercury_module_name_to_mlds(Import)))
 	    	;
 			{ sorry(this_file, "foreign code other than C") }
diff -u compiler/mlds_to_il.m compiler/mlds_to_il.m
--- compiler/mlds_to_il.m
+++ compiler/mlds_to_il.m
@@ -305,7 +305,8 @@
 			% reference
 		list__map((pred(F::in, I::out) is det :-
 				mangle_foreign_code_module(ModuleName, F, N),
-				I = mercury_import(import_implementation, N)
+				I = mercury_import(compiler_visible_interface,
+					N)
 			),
 			set__to_sorted_list(ForeignLangs),
 			ForeignCodeAssemblerRefs),
@@ -2835,7 +2836,8 @@
 	set_rtti_initialization_field(DoneFieldRef, SetInstrs),
 	{ CCtorCalls = list__filter_map(
 		(func(I::in) = (C::out) is semidet :-
-			I = mercury_import(import_implementation, ImportName),
+			I = mercury_import(compiler_visible_interface,
+				ImportName),
 			C = call_class_constructor(
 				class_name(ImportName, wrapper_class_name))
 		), Imports) },
@@ -4002,7 +4004,8 @@
 mlds_to_il__generate_extern_assembly(CurrentAssembly, Version, SignAssembly,
 		SeparateAssemblies, Imports, AllDecls) :-
 	Gen = (pred(Import::in, Decl::out) is semidet :-
-		( Import = mercury_import(import_implementation, ImportName),
+		( Import = mercury_import(compiler_visible_interface,
+				ImportName),
 			( SignAssembly = yes,
 				AsmDecls = mercury_strong_name_assembly_decls
 			; SignAssembly = no,
diff -u compiler/mlds_to_java.m compiler/mlds_to_java.m
--- compiler/mlds_to_java.m
+++ compiler/mlds_to_java.m
@@ -319,11 +319,11 @@
 	% XXX Handle `:- pragma export' to Java.
 	{ Import = mercury_import(ImportType, ImportName),
 		(
-			ImportType = import_interface,
+			ImportType = user_visible_interface,
 			unexpected(this_file,
-			    "import_type `import_interface' in Java backend")
+		"import_type `user_visible_interface' in Java backend")
 		;
-			ImportType = import_implementation
+			ImportType = compiler_visible_interface
 		)
 	; Import = foreign_import(_),
 		unexpected(this_file, "foreign import in Java backend")
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list