示例#1
0
文件: retro.c 项目: crcx/retroforth
/* Main ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
int main(int argc, char **argv)
{
  int i;
  VM *vm = malloc(sizeof(VM));
  strcpy(vm->filename, "retroImage");

  init_vm(vm);
  dev_init_input();

  /* Parse the command line arguments */
  for (i = 1; i < argc; i++) {
    if (strcmp(argv[i], "--with") == 0)
      dev_include(argv[++i]);
    if (strcmp(argv[i], "--image") == 0)
      strcpy(vm->filename, argv[++i]);
    if (strcmp(argv[i], "--shrink") == 0)
      vm->shrink = 1;
  }

  dev_init_output();

  if (vm_load_image(vm, vm->filename) == -1) {
    dev_cleanup();
    printf("Sorry, unable to find %s\n", vm->filename);
    exit(1);
  }

  for (vm->ip = 0; vm->ip < IMAGE_SIZE; vm->ip++)
    vm_process(vm);

  dev_cleanup();
  return 0;
}
示例#2
0
VMProcess::VMProcess() {
  assert(vm_process() == NULL, "we can only allocate one VMProcess");

  _vm_process   = this;
  _vm_operation = NULL;

  _thread    = os::starting_thread(&_thread_id);
  _event     = os::create_event(true);
}
示例#3
0
文件: ngaro.c 项目: crcx/retroforth
/******************************************************
 * Main entry point into the VM
 ******************************************************/
int main(int argc, char **argv)
{
  int a, i, endian;
  char *opstat_path = 0;
  FILE *opstats = 0;

  VM *vm = malloc(sizeof(VM));

  endian = 0;

  strcpy(vm->filename, "retroImage");

  init_vm(vm);
  dev_init(INPUT);

  vm->shrink = 0;
  vm->trace = 0;
  vm->trace_stacks = 0;

  /* Parse the command line arguments */
  for (i = 1; i < argc; i++)
  {
    if (strcmp(argv[i], "--trace") == 0)
    {
      vm->trace = -1;
    }
    else if (strcmp(argv[i], "--trace-stacks") == 0)
    {
      vm->trace_stacks = -1;
    }
    else if (strcmp(argv[i], "--endian") == 0)
    {
      endian = -1;
    }
    else if (strcmp(argv[i], "--with") == 0)
    {
      i++; dev_include(argv[i]);
    }
    else if (strcmp(argv[i], "--opstats") == 0)
    {
      i++; opstat_path = argv[i];
      init_stats(&opstats, opstat_path, call_stats_please);
    }
    else if (strcmp(argv[i], "--callstats") == 0)
    {
      call_stats_please = 1;
      if (opstat_path)
      {
        init_stats(&opstats, opstat_path, call_stats_please);
      }
    }
    else if (strcmp(argv[i], "--shrink") == 0)
    {
      vm->shrink = 1;
    }
    else if ((strcmp(argv[i], "--help") == 0) ||
             (strcmp(argv[i], "-help") == 0)  ||
             (strcmp(argv[i], "/help") == 0)  ||
             (strcmp(argv[i], "/?") == 0)     ||
             (strcmp(argv[i], "/h") == 0)     ||
             (strcmp(argv[i], "-h") == 0))
    {
      fprintf(stderr, "%s [options] [imagename]\n", argv[0]);
      fprintf(stderr, "Valid options are:\n");
      fprintf(stderr, "   --about          Display some information about Ngaro\n");
      fprintf(stderr, "   --trace          Trace instructions being executed\n");
      fprintf(stderr, "     --trace-stacks Also trace data and return stack contents\n");
      fprintf(stderr, "   --endian         Load an image with a different endianness\n");
      fprintf(stderr, "   --shrink         Shrink the image to the current heap size when saving\n");
      fprintf(stderr, "   --with [file]    Treat [file] as an input source\n");
      fprintf(stderr, "   --opstats [file] Write statistics about VM operations to [file]\n");
      fprintf(stderr, "      --callstats      Include how many times each address is called (slow)\n");
      fprintf(stderr, "                       Also includes distribution of stack depths.\n");
      exit(0);
    }
    else if ((strcmp(argv[i], "--about") == 0) ||
             (strcmp(argv[i], "--version") == 0))
    {
      fprintf(stderr, "Retro Language  [VM: C, console]\n\n");
      exit(0);
    }
    else
    {
      strcpy(vm->filename, argv[i]);
    }
  }

  dev_init(OUTPUT);

  a = vm_load_image(vm, vm->filename);
  if (a == -1)
  {
    dev_cleanup();
    printf("Sorry, unable to find %s\n", vm->filename);
    exit(1);
  }

  /* Swap endian if --endian was passed */
  if (endian == -1)
    swapEndian(vm);

  /* Process the image */
  if (opstats == 0)
  {
    for (vm->ip = 0; vm->ip < IMAGE_SIZE; vm->ip++)
      vm_process(vm);
  }
  else
  {
    for (vm->ip = 0; vm->ip < IMAGE_SIZE; vm->ip++)
    {
      collect_stats(vm);
      vm_process(vm);
    }
    report_stats(opstats);
  }

  /* Once done, cleanup */
  dev_cleanup();
  return 0;
}
示例#4
0
文件: ngaro.c 项目: js4/ngaro
/******************************************************
 *|F| int main(int argc, char **argv)
 ******************************************************/
int main(int argc, char **argv)
{
  int a, i, trace, endian;

  printf("Video @ %i\n", VIDEO_BASE);

  trace = 0;
  endian = 0;

  strcpy(vm.filename, "retroImage");

  init_vm();
  init_devices();

  vm.shrink = 0;

  /* Parse the command line arguments */
  for (i = 1; i < argc; i++)
  {
    if (strcmp(argv[i], "--trace") == 0)
    {
      trace = 1;
    }
    else if (strcmp(argv[i], "--endian") == 0)
    {
      endian = 1;
    }
    else if (strcmp(argv[i], "--shrink") == 0)
    {
      vm.shrink = 1;
    }
    else if (strcmp(argv[i], "--help") == 0)
    {
      fprintf(stderr, "%s [options] [imagename]\n", argv[0]);
      fprintf(stderr, "Valid options are:\n");
      fprintf(stderr, "   --trace    Execution trace\n");
      fprintf(stderr, "   --endian   Load an image with a different endianness\n");
      fprintf(stderr, "   --shrink   Only save used heap during save operation\n");
      exit(0);
    }
    else
    {
      strcpy(vm.filename, argv[i]);
    }
  }


  /* Load the image */
  a = vm_load_image(vm.filename);

  /* Swap endian if --endian was passed */
  if (endian == 1)
    swapEndian();


  /* Process the image */
  if (trace == 0)
  {
    for (vm.ip = 0; vm.ip < IMAGE_SIZE; vm.ip++)
    {
      vm_process(vm.image[vm.ip]);
      update_display(0);
    }
  }
  else
  {
    for (vm.ip = 0; vm.ip < IMAGE_SIZE; vm.ip++)
    {
      display_instruction();
      vm_process(vm.image[vm.ip]);
      update_display(0);
    }
  }

  /* Once done, cleanup */
  cleanup_devices();
  return 0;
}