X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=src%2Fcomet2.c;h=f358ec110a5a80153fd931768c65431b814bc23e;hp=af4bfb84d1a6e3d535b51fac05c87ccb02c71116;hb=HEAD;hpb=72c8f26e688864051d3a79897fe6748c3f65503c diff --git a/src/comet2.c b/src/comet2.c index af4bfb8..f358ec1 100644 --- a/src/comet2.c +++ b/src/comet2.c @@ -1,11 +1,6 @@ -#include -#include -#define _GNU_SOURCE -#include - +#include "package.h" #include "exec.h" -#include "cmem.h" -#include "cerr.h" +#include "load.h" /** * comet2コマンドのオプション @@ -15,27 +10,40 @@ static struct option longopts[] = { {"tracearithmetic", no_argument, NULL, 't'}, {"tracelogical", no_argument, NULL, 'T'}, {"dump", no_argument, NULL, 'd'}, + {"monitor", no_argument, NULL, 'm'}, {"memorysize", required_argument, NULL, 'M'}, {"clocks", required_argument, NULL, 'C'}, + {"version", no_argument, NULL, 'v' }, {"help", no_argument, NULL, 'h'}, {0, 0, 0, 0}, }; + /** - * comet2コマンドのメイン + * @brief comet2コマンドのメイン + * + * @return 正常終了時は0、異常終了時は1 + * + * @param argc コマンドライン引数の数 + * @param *argv[] コマンドライン引数の配列 */ int main(int argc, char *argv[]) { - int memsize = DEFAULT_MEMSIZE, clocks = DEFAULT_CLOCKS; - int opt, status = 0; - const char *usage = "Usage: %s [-tTdh] [-M ] [-C ] FILE\n"; + int memsize = DEFAULT_MEMSIZE; + int clocks = DEFAULT_CLOCKS; + int opt = 0; + int stat = 0; + const char *version = PACKAGE_VERSION; + const char *cmdversion = "comet2 of YACASL2 version %s\n"; + const char *usage = "Usage: %s [-tTdmvh] [-M ] [-C ] FILE\n"; + /* エラーの定義 */ cerr_init(); addcerrlist_load(); addcerrlist_exec(); /* オプションの処理 */ - while((opt = getopt_long(argc, argv, "tTdM:C:h", longopts, NULL)) != -1) { + while((opt = getopt_long(argc, argv, "tTdmM:C:vh", longopts, NULL)) != -1) { switch(opt) { case 't': execmode.trace = true; @@ -47,39 +55,43 @@ int main(int argc, char *argv[]) case 'd': execmode.dump = true; break; + case 'm': + execmode.monitor = true; + break; case 'M': memsize = atoi(optarg); break; case 'C': clocks = atoi(optarg); break; + case 'v': + fprintf(stdout, cmdversion, version); + goto comet2fin; case 'h': fprintf(stdout, usage, argv[0]); - return 0; + goto comet2fin; case '?': fprintf(stderr, usage, argv[0]); - exit(-1); + setcerr(212, ""); /* invalid option */ + goto comet2fin; } } if(argv[optind] == NULL) { - setcerr(211, NULL); /* object file not specified */ + setcerr(211, ""); /* object file not specified */ fprintf(stderr, "comet2 error - %d: %s\n", cerr->num, cerr->msg); - exit(-1); + goto comet2fin; } - /* COMET II仮想マシンのリセット */ - reset(memsize, clocks); + reset(memsize, clocks); /* COMET II仮想マシンのリセット */ execptr->start = 0; - if(loadassemble(argv[optind]) == true) { - create_code_type(); /* タイプがキーの命令ハッシュ表を作成 */ - exec(); /* プログラム実行 */ - free_code_type(); /* タイプがキーの命令ハッシュ表を解放 */ + execptr->end = loadassemble(argv[optind], execptr->start); + if(execptr->end > 0 && cerr->num == 0) { + exec(); /* プログラム実行 */ } - /* COMET II仮想マシンのシャットダウン */ - shutdown(); + shutdown(); /* COMET II仮想マシンのシャットダウン */ +comet2fin: if(cerr->num > 0) { - status = -1; + stat = 1; } - /* エラーの解放 */ - freecerr(); - return status; + freecerr(); /* エラーの解放 */ + return stat; }