#include "opcodes.h" #include "hash.h" #include "optable.h" OpcodeInfo opcodeTable[NOF_OPCODES] = { { "mov", OPCODE_MOV_MASK, 2 }, { "or", OPCODE_OR, 2 }, { "and", OPCODE_AND, 2 }, { "sub", OPCODE_SUB, 2 }, { "add", OPCODE_ADD, 2 }, { "cmp", OPCODE_CMP, 2 }, { "jmp", OPCODE_JMP | OPCODE_JMP_JMP, 1 }, { "je", OPCODE_JMP | OPCODE_JMP_JE, 1 }, { "jne", OPCODE_JMP | OPCODE_JMP_JNE, 1 }, { "ja", OPCODE_JMP | OPCODE_JMP_JA, 1 }, { "jae", OPCODE_JMP | OPCODE_JMP_JAE, 1 }, { "jb", OPCODE_JMP | OPCODE_JMP_JB, 1 }, { "jbe", OPCODE_JMP | OPCODE_JMP_JBE, 1 }, { "jsr", OPCODE_JMP | OPCODE_JMP_JSR, 1 }, { "not", OPCODE_NOT, 1 }, { "push", OPCODE_STACK | OPCODE_STACK_PUSH, 1 }, { "pop", OPCODE_STACK | OPCODE_STACK_POP, 1 }, { "nop", OPCODE_NOP, 0 }, { "hlt", OPCODE_HLT, 0 }, { "ret", OPCODE_RET, 0 } }; intHashTable opcode_ht; void opcode_table_init( ) { int i; inthash_init( &opcode_ht, NOF_OPCODES ); for( i = 0; i < NOF_OPCODES; i++ ) { inthash_set( &opcode_ht, opcodeTable[i].mnemonic, i ); } } void opcode_table_done( ) { inthash_done( &opcode_ht ); } OpcodeInfo *lookup_opcode( char *mnemonic ) { int idx; idx = inthash_get( &opcode_ht, mnemonic ); if( idx >= 0 ) { return &opcodeTable[idx]; } return 0; }