X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fassemble.c;h=c9dd43b5e755129a906bdcf7ab3de4a6779d0822;hb=be496380efb4018b38076cfadb4b790fa388a1e3;hp=0b075b0ca9850de1718d11fe26adc1c636d1060b;hpb=7ec8afe886e95655022c8d435ea6085bd819b5fd;p=YACASL2.git diff --git a/src/assemble.c b/src/assemble.c index 0b075b0..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を返す * @@ -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); } } @@ -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() {