diff options
author | JF Bastien <jfb@google.com> | 2015-08-10 22:36:48 +0000 |
---|---|---|
committer | JF Bastien <jfb@google.com> | 2015-08-10 22:36:48 +0000 |
commit | 4a6422562d797fd2d860800992620a4a16021872 (patch) | |
tree | 533f3c34b3ac56a211f6bdb055220a18f6ff4c0c /llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp | |
parent | 6dce129051d849509727fdb953416a5c0fdbdc7c (diff) | |
download | bcm5719-llvm-4a6422562d797fd2d860800992620a4a16021872.tar.gz bcm5719-llvm-4a6422562d797fd2d860800992620a4a16021872.zip |
WebAssembly: print immediates
Summary:
For now output using C99's hexadecimal floating-point representation.
This patch also cleans up how machine operands are printed: instead of special-casing per type of machine instruction, the code now handles operands generically.
Reviewers: sunfish
Subscribers: llvm-commits, jfb
Differential Revision: http://reviews.llvm.org/D11914
llvm-svn: 244520
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp | 46 |
1 files changed, 27 insertions, 19 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp index 99b23c7433b..35a4be3805d 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp @@ -99,28 +99,36 @@ void WebAssemblyAsmPrinter::EmitInstruction(const MachineInstr *MI) { OS << "(setlocal @" << TargetRegisterInfo::virtReg2Index(Reg) << ' '; } - OS << '('; - - bool PrintOperands = true; - switch (MI->getOpcode()) { - case WebAssembly::ARGUMENT_Int32: - case WebAssembly::ARGUMENT_Int64: - case WebAssembly::ARGUMENT_Float32: - case WebAssembly::ARGUMENT_Float64: - OS << Name(TII, MI) << ' ' << MI->getOperand(1).getImm(); - PrintOperands = false; - break; - default: - OS << Name(TII, MI); - break; - } - - if (PrintOperands) - for (const MachineOperand &MO : MI->uses()) { - if (MO.isReg() && MO.isImplicit()) + OS << '(' << Name(TII, MI); + for (const MachineOperand &MO : MI->uses()) + switch (MO.getType()) { + default: + llvm_unreachable("unexpected machine operand type"); + case MachineOperand::MO_Register: { + if (MO.isImplicit()) continue; unsigned Reg = MO.getReg(); OS << " @" << TargetRegisterInfo::virtReg2Index(Reg); + } break; + case MachineOperand::MO_Immediate: { + OS << ' ' << MO.getImm(); + } break; + case MachineOperand::MO_FPImmediate: { + static const size_t BufBytes = 128; + char buf[BufBytes]; + APFloat FP = MO.getFPImm()->getValueAPF(); + const APFloat CanonicalNaN = APFloat::getQNaN(FP.getSemantics()); + if (FP.isNaN() && !FP.bitwiseIsEqual(CanonicalNaN)) + // WebAssembly only has NaNs that are positive, quiet, without payload. + FP = CanonicalNaN; + // Use C99's hexadecimal floating-point representation. + auto Written = + FP.convertToHexString(buf, /*hexDigits=*/0, /*upperCase=*/false, + APFloat::rmNearestTiesToEven); + assert(Written != 0); + assert(Written < BufBytes); + OS << ' ' << buf; + } break; } OS << ')'; |