#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "instructions_m32c.h"

typedef struct M32C_Instruction M32C_Instruction; 
typedef void M32C_InstructionProc(void);
typedef bool M32C_CheckAMExistence(M32C_Instruction *instr,uint32_t icode);

struct M32C_Instruction {
        uint32_t mask;
        uint32_t icode;
        char *name;
	int len;
        M32C_InstructionProc *proc;
	M32C_CheckAMExistence *existCheckProc;	
	struct M32C_Instruction **iTab;
};

extern M32C_Instruction **m32c_iTab;

void M32C_IDecoderNew(void);

static inline M32C_Instruction *
M32C_InstructionFind(uint32_t icode) 
{
	M32C_Instruction *instr;
	instr = m32c_iTab[icode >> 8];
	if(instr->proc) {
		return instr;
	} else {
		return instr->iTab[icode & 0xff];
	}
}
#if 0
static inline M32C_InstructionProc *
M32C_InstructionProcFind(uint16_t icode) 
{
	return m32c_und;
        //return iProcTab[icode];
}
#endif

static inline int
M32C_InstructionLen(icode) {
	M32C_Instruction *instr = M32C_InstructionFind(icode);
	return instr->len;
}
