YACASL2
Loading...
Searching...
No Matches
comet2monitor.c
Go to the documentation of this file.
1#define _GNU_SOURCE
2#include "package.h"
3#include "exec.h"
4#include "load.h"
5#include "monitor.h"
6
10static 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 {"reverse", no_argument, NULL, 'r'},
16 {"memorysize", required_argument, NULL, 'M'},
17 {"clocks", required_argument, NULL, 'C'},
18 {"version", no_argument, NULL, 'v' },
19 {"help", no_argument, NULL, 'h'},
20 {0, 0, 0, 0},
21};
22
27 { 401, "invalid option" },
28};
29
34
43int main(int argc, char *argv[])
44{
45 int memsize = DEFAULT_MEMSIZE;
46 int clocks = DEFAULT_CLOCKS;
47 int opt = 0;
48 int stat = 0;
49 const char *version = PACKAGE_VERSION;
50 const char *cmdversion = "comet2monitor: COMET II machine code monitor of YACASL2 version %s\n";
51 const char *usage = "Usage: %s [-tTdrvh] [-M <MEMORYSIZE>] [-C <CLOCKS>] FILE\n";
52
53 /* エラーの定義 */
54 cerr_init();
58
59 execmode.reverse = true;
60 /* オプションの処理 */
61 while((opt = getopt_long(argc, argv, "tTdqM:C:vh", longopts, NULL)) != -1) {
62 switch(opt) {
63 case 't':
64 execmode.trace = true;
65 break;
66 case 'T':
67 execmode.trace = true;
68 execmode.logical = true;
69 break;
70 case 'd':
71 execmode.dump = true;
72 break;
73 case 'q':
74 execmode.reverse = false;
75 break;
76 case 'M':
77 if((memsize = memsize_str2word(optarg)) == 0) {
78 goto comet2monitorfin;
79 }
80 break;
81 case 'C':
82 if((clocks = clock_str2clock(optarg)) == 0) {
83 goto comet2monitorfin;
84 }
85 break;
86 case 'v':
87 fprintf(stdout, cmdversion, version);
88 return 0;
89 case 'h':
90 fprintf(stdout, usage, argv[0]);
91 return 0;
92 case '?':
93 fprintf(stderr, usage, argv[0]);
94 setcerr(212, ""); /* invalid option */
95 goto comet2monitorfin;
96 }
97 }
99 comet2_init(memsize, clocks); /* COMET II仮想マシンの初期化 */
100 execptr->start = 0;
101 if(argv[optind] != NULL) {
102 execptr->end = loadassemble(argv[optind++], execptr->start);
103 }
104 /* 残りの引数(オプション以外の引数)があるかチェック */
105 if (optind < argc) {
106 warn_ignore_arg(argc - optind, argv + optind);
107 }
108 execmode.monitor = true;
109 exec(); /* プログラム実行 */
111comet2monitorfin:
113 if(cerr->num > 0) {
114 stat = 1;
115 }
116 freecerr(); /* エラーの解放 */
117 return stat;
118}
static struct option longopts[]
casl2コマンドのオプション
Definition casl2.c:24
CERR * cerr
現在のエラー
Definition cerr.c:10
struct _CERR CERR
エラーを表すデータ型
void addcerrlist(int cerrc, CERR cerrv[])
エラーリストを作成・追加する
Definition cerr.c:14
void warn_ignore_arg(int argc, char *argv[])
引数が無視されることを表示する
Definition cerr.c:92
void freecerr()
エラーリストと現在のエラーを解放する
Definition cerr.c:76
void cerr_init()
エラーを初期化する
Definition cerr.c:3
void setcerr(int num, const char *str)
現在のエラーを設定する
Definition cerr.c:46
#define ARRAYSIZE(array)
配列のサイズを返すマクロ
Definition cmem.h:15
int main(int argc, char *argv[])
comet2monitorコマンドのメイン
void addcerrlist_comet2monitor()
CERR cerr_comet2monitor[]
casl2のエラー定義
void exec()
COMET II仮想マシンを実行する
Definition exec.c:684
CLOCK clock_str2clock(const char *str)
クロック周波数を表す数値文字列を、正の整数値であるCLOCK型の数値に変換。変換できない場合は、エラーを表示して0を返す
Definition exec.c:92
void addcerrlist_exec()
実行エラーをエラーリストに追加する
Definition exec.c:221
WORD loadassemble(const char *file, WORD start)
指定されたファイルからアセンブル結果を読み込む
Definition load.c:20
void addcerrlist_load()
アセンブル結果読み込みエラーをエラーリストに追加する
Definition load.c:15
WORD memsize_str2word(const char *str)
メモリーサイズを表す数値文字列をWORD値に変換して返す。WORD値に変換できない場合は、エラーを表示して0を返す
Definition struct.c:322
@ HASH_CMDTYPE
Definition struct.h:64
@ DEFAULT_MEMSIZE
Definition struct.h:21
@ DEFAULT_CLOCKS
Definition struct.h:23
void comet2_shutdown()
COMET II仮想マシンのシャットダウン
Definition struct.c:399
EXECPTR * execptr
Definition struct.c:13
bool create_cmdtable(CMDTAB_HASH hash)
命令ハッシュ表を作成する
Definition struct.c:124
void free_cmdtable(CMDTAB_HASH hash)
Definition struct.c:146
void comet2_init(WORD memsize, CLOCK clocks)
COMET II仮想マシンの初期化
Definition struct.c:329
EXECMODE execmode
実行モード: trace, logical, dump, reverse, monitor, step
Definition exec.c:90
#define PACKAGE_VERSION
Definition version.h:4