[m-rev.] already reviewed: mkinit -A
Zoltan Somogyi
zs at cs.mu.OZ.AU
Mon May 2 12:13:00 AEST 2005
This has already been reviewed by Ralph. Changes to the compiler to take
advantage of the new capability will come after we submit the paper.
Zoltan.
util/mkinit.c:
Add a mechanism that allows users to insert a call to a specified
function into the mercury_init function generated by mkinit. The
intention is that this should be used to initialize constraint stores
in program using constraint solvers. The store cannot be initialized
when the C global variable holding it is defined if the C global points
to a Mercury term.
cvs diff: Diffing .
Index: mkinit.c
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/util/mkinit.c,v
retrieving revision 1.97
diff -u -b -r1.97 mkinit.c
--- mkinit.c 2 May 2005 01:44:42 -0000 1.97
+++ mkinit.c 2 May 2005 01:56:24 -0000
@@ -199,6 +199,12 @@
/* Pointer to tail of the init_file_dirs list */
static String_List **init_file_dirs_tail = &init_file_dirs;
+ /* List of functions to always execute at initialization */
+static String_List *always_exec_funcs = NULL;
+
+ /* Pointer to tail of the init_file_dirs list */
+static String_List **always_exec_funcs_tail = &always_exec_funcs;
+
/* --- code fragments to put in the output file --- */
static const char header1[] =
"/*\n"
@@ -378,6 +384,10 @@
static const char mercury_funcs3[] =
"\n"
" mercury_runtime_init(argc, argv);\n"
+ "\n"
+ ;
+
+static const char mercury_funcs4[] =
" return;\n"
"}\n"
"\n"
@@ -544,12 +554,28 @@
int i;
String_List *tmp_slist;
- while ((c = getopt(argc, argv, "ac:g:iI:lo:r:tw:xX:")) != EOF) {
+ while ((c = getopt(argc, argv, "aA:c:g:iI:lo:r:tw:xX:")) != EOF) {
switch (c) {
case 'a':
aditi = MR_TRUE;
break;
+ case 'A':
+ /*
+ ** Add the argument to the end of the list of always executed
+ ** initialization functions.
+ */
+ 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);
+ *always_exec_funcs_tail = tmp_slist;
+ always_exec_funcs_tail = &tmp_slist->next;
+ }
+ break;
+
case 'c':
if (sscanf(optarg, "%d", &maxcalls) != 1) {
usage();
@@ -941,7 +967,7 @@
output_main(void)
{
const char *aditi_load_func;
- String_List *list_tmp;
+ String_List *list;
char *options_str;
if (aditi) {
@@ -963,11 +989,8 @@
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)
- {
- for (options_str = list_tmp->data;
- *options_str != '\0'; options_str++)
- {
+ for (list = runtime_flags; list != NULL; list = list->next) {
+ for (options_str = list->data; *options_str != '\0'; options_str++) {
if (*options_str == '\n') {
putchar('\\');
putchar('n');
@@ -987,6 +1010,12 @@
printf("\";\n");
fputs(mercury_funcs3, stdout);
+
+ for (list = always_exec_funcs; list != NULL; list = list->next) {
+ printf(" %s();\n", list->data);
+ }
+
+ fputs(mercury_funcs4, 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