Chromium Code Reviews| Index: src/wasm/wasm-module.cc |
| diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc |
| index 79b7c405fe2f3de4208c1bef5014d6a86964a9af..8b2caeec70951f8af60a241560a967d9d49913ad 100644 |
| --- a/src/wasm/wasm-module.cc |
| +++ b/src/wasm/wasm-module.cc |
| @@ -20,13 +20,19 @@ namespace internal { |
| namespace wasm { |
| static const char* wasmSections[] = { |
| -#define F(enumerator, string) string, |
| +#define F(enumerator, order, string) string, |
| FOR_EACH_WASM_SECTION_TYPE(F) |
| #undef F |
|
JF
2016/04/20 17:59:54
Need an entry for Code::Max. Should probably make
titzer
2016/04/21 10:59:22
done.
|
| }; |
| static uint8_t wasmSectionsLengths[]{ |
| -#define F(enumerator, string) sizeof(string) - 1, |
| +#define F(enumerator, order, string) sizeof(string) - 1, |
| + FOR_EACH_WASM_SECTION_TYPE(F) |
| +#undef F |
|
JF
2016/04/20 17:59:54
Same, but this one's weird.
titzer
2016/04/21 10:59:22
done
|
| +}; |
| + |
| +static uint8_t wasmSectionsOrders[]{ |
| +#define F(enumerator, order, string) order, |
| FOR_EACH_WASM_SECTION_TYPE(F) |
| #undef F |
|
JF
2016/04/20 17:59:54
Need a 0 at the end for Code::Max?
titzer
2016/04/21 10:59:22
done
|
| }; |
| @@ -49,6 +55,20 @@ size_t WasmSection::getNameLength(WasmSection::Code code) { |
| return wasmSectionsLengths[(size_t)code]; |
| } |
| +int WasmSection::getOrder(WasmSection::Code code) { |
| + return wasmSectionsOrders[(size_t)code]; |
| +} |
| + |
| +WasmSection::Code WasmSection::lookup(const byte* string, uint32_t length) { |
| + // TODO(jfb) Linear search, it may be better to do a common-prefix search. |
| + for (Code i = begin(); i != end(); i = next(i)) { |
| + if (getNameLength(i) == length && 0 == memcmp(getName(i), string, length)) { |
| + return i; |
| + } |
| + } |
| + return Code::Max; |
| +} |
| + |
| std::ostream& operator<<(std::ostream& os, const WasmModule& module) { |
| os << "WASM module with "; |
| os << (module.min_mem_pages * module.kPageSize) << " min mem"; |