From 7f7bde5dd1305cfc598fe09030c69aad0dc01368 Mon Sep 17 00:00:00 2001 From: j8takagi Date: Tue, 28 Dec 2010 15:12:41 +0900 Subject: [PATCH] =?utf8?q?doxygen=E7=94=A8=E3=81=AB=E3=82=B3=E3=83=A1?= =?utf8?q?=E3=83=B3=E3=83=88=E4=BF=AE=E6=AD=A3=E3=80=82=E9=96=A2=E6=95=B0?= =?utf8?q?=E3=81=AEstatic=E6=8C=87=E5=AE=9A=E3=82=92=E5=A4=96=E3=81=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- include/assemble.h | 75 ++++++++-------- include/casl2.h | 141 ------------------------------ include/cerr.h | 8 +- include/cmem.h | 24 ++++-- include/hash.h | 8 +- src/assemble.c | 40 ++++----- src/cmd.c | 8 +- src/cmem.c | 3 +- src/doxygen.c | 35 ++++++++ src/dump.c | 4 +- src/dumpword.c | 3 + src/label.c | 8 +- src/macro.c | 143 ------------------------------- src/struct.c | 16 +++- src/token.c | 24 ++++-- src/word.c | 32 +++++-- test/system/casl2/Test.mk | 3 +- test/system/casl2/lib_inl/cmd | 2 +- test/system/casl2/lib_mull/cmd | 2 +- test/system/comet2/err_201/0.txt | 2 +- 20 files changed, 181 insertions(+), 400 deletions(-) delete mode 100644 include/casl2.h create mode 100644 src/doxygen.c delete mode 100644 src/macro.c diff --git a/include/assemble.h b/include/assemble.h index 15d314c..a878058 100644 --- a/include/assemble.h +++ b/include/assemble.h @@ -9,27 +9,27 @@ * CASL IIの仕様 */ enum { - LABELSIZE = 8, /** ラベルの最大文字数 */ - OPDSIZE = 40, /** オペラントの最大数。CASL IIシミュレータの制限 */ + LABELSIZE = 8, /**<ラベルの最大文字数 */ + OPDSIZE = 40, /**<オペラントの最大数。CASL IIシミュレータの制限 */ }; /** * YACASL2の制限 */ enum { - LINESIZE = 1024, /* 行の最大文字数 */ - TOKENSIZE = 256, /* トークンの最大文字数 */ + LINESIZE = 1024, /**<行の最大文字数 */ + TOKENSIZE = 256, /**<トークンの最大文字数 */ }; /** * アセンブルモード */ typedef struct { - bool src; /* ソースを表示する場合はtrue */ - bool label; /* ラベル表を表示する場合はtrue */ - bool onlylabel; /* ラベル表を表示して終了する場合はtrue */ - bool asdetail; /* アセンブラ詳細結果を表示する場合はtrue */ - bool onlyassemble; /* アセンブルだけを行う場合はtrue */ + bool src; /**<ソースを表示する場合はtrue */ + bool label; /**<ラベル表を表示する場合はtrue */ + bool onlylabel; /**<ラベル表を表示して終了する場合はtrue */ + bool asdetail; /**<アセンブラ詳細結果を表示する場合はtrue */ + bool onlyassemble; /**<アセンブルだけを行う場合はtrue */ } ASMODE; extern ASMODE asmode; @@ -38,11 +38,14 @@ extern ASMODE asmode; * アセンブルのプロパティ */ typedef struct { - WORD ptr; /* 現在のポインタ */ - WORD lptr; /* リテラル(=付きの値)を格納するポインタ */ - char *prog; /* 他のプログラムで参照する入口名 */ + WORD ptr; /**<現在のポインタ */ + WORD lptr; /**<リテラル(=付きの値)を格納するポインタ */ + char *prog; /**<他のプログラムで参照する入口名 */ } ASPROP; +/** + * アセンブルのプロパティ: ptr, lptr, *prog + */ extern ASPROP *asprop; /** @@ -59,10 +62,10 @@ typedef enum { * アセンブラ命令を表す配列 */ typedef struct { - ASCMDID cmdid; - int opdc_min; - int opdc_max; - char *cmd; + ASCMDID cmdid; /**<アセンブル命令のID */ + int opdc_min; /**<最小オペランド数 */ + int opdc_max; /**<最大オペランド数 */ + char *cmd; /**<コマンド名 */ } ASCMD; /** @@ -79,29 +82,29 @@ typedef enum { * マクロ命令を表す配列 */ typedef struct { - MACROCMDID cmdid; - int opdc_min; - int opdc_max; - char *cmd; + MACROCMDID cmdid; /**<アセンブル命令のID */ + int opdc_min; /**<最小オペランド数 */ + int opdc_max; /**<最大オペランド数 */ + char *cmd; /**<コマンド名 */ } MACROCMD; /** * ラベル配列 */ typedef struct { - char *prog; - char *label; - WORD adr; + char *prog; /**<プログラム */ + char *label; /**<ラベル */ + WORD adr; /**<アドレス */ } LABELARRAY; /** * ラベル表 */ typedef struct _LABELTAB { - struct _LABELTAB *next; - char *prog; - char *label; - WORD adr; + struct _LABELTAB *next; /**<リスト次項目へのポインタ */ + char *prog; /**<プログラム名 */ + char *label; /**<ラベル名 */ + WORD adr; /**<アドレス */ } LABELTAB; enum { @@ -112,7 +115,7 @@ enum { }; /** - * アセンブラが、1回目か、2回目か、を表す + * アセンブラが、1回目か2回目か */ typedef enum { FIRST = 0, @@ -125,7 +128,7 @@ typedef enum { WORD getlabel(const char *prog, const char *label); /** - * ラベルを表に追加する + * プログラム名、ラベル、アドレスをラベル表に追加する */ bool addlabel(const char *prog, const char *label, WORD word); @@ -143,21 +146,21 @@ void freelabel(); * オペランド */ typedef struct { - int opdc; - char *opdv[OPDSIZE]; + int opdc; /**<オペランド数 */ + char *opdv[OPDSIZE]; /**<オペランド配列 */ } OPD; /** * 命令行 */ typedef struct { - char *label; - char *cmd; - OPD *opd; + char *label; /**<ラベル */ + char *cmd; /**<コマンド */ + OPD *opd; /**<オペランド */ } CMDLINE; /** - * 1行を解析する + * 空白またはタブで区切られた1行から、トークンを取得する */ CMDLINE *linetok(const char *line); @@ -168,7 +171,7 @@ CMDLINE *linetok(const char *line); bool assemble(const char *file, PASS pass); /** - * 指定されたファイルにアセンブル結果を書込 + * 引数で指定したファイルにアセンブル結果を書込 */ void outassemble(const char *file); diff --git a/include/casl2.h b/include/casl2.h deleted file mode 100644 index 49f4c8c..0000000 --- a/include/casl2.h +++ /dev/null @@ -1,141 +0,0 @@ -#ifndef YACASL2_CASL2_INCLUDED -#define YACASL2_CASL2_INCLUDED - -#include -#include -#include -#include -#include -#include -#include - -#include "word.h" -#include "hash.h" -#include "cmem.h" -#include "cerr.h" - -/* COMET IIの規格 */ -enum { - CMDSIZE = 4, /* 命令の最大文字数 */ - GRSIZE = 8, /* 汎用レジスタの数。COMET II規格で、7 */ - DEFAULT_MEMSIZE = 512, /* デフォルトのメモリ容量。COMET II規格では、65536語 */ - DEFAULT_CLOCKS = 5000000, /* デフォルトのクロック周波数。COMET II規格では、未定義 */ -}; - -/* COMET II フラグのマスク値 */ -enum { - OF = 0x4, /* Overflow Flag */ - SF = 0x2, /* Sign Flag */ - ZF = 0x1, /* Zero Flag */ -}; - -/* COMET IIのCPU */ -typedef struct { - WORD gr[GRSIZE]; /* 汎用レジスタ */ - WORD sp; /* スタックポインタ */ - WORD pr; /* プログラムレジスタ */ - WORD fr; /* フラグレジスタ */ -} CPU; - -/* COMET IIの仮装実行マシンシステム */ -typedef struct { - CPU *cpu; /* CPU */ - WORD *memory; /* メモリ */ - int memsize; /* メモリサイズ */ - int clocks; /* クロック周波数 */ -} SYSTEM; - -extern SYSTEM *sys; - -/* 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 *name; - CMDTYPE type; - WORD code; -} CMD; - -/* 命令コード配列のサイズ */ -extern int comet2cmdsize; - -/* 命令コードのハッシュ表 */ -typedef struct _CMDTAB { - struct _CMDTAB *next; - CMD *cmd; -} CMDTAB; - -extern CMDTAB **cmdtype_code; -extern CMDTAB **code_type; -extern int cmdtabsize; - -/* CASL2プログラムのプロパティ */ -typedef struct { - WORD start; /* プログラムの開始番地 */ - WORD end; /* プログラムの終了番地 */ -} PROGPROP; - -extern PROGPROP *prog; - -/* COMET II仮想マシンのリセット */ -void reset(int memsize, int clocks); - -/* COMET II仮想マシンのシャットダウン */ -void shutdown(); - -/* 命令と命令タイプがキーのハッシュ表を作成する */ -bool create_cmdtype_code(); - -/* 命令と命令タイプから、命令コードを取得する */ -/* 無効な場合は0xFFFFを返す */ -WORD getcmdcode(const char *cmd, CMDTYPE type); - -/* 命令と命令タイプがキーのハッシュ表を表示する */ -void print_cmdtype_code(); - -/* 命令と命令タイプがキーのハッシュ表を解放する */ -void free_cmdtype_code(); - -/* 命令コードがキーのハッシュ表を作成する */ -bool create_code_type(); - -/* 命令コードから命令タイプを取得する */ -/* 無効な場合はNONEを返す */ -CMDTYPE getcmdtype(WORD code); - -/* 命令コードがキーのハッシュ表を表示する */ -void print_code_type(); - -/* 命令コードがキーのハッシュ表を解放する */ -void free_code_type(); - -/* 指定されたファイルにアセンブル結果を書込 */ -void outassemble(const char *file); - -#endif /* YACASL2_CASL2_INCLUDEDの終端 */ diff --git a/include/cerr.h b/include/cerr.h index db9adbe..1433f90 100644 --- a/include/cerr.h +++ b/include/cerr.h @@ -8,8 +8,8 @@ * エラーの構造体 */ typedef struct { - int num; /* エラー番号 */ - char *msg; /* エラーメッセージ */ + int num; /**<エラー番号 */ + char *msg; /**<エラーメッセージ */ } CERR; /** @@ -21,8 +21,8 @@ extern CERR *cerr; * エラーリスト型 */ typedef struct _CERRLIST { - struct _CERRLIST *next; - CERR *cerr; + struct _CERRLIST *next; /**<リスト次項目へのポインタ */ + CERR *cerr; /**<エラーの構造体 */ } CERRLIST; /** diff --git a/include/cmem.h b/include/cmem.h index a8629ab..a38c81d 100644 --- a/include/cmem.h +++ b/include/cmem.h @@ -2,22 +2,32 @@ #define YACASL2_CMEM_H_INCLUDED #include +/* + * 配列のサイズを返す + */ #ifndef ARRAYSIZE #define ARRAYSIZE(array) (sizeof(array)/sizeof(array[0])) #endif -/* mallocを実行し、0で初期化 */ -/* メモリを確保できない場合はエラーを出力して終了 */ +/** + * mallocを実行し、0で初期化 + * メモリを確保できない場合はエラーを出力して終了 + */ void *malloc_chk(size_t size, char *tag); -/* callocを実行 */ -/* メモリを確保できない場合はエラーを出力して終了 */ +/** + * callocを実行 + * メモリを確保できない場合はエラーを出力して終了 + */ void *calloc_chk(size_t nmemb, size_t size, char *tag); -/* malloc_chkを実行してメモリを確保してから、 */ -/* コピーした文字列を返す */ +/** + * malloc_chkを実行してメモリを確保し、コピーした文字列を返す + */ char *strdup_chk(const char *s, char *tag); -/* メモリがNULLの場合は解放 */ +/** + * メモリを解放 + */ void free_chk(void *ptr, char *tag); #endif diff --git a/include/hash.h b/include/hash.h index 3c05972..361e251 100644 --- a/include/hash.h +++ b/include/hash.h @@ -13,11 +13,11 @@ typedef enum { * ハッシュ共用体 */ typedef struct { - UTYPE type; + UTYPE type; /**<ハッシュ値の元データのデータ型 */ union { - char *s; - int i; - } val; + char *s; /**ptr)++, pass); - writememory(0x0, (asprop->ptr)++, pass); - /* PUSH 0,GR2 */ - writememory(0x7002, (asprop->ptr)++, pass); - writememory(0x0, (asprop->ptr)++, pass); - /* LAD GR1,IBUF */ - writememory(0x1210, (asprop->ptr)++, pass); - writememory(getadr(asprop->prog, ibuf, pass), (asprop->ptr)++, pass); - /* LAD GR2,LEN */ - writememory(0x1220, (asprop->ptr)++, pass); - writememory(getadr(asprop->prog, len, pass), (asprop->ptr)++, pass); - /* SVC 1 */ - writememory(0xF000, (asprop->ptr)++, pass); - writememory(0x0001, (asprop->ptr)++, pass); - /* POP GR2 */ - writememory(0x7120, (asprop->ptr)++, pass); - /* POP GR1 */ - writememory(0x7110, (asprop->ptr)++, pass); - if(cerr->num == 0) { - status = true; - } - return status; -} - -/* マクロ命令「OUT OBUF,LEN」をメモリに書込 */ -/* PUSH 0,GR1 */ -/* PUSH 0,GR2 */ -/* LAD GR1,OBUF */ -/* LAD GR2,LEN */ -/* SVC 2 */ -/* LAD GR1,=#A */ -/* LAD GR2,1 */ -/* SVC 2 */ -/* POP GR2 */ -/* POP GR1 */ -bool writeOUT(const char *obuf, const char *len, PASS pass) -{ - bool status = false; - - /* PUSH 0,GR1 */ - writememory(0x7001, (asprop->ptr)++, pass); - writememory(0x0, (asprop->ptr)++, pass); - /* PUSH 0,GR2 */ - writememory(0x7002, (asprop->ptr)++, pass); - writememory(0x0, (asprop->ptr)++, pass); - /* LAD GR1,OBUF */ - writememory(0x1210, (asprop->ptr)++, pass); - writememory(getadr(asprop->prog, obuf, pass), (asprop->ptr)++, pass); - /* LAD GR2,OLEN */ - writememory(0x1220, (asprop->ptr)++, pass); - writememory(getadr(asprop->prog, len, pass), (asprop->ptr)++, pass); - /* SVC 2 */ - writememory(0xF000, (asprop->ptr)++, pass); - writememory(0x0002, (asprop->ptr)++, pass); - /* LAD GR1,=#A */ - writememory(0x1210, (asprop->ptr)++, pass); - if(pass == FIRST) { - (asprop->ptr)++; - } else { - writememory(asprop->lptr, (asprop->ptr)++, pass); /* リテラルのアドレスを書込 */ - } - writememory(0xA, (asprop->lptr)++, pass); - /* LAD GR2,=1 */ - writememory(0x1220, (asprop->ptr)++, pass); - if(pass == FIRST) { - (asprop->ptr)++; - } else { - writememory(asprop->lptr, (asprop->ptr)++, pass); /* リテラルのアドレスを書込 */ - } - writememory(0x1, (asprop->lptr)++, pass); - /* SVC 2 */ - writememory(0xF000, (asprop->ptr)++, pass); - writememory(0x0002, (asprop->ptr)++, pass); - /* POP GR2 */ - writememory(0x7120, (asprop->ptr)++, pass); - /* POP GR1 */ - writememory(0x7110, (asprop->ptr)++, pass); - if(cerr->num == 0) { - status = true; - } - return status; -} - -/* マクロ命令「RPUSH」をメモリに書き込む - PUSH 0,GR1 - PUSH 0,GR2 - PUSH 0,GR3 - PUSH 0,GR4 - PUSH 0,GR5 - PUSH 0,GR6 - PUSH 0,GR7 - */ -bool writeRPUSH(PASS pass) { - int i; - bool status = false; - - for(i = 1; i <= 7; i++) { - writememory(0x7000 + i, (asprop->ptr)++, pass); /* PUSH GRn */ - writememory(0x0, (asprop->ptr)++, pass); - } - if(cerr->num == 0) { - status = true; - } - return status; -} - -/* マクロ命令「RPOP」をメモリに書き込む - POP GR7 - POP GR6 - POP GR5 - POP GR4 - POP GR3 - POP GR3 - POP GR2 - POP GR1 - */ -bool writeRPOP(PASS pass) { - int i; - bool status = false; - for(i = 7; i >= 1; i--) { - writememory((0x7100 + (i << 4)), (asprop->ptr)++, pass); /* POP GRn */ - } - if(cerr->num == 0) { - status = true; - } - return status; -} diff --git a/src/struct.c b/src/struct.c index 7ac58e5..58a3585 100644 --- a/src/struct.c +++ b/src/struct.c @@ -1,13 +1,19 @@ #include "struct.h" #include "cmem.h" -/* COMET IIの仮装実行マシンシステム */ +/** + * COMET IIの仮装実行マシンシステム + */ SYSTEM *sys; -/* CASL IIプログラムのプロパティ */ +/** + * CASL IIプログラムのプロパティ + */ PROGPROP *prog; -/* COMET II仮想マシンのリセット */ +/** + * COMET II仮想マシンのリセット + */ void reset(int memsize, int clocks) { int i; @@ -29,7 +35,9 @@ void reset(int memsize, int clocks) prog = malloc_chk(sizeof(PROGPROP), "prog"); } -/* COMET II仮想マシンのシャットダウン */ +/** + * COMET II仮想マシンのシャットダウン + */ void shutdown() { free_chk(prog, "prog"); diff --git a/src/token.c b/src/token.c index 3972d51..9731605 100644 --- a/src/token.c +++ b/src/token.c @@ -4,11 +4,9 @@ #include "cmem.h" #include "assemble.h" -#ifndef UNITTEST -static OPD *opdtok(const char *str); -#endif - -/* 「,」区切りの文字列から、オペランドのトークンを取得 */ +/** + * 「,」区切りの文字列から、オペランドのトークンを取得 + */ OPD *opdtok(const char *str) { OPD *opd = malloc_chk(sizeof(OPD), "opd"); @@ -16,6 +14,13 @@ OPD *opdtok(const char *str) int sepc = ',', rcnt = 0; bool quoting = false; + CERR cerr_opdtok[] = { + { 117, "operand too many in DC" }, + { 118, "operand length too long" }, + { 121, "cannot get operand token" }, + { 123, "unclosed quote" }, + }; + addcerrlist(ARRAYSIZE(cerr_opdtok), cerr_opdtok); opd->opdc = 0; if(str == NULL) { return opd; @@ -70,13 +75,20 @@ OPD *opdtok(const char *str) return opd; } -/* 空白またはタブで区切られた1行から、トークンを取得 */ +/** + * 空白またはタブで区切られた1行から、トークンを取得する + */ CMDLINE *linetok(const char *line) { char *tokens, *p, *sepp; bool quoting = false; CMDLINE *cmdl = malloc_chk(sizeof(CMDLINE), "cmdl"); + CERR cerr_linetok[] = { + { 104, "label length is too long" }, + { 105, "no command in the line" }, + }; + addcerrlist(ARRAYSIZE(cerr_linetok), cerr_linetok); if(line == NULL || strlen(line) == 0) { return NULL; } diff --git a/src/word.c b/src/word.c index 3e9d305..bc51180 100644 --- a/src/word.c +++ b/src/word.c @@ -7,15 +7,19 @@ #include "word.h" #include "cerr.h" -/* wordのエラー定義 */ +/** + * wordのエラー定義 + */ static CERR cerr_word[] = { { 114, "not integer" }, { 115, "not hex" }, { 116, "out of hex range" }, }; -/* 10進数の文字列をWORD値に変換 */ -static WORD n2word(const char *str) +/** + * 10進数の文字列をWORD値に変換 + */ +WORD n2word(const char *str) { assert(isdigit(*str) || *str == '-'); @@ -34,8 +38,10 @@ static WORD n2word(const char *str) return (WORD)n; } -/* 16進数の文字列をWORD値に変換 */ -static WORD h2word(const char *str) +/** + * 16進数の文字列をWORD値に変換 + */ +WORD h2word(const char *str) { assert(*str == '#'); @@ -55,7 +61,9 @@ static WORD h2word(const char *str) return word; } -/* 10進数または16進数の文字列をWORD値に変換 */ +/** + * 10進数または16進数の文字列をWORD値に変換 + */ WORD nh2word(const char *str) { assert(sizeof(WORD)*8 == 16); /* WORD型のサイズが16ビットであることを確認 */ @@ -75,7 +83,9 @@ WORD nh2word(const char *str) return word; } -/* WORD値を10進数の文字列に変換 */ +/** + * WORD値を10進数の文字列に変換 + */ char *word2n(WORD word) { enum { @@ -95,7 +105,9 @@ char *word2n(WORD word) return digit; } -/* WORD値を2進数の文字列に変換 */ +/** + * WORD値を2進数の文字列に変換 + */ char *word2bit(const WORD word) { enum { @@ -112,7 +124,9 @@ char *word2bit(const WORD word) return bit; } -/* WORD値を解析して表示 */ +/** + * WORD値を解析して表示 + */ void print_dumpword(WORD word, bool logicalmode) { if(logicalmode == true) { diff --git a/test/system/casl2/Test.mk b/test/system/casl2/Test.mk index 8da44c1..216986e 100644 --- a/test/system/casl2/Test.mk +++ b/test/system/casl2/Test.mk @@ -19,8 +19,7 @@ SHELL = /bin/bash TEST = $(notdir $(CURRDIR)) # コマンドファイルのソース -CMDSRC_FILE := $(CMD_FILE) -#CMDSRC_FILE := $(CMD_FILE).c +CMDSRC_FILE ?= $(CMD_FILE) .PHONY: check set reset time cleantime clean cleanall diff --git a/test/system/casl2/lib_inl/cmd b/test/system/casl2/lib_inl/cmd index 7a7215c..f68c159 100755 --- a/test/system/casl2/lib_inl/cmd +++ b/test/system/casl2/lib_inl/cmd @@ -1 +1 @@ -../../../../casl2 -M720 inl.casl ../../../../as/casl2lib/inl.casl ../../../../as/casl2lib/outl.casl ../../../../as/casl2lib/str2l.casl ../../../../as/casl2lib/divl.casl ../../../../as/casl2lib/rev.casl