From: j8takagi Date: Sun, 7 Feb 2010 01:21:39 +0000 (+0900) Subject: ソースコードで、モードを表す構造体メンバーの名前とコメントを修正 X-Git-Tag: v0.1~60 X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=commitdiff_plain;h=ed3225328d7bc0d718fc97dd0b05692b7287667b ソースコードで、モードを表す構造体メンバーの名前とコメントを修正 --- diff --git a/include/assemble.h b/include/assemble.h index f6e081a..ae746fd 100644 --- a/include/assemble.h +++ b/include/assemble.h @@ -12,11 +12,11 @@ enum { /* アセンブルモード */ typedef struct { - bool srcmode; /* ソースを表示する場合はtrue */ - bool labelmode; /* ラベル表を表示する場合はtrue */ - bool onlylabelmode; /* ラベル表を表示して終了する場合はtrue */ - bool asdetailmode; /* アセンブラ詳細結果を表示する場合はtrue */ - bool onlyassemblemode; /* アセンブルだけを行う場合はtrue */ + bool src; /* ソースを表示する場合はtrue */ + bool label; /* ラベル表を表示する場合はtrue */ + bool onlylabel; /* ラベル表を表示して終了する場合はtrue */ + bool asdetail; /* アセンブラ詳細結果を表示する場合はtrue */ + bool onlyassemble; /* アセンブルだけを行う場合はtrue */ } ASMODE; extern ASMODE asmode; @@ -101,9 +101,9 @@ OPD *opdtok(const char *str); /* 1行を解析する */ CMDLINE *linetok(const char *line); -/* 汎用レジスタを表す文字列「GR[0-7]」をWORD値に変換 - is_xがTRUEの場合は、指標レジスタとして用いる汎用レジスタ - 文字列が汎用レジスタを表さない場合は、0xFFFFを返す */ +/* 汎用レジスタを表す文字列「GR[0-7]」から、レジスタ番号[0-7]をWORD値で返す */ +/* 文字列が汎用レジスタを表さない場合は、0xFFFFを返す */ +/* is_xがtrueの場合は指標レジスタ。GR0は、COMET IIの仕様により、エラー発生 */ WORD getgr(const char *str, bool is_x); /* 10進定数をWORDに変換 */ @@ -162,4 +162,4 @@ bool writeRPUSH(PASS pass); /* マクロ命令「RPOP」をメモリに書込 */ bool writeRPOP(PASS pass); -#endif +#endif /* YACASL2_ASSEMBLE_INCLUDEDの終端 */ diff --git a/include/casl2.h b/include/casl2.h index fa4b0ae..42ed92d 100644 --- a/include/casl2.h +++ b/include/casl2.h @@ -126,4 +126,4 @@ void free_code_type(); /* 指定されたファイルにアセンブル結果を書込 */ void outassemble(const char *file); -#endif +#endif /* YACASL2_CASL2_INCLUDEDの終端 */ diff --git a/include/exec.h b/include/exec.h index 6841146..40230b4 100644 --- a/include/exec.h +++ b/include/exec.h @@ -10,54 +10,12 @@ enum { /* 実行モード */ typedef struct { - bool tracemode; /* レジストリの内容を表示する場合はtrue */ - bool logicalmode; /* レジストリの内容を論理値(0〜65535)で表示する場合はtrue */ - bool dumpmode; /* メモリの内容を表示する場合はtrue */ + bool trace; /* レジストリの内容を表示する場合はtrue */ + bool logical; /* レジストリの内容を論理値(0〜65535)で表示する場合はtrue */ + bool dump; /* メモリの内容を表示する場合はtrue */ } EXECMODE; extern EXECMODE execmode; -/* 指定されたファイルからアセンブル結果を読込 */ -bool inassemble(char *file); - -/* 標準入力から文字データを読込(SVC 1) */ -void svcin(); - -/* 標準出力へ文字データを書出(SVC 2) */ -void svcout(); - -/* ロード/論理積/論理和/排他的論理和のフラグ設定。OFは常に0 */ -void setfr(WORD val); - -/* 算術加算。フラグを設定して値を返す */ -WORD adda(WORD val0, WORD val1); - -/* 算術減算。フラグを設定して値を返す */ -WORD suba(WORD val0, WORD val1); - -/* 論理加算。フラグを設定して値を返す */ -WORD addl(WORD val0, WORD val1); - -/* 論理減算。フラグを設定して値を返す */ -WORD subl(WORD val0, WORD val1); - -/* 算術比較のフラグ設定。OFは常に0 */ -void cpa(WORD val0, WORD val1); - -/* 論理比較のフラグ設定。OFは常に0 */ -void cpl(WORD val0, WORD val1); - -/* 算術左シフト。フラグを設定して値を返す */ -WORD sla(WORD val0, WORD val1); - -/* 算術右シフト。フラグを設定して値を返す */ -WORD sra(WORD val0, WORD val1); - -/* 論理左シフト。フラグを設定して値を返す */ -WORD sll(WORD val0, WORD val1); - -/* 論理右シフト。フラグを設定して値を返す */ -WORD srl(WORD val0, WORD val1); - /* 仮想マシンのリセット */ void reset(); @@ -70,4 +28,4 @@ void dumpmemory(); /* COMET IIのレジスタを表示 */ void dspregister(); -#endif +#endif /* YACASL2_EXEC_INCLUDEDの終端 */ diff --git a/src/assemble.c b/src/assemble.c index 27ebfdb..811f670 100644 --- a/src/assemble.c +++ b/src/assemble.c @@ -10,20 +10,21 @@ WORD lptr; /* 他のプログラムで参照する入口名 */ char *prog; -/* 汎用レジスタを表す文字列「GR[0-7]」をWORD値に変換 */ -/* is_xがtrueの場合は、指標レジスタとして用いる汎用レジスタ */ +/* 汎用レジスタを表す文字列「GR[0-7]」から、レジスタ番号[0-7]をWORD値で返す */ /* 文字列が汎用レジスタを表さない場合は、0xFFFFを返す */ +/* is_xがtrueの場合は指標レジスタ。GR0は、COMET IIの仕様により、エラー発生 */ WORD getgr(const char *str, bool is_x) { assert(str != NULL); WORD r; + /* 「GR[0-7]」以外の文字列では、0xFFFFを返して終了 */ if(!(strlen(str) == 3 && strncmp(str, "GR", 2) == 0 && (*(str+2) >= '0' && *(str+2) <= '7'))) { return 0xFFFF; } r = (WORD)(*(str+2) - '0'); - /* COMET IIの仕様により、GR0は指標レジスタとして用いることはできない */ + /* 指標レジスタとして用いることはできない */ if(is_x == true && r == 0x0) { setcerr(120, NULL); /* GR0 in operand x */ return 0x0; @@ -61,7 +62,7 @@ bool writememory(WORD word, WORD adr, PASS pass) } if(cerrno == 0) { memory[adr] = word; - if(pass == SECOND && (&asmode)->asdetailmode == true) { + if(pass == SECOND && (&asmode)->asdetail == true) { fprintf(stdout, "\t#%04X\t#%04X\n", adr, word); } status = true; @@ -417,8 +418,8 @@ bool assemble(const char *file, PASS pass) break; } lineno++; - if((pass == FIRST && (&asmode)->srcmode == true) || - (pass == SECOND && (&asmode)->asdetailmode == true)) + if((pass == FIRST && (&asmode)->src == true) || + (pass == SECOND && (&asmode)->asdetail == true)) { fprintf(stdout, "%s:%5d:%s", file, lineno, line); } diff --git a/src/casl2.c b/src/casl2.c index 1b438e5..35f9a80 100644 --- a/src/casl2.c +++ b/src/casl2.c @@ -4,6 +4,7 @@ #define _GNU_SOURCE #include +/* casl2コマンドのオプション */ static struct option longopts[] = { {"source", no_argument, NULL, 's'}, {"label", no_argument, NULL, 'l'}, @@ -22,7 +23,9 @@ static struct option longopts[] = { {0, 0, 0, 0}, }; +/* アセンブルモード: src, label, onlylabel, asdetail, onlyassemble */ ASMODE asmode = {false, false, false, false, false}; +/* 実行モード: trace, logical, dump */ EXECMODE execmode = {false, false, false}; /* エラー番号とエラーメッセージ */ @@ -84,7 +87,7 @@ const char *objfile_name(const char *str) } } -/* casl2コマンド */ +/* casl2コマンドのメイン */ int main(int argc, char *argv[]) { int opt, i; @@ -98,38 +101,38 @@ int main(int argc, char *argv[]) while((opt = getopt_long(argc, argv, "tTdslLao::O::AM:C:h", longopts, NULL)) != -1) { switch(opt) { case 's': - (&asmode)->srcmode = true; + (&asmode)->src = true; break; case 'l': - (&asmode)->labelmode = true; + (&asmode)->label = true; break; case 'L': - (&asmode)->labelmode = true; - (&asmode)->onlylabelmode = true; + (&asmode)->label = true; + (&asmode)->onlylabel = true; break; case 'a': - (&asmode)->asdetailmode = true; + (&asmode)->asdetail = true; break; case 'A': - (&asmode)->asdetailmode = true; - (&asmode)->onlyassemblemode = true; + (&asmode)->asdetail = true; + (&asmode)->onlyassemble = true; break; case 'o': objfile = strdup(objfile_name(optarg)); break; case 'O': - (&asmode)->onlyassemblemode = true; + (&asmode)->onlyassemble = true; objfile = strdup(objfile_name(optarg)); break; case 't': - (&execmode)->tracemode = true; + (&execmode)->trace = true; break; case 'T': - (&execmode)->tracemode = true; - (&execmode)->logicalmode = true; + (&execmode)->trace = true; + (&execmode)->logical = true; break; case 'd': - (&execmode)->dumpmode = true; + (&execmode)->dump = true; break; case 'M': memsize = atoi(optarg); @@ -161,9 +164,9 @@ int main(int argc, char *argv[]) } else if(pass == SECOND) { ptr = beginptr[i]; } - if((&execmode)->tracemode == true || (&execmode)->dumpmode == true || - (&asmode)->srcmode == true || (&asmode)->labelmode == true || - (&asmode)->asdetailmode == true) + if((&execmode)->trace == true || (&execmode)->dump == true || + (&asmode)->src == true || (&asmode)->label == true || + (&asmode)->asdetail == true) { fprintf(stdout, "\nAssemble %s (%d)\n", argv[i], pass); } @@ -175,10 +178,10 @@ int main(int argc, char *argv[]) exit(-1); } } - if(pass == FIRST && (&asmode)->labelmode == true) { + if(pass == FIRST && (&asmode)->label == true) { fprintf(stdout, "\nLabel::::\n"); printlabel(); - if((&asmode)->onlylabelmode == true) { + if((&asmode)->onlylabel == true) { return 0; } } @@ -188,7 +191,7 @@ int main(int argc, char *argv[]) if(objfile != NULL) { outassemble(objfile); } - if((&asmode)->onlyassemblemode == false) { + if((&asmode)->onlyassemble == false) { exec(); /* プログラム実行 */ } } diff --git a/src/comet2.c b/src/comet2.c index bfe1634..7fa8d29 100644 --- a/src/comet2.c +++ b/src/comet2.c @@ -3,6 +3,7 @@ #define _GNU_SOURCE #include +/* comet2コマンドのオプション */ static struct option longopts[] = { {"trace", no_argument, NULL, 't'}, {"tracearithmetic", no_argument, NULL, 't'}, @@ -14,6 +15,7 @@ static struct option longopts[] = { {0, 0, 0, 0} }; +/* 実行モード: trace, logical, dump */ EXECMODE execmode = {false, false, false}; /* エラー番号とエラーメッセージ */ @@ -29,7 +31,7 @@ CERRARRAY cerr[] = { }; /* 指定されたファイルからアセンブル結果を読込 */ -bool inassemble(char *file) { +bool loadassemble(char *file) { FILE *fp; reset(); if((fp = fopen(file, "r")) == NULL) { @@ -50,14 +52,14 @@ int main(int argc, char *argv[]) while((opt = getopt_long(argc, argv, "tTdM:C:h", longopts, NULL)) != -1) { switch(opt) { case 't': - (&execmode)->tracemode = true; + (&execmode)->trace = true; break; case 'T': - (&execmode)->tracemode = true; - (&execmode)->logicalmode = true; + (&execmode)->trace = true; + (&execmode)->logical = true; break; case 'd': - (&execmode)->dumpmode = true; + (&execmode)->dump = true; break; case 'M': memsize = atoi(optarg); @@ -73,7 +75,7 @@ int main(int argc, char *argv[]) exit(-1); } } - if(inassemble(argv[optind]) == true) { + if(loadassemble(argv[optind]) == true) { exec(); /* プログラム実行 */ } if(cerrno > 0) { diff --git a/src/dump.c b/src/dump.c index c1184be..f1b575f 100644 --- a/src/dump.c +++ b/src/dump.c @@ -32,7 +32,7 @@ void dspregister() int i; for(i = 0; i < REGSIZE; i++ ) { fprintf(stdout, "#%04X: GR%d: ", PR, i); - print_dumpword(GR[i], (&execmode)->logicalmode); + print_dumpword(GR[i], (&execmode)->logical); } fprintf(stdout, "#%04X: SP: %6d = #%04X = %s\n", PR, SP, SP, word2bit(SP)); fprintf(stdout, "#%04X: PR: %6d = #%04X = %s\n", PR, PR, PR, word2bit(PR)); diff --git a/src/exec.c b/src/exec.c index 29b1afc..00cee8d 100644 --- a/src/exec.c +++ b/src/exec.c @@ -273,7 +273,7 @@ void exec() char *errpr = malloc(8); clock_t clock_begin, clock_end; - if((&execmode)->tracemode) { + if((&execmode)->trace) { fprintf(stdout, "\nExecuting machine codes\n"); } /* フラグレジスタの初期値設定 */ @@ -309,15 +309,15 @@ void exec() if(cerrno > 0) { goto execerr; } - if((&execmode)->tracemode){ + if((&execmode)->trace){ fprintf(stdout, "#%04X: Register::::\n", PR); dspregister(); } - if((&execmode)->dumpmode){ + if((&execmode)->dump){ fprintf(stdout, "#%04X: Memory::::\n", PR); dumpmemory(); } - if((&execmode)->dumpmode || (&execmode)->tracemode) { + if((&execmode)->dump || (&execmode)->trace) { fprintf(stdout, "\n"); } PR++;