diff options
author | Sam Clegg <sbc@chromium.org> | 2018-01-09 21:38:53 +0000 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2018-01-09 21:38:53 +0000 |
commit | e53af7f6df2cabaa62516e32ae00aaf271258fa4 (patch) | |
tree | dac521f63a63655bedd0ea9cb27429a8943ea6cb /llvm/lib/Object/WasmObjectFile.cpp | |
parent | d68fa1be57ae66236af53f7a16e78309d2aecdea (diff) | |
download | llvm-e53af7f6df2cabaa62516e32ae00aaf271258fa4.zip llvm-e53af7f6df2cabaa62516e32ae00aaf271258fa4.tar.gz llvm-e53af7f6df2cabaa62516e32ae00aaf271258fa4.tar.bz2 |
[WebAssembly] Explicitly specify function/global index space in YAML
These indexes are useful because they are not always zero based and
functions and globals are referenced elsewhere by their index.
This matches what we already do for the type index space.
Differential Revision: https://reviews.llvm.org/D41877
llvm-svn: 322121
Diffstat (limited to 'llvm/lib/Object/WasmObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/WasmObjectFile.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/lib/Object/WasmObjectFile.cpp b/llvm/lib/Object/WasmObjectFile.cpp index 48f98df..c33f4f6 100644 --- a/llvm/lib/Object/WasmObjectFile.cpp +++ b/llvm/lib/Object/WasmObjectFile.cpp @@ -632,6 +632,7 @@ Error WasmObjectFile::parseGlobalSection(const uint8_t *Ptr, const uint8_t *End) Globals.reserve(Count); while (Count--) { wasm::WasmGlobal Global; + Global.Index = NumImportedGlobals + Globals.size(); Global.Type = readVarint7(Ptr); Global.Mutable = readVaruint1(Ptr); if (Error Err = readInitExpr(Global.InitExpr, Ptr)) @@ -706,6 +707,7 @@ Error WasmObjectFile::parseCodeSection(const uint8_t *Ptr, const uint8_t *End) { uint32_t Size = readVaruint32(Ptr); const uint8_t *FunctionEnd = Ptr + Size; + Function.Index = NumImportedFunctions + Functions.size(); Function.CodeSectionOffset = FunctionStart - CodeSectionStart; Function.Size = FunctionEnd - FunctionStart; @@ -858,7 +860,7 @@ uint64_t WasmObjectFile::getWasmSymbolValue(const WasmSymbol& Sym) const { case WasmSymbol::SymbolType::GLOBAL_EXPORT: { uint32_t GlobalIndex = Sym.ElementIndex - NumImportedGlobals; assert(GlobalIndex < Globals.size()); - const wasm::WasmGlobal& Global = Globals[GlobalIndex]; + const wasm::WasmGlobal &Global = Globals[GlobalIndex]; // WasmSymbols correspond only to I32_CONST globals assert(Global.InitExpr.Opcode == wasm::WASM_OPCODE_I32_CONST); return Global.InitExpr.Value.Int32; |