[PATCH] D41894: [WebAssembly] Add seperate Writer::lookupType and Writer::registerType. NFC

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 9 17:34:57 PST 2018


sbc100 updated this revision to Diff 129202.
sbc100 added a comment.

- remove extra assert


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D41894

Files:
  wasm/Writer.cpp


Index: wasm/Writer.cpp
===================================================================
--- wasm/Writer.cpp
+++ wasm/Writer.cpp
@@ -68,7 +68,8 @@
 private:
   void openFile();
 
-  uint32_t getTypeIndex(const WasmSignature &Sig);
+  uint32_t lookupType(const WasmSignature &Sig);
+  uint32_t registerType(const WasmSignature &Sig);
   void assignIndexes();
   void calculateImports();
   void calculateOffsets();
@@ -78,7 +79,7 @@
   void createHeader();
   void createSections();
   SyntheticSection *createSyntheticSection(uint32_t Type,
-                                           std::string Name = "");
+                                           StringRef Name = "");
 
   // Builtin sections
   void createTypeSection();
@@ -154,8 +155,7 @@
     Import.Module = "env";
     Import.Field = Sym->getName();
     Import.Kind = WASM_EXTERNAL_FUNCTION;
-    assert(TypeIndices.count(Sym->getFunctionType()) > 0);
-    Import.SigIndex = TypeIndices.lookup(Sym->getFunctionType());
+    Import.SigIndex = lookupType(Sym->getFunctionType());
     writeImport(OS, Import);
   }
 
@@ -197,7 +197,7 @@
 
   writeUleb128(OS, DefinedFunctions.size(), "function count");
   for (const InputFunction *Func : DefinedFunctions)
-    writeUleb128(OS, TypeIndices.lookup(Func->Signature), "sig index");
+    writeUleb128(OS, lookupType(Func->Signature), "sig index");
 }
 
 void Writer::createMemorySection() {
@@ -520,7 +520,7 @@
 }
 
 SyntheticSection *Writer::createSyntheticSection(uint32_t Type,
-                                                 std::string Name) {
+                                                 StringRef Name) {
   auto Sec = make<SyntheticSection>(Type, Name);
   log("createSection: " + toString(*Sec));
   OutputSections.push_back(Sec);
@@ -570,18 +570,26 @@
   }
 }
 
-uint32_t Writer::getTypeIndex(const WasmSignature &Sig) {
+uint32_t Writer::lookupType(const WasmSignature &Sig) {
+  if (TypeIndices.count(Sig) == 0)
+    error("type not found: " + toString(Sig));
+  return TypeIndices.lookup(Sig);
+}
+
+uint32_t Writer::registerType(const WasmSignature &Sig) {
   auto Pair = TypeIndices.insert(std::make_pair(Sig, Types.size()));
-  if (Pair.second)
+  if (Pair.second) {
+    DEBUG(dbgs() << "type " << toString(Sig) << "\n");
     Types.push_back(&Sig);
+  }
   return Pair.first->second;
 }
 
 void Writer::calculateTypes() {
   for (ObjFile *File : Symtab->ObjectFiles) {
     File->TypeMap.reserve(File->getWasmObj()->types().size());
     for (const WasmSignature &Sig : File->getWasmObj()->types())
-      File->TypeMap.push_back(getTypeIndex(Sig));
+      File->TypeMap.push_back(registerType(Sig));
   }
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41894.129202.patch
Type: text/x-patch
Size: 2647 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180110/f607046c/attachment.bin>


More information about the llvm-commits mailing list