MacroAssemblerPrinter.h [plain text]
#ifndef MacroAssemblerPrinter_h
#define MacroAssemblerPrinter_h
#if ENABLE(MASM_PROBE)
#include "MacroAssembler.h"
namespace JSC {
struct AllRegisters { };
struct PCRegister { };
struct Memory {
using Address = MacroAssembler::Address;
using AbsoluteAddress = MacroAssembler::AbsoluteAddress;
using RegisterID = MacroAssembler::RegisterID;
enum class AddressType {
Address,
AbsoluteAddress,
};
enum DumpStyle {
SingleWordDump,
GenericDump,
};
Memory(RegisterID& reg, size_t bytes, DumpStyle style = GenericDump)
: addressType(AddressType::Address)
, dumpStyle(style)
, numBytes(bytes)
{
u.address = Address(reg, 0);
}
Memory(const Address& address, size_t bytes, DumpStyle style = GenericDump)
: addressType(AddressType::Address)
, dumpStyle(style)
, numBytes(bytes)
{
u.address = address;
}
Memory(const AbsoluteAddress& address, size_t bytes, DumpStyle style = GenericDump)
: addressType(AddressType::AbsoluteAddress)
, dumpStyle(style)
, numBytes(bytes)
{
u.absoluteAddress = address;
}
AddressType addressType;
DumpStyle dumpStyle;
size_t numBytes;
union UnionedAddress {
UnionedAddress() { }
Address address;
AbsoluteAddress absoluteAddress;
} u;
};
template <typename IntType>
struct MemWord : public Memory {
MemWord(RegisterID& reg)
: Memory(reg, sizeof(IntType), Memory::SingleWordDump)
{ }
MemWord(const Address& address)
: Memory(address, sizeof(IntType), Memory::SingleWordDump)
{ }
MemWord(const AbsoluteAddress& address)
: Memory(address, sizeof(IntType), Memory::SingleWordDump)
{ }
};
class MacroAssemblerPrinter {
using CPUState = MacroAssembler::CPUState;
using ProbeContext = MacroAssembler::ProbeContext;
using RegisterID = MacroAssembler::RegisterID;
using FPRegisterID = MacroAssembler::FPRegisterID;
public:
template<typename... Arguments>
static void print(MacroAssembler* masm, Arguments... args)
{
auto argsList = std::make_unique<PrintArgsList>();
appendPrintArg(argsList.get(), args...);
masm->probe(printCallback, argsList.release(), 0);
}
private:
struct PrintArg {
enum class Type {
AllRegisters,
PCRegister,
RegisterID,
FPRegisterID,
Memory,
ConstCharPtr,
ConstVoidPtr,
IntptrValue,
UintptrValue,
};
PrintArg(AllRegisters&)
: type(Type::AllRegisters)
{
}
PrintArg(PCRegister&)
: type(Type::PCRegister)
{
}
PrintArg(RegisterID regID)
: type(Type::RegisterID)
{
u.gpRegisterID = regID;
}
PrintArg(FPRegisterID regID)
: type(Type::FPRegisterID)
{
u.fpRegisterID = regID;
}
PrintArg(const Memory& memory)
: type(Type::Memory)
{
u.memory = memory;
}
PrintArg(const char* ptr)
: type(Type::ConstCharPtr)
{
u.constCharPtr = ptr;
}
PrintArg(const void* ptr)
: type(Type::ConstVoidPtr)
{
u.constVoidPtr = ptr;
}
PrintArg(int value)
: type(Type::IntptrValue)
{
u.intptrValue = value;
}
PrintArg(unsigned value)
: type(Type::UintptrValue)
{
u.intptrValue = value;
}
PrintArg(intptr_t value)
: type(Type::IntptrValue)
{
u.intptrValue = value;
}
PrintArg(uintptr_t value)
: type(Type::UintptrValue)
{
u.uintptrValue = value;
}
Type type;
union Value {
Value() { }
RegisterID gpRegisterID;
FPRegisterID fpRegisterID;
Memory memory;
const char* constCharPtr;
const void* constVoidPtr;
intptr_t intptrValue;
uintptr_t uintptrValue;
} u;
};
typedef Vector<PrintArg> PrintArgsList;
template<typename FirstArg, typename... Arguments>
static void appendPrintArg(PrintArgsList* argsList, FirstArg& firstArg, Arguments... otherArgs)
{
argsList->append(PrintArg(firstArg));
appendPrintArg(argsList, otherArgs...);
}
static void appendPrintArg(PrintArgsList*) { }
private:
static void printCallback(ProbeContext*);
};
template<typename... Arguments>
void MacroAssembler::print(Arguments... args)
{
MacroAssemblerPrinter::print(this, args...);
}
void printCPU(MacroAssembler::CPUState&, int indentation = 0);
void printCPURegisters(MacroAssembler::CPUState&, int indentation = 0);
void printRegister(MacroAssembler::CPUState&, MacroAssembler::RegisterID);
void printRegister(MacroAssembler::CPUState&, MacroAssembler::FPRegisterID);
void printMemory(MacroAssembler::CPUState&, const Memory&);
}
#endif // ENABLE(MASM_PROBE)
#endif // MacroAssemblerPrinter_h