aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
diff options
context:
space:
mode:
authorDan Gohman <dan433584@gmail.com>2015-11-05 19:28:16 +0000
committerDan Gohman <dan433584@gmail.com>2015-11-05 19:28:16 +0000
commite9361d58ffb72aa18522c93cab0c6b5e8441a247 (patch)
tree77515b15ba5bbda485c36c7a0741a92a7a3f1f25 /llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
parent35dfc95efe730be455996970586d055795bdffa1 (diff)
downloadllvm-e9361d58ffb72aa18522c93cab0c6b5e8441a247.zip
llvm-e9361d58ffb72aa18522c93cab0c6b5e8441a247.tar.gz
llvm-e9361d58ffb72aa18522c93cab0c6b5e8441a247.tar.bz2
[WebAssembly] Add WebAssemblyMCInstLower.cpp.
This isn't used yet; it's just a start towards eventually using MC to do instruction printing, and eventually binary encoding. llvm-svn: 252194
Diffstat (limited to 'llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp')
-rw-r--r--llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp28
1 files changed, 24 insertions, 4 deletions
diff --git a/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp b/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
index cbd2f7d..bb10f20 100644
--- a/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
+++ b/llvm/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
@@ -21,6 +21,7 @@
#include "llvm/MC/MCSymbol.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormattedStream.h"
+#include "llvm/Target/TargetRegisterInfo.h"
#include <cctype>
using namespace llvm;
@@ -35,7 +36,10 @@ WebAssemblyInstPrinter::WebAssemblyInstPrinter(const MCAsmInfo &MAI,
void WebAssemblyInstPrinter::printRegName(raw_ostream &OS,
unsigned RegNo) const {
- OS << getRegisterName(RegNo);
+ if (TargetRegisterInfo::isPhysicalRegister(RegNo))
+ OS << getRegisterName(RegNo);
+ else
+ OS << TargetRegisterInfo::virtReg2Index(RegNo);
}
void WebAssemblyInstPrinter::printInst(const MCInst *MI, raw_ostream &OS,
@@ -43,15 +47,31 @@ void WebAssemblyInstPrinter::printInst(const MCInst *MI, raw_ostream &OS,
const MCSubtargetInfo &STI) {
printInstruction(MI, OS);
printAnnotation(OS, Annot);
+
+ unsigned NumDefs = MII.get(MI->getOpcode()).getNumDefs();
+ assert(NumDefs <= 1 &&
+ "Instructions with multiple result values not implemented");
+
+ if (NumDefs != 0) {
+ OS << "\n"
+ "\t" "set_local ";
+ printRegName(OS, MI->getOperand(0).getReg());
+ OS << ", pop";
+ }
}
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())
+ if (Op.isReg()) {
+ if (OpNo < MII.get(MI->getOpcode()).getNumDefs())
+ O << "push";
+ else
+ printRegName(O, Op.getReg());
+ } else if (Op.isImm())
O << '#' << Op.getImm();
+ else if (Op.isFPImm())
+ O << '#' << Op.getFPImm();
else {
assert(Op.isExpr() && "unknown operand kind in printOperand");
Op.getExpr()->print(O, &MAI);