comet2monitorの追加と、モニター機能作成
[YACASL2.git] / src / casl2.c
index 237aff9..fb4290a 100644 (file)
@@ -1,6 +1,5 @@
 #include "package.h"
 #include "assemble.h"
-#include "exec.h"
 
 /**
  * @brief CASL IIのエラーをエラーリストに追加
@@ -18,16 +17,6 @@ void addcerrlist_casl2();
  */
 const char *objfile_name(const char *str);
 
-/**
- * @brief 指定された1つまたは複数のファイルを2回アセンブル
- *
- * @return なし
- *
- * @param filec アセンブルするファイルの数
- * @param filev アセンブルするファイル名の配列
- */
-void assemble(int filec, char *filev[]);
-
 /**
  * @brief casl2コマンドのオプション
  */
@@ -43,6 +32,7 @@ static struct option longopts[] = {
     { "tracearithmetic", no_argument, NULL, 't' },
     { "tracelogical", no_argument, NULL, 'T' },
     { "dump", no_argument, NULL, 'd' },
+    { "monitor", no_argument, NULL, 'm' },
     { "memorysize", required_argument, NULL, 'M' },
     { "clocks", required_argument, NULL, 'C' },
     { "version", no_argument, NULL, 'v' },
@@ -68,50 +58,6 @@ const char *objfile_name(const char *str)
     return (str == NULL) ? default_name : str;
 }
 
-void assemble(int filec, char *filev[])
-{
-    int i;
-    PASS pass;
-    WORD bp[filec];
-
-    create_cmdtype_code();                         /* 命令の名前とタイプがキーのハッシュ表を作成 */
-    asptr = malloc_chk(sizeof(ASPTR), "asptr");    /* アセンブル時のプロパティ用の領域確保 */
-    asptr->prog = malloc_chk(LABELSIZE + 1, "asptr.prog");
-    asptr->ptr = 0;
-    /* アセンブル。ラベル表作成のため、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_cmdtype_code();                          /* 命令の名前とタイプがキーのハッシュ表を解放 */
-    FREE(asptr->prog);                            /* アセンブル時のプロパティを解放 */
-    FREE(asptr);
-}
-
 /**
  * @brief casl2コマンドのメイン
  *
@@ -122,18 +68,14 @@ asfin:
  */
 int main(int argc, char *argv[])
 {
-    int memsize = DEFAULT_MEMSIZE, clocks = DEFAULT_CLOCKS, opt, i, stat;
+    int memsize = DEFAULT_MEMSIZE, clocks = DEFAULT_CLOCKS, opt, i, stat = 0;
     char *af[argc], *objfile = NULL;
     const char *version = PACKAGE_VERSION,  *cmdversion = "casl2 of YACASL2 version %s\n";
     const char *usage =
-        "Usage: %s [-slLaAtTdbvh] [-oO[<OBJECTFILE>]] [-M <MEMORYSIZE>] [-C <CLOCKS>] FILE1[ FILE2  ...]\n";
+        "Usage: %s [-slLaAtTdmvh] [-oO[<OBJECTFILE>]] [-M <MEMORYSIZE>] [-C <CLOCKS>] FILE1[ FILE2  ...]\n";
 
-    cerr_init();
-    addcerrlist_casl2();
-    addcerrlist_assemble();
-    addcerrlist_exec();
     /* オプションの処理 */
-    while((opt = getopt_long(argc, argv, "tTdslLbao::O::AM:C:vh", longopts, NULL)) != -1) {
+    while((opt = getopt_long(argc, argv, "tTdslLmao::O::AM:C:vh", longopts, NULL)) != -1) {
         switch(opt) {
         case 's':
             asmode.src = true;
@@ -169,8 +111,8 @@ int main(int argc, char *argv[])
         case 'd':
             execmode.dump = true;
             break;
-        case 'b':
-            execmode.debugger = true;
+        case 'm':
+            execmode.step = true;
             break;
         case 'M':
             memsize = atoi(optarg);
@@ -189,17 +131,25 @@ int main(int argc, char *argv[])
             exit(1);
         }
     }
+
+    /* エラーの定義 */
+    cerr_init();
+    addcerrlist_casl2();
+    addcerrlist_assemble();
+    addcerrlist_exec();
+
     /* ソースファイルが指定されていない場合は終了 */
     if(argv[optind] == NULL) {
         setcerr(126, "");    /* no source file */
         fprintf(stderr, "CASL2 error - %d: %s\n", cerr->num, cerr->msg);
+        freecerr();                                    /* エラーの解放 */
         exit(1);
     }
     reset(memsize, clocks);                        /* 仮想マシンCOMET IIのリセット */
     for(i = 0; i < argc - optind; i++) {           /* 引数からファイル名配列を取得 */
         af[i] = argv[optind + i];
     }
-    assemble(i, af);                               /* アセンブル */
+    assemble(i, af, 0);                            /* アセンブル */
     if(asmode.onlylabel == true || cerr->num > 0) {
         goto casl2fin;
     }