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"); /* アセンブル時のプロパティ用の領域確保 */
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 if(assemblefile(filev[i], pass) == false) {
86 if(pass == FIRST && asmode.label == true) {
87 fprintf(stdout, "\nLabel::::\n");
89 if(asmode.onlylabel == true) {
95 freelabel(); /* ラベルハッシュ表を解放 */
96 free_cmdtype_code(); /* 命令の名前とタイプがキーのハッシュ表を解放 */
97 FREE(asptr); /* アセンブル時のプロパティを解放 */
103 int main(int argc, char *argv[])
105 int memsize = DEFAULT_MEMSIZE, clocks = DEFAULT_CLOCKS, opt, i, status;
107 char *objfile = NULL;
109 "Usage: %s [-slLaAtTdh] [-oO[<OBJECTFILE>]] [-M <MEMORYSIZE>] [-C <CLOCKS>] FILE1[ FILE2 ...]\n";
113 addcerrlist_assemble();
116 while((opt = getopt_long(argc, argv, "tTdslLao::O::AM:C:h", longopts, NULL)) != -1) {
126 asmode.onlylabel = true;
129 asmode.asdetail = true;
132 asmode.asdetail = true;
133 asmode.onlyassemble = true;
136 objfile = strdup_chk(objfile_name(optarg), "objfile");
139 asmode.onlyassemble = true;
140 objfile = strdup_chk(objfile_name(optarg), "objfile");
143 execmode.trace = true;
146 execmode.trace = true;
147 execmode.logical = true;
150 execmode.dump = true;
153 memsize = atoi(optarg);
156 clocks = atoi(optarg);
159 fprintf(stdout, usage, argv[0]);
162 fprintf(stderr, usage, argv[0]);
166 /* ソースファイルが指定されていない場合は終了 */
167 if(argv[optind] == NULL) {
168 setcerr(126, NULL); /* no source file */
169 fprintf(stderr, "CASL2 error - %d: %s\n", cerr->num, cerr->msg);
172 reset(memsize, clocks); /* 仮想マシンCOMET IIのリセット */
173 for(i = 0; i < argc - optind; i++) { /* 引数からファイル名配列を取得 */
174 af[i] = argv[optind + i];
176 assemble(i, af); /* アセンブル */
177 if(asmode.onlylabel == true || cerr->num > 0) {
180 /* オブジェクトファイル名が指定されている場合は、アセンブル結果をオブジェクトファイルに出力 */
181 if(objfile != NULL) {
182 outassemble(objfile);
185 /* onlyassembleモード以外の場合、仮想マシンCOMET IIを実行 */
186 if(asmode.onlyassemble == false) {
187 exec(); /* 仮想マシンCOMET IIの実行 */
190 shutdown(); /* 仮想マシンCOMET IIのシャットダウン */
191 status = (cerr->num == 0) ? 0 : -1;
192 freecerr(); /* エラーの解放 */