From: j8takagi Date: Sat, 2 Jun 2018 11:02:52 +0000 (+0900) Subject: 命令のコードとタイプがキーのハッシュ表の名前を修正 X-Git-Tag: v0.3~1 X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=commitdiff_plain;h=03e322484530da78d796401413d9f5f493d95345 命令のコードとタイプがキーのハッシュ表の名前を修正 --- 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); }