diff: nested modules & init files bug fix
Fergus Henderson
fjh at cs.mu.OZ.AU
Sat May 30 19:15:20 AEST 1998
Estimated hours taken: 1
Fix a bug which caused link errors in some grades for some test cases
where the module name wasn't the same as the file name, and which
probably would have caused runtime errors in some grades for test
cases using nested modules.
compiler/modules.m:
Call $(C2INIT) with $(foo.cs) instead of $(foo.ms).
This is necessary now that a single .m file can get compiled
to multiple .c files, if it contains nested modules,
or to a .c file whose name reflects the module name rather
than the source file name.
util/mkinit.c:
scripts/c2init.c:
For efficiency, change c2init and mkinit so that when c2init's
arguments are `.c' files, it computes the init function based
on the filename (like it used to do with `.m' files), rather
than by reading the file contents and searching for "** INIT"
comments. Add a new option `-x' (`--extra-inits') which keeps
the old behaviour.
compiler/modules.m:
scripts/Mmake.rules:
Instead of deleting the `_init.c' file every time we recreate
the `.dep' file, just tell make that the `_init.c' file depends on
the `.dep' file, so that make will remake it if the `.dep' file
changes. (I don't know why I didn't do it that way in the
first place.)
cvs diff compiler/modules.m scripts/Mmake.rules scripts/c2init.c util/mkinit.c
Index: compiler/modules.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/modules.m,v
retrieving revision 1.76
diff -u -r1.76 modules.m
--- modules.m 1998/05/30 07:38:12 1.76
+++ modules.m 1998/05/30 08:27:15
@@ -2222,8 +2222,8 @@
io__write_string(DepStream, "\n"),
io__write_strings(DepStream, [
- InitCFileName, " :\n",
- "\t$(C2INIT) $(C2INITFLAGS) $(", MakeVarName, ".ms) > ",
+ InitCFileName, " : ", DepFileName, "\n",
+ "\t$(C2INIT) $(C2INITFLAGS) $(", MakeVarName, ".cs) > ",
InitCFileName, "\n\n"
]),
cvs diff: I know nothing about scripts/c2init.c
Index: util/mkinit.c
===================================================================
RCS file: /home/mercury1/repository/mercury/util/mkinit.c,v
retrieving revision 1.30
diff -u -r1.30 mkinit.c
--- mkinit.c 1998/04/08 11:36:13 1.30
+++ mkinit.c 1998/05/30 08:49:10
@@ -42,6 +42,7 @@
static int num_files;
static char **files;
static bool output_main_func = TRUE;
+static bool c_files_contain_extra_inits = FALSE;
static int num_modules = 0;
static int num_errors = 0;
@@ -204,7 +205,7 @@
** Apparently SunOS 4.1.3 doesn't have strerror()
** (!%^&!^% non-ANSI systems, grumble...)
**
-** This code is duplicated in runtime/prof.c.
+** This code is duplicated in runtime/mercury_prof.c.
*/
extern int sys_nerr;
@@ -254,7 +255,7 @@
parse_options(int argc, char *argv[])
{
int c;
- while ((c = getopt(argc, argv, "c:w:l")) != EOF) {
+ while ((c = getopt(argc, argv, "c:w:lx")) != EOF) {
switch (c) {
case 'c':
if (sscanf(optarg, "%d", &maxcalls) != 1)
@@ -269,6 +270,10 @@
output_main_func = FALSE;
break;
+ case 'x':
+ c_files_contain_extra_inits = TRUE;
+ break;
+
default:
usage();
}
@@ -283,7 +288,7 @@
usage(void)
{
fprintf(stderr,
- "Usage: mkinit [-c maxcalls] [-w entry] [-l] files...\n");
+ "Usage: mkinit [-c maxcalls] [-w entry] [-l] [-x] files...\n");
exit(1);
}
@@ -356,40 +361,55 @@
process_file(char *filename)
{
int len = strlen(filename);
+ /*
+ ** XXX the following three lines are needed only for bootstrapping;
+ ** they should be deleted once the new compiler has been installed
+ ** everywhere.
+ */
if (len >= 2 && strcmp(filename + len - 2, ".m") == 0) {
- process_m_file(filename);
+ process_c_file(filename);
+ } else
+ if (len >= 2 && strcmp(filename + len - 2, ".c") == 0) {
+ if (c_files_contain_extra_inits) {
+ process_init_file(filename);
+ } else {
+ process_c_file(filename);
+ }
} else if (len >= 5 && strcmp(filename + len - 5, ".init") == 0) {
process_init_file(filename);
- } else if (len >= 2 && strcmp(filename + len - 2, ".c") == 0) {
- process_init_file(filename);
} else {
fprintf(stderr,
- "%s: filename `%s' must end in `.m', `.c' or `.init'\n",
+ "%s: filename `%s' must end in `.c' or `.init'\n",
progname, filename);
num_errors++;
}
}
static void
-process_m_file(char *filename)
+process_c_file(char *filename)
{
char func_name[1000];
- char *dot;
+ char *position;
- /* remove the trailing ".m" */
+ /* remove the trailing ".c" */
filename[strlen(filename) - 2] = '\0';
+ /* remove the directory name, if any */
+ if ((position = strrchr(filename, '/')) != NULL) {
+ filename = position + 1;
+ }
+
/*
** The func name is "mercury__<modulename>__init",
** where <modulename> is the base filename with all
** `.'s replaced with `__'.
*/
strcpy(func_name, "mercury");
- while ((dot = strchr(filename, '.')) != NULL) {
+ while ((position = strchr(filename, '.')) != NULL) {
strcat(func_name, "__");
- strncat(func_name, filename, dot - filename);
- filename = dot + 1;
+ strncat(func_name, filename, position - filename);
+ filename = position + 1;
}
strcat(func_name, "__");
strcat(func_name, filename);
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list