//===- X86DisassemblerTables.cpp - Disassembler tables ----------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file is part of the X86 Disassembler Emitter. // It contains the implementation of the disassembler tables. // Documentation for the disassembler emitter in general can be found in // X86DisassemblerEmitter.h. // //===----------------------------------------------------------------------===// #include "X86DisassemblerTables.h" #include "X86DisassemblerShared.h" #include "X86ModRMFilters.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/Format.h" #include "llvm/Support/raw_ostream.h" #include <map> usingnamespacellvm; usingnamespaceX86Disassembler; /// stringForContext - Returns a string containing the name of a particular /// InstructionContext, usually for diagnostic purposes. /// /// @param insnContext - The instruction class to transform to a string. /// @return - A statically-allocated string constant that contains the /// name of the instruction class. static inline const char *stringForContext(InstructionContext insnContext) { … } /// stringForOperandType - Like stringForContext, but for OperandTypes. static inline const char *stringForOperandType(OperandType type) { … } /// stringForOperandEncoding - like stringForContext, but for /// OperandEncodings. static inline const char *stringForOperandEncoding(OperandEncoding encoding) { … } /// inheritsFrom - Indicates whether all instructions in one class also belong /// to another class. /// /// @param child - The class that may be the subset /// @param parent - The class that may be the superset /// @return - True if child is a subset of parent, false otherwise. static inline bool inheritsFrom(InstructionContext child, InstructionContext parent, bool noPrefix = true, bool VEX_LIG = false, bool WIG = false, bool AdSize64 = false) { … } /// outranks - Indicates whether, if an instruction has two different applicable /// classes, which class should be preferred when performing decode. This /// imposes a total ordering (ties are resolved toward "lower") /// /// @param upper - The class that may be preferable /// @param lower - The class that may be less preferable /// @return - True if upper is to be preferred, false otherwise. static inline bool outranks(InstructionContext upper, InstructionContext lower) { … } /// getDecisionType - Determines whether a ModRM decision with 255 entries can /// be compacted by eliminating redundant information. /// /// @param decision - The decision to be compacted. /// @return - The compactest available representation for the decision. static ModRMDecisionType getDecisionType(ModRMDecision &decision) { … } /// stringForDecisionType - Returns a statically-allocated string corresponding /// to a particular decision type. /// /// @param dt - The decision type. /// @return - A pointer to the statically-allocated string (e.g., /// "MODRM_ONEENTRY" for MODRM_ONEENTRY). static const char *stringForDecisionType(ModRMDecisionType dt) { … } DisassemblerTables::DisassemblerTables() { … } DisassemblerTables::~DisassemblerTables() { … } void DisassemblerTables::emitModRMDecision(raw_ostream &o1, raw_ostream &o2, unsigned &i1, unsigned &i2, unsigned &ModRMTableNum, ModRMDecision &decision) const { … } void DisassemblerTables::emitOpcodeDecision(raw_ostream &o1, raw_ostream &o2, unsigned &i1, unsigned &i2, unsigned &ModRMTableNum, OpcodeDecision &opDecision) const { … } void DisassemblerTables::emitContextDecision(raw_ostream &o1, raw_ostream &o2, unsigned &i1, unsigned &i2, unsigned &ModRMTableNum, ContextDecision &decision, const char *name) const { … } void DisassemblerTables::emitInstructionInfo(raw_ostream &o, unsigned &i) const { … } void DisassemblerTables::emitContextTable(raw_ostream &o, unsigned &i) const { … } void DisassemblerTables::emitContextDecisions(raw_ostream &o1, raw_ostream &o2, unsigned &i1, unsigned &i2, unsigned &ModRMTableNum) const { … } void DisassemblerTables::emit(raw_ostream &o) const { … } void DisassemblerTables::setTableFields(ModRMDecision &decision, const ModRMFilter &filter, InstrUID uid, uint8_t opcode) { … } void DisassemblerTables::setTableFields( OpcodeType type, InstructionContext insnContext, uint8_t opcode, const ModRMFilter &filter, InstrUID uid, bool is32bit, bool noPrefix, bool ignoresVEX_L, bool ignoresW, unsigned addressSize) { … }