WebAssembly: Implement call
[oota-llvm.git] / lib / Target / WebAssembly / InstPrinter / WebAssemblyInstPrinter.cpp
1 //=- WebAssemblyInstPrinter.cpp - WebAssembly assembly instruction printing -=//
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 Print MCInst instructions to wasm format.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #include "InstPrinter/WebAssemblyInstPrinter.h"
16 #include "WebAssembly.h"
17 #include "llvm/MC/MCExpr.h"
18 #include "llvm/MC/MCInst.h"
19 #include "llvm/MC/MCInstrInfo.h"
20 #include "llvm/MC/MCSubtargetInfo.h"
21 #include "llvm/MC/MCSymbol.h"
22 #include "llvm/Support/ErrorHandling.h"
23 #include "llvm/Support/FormattedStream.h"
24 #include <cctype>
25 using namespace llvm;
26
27 #define DEBUG_TYPE "asm-printer"
28
29 #include "WebAssemblyGenAsmWriter.inc"
30
31 WebAssemblyInstPrinter::WebAssemblyInstPrinter(const MCAsmInfo &MAI,
32                                                const MCInstrInfo &MII,
33                                                const MCRegisterInfo &MRI)
34     : MCInstPrinter(MAI, MII, MRI) {}
35
36 void WebAssemblyInstPrinter::printRegName(raw_ostream &OS,
37                                           unsigned RegNo) const {
38   OS << getRegisterName(RegNo);
39 }
40
41 void WebAssemblyInstPrinter::printInst(const MCInst *MI, raw_ostream &OS,
42                                        StringRef Annot,
43                                        const MCSubtargetInfo &STI) {
44   printInstruction(MI, OS);
45   printAnnotation(OS, Annot);
46 }
47
48 void WebAssemblyInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
49                                           raw_ostream &O) {
50   const MCOperand &Op = MI->getOperand(OpNo);
51   if (Op.isReg())
52     O << getRegisterName(Op.getReg());
53   else if (Op.isImm())
54     O << '#' << Op.getImm();
55   else {
56     assert(Op.isExpr() && "unknown operand kind in printOperand");
57     Op.getExpr()->print(O, &MAI);
58   }
59 }