diff options
author | Sam Clegg <sbc@chromium.org> | 2021-10-04 16:47:59 -0700 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2021-10-04 17:33:56 -0700 |
commit | c0039de2953d15815448b4b3c3bafb45607781e0 (patch) | |
tree | 98b51e70a07d577c5447ba0f43a7b5ffb950b57b /llvm/lib/Object/WasmObjectFile.cpp | |
parent | 758ea6c03e466ca9035392f26941bd7524cfbdc6 (diff) | |
download | llvm-c0039de2953d15815448b4b3c3bafb45607781e0.zip llvm-c0039de2953d15815448b4b3c3bafb45607781e0.tar.gz llvm-c0039de2953d15815448b4b3c3bafb45607781e0.tar.bz2 |
[Object][WebAssemlby] Report function types (signatures). NFC
This simplifies the code in a number of ways and avoids
having to track functions and their types separately.
Differential Revision: https://reviews.llvm.org/D111104
Diffstat (limited to 'llvm/lib/Object/WasmObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/WasmObjectFile.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index 524a691..8dcd9af 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -412,7 +412,7 @@ Error WasmObjectFile::parseNameSection(ReadContext &Ctx) { llvm::DenseSet<uint64_t> SeenFunctions; llvm::DenseSet<uint64_t> SeenGlobals; llvm::DenseSet<uint64_t> SeenSegments; - if (FunctionTypes.size() && !SeenCodeSection) { + if (Functions.size() && !SeenCodeSection) { return make_error<GenericBinaryError>("names must come after code section", object_error::parse_failed); } @@ -480,7 +480,7 @@ Error WasmObjectFile::parseNameSection(ReadContext &Ctx) { Error WasmObjectFile::parseLinkingSection(ReadContext &Ctx) { HasLinkingSection = true; - if (FunctionTypes.size() && !SeenCodeSection) { + if (Functions.size() && !SeenCodeSection) { return make_error<GenericBinaryError>( "linking data must come after code section", object_error::parse_failed); @@ -598,8 +598,8 @@ Error WasmObjectFile::parseLinkingSectionSymtab(ReadContext &Ctx) { if (IsDefined) { Info.Name = readString(Ctx); unsigned FuncIndex = Info.ElementIndex - NumImportedFunctions; - Signature = &Signatures[FunctionTypes[FuncIndex]]; wasm::WasmFunction &Function = Functions[FuncIndex]; + Signature = &Signatures[Function.SigIndex]; if (Function.SymbolName.empty()) Function.SymbolName = Info.Name; } else { @@ -1140,15 +1140,16 @@ Error WasmObjectFile::parseImportSection(ReadContext &Ctx) { Error WasmObjectFile::parseFunctionSection(ReadContext &Ctx) { uint32_t Count = readVaruint32(Ctx); - FunctionTypes.reserve(Count); - Functions.resize(Count); + Functions.reserve(Count); uint32_t NumTypes = Signatures.size(); while (Count--) { uint32_t Type = readVaruint32(Ctx); if (Type >= NumTypes) return make_error<GenericBinaryError>("invalid function type", object_error::parse_failed); - FunctionTypes.push_back(Type); + wasm::WasmFunction F; + F.SigIndex = Type; + Functions.push_back(F); } if (Ctx.Ptr != Ctx.End) return make_error<GenericBinaryError>("function section ended prematurely", @@ -1272,7 +1273,7 @@ Error WasmObjectFile::parseExportSection(ReadContext &Ctx) { } bool WasmObjectFile::isValidFunctionIndex(uint32_t Index) const { - return Index < NumImportedFunctions + FunctionTypes.size(); + return Index < NumImportedFunctions + Functions.size(); } bool WasmObjectFile::isDefinedFunctionIndex(uint32_t Index) const { @@ -1360,7 +1361,7 @@ Error WasmObjectFile::parseCodeSection(ReadContext &Ctx) { SeenCodeSection = true; CodeSection = Sections.size(); uint32_t FunctionCount = readVaruint32(Ctx); - if (FunctionCount != FunctionTypes.size()) { + if (FunctionCount != Functions.size()) { return make_error<GenericBinaryError>("invalid function count", object_error::parse_failed); } |