X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=src%2Fcomet2.c;h=47f0b0bd65c5827a5347b05f45f17e73fc4ef93b;hp=c61299507b1a7cf172f456a8f1cb4128a087ee50;hb=a639337a9aa30a059c1695ab1701b8714fd26193;hpb=5a84169c51f754a58929ce360e9e1a358e0ca74e diff --git a/src/comet2.c b/src/comet2.c index c612995..47f0b0b 100644 --- a/src/comet2.c +++ b/src/comet2.c @@ -1,9 +1,15 @@ -#include "casl2.h" -#include "exec.h" +#include +#include #define _GNU_SOURCE #include -/* 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'}, @@ -15,50 +21,38 @@ static struct option longopts[] = { {0, 0, 0, 0} }; -/* 実行モード: trace, logical, dump */ -EXECMODE execmode = {false, false, false}; - -/* エラー番号とエラーメッセージ */ -CERRARRAY cerr[] = { - { 201, "execute - out of COMET II memory" }, - { 202, "SVC input - out of Input memory" }, - { 203, "SVC output - out of COMET II memory" }, - { 204, "Program Register (PR) - out of COMET II memory" }, - { 205, "Stack Pointer (SP) - cannot allocate stack buffer" }, - { 206, "Address - out of COMET II memory" }, - { 207, "Stack Pointer (SP) - out of COMET II memory" }, - { 0, NULL }, +/** + * comet2コマンドのエラー + */ +static CERR cerr_comet2[] = { + { 208, "object file is not specified" }, }; -/* 指定されたファイルからアセンブル結果を読込 */ -bool loadassemble(char *file) { - FILE *fp; - if((fp = fopen(file, "r")) == NULL) { - perror(file); - return false; - } - endptr = startptr + fread(memory, sizeof(WORD), memsize, fp); - fclose(fp); - return true; -} - -/* comet2コマンド */ +/** + * comet2コマンドのメイン + */ int main(int argc, char *argv[]) { - int opt; - const char *usage = "Usage: %s [-tTdh] [-M ] [-C ] FILE\n"; + int memsize = DEFAULT_MEMSIZE, clocks = DEFAULT_CLOCKS; + int opt, status = 0; + const char *usage = "Usage: %s [-tTdh] [-M ] [-C ] FILE\n"; + + cerr_init(); + addcerrlist(ARRAYSIZE(cerr_comet2), cerr_comet2); + addcerrlist_exec(); + /* オプションの処理 */ while((opt = getopt_long(argc, argv, "tTdM:C:h", longopts, NULL)) != -1) { switch(opt) { 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); @@ -74,14 +68,25 @@ int main(int argc, char *argv[]) exit(-1); } } - reset(); - startptr = 0; + if(argv[optind] == NULL) { + setcerr(208, NULL); /* object file is not specified */ + fprintf(stderr, "comet2 error - %d: %s\n", cerr->num, cerr->msg); + exit(-1); + } + /* COMET II仮想マシンのリセット */ + reset(memsize, clocks); + execptr->start = 0; if(loadassemble(argv[optind]) == true) { - exec(); /* プログラム実行 */ + create_code_type(); /* タイプがキーの命令ハッシュ表を作成 */ + exec(); /* プログラム実行 */ + free_code_type(); /* タイプがキーの命令ハッシュ表を解放 */ } - if(cerrno > 0) { - freecerr(); - exit(-1); + /* COMET II仮想マシンのシャットダウン */ + shutdown(); + if(cerr->num > 0) { + status = -1; } - return 0; + /* エラーの解放 */ + freecerr(); + return status; }