summaryrefslogtreecommitdiffhomepage
path: root/mixutils
diff options
context:
space:
mode:
authorjaortega <jaortega>2001-02-14 23:33:09 +0000
committerjaortega <jaortega>2001-02-14 23:33:09 +0000
commit9d97119cb4f191b7fa25a2d4913dd8bb41069776 (patch)
tree51acb65d80b266e3ee91da210dfa25ed23ced456 /mixutils
parent28d1b39edb08deff4edd50c7529c96aa23e39efe (diff)
downloadmdk-9d97119cb4f191b7fa25a2d4913dd8bb41069776.tar.gz
mdk-9d97119cb4f191b7fa25a2d4913dd8bb41069776.tar.bz2
mixvm-gud interface added
Diffstat (limited to 'mixutils')
-rw-r--r--mixutils/mixvm.c16
-rw-r--r--mixutils/mixvm_command.c169
-rw-r--r--mixutils/mixvm_command.h7
-rw-r--r--mixutils/mixvm_loop.c6
4 files changed, 136 insertions, 62 deletions
diff --git a/mixutils/mixvm.c b/mixutils/mixvm.c
index edf7ac5..4c28557 100644
--- a/mixutils/mixvm.c
+++ b/mixutils/mixvm.c
@@ -30,7 +30,7 @@
#include <getopt.h>
extern void
-mix_vmloop (const gchar *code_file);
+mix_vmloop (const gchar *code_file, gboolean use_emacs);
static void
mix_vmrun (const gchar *code_file, gboolean dump);
@@ -40,10 +40,11 @@ enum {
HELP_OPT = 'h',
USAGE_OPT = 'u',
RUN_OPT = 'r',
- DUMP_OPT = 'd'
+ DUMP_OPT = 'd',
+ EMACS_OPT = 'e', /* used by mixvm-gud only */
};
-static const char *options_ = "vhurd";
+static const char *options_ = "vhurd"; /* no short opt for --emacs */
static struct option long_options_[] =
{
@@ -52,13 +53,14 @@ static struct option long_options_[] =
{"usage", no_argument, 0, USAGE_OPT},
{"run", required_argument, 0, RUN_OPT},
{"dump", no_argument, 0, DUMP_OPT},
+ /* pek: yo! */
+ {"emacs", no_argument, 0, EMACS_OPT},
{0, 0, 0, 0}
};
static const gchar *USAGE_ =
N_("Usage: %s [-vhurd] [--version] [--help] [--usage] [--run] [--dump] [MIX_FILE]\n");
-
int
main (int argc, char **argv)
{
@@ -67,6 +69,7 @@ main (int argc, char **argv)
const char *in = NULL;
gboolean run = FALSE;
gboolean dump = FALSE;
+ gboolean emacs = FALSE;
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
@@ -101,6 +104,9 @@ main (int argc, char **argv)
/* getopt already handles the output of a warning message */
fprintf (stderr, _("(Try: %s -h)\n"), prog_name);
return EXIT_FAILURE;
+ case EMACS_OPT:
+ emacs = TRUE;
+ break;
default:
g_assert_not_reached ();
}
@@ -117,7 +123,7 @@ main (int argc, char **argv)
mix_init_lib ();
if (run) mix_vmrun(in, dump);
- else mix_vmloop (in);
+ else mix_vmloop (in, emacs);
mix_release_lib ();
diff --git a/mixutils/mixvm_command.c b/mixutils/mixvm_command.c
index 3fba0eb..ca72c51 100644
--- a/mixutils/mixvm_command.c
+++ b/mixutils/mixvm_command.c
@@ -1,7 +1,7 @@
/* -*-c-*- -------------- mixvm_command.c :
* Implementation of the functions declared in mixvm_command.h
* ------------------------------------------------------------------
- * Copyright (C) 2000 jose antonio ortega ruiz <jaortega@acm.org>
+ * Copyright (C) 2000, 2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -19,7 +19,6 @@
*
*/
-
#include <mixlib/mix.h>
#include <stdio.h>
@@ -32,6 +31,7 @@
#include <mixlib/mix_vm.h>
#include <mixlib/mix_vm_dump.h>
#include <mixlib/mix_eval.h>
+#include <mixlib/mix_src_file.h>
#include "mixvm_command.h"
/* The names of functions that actually do the manipulation. */
@@ -177,7 +177,6 @@ mixvm_cmd_generator_ (char *text, int state)
return ((char *)NULL);
}
-
/* command functions */
static COMMAND *
find_command_ (const char *name)
@@ -202,7 +201,96 @@ static gboolean is_tracing_ = FALSE;
/* uptime */
static mix_time_t uptime_ = 0;
static mix_time_t prog_time_ = 0;
+/* emacs interface */
+static gboolean emacs_ = FALSE;
+
+
+/* auxiliar methods */
+/* emacs interface */
+static void
+emacs_output_ (void);
+
+/* trace current instruction */
+static void
+trace_ (void);
+
+/* run a program tracing executed instructions */
+static int
+run_and_trace_ (void);
+
+/* print time statistics */
+static void
+print_time_ (void);
+
+
+static void
+emacs_output_ (void)
+{
+ /* pek: probably bad that we snag the src w/every emacs_output_,
+ however when multiple files are supported then this will
+ have to be done each time (but the info will be snagged
+ from elsewhere...) */
+ const mix_src_file_t *src = mix_vm_get_src_file (vm_);
+ const gchar *path = mix_src_file_get_path (src);
+ mix_address_t loc = mix_vm_get_prog_count (vm_);
+ guint lineno = mix_vm_get_address_lineno (vm_, loc);
+
+ printf ("\032\032mixvm:%s%s:%d\n", path, MIX_SRC_DEFEXT, lineno);
+ return;
+}
+
+/* trace current instruction */
+static void
+trace_ (void)
+{
+ enum {BUFFER_LEN = 128};
+ static gchar STRINS[BUFFER_LEN];
+
+ const mix_src_file_t *file = mix_vm_get_src_file (vm_);
+ const gchar *line = "\n";
+ mix_address_t loc = mix_vm_get_prog_count (vm_);
+ mix_word_t ins = mix_vm_get_addr_contents (vm_, loc);
+ mix_ins_t fins;
+ mix_word_to_ins_uncheck (ins, fins);
+ mix_ins_to_string_in_buffer (&fins, STRINS, BUFFER_LEN);
+
+ if (file != NULL)
+ {
+ gulong b = mix_vm_get_break_lineno (vm_);
+ if (b > 0) line = mix_src_file_get_line (file, b);
+ }
+
+ printf ("%d: [%s]\t%s", (gint)loc, STRINS, line);
+}
+
+/* run a program tracing executed instructions */
+static int
+run_and_trace_ (void)
+{
+ int k = MIX_VM_OK;
+ if (!is_tracing_)
+ return mix_vm_run (vm_);
+ else while (k == MIX_VM_OK)
+ {
+ trace_ ();
+ k = mix_vm_exec_next (vm_);
+ }
+ return k;
+}
+
+/* print time statistics */
+static void
+print_time_ (void)
+{
+ mix_time_t lapse = mix_vm_get_uptime(vm_) - uptime_;
+ uptime_ += lapse;
+ prog_time_ += lapse;
+ printf(_("Elapsed time: %ld /Total program time: %ld (Total uptime: %ld)\n"),
+ lapse, prog_time_, uptime_);
+}
+
+/* commands */
static int
cmd_help_ (char *arg)
@@ -272,56 +360,14 @@ cmd_load_ (char *arg)
prog_time_ = 0;
- return TRUE;
-}
-
-/* trace current instruction */
-static void
-trace_ (void)
-{
- enum {BUFFER_LEN = 128};
- static gchar STRINS[BUFFER_LEN];
-
- const mix_src_file_t *file = mix_vm_get_src_file (vm_);
- const gchar *line = "\n";
- mix_address_t loc = mix_vm_get_prog_count (vm_);
- mix_word_t ins = mix_vm_get_addr_contents (vm_, loc);
- mix_ins_t fins;
- mix_word_to_ins_uncheck (ins, fins);
- mix_ins_to_string_in_buffer (&fins, STRINS, BUFFER_LEN);
-
- if (file != NULL)
+ if (emacs_)
{
- gulong b = mix_vm_get_break_lineno (vm_);
- if (b > 0) line = mix_src_file_get_line (file, b);
+ emacs_output_();
}
-
- printf ("%d: [%s]\t%s", (gint)loc, STRINS, line);
-}
-static int
-run_and_trace_ (void)
-{
- int k = MIX_VM_OK;
- if (!is_tracing_)
- return mix_vm_run (vm_);
- else while (k == MIX_VM_OK)
- {
- trace_ ();
- k = mix_vm_exec_next (vm_);
- }
- return k;
+ return TRUE;
}
-static void
-print_time_ (void)
-{
- mix_time_t lapse = mix_vm_get_uptime(vm_) - uptime_;
- uptime_ += lapse;
- prog_time_ += lapse;
- printf(_("Elapsed time: %ld /Total program time: %ld (Total uptime: %ld)\n"),
- lapse, prog_time_, uptime_);
-}
static int
cmd_run_ (char *arg)
@@ -360,6 +406,12 @@ cmd_run_ (char *arg)
break;
}
print_time_ ();
+
+ if (emacs_)
+ {
+ emacs_output_();
+ }
+
return TRUE;
}
@@ -406,6 +458,12 @@ cmd_next_ (char *arg)
}
}
print_time_ ();
+
+ if (emacs_)
+ {
+ emacs_output_();
+ }
+
return TRUE;
}
@@ -415,6 +473,8 @@ cmd_quit_ (char *arg)
puts ("Quitting ...");
if ( vm_ ) mix_vm_delete (vm_);
if ( dc_ ) mix_dump_context_delete (dc_);
+
+ /* pek: anything needed here to make the marker disappear??? */
return FALSE;
}
@@ -1022,10 +1082,12 @@ cmd_troff_ (char *arg)
/* external interface */
void
-mixvm_cmd_init (char *arg)
+mixvm_cmd_init (char *arg, gboolean use_emacs)
{
/* Tell the completer that we want a crack first. */
rl_attempted_completion_function = (CPPFunction *)mixvm_cmd_completion_;
+ /* set the emacs flag */
+ emacs_ = use_emacs;
/* initialise the vm */
vm_ = mix_vm_new ();
dc_ = mix_dump_context_new (MIX_DUMP_DEF_CHANNEL,
@@ -1080,6 +1142,15 @@ mixvm_cmd_exec (char *line)
word = line + i;
+ /* pek note: as far as I know, only load, run,
+ next, and quit can affect where gud will
+ displays the "marker". I am toying with the
+ idea of adding some logic before and after
+ the *(command->func) that determines if
+ either the source file or line number have
+ changed. If another command is added later,
+ then the logic won't have to be inserted... */
+
/* Call the function. */
return ((*(command->func)) (word));
}
diff --git a/mixutils/mixvm_command.h b/mixutils/mixvm_command.h
index 663aa41..9741164 100644
--- a/mixutils/mixvm_command.h
+++ b/mixutils/mixvm_command.h
@@ -1,7 +1,7 @@
/* -*-c-*- ---------------- mixvm_command.h :
* Declarations for commands accepted by the mix virtual machine
* ------------------------------------------------------------------
- * Copyright (C) 2000 jose antonio ortega ruiz <jaortega@acm.org>
+ * Copyright (C) 2000, 2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -26,13 +26,10 @@
#include <glib.h>
extern void
-mixvm_cmd_init (char *arg);
+mixvm_cmd_init (char *arg, gboolean use_emacs);
extern gboolean
mixvm_cmd_exec (char *line);
-
-
-
#endif /* MIXVM_COMMAND_H */
diff --git a/mixutils/mixvm_loop.c b/mixutils/mixvm_loop.c
index 309c492..8a571d8 100644
--- a/mixutils/mixvm_loop.c
+++ b/mixutils/mixvm_loop.c
@@ -1,7 +1,7 @@
/* -*-c-*- -------------- mixvm_loop.c :
* Implementation of mix vm command loop.
* ------------------------------------------------------------------
- * Copyright (C) 2000 jose antonio ortega ruiz <jaortega@acm.org>
+ * Copyright (C) 2000, 2001 Free Software Foundation, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -56,9 +56,9 @@ rl_gets ()
/* The main command loop of the virtual machine */
void
-mix_vmloop (const gchar *file)
+mix_vmloop (const gchar *file, gboolean use_emacs)
{
- mixvm_cmd_init ((char *)file);
+ mixvm_cmd_init ((char *)file, use_emacs);
while ( mixvm_cmd_exec (rl_gets ()) )
;
}