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

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