命令ハッシュ表の構造を変更
[YACASL2.git] / src / assemble.c
index 68a3457..c9dd43b 100644 (file)
@@ -1,12 +1,4 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <assert.h>
-#include <errno.h>
-
 #include "assemble.h"
-#include "cerr.h"
 
 /**
  * @brief ファイルストリームの現在行を番号付きで表示する
@@ -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()
 {