1995-08-09 08:06:35 -07:00
|
|
|
/***********************************************************************/
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Objective Caml */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
|
|
|
|
/* */
|
1996-04-30 07:53:58 -07:00
|
|
|
/* Copyright 1996 Institut National de Recherche en Informatique et */
|
1999-11-17 10:59:06 -08:00
|
|
|
/* en Automatique. All rights reserved. This file is distributed */
|
2001-12-07 05:41:02 -08:00
|
|
|
/* under the terms of the GNU Library General Public License, with */
|
|
|
|
/* the special exception on linking described in file ../LICENSE. */
|
1995-08-09 08:06:35 -07:00
|
|
|
/* */
|
|
|
|
/***********************************************************************/
|
|
|
|
|
|
|
|
/* $Id$ */
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
/* Trace the instructions executed */
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "instruct.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "mlvalues.h"
|
|
|
|
#include "opnames.h"
|
2003-05-26 05:41:54 -07:00
|
|
|
#include "prims.h"
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2004-01-02 11:23:29 -08:00
|
|
|
extern code_t caml_start_code;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2004-01-02 11:23:29 -08:00
|
|
|
long caml_icount = 0;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2004-01-02 11:23:29 -08:00
|
|
|
void caml_stop_here () {}
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2004-01-02 11:23:29 -08:00
|
|
|
int caml_trace_flag = 0;
|
1995-05-04 03:15:53 -07:00
|
|
|
|
2004-01-02 11:23:29 -08:00
|
|
|
void caml_disasm_instr(pc)
|
1995-05-04 03:15:53 -07:00
|
|
|
code_t pc;
|
|
|
|
{
|
|
|
|
int instr = *pc;
|
2004-01-02 11:23:29 -08:00
|
|
|
printf("%6ld %s", (long) (pc - caml_start_code),
|
1995-05-04 03:15:53 -07:00
|
|
|
instr < 0 || instr > STOP ? "???" : names_of_instructions[instr]);
|
|
|
|
pc++;
|
|
|
|
switch(instr) {
|
1998-10-07 12:01:42 -07:00
|
|
|
/* Instructions with one integer operand */
|
|
|
|
case PUSHACC: case ACC: case POP: case ASSIGN:
|
|
|
|
case PUSHENVACC: case ENVACC: case PUSH_RETADDR: case APPLY:
|
|
|
|
case APPTERM1: case APPTERM2: case APPTERM3: case RETURN:
|
|
|
|
case GRAB: case PUSHGETGLOBAL: case GETGLOBAL: case SETGLOBAL:
|
|
|
|
case PUSHATOM: case ATOM: case MAKEBLOCK1: case MAKEBLOCK2:
|
|
|
|
case MAKEBLOCK3: case MAKEFLOATBLOCK:
|
|
|
|
case GETFIELD: case SETFIELD: case GETFLOATFIELD: case SETFLOATFIELD:
|
|
|
|
case BRANCH: case BRANCHIF: case BRANCHIFNOT: case PUSHTRAP:
|
|
|
|
case CONSTINT: case PUSHCONSTINT: case OFFSETINT: case OFFSETREF:
|
|
|
|
case OFFSETCLOSURE: case PUSHOFFSETCLOSURE:
|
|
|
|
printf(" %d\n", pc[0]); break;
|
|
|
|
/* Instructions with two operands */
|
|
|
|
case APPTERM: case CLOSURE: case CLOSUREREC: case PUSHGETGLOBALFIELD:
|
|
|
|
case GETGLOBALFIELD: case MAKEBLOCK:
|
2000-10-02 07:18:05 -07:00
|
|
|
case BEQ: case BNEQ: case BLTINT: case BLEINT: case BGTINT: case BGEINT:
|
|
|
|
case BULTINT: case BUGEINT:
|
1998-10-07 12:01:42 -07:00
|
|
|
printf(" %d, %d\n", pc[0], pc[1]); break;
|
|
|
|
/* Instructions with a C primitive as operand */
|
|
|
|
case C_CALLN:
|
2003-05-26 05:41:54 -07:00
|
|
|
printf(" %d,", pc[0]); pc++;
|
|
|
|
/* fallthrough */
|
|
|
|
case C_CALL1: case C_CALL2: case C_CALL3: case C_CALL4: case C_CALL5:
|
2004-01-01 08:42:43 -08:00
|
|
|
if (pc[0] < 0 || pc[0] >= caml_prim_name_table.size)
|
2003-05-26 05:41:54 -07:00
|
|
|
printf(" unknown primitive %d\n", pc[0]);
|
|
|
|
else
|
2004-01-01 08:42:43 -08:00
|
|
|
printf(" %s\n", (char *) caml_prim_name_table.contents[pc[0]]);
|
2003-05-26 05:41:54 -07:00
|
|
|
break;
|
1998-10-07 12:01:42 -07:00
|
|
|
default:
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
fflush (stdout);
|
1995-05-04 03:15:53 -07:00
|
|
|
}
|
|
|
|
|
2003-12-15 10:10:51 -08:00
|
|
|
#endif /* DEBUG */
|