projects
/
YACASL2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
ソースコードの推敲
[YACASL2.git]
/
src
/
comet2.c
diff --git
a/src/comet2.c
b/src/comet2.c
index
bb07c5f
..
b68b093
100644
(file)
--- a/
src/comet2.c
+++ b/
src/comet2.c
@@
-1,9
+1,15
@@
-#include
"casl2.h"
-#include
"exec.h"
+#include
<stdio.h>
+#include
<stdlib.h>
#define _GNU_SOURCE
#include <getopt.h>
#define _GNU_SOURCE
#include <getopt.h>
-/* comet2コマンドのオプション */
+#include "exec.h"
+#include "cmem.h"
+#include "cerr.h"
+
+/**
+ * comet2コマンドのオプション
+ */
static struct option longopts[] = {
{"trace", no_argument, NULL, 't'},
{"tracearithmetic", no_argument, NULL, 't'},
static struct option longopts[] = {
{"trace", no_argument, NULL, 't'},
{"tracearithmetic", no_argument, NULL, 't'},
@@
-12,44
+18,23
@@
static struct option longopts[] = {
{"memorysize", required_argument, NULL, 'M'},
{"clocks", required_argument, NULL, 'C'},
{"help", no_argument, NULL, 'h'},
{"memorysize", required_argument, NULL, 'M'},
{"clocks", required_argument, NULL, 'C'},
{"help", no_argument, NULL, 'h'},
- {0, 0, 0, 0}
-};
-
-/* comet2のエラー定義 */
-CERRARRAY cerr_comet2[] = {
- { 201, "Load object file - full of COMET II memory" },
- { 208, "object file is not specified" },
+ {0, 0, 0, 0},
};
};
-bool addcerrlist_comet2()
-{
- return addcerrlist(ARRAYSIZE(cerr_comet2), cerr_comet2);
-}
-
-/* 指定されたファイルからアセンブル結果を読込 */
-bool loadassemble(char *file) {
- FILE *fp;
- bool status = true;
- if((fp = fopen(file, "r")) == NULL) {
- perror(file);
- return false;
- }
- if((endptr = startptr + fread(memory, sizeof(WORD), memsize-startptr, fp)) == memsize) {
- setcerr(201, NULL); /* Load object file - full of COMET II memory */
- fprintf(stderr, "Execute error - %d: %s\n", cerrno, cerrmsg);
- status = false;
- }
- fclose(fp);
- return status;
-}
-
-/* comet2コマンド */
+/**
+ * comet2コマンドのメイン
+ */
int main(int argc, char *argv[])
{
int main(int argc, char *argv[])
{
- int opt;
+ int memsize = DEFAULT_MEMSIZE, clocks = DEFAULT_CLOCKS;
+ int opt, status = 0;
const char *usage = "Usage: %s [-tTdh] [-M <MEMORYSIZE>] [-C <CLOCKS>] FILE\n";
const char *usage = "Usage: %s [-tTdh] [-M <MEMORYSIZE>] [-C <CLOCKS>] FILE\n";
- addcerrlist_comet2();
+ cerr_init();
+ addcerrlist_load();
+ addcerrlist_exec();
+
+ /* オプションの処理 */
while((opt = getopt_long(argc, argv, "tTdM:C:h", longopts, NULL)) != -1) {
switch(opt) {
case 't':
while((opt = getopt_long(argc, argv, "tTdM:C:h", longopts, NULL)) != -1) {
switch(opt) {
case 't':
@@
-78,19
+63,23
@@
int main(int argc, char *argv[])
}
if(argv[optind] == NULL) {
setcerr(208, NULL); /* object file is not specified */
}
if(argv[optind] == NULL) {
setcerr(208, NULL); /* object file is not specified */
- fprintf(stderr, "comet2 error - %d: %s\n", cerr
no, cerr
msg);
-
goto comet2err
;
+ fprintf(stderr, "comet2 error - %d: %s\n", cerr
->num, cerr->
msg);
+
exit(-1)
;
}
}
- reset();
- startptr = 0;
+ /* COMET II仮想マシンのリセット */
+ reset(memsize, clocks);
+ execptr->start = 0;
if(loadassemble(argv[optind]) == true) {
if(loadassemble(argv[optind]) == true) {
- exec(); /* プログラム実行 */
+ create_code_type(); /* タイプがキーの命令ハッシュ表を作成 */
+ exec(); /* プログラム実行 */
+ free_code_type(); /* タイプがキーの命令ハッシュ表を解放 */
}
}
- if(cerrno > 0) {
- goto comet2err;
+ /* COMET II仮想マシンのシャットダウン */
+ shutdown();
+ if(cerr->num > 0) {
+ status = -1;
}
}
- return 0;
-comet2err:
+ /* エラーの解放 */
freecerr();
freecerr();
-
exit(-1)
;
+
return status
;
}
}