llvm.org GIT mirror llvm / 26edbcb
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 Jim Grosbach 9 years ago
3 changed file(s) with 29 addition(s) and 3 deletion(s). Raw diff Collapse all Expand all
1515 #ifndef LLVM_MC_MCINST_H
1616 #define LLVM_MC_MCINST_H
1717
18 #include "llvm/ADT/APFloat.h"
1819 #include "llvm/ADT/SmallVector.h"
1920 #include "llvm/ADT/StringRef.h"
2021 #include "llvm/System/DataTypes.h"
3233 kInvalid, ///< Uninitialized.
3334 kRegister, ///< Register operand.
3435 kImmediate, ///< Immediate operand.
36 kFPImmediate, ///< Floating-point immediate operand.
3537 kExpr ///< Relocatable immediate operand.
3638 };
3739 unsigned char Kind;
4143 int64_t ImmVal;
4244 const MCExpr *ExprVal;
4345 };
46 // This can't go in the union due to the non-trivial copy constructor
47 // of APFloat. It's still only valid for Kind == kFPImmediate, though.
48 APFloat FPImmVal;
4449 public:
4550
46 MCOperand() : Kind(kInvalid) {}
51 MCOperand() : Kind(kInvalid), FPImmVal(0.0) {}
4752
4853 bool isValid() const { return Kind != kInvalid; }
4954 bool isReg() const { return Kind == kRegister; }
5055 bool isImm() const { return Kind == kImmediate; }
56 bool isFPImm() const { return Kind == kFPImmediate; }
5157 bool isExpr() const { return Kind == kExpr; }
5258
5359 /// getReg - Returns the register number.
7177 ImmVal = Val;
7278 }
7379
80 const APFloat &getFPImm() const {
81 assert(isFPImm() && "This is not an FP immediate");
82 return FPImmVal;
83 }
84
85 void setFPImm(const APFloat &Val) {
86 assert(isFPImm() && "This is not an FP immediate");
87 FPImmVal = Val;
88 }
89
7490 const MCExpr *getExpr() const {
7591 assert(isExpr() && "This is not an expression");
7692 return ExprVal;
90106 MCOperand Op;
91107 Op.Kind = kImmediate;
92108 Op.ImmVal = Val;
109 return Op;
110 }
111 static MCOperand CreateFPImm(const APFloat &Val) {
112 MCOperand Op;
113 Op.Kind = kFPImmediate;
114 Op.FPImmVal = Val;
93115 return Op;
94116 }
95117 static MCOperand CreateExpr(const MCExpr *Val) {
1515 #include "ARMMCInstLower.h"
1616 //#include "llvm/CodeGen/MachineModuleInfoImpls.h"
1717 #include "llvm/CodeGen/AsmPrinter.h"
18 #include "llvm/Constants.h"
1819 #include "llvm/CodeGen/MachineBasicBlock.h"
1920 #include "llvm/MC/MCAsmInfo.h"
2021 #include "llvm/MC/MCContext.h"
154155 MCOp = LowerSymbolOperand(MO, Printer.GetBlockAddressSymbol(
155156 MO.getBlockAddress()));
156157 break;
158 case MachineOperand::MO_FPImmediate:
159 MCOp = MCOperand::CreateFPImm(MO.getFPImm()->getValueAPF());
160 break;
157161 }
158162
159163 OutMI.addOperand(MCOp);
728728
729729 void ARMInstPrinter::printVFPf32ImmOperand(const MCInst *MI, unsigned OpNum,
730730 raw_ostream &O) {
731 O << '#' << MI->getOperand(OpNum).getImm();
731 O << '#' << MI->getOperand(OpNum).getFPImm().convertToFloat();
732732 }
733733
734734 void ARMInstPrinter::printVFPf64ImmOperand(const MCInst *MI, unsigned OpNum,
735735 raw_ostream &O) {
736 O << '#' << MI->getOperand(OpNum).getImm();
736 O << '#' << MI->getOperand(OpNum).getFPImm().convertToDouble();
737737 }
738738
739739 void ARMInstPrinter::printNEONModImmOperand(const MCInst *MI, unsigned OpNum,