root/src/comet2monitor.c

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

DEFINITIONS

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

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

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