Add new options -gd and -d.  Remove TEST_GEN_DEBUG and modify code switched on by it.
@@ -9,29 +9,31 @@ static void our_exit (int code) {
exit (code);
}
-#ifndef TEST_GEN_DEBUG
-#define TEST_GEN_DEBUG 0
-#endif
-
int main (int argc, char *argv[]) {
const char *mir_fname = NULL;
MIR_module_t mir_module;
MIR_item_t f, main_func;
MIR_val_t val;
- int interpr_p, gen_p;
+ int interpr_p, gen_p, debug_p, execute_p;
int res;
uint64_t (*fun_addr) (void);
MIR_context_t ctx;
if (argc != 2 && argc != 3) {
- fprintf (stderr, "%s: [-i|-g] <input mir file>\n", argv[0]);
+ fprintf (stderr, "%s: [-i|-g|-d|-gd] <input mir file>\n", argv[0]);
exit (1);
}
- interpr_p = gen_p = FALSE;
+ interpr_p = gen_p = debug_p = FALSE;
+ execute_p = TRUE;
if (strcmp (argv[1], "-i") == 0) {
interpr_p = TRUE;
} else if (strcmp (argv[1], "-g") == 0) {
gen_p = TRUE;
+ } else if (strcmp (argv[1], "-gd") == 0) {
+ gen_p = debug_p = TRUE;
+ } else if (strcmp (argv[1], "-d") == 0) {
+ gen_p = debug_p = TRUE;
+ execute_p = FALSE;
} else if (argc == 3) {
fprintf (stderr, "%s: unknown option %s\n", argv[0], argv[1]);
exit (1);
@@ -49,7 +51,7 @@ int main (int argc, char *argv[]) {
main_func = NULL;
for (f = DLIST_HEAD (MIR_item_t, mir_module->items); f != NULL; f = DLIST_NEXT (MIR_item_t, f))
if (f->item_type == MIR_func_item && strcmp (f->u.func->name, "main") == 0) main_func = f;
- if (main_func == NULL) {
+ if (main_func == NULL && execute_p) {
fprintf (stderr, "%s: cannot execute program w/o main function\n", argv[0]);
our_exit (1);
}
@@ -64,18 +66,19 @@ int main (int argc, char *argv[]) {
MIR_load_external (ctx, "malloc", malloc);
MIR_load_external (ctx, "free", free);
if (interpr_p) {
+ assert (execute_p);
MIR_link (ctx, MIR_set_interp_interface, NULL);
MIR_interp (ctx, main_func, &val, 0);
fprintf (stderr, "%s: %lu\n", mir_fname, (unsigned long) val.i);
} else if (gen_p) {
MIR_gen_init (ctx, 1);
-#if TEST_GEN_DEBUG
- MIR_gen_set_debug_file (ctx, 0, stderr);
-#endif
+ if (debug_p) MIR_gen_set_debug_file (ctx, 0, stderr);
+ if (execute_p) {
MIR_link (ctx, MIR_set_gen_interface, NULL);
fun_addr = MIR_gen (ctx, 0, main_func);
res = fun_addr ();
fprintf (stderr, "%s: %d\n", mir_fname, res);
+ }
MIR_gen_finish (ctx);
} else {
MIR_link (ctx, MIR_set_interp_interface, NULL);
