diff options
author | JF Bastien <jfb@google.com> | 2015-08-07 01:57:03 +0000 |
---|---|---|
committer | JF Bastien <jfb@google.com> | 2015-08-07 01:57:03 +0000 |
commit | 315cc068409555a2969da4a57f1295c3d98e4a85 (patch) | |
tree | 63c4f74b316c7e5d774bd48e9fc745b676591587 /llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp | |
parent | f594fcad73ab45a46b30b405b022916b819a8bd7 (diff) | |
download | bcm5719-llvm-315cc068409555a2969da4a57f1295c3d98e4a85.tar.gz bcm5719-llvm-315cc068409555a2969da4a57f1295c3d98e4a85.zip |
WebAssembly: textual emission uses expected opcode names
Summary: WebAssembly's tablegen instructions have the names WebAssembly expects, but by LLVM convention they're uppercase and suffixed with their type after an underscore. Leave the C++ code that way, but print outt he names WebAssembly expects (lowercase, no type). We could teach tablegen to do this later, maybe by using `!cast<string>(node)` in the .td files.
Reviewers: sunfish
Subscribers: jfb, llvm-commits
Differential Revision: http://reviews.llvm.org/D11776
llvm-svn: 244305
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp')
-rw-r--r-- | llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp index a3157f40a66..99b23c7433b 100644 --- a/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp @@ -74,6 +74,17 @@ private: //===----------------------------------------------------------------------===// +// Untyped, lower-case version of the opcode's name matching the names +// WebAssembly opcodes are expected to have. The tablegen names are uppercase +// and suffixed with their type (after an underscore). +static SmallString<32> Name(const WebAssemblyInstrInfo *TII, + const MachineInstr *MI) { + std::string N(StringRef(TII->getName(MI->getOpcode())).lower()); + std::string::size_type End = N.find('_'); + End = std::string::npos == End ? N.length() : End; + return SmallString<32>(&N[0], &N[End]); +} + void WebAssemblyAsmPrinter::EmitInstruction(const MachineInstr *MI) { SmallString<128> Str; raw_svector_ostream OS(Str); @@ -96,21 +107,11 @@ void WebAssemblyAsmPrinter::EmitInstruction(const MachineInstr *MI) { case WebAssembly::ARGUMENT_Int64: case WebAssembly::ARGUMENT_Float32: case WebAssembly::ARGUMENT_Float64: - OS << "argument " << MI->getOperand(1).getImm(); + OS << Name(TII, MI) << ' ' << MI->getOperand(1).getImm(); PrintOperands = false; break; - case WebAssembly::RETURN_Int32: - case WebAssembly::RETURN_Int64: - case WebAssembly::RETURN_Float32: - case WebAssembly::RETURN_Float64: - case WebAssembly::RETURN_VOID: - // FIXME This is here only so "return" prints nicely, instead of printing - // the isel name. Other operations have the same problem, fix this in - // a generic way instead. - OS << "return"; - break; default: - OS << TII->getName(MI->getOpcode()); + OS << Name(TII, MI); break; } |