LLVM  4.0.0
Classes | Macros | Functions
X86DisassemblerDecoder.cpp File Reference
#include <cstdarg>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "X86DisassemblerDecoder.h"
#include "X86GenDisassemblerTables.inc"
Include dependency graph for X86DisassemblerDecoder.cpp:

Go to the source code of this file.

Classes

struct  ModRMDecision
 Specifies whether a ModR/M byte is needed and (if so) which instruction each possible value of the ModR/M byte corresponds to. More...
 
struct  OpcodeDecision
 Specifies which set of ModR/M->instruction tables to look at given a particular opcode. More...
 
struct  ContextDecision
 Specifies which opcode->instruction tables to look at given a particular context (set of attributes). More...
 

Macros

#define debug(s)   do { Debug(__FILE__, __LINE__, s); } while (0)
 
#define CONSUME_FUNC(name, type)
 
#define GENERIC_FIXUP_FUNC(name, base, prefix)
 

Functions

static InstructionContext contextForAttrs (uint16_t attrMask)
 
static int modRMRequired (OpcodeType type, InstructionContext insnContext, uint16_t opcode)
 
static InstrUID decode (OpcodeType type, InstructionContext insnContext, uint8_t opcode, uint8_t modRM)
 
static const struct
InstructionSpecifier
specifierForUID (InstrUID uid)
 
static int consumeByte (struct InternalInstruction *insn, uint8_t *byte)
 
static int lookAtByte (struct InternalInstruction *insn, uint8_t *byte)
 
static void unconsumeByte (struct InternalInstruction *insn)
 
static void dbgprintf (struct InternalInstruction *insn, const char *format,...)
 
static void setPrefixPresent (struct InternalInstruction *insn, uint8_t prefix, uint64_t location)
 
static bool isPrefixAtLocation (struct InternalInstruction *insn, uint8_t prefix, uint64_t location)
 
static int readPrefixes (struct InternalInstruction *insn)
 
static int readOpcode (struct InternalInstruction *insn)
 
static int readModRM (struct InternalInstruction *insn)
 
static int getIDWithAttrMask (uint16_t *instructionID, struct InternalInstruction *insn, uint16_t attrMask)
 
static bool is16BitEquivalent (const char *orig, const char *equiv)
 
static bool is64Bit (const char *name)
 
static int getID (struct InternalInstruction *insn, const void *miiArg)
 
static int readSIB (struct InternalInstruction *insn)
 
static int readDisplacement (struct InternalInstruction *insn)
 
static int fixupReg (struct InternalInstruction *insn, const struct OperandSpecifier *op)
 
static int readOpcodeRegister (struct InternalInstruction *insn, uint8_t size)
 
static int readImmediate (struct InternalInstruction *insn, uint8_t size)
 
static int readVVVV (struct InternalInstruction *insn)
 
static int readMaskRegister (struct InternalInstruction *insn)
 
static int readOperands (struct InternalInstruction *insn)
 

Macro Definition Documentation

