comet2monitorの追加と、モニター機能作成
[YACASL2.git] / src / struct.c
index b01ffb8..12caf87 100644 (file)
@@ -1,9 +1,4 @@
-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-#include "hash.h"
 #include "struct.h"
-#include "cmem.h"
 #include "exec.h"
 
 /**
@@ -75,7 +70,7 @@ enum {
 /**
  * ハッシュ表
  */
-static CMDTAB *cmdtype_code[CMDTABSIZE], *code_type[CMDTABSIZE];
+static CMDTAB *cmdtype_code[CMDTABSIZE], *code_cmdtype[CMDTABSIZE];
 
 /**
  * 命令の名前とタイプからハッシュ値を生成する
@@ -176,7 +171,7 @@ unsigned hash_code(WORD code)
 /**
  * コードがキーの命令ハッシュ表を作成する
  */
-bool create_code_type()
+bool create_code_cmdtype()
 {
     CMDTAB *p;
     unsigned hashval;
@@ -184,10 +179,10 @@ bool create_code_type()
 
     for(i = 0; i < comet2cmdsize; i++) {
         hashval = hash_code((&comet2cmd[i])->code);    /* ハッシュ値の生成 */
-        p = malloc_chk(sizeof(CMDTAB), "code_type");
+        p = malloc_chk(sizeof(CMDTAB), "code_cmdtype");
         p->cmd = &comet2cmd[i];
-        p->next = code_type[hashval];                  /* ハッシュ表に値を追加 */
-        code_type[hashval] = p;
+        p->next = code_cmdtype[hashval];                  /* ハッシュ表に値を追加 */
+        code_cmdtype[hashval] = p;
     }
     return true;
 }
@@ -200,7 +195,7 @@ const void (*getcmdptr(WORD code))
     CMDTAB *t;
     const void *ptr = NULL;
 
-    for(t = code_type[hash_code(code)]; t != NULL; t = t->next) {
+    for(t = code_cmdtype[hash_code(code)]; t != NULL; t = t->next) {
         if(code == t->cmd->code) {
             ptr = t->cmd->ptr;
             break;
@@ -209,15 +204,61 @@ const void (*getcmdptr(WORD code))
     return ptr;
 }
 
+/**
+ * 命令コードから命令のタイプを返す
+ */
+CMDTYPE getcmdtype(WORD code)
+{
+    CMDTAB *t;
+    CMDTYPE type = NONE;
+
+    for(t = code_cmdtype[hash_code(code)]; t != NULL; t = t->next) {
+        if(code == t->cmd->code) {
+            type = t->cmd->type;
+            break;
+        }
+    }
+    return type;
+}
+
+/**
+ * 命令コードから命令の名前を返す
+ */
+char *getcmdname(WORD code)
+{
+    CMDTAB *t;
+    char *cmd = NULL;
+
+    for(t = code_cmdtype[hash_code(code)]; t != NULL; t = t->next) {
+        if(code == t->cmd->code) {
+            cmd = t->cmd->name;
+            break;
+        }
+    }
+    return cmd;
+}
+
+/**
+ * 汎用レジスタの番号からレジスタを表す文字列を返す
+ */
+
+char *grstr(WORD word)
+{
+    assert(word <= 7);
+    char *str = malloc_chk(3 + 1, "grstr.str");
+    sprintf(str, "GR%d", word);
+    return str;
+}
+
 /**
  * コードがキーの命令ハッシュ表を解放する
  */
-void free_code_type()
+void free_code_cmdtype()
 {
     int i;
     CMDTAB *p, *q;
     for(i = 0; i < CMDTABSIZE; i++) {
-        for(p = code_type[i]; p != NULL; p = q) {
+        for(p = code_cmdtype[i]; p != NULL; p = q) {
             q = p->next;
             FREE(p);
         }