root/src/comet2monitor.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. addcerrlist_comet2monitor
  2. main

   1 #define _GNU_SOURCE
   2 #include "package.h"
   3 #include "exec.h"
   4 #include "load.h"
   5 #include "monitor.h"
   6 
   7 /**
   8  * comet2monitorコマンドのオプション
   9  */
  10 static struct option longopts[] = {
  11     {"trace", no_argument, NULL, 't'},
  12     {"tracearithmetic", no_argument, NULL, 't'},
  13     {"tracelogical", no_argument, NULL, 'T'},
  14     {"dump", no_argument, NULL, 'd'},
  15     {"memorysize", required_argument, NULL, 'M'},
  16     {"clocks", required_argument, NULL, 'C'},
  17     {"version", no_argument, NULL, 'v' },
  18     {"help", no_argument, NULL, 'h'},
  19     {0, 0, 0, 0},
  20 };
  21 
  22 /**
  23  * @brief casl2のエラー定義
  24  */
  25 CERR cerr_comet2monitor[] = {
  26     { 401, "invalid option" },
  27 };
  28 
  29 void addcerrlist_comet2monitor()
  30 {
  31     addcerrlist(ARRAYSIZE(cerr_comet2monitor), cerr_comet2monitor);
  32 }
  33 
  34 /**
  35  * @brief comet2monitorコマンドのメイン
  36  *
  37  * @return 正常終了時は0、異常終了時は1
  38  *
  39  * @param argc コマンドライン引数の数
  40  * @param *argv[] コマンドライン引数の配列
  41  */
  42 int main(int argc, char *argv[])
  43 {
  44     int memsize = DEFAULT_MEMSIZE;
  45     int clocks = DEFAULT_CLOCKS;
  46     int opt = 0;
  47     int stat = 0;
  48     const char *version = PACKAGE_VERSION;
  49     const char *cmdversion = "comet2monitor: COMET II machine code monitor of YACASL2 version %s\n";
  50     const char *usage = "Usage: %s [-tTdvh] [-M <MEMORYSIZE>] [-C <CLOCKS>] FILE\n";
  51 
  52     /* エラーの定義 */
  53     cerr_init();
  54     addcerrlist_load();
  55     addcerrlist_exec();
  56     addcerrlist_comet2monitor();
  57 
  58     /* オプションの処理 */
  59     while((opt = getopt_long(argc, argv, "tTdM:C:vh", longopts, NULL)) != -1) {
  60         switch(opt) {
  61         case 't':
  62             execmode.trace = true;
  63             break;
  64         case 'T':
  65             execmode.trace = true;
  66             execmode.logical = true;
  67             break;
  68         case 'd':
  69             execmode.dump = true;
  70             break;
  71         case 'M':
  72             if((memsize = memsize_str2word(optarg)) == 0) {
  73                 goto comet2monitorfin;
  74             }
  75             break;
  76         case 'C':
  77             if((clocks = clock_str2clock(optarg)) == 0) {
  78                 goto comet2monitorfin;
  79             }
  80             break;
  81         case 'v':
  82             fprintf(stdout, cmdversion, version);
  83             return 0;
  84         case 'h':
  85             fprintf(stdout, usage, argv[0]);
  86             return 0;
  87         case '?':
  88             fprintf(stderr, usage, argv[0]);
  89             setcerr(212, "");    /* invalid option */
  90             goto comet2monitorfin;
  91         }
  92     }
  93     create_cmdtable(HASH_CMDTYPE);
  94     comet2_init(memsize, clocks);     /* COMET II仮想マシンの初期化 */
  95     execptr->start = 0;
  96     if(argv[optind] != NULL) {
  97         execptr->end = loadassemble(argv[optind++], execptr->start);
  98     }
  99     /* 残りの引数(オプション以外の引数)があるかチェック */
 100     if (optind < argc) {
 101         warn_ignore_arg(argc - optind, argv + optind);
 102     }
 103     execmode.monitor = true;
 104     exec();                     /* プログラム実行 */
 105     comet2_shutdown();
 106 comet2monitorfin:
 107     free_cmdtable(HASH_CMDTYPE);
 108     if(cerr->num > 0) {
 109         stat = 1;
 110     }
 111     freecerr();                 /* エラーの解放 */
 112     return stat;
 113 }

/* [<][>][^][v][top][bottom][index][help] */