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 const char *objfile_name(const char *str)
53 const char *default_name = "a.o";
54 return (str == NULL) ? default_name : str;
58 * 指定された1つまたは複数のファイルを2回アセンブル
60 void assemble(int filec, char *filev[])
66 create_cmdtype_code(); /* 命令の名前とタイプがキーのハッシュ表を作成 */
67 asptr = malloc_chk(sizeof(ASPTR), "asptr"); /* アセンブル時のプロパティ用の領域確保 */
69 /* アセンブル。ラベル表作成のため、2回行う */
70 for(pass = FIRST; pass <= SECOND; pass++) {
71 for(i = 0; i < filec; i++) {
75 } else if(pass == SECOND) {
78 if(execmode.trace == true || execmode.dump == true ||
79 asmode.src == true || asmode.label == true || asmode.asdetail == true)
81 fprintf(stdout, "\nAssemble %s (%d)\n", filev[i], pass);
84 if(assemblefile(filev[i], pass) == false) {
88 if(pass == FIRST && asmode.label == true) {
89 fprintf(stdout, "\nLabel::::\n");
91 if(asmode.onlylabel == true) {
97 freelabel(); /* ラベルハッシュ表を解放 */
98 free_cmdtype_code(); /* 命令の名前とタイプがキーのハッシュ表を解放 */
99 FREE(asptr); /* アセンブル時のプロパティを解放 */
105 int main(int argc, char *argv[])
107 int memsize = DEFAULT_MEMSIZE, clocks = DEFAULT_CLOCKS, opt, i, status;
109 char *objfile = NULL;
111 "Usage: %s [-slLaAtTdh] [-oO[<OBJECTFILE>]] [-M <MEMORYSIZE>] [-C <CLOCKS>] FILE1[ FILE2 ...]\n";
115 addcerrlist_assemble();
118 while((opt = getopt_long(argc, argv, "tTdslLao::O::AM:C:h", longopts, NULL)) != -1) {
128 asmode.onlylabel = true;
131 asmode.asdetail = true;
134 asmode.asdetail = true;
135 asmode.onlyassemble = true;
138 objfile = strdup_chk(objfile_name(optarg), "objfile");
141 asmode.onlyassemble = true;
142 objfile = strdup_chk(objfile_name(optarg), "objfile");
145 execmode.trace = true;
148 execmode.trace = true;
149 execmode.logical = true;
152 execmode.dump = true;
155 memsize = atoi(optarg);
158 clocks = atoi(optarg);
161 fprintf(stdout, usage, argv[0]);
164 fprintf(stderr, usage, argv[0]);
168 /* ソースファイルが指定されていない場合は終了 */
169 if(argv[optind] == NULL) {
170 setcerr(126, NULL); /* no source file */
171 fprintf(stderr, "CASL2 error - %d: %s\n", cerr->num, cerr->msg);
174 reset(memsize, clocks); /* 仮想マシンCOMET IIのリセット */
175 for(i = 0; i < argc - optind; i++) { /* 引数からファイル名配列を取得 */
176 af[i] = argv[optind + i];
178 assemble(i, af); /* アセンブル */
179 if(asmode.onlylabel == true || cerr->num > 0) {
182 /* オブジェクトファイル名が指定されている場合は、アセンブル結果をオブジェクトファイルに出力 */
183 if(objfile != NULL) {
184 outassemble(objfile);
187 /* onlyassembleモード以外の場合、仮想マシンCOMET IIを実行 */
188 if(asmode.onlyassemble == false) {
189 exec(); /* 仮想マシンCOMET IIの実行 */
192 shutdown(); /* 仮想マシンCOMET IIのシャットダウン */
193 status = (cerr->num == 0) ? 0 : -1;
194 freecerr(); /* エラーの解放 */