| 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
|
| };
|
|
|
| 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
|
| +};
|
| +
|
| +static uint8_t wasmSectionsOrders[]{
|
| +#define F(enumerator, order, string) order,
|
| FOR_EACH_WASM_SECTION_TYPE(F)
|
| #undef F
|
| };
|
| @@ -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";
|
|
|