X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=blobdiff_plain;f=src%2Fassemble.c;h=c9dd43b5e755129a906bdcf7ab3de4a6779d0822;hp=c24109d6ca3f4d78e9f90fc2f3f97cba14029ba9;hb=refs%2Ftags%2Fv0.5p1;hpb=910abe0d6a7e4bb1550a29015025b46331b8b8a0 diff --git a/src/assemble.c b/src/assemble.c index c24109d..c9dd43b 100644 --- a/src/assemble.c +++ b/src/assemble.c @@ -1,12 +1,4 @@ -#include -#include -#include -#include -#include -#include - #include "assemble.h" -#include "cerr.h" /** * @brief ファイルストリームの現在行を番号付きで表示する @@ -34,7 +26,7 @@ void printline(FILE *stream, const char *filename, int lineno, char *line); WORD getadr(const char *prog, const char *str, PASS pass); /** - * @brief 汎用レジスタを表す文字列 からレジスタ番号を返す + * @brief 汎用レジスタを表す文字列からレジスタ番号を返す * * @brief 文字列が汎用レジスタを表さない場合は、0xFFFFを返す * @@ -45,7 +37,7 @@ WORD getadr(const char *prog, const char *str, PASS pass); * @param *str 汎用レジスタを表す文字列。「GR0」「GR1」・・・「GR7」のいずれか * @param is_x trueの場合は指標レジスタ */ -WORD getgr(const char *str, bool is_x); +WORD grword(const char *str, bool is_x); /** * @brief リテラルを返す @@ -342,7 +334,7 @@ WORD getadr(const char *prog, const char *str, PASS pass) return adr; } -WORD getgr(const char *str, bool is_x) +WORD grword(const char *str, bool is_x) { WORD r; @@ -449,11 +441,9 @@ void assemble_start(const CMDLINE *cmdl, PASS pass) } /* プログラム名の設定 */ strcpy(asptr->prog, cmdl->label); - /* オペランドがある場合、実行開始アドレスを設定 */ - if(pass == SECOND && cmdl->opd->opdv[0] != NULL) { - if((execptr->start = getlabel(asptr->prog, cmdl->opd->opdv[0])) == 0xFFFF) { - setcerr(103, cmdl->opd->opdv[0]); /* label not found */ - } + /* オペランドがある場合、書き込みと実行の開始アドレスを設定 */ + if(cmdl->opd->opdv[0] != NULL) { + asptr->ptr = execptr->start = getadr(asptr->prog, cmdl->opd->opdv[0], pass); } } @@ -602,7 +592,7 @@ bool assemble_comet2cmd(const CMDLINE *cmdl, PASS pass) writememory(cmd, (asptr->ptr)++, pass); } /* 第1オペランドは汎用レジスタ */ - else if((r_r1 = getgr(cmdl->opd->opdv[0], false)) != 0xFFFF) { + else if((r_r1 = grword(cmdl->opd->opdv[0], false)) != 0xFFFF) { /* オペランド数1 */ if(cmdl->opd->opdc == 1) { if((cmd = getcmdcode(cmdl->cmd, R_)) == 0xFFFF) { @@ -613,7 +603,7 @@ bool assemble_comet2cmd(const CMDLINE *cmdl, PASS pass) writememory(cmd, (asptr->ptr)++, pass); } /* オペランド数2。第2オペランドは汎用レジスタ */ - else if(cmdl->opd->opdc == 2 && (x_r2 = getgr(cmdl->opd->opdv[1], false)) != 0xFFFF) { + else if(cmdl->opd->opdc == 2 && (x_r2 = grword(cmdl->opd->opdv[1], false)) != 0xFFFF) { if((cmd = getcmdcode(cmdl->cmd, R1_R2)) == 0xFFFF) { setcerr(109, cmdl->cmd); /* not command of operand "r1,r2" */ return false; @@ -631,7 +621,7 @@ bool assemble_comet2cmd(const CMDLINE *cmdl, PASS pass) cmd |= (r_r1 << 4); /* 第1オペランドは汎用レジスタ */ /* オペランド数3の場合 */ if(cmdl->opd->opdc == 3) { /* 第3オペランドは指標レジスタとして用いる汎用レジスタ */ - if((x_r2 = getgr(cmdl->opd->opdv[2], true)) == 0xFFFF) { + if((x_r2 = grword(cmdl->opd->opdv[2], true)) == 0xFFFF) { setcerr(125, cmdl->cmd); /* not GR in operand x */ return false; } @@ -654,7 +644,7 @@ bool assemble_comet2cmd(const CMDLINE *cmdl, PASS pass) } /* オペランド数2の場合 */ if(cmdl->opd->opdc == 2) { /* 第2オペランドは指標レジスタとして用いる汎用レジスタ */ - x_r2 = getgr(cmdl->opd->opdv[1], true); + x_r2 = grword(cmdl->opd->opdv[1], true); if(cerr->num > 0) { return false; } @@ -757,6 +747,48 @@ bool assemblefile(const char *file, PASS pass) return (cerr->num == 0) ? true : false; } +void assemble(int filec, char *filev[], WORD adr) +{ + int i; + PASS pass; + WORD bp[filec]; + + asptr = malloc_chk(sizeof(ASPTR), "asptr"); /* アセンブル時のプロパティ用の領域確保 */ + asptr->prog = malloc_chk(LABELSIZE + 1, "asptr.prog"); + asptr->ptr = adr; + /* アセンブル。ラベル表作成のため、2回行う */ + for(pass = FIRST; pass <= SECOND; pass++) { + for(i = 0; i < filec; i++) { + /* データの格納開始位置 */ + if(pass == FIRST) { + bp[i] = asptr->ptr; + } else if(pass == SECOND) { + asptr->ptr = bp[i]; + } + if(execmode.trace == true || execmode.dump == true || + asmode.src == true || asmode.label == true || asmode.asdetail == true) + { + fprintf(stdout, "\nAssemble %s (%d)\n", filev[i], pass); + } + /* ファイルをアセンブル */ + if(assemblefile(filev[i], pass) == false) { + goto asfin; + } + } + if(pass == FIRST && asmode.label == true) { + fprintf(stdout, "\nLabel::::\n"); + printlabel(); + if(asmode.onlylabel == true) { + break; + } + } + } +asfin: + freelabel(); /* ラベルハッシュ表を解放 */ + FREE(asptr->prog); /* アセンブル時のプロパティを解放 */ + FREE(asptr); +} + /* assemble.hで定義された関数群 */ void addcerrlist_assemble() {