{ 123, "unclosed quote" },
{ 124, "more than one character in literal" },
{ 125, "not GR in operand x" },
+ { 126, "source file is not specified" },
{ 201, "execute - out of COMET II memory" },
{ 202, "SVC input - out of Input memory" },
{ 203, "SVC output - out of COMET II memory" },
while((opt = getopt_long(argc, argv, "tTdslLao::O::AM:C:h", longopts, NULL)) != -1) {
switch(opt) {
case 's':
- (&asmode)->src = true;
+ asmode.src = true;
break;
case 'l':
- (&asmode)->label = true;
+ asmode.label = true;
break;
case 'L':
- (&asmode)->label = true;
- (&asmode)->onlylabel = true;
+ asmode.label = true;
+ asmode.onlylabel = true;
break;
case 'a':
- (&asmode)->asdetail = true;
+ asmode.asdetail = true;
break;
case 'A':
- (&asmode)->asdetail = true;
- (&asmode)->onlyassemble = true;
+ asmode.asdetail = true;
+ asmode.onlyassemble = true;
break;
case 'o':
objfile = strdup(objfile_name(optarg));
break;
case 'O':
- (&asmode)->onlyassemble = true;
+ asmode.onlyassemble = true;
objfile = strdup(objfile_name(optarg));
break;
case 't':
- (&execmode)->trace = true;
+ execmode.trace = true;
break;
case 'T':
- (&execmode)->trace = true;
- (&execmode)->logical = true;
+ execmode.trace = true;
+ execmode.logical = true;
break;
case 'd':
- (&execmode)->dump = true;
+ execmode.dump = true;
break;
case 'M':
memsize = atoi(optarg);
}
/* ソースファイルが指定されていない場合は終了 */
if(argv[optind] == NULL) {
- fprintf(stderr, "source file is not specified\n");
- exit(-1);
+ setcerr(126, NULL); /* source file is not specified */
+ goto casl2err;
}
/* COMET II仮想マシンのリセット */
reset();
/* アセンブル。ラベル表作成のため、2回行う */
for(pass = FIRST; pass <= SECOND; pass++) {
+ if(pass == FIRST && create_cmdtype_code() == false) {
+ goto casl2err;
+ }
for(i = optind; i < argc; i++) {
/* データの格納開始位置 */
if(pass == FIRST) {
} else if(pass == SECOND) {
ptr = beginptr[i];
}
- if((&execmode)->trace == true || (&execmode)->dump == true ||
- (&asmode)->src == true || (&asmode)->label == true ||
- (&asmode)->asdetail == true)
+ if(execmode.trace == true || execmode.dump == true || asmode.src == true ||
+ asmode.label == true || asmode.asdetail == true)
{
fprintf(stdout, "\nAssemble %s (%d)\n", argv[i], pass);
}
if((status = assemble(argv[i], pass)) == false) {
- freelabel(); /* ラベル表の解放 */
- if(cerrno > 0) {
- freecerr(); /* エラーの解放 */
- }
exit(-1);
}
}
- if(pass == FIRST && (&asmode)->label == true) {
+ if(pass == FIRST && asmode.label == true) {
fprintf(stdout, "\nLabel::::\n");
printlabel();
- if((&asmode)->onlylabel == true) {
+ if(asmode.onlylabel == true) {
return 0;
}
}
if(objfile != NULL) {
outassemble(objfile);
}
- if((&asmode)->onlyassemble == false) {
+ if(asmode.onlyassemble == false) {
exec(); /* プログラム実行 */
}
}
exit(-1);
}
return 0;
+casl2err:
+ fprintf(stderr, "Casl2 error - %d: %s\n", cerrno, cerrmsg);
+ exit(-1);
}
};
int cmdcodesize = ARRAYSIZE(cmdcodearray);
-CMDCODETAB *cmdtype_code[ARRAYSIZE(cmdcodearray)], *code_type[ARRAYSIZE(cmdcodearray)];
+int hashtabsize;
+CMDCODETAB **cmdtype_code, **code_type;
/* 命令と命令タイプからハッシュ値を生成する */
unsigned hash_cmdtype(const char *cmd, CMDTYPE type) {
unsigned hashval;
int i;
+ hashtabsize = cmdcodesize;
+ cmdtype_code = malloc(cmdcodesize * sizeof(CMDCODETAB *));
for(i = 0; i < cmdcodesize; i++) {
- np = malloc(sizeof(CMDCODETAB *));
+ np = malloc(sizeof(CMDCODETAB));
if(np == NULL) {
setcerr(122, NULL); /* cannot create hash table */
return false;
unsigned hashval;
int i;
+ hashtabsize = cmdcodesize;
+ code_type = malloc(cmdcodesize * sizeof(CMDCODETAB *));
for(i = 0; i < cmdcodesize; i++) {
- if((np = malloc(sizeof(CMDCODETAB *))) == NULL) {
+ if((np = malloc(sizeof(CMDCODETAB))) == NULL) {
setcerr(122, NULL); /* cannot create hash table */
return false;
}
{
WORD op, r_r1, x_r2, val;
CMDTYPE cmdtype;
- char *errpr = malloc(8);
+ char *errpr = malloc(CERRSTRSIZE + 1);
clock_t clock_begin, clock_end;
if((&execmode)->trace) {
do {
clock_end = clock();
} while(clock_end - clock_begin < CLOCKS_PER_SEC / clocks);
-/* printf("PR:%04X; time: %f\n", PR, (double)((clock_end - clock_begin) * CLOCKS_PER_SEC)); */
+ #if 0
+ printf("PR:%04X; time: %f\n", PR, (double)((clock_end - clock_begin) * CLOCKS_PER_SEC));
+ #endif
}
execerr:
fprintf(stderr, "Execute error - %d: %s\n", cerrno, cerrmsg);