Files
mercury/bytecode/mdis.c
Levi Cameron 2ca8f64b76 The beginnings of the new bytecode interpreter.
Estimated hours taken: 40

 The beginnings of the new bytecode interpreter. Probably
 just over half the code is the same or a
 superficially modified revision of the old one.

bytecode/mb_bytecode.c
bytecode/mb_bytecode.h
	Almost identical. Only real change is made MB_read_cstring not use
	any static variables

bytecode/mb_disasm.c
bytecode/mb_disasm.h
	Again, code very similar. Changed all the functions to write to a
	buffer instead of a file and to allow for bytecode indenting. Output
	format string for some instructions changed (hopefully more menaingful
	than just a dump of numbers)

bytecode/mb_machine.c
bytecode/mb_machine.h
	(completely different from old machine.c)
	The actual part that contains an abstract machine.
	 The rest is really just support code.
	 The instruction_table array is how instructions are dispatched. Look
	 at instr_xxxx for the actual interpreter code. Not all instructions
	 are implemented. MB_step and MB_run execute the actual
	  interpreting code

bytecode/mb_machine_show.h
bytecode/mb_machine_show.c
	  displays output showing the state of the machine


bytecode/mb_mem.c
bytecode/mb_mem.h
	  Identical to old mem apart from file name changes

bytecode/mb_util.c
bytecode/mb_util.h
	  took out strdup (not needed) and changed some comments

bytecode/mb_stack.c
bytecode/mb_stack.h
	  word based stack that will reallocate itself if it needs to


bytecode/mbi.c
	  front end for bytecode interpreter

bytecode/mdis.c
	  disassembles a file and dumps it to the screen
2001-01-24 07:42:29 +00:00

88 lines
1.8 KiB
C

/*
** Copyright (C) 2000 The University of Melbourne.
** This file may only be copied under the terms of the GNU Library General
** Public License - see the file COPYING.LIB in the Mercury distribution.
**
** $Id: mdis.c,v 1.8 2001-01-24 07:42:29 lpcam Exp $
*/
static char
rcs_id[] = "$Id: mdis.c,v 1.8 2001-01-24 07:42:29 lpcam Exp $";
/* Imports */
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include "mb_util.h"
#include "mb_disasm.h"
#include "mb_machine.h"
/* Exported definitions */
/* Local declarations */
static void
usage(const char* program_name, FILE* fp);
/* Implementation */
int
main(int argc, char* argv[]) {
int c;
/* Don't use default error messages from getopt() */
opterr = 0;
/* Read options */
while ((c = getopt(argc,argv,"h")) != EOF) {
switch (c) {
case 'h':
usage(argv[0], stderr);
exit(EXIT_SUCCESS);
break;
default:
usage(argv[0], stdout);
exit(EXIT_FAILURE);
break;
}
}
/* If no arguments, then assume bytecode stream is on stdin */
if (optind == argc) {
printf("<<dissassemble here>>\n");
/*MB_disassemble(stdin);*/
} else {
/* Process each bytecode file in order */
int i;
char *filename;
MB_Machine_State* ms;
for (i = optind; i < argc; i++) {
int indent_level = 0;
ms = MB_load_program_name(argv[i]);
if (ms != NULL) {
MB_listing(ms, stdout, 0, MB_code_size(ms)-1);
MB_unload_program(ms);
} else {
/* XXX: Give better error message */
MB_util_error("error reading bytecode file `%s'",
argv[i]);
}
}
} /* end else */
exit(EXIT_SUCCESS);
} /* end main() */
/* usage - print a short help screen to given output file */
static void
usage(const char* program_name, FILE* fp) {
fprintf(fp,
"usage: %s [-h | file]\n", program_name);
}