[lld] r322211 - [WebAssembly] Add seperate Writer::lookupType and Writer::registerType. NFC
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 10 11:18:22 PST 2018
Author: sbc
Date: Wed Jan 10 11:18:22 2018
New Revision: 322211
URL: http://llvm.org/viewvc/llvm-project?rev=322211&view=rev
Log:
[WebAssembly] Add seperate Writer::lookupType and Writer::registerType. NFC
Differential Revision: https://reviews.llvm.org/D41894
Modified:
lld/trunk/wasm/Writer.cpp
Modified: lld/trunk/wasm/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Writer.cpp?rev=322211&r1=322210&r2=322211&view=diff
==============================================================================
--- lld/trunk/wasm/Writer.cpp (original)
+++ lld/trunk/wasm/Writer.cpp Wed Jan 10 11:18:22 2018
@@ -68,7 +68,8 @@ public:
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 @@ private:
void createHeader();
void createSections();
SyntheticSection *createSyntheticSection(uint32_t Type,
- std::string Name = "");
+ StringRef Name = "");
// Builtin sections
void createTypeSection();
@@ -154,8 +155,7 @@ void Writer::createImportSection() {
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 @@ void Writer::createFunctionSection() {
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 @@ void Writer::layoutMemory() {
}
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,10 +570,18 @@ void Writer::calculateImports() {
}
}
-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;
}
@@ -581,7 +589,7 @@ 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));
}
}
More information about the llvm-commits
mailing list