[llvm] r254884 - [WebAssembly] Factor out a TypeToString function, since we need it in multiple places.
Dan Gohman via llvm-commits
llvm-commits at lists.llvm.org
Sun Dec 6 11:42:29 PST 2015
Author: djg
Date: Sun Dec 6 13:42:29 2015
New Revision: 254884
URL: http://llvm.org/viewvc/llvm-project?rev=254884&view=rev
Log:
[WebAssembly] Factor out a TypeToString function, since we need it in multiple places.
Modified:
llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.h
llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
Modified: llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp?rev=254884&r1=254883&r2=254884&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.cpp Sun Dec 6 13:42:29 2015
@@ -98,22 +98,7 @@ void WebAssemblyInstPrinter::printOperan
case WebAssembly::PARAM:
case WebAssembly::RESULT:
case WebAssembly::LOCAL:
- switch (Op.getImm()) {
- case MVT::i32:
- O << "i32";
- break;
- case MVT::i64:
- O << "i64";
- break;
- case MVT::f32:
- O << "f32";
- break;
- case MVT::f64:
- O << "f64";
- break;
- default:
- llvm_unreachable("unexpected type");
- }
+ O << WebAssembly::TypeToString(MVT::SimpleValueType(Op.getImm()));
break;
default:
O << Op.getImm();
@@ -126,3 +111,18 @@ void WebAssemblyInstPrinter::printOperan
Op.getExpr()->print(O, &MAI);
}
}
+
+const char *llvm::WebAssembly::TypeToString(MVT Ty) {
+ switch (Ty.SimpleTy) {
+ case MVT::i32:
+ return "i32";
+ case MVT::i64:
+ return "i64";
+ case MVT::f32:
+ return "f32";
+ case MVT::f64:
+ return "f64";
+ default:
+ llvm_unreachable("unsupported type");
+ }
+}
Modified: llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.h?rev=254884&r1=254883&r2=254884&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.h (original)
+++ llvm/trunk/lib/Target/WebAssembly/InstPrinter/WebAssemblyInstPrinter.h Sun Dec 6 13:42:29 2015
@@ -17,6 +17,7 @@
#include "llvm/MC/MCInstPrinter.h"
#include "llvm/Support/raw_ostream.h"
+#include "llvm/CodeGen/MachineValueType.h"
namespace llvm {
@@ -40,6 +41,12 @@ public:
static const char *getRegisterName(unsigned RegNo);
};
+namespace WebAssembly {
+
+const char *TypeToString(MVT Ty);
+
+} // end namespace WebAssembly
+
} // end namespace llvm
#endif
Modified: llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp?rev=254884&r1=254883&r2=254884&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp Sun Dec 6 13:42:29 2015
@@ -115,21 +115,7 @@ std::string WebAssemblyAsmPrinter::regTo
}
const char *WebAssemblyAsmPrinter::toString(MVT VT) const {
- switch (VT.SimpleTy) {
- default:
- break;
- case MVT::f32:
- return "f32";
- case MVT::f64:
- return "f64";
- case MVT::i32:
- return "i32";
- case MVT::i64:
- return "i64";
- }
- DEBUG(dbgs() << "Invalid type " << EVT(VT).getEVTString() << '\n');
- llvm_unreachable("invalid type");
- return "<invalid>";
+ return WebAssembly::TypeToString(VT);
}
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list