1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/* ---------------------- mix_vm_dump.c :
* Implementation of the functions declared in mix_vm_dump.h
* ------------------------------------------------------------------
** Copyright (C) 2000, 2007 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
** the Free Software Foundation; either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
*/
#include "mix.h"
#include <unistd.h>
#include "xmix_vm.h"
#include "mix_vm_dump.h"
/* Create/destroy a dump context */
mix_dump_context_t *
mix_dump_context_new(FILE *fd, mix_address_t begin, mix_address_t end,
guint32 options)
{
mix_dump_context_t *result = NULL;
g_return_val_if_fail (fd != NULL, NULL);
if ( begin > end ) begin = end;
if ( end >= MEM_CELLS_NO_ ) end = MEM_CELLS_NO_;
result = g_new (mix_dump_context_t,1);
result->options = options;
result->begin = begin;
result->end = end;
result->channel = fd;
return result;
}
void
mix_dump_context_delete (mix_dump_context_t *dc)
{
g_return_if_fail (dc != NULL);
g_free (dc);
}
/* Use the dump context */
#define WORD_FMT_ "%s %02d %02d %02d %02d %02d (%010ld)"
#define SHORT_FMT_ "%s %02d %02d (%04d)"
#define WORD_SIGN_(w) mix_word_is_negative (w)? "-":"+"
#define SHORT_SIGN_(s) mix_short_is_negative (s)? "-":"+"
#define WORD_ABS_(w) mix_word_magnitude (w)
#define SHORT_ABS_(s) mix_short_magnitude (s)
#define WORD_BYTE_(w,i) mix_byte_new (mix_word_magnitude (w)>>(6*(5-i)))
#define SHORT_BYTE_(s,i) mix_byte_new (mix_short_magnitude (s)>>(6*(2-i)))
#define WORD_ARGS_(w) WORD_SIGN_ (w), WORD_BYTE_ (w,1), WORD_BYTE_ (w,2), \
WORD_BYTE_ (w,3), WORD_BYTE_ (w,4), WORD_BYTE_ (w,5), WORD_ABS_ (w)
#define SHORT_ARGS_(s) SHORT_SIGN_ (s), SHORT_BYTE_ (s,1), SHORT_BYTE_ (s,2), \
SHORT_ABS_ (s)
void
mix_vm_dump (const mix_vm_t *vm, const mix_dump_context_t *dc)
{
guint j, i;
FILE *f;
g_return_if_fail (vm != NULL);
g_return_if_fail (dc != NULL);
f = dc->channel;
if ( (dc->options & MIX_DUMP_rA) == MIX_DUMP_rA )
{
mix_word_t rA = get_rA_ (vm);
fprintf (f, "rA: " WORD_FMT_ "\n", WORD_ARGS_ (rA));
}
if ( (dc->options & MIX_DUMP_rX) == MIX_DUMP_rX )
{
mix_word_t rX = get_rX_ (vm);
fprintf (f, "rX: " WORD_FMT_ "\n", WORD_ARGS_ (rX));
}
if ( (dc->options & MIX_DUMP_rJ) == MIX_DUMP_rJ )
{
mix_short_t rJ = get_rJ_ (vm);
fprintf (f, "rJ: " SHORT_FMT_ "\n", SHORT_ARGS_ (rJ));
}
for (j = 0, i = 0; j < IREG_NO_; ++j)
{
if ( (dc->options & (MIX_DUMP_rI1<<j)) == (MIX_DUMP_rI1<<j) )
{
mix_short_t rI = mix_word_to_short_fast (get_rI_ (vm, j+1));
fprintf (f, "rI%d: " SHORT_FMT_ "\t", j+1, SHORT_ARGS_ (rI));
i++;
}
if ( i%2 == 0 && i != 0 ) fprintf (f, "\n");
}
if ( i%2 == 1 ) fprintf (f, "\n");
if ( (dc->options & MIX_DUMP_OVER) == MIX_DUMP_OVER )
{
fprintf (f, _("Overflow: %s\n"), get_over_ (vm)? "T":"F");
}
if ( (dc->options & MIX_DUMP_CMP) == MIX_DUMP_CMP )
{
const gchar *val = "?";
switch (get_cmp_ (vm))
{
case mix_LESS:
val = "L";
break;
case mix_GREAT:
val = "G";
break;
case mix_EQ:
val = "E";
break;
default:
g_assert_not_reached ();
break;
}
fprintf (f, _("Cmp: %s\n"), val);
}
if ( (dc->options & MIX_DUMP_CELLS) == MIX_DUMP_CELLS )
{
for (j = dc->begin; j < dc->end; ++j)
{
mix_word_t cell = get_cell_ (vm,j);
fprintf (f, "%04d: " WORD_FMT_ "\n", j, WORD_ARGS_ (cell));
}
}
fflush (f);
}
|