[llvm] r305316 - [WebAssembly] Cleanup WebAssemblyWasmObjectWriter

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 13 11:51:51 PDT 2017


Author: sbc
Date: Tue Jun 13 13:51:50 2017
New Revision: 305316

URL: http://llvm.org/viewvc/llvm-project?rev=305316&view=rev
Log:
[WebAssembly] Cleanup WebAssemblyWasmObjectWriter

Differential Revision: https://reviews.llvm.org/D34131

Modified:
    llvm/trunk/include/llvm/MC/MCSymbolWasm.h
    llvm/trunk/include/llvm/MC/MCWasmObjectWriter.h
    llvm/trunk/lib/MC/WasmObjectWriter.cpp
    llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.h
    llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp

Modified: llvm/trunk/include/llvm/MC/MCSymbolWasm.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSymbolWasm.h?rev=305316&r1=305315&r2=305316&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSymbolWasm.h (original)
+++ llvm/trunk/include/llvm/MC/MCSymbolWasm.h Tue Jun 13 13:51:50 2017
@@ -13,6 +13,7 @@
 #include "llvm/MC/MCSymbol.h"
 
 namespace llvm {
+
 class MCSymbolWasm : public MCSymbol {
 private:
   bool IsFunction = false;
@@ -52,6 +53,7 @@ public:
     Params = std::move(Pars);
   }
 };
-}
 
-#endif
+}  // end namespace llvm
+
+#endif // LLVM_MC_MCSYMBOLWASM_H

Modified: llvm/trunk/include/llvm/MC/MCWasmObjectWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCWasmObjectWriter.h?rev=305316&r1=305315&r2=305316&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCWasmObjectWriter.h (original)
+++ llvm/trunk/include/llvm/MC/MCWasmObjectWriter.h Tue Jun 13 13:51:50 2017
@@ -12,20 +12,12 @@
 
 #include "llvm/ADT/Triple.h"
 #include "llvm/BinaryFormat/Wasm.h"
-#include "llvm/MC/MCValue.h"
 #include "llvm/Support/DataTypes.h"
-#include "llvm/Support/raw_ostream.h"
-#include <vector>
 
 namespace llvm {
-class MCAssembler;
-class MCContext;
+
 class MCFixup;
-class MCFragment;
 class MCObjectWriter;
-class MCSectionWasm;
-class MCSymbol;
-class MCSymbolWasm;
 class MCValue;
 class raw_pwrite_stream;
 
@@ -38,8 +30,8 @@ protected:
 public:
   virtual ~MCWasmObjectTargetWriter();
 
-  virtual unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
-                                const MCFixup &Fixup, bool IsPCRel) const = 0;
+  virtual unsigned getRelocType(const MCValue &Target,
+                                const MCFixup &Fixup) const = 0;
 
   /// \name Accessors
   /// @{
@@ -54,6 +46,7 @@ public:
 /// \returns The constructed object writer.
 MCObjectWriter *createWasmObjectWriter(MCWasmObjectTargetWriter *MOTW,
                                        raw_pwrite_stream &OS);
+
 } // End llvm namespace
 
 #endif

Modified: llvm/trunk/lib/MC/WasmObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/WasmObjectWriter.cpp?rev=305316&r1=305315&r2=305316&view=diff
==============================================================================
--- llvm/trunk/lib/MC/WasmObjectWriter.cpp (original)
+++ llvm/trunk/lib/MC/WasmObjectWriter.cpp Tue Jun 13 13:51:50 2017
@@ -192,9 +192,8 @@ class WasmObjectWriter : public MCObject
 
   // TargetObjectWriter wrappers.
   bool is64Bit() const { return TargetObjectWriter->is64Bit(); }
