[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:33:39 PST 2018
sbc100 created this revision.
Herald added subscribers: llvm-commits, sunfish, aheejin, jgravelle-google, dschuff, jfb.
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,27 @@
}
}
-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));
+ assert(TypeIndices.count(Sig) > 0);
+ 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.129201.patch
Type: text/x-patch
Size: 2686 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180110/9218eaee/attachment.bin>
More information about the llvm-commits
mailing list