diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-03-16 16:00:10 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-03-16 16:00:10 -0700 |
commit | cec883550664a64b9f6a425dd68a3caf529fa306 (patch) | |
tree | 4a6e07b04000eb8a13c521273fc7ffad3897379e /src | |
parent | 4af293a357d6db3726b57deeacbbb37b5f9dab1e (diff) | |
download | binaryen-cec883550664a64b9f6a425dd68a3caf529fa306.tar.gz binaryen-cec883550664a64b9f6a425dd68a3caf529fa306.tar.bz2 binaryen-cec883550664a64b9f6a425dd68a3caf529fa306.zip |
use names section for function names
Diffstat (limited to 'src')
-rw-r--r-- | src/wasm-binary.h | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 870f5832d..d1dd038c6 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -180,6 +180,7 @@ namespace Section { auto ExportTable = "export_table"; auto DataSegments = "data_segments"; auto FunctionTable = "function_table"; + auto Names = "names"; auto End = "end"; auto Start = "start_function"; }; @@ -422,6 +423,7 @@ public: writeExports(); writeDataSegments(); writeFunctionTable(); + writeNames(); writeEnd(); finishUp(); } @@ -568,15 +570,11 @@ public: for (size_t i = 0; i < total; i++) { if (debug) std::cerr << "write one at" << o.size() << std::endl; Function* function = wasm->functions[i]; - Name name, type; - name = function->name; - type = function->type; mappedLocals.clear(); numLocalsByType.clear(); - if (debug) std::cerr << "writing" << name << std::endl; + if (debug) std::cerr << "writing" << function->name << std::endl; o << int8_t(BinaryConsts::Named | (BinaryConsts::Locals * (function && function->locals.size() > 0))); - emitString(name.str); mapLocals(function); if (function->locals.size() > 0) { o << uint16_t(numLocalsByType[i32]) @@ -654,6 +652,18 @@ public: finishSection(start); } + void writeNames() { + if (wasm->functions.size() == 0) return; + if (debug) std::cerr << "== writeNames" << std::endl; + auto start = startSection(BinaryConsts::Section::Names); + o << LEB128(wasm->functions.size()); + for (auto* curr : wasm->functions) { + writeInlineString(curr->name.str); + o << LEB128(0); // TODO: locals + } + finishSection(start); + } + void writeEnd() { auto start = startSection(BinaryConsts::Section::End); finishSection(start); @@ -1095,6 +1105,7 @@ public: else if (match(BinaryConsts::Section::ExportTable)) readExports(); else if (match(BinaryConsts::Section::DataSegments)) readDataSegments(); else if (match(BinaryConsts::Section::FunctionTable)) readFunctionTable(); + else if (match(BinaryConsts::Section::Names)) readNames(); else if (match(BinaryConsts::Section::End)) { if (debug) std::cerr << "== readEnd" << std::endl; break; @@ -1305,10 +1316,8 @@ public: bool named = data & BinaryConsts::Named; assert(named); bool locals = data & BinaryConsts::Locals; - Name name = getString(); - if (debug) std::cerr << "reading" << name << std::endl; + if (debug) std::cerr << "reading" << i << std::endl; auto func = allocator.alloc<Function>(); - func->name = name; func->type = type->name; func->result = type->result; size_t nextVar = 0; @@ -1461,6 +1470,16 @@ public: } } + void readNames() { + if (debug) std::cerr << "== readNames" << std::endl; + auto num = getLEB128(); + for (size_t i = 0; i < num; i++) { + functions[i]->name = getInlineString(); + auto numLocals = getLEB128(); + assert(numLocals == 0); // TODO + } + } + // AST reading int depth; // only for debugging |