2015-06-30 07:51:55 +08:00
|
|
|
//=- WebAssemblyInstPrinter.cpp - WebAssembly assembly instruction printing -=//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// \brief Print MCInst instructions to wasm format.
|
|
|
|
///
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "InstPrinter/WebAssemblyInstPrinter.h"
|
|
|
|
#include "WebAssembly.h"
|
|
|
|
#include "llvm/MC/MCExpr.h"
|
|
|
|
#include "llvm/MC/MCInst.h"
|
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
|
|
|
#include "llvm/MC/MCSymbol.h"
|
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
|
|
|
#include "llvm/Support/FormattedStream.h"
|
|
|
|
#include <cctype>
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
#define DEBUG_TYPE "asm-printer"
|
|
|
|
|
2015-07-23 05:28:15 +08:00
|
|
|
#include "WebAssemblyGenAsmWriter.inc"
|
|
|
|
|
2015-06-30 07:51:55 +08:00
|
|
|
WebAssemblyInstPrinter::WebAssemblyInstPrinter(const MCAsmInfo &MAI,
|
|
|
|
const MCInstrInfo &MII,
|
|
|
|
const MCRegisterInfo &MRI)
|
|
|
|
: MCInstPrinter(MAI, MII, MRI) {}
|
|
|
|
|
|
|
|
void WebAssemblyInstPrinter::printRegName(raw_ostream &OS,
|
|
|
|
unsigned RegNo) const {
|
2015-07-23 05:28:15 +08:00
|
|
|
OS << getRegisterName(RegNo);
|
2015-06-30 07:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void WebAssemblyInstPrinter::printInst(const MCInst *MI, raw_ostream &OS,
|
|
|
|
StringRef Annot,
|
|
|
|
const MCSubtargetInfo &STI) {
|
2015-07-23 05:28:15 +08:00
|
|
|
printInstruction(MI, OS);
|
|
|
|
printAnnotation(OS, Annot);
|
2015-06-30 07:51:55 +08:00
|
|
|
}
|
2015-08-25 06:16:48 +08:00
|
|
|
|
|
|
|
void WebAssemblyInstPrinter::printOperand(const MCInst *MI, unsigned OpNo,
|
|
|
|
raw_ostream &O) {
|
|
|
|
const MCOperand &Op = MI->getOperand(OpNo);
|
|
|
|
if (Op.isReg())
|
|
|
|
O << getRegisterName(Op.getReg());
|
|
|
|
else if (Op.isImm())
|
|
|
|
O << '#' << Op.getImm();
|
|
|
|
else {
|
|
|
|
assert(Op.isExpr() && "unknown operand kind in printOperand");
|
|
|
|
Op.getExpr()->print(O, &MAI);
|
|
|
|
}
|
|
|
|
}
|