8 static struct option longopts[] = {
9 {"source", no_argument, NULL, 's'},
10 {"label", no_argument, NULL, 'l'},
11 {"labelonly", no_argument, NULL, 'L'},
12 {"assembledetail", no_argument, NULL, 'a'},
13 {"assembledetailonly", no_argument, NULL, 'A'},
14 {"assembleout", optional_argument, NULL, 'o'},
15 {"assembleoutonly", optional_argument, NULL, 'O'},
16 {"trace", no_argument, NULL, 't'},
17 {"tracearithmetic", no_argument, NULL, 't'},
18 {"tracelogical", no_argument, NULL, 'T'},
19 {"dump", no_argument, NULL, 'd'},
20 {"memorysize", required_argument, NULL, 'M'},
21 {"clocks", required_argument, NULL, 'C'},
22 {"help", no_argument, NULL, 'h'},
27 CERRARRAY cerr_casl2[] = {
28 { 126, "source file is not specified" },
30 bool addcerrlist_casl2()
32 return addcerrlist_casl2(ARRAYSIZE(cerr_casl2), cerr_casl2);
35 /* 指定されたファイルにアセンブル結果を書込 */
36 void outassemble(const char *file) {
38 if((fp = fopen(file, "w")) == NULL) {
42 fwrite(memory, sizeof(WORD), endptr, fp);
46 /* アセンブル結果を書き込むファイルの名前 */
47 const char *objfile_name(const char *str)
49 const char *default_name = "a.o";
59 int main(int argc, char *argv[])
67 "Usage: %s [-slLaAtTdh] [-oO<OBJECTFILE>] [-M <MEMORYSIZE>] [-C <CLOCKS>] FILE ...\n";
69 while((opt = getopt_long(argc, argv, "tTdslLao::O::AM:C:h", longopts, NULL)) != -1) {
79 asmode.onlylabel = true;
82 asmode.asdetail = true;
85 asmode.asdetail = true;
86 asmode.onlyassemble = true;
89 objfile = strdup(objfile_name(optarg));
92 asmode.onlyassemble = true;
93 objfile = strdup(objfile_name(optarg));
96 execmode.trace = true;
99 execmode.trace = true;
100 execmode.logical = true;
103 execmode.dump = true;
106 memsize = atoi(optarg);
109 clocks = atoi(optarg);
112 fprintf(stdout, usage, argv[0]);
115 fprintf(stderr, usage, argv[0]);
123 /* ソースファイルが指定されていない場合は終了 */
124 if(argv[optind] == NULL) {
125 setcerr(126, NULL); /* source file is not specified */
128 /* COMET II仮想マシンのリセット */
130 /* アセンブル。ラベル表作成のため、2回行う */
131 for(pass = FIRST; pass <= SECOND; pass++) {
132 if(pass == FIRST && create_cmdtype_code() == false) {
135 for(i = optind; i < argc; i++) {
139 } else if(pass == SECOND) {
142 if(execmode.trace == true || execmode.dump == true || asmode.src == true ||
143 asmode.label == true || asmode.asdetail == true)
145 fprintf(stdout, "\nAssemble %s (%d)\n", argv[i], pass);
147 if((status = assemble(argv[i], pass)) == false) {
151 if(pass == FIRST && asmode.label == true) {
152 fprintf(stdout, "\nLabel::::\n");
154 if(asmode.onlylabel == true) {
159 free_cmdtype_code(); /* 命令表の解放 */
160 freelabel(); /* ラベル表の解放 */
162 if(objfile != NULL) {
163 outassemble(objfile);
165 if(asmode.onlyassemble == false) {
166 exec(); /* プログラム実行 */
175 fprintf(stderr, "CASL2 error - %d: %s\n", cerrno, cerrmsg);