Changed execute function to use function pointer array w/ S
This commit is contained in:
parent
297ec15436
commit
24fd0c4ad6
@ -16,44 +16,33 @@
|
|||||||
// instruction if the shift flag is enabled.
|
// instruction if the shift flag is enabled.
|
||||||
#define DPI_WIDEMOV_SHIFT 16
|
#define DPI_WIDEMOV_SHIFT 16
|
||||||
|
|
||||||
|
// Type definition for a pointer to a function that executes a particular type
|
||||||
|
// of a64instruction (requires pointer to the processor state to update, and a
|
||||||
|
// pointer to the instruction struct to execute).
|
||||||
|
typedef void (*executeFunction)(Machine *, a64inst_instruction *);
|
||||||
|
|
||||||
// Prototypes
|
// Prototypes
|
||||||
static void executeSDT(Machine *state, a64inst_instruction *inst);
|
static void executeSDT(Machine *state, a64inst_instruction *inst);
|
||||||
static void executeBranch(Machine *state, a64inst_instruction *inst);
|
static void executeBranch(Machine *state, a64inst_instruction *inst);
|
||||||
static void executeDPImmediate(Machine *state, a64inst_instruction *inst);
|
static void executeDPImmediate(Machine *state, a64inst_instruction *inst);
|
||||||
static void executeDPRegister(Machine *state, a64inst_instruction *inst);
|
static void executeDPRegister(Machine *state, a64inst_instruction *inst);
|
||||||
|
|
||||||
|
// Halt function definition
|
||||||
|
static void executeHalt(Machine *state, a64inst_instruction *inst) { /*NOP*/ }
|
||||||
|
|
||||||
|
// Define a constant array mapping instruction type enum values to their
|
||||||
|
// corresponding execute functions
|
||||||
|
const executeFunction EXECUTE_FUNCTIONS[] =
|
||||||
|
{&executeDPImmediate,
|
||||||
|
&executeDPRegister,
|
||||||
|
&executeSDT,
|
||||||
|
&executeSDT,
|
||||||
|
&executeBranch,
|
||||||
|
&executeHalt};
|
||||||
|
|
||||||
|
// Main execute function
|
||||||
void execute(Machine *state, a64inst_instruction *inst) {
|
void execute(Machine *state, a64inst_instruction *inst) {
|
||||||
|
EXECUTE_FUNCTIONS[inst->type](state, inst);
|
||||||
switch (inst->type) {
|
|
||||||
|
|
||||||
// Halt the program
|
|
||||||
case a64inst_HALT:
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Execute a data processing immediate instruction
|
|
||||||
case a64inst_DPIMMEDIATE:
|
|
||||||
executeDPImmediate(state, inst);
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Execute a branch instruction
|
|
||||||
case a64inst_BRANCH:
|
|
||||||
executeBranch(state, inst);
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Execute a data processing register instruction
|
|
||||||
case a64inst_DPREGISTER:
|
|
||||||
executeDPRegister(state, inst);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case a64inst_SINGLETRANSFER:
|
|
||||||
executeSDT(state, inst);
|
|
||||||
break;
|
|
||||||
|
|
||||||
// Unknown instruction
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updates N and Z condition codes given the machine and a result value
|
// Updates N and Z condition codes given the machine and a result value
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user