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'},
28 { 101, "label already defined" },
29 { 102, "label table is full" },
30 { 103, "label not found" },
31 { 104, "label length is too long" },
32 { 105, "no command in the line" },
33 { 106, "operand mismatch in assemble command" },
34 { 107, "no label in START" },
35 { 108, "not command of operand \"r\"" },
36 { 109, "not command of operand \"r1,r2\"" },
37 { 110, "not command of operand \"r,adr[,x]\"" },
38 { 111, "not command of operand \"adr[,x]\"" },
39 { 112, "not command of no operand" },
40 { 113, "operand too many in machine command" },
41 { 114, "not integer" },
43 { 116, "out of hex range" },
44 { 117, "operand too many in DC" },
45 { 118, "operand length too long" },
46 { 119, "out of COMET II memory" },
47 { 120, "GR0 in operand x" },
48 { 121, "cannot get operand token" },
49 { 122, "cannot create hash table" },
50 { 123, "unclosed quote" },
51 { 124, "more than one character in literal" },
52 { 125, "not GR in operand x" },
53 { 126, "source file is not specified" },
54 { 201, "execute - out of COMET II memory" },
55 { 202, "SVC input - out of Input memory" },
56 { 203, "SVC output - out of COMET II memory" },
57 { 204, "Program Register (PR) - out of COMET II memory" },
58 { 205, "Stack Pointer (SP) - cannot allocate stack buffer" },
59 { 206, "Address - out of COMET II memory" },
60 { 207, "Stack Pointer (SP) - out of COMET II memory" },
64 /* 指定されたファイルにアセンブル結果を書込 */
65 void outassemble(const char *file) {
67 if((fp = fopen(file, "w")) == NULL) {
71 fwrite(memory, sizeof(WORD), endptr, fp);
75 /* アセンブル結果を書き込むファイルの名前 */
76 const char *objfile_name(const char *str)
78 const char *default_name = "a.o";
88 int main(int argc, char *argv[])
96 "Usage: %s [-slLaAtTdh] [-oO<OUTFILE>] [-M <memorysize>] [-C <clocks>] FILE ...\n";
98 while((opt = getopt_long(argc, argv, "tTdslLao::O::AM:C:h", longopts, NULL)) != -1) {
108 asmode.onlylabel = true;
111 asmode.asdetail = true;
114 asmode.asdetail = true;
115 asmode.onlyassemble = true;
118 objfile = strdup(objfile_name(optarg));
121 asmode.onlyassemble = true;
122 objfile = strdup(objfile_name(optarg));
125 execmode.trace = true;
128 execmode.trace = true;
129 execmode.logical = true;
132 execmode.dump = true;
135 memsize = atoi(optarg);
138 clocks = atoi(optarg);
141 fprintf(stdout, usage, argv[0]);
144 fprintf(stderr, usage, argv[0]);
148 /* ソースファイルが指定されていない場合は終了 */
149 if(argv[optind] == NULL) {
150 setcerr(126, NULL); /* source file is not specified */
153 /* COMET II仮想マシンのリセット */
155 /* アセンブル。ラベル表作成のため、2回行う */
156 for(pass = FIRST; pass <= SECOND; pass++) {
157 if(pass == FIRST && create_cmdtype_code() == false) {
160 for(i = optind; i < argc; i++) {
164 } else if(pass == SECOND) {
167 if(execmode.trace == true || execmode.dump == true || asmode.src == true ||
168 asmode.label == true || asmode.asdetail == true)
170 fprintf(stdout, "\nAssemble %s (%d)\n", argv[i], pass);
172 if((status = assemble(argv[i], pass)) == false) {
176 if(pass == FIRST && asmode.label == true) {
177 fprintf(stdout, "\nLabel::::\n");
179 if(asmode.onlylabel == true) {
184 freelabel(); /* ラベル表の解放 */
186 if(objfile != NULL) {
187 outassemble(objfile);
189 if(asmode.onlyassemble == false) {
190 exec(); /* プログラム実行 */
199 fprintf(stderr, "Casl2 error - %d: %s\n", cerrno, cerrmsg);