// specifies the encoding used by the instruction, as well as a helper function
// to convert the enums to printable char strings.
//
-// It also contains code to represent the concepts of Builder, Builder Factory,
-// as well as the Algorithm to solve the problem of disassembling an ARM instr.
+// It also contains code to represent the concepts of Builder and DisassembleFP
+// to solve the problem of disassembling an ARM instr.
//
//===----------------------------------------------------------------------===//
/// Various utilities for checking the target specific flags.
/// A unary data processing instruction doesn't have an Rn operand.
-static inline bool isUnaryDP(unsigned TSFlags) {
+static inline bool isUnaryDP(uint64_t TSFlags) {
return (TSFlags & ARMII::UnaryDP);
}
/// This four-bit field describes the addressing mode used.
/// See also ARMBaseInstrInfo.h.
-static inline unsigned getAddrMode(unsigned TSFlags) {
+static inline unsigned getAddrMode(uint64_t TSFlags) {
return (TSFlags & ARMII::AddrModeMask);
}
/// {IndexModePre, IndexModePost}
/// Only valid for load and store ops.
/// See also ARMBaseInstrInfo.h.
-static inline unsigned getIndexMode(unsigned TSFlags) {
+static inline unsigned getIndexMode(uint64_t TSFlags) {
return (TSFlags & ARMII::IndexModeMask) >> ARMII::IndexModeShift;
}
/// Pre-/post-indexed operations define an extra $base_wb in the OutOperandList.
-static inline bool isPrePostLdSt(unsigned TSFlags) {
+static inline bool isPrePostLdSt(uint64_t TSFlags) {
return (TSFlags & ARMII::IndexModeMask) != 0;
}
typedef bool (*DisassembleFP)(MCInst &MI, unsigned Opcode, uint32_t insn,
unsigned short NumOps, unsigned &NumOpsAdded, BO Builder);
-/// ARMAlgorithm - ARMAlgorithm implements the ARM/Thumb disassembly by solving
-/// the problem of building the MCOperands of an MCInst. Construction of
-/// ARMAlgorithm requires passing in a function pointer with the DisassembleFP
-/// data type.
-class ARMAlgorithm {
-public:
- /// GetInstance - GetInstance returns an instance of ARMAlgorithm given the
- /// encoding Format. API clients should not free up the returned instance.
- static ARMAlgorithm *GetInstance(ARMFormat Format);
-
- /// DoCleanup - DoCleanup is meant to be called upon exit as an exit handler.
- static void DoCleanup();
-
- /// Return true if this algorithm successfully disassembles the instruction.
- /// NumOpsAdded is updated to reflect the number of operands added by the
- /// algorithm. NumOpsAdded may be less than NumOps, in which case, there are
- /// operands unaccounted for which need to be dealt with by the API client.
- bool Solve(MCInst &MI, unsigned Opcode, uint32_t insn, unsigned short NumOps,
- unsigned &NumOpsAdded, BO Builder) const {
- if (Disassemble == NULL)
- return false;
-
- return (*Disassemble)(MI, Opcode, insn, NumOps, NumOpsAdded, Builder);
- }
-
-private:
- ARMAlgorithm(DisassembleFP fp) : Disassemble(fp) {}
- ARMAlgorithm(ARMAlgorithm &AA) : Disassemble(AA.Disassemble) {}
-
- virtual ~ARMAlgorithm() {}
-
- DisassembleFP Disassemble;
-};
+/// CreateMCBuilder - Return an ARMBasicMCBuilder that can build up the MC
+/// infrastructure of an MCInst given the Opcode and Format of the instr.
+/// Return NULL if it fails to create/return a proper builder. API clients
+/// are responsible for freeing up of the allocated memory. Cacheing can be
+/// performed by the API clients to improve performance.
+extern ARMBasicMCBuilder *CreateMCBuilder(unsigned Opcode, ARMFormat Format);
/// ARMBasicMCBuilder - ARMBasicMCBuilder represents an ARM MCInst builder that
/// knows how to build up the MCOperand list.
class ARMBasicMCBuilder {
+ friend ARMBasicMCBuilder *CreateMCBuilder(unsigned Opcode, ARMFormat Format);
unsigned Opcode;
ARMFormat Format;
unsigned short NumOps;
- const ARMAlgorithm &Algo;
+ DisassembleFP Disasm;
Session *SP;
+ int Err; // !=0 if the builder encounters some error condition during build.
+
+private:
+ /// Opcode, Format, and NumOperands make up an ARM Basic MCBuilder.
+ ARMBasicMCBuilder(unsigned opc, ARMFormat format, unsigned short num);
public:
ARMBasicMCBuilder(ARMBasicMCBuilder &B)
- : Opcode(B.Opcode), Format(B.Format), NumOps(B.NumOps), Algo(B.Algo),
- SP(B.SP)
- {}
-
- /// Opcode, Format, NumOperands, and Algo make an ARM Basic MCBuilder.
- ARMBasicMCBuilder(unsigned opc, ARMFormat format, unsigned short num,
- const ARMAlgorithm &algo)
- : Opcode(opc), Format(format), NumOps(num), Algo(algo), SP(0)
- {}
+ : Opcode(B.Opcode), Format(B.Format), NumOps(B.NumOps), Disasm(B.Disasm),
+ SP(B.SP) {
+ Err = 0;
+ }
virtual ~ARMBasicMCBuilder() {}
- void setSession(Session *sp) {
+ void SetSession(Session *sp) {
SP = sp;
}
+ void SetErr(int ErrCode) {
+ Err = ErrCode;
+ }
+
+ /// DoPredicateOperands - DoPredicateOperands process the predicate operands
+ /// of some Thumb instructions which come before the reglist operands. It
+ /// returns true if the two predicate operands have been processed.
+ bool DoPredicateOperands(MCInst& MI, unsigned Opcode,
+ uint32_t insn, unsigned short NumOpsRemaning);
+
/// TryPredicateAndSBitModifier - TryPredicateAndSBitModifier tries to process
/// the possible Predicate and SBitModifier, to build the remaining MCOperand
/// constituents.
/// BuildIt - BuildIt performs the build step for this ARM Basic MC Builder.
/// The general idea is to set the Opcode for the MCInst, followed by adding
/// the appropriate MCOperands to the MCInst. ARM Basic MC Builder delegates
- /// to the Algo (ARM Disassemble Algorithm) object to perform Format-specific
- /// disassembly, followed by class method TryPredicateAndSBitModifier() to do
- /// PredicateOperand and OptionalDefOperand which follow the Dst/Src Operands.
+ /// to the Format-specific disassemble function for disassembly, followed by
+ /// TryPredicateAndSBitModifier() for PredicateOperand and OptionalDefOperand
+ /// which follow the Dst/Src Operands.
virtual bool BuildIt(MCInst &MI, uint32_t insn);
/// RunBuildAfterHook - RunBuildAfterHook performs operations deemed necessary
}
};
-/// CreateMCBuilder - Return an ARMBasicMCBuilder that can build up the MC
-/// infrastructure of an MCInst given the Opcode and Format of the instr.
-/// Return NULL if it fails to create/return a proper builder. API clients
-/// are responsible for freeing up of the allocated memory. Cacheing can be
-/// performed by the API clients to improve performance.
-extern ARMBasicMCBuilder *CreateMCBuilder(unsigned Opcode, ARMFormat Format);
-
} // namespace llvm
#endif