[m-rev.] diff: finalise declarations (part 1)
Julien Fischer
juliensf at cs.mu.OZ.AU
Mon Sep 26 01:19:39 AEST 2005
Estimated hours taken: 2
Branches: main
Add the initial stage of finalise declarations. These are a counterpart
to the recently added initialise declarations; they allow the user to specify
predicates that are to be run after main/2 exits.
util/mkinit.c:
Add support for `REQUIRED_FINAL' directives. These are similar to
`REQUIRED_INIT' directives except that the specified functions are
run after main/2. Any functions specified using this directive are
gathered into bunches and called from the final_module_required
function.
runtime/mercury_wrapper.h:
runtime/mercury_wrapper.c:
Export a new global that points to the final_module_required function
for the program.
Julien.
Index: runtime/mercury_wrapper.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.c,v
retrieving revision 1.154
diff -u -r1.154 mercury_wrapper.c
--- runtime/mercury_wrapper.c 19 Sep 2005 07:26:33 -0000 1.154
+++ runtime/mercury_wrapper.c 24 Sep 2005 16:58:53 -0000
@@ -342,6 +342,7 @@
void (*MR_address_of_write_out_proc_statics)(FILE *fp);
#endif
void (*MR_address_of_init_modules_required)(void);
+void (*MR_address_of_final_modules_required)(void);
MR_TypeCtorInfo MR_type_ctor_info_for_univ;
MR_TypeCtorInfo MR_type_info_for_type_info;
Index: runtime/mercury_wrapper.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_wrapper.h,v
retrieving revision 1.71
diff -u -r1.71 mercury_wrapper.h
--- runtime/mercury_wrapper.h 19 Sep 2005 07:26:33 -0000 1.71
+++ runtime/mercury_wrapper.h 24 Sep 2005 17:00:42 -0000
@@ -108,6 +108,7 @@
extern void (*MR_address_of_write_out_proc_statics)(FILE *fp);
#endif
extern void (*MR_address_of_init_modules_required)(void);
+extern void (*MR_address_of_final_modules_required)(void);
extern MR_TypeCtorInfo MR_type_ctor_info_for_univ;
extern MR_TypeCtorInfo MR_type_info_for_type_info;
Index: util/mkinit.c
===================================================================
RCS file: /home/mercury1/repository/mercury/util/mkinit.c,v
retrieving revision 1.104
diff -u -r1.104 mkinit.c
--- util/mkinit.c 19 Sep 2005 07:26:38 -0000 1.104
+++ util/mkinit.c 24 Sep 2005 16:57:05 -0000
@@ -78,7 +78,8 @@
PURPOSE_DEBUGGER = 2,
PURPOSE_COMPLEXITY = 3,
PURPOSE_PROC_STATIC = 4,
- PURPOSE_REQ_INIT = 5
+ PURPOSE_REQ_INIT = 5,
+ PURPOSE_REQ_FINAL = 6
} Purpose;
const char *main_func_name[] =
@@ -89,6 +90,7 @@
"init_modules_complexity_procs",
"write_out_proc_statics",
"init_modules_required",
+ "final_modules_required"
};
const char *module_suffix[] =
@@ -99,6 +101,7 @@
"init_complexity_procs",
"write_out_proc_statics",
"",
+ "",
};
const char *init_suffix[] =
@@ -117,7 +120,8 @@
if_need_to_init,
if_need_term_size,
if_need_deep_prof,
- NULL
+ NULL,
+ NULL,
};
const char *main_func_guard[] =
@@ -128,6 +132,7 @@
if_need_term_size,
if_need_deep_prof,
NULL,
+ NULL,
};
const char *main_func_body_guard[] =
@@ -137,6 +142,7 @@
if_need_to_init,
NULL,
NULL,
+ NULL,
NULL
};
@@ -147,6 +153,7 @@
"void",
"void",
"FILE *fp",
+ "void",
"void"
};
@@ -157,6 +164,7 @@
"void",
"void",
"FILE *",
+ "void",
"void"
};
@@ -167,6 +175,7 @@
"",
"",
"fp",
+ "",
""
};
@@ -215,7 +224,6 @@
** The concatenation of std_modules and special_modules; created with the
** right size (std_module_next + special_module_next).
*/
-
static const char **std_and_special_modules = NULL;
/*
@@ -223,12 +231,20 @@
** always be run. This is currently used to initialize the states of constraint
** solvers. We call an "init_required" function for each such module.
*/
-
-static const char **req_modules = NULL;
-static int req_module_max = 0;
-static int req_module_next = 0;
+static const char **req_init_modules = NULL;
+static int req_init_module_max = 0;
+static int req_init_module_next = 0;
#define MR_INIT_REQ_MODULE_SIZE 10
+/*
+** List of names of modules that have finialisation function that should
+** always be run. We call a "final_required" function for each such module.
+*/
+static const char **req_final_modules = NULL;
+static int req_final_module_max = 0;
+static int req_final_module_next = 0;
+#define MR_FINAL_REQ_MODULE_SIZE 10
+
/* List of names of Aditi-RL code constants. */
static String_List *rl_data = NULL;
@@ -378,6 +394,7 @@
" write_out_proc_statics;\n"
"#endif\n"
" MR_address_of_init_modules_required = init_modules_required;\n"
+ " MR_address_of_final_modules_required = final_modules_required;\n"
"#ifdef MR_RECORD_TERM_SIZES\n"
" MR_complexity_procs = MR_complexity_proc_table;\n"
" MR_num_complexity_procs = %d;\n"
@@ -612,9 +629,14 @@
output_main_init_function(PURPOSE_PROC_STATIC, num_bunches);
num_bunches = output_sub_init_functions(PURPOSE_REQ_INIT,
- req_modules, req_module_next);
+ req_init_modules, req_init_module_next);
output_main_init_function(PURPOSE_REQ_INIT, num_bunches);
+ num_bunches = output_sub_init_functions(PURPOSE_REQ_FINAL,
+ req_final_modules, req_final_module_next);
+ output_main_init_function(PURPOSE_REQ_FINAL, num_bunches);
+
+
if (aditi) {
output_aditi_load_function();
}
@@ -1218,10 +1240,12 @@
{
const char * const init_str = "INIT ";
const char * const reqinit_str = "REQUIRED_INIT ";
+ const char * const reqfinal_str = "REQUIRED_FINAL ";
const char * const endinit_str = "ENDINIT ";
const char * const aditi_init_str = "ADITI_DATA ";
const int init_strlen = strlen(init_str);
const int reqinit_strlen = strlen(reqinit_str);
+ const int reqfinal_strlen = strlen(reqfinal_str);
const int endinit_strlen = strlen(endinit_str);
const int aditi_init_strlen = strlen(aditi_init_str);
char line[MAXLINE];
@@ -1273,10 +1297,24 @@
line[j] = '\0';
func_name = line + reqinit_strlen;
- MR_ensure_room_for_next(req_module, const char *,
+ MR_ensure_room_for_next(req_init_module, const char *,
MR_INIT_REQ_MODULE_SIZE);
- req_modules[req_module_next] = checked_strdup(func_name);
- req_module_next++;
+ req_init_modules[req_init_module_next] = checked_strdup(func_name);
+ req_init_module_next++;
+ } else if (strncmp(line, reqfinal_str, reqfinal_strlen) == 0) {
+ char *func_name;
+ int j;
+
+ for (j = reqfinal_strlen; MR_isalnumunder(line[j]); j++) {
+ /* VOID */
+ }
+ line[j] = '\0';
+
+ func_name = line + reqfinal_strlen;
+ MR_ensure_room_for_next(req_final_module, const char *,
+ MR_FINAL_REQ_MODULE_SIZE);
+ req_final_modules[req_final_module_next] = checked_strdup(func_name);
+ req_final_module_next++;
} else if (aditi &&
strncmp(line, aditi_init_str, aditi_init_strlen) == 0)
{
--------------------------------------------------------------------------
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