Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Unified Diff: src/wasm/module-decoder.cc

Issue 1765843002: wasm: use strings for section names (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/module-decoder.cc
diff --git a/src/wasm/module-decoder.cc b/src/wasm/module-decoder.cc
index 4653e1d44bd7b53b145afb4bc8fbf8843231f6af..086788f4e8ccf8a271fe180ead88119b35bc62b5 100644
--- a/src/wasm/module-decoder.cc
+++ b/src/wasm/module-decoder.cc
@@ -78,18 +78,17 @@ class ModuleDecoder : public Decoder {
// Decode the module sections.
while (pc_ < limit_) {
TRACE("DecodeSection\n");
- uint8_t section_u8 = consume_u8("section");
+ int length;
+ uint32_t section_bytes = consume_u32v(&length, "section size");
titzer 2016/03/07 08:45:33 Should the section size also include the string si
JF 2016/03/09 02:38:57 Agreed, fixed.
- if (section_u8 >= kMaxModuleSectionCode) {
+ WasmSectionDeclCode section = consume_section_name();
+ if (section == kMaxModuleSectionCode) {
// Skip unknown section.
- int length;
- uint32_t section_bytes = consume_u32v(&length, "section size");
consume_bytes(section_bytes);
continue;
}
// Each section should appear at most once.
- auto section = static_cast<WasmSectionDeclCode>(section_u8);
CheckForPreviousSection(sections, section, false);
sections[section] = true;
@@ -521,6 +520,35 @@ class ModuleDecoder : public Decoder {
return consume_offset(name ? name : "string");
}
+ // Reads a section name.
+ WasmSectionDeclCode consume_section_name() {
+ static const char* sections[] = {
+#define F(enumerator, string) string,
+ FOR_EACH_WASM_SECTION_TYPE(F)
+#undef F
+ };
+ static uint8_t sizes[] {
+#define F(enumerator, string) sizeof(string),
+ FOR_EACH_WASM_SECTION_TYPE(F)
+#undef F
+ };
+ static_assert(
+ sizeof(sections) / sizeof(sections[0]) == kMaxModuleSectionCode,
+ "expected enum WasmSectionDeclCode to be monotonic from 0");
+ int length;
+ uint32_t string_bytes = consume_u32v(&length, "section module name");
+ const byte* start = pc_;
+ consume_bytes(string_bytes);
+ if (failed()) return kMaxModuleSectionCode;
+ for (size_t i = 0; i != kMaxModuleSectionCode; ++i) {
+ if (sizes[i] == string_bytes &&
+ 0 == memcmp(sections[i], start, string_bytes)) {
+ return (WasmSectionDeclCode)i;
+ }
+ }
+ return kMaxModuleSectionCode;
+ }
+
// Reads a single 8-bit integer, interpreting it as a local type.
LocalType consume_local_type() {
byte val = consume_u8("local type");
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698