#define CONSUME_FUNC (   name,
  type 
)
Value:
static int name(struct InternalInstruction* insn, type* ptr) { \
type combined = 0; \
unsigned offset; \
for (offset = 0; offset < sizeof(type); ++offset) { \
uint8_t byte; \
int ret = insn->reader(insn->readerArg, \
&byte, \
insn->readerCursor + offset); \
if (ret) \
return ret; \
combined = combined | ((uint64_t)byte << (offset * 8)); \
} \
*ptr = combined; \
insn->readerCursor += sizeof(type); \
return 0; \
}
* if(!EatIfPresent(lltok::kw_thread_local)) return false
ParseOptionalThreadLocal := /*empty.
for(unsigned i=0, e=MI->getNumOperands();i!=e;++i)
The x86 internal instruction, which is produced by the decoder.
static const char * name

Definition at line 221 of file X86DisassemblerDecoder.cpp.

#define debug (   s)    do { Debug(__FILE__, __LINE__, s); } while (0)

Definition at line 51 of file X86DisassemblerDecoder.cpp.

Referenced by decode(), fixupReg(), readImmediate(), readPrefixes(), and readSIB().

#define GENERIC_FIXUP_FUNC (   name,
  base,
  prefix 
)

Definition at line 1452 of file X86DisassemblerDecoder.cpp.

Function Documentation

static int consumeByte ( struct InternalInstruction insn,
uint8_t *  byte 
)
static
static InstructionContext contextForAttrs ( uint16_t  attrMask)
static

Definition at line 64 of file X86DisassemblerDecoder.cpp.

References CONTEXTS_SYM.

Referenced by getIDWithAttrMask().

static void dbgprintf ( struct InternalInstruction insn,
const char *  format,
  ... 
)
static
static InstrUID decode ( OpcodeType  type,
InstructionContext  insnContext,
uint8_t  opcode,
uint8_t  modRM 
)
static
static int fixupReg ( struct InternalInstruction insn,
const struct OperandSpecifier op 
)
static

Definition at line 1538 of file X86DisassemblerDecoder.cpp.

References CASE_ENCODING_RM, dbgprintf(), and debug.

Referenced by readOperands().

static int getID ( struct InternalInstruction insn,
const void *  miiArg 
)
static

Definition at line 873 of file X86DisassemblerDecoder.cpp.

References aaaFromEVEX4of4, bFromEVEX4of4, llvm::StringRef::data(), dbgprintf(), llvm::X86Disassembler::InternalInstruction::displacementSize, getIDWithAttrMask(), llvm::X86Disassembler::GetInstrName(), llvm::X86Disassembler::InternalInstruction::immediateSize, llvm::X86Disassembler::InternalInstruction::instructionID, is16BitEquivalent(), is64Bit(), isPrefixAtLocation(), l2FromEVEX4of4, lFromEVEX4of4, lFromVEX2of2, lFromVEX3of3, lFromXOP3of3, llvm::X86Disassembler::InternalInstruction::mode, llvm::X86Disassembler::MODE_16BIT, llvm::X86Disassembler::MODE_64BIT, llvm::X86Disassembler::InternalInstruction::necessaryPrefixLocation, llvm::X86Disassembler::ONEBYTE, llvm::X86Disassembler::InternalInstruction::opcode, llvm::X86Disassembler::InternalInstruction::opcodeType, ppFromEVEX3of4, ppFromVEX2of2, ppFromVEX3of3, ppFromXOP3of3, llvm::X86Disassembler::InternalInstruction::prefixPresent, llvm::X86Disassembler::InternalInstruction::rexPrefix, llvm::X86Disassembler::InternalInstruction::spec, specifierForUID(), llvm::X86Disassembler::TWOBYTE, llvm::X86Disassembler::TYPE_EVEX, llvm::X86Disassembler::TYPE_NO_VEX_XOP, llvm::X86Disassembler::TYPE_VEX_2B, llvm::X86Disassembler::TYPE_VEX_3B, llvm::X86Disassembler::TYPE_XOP, llvm::X86Disassembler::InternalInstruction::vectorExtensionPrefix, llvm::X86Disassembler::InternalInstruction::vectorExtensionType, llvm::X86Disassembler::VEX_PREFIX_66, llvm::X86Disassembler::VEX_PREFIX_F2, llvm::X86Disassembler::VEX_PREFIX_F3, wFromEVEX3of4, wFromVEX3of3, wFromXOP3of3, and zFromEVEX4of4.

Referenced by llvm::X86Disassembler::decodeInstruction(), llvm::RegisterBankInfo::InstructionMapping::print(), llvm::MemoryDef::print(), and llvm::MemoryPhi::print().

static int getIDWithAttrMask ( uint16_t *  instructionID,
struct InternalInstruction insn,
uint16_t  attrMask 
)
static
static bool is16BitEquivalent ( const char *  orig,
const char *  equiv 
)
static

Definition at line 828 of file X86DisassemblerDecoder.cpp.

References i.

Referenced by getID().

static bool is64Bit ( const char *  name)
static
static bool isPrefixAtLocation ( struct InternalInstruction insn,
uint8_t  prefix,
uint64_t  location 
)
static
static int lookAtByte ( struct InternalInstruction insn,
uint8_t *  byte 
)
static
static int modRMRequired ( OpcodeType  type,
InstructionContext  insnContext,
uint16_t  opcode 
)
static
static int readDisplacement ( struct InternalInstruction insn)
static
static int readImmediate ( struct InternalInstruction insn,
uint8_t  size 
)
static
static int readMaskRegister ( struct InternalInstruction insn)
static
static int readModRM ( struct InternalInstruction insn)
static
static int readOpcode ( struct InternalInstruction insn)
static
static int readOpcodeRegister ( struct InternalInstruction insn,
uint8_t  size 
)
static
static int readOperands ( struct InternalInstruction insn)
static
static int readPrefixes ( struct InternalInstruction insn)
static

Definition at line 323 of file X86DisassemblerDecoder.cpp.

References llvm::X86Disassembler::InternalInstruction::addressSize, bFromEVEX2of4, bFromVEX2of3, bFromXOP2of3, consumeByte(), dbgprintf(), debug, llvm::X86Disassembler::InternalInstruction::displacementSize, llvm::X86Disassembler::InternalInstruction::immediateSize, llvm::HexagonMCInstrInfo::isPrefix(), lookAtByte(), llvm::X86Disassembler::InternalInstruction::mode, llvm::X86Disassembler::MODE_16BIT, llvm::X86Disassembler::MODE_32BIT, llvm::X86Disassembler::MODE_64BIT, llvm::X86Disassembler::InternalInstruction::necessaryPrefixLocation, ppFromVEX2of2, ppFromXOP3of3, llvm::X86Disassembler::InternalInstruction::readerCursor, llvm::X86Disassembler::InternalInstruction::registerSize, llvm::X86Disassembler::InternalInstruction::rexPrefix, rFromEVEX2of4, rFromVEX2of2, rFromVEX2of3, rFromXOP2of3, llvm::X86Disassembler::SEG_OVERRIDE_CS, llvm::X86Disassembler::SEG_OVERRIDE_DS, llvm::X86Disassembler::SEG_OVERRIDE_ES, llvm::X86Disassembler::SEG_OVERRIDE_FS, llvm::X86Disassembler::SEG_OVERRIDE_GS, llvm::X86Disassembler::SEG_OVERRIDE_SS, llvm::X86Disassembler::InternalInstruction::segmentOverride, setPrefixPresent(), llvm::X86Disassembler::InternalInstruction::startLocation, llvm::X86Disassembler::TYPE_EVEX, llvm::X86Disassembler::TYPE_NO_VEX_XOP, llvm::X86Disassembler::TYPE_VEX_2B, llvm::X86Disassembler::TYPE_VEX_3B, llvm::X86Disassembler::TYPE_XOP, unconsumeByte(), llvm::X86Disassembler::InternalInstruction::vectorExtensionPrefix, llvm::X86Disassembler::InternalInstruction::vectorExtensionType, llvm::X86Disassembler::VEX_PREFIX_66, wFromEVEX3of4, wFromREX, wFromVEX3of3, wFromXOP3of3, llvm::X86Disassembler::InternalInstruction::xAcquireRelease, xFromEVEX2of4, xFromVEX2of3, and xFromXOP2of3.

Referenced by llvm::X86Disassembler::decodeInstruction().

static int readSIB ( struct InternalInstruction insn)
static
static int readVVVV ( struct InternalInstruction insn)
static
static void setPrefixPresent ( struct InternalInstruction insn,
uint8_t  prefix,
uint64_t  location 
)
static
static const struct InstructionSpecifier* specifierForUID ( InstrUID  uid)
static

Definition at line 183 of file X86DisassemblerDecoder.cpp.

References INSTRUCTIONS_SYM.

Referenced by getID().

static void unconsumeByte ( struct InternalInstruction insn)
static