diff options
Diffstat (limited to 'llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp | 46 |
1 files changed, 12 insertions, 34 deletions
diff --git a/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp b/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp index cc77f56dce3..bb10f20fd6d 100644 --- a/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp +++ b/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp @@ -36,50 +36,28 @@ WebAssemblyInstPrinter::WebAssemblyInstPrinter(const MCAsmInfo &MAI, void WebAssemblyInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const { - // FIXME: Revisit whether we actually print the get_local explicitly. - OS << "(get_local " << RegNo << ")"; + if (TargetRegisterInfo::isPhysicalRegister(RegNo)) + OS << getRegisterName(RegNo); + else + OS << TargetRegisterInfo::virtReg2Index(RegNo); } void WebAssemblyInstPrinter::printInst(const MCInst *MI, raw_ostream &OS, StringRef Annot, const MCSubtargetInfo &STI) { printInstruction(MI, OS); - - const MCInstrDesc &Desc = MII.get(MI->getOpcode()); - if (Desc.isVariadic()) - for (unsigned i = Desc.getNumOperands(), e = MI->getNumOperands(); i < e; - ++i) { - OS << ", "; - printOperand(MI, i, OS); - } - printAnnotation(OS, Annot); unsigned NumDefs = MII.get(MI->getOpcode()).getNumDefs(); assert(NumDefs <= 1 && "Instructions with multiple result values not implemented"); - // FIXME: Revisit whether we actually print the set_local explicitly. - if (NumDefs != 0) + if (NumDefs != 0) { OS << "\n" - "\t" "set_local " << MI->getOperand(0).getReg() << ", $pop"; -} - -static std::string toString(const APFloat &FP) { - static const size_t BufBytes = 128; - char buf[BufBytes]; - if (FP.isNaN()) - assert((FP.bitwiseIsEqual(APFloat::getQNaN(FP.getSemantics())) || - FP.bitwiseIsEqual( - APFloat::getQNaN(FP.getSemantics(), /*Negative=*/true))) && - "convertToHexString handles neither SNaN nor NaN payloads"); - // Use C99's hexadecimal floating-point representation. - auto Written = FP.convertToHexString( - buf, /*hexDigits=*/0, /*upperCase=*/false, APFloat::rmNearestTiesToEven); - (void)Written; - assert(Written != 0); - assert(Written < BufBytes); - return buf; + "\t" "set_local "; + printRegName(OS, MI->getOperand(0).getReg()); + OS << ", pop"; + } } void WebAssemblyInstPrinter::printOperand(const MCInst *MI, unsigned OpNo, @@ -87,13 +65,13 @@ void WebAssemblyInstPrinter::printOperand(const MCInst *MI, unsigned OpNo, const MCOperand &Op = MI->getOperand(OpNo); if (Op.isReg()) { if (OpNo < MII.get(MI->getOpcode()).getNumDefs()) - O << "$push"; + O << "push"; else printRegName(O, Op.getReg()); } else if (Op.isImm()) - O << Op.getImm(); + O << '#' << Op.getImm(); else if (Op.isFPImm()) - O << toString(APFloat(Op.getFPImm())); + O << '#' << Op.getFPImm(); else { assert(Op.isExpr() && "unknown operand kind in printOperand"); Op.getExpr()->print(O, &MAI); |