7 static struct option longopts[] = {
8 {"trace", no_argument, NULL, 't'},
9 {"tracearithmetic", no_argument, NULL, 't'},
10 {"tracelogical", no_argument, NULL, 'T'},
11 {"dump", no_argument, NULL, 'd'},
12 {"memorysize", required_argument, NULL, 'M'},
13 {"clocks", required_argument, NULL, 'C'},
14 {"help", no_argument, NULL, 'h'},
19 CERR cerr_comet2[] = {
20 { 201, "load object file - full of COMET II memory" },
21 { 208, "object file is not specified" },
23 bool addcerrlist_comet2()
25 return addcerrlist(ARRAYSIZE(cerr_comet2), cerr_comet2);
28 /* 指定されたファイルからアセンブル結果を読込 */
29 bool loadassemble(char *file) {
33 if((fp = fopen(file, "r")) == NULL) {
37 progprop->end = progprop->start +
38 fread(memory, sizeof(WORD), memsize-progprop->start, fp);
39 if(progprop->end == memsize) {
40 setcerr(201, NULL); /* Load object file - full of COMET II memory */
41 fprintf(stderr, "Execute error - %d: %s\n", cerr->num, cerr->msg);
49 int main(int argc, char *argv[])
52 const char *usage = "Usage: %s [-tTdh] [-M <MEMORYSIZE>] [-C <CLOCKS>] FILE\n";
55 cerr = malloc_chk(sizeof(CERR), "cerr");
58 while((opt = getopt_long(argc, argv, "tTdM:C:h", longopts, NULL)) != -1) {
61 execmode.trace = true;
64 execmode.trace = true;
65 execmode.logical = true;
71 memsize = atoi(optarg);
74 clocks = atoi(optarg);
77 fprintf(stdout, usage, argv[0]);
80 fprintf(stderr, usage, argv[0]);
84 if(argv[optind] == NULL) {
85 setcerr(208, NULL); /* object file is not specified */
86 fprintf(stderr, "comet2 error - %d: %s\n", cerr->num, cerr->msg);
91 if(loadassemble(argv[optind]) == true) {
92 create_code_type(); /* 命令と命令タイプがキーのハッシュ表を作成 */
94 free_code_type(); /* 命令と命令タイプがキーのハッシュ表を解放 */
96 /* COMET II仮想マシンのシャットダウン */