-#include <stdio.h>
-#include <assert.h>
-#include <string.h>
-#include "hash.h"
#include "struct.h"
-#include "cmem.h"
#include "exec.h"
/**
/**
* システムCOMET IIの命令表
*/
-static COMET2CMD comet2cmd[] = {
+static const COMET2CMD comet2cmd[] = {
{ "NOP", NONE, 0x0, nop },
{ "LD", R_ADR_X, 0x1000, ld_r_adr_x },
{ "ST", R_ADR_X, 0x1100, st },
* ハッシュ表のサイズ
*/
enum {
- CMDTABSIZE = 39,
+ CMDTABSIZE = 41,
};
/**
* ハッシュ表
*/
-static CMDTAB *cmdtype_code[CMDTABSIZE], *code_cmdtype[CMDTABSIZE];
+static CMDTAB *cmdtab[HASH_MAX][CMDTABSIZE];
+
+/**
+ * 命令の名前とタイプからハッシュ値を生成する
+ */
+unsigned hash_cmdtype(const char *cmd, CMDTYPE type);
+
+/**
+ * 命令コードからハッシュ値を生成する
+ */
+unsigned hash_code(WORD code);
/**
* 命令の名前とタイプからハッシュ値を生成する
}
/**
- * å\90\8då\89\8dã\81¨ã\82¿ã\82¤ã\83\97ã\81\8cã\82ã\83¼ã\81®å\91½ä»¤ã\83\8fã\83\83ã\82·ã\83¥è¡¨ã\82\92ä½\9cæ\88\90ã\81\99ã\82\8b
+ * 命令ハッシュ表を作成する
*/
-bool create_cmdtype_code()
+bool create_cmdtable(CMDTAB_HASH hash)
{
CMDTAB *p;
unsigned hashval;
int i;
for(i = 0; i < comet2cmdsize; i++) {
- hashval = hash_cmdtype(comet2cmd[i].name, comet2cmd[i].type); /* ハッシュ値の生成 */
- p = malloc_chk(sizeof(CMDTAB), "cmdtype_code");
+ p = malloc_chk(sizeof(CMDTAB), "create_cmdtable.p");
p->cmd = &comet2cmd[i];
- p->next = cmdtype_code[hashval]; /* ハッシュ表に値を追加 */
- cmdtype_code[hashval] = p;
+ if(hash == HASH_CMDTYPE) {
+ hashval = hash_cmdtype(comet2cmd[i].name, comet2cmd[i].type);
+ } else if(hash == HASH_CODE) {
+ hashval = hash_code(comet2cmd[i].code);
+ }
+ p->next = cmdtab[hash][hashval];
+ cmdtab[hash][hashval] = p;
}
return true;
}
+/**
+ * 命令ハッシュ表を解放する
+ */
+void free_cmdtable(CMDTAB_HASH hash)
+{
+ int i;
+ CMDTAB *p, *q;
+
+ for(i = 0; i < CMDTABSIZE; i++) {
+ for(p = cmdtab[hash][i]; p != NULL; p = q) {
+ q = p->next;
+ FREE(p);
+ }
+ cmdtab[hash][i] = NULL;
+ }
+}
+
/**
* 命令の名前とタイプから、命令コードを返す\n
* 無効な場合は0xFFFFを返す
WORD w = 0xFFFF;
assert(cmd != NULL);
- for(p = cmdtype_code[hash_cmdtype(cmd, type)]; p != NULL; p = p->next) {
+ for(p = cmdtab[HASH_CMDTYPE][hash_cmdtype(cmd, type)]; p != NULL; p = p->next) {
if(strcmp(cmd, p->cmd->name) == 0 && type == p->cmd->type) {
w = p->cmd->code;
break;
return w;
}
-/**
- * 名前とタイプがキーの命令ハッシュ表を解放する
- */
-void free_cmdtype_code()
-{
- int i;
- CMDTAB *p, *q;
-
- for(i = 0; i < CMDTABSIZE; i++) {
- for(p = cmdtype_code[i]; p != NULL; p = q) {
- q = p->next;
- FREE(p);
- }
- }
-}
-
/**
* 命令コードからハッシュ値を生成する
*/
return h;
}
-/**
- * コードがキーの命令ハッシュ表を作成する
- */
-bool create_code_cmdtype()
-{
- CMDTAB *p;
- unsigned hashval;
- int i;
-
- for(i = 0; i < comet2cmdsize; i++) {
- hashval = hash_code((&comet2cmd[i])->code); /* ハッシュ値の生成 */
- p = malloc_chk(sizeof(CMDTAB), "code_cmdtype");
- p->cmd = &comet2cmd[i];
- p->next = code_cmdtype[hashval]; /* ハッシュ表に値を追加 */
- code_cmdtype[hashval] = p;
- }
- return true;
-}
-
/**
* 命令コードから命令の関数ポインタを返す
*/
CMDTAB *t;
const void *ptr = NULL;
- for(t = code_cmdtype[hash_code(code)]; t != NULL; t = t->next) {
+ for(t = cmdtab[HASH_CODE][hash_code(code)]; t != NULL; t = t->next) {
if(code == t->cmd->code) {
ptr = t->cmd->ptr;
break;
CMDTYPE getcmdtype(WORD code)
{
CMDTAB *t;
- CMDTYPE type = 0;
+ CMDTYPE type = NONE;
- for(t = code_cmdtype[hash_code(code)]; t != NULL; t = t->next) {
+ for(t = cmdtab[HASH_CODE][hash_code(code)]; t != NULL; t = t->next) {
if(code == t->cmd->code) {
type = t->cmd->type;
break;
CMDTAB *t;
char *cmd = NULL;
- for(t = code_cmdtype[hash_code(code)]; t != NULL; t = t->next) {
+ for(t = cmdtab[HASH_CODE][hash_code(code)]; t != NULL; t = t->next) {
if(code == t->cmd->code) {
cmd = t->cmd->name;
break;
}
/**
- * コードがキーの命令ハッシュ表を解放する
+ * 汎用レジスタの番号からレジスタを表す文字列を返す
*/
-void free_code_cmdtype()
+
+char *grstr(WORD word)
{
- int i;
- CMDTAB *p, *q;
- for(i = 0; i < CMDTABSIZE; i++) {
- for(p = code_cmdtype[i]; p != NULL; p = q) {
- q = p->next;
- FREE(p);
- }
- }
+ assert(word <= 7);
+ char *str = malloc_chk(3 + 1, "grstr.str");
+ sprintf(str, "GR%d", word);
+ return str;
}
/**