Add util.c util.h

svn path=/trunk/mono/; revision=33


Commit migrated from fb90b4929c
This commit is contained in:
Miguel de Icaza 2001-06-25 19:10:22 +00:00
parent baed4b1502
commit 19af4cdf55
3 changed files with 91 additions and 2 deletions

View File

@ -324,7 +324,12 @@ get_typeref (metadata_t *m, int idx)
s = mono_metadata_string_heap (m, cols [2]);
rs_idx = cols [0] >> 3;
table = cols [0] & 7;
printf ("------------ %d %d --------\n", rs_idx, table);
#if 0
rs_idx = cols [0];
table = 0;
#endif
printf ("------------ %d %d %d --------\n", idx, rs_idx, table);
switch (table){
case 0: /* Module */
@ -343,7 +348,7 @@ get_typeref (metadata_t *m, int idx)
ret = g_strdup_printf ("TypeRef: TYPEREF! (%s.%s)", s, t);
default:
ret = g_strdup ("ERROR");
ret = g_strdup_printf (">>>>>>>>>>> %d", cols [0] & 7);
}
return ret;

74
src/mono/mono/dis/util.c Normal file
View File

@ -0,0 +1,74 @@
/*
* util.c: Assorted utilities for the dissasembler
*
* Author:
* Miguel de Icaza (miguel@ximian.com)
*
* (C) 2001 Ximian, Inc (http://www.ximian.com)
*/
#include <config.h>
#include <glib.h>
#include <string.h>
#include <stdio.h>
#include "util.h"
/**
* map:
* @code: code to lookup in table
* @table: table to decode code
*
* Warning: returns static buffer.
*/
const char *
map (guint32 code, map_t *table)
{
int i;
for (i = 0; table [i].str != NULL; i++)
if (table [i].code == code)
return table [i].str;
g_assert_not_reached ();
return "";
}
/**
* flags:
* @code: bitfield
* @table: table to decode bitfield
*
* Warning: returns static buffer.
*/
const char *
flags (guint32 code, map_t *table)
{
static char buffer [1024];
int i;
buffer [0] = 0;
for (i = 0; table [i].str != NULL; i++)
if (table [i].code & code)
strcat (buffer, table [i].str);
return buffer;
}
/**
* hex_dump:
* @buffer: pointer to buffer to dump
* @base: numbering base to use
* @count: number of bytes to dump
*/
void
hex_dump (const char *buffer, int base, int count)
{
int i;
for (i = 0; i < count; i++){
if ((i % 16) == 0)
printf ("\n0x%08x: ", (unsigned char) base + i);
printf ("%02x ", (unsigned char) (buffer [i]));
}
fflush (stdout);
}

10
src/mono/mono/dis/util.h Normal file
View File

@ -0,0 +1,10 @@
typedef struct {
int code;
char *str;
} map_t;
const char *map (guint32 code, map_t *table);
const char *flags (guint32 code, map_t *table);
void hex_dump (const char *buffer, int base, int count);