15 static struct option longopts[] = {
16 { "source", no_argument, NULL, 's' },
17 { "label", no_argument, NULL, 'l' },
18 { "labelonly", no_argument, NULL, 'L' },
19 { "assembledetail", no_argument, NULL, 'a' },
20 { "assembledetailonly", no_argument, NULL, 'A' },
21 { "assembleout", optional_argument, NULL, 'o' },
22 { "assembleoutonly", optional_argument, NULL, 'O' },
23 { "trace", no_argument, NULL, 't' },
24 { "tracearithmetic", no_argument, NULL, 't' },
25 { "tracelogical", no_argument, NULL, 'T' },
26 { "dump", no_argument, NULL, 'd' },
27 { "memorysize", required_argument, NULL, 'M' },
28 { "clocks", required_argument, NULL, 'C' },
29 { "help", no_argument, NULL, 'h' },
37 { 126, "no source file" },
41 * CASL IIのエラーをエラーリストに追加
43 void addcerrlist_casl2()
45 addcerrlist(ARRAYSIZE(cerr_casl2), cerr_casl2);
51 static const char *objfile_name(const char *str)
53 const char *default_name = "a.o";
54 return (str == NULL) ? default_name : str;
60 int main(int argc, char *argv[])
62 int memsize = DEFAULT_MEMSIZE, clocks = DEFAULT_CLOCKS;
63 int status = 0, opt, i;
69 "Usage: %s [-slLaAtTdh] [-oO[<OBJECTFILE>]] [-M <MEMORYSIZE>] [-C <CLOCKS>] FILE1[ FILE2 ...]\n";
73 addcerrlist_assemble();
76 while((opt = getopt_long(argc, argv, "tTdslLao::O::AM:C:h", longopts, NULL)) != -1) {
86 asmode.onlylabel = true;
89 asmode.asdetail = true;
92 asmode.asdetail = true;
93 asmode.onlyassemble = true;
96 objfile = strdup_chk(objfile_name(optarg), "objfile");
99 asmode.onlyassemble = true;
100 objfile = strdup_chk(objfile_name(optarg), "objfile");
103 execmode.trace = true;
106 execmode.trace = true;
107 execmode.logical = true;
110 execmode.dump = true;
113 memsize = atoi(optarg);
116 clocks = atoi(optarg);
119 fprintf(stdout, usage, argv[0]);
122 fprintf(stderr, usage, argv[0]);
126 /* ソースファイルが指定されていない場合は終了 */
127 if(argv[optind] == NULL) {
128 setcerr(126, NULL); /* no source file */
129 fprintf(stderr, "CASL2 error - %d: %s\n", cerr->num, cerr->msg);
132 /* COMET II仮想マシンのリセット */
133 reset(memsize, clocks);
134 /* アセンブル。ラベル表作成のため、2回行う */
135 for(pass = FIRST; pass <= SECOND; pass++) {
137 create_cmdtype_code(); /* 命令の名前とタイプがキーのハッシュ表を作成 */
138 asptr = malloc_chk(sizeof(ASPTR), "asptr"); /* アセンブル時のプロパティ用の領域確保 */
140 for(i = optind; i < argc; i++) {
143 beginptr[i] = asptr->ptr;
144 } else if(pass == SECOND) {
145 asptr->ptr = beginptr[i];
147 if(execmode.trace == true || execmode.dump == true || asmode.src == true ||
148 asmode.label == true || asmode.asdetail == true)
150 fprintf(stdout, "\nAssemble %s (%d)\n", argv[i], pass);
152 if((res = assemble(argv[i], pass)) == false) {
153 freecerr(); /* エラーの解放 */
157 if(pass == FIRST && asmode.label == true) {
158 fprintf(stdout, "\nLabel::::\n");
160 if(asmode.onlylabel == true) {
165 freelabel(); /* ラベルハッシュ表を解放 */
166 free_cmdtype_code(); /* 命令の名前とタイプがキーのハッシュ表を解放 */
167 FREE(asptr); /* アセンブル時のプロパティを解放 */
171 if(objfile != NULL) {
172 outassemble(objfile);
175 if(asmode.onlyassemble == false) {
176 create_code_type(); /* 命令のコードとタイプがキーのハッシュ表を作成 */
177 res = exec(); /* プログラム実行 */
178 free_code_type(); /* 命令のコードとタイプがキーのハッシュ表を解放 */
181 /* COMET II仮想マシンのシャットダウン */
186 freecerr(); /* エラーの解放 */