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;
60 void doassemble(int filec, char *filev[])
66 create_cmdtype_code(); /* 命令の名前とタイプがキーのハッシュ表を作成 */
67 asptr = malloc_chk(sizeof(ASPTR), "asptr"); /* アセンブル時のプロパティ用の領域確保 */
68 /* アセンブル。ラベル表作成のため、2回行う */
69 for(pass = FIRST; pass <= SECOND; pass++) {
70 for(i = 0; i < filec; i++) {
74 } else if(pass == SECOND) {
77 if(execmode.trace == true || execmode.dump == true || asmode.src == true ||
78 asmode.label == true || asmode.asdetail == true)
80 fprintf(stdout, "\nAssemble %s (%d)\n", filev[i], pass);
82 assemble(filev[i], pass);
87 if(pass == FIRST && asmode.label == true) {
88 fprintf(stdout, "\nLabel::::\n");
90 if(asmode.onlylabel == true) {
96 freelabel(); /* ラベルハッシュ表を解放 */
97 free_cmdtype_code(); /* 命令の名前とタイプがキーのハッシュ表を解放 */
98 FREE(asptr); /* アセンブル時のプロパティを解放 */
104 int main(int argc, char *argv[])
106 int memsize = DEFAULT_MEMSIZE, clocks = DEFAULT_CLOCKS, opt, i, status;
108 char *objfile = NULL;
110 "Usage: %s [-slLaAtTdh] [-oO[<OBJECTFILE>]] [-M <MEMORYSIZE>] [-C <CLOCKS>] FILE1[ FILE2 ...]\n";
114 addcerrlist_assemble();
117 while((opt = getopt_long(argc, argv, "tTdslLao::O::AM:C:h", longopts, NULL)) != -1) {
127 asmode.onlylabel = true;
130 asmode.asdetail = true;
133 asmode.asdetail = true;
134 asmode.onlyassemble = true;
137 objfile = strdup_chk(objfile_name(optarg), "objfile");
140 asmode.onlyassemble = true;
141 objfile = strdup_chk(objfile_name(optarg), "objfile");
144 execmode.trace = true;
147 execmode.trace = true;
148 execmode.logical = true;
151 execmode.dump = true;
154 memsize = atoi(optarg);
157 clocks = atoi(optarg);
160 fprintf(stdout, usage, argv[0]);
163 fprintf(stderr, usage, argv[0]);
167 /* ソースファイルが指定されていない場合は終了 */
168 if(argv[optind] == NULL) {
169 setcerr(126, NULL); /* no source file */
170 fprintf(stderr, "CASL2 error - %d: %s\n", cerr->num, cerr->msg);
173 reset(memsize, clocks); /* 仮想マシンCOMET IIのリセット */
174 for(i = 0; i < argc - optind; i++) { /* 引数からファイル名配列を取得 */
175 af[i] = argv[optind + i];
177 doassemble(i, af); /* アセンブル */
178 if(asmode.onlylabel == true || cerr->num > 0) {
181 /* オブジェクトファイル名が指定されている場合は、アセンブル結果をオブジェクトファイルに出力 */
182 if(objfile != NULL) {
183 outassemble(objfile);
186 /* onlyassembleモード以外の場合、仮想マシンCOMET IIを実行 */
187 if(asmode.onlyassemble == false) {
188 exec(); /* 仮想マシンCOMET IIの実行 */
191 shutdown(); /* 仮想マシンCOMET IIのシャットダウン */
192 status = (cerr->num == 0) ? 0 : -1;
193 freecerr(); /* エラーの解放 */