Skip to content

Commit

Permalink
CachedInterpreter: Use an enum class for instruction type
Browse files Browse the repository at this point in the history
  • Loading branch information
lioncash committed Mar 25, 2018
1 parent b68952f commit 071da46
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions Source/Core/Core/PowerPC/CachedInterpreter/CachedInterpreter.cpp
Expand Up @@ -20,29 +20,32 @@ struct CachedInterpreter::Instruction
typedef void (*CommonCallback)(UGeckoInstruction);
typedef bool (*ConditionalCallback)(u32 data);

Instruction() : type(INSTRUCTION_ABORT) {}
Instruction() {}
Instruction(const CommonCallback c, UGeckoInstruction i)
: common_callback(c), data(i.hex), type(INSTRUCTION_TYPE_COMMON)
: common_callback(c), data(i.hex), type(Type::Common)
{
}

Instruction(const ConditionalCallback c, u32 d)
: conditional_callback(c), data(d), type(INSTRUCTION_TYPE_CONDITIONAL)
: conditional_callback(c), data(d), type(Type::Conditional)
{
}

enum class Type
{
Abort,
Common,
Conditional,
};

union
{
const CommonCallback common_callback;
const ConditionalCallback conditional_callback;
};
u32 data;
enum
{
INSTRUCTION_ABORT,
INSTRUCTION_TYPE_COMMON,
INSTRUCTION_TYPE_CONDITIONAL,
} type;

u32 data = 0;
Type type = Type::Abort;
};

CachedInterpreter::CachedInterpreter() : code_buffer(32000)
Expand Down Expand Up @@ -86,15 +89,15 @@ void CachedInterpreter::ExecuteOneBlock()

const Instruction* code = reinterpret_cast<const Instruction*>(normal_entry);

for (; code->type != Instruction::INSTRUCTION_ABORT; ++code)
for (; code->type != Instruction::Type::Abort; ++code)
{
switch (code->type)
{
case Instruction::INSTRUCTION_TYPE_COMMON:
case Instruction::Type::Common:
code->common_callback(UGeckoInstruction(code->data));
break;

case Instruction::INSTRUCTION_TYPE_CONDITIONAL:
case Instruction::Type::Conditional:
if (code->conditional_callback(code->data))
return;
break;
Expand Down

0 comments on commit 071da46

Please sign in to comment.