From: j8takagi Date: Thu, 4 Feb 2010 15:32:10 +0000 (+0900) Subject: モードを構造体に記述するように内部構造を変更 X-Git-Tag: v0.1~69 X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=commitdiff_plain;h=712486afe58b10ef37c5fa915de889ab8d1dd6cd モードを構造体に記述するように内部構造を変更 --- diff --git a/include/assemble.h b/include/assemble.h index 594157c..f6e081a 100644 --- a/include/assemble.h +++ b/include/assemble.h @@ -10,6 +10,16 @@ enum { OPDSIZE = 40, /* オペラントの最大数 */ }; +/* アセンブルモード */ +typedef struct { + bool srcmode; /* ソースを表示する場合はtrue */ + bool labelmode; /* ラベル表を表示する場合はtrue */ + bool onlylabelmode; /* ラベル表を表示して終了する場合はtrue */ + bool asdetailmode; /* アセンブラ詳細結果を表示する場合はtrue */ + bool onlyassemblemode; /* アセンブルだけを行う場合はtrue */ +} ASMODE; +extern ASMODE asmode; + /* 値を格納するポインタ */ extern WORD ptr; diff --git a/include/casl2.h b/include/casl2.h index 9c71c28..a293b13 100644 --- a/include/casl2.h +++ b/include/casl2.h @@ -38,30 +38,6 @@ enum { ZF = 0x1, /* Zero Flag */ }; -/* レジストリの内容を表示する場合はTRUE */ -extern bool tracemode; - -/* レジストリの内容を論理値(0〜65535)で表示する場合はTRUE */ -extern bool logicalmode; - -/* メモリの内容を表示する場合はTRUE */ -extern bool dumpmode; - -/* ソースを表示する場合はTRUE */ -extern bool srcmode; - -/* ラベル表を表示する場合はTRUE */ -extern bool labelmode; - -/* ラベル表を表示して終了する場合はTRUE */ -extern bool onlylabelmode; - -/* アセンブラ詳細結果を表示するならTRUE */ -extern bool asdetailmode; - -/* アセンブルだけを行う場合はTRUE */ -extern bool onlyassemblemode; - /* メモリーサイズ */ extern int memsize; @@ -74,25 +50,35 @@ extern WORD startptr; /* 実行終了番地 */ extern WORD endptr; -/* COMET II 命令 - 命令タイプは、オペランドにより6つに分類 - R_ADR_X = 010: オペランド数2または3。 - 第1オペランドは汎用レジスタ、第2オペランドはアドレス、第3オペランドは指標レジスタ - R_ADR_X_ = 011: 同上。ただし、実効アドレスに格納されている内容を示す - R1_R2 = 020: オペランド数2。第1オペランド、第2オペランドともに汎用レジスタ - ADR_X = 030: オペランド数1または2。第1オペランドはアドレス、第2オペランドは指標レジスタ - R_ = 040: オペランド数1。第1オペランドはGR - NONE = 0: オペランドなし -*/ +/* COMET II 命令 */ +/* 命令タイプは、オペランドにより6種類に分類 */ typedef enum { + /* オペランド数2または3 */ + /* 第1オペランド: 汎用レジスタ */ + /* 第2オペランド: アドレス */ + /* 第3オペランド: 指標レジスタ */ R_ADR_X = 010, + /* オペランド数2または3 */ + /* 第1オペランド: 汎用レジスタ、*/ + /* 第2オペランド: アドレスに格納されている内容 */ + /* 第3オペランド: 指標レジスタ */ R_ADR_X_ = 011, + /* オペランド数2 */ + /* 第1オペランド: 汎用レジスタ */ + /* 第2オペランド: 汎用レジスタ */ R1_R2 = 020, + /* オペランド数1または2 */ + /* 第1オペランド: アドレス */ + /* 第2オペランド: 指標レジスタ */ ADR_X = 030, + /* オペランド数1 */ + /* 第1オペランド: 汎用レジスタ */ R_ = 040, + /* オペランドなし */ NONE = 0, } CMDTYPE; +/* 命令コードの配列 */ typedef struct { char *cmd; CMDTYPE type; @@ -108,8 +94,8 @@ typedef struct _CMDCODETAB { /* 命令と命令タイプがキーのハッシュ表を作成する */ bool create_cmdtype_code(); -/* 命令と命令タイプから、命令コードを取得する。 - 無効な場合は0xFFFFを返す */ +/* 命令と命令タイプから、命令コードを取得する */ +/* 無効な場合は0xFFFFを返す */ WORD getcmdcode(const char *cmd, CMDTYPE type); /* 命令と命令タイプからハッシュ値を生成する */ @@ -127,8 +113,8 @@ bool create_code_type(); /* 命令コードからハッシュ値を生成する */ unsigned hash_code(WORD code); -/* 命令コードから命令タイプを取得する。 - 無効な場合はNONEを返す */ +/* 命令コードから命令タイプを取得する */ +/* 無効な場合はNONEを返す */ CMDTYPE getcmdtype(WORD code); /* 命令コードがキーのハッシュ表を表示する */ diff --git a/include/exec.h b/include/exec.h index 1da878d..6841146 100644 --- a/include/exec.h +++ b/include/exec.h @@ -8,6 +8,14 @@ enum { INSIZE = 256 /* CASL IIの、IN命令入力領域 */ }; +/* 実行モード */ +typedef struct { + bool tracemode; /* レジストリの内容を表示する場合はtrue */ + bool logicalmode; /* レジストリの内容を論理値(0〜65535)で表示する場合はtrue */ + bool dumpmode; /* メモリの内容を表示する場合はtrue */ +} EXECMODE; +extern EXECMODE execmode; + /* 指定されたファイルからアセンブル結果を読込 */ bool inassemble(char *file); diff --git a/src/assemble.c b/src/assemble.c index 3297041..d46caef 100644 --- a/src/assemble.c +++ b/src/assemble.c @@ -61,7 +61,7 @@ bool writememory(WORD word, WORD adr, PASS pass) } if(cerrno == 0) { memory[adr] = word; - if(pass == SECOND && asdetailmode == true) { + if(pass == SECOND && (&asmode)->asdetailmode == true) { fprintf(stdout, "\t#%04X\t#%04X\n", adr, word); } status = true; @@ -409,7 +409,9 @@ bool assemble(const char *file, PASS pass) break; } lineno++; - if((pass == FIRST && srcmode == true) || (pass == SECOND && asdetailmode == true)) { + if((pass == FIRST && (&asmode)->srcmode == true) || + (pass == SECOND && (&asmode)->asdetailmode == true)) + { fprintf(stdout, "%s:%5d:%s", file, lineno, line); } if((cmdl = linetok(line)) != NULL) { diff --git a/src/casl2.c b/src/casl2.c index 430b3c6..e2d8cc5 100644 --- a/src/casl2.c +++ b/src/casl2.c @@ -4,18 +4,8 @@ #define _GNU_SOURCE #include -/* 指定されたファイルにCOMET II仮想メモリ(アセンブル結果)を書込 */ -void outassemble(char *file) { - FILE *fp; - if((fp = fopen(file, "w")) == NULL) { - perror(file); - return; - } - fwrite(memory, sizeof(WORD), endptr, fp); - fclose(fp); -} - -static struct option longopts[] = { +static struct option longopts[] = +{ {"source", no_argument, NULL, 's'}, {"label", no_argument, NULL, 'l'}, {"labelonly", no_argument, NULL, 'L'}, @@ -33,6 +23,20 @@ static struct option longopts[] = { {0, 0, 0, 0}, }; +ASMODE asmode = {false, false, false, false, false}; +EXECMODE execmode = {false, false, false}; + +/* 指定されたファイルにCOMET II仮想メモリ(アセンブル結果)を書込 */ +void outassemble(char *file) { + FILE *fp; + if((fp = fopen(file, "w")) == NULL) { + perror(file); + exit(-1); + } + fwrite(memory, sizeof(WORD), endptr, fp); + fclose(fp); +} + int main(int argc, char *argv[]) { int opt, i; @@ -41,25 +45,27 @@ int main(int argc, char *argv[]) WORD beginptr[argc]; char *objfile = NULL; const char *default_objfile = "a.o"; - const char *usage = "Usage: %s [-slLaAtTdh] [-oO] [-M ] [-C ] FILE ...\n"; + const char *usage = + "Usage: %s [-slLaAtTdh] [-oO] [-M ] [-C ] FILE ...\n"; while((opt = getopt_long(argc, argv, "tTdslLao::O::AM:C:h", longopts, NULL)) != -1) { switch(opt) { case 's': - srcmode = true; + (&asmode)->srcmode = true; break; case 'l': - labelmode = true; + (&asmode)->labelmode = true; break; case 'L': - onlylabelmode = true; + (&asmode)->labelmode = true; + (&asmode)->onlylabelmode = true; break; case 'a': - asdetailmode = true; + (&asmode)->asdetailmode = true; break; case 'A': - onlyassemblemode = true; - asdetailmode = true; + (&asmode)->onlyassemblemode = true; + (&asmode)->asdetailmode = true; break; case 'o': if(optarg == NULL) { @@ -69,7 +75,7 @@ int main(int argc, char *argv[]) } break; case 'O': - onlyassemblemode = true; + (&asmode)->onlyassemblemode = true; if(optarg == NULL) { objfile = strdup(default_objfile); } else { @@ -77,14 +83,14 @@ int main(int argc, char *argv[]) } break; case 't': - tracemode = true; + (&execmode)->tracemode = true; break; case 'T': - tracemode = true; - logicalmode = true; + (&execmode)->tracemode = true; + (&execmode)->logicalmode = true; break; case 'd': - dumpmode = true; + (&execmode)->dumpmode = true; break; case 'M': memsize = atoi(optarg); @@ -115,8 +121,10 @@ int main(int argc, char *argv[]) } else if(pass == SECOND) { ptr = beginptr[i]; } - if(tracemode == true || dumpmode == true || srcmode == true || - labelmode == true || asdetailmode == true) { + if((&execmode)->tracemode == true || (&execmode)->dumpmode == true || + (&asmode)->srcmode == true || (&asmode)->labelmode == true || + (&asmode)->asdetailmode == true) + { fprintf(stdout, "\nAssemble %s (%d)\n", argv[i], pass); } if((status = assemble(argv[i], pass)) == false) { @@ -127,10 +135,10 @@ int main(int argc, char *argv[]) exit(-1); } } - if(pass == FIRST && (labelmode == true || onlylabelmode == true)) { + if(pass == FIRST && (&asmode)->labelmode == true) { fprintf(stdout, "\nLabel::::\n"); printlabel(); - if(onlylabelmode == true) { + if((&asmode)->onlylabelmode == true) { return 0; } } @@ -140,7 +148,7 @@ int main(int argc, char *argv[]) if(objfile != NULL) { outassemble(objfile); } - if(onlyassemblemode == false) { + if((&asmode)->onlyassemblemode == false) { exec(); /* プログラム実行 */ } } diff --git a/src/cmd.c b/src/cmd.c index c399ac4..93ae8cd 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -83,8 +83,8 @@ unsigned hash_cmdtype(const char *cmd, CMDTYPE type) { return hash(2, keys, cmdcodesize); } -/* 命令と命令タイプから、命令コードを取得する。 - 無効な場合は0xFFFFを返す */ +/* 命令と命令タイプから、命令コードを取得する */ +/* 無効な場合は0xFFFFを返す */ WORD getcmdcode(const char *cmd, CMDTYPE type) { CMDCODETAB *np; @@ -162,8 +162,8 @@ unsigned hash_code(WORD code) return hash(1, keys, cmdcodesize); } -/* 命令コードから命令タイプを取得する。 - 無効な場合はNONEを返す */ +/* 命令コードから命令タイプを取得する */ +/* 無効な場合はNONEを返す */ CMDTYPE getcmdtype(WORD code) { CMDCODETAB *np; diff --git a/src/comet2.c b/src/comet2.c index c6cf486..1c47d19 100644 --- a/src/comet2.c +++ b/src/comet2.c @@ -3,6 +3,19 @@ #define _GNU_SOURCE #include +static struct option longopts[] = { + {"trace", no_argument, NULL, 't'}, + {"tracearithmetic", no_argument, NULL, 't'}, + {"tracelogical", no_argument, NULL, 'T'}, + {"dump", no_argument, NULL, 'd'}, + {"memorysize", required_argument, NULL, 'M'}, + {"clocks", required_argument, NULL, 'C'}, + {"help", no_argument, NULL, 'h'}, + {0, 0, 0, 0} +}; + +EXECMODE execmode = {false, false, false}; + /* 指定されたファイルからCOMET II仮想メモリ(アセンブル結果)を読込 */ bool inassemble(char *file) { FILE *fp; @@ -16,17 +29,6 @@ bool inassemble(char *file) { return true; } -static struct option longopts[] = { - {"trace", no_argument, NULL, 't'}, - {"tracearithmetic", no_argument, NULL, 't'}, - {"tracelogical", no_argument, NULL, 'T'}, - {"dump", no_argument, NULL, 'd'}, - {"memorysize", required_argument, NULL, 'M'}, - {"clocks", required_argument, NULL, 'C'}, - {"help", no_argument, NULL, 'h'}, - {0, 0, 0, 0} -}; - int main(int argc, char *argv[]) { int opt; @@ -35,14 +37,14 @@ int main(int argc, char *argv[]) while((opt = getopt_long(argc, argv, "tTdM:C:h", longopts, NULL)) != -1) { switch(opt) { case 't': - tracemode = true; + (&execmode)->tracemode = true; break; case 'T': - tracemode = true; - logicalmode = true; + (&execmode)->tracemode = true; + (&execmode)->logicalmode = true; break; case 'd': - dumpmode = true; + (&execmode)->dumpmode = true; break; case 'M': memsize = atoi(optarg); diff --git a/src/dump.c b/src/dump.c index 09fe4dd..8fab87d 100644 --- a/src/dump.c +++ b/src/dump.c @@ -1,4 +1,5 @@ #include "casl2.h" +#include "exec.h" /* COMET IIのメモリを表示 */ void dumpmemory() @@ -30,7 +31,7 @@ void dspregister() { int i; for(i = 0; i < REGSIZE; i++ ) { - if(logicalmode == true) { + if((&execmode)->logicalmode == true) { fprintf(stdout, "#%04X: GR%d: %6d = #%04X = %s\n", PR, i, GR[i], GR[i], word2bit(GR[i])); } else { diff --git a/src/dumpword.c b/src/dumpword.c index cefbc0f..7544f25 100644 --- a/src/dumpword.c +++ b/src/dumpword.c @@ -16,16 +16,13 @@ CERRARRAY cerr[] = { { 0, NULL }, }; -/* レジストリの内容を論理値(0〜65535)で表示する場合はtrue */ -bool logicalmode = false; - int main(int argc, char *argv[]) { + bool logicalmode = false; /* レジストリの内容を論理値(0〜65535)で表示する場合はtrue */ int opt; WORD word; const char *usage = "Usage: %s [-alh] WORD\n"; - logicalmode = false; while((opt = getopt_long(argc, argv, "alh", longopts, NULL)) != -1) { switch(opt) { case 'l': diff --git a/src/exec.c b/src/exec.c index 94c7925..4e34404 100644 --- a/src/exec.c +++ b/src/exec.c @@ -253,7 +253,7 @@ void exec() char *errpr = malloc(8); clock_t clock_begin, clock_end; - if(tracemode) { + if((&execmode)->tracemode) { fprintf(stdout, "\nExecuting machine codes\n"); } /* フラグレジスタの初期値設定 */ @@ -289,15 +289,15 @@ void exec() if(cerrno > 0) { goto execerr; } - if(tracemode){ + if((&execmode)->tracemode){ fprintf(stdout, "#%04X: Register::::\n", PR); dspregister(); } - if(dumpmode){ + if((&execmode)->dumpmode){ fprintf(stdout, "#%04X: Memory::::\n", PR); dumpmemory(); } - if(dumpmode || tracemode) { + if((&execmode)->dumpmode || (&execmode)->tracemode) { fprintf(stdout, "\n"); } PR++; diff --git a/src/struct.c b/src/struct.c index d918c7a..4546648 100644 --- a/src/struct.c +++ b/src/struct.c @@ -39,30 +39,6 @@ CERRARRAY cerr[] = { { 0, NULL }, }; -/* レジストリの内容を表示する場合はtrue */ -bool tracemode = false; - -/* レジストリの内容を論理値(0〜65535)で表示する場合はtrue */ -bool logicalmode = false; - -/* メモリの内容を表示する場合はtrue */ -bool dumpmode = false; - -/* ソースを表示する場合はtrue */ -bool srcmode = false; - -/* ラベル表を表示する場合はtrue */ -bool labelmode = false; - -/* ラベル表を表示して終了する場合はtrue */ -bool onlylabelmode = false; - -/* アセンブラ詳細結果を表示する場合はtrue */ -bool asdetailmode = false; - -/* アセンブルだけを行う場合はtrue */ -bool onlyassemblemode = false; - /* メモリーサイズ */ int memsize = DEFAULT_MEMSIZE;