diff options
author | Jim Grosbach <grosbach@apple.com> | 2010-09-15 18:47:08 +0000 |
---|---|---|
committer | Jim Grosbach <grosbach@apple.com> | 2010-09-15 18:47:08 +0000 |
commit | 26edbcb8d5da5fb65816a97f740c9868fa798df4 (patch) | |
tree | 7f20db4d589e18fa0bc2e062e75458d82ea173e3 /include/llvm/MC/MCInst.h | |
parent | 27ede1ba6daa893557db477fe3252084fd9f6147 (diff) | |
download | llvm-26edbcb8d5da5fb65816a97f740c9868fa798df4.tar.gz llvm-26edbcb8d5da5fb65816a97f740c9868fa798df4.tar.bz2 llvm-26edbcb8d5da5fb65816a97f740c9868fa798df4.tar.xz |
Add support for floating point immediates to MC instruction printing. ARM
VFP instructions use it for loading some constants, so implement that
handling.
Not thrilled with adding a member to MCOperand, but not sure there's much of
a better option that's not pretty fragile (like putting a double in the
union instead and just assuming that's good enough). Suggestions welcome...
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113996 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/MC/MCInst.h')
-rw-r--r-- | include/llvm/MC/MCInst.h | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/include/llvm/MC/MCInst.h b/include/llvm/MC/MCInst.h index bd1b58a05a..f008b2036c 100644 --- a/include/llvm/MC/MCInst.h +++ b/include/llvm/MC/MCInst.h @@ -16,6 +16,7 @@ #ifndef LLVM_MC_MCINST_H #define LLVM_MC_MCINST_H +#include "llvm/ADT/APFloat.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/System/DataTypes.h" @@ -33,6 +34,7 @@ class MCOperand { kInvalid, ///< Uninitialized. kRegister, ///< Register operand. kImmediate, ///< Immediate operand. + kFPImmediate, ///< Floating-point immediate operand. kExpr ///< Relocatable immediate operand. }; unsigned char Kind; @@ -42,13 +44,17 @@ class MCOperand { int64_t ImmVal; const MCExpr *ExprVal; }; + // This can't go in the union due to the non-trivial copy constructor + // of APFloat. It's still only valid for Kind == kFPImmediate, though. + APFloat FPImmVal; public: - MCOperand() : Kind(kInvalid) {} + MCOperand() : Kind(kInvalid), FPImmVal(0.0) {} bool isValid() const { return Kind != kInvalid; } bool isReg() const { return Kind == kRegister; } bool isImm() const { return Kind == kImmediate; } + bool isFPImm() const { return Kind == kFPImmediate; } bool isExpr() const { return Kind == kExpr; } /// getReg - Returns the register number. @@ -72,6 +78,16 @@ public: ImmVal = Val; } + const APFloat &getFPImm() const { + assert(isFPImm() && "This is not an FP immediate"); + return FPImmVal; + } + + void setFPImm(const APFloat &Val) { + assert(isFPImm() && "This is not an FP immediate"); + FPImmVal = Val; + } + const MCExpr *getExpr() const { assert(isExpr() && "This is not an expression"); return ExprVal; @@ -93,6 +109,12 @@ public: Op.ImmVal = Val; return Op; } + static MCOperand CreateFPImm(const APFloat &Val) { + MCOperand Op; + Op.Kind = kFPImmediate; + Op.FPImmVal = Val; + return Op; + } static MCOperand CreateExpr(const MCExpr *Val) { MCOperand Op; Op.Kind = kExpr; |