diff options
-rw-r--r-- | mixlib/mix_src_file.c | 46 | ||||
-rw-r--r-- | mixlib/mix_vm.c | 33 | ||||
-rw-r--r-- | mixlib/mix_vm.h | 4 | ||||
-rw-r--r-- | mixlib/mix_vm_command.c | 62 | ||||
-rw-r--r-- | mixlib/mix_vm_command.h | 20 |
5 files changed, 149 insertions, 16 deletions
diff --git a/mixlib/mix_src_file.c b/mixlib/mix_src_file.c index b0e680b..1cb6656 100644 --- a/mixlib/mix_src_file.c +++ b/mixlib/mix_src_file.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mix_src_file.c : * Implementation of the functions declared in mix_src_file.h * ------------------------------------------------------------------ - * Last change: Time-stamp: "01/02/16 00:03:10 jose" + * Last change: Time-stamp: "01/03/10 03:25:50 jose" * ------------------------------------------------------------------ * Copyright (C) 2000, 2001 Free Software Foundation, Inc. * @@ -21,6 +21,7 @@ * */ +#include <ctype.h> #include <stdio.h> #include <unistd.h> #include "mix_src_file.h" @@ -32,7 +33,48 @@ struct mix_src_file_t GPtrArray *lines; /* an array of the file lines */ guint lineno; /* the number of lines */ }; + +/* format a source line */ +static gchar * +format_line_ (gchar *line) +{ + const gchar *label, *op, *rest; + gint k = 0; + + if (!line) return line; + if (line[0] == '*' || strlen(line) == 0) return g_strdup (line); + + + if (isspace (line[0])) + { + label = " "; + while (line[k] && isspace (line[k])) ++k; + } + else + { + label = line; + while (line[k] && !isspace (line[k])) ++k; + while (line[k] && isspace (line[k])) ++k; + } + if (line[k]) + { + line[k - 1] = 0; + op = line + k; + while (line[k] && !isspace (line[k])) ++k; + while (line[k] && isspace (line[k])) ++k; + line[k - 1] = 0; + rest = (line[k]) ? line + k: "\n"; + } + else + { + op = rest = "\n"; + } + + + return g_strdup_printf ("%-12s%-6s%s", label, op, rest); +} + /* load the source file lines into memory */ static gboolean load_file_ (mix_src_file_t *file) @@ -51,7 +93,7 @@ load_file_ (mix_src_file_t *file) while (fgets (BUFFER, BUFFER_SIZE, f) == BUFFER) { - g_ptr_array_add (file->lines, (gpointer) g_strdup (BUFFER)); + g_ptr_array_add (file->lines, (gpointer) format_line_ (BUFFER)); file->lineno++; } diff --git a/mixlib/mix_vm.c b/mixlib/mix_vm.c index 6da21e2..0a885d8 100644 --- a/mixlib/mix_vm.c +++ b/mixlib/mix_vm.c @@ -343,6 +343,39 @@ mix_vm_get_address_lineno (const mix_vm_t *vm, mix_address_t addr) return lineno; } +/* Get the address for a given source line number */ +typedef struct +{ + guint lineno; + mix_address_t result; +} addr_traverse_t; + +static gint +get_address_ (gpointer key, gpointer value, gpointer data) +{ + addr_traverse_t *tr = (addr_traverse_t *)data; + if (GPOINTER_TO_UINT (key) == tr->lineno) + { + tr->result = mix_short_new (GPOINTER_TO_UINT (value)); + return TRUE; + } + return (GPOINTER_TO_UINT (key) < tr->lineno)? FALSE:TRUE; +} + +mix_address_t +mix_vm_get_lineno_address (const mix_vm_t *vm, guint lineno) +{ + addr_traverse_t tr; + + g_return_val_if_fail (vm != NULL, MIX_VM_CELL_NO); + if (!vm->line_table) return MIX_VM_CELL_NO; + tr.lineno = lineno; + tr.result = MIX_VM_CELL_NO; + g_tree_traverse (vm->line_table, get_address_, G_IN_ORDER, (gpointer)&tr); + return tr.result; +} + + /* Reposition program counter and reset state so that a loaded program can be restarted. */ diff --git a/mixlib/mix_vm.h b/mixlib/mix_vm.h index b4b408c..95ed742 100644 --- a/mixlib/mix_vm.h +++ b/mixlib/mix_vm.h @@ -137,6 +137,10 @@ mix_vm_get_prog_count (const mix_vm_t *vm); extern guint mix_vm_get_address_lineno (const mix_vm_t *vm, mix_address_t addr); +/* Get the address for a given source line number */ +extern mix_address_t +mix_vm_get_lineno_address (const mix_vm_t *vm, guint lineno); + /* Reposition program counter and reset state so that a loaded program can be restarted. */ diff --git a/mixlib/mix_vm_command.c b/mixlib/mix_vm_command.c index 49f7d1d..1ef0d7e 100644 --- a/mixlib/mix_vm_command.c +++ b/mixlib/mix_vm_command.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mix_vm_command.c : * Implementation of the functions declared in mix_vm_command.h * ------------------------------------------------------------------ - * Last change: Time-stamp: "01/02/26 03:29:19 jose" + * Last change: Time-stamp: "01/03/10 03:21:33 jose" * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -53,8 +53,10 @@ struct mix_vm_cmd_dispatcher_t mix_dump_context_t *dump; /* dump context for output */ mix_eval_t *eval; /* evaluator for w-expressions */ gboolean trace; /* tracing flag */ + gboolean printtime; /* printing times flag */ mix_time_t uptime; /* total running time */ - mix_time_t laptime; /* current program running time */ + mix_time_t laptime; /* last run time */ + mix_time_t progtime; /* current program running time */ hook_ pre_hooks[MIX_CMD_INVALID]; /* Pre-command hooks */ hook_ post_hooks[MIX_CMD_INVALID]; /* Post-command hooks */ global_hook_ global_pre; /* global pre-command hook */ @@ -188,7 +190,8 @@ mix_vm_cmd_dispatcher_new (FILE *out_fd, /* output messages file */ result = g_new (mix_vm_cmd_dispatcher_t, 1); result->out = out_fd; result->err = err_fd; - result->uptime = result->laptime = 0; + result->uptime = result->laptime = result->progtime = 0; + result->printtime = TRUE; result->trace = FALSE; result->eval = mix_eval_new (); result->dump = mix_dump_context_new (out_fd, @@ -320,6 +323,38 @@ mix_vm_cmd_dispatcher_dispatch_text (mix_vm_cmd_dispatcher_t *dis, return result; } +/* get total uptime */ +mix_time_t +mix_vm_cmd_dispatcher_get_uptime (const mix_vm_cmd_dispatcher_t *dis) +{ + g_return_val_if_fail (dis != NULL, 0); + return dis->uptime; +} + +/* get program total time */ +mix_time_t +mix_vm_cmd_dispatcher_get_progtime (const mix_vm_cmd_dispatcher_t *dis) +{ + g_return_val_if_fail (dis != NULL, 0); + return dis->progtime; +} + +/* get time lapse */ +mix_time_t +mix_vm_cmd_dispatcher_get_laptime (const mix_vm_cmd_dispatcher_t *dis) +{ + g_return_val_if_fail (dis != NULL, 0); + return dis->laptime; +} + +/* toggle time printing */ +void +mix_vm_cmd_dispatcher_print_time (mix_vm_cmd_dispatcher_t * dis, gboolean print) +{ + g_return_if_fail (dis != NULL); + dis->printtime = print; +} + /* get the mix vm */ const mix_vm_t * mix_vm_cmd_dispatcher_get_vm (const mix_vm_cmd_dispatcher_t *dis) @@ -350,7 +385,7 @@ trace_ (mix_vm_cmd_dispatcher_t *dis) if (b > 0) line = mix_src_file_get_line (file, b); } - fprintf (dis->out, "%d: [%s]\t%s", (gint)loc, STRINS, line); + fprintf (dis->out, "%d: [%-15s]\t%s", (gint)loc, STRINS, line); } /* run a program tracing executed instructions */ @@ -372,12 +407,13 @@ run_and_trace_ (mix_vm_cmd_dispatcher_t *dis) static void print_time_ (mix_vm_cmd_dispatcher_t *dis) { - mix_time_t lapse = mix_vm_get_uptime(dis->vm) - dis->uptime; - dis->uptime += lapse; - dis->laptime += lapse; - fprintf( dis->out, - _("Elapsed time: %ld /Total program time: %ld (Total uptime: %ld)\n"), - lapse, dis->laptime, dis->uptime); + dis->laptime = mix_vm_get_uptime(dis->vm) - dis->uptime; + dis->uptime += dis->laptime; + dis->progtime += dis->laptime; + if (dis->printtime) + fprintf( dis->out, + _("Elapsed time: %ld /Total program time: %ld (Total uptime: %ld)\n"), + dis->laptime, dis->progtime, dis->uptime); } @@ -450,7 +486,7 @@ cmd_load_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) fprintf (dis->out, _("Program loaded. Start address: %d\n"), mix_vm_get_prog_count (dis->vm)); - dis->laptime = 0; + dis->laptime = dis->progtime = 0; return TRUE; } @@ -465,7 +501,7 @@ cmd_run_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) if (mix_vm_is_halted (dis->vm)) { mix_vm_reset_program (dis->vm); - dis->laptime = 0; + dis->laptime = dis->progtime = 0; } switch (run_and_trace_ (dis)) @@ -519,7 +555,7 @@ cmd_next_ (mix_vm_cmd_dispatcher_t *dis, const gchar *arg) if (mix_vm_is_halted (dis->vm)) { mix_vm_reset_program (dis->vm); - dis->laptime = 0; + dis->laptime = dis->progtime = 0; } while ( ins_no-- > 0 ) diff --git a/mixlib/mix_vm_command.h b/mixlib/mix_vm_command.h index 89a2c2b..a805e68 100644 --- a/mixlib/mix_vm_command.h +++ b/mixlib/mix_vm_command.h @@ -1,7 +1,7 @@ /* -*-c-*- ---------------- mix_vm_command.h : * declarations for mix_vm_command_t, describing commands issued to a vm * ------------------------------------------------------------------ - * Last change: Time-stamp: <01/02/26 02:41:26 jose> + * Last change: Time-stamp: <01/03/09 21:53:43 jose> * ------------------------------------------------------------------ * Copyright (C) 2001 Free Software Foundation, Inc. * @@ -107,6 +107,24 @@ extern gboolean mix_vm_cmd_dispatcher_dispatch_text (mix_vm_cmd_dispatcher_t *dis, const gchar *text); + +/* get total uptime */ +extern mix_time_t +mix_vm_cmd_dispatcher_get_uptime (const mix_vm_cmd_dispatcher_t *dis); + +/* get program total time */ +extern mix_time_t +mix_vm_cmd_dispatcher_get_progtime (const mix_vm_cmd_dispatcher_t *dis); + +/* get time lapse */ +extern mix_time_t +mix_vm_cmd_dispatcher_get_laptime (const mix_vm_cmd_dispatcher_t *dis); + +/* toggle time printing */ +extern void +mix_vm_cmd_dispatcher_print_time (mix_vm_cmd_dispatcher_t * dis, + gboolean print); + /* install hooks */ extern void mix_vm_cmd_dispatcher_pre_hook (mix_vm_cmd_dispatcher_t *dis, |