From: j8takagi Date: Mon, 28 Feb 2011 03:19:14 +0000 (+0900) Subject: Ubuntu 10.04 PPC版で判明した問題を修正 X-Git-Tag: v0.1p19 X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=commitdiff_plain;h=de18494f8acd2f8ca87b86c54bfee1c2094c0d83 Ubuntu 10.04 PPC版で判明した問題を修正 エラーリストの追加方法を修正 cerr->msgの開放時にエラーとなっているため、cerr.c内でコメントアウト --- diff --git a/include/assemble.h b/include/assemble.h index a878058..8ab4255 100644 --- a/include/assemble.h +++ b/include/assemble.h @@ -159,11 +159,21 @@ typedef struct { OPD *opd; /**<オペランド */ } CMDLINE; +/** + * トークン取得のエラーを追加 + */ +void addcerrlist_tok(); + /** * 空白またはタブで区切られた1行から、トークンを取得する */ CMDLINE *linetok(const char *line); +/** + * アセンブルエラーをエラーリストに追加 + */ +void addcerrlist_assemble(); + /** * 指定された名前のファイルをアセンブル * 2回実行される diff --git a/include/cerr.h b/include/cerr.h index 1433f90..a67b65d 100644 --- a/include/cerr.h +++ b/include/cerr.h @@ -7,7 +7,7 @@ /** * エラーの構造体 */ -typedef struct { +typedef struct _CERR { int num; /**<エラー番号 */ char *msg; /**<エラーメッセージ */ } CERR; @@ -45,6 +45,11 @@ void cerr_init(); */ bool addcerrlist(int cerrc, CERR cerrv[]); +/** + * エラーリストを表示する + */ +void printcerrlist(); + /** * 現在のエラーを設定する */ diff --git a/include/exec.h b/include/exec.h index 073e576..83ce07f 100644 --- a/include/exec.h +++ b/include/exec.h @@ -23,6 +23,11 @@ typedef struct { */ extern EXECMODE execmode; +/** + * 実行エラーをエラーリストに追加 + */ +bool addcerrlist_exec(); + /** * 指定されたファイルからアセンブル結果を読み込む */ diff --git a/include/word.h b/include/word.h index 0af12b4..93669dc 100644 --- a/include/word.h +++ b/include/word.h @@ -6,16 +6,29 @@ /* WORD - 16ビットデータ型 */ typedef unsigned short WORD; -/* 10進数または16進数の文字列をWORD値に変換 */ +/** + * wordのエラーをエラーリストに追加 + */ +bool addcerrlist_word(); + +/** + * 10進数または16進数の文字列をWORD値に変換 + */ WORD nh2word(const char *str); -/* WORD値を10進数の文字列に変換 */ +/** + * WORD値を10進数の文字列に変換 + */ char *word2n(WORD word); -/* WORD値を2進数の文字列に変換 */ +/** + * WORD値を2進数の文字列に変換 + */ char *word2bit(const WORD word); -/* WORD値を解析して表示 */ +/** + * WORD値を解析して表示 + */ void print_dumpword(WORD word, bool logicalmode); #endif diff --git a/src/assemble.c b/src/assemble.c index c86334f..a99c62e 100644 --- a/src/assemble.c +++ b/src/assemble.c @@ -609,6 +609,16 @@ bool assembleline(const char *line, PASS pass) return true; } +/** + * アセンブルのエラーをエラーリストに追加 + */ +void addcerrlist_assemble() +{ + addcerrlist_tok(); + addcerrlist_word(); + addcerrlist(ARRAYSIZE(cerr_assemble), cerr_assemble); +} + /** * 指定された名前のファイルをアセンブル * 2回実行される @@ -621,7 +631,6 @@ bool assemble(const char *file, PASS pass) char *line; FILE *fp; - addcerrlist(ARRAYSIZE(cerr_assemble), cerr_assemble); if((fp = fopen(file, "r")) == NULL) { perror(file); return false; diff --git a/src/casl2.c b/src/casl2.c index d17922c..1f18a40 100644 --- a/src/casl2.c +++ b/src/casl2.c @@ -4,10 +4,10 @@ #define _GNU_SOURCE #include +#include "cmem.h" +#include "cerr.h" #include "assemble.h" #include "exec.h" -#include "cerr.h" -#include "cmem.h" /** * casl2コマンドのオプション @@ -33,7 +33,7 @@ static struct option longopts[] = { /** * casl2のエラー定義 */ -static CERR cerr_casl2[] = { +CERR cerr_casl2[] = { { 126, "no source file" }, }; @@ -61,7 +61,9 @@ int main(int argc, char *argv[]) "Usage: %s [-slLaAtTdh] [-oO[]] [-M ] [-C ] FILE1[ FILE2 ...]\n"; cerr_init(); - addcerrlist(sizeof(cerr_casl2), cerr_casl2); + addcerrlist(ARRAYSIZE(cerr_casl2), cerr_casl2); + addcerrlist_assemble(); + addcerrlist_exec(); /* オプションの処理 */ while((opt = getopt_long(argc, argv, "tTdslLao::O::AM:C:h", longopts, NULL)) != -1) { switch(opt) { @@ -141,6 +143,7 @@ int main(int argc, char *argv[]) fprintf(stdout, "\nAssemble %s (%d)\n", argv[i], pass); } if((res = assemble(argv[i], pass)) == false) { + freecerr(); /* エラーの解放 */ exit(-1); } } @@ -161,6 +164,7 @@ int main(int argc, char *argv[]) if(res == true) { if(objfile != NULL) { outassemble(objfile); + free_chk(objfile, "objfile"); } if(asmode.onlyassemble == false) { create_code_type(); /* 命令のコードとタイプがキーのハッシュ表を作成 */ @@ -173,8 +177,6 @@ int main(int argc, char *argv[]) if(cerr->num > 0) { status = -1; } - free_chk(objfile, "objfile"); - /* エラーの解放 */ - freecerr(); + freecerr(); /* エラーの解放 */ return status; } diff --git a/src/cerr.c b/src/cerr.c index 36b33a4..069564b 100644 --- a/src/cerr.c +++ b/src/cerr.c @@ -25,7 +25,7 @@ CERR *cerr; CERRLIST *cerrlist; /** - * エラーリストを作成・追加する + * エラーリストを作成または追加する */ bool addcerrlist(int newerrc, CERR newerrv[]) { @@ -51,6 +51,22 @@ bool addcerrlist(int newerrc, CERR newerrv[]) return true; } +/** + * エラーリストを表示する + */ +void printcerrlist() +{ + CERRLIST *p; + + if(cerrlist == NULL) { + puts("error list is null."); + } else { + for(p = cerrlist; p != NULL; p = p->next) { + printf("%d: %s\n", p->cerr->num, p->cerr->msg); + } + } +} + /** * 現在のエラーを設定する */ @@ -96,7 +112,7 @@ void freecerr() p = q; } /* 現在のエラーメッセージを解放 */ - free_chk(cerr->msg, "cerr.msg"); + /* free_chk(cerr->msg, "cerr->msg"); */ /* 現在のエラーを解放 */ free_chk(cerr, "cerr"); } diff --git a/src/comet2.c b/src/comet2.c index 138382a..2f7696a 100644 --- a/src/comet2.c +++ b/src/comet2.c @@ -38,7 +38,8 @@ int main(int argc, char *argv[]) const char *usage = "Usage: %s [-tTdh] [-M ] [-C ] FILE\n"; cerr_init(); - addcerrlist(ARRAYSIZE(cerr_comet2), cerr_comet2); /* エラーリスト作成 */ + addcerrlist(ARRAYSIZE(cerr_comet2), cerr_comet2); + addcerrlist_exec(); /* オプションの処理 */ while((opt = getopt_long(argc, argv, "tTdM:C:h", longopts, NULL)) != -1) { diff --git a/src/dumpword.c b/src/dumpword.c index 0bc9a47..9574364 100644 --- a/src/dumpword.c +++ b/src/dumpword.c @@ -26,6 +26,7 @@ int main(int argc, char *argv[]) const char *usage = "Usage: %s [-alh] WORD\n"; cerr_init(); + addcerrlist_word(); 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 340ec52..4bbe350 100644 --- a/src/exec.c +++ b/src/exec.c @@ -5,17 +5,11 @@ #include "exec.h" #include "cerr.h" -/** - * アセンブルファイル読み込みエラーの定義 - */ -static CERR cerr_loadassemble[] = { - { 201, "Loading - full of COMET II memory" }, -}; - /** * 実行エラーの定義 */ static CERR cerr_exec[] = { + { 201, "Loading - full of COMET II memory" }, { 202, "SVC input - out of Input memory" }, { 203, "SVC output - out of COMET II memory" }, { 204, "Program Register (PR) - out of COMET II memory" }, @@ -29,14 +23,22 @@ static CERR cerr_exec[] = { */ EXECMODE execmode = {false, false, false}; +/** + * 実行エラーをエラーリストに追加 + */ +bool addcerrlist_exec() +{ + return addcerrlist(ARRAYSIZE(cerr_exec), cerr_exec); +} + /** * 指定されたファイルからアセンブル結果を読み込む */ -bool loadassemble(char *file) { +bool loadassemble(char *file) +{ FILE *fp; bool status = true; - addcerrlist(ARRAYSIZE(cerr_exec), cerr_loadassemble); /* エラーリスト作成 */ assert(file != NULL); if((fp = fopen(file, "r")) == NULL) { perror(file); @@ -339,7 +341,6 @@ bool exec() char *errpr = malloc_chk(CERRSTRSIZE + 1, "exec.errpr"); clock_t clock_begin, clock_end; - addcerrlist(ARRAYSIZE(cerr_exec), cerr_exec); /* エラーリスト作成 */ if(execmode.trace == true) { fprintf(stdout, "\nExecuting machine codes\n"); } diff --git a/src/token.c b/src/token.c index 9731605..c185d8d 100644 --- a/src/token.c +++ b/src/token.c @@ -4,6 +4,34 @@ #include "cmem.h" #include "assemble.h" + +/** + * 行トークン取得のエラー定義 + */ +CERR cerr_linetok[] = { + { 104, "label length is too long" }, + { 105, "no command in the line" }, +}; + +/** + * オペランドトークン取得のエラー定義 + */ +static CERR cerr_opdtok[] = { + { 117, "operand too many in DC" }, + { 118, "operand length too long" }, + { 121, "cannot get operand token" }, + { 123, "unclosed quote" }, +}; + +/** + * オペランドトークン取得のエラーを追加 + */ +void addcerrlist_tok() +{ + addcerrlist(ARRAYSIZE(cerr_linetok), cerr_linetok); + addcerrlist(ARRAYSIZE(cerr_opdtok), cerr_opdtok); +} + /** * 「,」区切りの文字列から、オペランドのトークンを取得 */ @@ -14,13 +42,6 @@ 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; @@ -84,11 +105,6 @@ CMDLINE *linetok(const char *line) 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 bc51180..1bbffdb 100644 --- a/src/word.c +++ b/src/word.c @@ -16,6 +16,14 @@ static CERR cerr_word[] = { { 116, "out of hex range" }, }; +/** + * wordのエラーをエラーリストに追加 + */ +bool addcerrlist_word() +{ + return addcerrlist(ARRAYSIZE(cerr_word), cerr_word); +} + /** * 10進数の文字列をWORD値に変換 */ @@ -67,7 +75,6 @@ WORD h2word(const char *str) WORD nh2word(const char *str) { assert(sizeof(WORD)*8 == 16); /* WORD型のサイズが16ビットであることを確認 */ - addcerrlist(ARRAYSIZE(cerr_word), cerr_word); /* エラーの設定 */ WORD word;