[m-rev.] for review: rename the top-level of the compiler
Julien Fischer
jfischer at opturion.com
Tue Feb 16 10:06:55 AEDT 2016
For review by anyone.
An alternative approach to the change below would be to rename the 'top_level'
package to the 'mercury_compile' package'. I think 'top_level' is more
meaningful as a package name, so I have left it as-is. As such, the new
'mercury_compile' module sits outside the compiler's existing package
hierarchy.
Note that I have omitted most of the changes from compiler/mercury_compile.m
and compiler/mercury_compile_main.m from the diff below as there is no point
reviewing several thousand lines shifting from one file to another.
Julien.
------------------------------------
Rename the top-level of the compiler.
Currently, the compiler's top-level module is the module 'top_level'. This
means that the executable (or Java archive, or assembly) we generate is named
after that. However, the rest of the system requires that the compiler
executable be named 'mercury_compile', so we currently rename it after it is
generated. (At least, we do in C grades, in non-C grades the compiler
"executable" currently has the "wrong" name.) Making this scheme work across
multiple backends and platforms leads to quite a bit of complication in the
build system. This change simplifies matters by repurposing the
'mercury_compile' module to be the new top-level module; this means that the
executable is generated with the correct name to begin with.
compiler/mercury_compile.m:
Shift the existing contents of this module to new module,
mercury_compile_main.
Shift this module out of the top_level package and export main/2 from it.
compiler/mercury_compile_main.m:
New module that contains the old contents of mercury_compile.m.
compiler/top_level.m:
Conform to the above changes.
Delete the definition of main/2 from this module.
compiler/make.m:
compiler/make.module_target.m:
Conform to the above changes.
compiler/Mmakefile:
Conform to the change in the name of the top-level module.
Delete the rule for renaming the compiler executable.
Mmakefile:
Update the dep_compiler target.
compiler/notes/compiler_design.html:
Update this document.
scripts/mercury_compile.sh-csharp:
scripts/mercury_compile.sh-java:
Update these scripts.
diff --git a/Mmakefile b/Mmakefile
index ba6f2d9..9d3d27b 100644
--- a/Mmakefile
+++ b/Mmakefile
@@ -136,9 +136,9 @@ ssdb/$(deps_subdir)$(SSDB_LIB_NAME).dep:
+cd ssdb && $(SUBDIR_MMAKE) $(SSDB_LIB_NAME).depend
.PHONY: dep_compiler
-dep_compiler: compiler/$(deps_subdir)top_level.dep
+dep_compiler: compiler/$(deps_subdir)mercury_compile.dep
-compiler/$(deps_subdir)top_level.dep: library/$(deps_subdir)$(STD_LIB_NAME).dep
+compiler/$(deps_subdir)mercury_compile.dep: library/$(deps_subdir)$(STD_LIB_NAME).dep
+cd compiler && $(SUBDIR_MMAKE) depend
.PHONY: dep_slice
diff --git a/compiler/Mmakefile b/compiler/Mmakefile
index 32eeb5e..fbff95f 100644
--- a/compiler/Mmakefile
+++ b/compiler/Mmakefile
@@ -31,7 +31,7 @@ include Mercury.options
MAIN_TARGET=all
-MERCURY_MAIN_MODULES = top_level
+MERCURY_MAIN_MODULES = mercury_compile
PDBS = $(patsubst %,%.pdb,$(MERCURY_MAIN_MODULES))
@@ -96,7 +96,7 @@ endif
# targets
# specify the name of the top-level module to build
-MC_PROG = top_level
+MC_PROG = mercury_compile
# mercury_compile
@@ -118,22 +118,6 @@ all: mercury $(TAGS_FILE_EXISTS)
.PHONY: mercury
mercury: mercury_compile
-# The executable was previous known as `mercury_compile',
-# but now we generate it as `top_level'. For compatibility with
-# various existing code, we make links to the old names.
-
-LN = ln
-
-ifneq ("$(EXT_FOR_EXE)","")
-.PHONY: mercury_compile
-mercury_compile: mercury_compile$(EXT_FOR_EXE)
-endif
-
-mercury_compile$(EXT_FOR_EXE): $(MC_PROG)$(EXT_FOR_EXE)
- rm -f mercury_compile$(EXT_FOR_EXE)
- $(LN) $(MC_PROG)$(EXT_FOR_EXE) mercury_compile$(EXT_FOR_EXE) || \
- cp $(MC_PROG)$(EXT_FOR_EXE) mercury_compile$(EXT_FOR_EXE)
-
#-----------------------------------------------------------------------------#
# Tell the C# compiler where the stdlib and mdbcomp assemblies are.
@@ -247,7 +231,7 @@ install_dirs:
-[ -d $(INSTALL_MERC_BIN_DIR) ] || mkdir -p $(INSTALL_MERC_BIN_DIR)
# If the compiler is built in the Java grade then we need to install Java
-# archive containing its class files (currently called top_level.jar), but
+# archive containing its class files, 'mercury_compiler.jar', but
# *not* the generated wrapper script 'mercury_compile' from this directory.
# The latter will set the CLASSPATH variable relative to this directory and
# won't work when moved to the installation directory. Instead we use the
@@ -255,16 +239,16 @@ install_dirs:
# one here alone.
#
# Similarly, for compilers built in the C# grade we need to install the
-# executable assembly (currently called top_level.exe), but *not* the generated
+# executable assembly, 'mercury_compile.exe', but *not* the generated
# wrapper script 'mercury_compile' from this directory. As with the Java grade,
# we use the version of the wrapper script from the scripts directory.
# XXX This covers Mono but not actual .NET; in the latter case we don't need
-# a wrapper script at all -- probably we should just rename the assembly.
+# a wrapper script at all.
#
ifeq ($(findstring java,$(GRADE)),java)
-INSTALL_PROGRAM=top_level.jar
+INSTALL_PROGRAM=mercury_compile.jar
else ifeq ($(findstring csharp,$(GRADE)),csharp)
-INSTALL_PROGRAM=top_level.exe
+INSTALL_PROGRAM=mercury_compile.exe
else
INSTALL_PROGRAM=mercury_compile$(EXT_FOR_EXE)
endif
diff --git a/compiler/make.m b/compiler/make.m
index 7d7b2b7..dca33d8 100644
--- a/compiler/make.m
+++ b/compiler/make.m
@@ -76,8 +76,8 @@
:- import_module mdbcomp.sym_name.
:- import_module parse_tree.error_util.
:- import_module parse_tree.file_names.
-:- import_module top_level. % XXX unwanted dependency
-:- import_module top_level.mercury_compile. % XXX unwanted dependency
+:- import_module top_level. % XXX unwanted dependency
+:- import_module top_level.mercury_compile_main. % XXX unwanted dependency
:- import_module assoc_list.
:- import_module bool.
diff --git a/compiler/make.module_target.m b/compiler/make.module_target.m
index 3f1504c..f569c43 100644
--- a/compiler/make.module_target.m
+++ b/compiler/make.module_target.m
@@ -622,7 +622,7 @@ get_object_extension(Globals, PIC) = Ext :-
call_mercury_compile_main(Globals, Args, Succeeded, !IO) :-
io.get_exit_status(Status0, !IO),
io.set_exit_status(0, !IO),
- mercury_compile.main_for_make(Globals, Args, !IO),
+ mercury_compile_main.main_for_make(Globals, Args, !IO),
io.get_exit_status(Status, !IO),
Succeeded = ( if Status = 0 then yes else no ),
io.set_exit_status(Status0, !IO).
diff --git a/compiler/mercury_compile.m b/compiler/mercury_compile.m
index cedac14..1a4f37a 100644
--- a/compiler/mercury_compile.m
+++ b/compiler/mercury_compile.m
@@ -1,2338 +1,36 @@
-%---------------------------------------------------------------------------%
-% vim: ts=4 sw=4 et ft=mercury
-%---------------------------------------------------------------------------%
-% Copyright (C) 1994-2012 The University of Melbourne.
+%-----------------------------------------------------------------------------%
+% vim: ft=mercury ts=4 sw=4 et
+%-----------------------------------------------------------------------------%
+% Copyright (C) 2002-2009 The University of Melbourne.
+% Copyright (C) 2016 The Mercury team.
% This file may only be copied under the terms of the GNU General
% Public License - see the file COPYING in the Mercury distribution.
-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
%
-% File: mercury_compile.m.
-% Main authors: fjh, zs.
+% This module defines main/2. Note that main/2 forwards all of its work to
+% mercury_compile_main.real_main/2, but main/2 must be defined in this module
+% so that the compiler executable is generated with the right name.
%
-% This is the top-level of the Mercury compiler.
-%
-% This module invokes the different passes of the compiler as appropriate.
-% The constraints on pass ordering are documented in
-% compiler/notes/compiler_design.html.
-%
-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
-:- module top_level.mercury_compile.
+:- module mercury_compile.
:- interface.
-:- import_module libs.
-:- import_module libs.globals.
-
:- import_module io.
-:- import_module list.
- % This is the main entry point for the Mercury compiler.
- % It is called from top_level.main.
- %
-:- pred real_main(io::di, io::uo) is det.
+:- pred main(io::di, io::uo) is det.
- % main_for_make(Globals, Args, !IO) is called from
- % make.module_target.call_mercury_compile_main.
- %
-:- pred main_for_make(globals::in, list(string)::in, io::di, io::uo) is det.
-
-%---------------------------------------------------------------------------%
-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
:- implementation.
... <diff omitted> ...
-
-% This version is only used if there is no matching foreign_proc version.
-gc_init(!IO).
+:- import_module top_level.
+:- import_module top_level.mercury_compile_main.
-:- pragma foreign_proc("C",
- gc_init(_IO0::di, _IO::uo),
- [will_not_call_mercury, promise_pure, tabled_for_io],
-"
-#ifdef MR_BOEHM_GC
- /*
- ** Explicitly force the initial heap size to be at least 4 Mb.
- **
- ** This works around a bug in the Boehm collector (for versions up
- ** to at least 6.2) where the collector would sometimes abort with
- ** the message `unexpected mark stack overflow' (e.g. in grade hlc.gc
- ** on dec-alpha-osf3.2).
- **
- ** Doing this should also improve performance slightly by avoiding
- ** frequent garbage collection during start-up.
- */
- GC_expand_hp(4 * 1024 * 1024);
-#endif
-").
+main(!IO) :-
+ mercury_compile_main.real_main(!IO).
-%---------------------------------------------------------------------------%
-:- end_module top_level.mercury_compile.
-%---------------------------------------------------------------------------%
+%-----------------------------------------------------------------------------%
+:- end_module mercury_compile.
+%-----------------------------------------------------------------------------%
diff --git a/compiler/mercury_compile_main.m b/compiler/mercury_compile_main.m
new file mode 100644
index 0000000..e1dc41d
--- /dev/null
+++ b/compiler/mercury_compile_main.m
@@ -0,0 +1,2338 @@
<diff omitted>
diff --git a/compiler/notes/compiler_design.html b/compiler/notes/compiler_design.html
index 39c0bd8..9af39a7 100644
--- a/compiler/notes/compiler_design.html
+++ b/compiler/notes/compiler_design.html
@@ -27,13 +27,13 @@ library, runtime, etc.) fit together.
The main job of the compiler is to translate Mercury into C, although it
can also translate (subsets of) Mercury to some other languages:
-Mercury bytecode (for a planned bytecode interpreter), MSIL (for the
-Microsoft .NET platform), C#, Java and Erlang.
+Mercury bytecode (for a planned bytecode interpreter), C#, Java and Erlang.
<p>
-The top-level of the compiler is in the file mercury_compile.m,
-which is a sub-module of the top_level.m package.
+The top-level of the compiler is in the file mercury_compiler.m.
+This forwards all of the work to the file mercury_compiler_main.m which is a
+sub-module of the top_level.m package.
The basic design is that compilation is broken into the following
stages:
diff --git a/compiler/top_level.m b/compiler/top_level.m
index b879cc3..106b40f 100644
--- a/compiler/top_level.m
+++ b/compiler/top_level.m
@@ -14,28 +14,13 @@
:- module top_level.
:- interface.
-:- include_module mercury_compile.
+:- include_module mercury_compile_main.
:- include_module mercury_compile_front_end.
:- include_module mercury_compile_middle_passes.
:- include_module mercury_compile_erl_back_end.
:- include_module mercury_compile_llds_back_end.
:- include_module mercury_compile_mlds_back_end.
-% XXX It would be nicer to define `main' in top_level.mercury_compile,
-% rather than defining it here. But that doesn't work with the Mercury
-% compiler's .NET back-end, which assumes that main is defined in the program's
-% top-level module.
-
-:- use_module io.
-:- pred main(io.state::di, io.state::uo) is det.
-
-:- implementation.
-
-:- use_module top_level.mercury_compile.
-
-main(!IO) :-
- top_level.mercury_compile.real_main(!IO).
-
%-----------------------------------------------------------------------------%
:- end_module top_level.
%-----------------------------------------------------------------------------%
diff --git a/scripts/mercury_compile.sh-csharp b/scripts/mercury_compile.sh-csharp
index 0251c46..2e7f23d 100755
--- a/scripts/mercury_compile.sh-csharp
+++ b/scripts/mercury_compile.sh-csharp
@@ -12,4 +12,4 @@ esac
MONO_PATH="$DIR/../lib/mercury/lib/csharp"${SEP}$MONO_PATH
export MONO_PATH
CLI_INTERPRETER=${CLI_INTERPRETER:-/opt/local/bin/mono}
-exec "$CLI_INTERPRETER" "$DIR/top_level.exe" "$@"
+exec "$CLI_INTERPRETER" "$DIR/mercury_compile.exe" "$@"
diff --git a/scripts/mercury_compile.sh-java b/scripts/mercury_compile.sh-java
index a0d6725..14c7e24 100755
--- a/scripts/mercury_compile.sh-java
+++ b/scripts/mercury_compile.sh-java
@@ -10,7 +10,7 @@ case $WINDIR in
*) SEP=';' ;;
esac
JARDIR="$DIR/../lib/mercury/lib/java"
-CLASSPATH="$DIR/top_level.jar"${SEP}$CLASSPATH${SEP}$JARDIR/mer_rt.jar${SEP}$JARDIR/mer_std.jar${SEP}$JARDIR/mer_browser.jar${SEP}$JARDIR/mer_mdbcomp.jar
+CLASSPATH="$DIR/mercury_compile.jar"${SEP}$CLASSPATH${SEP}$JARDIR/mer_rt.jar${SEP}$JARDIR/mer_std.jar${SEP}$JARDIR/mer_browser.jar${SEP}$JARDIR/mer_mdbcomp.jar
export CLASSPATH
JAVA=${JAVA:-java}
-exec "$JAVA" -Xss32M jmercury.top_level "$@"
+exec "$JAVA" -Xss32M jmercury.mercury_compile "$@"
More information about the reviews
mailing list