JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 1 | //===-- WebAssemblyAsmPrinter.cpp - WebAssembly LLVM assembly writer ------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// |
| 10 | /// \file |
| 11 | /// \brief This file contains a printer that converts from our internal |
| 12 | /// representation of machine-dependent LLVM code to the WebAssembly assembly |
| 13 | /// language. |
| 14 | /// |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
| 17 | #include "WebAssembly.h" |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 18 | #include "InstPrinter/WebAssemblyInstPrinter.h" |
| 19 | #include "MCTargetDesc/WebAssemblyMCTargetDesc.h" |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame^] | 20 | #include "MCTargetDesc/WebAssemblyTargetStreamer.h" |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 21 | #include "WebAssemblyMCInstLower.h" |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 22 | #include "WebAssemblyMachineFunctionInfo.h" |
| 23 | #include "WebAssemblyRegisterInfo.h" |
| 24 | #include "WebAssemblySubtarget.h" |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/StringExtras.h" |
Dan Gohman | 754cd11 | 2015-11-11 01:33:02 +0000 | [diff] [blame] | 26 | #include "llvm/CodeGen/Analysis.h" |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 27 | #include "llvm/CodeGen/AsmPrinter.h" |
JF Bastien | 54be3b1 | 2015-08-25 23:19:49 +0000 | [diff] [blame] | 28 | #include "llvm/CodeGen/MachineConstantPool.h" |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 29 | #include "llvm/CodeGen/MachineInstr.h" |
| 30 | #include "llvm/IR/DataLayout.h" |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 31 | #include "llvm/MC/MCContext.h" |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 32 | #include "llvm/MC/MCStreamer.h" |
JF Bastien | b6091df | 2015-08-25 22:58:05 +0000 | [diff] [blame] | 33 | #include "llvm/MC/MCSymbol.h" |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 34 | #include "llvm/Support/Debug.h" |
| 35 | #include "llvm/Support/TargetRegistry.h" |
| 36 | #include "llvm/Support/raw_ostream.h" |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 37 | using namespace llvm; |
| 38 | |
| 39 | #define DEBUG_TYPE "asm-printer" |
| 40 | |
| 41 | namespace { |
| 42 | |
| 43 | class WebAssemblyAsmPrinter final : public AsmPrinter { |
JF Bastien | 1d20a5e | 2015-10-16 00:53:49 +0000 | [diff] [blame] | 44 | const MachineRegisterInfo *MRI; |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 45 | const WebAssemblyFunctionInfo *MFI; |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 46 | |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 47 | public: |
| 48 | WebAssemblyAsmPrinter(TargetMachine &TM, std::unique_ptr<MCStreamer> Streamer) |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 49 | : AsmPrinter(TM, std::move(Streamer)), MRI(nullptr), MFI(nullptr) {} |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 50 | |
| 51 | private: |
| 52 | const char *getPassName() const override { |
| 53 | return "WebAssembly Assembly Printer"; |
| 54 | } |
| 55 | |
| 56 | //===------------------------------------------------------------------===// |
| 57 | // MachineFunctionPass Implementation. |
| 58 | //===------------------------------------------------------------------===// |
| 59 | |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 60 | bool runOnMachineFunction(MachineFunction &MF) override { |
JF Bastien | 1d20a5e | 2015-10-16 00:53:49 +0000 | [diff] [blame] | 61 | MRI = &MF.getRegInfo(); |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 62 | MFI = MF.getInfo<WebAssemblyFunctionInfo>(); |
JF Bastien | 600aee9 | 2015-07-31 17:53:38 +0000 | [diff] [blame] | 63 | return AsmPrinter::runOnMachineFunction(MF); |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | //===------------------------------------------------------------------===// |
| 67 | // AsmPrinter Implementation. |
| 68 | //===------------------------------------------------------------------===// |
| 69 | |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 70 | void EmitJumpTableInfo() override; |
JF Bastien | 54be3b1 | 2015-08-25 23:19:49 +0000 | [diff] [blame] | 71 | void EmitConstantPool() override; |
JF Bastien | b6091df | 2015-08-25 22:58:05 +0000 | [diff] [blame] | 72 | void EmitFunctionBodyStart() override; |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame^] | 73 | void EmitFunctionBodyEnd() override; |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 74 | void EmitInstruction(const MachineInstr *MI) override; |
Dan Gohman | 26c6765 | 2016-01-11 23:38:05 +0000 | [diff] [blame] | 75 | const MCExpr *lowerConstant(const Constant *CV) override; |
Dan Gohman | f19ed56 | 2015-11-13 01:42:29 +0000 | [diff] [blame] | 76 | bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo, |
| 77 | unsigned AsmVariant, const char *ExtraCode, |
| 78 | raw_ostream &OS) override; |
| 79 | bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo, |
| 80 | unsigned AsmVariant, const char *ExtraCode, |
| 81 | raw_ostream &OS) override; |
Dan Gohman | 979840d | 2015-09-23 16:59:10 +0000 | [diff] [blame] | 82 | |
Dan Gohman | 53828fd | 2015-11-23 16:50:18 +0000 | [diff] [blame] | 83 | MVT getRegType(unsigned RegNo) const; |
Dan Gohman | 754cd11 | 2015-11-11 01:33:02 +0000 | [diff] [blame] | 84 | const char *toString(MVT VT) const; |
JF Bastien | 1d20a5e | 2015-10-16 00:53:49 +0000 | [diff] [blame] | 85 | std::string regToString(const MachineOperand &MO); |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame^] | 86 | WebAssemblyTargetStreamer *getTargetStreamer(); |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | } // end anonymous namespace |
| 90 | |
| 91 | //===----------------------------------------------------------------------===// |
JF Bastien | 45479f6 | 2015-08-26 22:09:54 +0000 | [diff] [blame] | 92 | // Helpers. |
| 93 | //===----------------------------------------------------------------------===// |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 94 | |
Dan Gohman | 53828fd | 2015-11-23 16:50:18 +0000 | [diff] [blame] | 95 | MVT WebAssemblyAsmPrinter::getRegType(unsigned RegNo) const { |
Derek Schuff | 83717cc | 2015-12-16 20:43:08 +0000 | [diff] [blame] | 96 | const TargetRegisterClass *TRC = |
Dan Gohman | 35e4a28 | 2016-01-08 01:06:00 +0000 | [diff] [blame] | 97 | TargetRegisterInfo::isVirtualRegister(RegNo) |
| 98 | ? MRI->getRegClass(RegNo) |
| 99 | : MRI->getTargetRegisterInfo()->getMinimalPhysRegClass(RegNo); |
JF Bastien | 1d20a5e | 2015-10-16 00:53:49 +0000 | [diff] [blame] | 100 | for (MVT T : {MVT::i32, MVT::i64, MVT::f32, MVT::f64}) |
| 101 | if (TRC->hasType(T)) |
Dan Gohman | 53828fd | 2015-11-23 16:50:18 +0000 | [diff] [blame] | 102 | return T; |
JF Bastien | 1d20a5e | 2015-10-16 00:53:49 +0000 | [diff] [blame] | 103 | DEBUG(errs() << "Unknown type for register number: " << RegNo); |
| 104 | llvm_unreachable("Unknown register type"); |
Dan Gohman | 53828fd | 2015-11-23 16:50:18 +0000 | [diff] [blame] | 105 | return MVT::Other; |
JF Bastien | 1d20a5e | 2015-10-16 00:53:49 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame^] | 108 | const char *WebAssemblyAsmPrinter::toString(MVT VT) const { |
| 109 | return WebAssembly::TypeToString(VT); |
| 110 | } |
| 111 | |
JF Bastien | 1d20a5e | 2015-10-16 00:53:49 +0000 | [diff] [blame] | 112 | std::string WebAssemblyAsmPrinter::regToString(const MachineOperand &MO) { |
| 113 | unsigned RegNo = MO.getReg(); |
Dan Gohman | d962527 | 2015-11-20 03:13:31 +0000 | [diff] [blame] | 114 | assert(TargetRegisterInfo::isVirtualRegister(RegNo) && |
| 115 | "Unlowered physical register encountered during assembly printing"); |
Dan Gohman | 4ba4816 | 2015-11-18 16:12:01 +0000 | [diff] [blame] | 116 | assert(!MFI->isVRegStackified(RegNo)); |
Dan Gohman | 058fce5 | 2015-11-13 00:21:05 +0000 | [diff] [blame] | 117 | unsigned WAReg = MFI->getWAReg(RegNo); |
| 118 | assert(WAReg != WebAssemblyFunctionInfo::UnusedReg); |
Dan Gohman | 4ba4816 | 2015-11-18 16:12:01 +0000 | [diff] [blame] | 119 | return '$' + utostr(WAReg); |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 120 | } |
| 121 | |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame^] | 122 | WebAssemblyTargetStreamer * |
| 123 | WebAssemblyAsmPrinter::getTargetStreamer() { |
| 124 | MCTargetStreamer *TS = OutStreamer->getTargetStreamer(); |
| 125 | return static_cast<WebAssemblyTargetStreamer *>(TS); |
JF Bastien | 73ff6af | 2015-08-31 22:24:11 +0000 | [diff] [blame] | 126 | } |
| 127 | |
JF Bastien | 45479f6 | 2015-08-26 22:09:54 +0000 | [diff] [blame] | 128 | //===----------------------------------------------------------------------===// |
| 129 | // WebAssemblyAsmPrinter Implementation. |
| 130 | //===----------------------------------------------------------------------===// |
| 131 | |
JF Bastien | 54be3b1 | 2015-08-25 23:19:49 +0000 | [diff] [blame] | 132 | void WebAssemblyAsmPrinter::EmitConstantPool() { |
| 133 | assert(MF->getConstantPool()->getConstants().empty() && |
| 134 | "WebAssembly disables constant pools"); |
| 135 | } |
| 136 | |
Dan Gohman | 950a13c | 2015-09-16 16:51:30 +0000 | [diff] [blame] | 137 | void WebAssemblyAsmPrinter::EmitJumpTableInfo() { |
| 138 | // Nothing to do; jump tables are incorporated into the instruction stream. |
| 139 | } |
| 140 | |
Dan Gohman | 7a6b982 | 2015-11-29 22:32:02 +0000 | [diff] [blame] | 141 | static void ComputeLegalValueVTs(const Function &F, const TargetMachine &TM, |
| 142 | Type *Ty, SmallVectorImpl<MVT> &ValueVTs) { |
| 143 | const DataLayout &DL(F.getParent()->getDataLayout()); |
Derek Schuff | 46e3316 | 2015-11-16 21:12:41 +0000 | [diff] [blame] | 144 | const WebAssemblyTargetLowering &TLI = |
| 145 | *TM.getSubtarget<WebAssemblySubtarget>(F).getTargetLowering(); |
| 146 | SmallVector<EVT, 4> VTs; |
| 147 | ComputeValueVTs(TLI, DL, Ty, VTs); |
| 148 | |
| 149 | for (EVT VT : VTs) { |
| 150 | unsigned NumRegs = TLI.getNumRegisters(F.getContext(), VT); |
| 151 | MVT RegisterVT = TLI.getRegisterType(F.getContext(), VT); |
| 152 | for (unsigned i = 0; i != NumRegs; ++i) |
| 153 | ValueVTs.push_back(RegisterVT); |
| 154 | } |
| 155 | } |
| 156 | |
JF Bastien | b6091df | 2015-08-25 22:58:05 +0000 | [diff] [blame] | 157 | void WebAssemblyAsmPrinter::EmitFunctionBodyStart() { |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame^] | 158 | if (!MFI->getParams().empty()) |
| 159 | getTargetStreamer()->emitParam(MFI->getParams()); |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 160 | |
Derek Schuff | 46e3316 | 2015-11-16 21:12:41 +0000 | [diff] [blame] | 161 | SmallVector<MVT, 4> ResultVTs; |
| 162 | const Function &F(*MF->getFunction()); |
| 163 | ComputeLegalValueVTs(F, TM, F.getReturnType(), ResultVTs); |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame^] | 164 | |
Derek Schuff | 46e3316 | 2015-11-16 21:12:41 +0000 | [diff] [blame] | 165 | // If the return type needs to be legalized it will get converted into |
| 166 | // passing a pointer. |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame^] | 167 | if (ResultVTs.size() == 1) |
| 168 | getTargetStreamer()->emitResult(ResultVTs); |
JF Bastien | b6091df | 2015-08-25 22:58:05 +0000 | [diff] [blame] | 169 | |
Dan Gohman | 53828fd | 2015-11-23 16:50:18 +0000 | [diff] [blame] | 170 | bool AnyWARegs = false; |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame^] | 171 | SmallVector<MVT, 16> LocalTypes; |
JF Bastien | 1d20a5e | 2015-10-16 00:53:49 +0000 | [diff] [blame] | 172 | for (unsigned Idx = 0, IdxE = MRI->getNumVirtRegs(); Idx != IdxE; ++Idx) { |
| 173 | unsigned VReg = TargetRegisterInfo::index2VirtReg(Idx); |
Dan Gohman | 4ba4816 | 2015-11-18 16:12:01 +0000 | [diff] [blame] | 174 | unsigned WAReg = MFI->getWAReg(VReg); |
| 175 | // Don't declare unused registers. |
| 176 | if (WAReg == WebAssemblyFunctionInfo::UnusedReg) |
| 177 | continue; |
| 178 | // Don't redeclare parameters. |
| 179 | if (WAReg < MFI->getParams().size()) |
| 180 | continue; |
| 181 | // Don't declare stackified registers. |
| 182 | if (int(WAReg) < 0) |
| 183 | continue; |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame^] | 184 | LocalTypes.push_back(getRegType(VReg)); |
Dan Gohman | 53828fd | 2015-11-23 16:50:18 +0000 | [diff] [blame] | 185 | AnyWARegs = true; |
JF Bastien | 1d20a5e | 2015-10-16 00:53:49 +0000 | [diff] [blame] | 186 | } |
Derek Schuff | 83717cc | 2015-12-16 20:43:08 +0000 | [diff] [blame] | 187 | auto &PhysRegs = MFI->getPhysRegs(); |
| 188 | for (unsigned PReg = 0; PReg < PhysRegs.size(); ++PReg) { |
| 189 | if (PhysRegs[PReg] == -1U) |
| 190 | continue; |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame^] | 191 | LocalTypes.push_back(getRegType(PReg)); |
Derek Schuff | 45cd5a7 | 2015-12-16 20:43:06 +0000 | [diff] [blame] | 192 | AnyWARegs = true; |
| 193 | } |
Dan Gohman | 53828fd | 2015-11-23 16:50:18 +0000 | [diff] [blame] | 194 | if (AnyWARegs) |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame^] | 195 | getTargetStreamer()->emitLocal(LocalTypes); |
JF Bastien | 1d20a5e | 2015-10-16 00:53:49 +0000 | [diff] [blame] | 196 | |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 197 | AsmPrinter::EmitFunctionBodyStart(); |
JF Bastien | b6091df | 2015-08-25 22:58:05 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Dan Gohman | 3469ee1 | 2016-01-12 20:30:51 +0000 | [diff] [blame^] | 200 | void WebAssemblyAsmPrinter::EmitFunctionBodyEnd() { |
| 201 | getTargetStreamer()->emitEndFunc(); |
| 202 | } |
| 203 | |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 204 | void WebAssemblyAsmPrinter::EmitInstruction(const MachineInstr *MI) { |
JF Bastien | af111db | 2015-08-24 22:16:48 +0000 | [diff] [blame] | 205 | DEBUG(dbgs() << "EmitInstruction: " << *MI << '\n'); |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 206 | |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 207 | switch (MI->getOpcode()) { |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 208 | case WebAssembly::ARGUMENT_I32: |
| 209 | case WebAssembly::ARGUMENT_I64: |
| 210 | case WebAssembly::ARGUMENT_F32: |
| 211 | case WebAssembly::ARGUMENT_F64: |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 212 | // These represent values which are live into the function entry, so there's |
| 213 | // no instruction to emit. |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 214 | break; |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 215 | default: { |
Dan Gohman | cf4748f | 2015-11-12 17:04:33 +0000 | [diff] [blame] | 216 | WebAssemblyMCInstLower MCInstLowering(OutContext, *this); |
| 217 | MCInst TmpInst; |
| 218 | MCInstLowering.Lower(MI, TmpInst); |
| 219 | EmitToStreamer(*OutStreamer, TmpInst); |
Dan Gohman | e51c058 | 2015-10-06 00:27:55 +0000 | [diff] [blame] | 220 | break; |
| 221 | } |
Dan Gohman | 4f52e00 | 2015-09-09 00:52:47 +0000 | [diff] [blame] | 222 | } |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Dan Gohman | 26c6765 | 2016-01-11 23:38:05 +0000 | [diff] [blame] | 225 | const MCExpr *WebAssemblyAsmPrinter::lowerConstant(const Constant *CV) { |
| 226 | if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) |
| 227 | if (GV->getValueType()->isFunctionTy()) |
| 228 | return MCSymbolRefExpr::create( |
| 229 | getSymbol(GV), MCSymbolRefExpr::VK_WebAssembly_FUNCTION, OutContext); |
| 230 | return AsmPrinter::lowerConstant(CV); |
| 231 | } |
| 232 | |
Dan Gohman | f19ed56 | 2015-11-13 01:42:29 +0000 | [diff] [blame] | 233 | bool WebAssemblyAsmPrinter::PrintAsmOperand(const MachineInstr *MI, |
| 234 | unsigned OpNo, unsigned AsmVariant, |
| 235 | const char *ExtraCode, |
| 236 | raw_ostream &OS) { |
| 237 | if (AsmVariant != 0) |
| 238 | report_fatal_error("There are no defined alternate asm variants"); |
| 239 | |
Dan Gohman | 30a42bf | 2015-12-16 17:15:17 +0000 | [diff] [blame] | 240 | // First try the generic code, which knows about modifiers like 'c' and 'n'. |
| 241 | if (!AsmPrinter::PrintAsmOperand(MI, OpNo, AsmVariant, ExtraCode, OS)) |
| 242 | return false; |
| 243 | |
Dan Gohman | f19ed56 | 2015-11-13 01:42:29 +0000 | [diff] [blame] | 244 | if (!ExtraCode) { |
| 245 | const MachineOperand &MO = MI->getOperand(OpNo); |
Dan Gohman | 30a42bf | 2015-12-16 17:15:17 +0000 | [diff] [blame] | 246 | switch (MO.getType()) { |
| 247 | case MachineOperand::MO_Immediate: |
Dan Gohman | f19ed56 | 2015-11-13 01:42:29 +0000 | [diff] [blame] | 248 | OS << MO.getImm(); |
Dan Gohman | 30a42bf | 2015-12-16 17:15:17 +0000 | [diff] [blame] | 249 | return false; |
| 250 | case MachineOperand::MO_Register: |
Dan Gohman | f19ed56 | 2015-11-13 01:42:29 +0000 | [diff] [blame] | 251 | OS << regToString(MO); |
Dan Gohman | 30a42bf | 2015-12-16 17:15:17 +0000 | [diff] [blame] | 252 | return false; |
| 253 | case MachineOperand::MO_GlobalAddress: |
| 254 | getSymbol(MO.getGlobal())->print(OS, MAI); |
| 255 | printOffset(MO.getOffset(), OS); |
| 256 | return false; |
| 257 | case MachineOperand::MO_ExternalSymbol: |
| 258 | GetExternalSymbolSymbol(MO.getSymbolName())->print(OS, MAI); |
| 259 | printOffset(MO.getOffset(), OS); |
| 260 | return false; |
| 261 | case MachineOperand::MO_MachineBasicBlock: |
| 262 | MO.getMBB()->getSymbol()->print(OS, MAI); |
| 263 | return false; |
| 264 | default: |
| 265 | break; |
| 266 | } |
Dan Gohman | f19ed56 | 2015-11-13 01:42:29 +0000 | [diff] [blame] | 267 | } |
| 268 | |
Dan Gohman | 30a42bf | 2015-12-16 17:15:17 +0000 | [diff] [blame] | 269 | return true; |
Dan Gohman | f19ed56 | 2015-11-13 01:42:29 +0000 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | bool WebAssemblyAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, |
| 273 | unsigned OpNo, |
| 274 | unsigned AsmVariant, |
| 275 | const char *ExtraCode, |
| 276 | raw_ostream &OS) { |
| 277 | if (AsmVariant != 0) |
| 278 | report_fatal_error("There are no defined alternate asm variants"); |
| 279 | |
| 280 | if (!ExtraCode) { |
Dan Gohman | e2831b4 | 2015-12-16 18:14:49 +0000 | [diff] [blame] | 281 | // TODO: For now, we just hard-code 0 as the constant offset; teach |
| 282 | // SelectInlineAsmMemoryOperand how to do address mode matching. |
| 283 | OS << "0(" + regToString(MI->getOperand(OpNo)) + ')'; |
Dan Gohman | f19ed56 | 2015-11-13 01:42:29 +0000 | [diff] [blame] | 284 | return false; |
| 285 | } |
| 286 | |
| 287 | return AsmPrinter::PrintAsmMemoryOperand(MI, OpNo, AsmVariant, ExtraCode, OS); |
| 288 | } |
| 289 | |
JF Bastien | b9073fb | 2015-07-22 21:28:15 +0000 | [diff] [blame] | 290 | // Force static initialization. |
| 291 | extern "C" void LLVMInitializeWebAssemblyAsmPrinter() { |
| 292 | RegisterAsmPrinter<WebAssemblyAsmPrinter> X(TheWebAssemblyTarget32); |
| 293 | RegisterAsmPrinter<WebAssemblyAsmPrinter> Y(TheWebAssemblyTarget64); |
| 294 | } |