-  unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
-                        const MCFixup &Fixup, bool IsPCRel) const {
-    return TargetObjectWriter->getRelocType(Ctx, Target, Fixup, IsPCRel);
+  unsigned getRelocType(const MCValue &Target, const MCFixup &Fixup) const {
+    return TargetObjectWriter->getRelocType(Target, Fixup);
   }
 
   void startSection(SectionBookkeeping &Section, unsigned SectionId,
@@ -406,7 +405,9 @@ void WasmObjectWriter::recordRelocation(
       SymA->setUsedInReloc();
   }
 
-  unsigned Type = getRelocType(Ctx, Target, Fixup, IsPCRel);
+  assert(!IsPCRel);
+  unsigned Type = getRelocType(Target, Fixup);
+
   WasmRelocationEntry Rec(FixupOffset, SymA, C, Type, &FixupSection);
 
   if (FixupSection.hasInstructions())

Modified: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.h?rev=305316&r1=305315&r2=305316&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.h (original)
+++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyTargetStreamer.h Tue Jun 13 13:51:50 2017
@@ -46,9 +46,7 @@ public:
   /// .functype
   virtual void emitIndirectFunctionType(StringRef name,
                                         SmallVectorImpl<MVT> &Params,
-                                        SmallVectorImpl<MVT> &Results) {
-    llvm_unreachable("emitIndirectFunctionType not implemented");
-  }
+                                        SmallVectorImpl<MVT> &Results) = 0;
   /// .indidx
   virtual void emitIndIdx(const MCExpr *Value) = 0;
   /// .import_global

Modified: llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp?rev=305316&r1=305315&r2=305316&view=diff
==============================================================================
--- llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyWasmObjectWriter.cpp Tue Jun 13 13:51:50 2017
@@ -16,11 +16,15 @@
 #include "MCTargetDesc/WebAssemblyFixupKinds.h"
 #include "MCTargetDesc/WebAssemblyMCTargetDesc.h"
 #include "llvm/BinaryFormat/Wasm.h"
+#include "llvm/MC/MCAsmBackend.h"
 #include "llvm/MC/MCFixup.h"
+#include "llvm/MC/MCFixupKindInfo.h"
 #include "llvm/MC/MCSymbolWasm.h"
 #include "llvm/MC/MCWasmObjectWriter.h"
+#include "llvm/MC/MCValue.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/ErrorHandling.h"
+
 using namespace llvm;
 
 namespace {
@@ -29,8 +33,8 @@ public:
   explicit WebAssemblyWasmObjectWriter(bool Is64Bit);
 
 private:
-  unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
-                        const MCFixup &Fixup, bool IsPCRel) const override;
+  unsigned getRelocType(const MCValue &Target,
+                        const MCFixup &Fixup) const override;
 };
 } // end anonymous namespace
 
@@ -39,16 +43,13 @@ WebAssemblyWasmObjectWriter::WebAssembly
 
 // Test whether the given expression computes a function address.
 static bool IsFunctionExpr(const MCExpr *Expr) {
-  if (const MCSymbolRefExpr *SyExp =
-          dyn_cast<MCSymbolRefExpr>(Expr))
+  if (auto SyExp = dyn_cast<MCSymbolRefExpr>(Expr))
     return cast<MCSymbolWasm>(SyExp->getSymbol()).isFunction();
 
-  if (const MCBinaryExpr *BinOp =
-          dyn_cast<MCBinaryExpr>(Expr))
+  if (auto BinOp = dyn_cast<MCBinaryExpr>(Expr))
     return IsFunctionExpr(BinOp->getLHS()) != IsFunctionExpr(BinOp->getRHS());
 
-  if (const MCUnaryExpr *UnOp =
-          dyn_cast<MCUnaryExpr>(Expr))
+  if (auto UnOp = dyn_cast<MCUnaryExpr>(Expr))
     return IsFunctionExpr(UnOp->getSubExpr());
 
   return false;
@@ -59,15 +60,13 @@ static bool IsFunctionType(const MCValue
   return RefA && RefA->getKind() == MCSymbolRefExpr::VK_WebAssembly_TYPEINDEX;
 }
 
-unsigned WebAssemblyWasmObjectWriter::getRelocType(MCContext &Ctx,
-                                                   const MCValue &Target,
-                                                   const MCFixup &Fixup,
-                                                   bool IsPCRel) const {
+unsigned
+WebAssemblyWasmObjectWriter::getRelocType(const MCValue &Target,
+                                          const MCFixup &Fixup) const {
   // WebAssembly functions are not allocated in the data address space. To
   // resolve a pointer to a function, we must use a special relocation type.
   bool IsFunction = IsFunctionExpr(Fixup.getValue());
 
-  assert(!IsPCRel);
   switch (unsigned(Fixup.getKind())) {
   case WebAssembly::fixup_code_sleb128_i32:
     if (IsFunction)




More information about the llvm-commits mailing list