/* * sim_main - main simulator routine. This function is called from the * main() routine in the HCL file. */ int sim_main(int argc, char **argv) { int i; char c; char *myargv[MAXARGS]; /* Parse the command line arguments */ while ((c = getopt(argc, argv, "htgl:v:")) != -1) { switch(c) { case 'h': usage(argv[0]); break; case 'l': instr_limit = atoi(optarg); break; case 'v': verbosity = atoi(optarg); if (verbosity < 0 || verbosity > 2) { printf("Invalid verbosity %d\n", verbosity); usage(argv[0]); } break; case 't': do_check = TRUE; break; case 'g': gui_mode = TRUE; break; default: printf("Invalid option '%c'\n", c); usage(argv[0]); break; } } /* Do we have too many arguments? */ if (optind < argc - 1) { printf("Too many command line arguments:"); for (i = optind; i < argc; i++) printf(" %s", argv[i]); printf("\n"); usage(argv[0]); } /* The single unflagged argument should be the object file name */ object_filename = NULL; object_file = NULL; if (optind < argc) { object_filename = argv[optind]; object_file = fopen(object_filename, "r"); if (!object_file) { fprintf(stderr, "Couldn't open object file %s\n", object_filename); exit(1); } } /* Run the simulator in GUI mode (-g flag) */ if (gui_mode) { #ifndef HAS_GUI printf("To run in GUI mode, you must recompile with the HAS_GUI constant defined.\n"); exit(1); #endif// HAS_GUI /* In GUI mode, we must specify the object file on command line */ if (!object_file) { printf("Missing object file argument in GUI mode\n"); usage(argv[0]); } /* Build the command line for the GUI simulator */ for (i = 0; i < TKARGS; i++) { if ((myargv[i] = malloc(MAXBUF*sizeof(char))) == NULL) { perror("malloc error"); exit(1); } } strcpy(myargv[0], argv[0]); if (plusmode == 0) /* SEQ */ strcpy(myargv[1], "seq.tcl"); else strcpy(myargv[1], "seq+.tcl"); strcpy(myargv[2], object_filename); myargv[3] = NULL; /* Start the GUI simulator */ #ifdef HAS_GUI Tk_Main(TKARGS, myargv, Tcl_AppInit); #endif// HAS_GUI exit(0); } /* Otherwise, run the simulator in TTY mode (no -g flag) */ run_tty_sim(); exit(0); }
/* * sim_main - main simulator routine. This function is called from the * main() routine in the HCL file. */ int sim_main(int argc, char **argv) { int i; int c; char *myargv[MAXARGS]; if (argc>2 && PSIM_ID!=-1){ //the maximum length of memory is 1000 PSIM_ID = atoi(argv[2]); argc-=1; } if(PSIM_ID == 1) START_PLACE = 1000; /* Parse the command line arguments */ while ((c = getopt(argc, argv, "htgl:v:")) != -1) { switch(c) { case 'h': usage(argv[0]); break; case 'l': instr_limit = atoi(optarg); break; case 'v': verbosity = atoi(optarg); if (verbosity < 0 || verbosity > 2) { printf("Invalid verbosity %d\n", verbosity); usage(argv[0]); } break; case 't': do_check = TRUE; break; case 'g': gui_mode = TRUE; break; default: printf("Invalid option '%c'\n", c); usage(argv[0]); break; } } /* Do we have too many arguments? */ if (optind < argc - 1) { printf("Too many command line arguments:"); for (i = optind; i < argc; i++) printf(" %s", argv[i]); printf("\n"); usage(argv[0]); } /* The single unflagged argument should be the object file name */ object_filename = NULL; object_file = NULL; if (optind < argc) { object_filename = argv[optind]; object_file = fopen(object_filename, "r"); if (!object_file) { fprintf(stderr, "Couldn't open object file %s\n", object_filename); exit(1); } } /* Otherwise, run the simulator in TTY mode (no -g flag) */ run_tty_sim(); exit(0); }