[m-rev.] for review: set runtime flags at compile time

Simon Taylor stayl at cs.mu.OZ.AU
Sat Jan 12 00:26:35 AEDT 2002


Estimated hours taken: 1.5
Branches: main

Allow Mercury runtime options to be set at compile time.

scripts/parse_ml_options.sh-subr.in:
	Add an initialization option `--runtime-flags'.
	
runtime/mercury_wrapper.h:
	Add a global variable MR_runtime_flags. 

util/mkinit.c:
	Set MR_runtime_flags.

runtime/mercury_wrapper.c:
	Add the value of MR_runtime_flags to the dummy
	command line passed to getopt().

tests/hard_coded/Mmakefile:
	Use `--runtime-flags' rather than MERCURY_OPTIONS.

Index: runtime/mercury_wrapper.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.94
diff -u -u -r1.94 mercury_wrapper.c
--- runtime/mercury_wrapper.c	31 Dec 2001 04:26:54 -0000	1.94
+++ runtime/mercury_wrapper.c	11 Jan 2002 12:43:36 -0000
@@ -209,6 +209,8 @@
 		/* normally mercury__main_2_0 (main/2) */
 #endif
 
+const char *MR_runtime_flags = "";
+
 void	(*MR_library_initializer)(void);
 		/* normally ML_io_init_state (io__init_state/2)*/
 void	(*MR_library_finalizer)(void);
