momiji

m68k emulator infrastructure

About Source code

Table of contents

momiji::mapOperand

Defined in header <momiji/Parser.h>

Executes a functor to an [momiji::Operand]({{ ‘/userapi/Parser#typedefs’ | relative_url }}) if it holds an OperandType.


inline bool mapOperand(momiji::Operand& op, Fun&& fn) (1)
  1. This function takes an Operand, a functor and a template (OperandType). It checks that the Operand is of type OperandType (which means the variant is storing that particular type), if it is it calls the functor with the Operand and returns true.
    Parameters:
    • [T] OperandType : The expected operand type to match
    • [T] Fun : Functor with signature void(momiji::Operand&)
    • momiji::Operand& op : The Operand of which to apply the function
    • Fun&& fn : The functor to execute
    Returns: true if it could apply the functor, false otherwise.

Examples

momiji::Operand op = momiji::operands::DataRegister{ 2 };

// ...
// In some generic code down the line:

// This works
mapOperand<momiji::operands::DataRegister>(op, [] (momiji::operands::DataRegister& x) {
    std::cout << x.reg << '\n';
});

// This doesn't
mapOperand<momiji::operands::AddressRegister>(op, [] (momiji::operands::AddressRegister& x) {
    std::cout << x.reg << '\n';
});

// You can also use "auto" and friends, if you know what you're doing
mapOperand<momiji::operands::Immediate>(op, [] (auto&) {
    std::cout << "Matched an immediate!\n";
});