[WebAssembly] Factor out a TypeToString function, since we need it in multiple places.
[oota-llvm.git] / lib / Target / WebAssembly / WebAssemblyAsmPrinter.cpp
index 0cf87a95d629317c3b6c2f01b5b24bbbc815c838..1b175a7f8d5b2e3fa6907d781126580ece4898bf 100644 (file)
@@ -115,21 +115,7 @@ std::string WebAssemblyAsmPrinter::regToString(const MachineOperand &MO) {
 }
 
 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);
 }
 
 //===----------------------------------------------------------------------===//
@@ -145,11 +131,9 @@ void WebAssemblyAsmPrinter::EmitJumpTableInfo() {
   // Nothing to do; jump tables are incorporated into the instruction stream.
 }
 
-static void ComputeLegalValueVTs(const Function &F,
-                                 const TargetMachine &TM,
-                                 Type *Ty,
-                                 SmallVectorImpl<MVT> &ValueVTs) {
-  const DataLayout& DL(F.getParent()->getDataLayout());
+static void ComputeLegalValueVTs(const Function &F, const TargetMachine &TM,
+                                 Type *Ty, SmallVectorImpl<MVT> &ValueVTs) {
+  const DataLayout &DL(F.getParent()->getDataLayout());
   const WebAssemblyTargetLowering &TLI =
       *TM.getSubtarget<WebAssemblySubtarget>(F).getTargetLowering();
   SmallVector<EVT, 4> VTs;
@@ -172,7 +156,6 @@ void WebAssemblyAsmPrinter::EmitFunctionBodyStart() {
     EmitToStreamer(*OutStreamer, Param);
   }
 
-
   SmallVector<MVT, 4> ResultVTs;
   const Function &F(*MF->getFunction());
   ComputeLegalValueVTs(F, TM, F.getReturnType(), ResultVTs);