X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=src%2Fcomet2.c;h=f358ec110a5a80153fd931768c65431b814bc23e;hp=42ba4babf3c3ecea61d8dcd001533766aece35dc;hb=HEAD;hpb=1708c99d4b6263863304d48ebca3b3473d6a0112 diff --git a/src/comet2.c b/src/comet2.c index 42ba4ba..f358ec1 100644 --- a/src/comet2.c +++ b/src/comet2.c @@ -1,12 +1,6 @@ -#include -#include -#define _GNU_SOURCE -#include - -#include "exec.h" -#include "cmem.h" -#include "cerr.h" #include "package.h" +#include "exec.h" +#include "load.h" /** * comet2コマンドのオプション @@ -16,13 +10,15 @@ 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' }, + {"version", no_argument, NULL, 'v' }, {"help", no_argument, NULL, 'h'}, {0, 0, 0, 0}, }; + /** * @brief comet2コマンドのメイン * @@ -33,17 +29,21 @@ static struct option longopts[] = { */ int main(int argc, char *argv[]) { - int memsize = DEFAULT_MEMSIZE, clocks = DEFAULT_CLOCKS; - int opt, stat = 0; - const char *version = PACKAGE_VERSION, *cmdversion = "comet2 of YACASL2 version %s\n"; - const char *usage = "Usage: %s [-tTdvh] [-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:vh", longopts, NULL)) != -1) { + while((opt = getopt_long(argc, argv, "tTdmM:C:vh", longopts, NULL)) != -1) { switch(opt) { case 't': execmode.trace = true; @@ -55,6 +55,9 @@ int main(int argc, char *argv[]) case 'd': execmode.dump = true; break; + case 'm': + execmode.monitor = true; + break; case 'M': memsize = atoi(optarg); break; @@ -63,30 +66,32 @@ int main(int argc, char *argv[]) break; case 'v': fprintf(stdout, cmdversion, version); - return 0; + 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, ""); /* 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) { - exec(); /* プログラム実行 */ + execptr->end = loadassemble(argv[optind], execptr->start); + if(execptr->end > 0 && cerr->num == 0) { + exec(); /* プログラム実行 */ + } + shutdown(); /* COMET II仮想マシンのシャットダウン */ +comet2fin: + if(cerr->num > 0) { + stat = 1; } - /* COMET II仮想マシンのシャットダウン */ - shutdown(); - stat = (cerr->num == 0) ? 0 : 1; - /* エラーの解放 */ - freecerr(); + freecerr(); /* エラーの解放 */ return stat; }