momiji
m68k emulator infrastructure
About Source codeTable of contents
momiji::extractRegister
Defined in header <momiji/Parser.h>
std::int32_t extractRegister(const Operand& operand) |
(1) |
-
Parameters:
-
const momiji::Operand& operand
: The operand of which the function should extract the value of the register.
-
This function takes any Operand: if it is a RegOperand then it will return the stored register number, else it will return zero.
This is mostly useful in generic code, otherwise one should have to switch on the Operand variant, and that would be annoying.
Example
Instead of this:
momiji::Operand op = /* ... */;
// ...
// A call stack later
std::int32_t regval = 0;
std::visit(op, asl::overloaded{
[®val] (const momiji::operands::DataRegister& op) {
regval = op.reg;
},
[®val] (const momiji::operands::AddressRegister& op) {
regval = op.reg;
},
[®val] (const momiji::operands::Address& op) {
regval = op.reg;
},
// Repeat for all the other classes that expose 'reg'
// ...
[] (auto&&) {
// Do nothing if none of the above
}
});
You can write this instead:
momiji::Operand op = /* ... */;
const std::int32_t regval = momiji::extractReg(op);