From 03e322484530da78d796401413d9f5f493d95345 Mon Sep 17 00:00:00 2001 From: j8takagi Date: Sat, 2 Jun 2018 20:02:52 +0900 Subject: [PATCH] =?utf8?q?=E5=91=BD=E4=BB=A4=E3=81=AE=E3=82=B3=E3=83=BC?= =?utf8?q?=E3=83=89=E3=81=A8=E3=82=BF=E3=82=A4=E3=83=97=E3=81=8C=E3=82=AD?= =?utf8?q?=E3=83=BC=E3=81=AE=E3=83=8F=E3=83=83=E3=82=B7=E3=83=A5=E8=A1=A8?= =?utf8?q?=E3=81=AE=E5=90=8D=E5=89=8D=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- include/struct.h | 4 ++-- src/exec.c | 4 ++-- src/struct.c | 33 +++++++++++++++++++++++++-------- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/include/struct.h b/include/struct.h index c806e57..54a2418 100644 --- a/include/struct.h +++ b/include/struct.h @@ -149,7 +149,7 @@ void free_cmdtype_code(); /** * コードがキーの命令ハッシュ表を作成する */ -bool create_code_type(); +bool create_code_cmdtype(); /** * 命令コードから命令の関数ポインタを返す @@ -159,6 +159,6 @@ const void (*getcmdptr(WORD code)); /** * コードがキーの命令ハッシュ表を解放する */ -void free_code_type(); +void free_code_cmdtype(); #endif /* YACASL2_CASL2_INCLUDEDの終端 */ diff --git a/src/exec.c b/src/exec.c index c667598..a6c7edc 100644 --- a/src/exec.c +++ b/src/exec.c @@ -758,7 +758,7 @@ void exec() void (*cmdptr)(); char *s; - create_code_type(); /* 命令のコードとタイプがキーのハッシュ表を作成 */ + create_code_cmdtype(); /* 命令のコードとタイプがキーのハッシュ表を作成 */ if(execmode.trace == true) { fprintf(stdout, "\nExecuting machine codes\n"); } @@ -811,7 +811,7 @@ void exec() } while(clock_end - clock_begin < CLOCKS_PER_SEC / sys->clocks); } execfin: - free_code_type(); /* 命令のコードとタイプがキーのハッシュ表を解放 */ + free_code_cmdtype(); /* 命令のコードとタイプがキーのハッシュ表を解放 */ if(cerr->num > 0) { fprintf(stderr, "Execute error - %d: %s\n", cerr->num, cerr->msg); } diff --git a/src/struct.c b/src/struct.c index b01ffb8..981409a 100644 --- a/src/struct.c +++ b/src/struct.c @@ -75,7 +75,7 @@ enum { /** * ハッシュ表 */ -static CMDTAB *cmdtype_code[CMDTABSIZE], *code_type[CMDTABSIZE]; +static CMDTAB *cmdtype_code[CMDTABSIZE], *code_cmdtype[CMDTABSIZE]; /** * 命令の名前とタイプからハッシュ値を生成する @@ -176,7 +176,7 @@ unsigned hash_code(WORD code) /** * コードがキーの命令ハッシュ表を作成する */ -bool create_code_type() +bool create_code_cmdtype() { CMDTAB *p; unsigned hashval; @@ -184,10 +184,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 +200,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 +209,32 @@ const void (*getcmdptr(WORD code)) return ptr; } +/** + * 命令コードから命令の名前を返す + */ +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; +} + /** * コードがキーの命令ハッシュ表を解放する */ -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); } -- 2.18.0