@@ -665,10 +667,14 @@
 static void
 process_environment_options(void)
 {
-	char*	options;
+	char*	env_options;
+
+	env_options = getenv("MERCURY_OPTIONS");
+	if (env_options == NULL) {
+		env_options = (char *) "";
+	}
 
-	options = getenv("MERCURY_OPTIONS");
-	if (options != NULL) {
+	if (env_options[0] != '\0' || MR_runtime_flags[0] != '\0') {
 		const char	*cmd;
 		char		*arg_str, **argv;
 		char		*dummy_command_line;
@@ -684,9 +690,15 @@
 		*/
 		cmd = "mercury_runtime ";
 		dummy_command_line = MR_GC_NEW_ARRAY(char,
-					strlen(options) + strlen(cmd) + 1);
+					strlen(MR_runtime_flags) +
+					strlen(env_options) + strlen(cmd) + 1);
 		strcpy(dummy_command_line, cmd);
-		strcat(dummy_command_line, options);
+		/*
+		** mkinit always puts a trailing space on MR_runtime_flags
+		** if it is non-empty.
+		*/
+		strcat(dummy_command_line, MR_runtime_flags);
+		strcat(dummy_command_line, env_options);
 		
 		error_msg = MR_make_argv(dummy_command_line,
 			&arg_str, &argv, &argc);
Index: runtime/mercury_wrapper.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.h,v
retrieving revision 1.44
diff -u -u -r1.44 mercury_wrapper.h
--- runtime/mercury_wrapper.h	4 Dec 2001 00:44:36 -0000	1.44
+++ runtime/mercury_wrapper.h	11 Jan 2002 12:43:53 -0000
@@ -74,6 +74,8 @@
 			/* normally mercury__main_2_0; */
 #endif
 
+extern const char *	MR_runtime_flags;
+
 extern	void		(*MR_library_initializer)(void);
 extern	void		(*MR_library_finalizer)(void);
 
Index: scripts/c2init.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/c2init.in,v
retrieving revision 1.34
diff -u -u -r1.34 c2init.in
--- scripts/c2init.in	18 Dec 2001 05:44:17 -0000	1.34
+++ scripts/c2init.in	10 Jan 2002 15:33:41 -0000
@@ -73,7 +73,7 @@
 	   ;;
 	*) exec $MKINIT $aditi_opt -c"$maxcalls" $init_opt $trace_opt \
 		$library_opt $defentry_opt $extra_inits_opt \
-		-g "$GRADE" -o "$init_c_file" \
+		-g "$GRADE" -o "$init_c_file" -r "$runtime_flags" \
 		$extra_init_dirs "$@" $EXTRA_INIT_FILES $MERCURY_ALL_LIB_MODS
 	   ;;
 esac
Index: scripts/parse_ml_options.sh-subr.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/parse_ml_options.sh-subr.in,v
retrieving revision 1.2
diff -u -u -r1.2 parse_ml_options.sh-subr.in
--- scripts/parse_ml_options.sh-subr.in	6 Dec 2001 14:39:51 -0000	1.2
+++ scripts/parse_ml_options.sh-subr.in	11 Jan 2002 10:13:21 -0000
@@ -54,6 +54,7 @@
 aditi_opt=""
 extra_init_dirs=""
 init_c_file="-"
+runtime_flags=""
 
 # include the file `init_grade_options.sh-subr'
 @INIT_GRADE_OPTIONS@
@@ -137,10 +138,6 @@
 		Do not strip C debugging information.
 
 Initialization options:
-	-a, --aditi
-		Generate a function to upload Aditi-RL data to a database.
-		This option is needed when interfacing with the Aditi
-		deductive database system.
 	--no-main, --library
 		Don't generate a \`main()' function.
 		Instead, generate a function
@@ -152,13 +149,24 @@
 	-I <directory>, --init-file-directory <directory>
 		Include <directory> in the list of directories searched to
 		locate \`.init' files.
+	-w <label>, --entry-point <label>
+		Set entry point to <label>.
+		(Default value corresponds to main/2.)
+	--runtime-flags <flags>
+		Add <flags> to the list of flags to pass to the
+		Mercury runtime.  Flags can also be passed at runtime
+		in the MERCURY_OPTIONS environment variable.
+		For the list of available flags, see the documentation
+		for MERCURY_OPTIONS in the "Environment" chapter
+		of the Mercury User's Guide.
 	--init-c-file <filename>
 		Output the generated C initialization program to the
 		specified file, rather than sending it to the standard
 		output.
-	-w <label>, --entry-point <label>
-		Set entry point to <label>.
-		(Default value corresponds to main/2.)
+	-a, --aditi
+		Generate a function to upload Aditi-RL data to a database.
+		This option is needed when interfacing with the Aditi
+		deductive database system.
 	-x, --extra-inits
 		Search \`.c' files for extra initialization functions.
 		(This may be necessary if the C files contain
@@ -364,6 +372,9 @@
 	
 	--init-c-file)
 		init_c_file="$2"; shift;;
+
+	--runtime-flags)
+		runtime_flags="$runtime_flags $2"; shift;;
 
 	-w|--entry-point)
 		defentry_opt="-w$2"; shift;;
Index: tests/hard_coded/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/Mmakefile,v
retrieving revision 1.140
diff -u -u -r1.140 Mmakefile
--- tests/hard_coded/Mmakefile	8 Jan 2002 06:44:21 -0000	1.140
+++ tests/hard_coded/Mmakefile	11 Jan 2002 05:55:52 -0000
@@ -270,6 +270,13 @@
 
 MLFLAGS-needs_init		= 	--include-initialization-code --extra-inits
 
+# These tests run out of memory in non-GC grades
+# unless we increase the heap size from the default 4M.
+# The sizes specified here (70 Mb and 20 Mb respectively)
+# are sufficient for running these tests on 64-bit systems.
+MLFLAGS-integer_test = --runtime-flags "--heap-size 70000"
+MLFLAGS-rational_test = --runtime-flags "--heap-size 20000"
+
 # no_fully_strict is expected to fail (it calls error/1).
 # We also need to pipe the output through sed to avoid hard-coding
 # dependencies on particular line numbers in the standard library source code.
@@ -283,15 +290,6 @@
 			< $@.tmp > $@; \
 		rm -f $@.tmp; \
 	fi
-
-# These tests run out of memory in non-GC grades
-# unless we increase the heap size from the default 4M.
-# The sizes specified here (70 Mb and 20 Mb respectively)
-# are sufficient for running these tests on 64-bit systems.
-integer_test.out: integer_test
-	MERCURY_OPTIONS="--heap-size 70000" ./integer_test > $@ 2>&1
-rational_test.out: rational_test
-	MERCURY_OPTIONS="--heap-size 20000" ./rational_test > $@ 2>&1
 
 #-----------------------------------------------------------------------------#
 
Index: util/mkinit.c
===================================================================
RCS file: /home/mercury1/repository/mercury/util/mkinit.c,v
retrieving revision 1.80
diff -u -u -r1.80 mkinit.c
--- util/mkinit.c	18 Dec 2001 05:44:13 -0000	1.80
+++ util/mkinit.c	11 Jan 2002 13:14:49 -0000
@@ -151,6 +151,9 @@
 
 static const char *MR_progname = NULL;
 
+	/* List of names of Aditi-RL code constants. */
+static String_List *rl_data = NULL;
+
 /* options and arguments, set by parse_options() */
 static const char *output_file_name = NULL;
 static const char *entry_point = "mercury__main_2_0";
@@ -167,15 +170,18 @@
 
 static int num_errors = 0;
 
+	/* List of options to pass to the runtime */
+static String_List *runtime_flags = NULL;
+
+	/* Pointer to tail of the runtime_flags list */
+static String_List **runtime_flags_tail = &runtime_flags;
+
 	/* List of directories to search for init files */
 static String_List *init_file_dirs = NULL;
 
 	/* Pointer to tail of the init_file_dirs list */
 static String_List **init_file_dirs_tail = &init_file_dirs;
 
-	/* List of names of Aditi-RL code constants. */
-static String_List *rl_data = NULL;
-
 /* --- code fragments to put in the output file --- */
 static const char header1[] = 
 	"/*\n"
@@ -323,6 +329,9 @@
 	"#else\n"
 	"	MR_program_entry_point = MR_ENTRY(%s);\n"
 	"#endif\n"
+	;
+
+static const char mercury_funcs2[] =
 	"\n"
 	"	mercury_runtime_init(argc, argv);\n"
 	"	return;\n"
@@ -478,7 +487,7 @@
 	int		i;
 	String_List	*tmp_slist;
 
-	while ((c = getopt(argc, argv, "ac:g:iI:lo:tw:x")) != EOF) {
+	while ((c = getopt(argc, argv, "ac:g:iI:lo:r:tw:x")) != EOF) {
 		switch (c) {
 		case 'a':
 			aditi = TRUE;
@@ -524,6 +533,23 @@
 			}
 			break;
 
+		case 'r':
+			/*
+			** Add the directory name to the end of the
+			** search path for `.init' files.
+			*/
+			if (optarg[0] != '\0') {
+				tmp_slist = (String_List *)
+					checked_malloc(sizeof(String_List));
+				tmp_slist->next = NULL;
+				tmp_slist->data = (char *)
+					checked_malloc(strlen(optarg) + 1);
+				strcpy(tmp_slist->data, optarg);
+				*runtime_flags_tail = tmp_slist;
+				runtime_flags_tail = &tmp_slist->next;
+			}
+			break;
+
 		case 't':
 			need_tracing = TRUE;
 			need_initialization_code = TRUE;
@@ -762,6 +788,7 @@
 output_main(void)
 {
 	const char *aditi_load_func;
+	String_List *list_tmp;
 
 	if (aditi) {
 		aditi_load_func = "MR_do_load_aditi_rl_code";
@@ -771,6 +798,16 @@
 	
 	printf(mercury_funcs, hl_entry_point, entry_point,
 		aditi_load_func, hl_entry_point, entry_point);
+
+	printf("	MR_runtime_flags = \"");
+	for (list_tmp = runtime_flags;
+			list_tmp != NULL; list_tmp = list_tmp->next) {
+		fputs(list_tmp->data, stdout);
+		putchar(' ');
+	}
+	printf("\";\n");
+
+	fputs(mercury_funcs2, stdout);
 
 	if (output_main_func) {
 		fputs(main_func, stdout);
--------------------------------------------------------------------------
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