All pastes #1988905 Raw Edit

Mathias

public diff v1 · immutable
#1988905 ·published 2010-11-12 09:26 UTC
rendered paste body
diff --git a/ijvm.c b/ijvm.cindex 4827882..5ee6aa2 100644--- a/ijvm.c+++ b/ijvm.c@@ -361,7 +361,8 @@ main (int argc, char *argv[])     fprintf (stderr, "Usage: ijvm [OPTION] FILENAME [PARAMETERS ...]\n\n");     fprintf (stderr, "Where OPTION is\n\n");     fprintf (stderr, "  -s            Silent mode.  No snapshot is produced.\n");-    fprintf (stderr, "  -f SPEC-FILE  The IJVM specification file to use.\n\n");+    fprintf (stderr, "  -f SPEC-FILE  The IJVM specification file to use.\n");+    fprintf (stderr, "  -l LEN        Stack output length.  Default 20.\n\n");     fprintf (stderr, "If you pass `-' as the filename the simulator will read the bytecode\nfile from stdin.\n\n");     fprintf (stderr, "You must specify as many arguments as your main method requires, except\n");     fprintf (stderr, "one; the simulator will pass the initial object reference for you.\n");@@ -375,6 +376,24 @@ main (int argc, char *argv[])     argc = argc - 1;   } +  int stacksize = 20;+  if (strcmp (argv[1], "-l") == 0) {+    argv = argv + 1;+    argc = argc - 1;+    if (argc < 2 || !*argv[1]) {+      fprintf (stderr, "No argument to -l given.\n");+      exit (-1);+    }+    char *c;+    stacksize = strtol(argv[1], &c, 0);+    if (c == NULL) {+      fprintf (stderr, "Non-numeric argument to -l given.\n");+      exit (-1);+    }+    argv = argv + 1;+    argc = argc - 1;+  }+   if (strcmp (argv[1], "-") == 0)     file = stdin;   else@@ -394,19 +413,18 @@ main (int argc, char *argv[])   }    /* This is the interpreter main loop.  It essentially excecutes-   * ijvm_execute_opcode until the program terminates (which is when-   * an ireturn from main is encountered).  In each step, the-   * instruction, its arguments and the top 8 elements on the stack-   * are printed. */+   * ijvm_execute_opcode until the program terminates (which is when an ireturn+   * from main is encountered).  In each step, the instruction, its arguments+   * and the top stacksize elements on the stack are printed. */    if (verbose)-    ijvm_print_stack (i->stack + i->sp, MIN (i->sp - i->initial_sp, 8), TRUE);+    ijvm_print_stack (i->stack + i->sp, MIN (i->sp - i->initial_sp, stacksize), TRUE);   while (ijvm_active (i)) {     if (verbose)       ijvm_print_snapshot (i->method + i->pc);     ijvm_execute_opcode (i);     if (verbose)-      ijvm_print_stack (i->stack + i->sp, MIN (i->sp - i->initial_sp, 8), FALSE);+      ijvm_print_stack (i->stack + i->sp, MIN (i->sp - i->initial_sp, stacksize), FALSE);   }    ijvm_print_result (i);