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

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

Issue 2520943002: [wasm] Implement official wasm text format (Closed)
Patch Set: Address comments Created 4 years, 1 month 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 | « src/wasm/wasm-module.h ('k') | src/wasm/wasm-text.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/wasm-module.cc
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc
index f70467f50dcf87d22122630323370c717fc899fb..f0850f315ec55aefb6334e2976718c61d2e05672 100644
--- a/src/wasm/wasm-module.cc
+++ b/src/wasm/wasm-module.cc
@@ -20,6 +20,7 @@
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects.h"
#include "src/wasm/wasm-result.h"
+#include "src/wasm/wasm-text.h"
#include "src/compiler/wasm-compiler.h"
@@ -634,15 +635,6 @@ std::pair<int, int> GetFunctionOffsetAndLength(
static_cast<int>(func.code_end_offset - func.code_start_offset)};
}
-Vector<const uint8_t> GetFunctionBytes(
- Handle<WasmCompiledModule> compiled_module, int func_index) {
- int offset, length;
- std::tie(offset, length) =
- GetFunctionOffsetAndLength(compiled_module, func_index);
- return Vector<const uint8_t>(
- compiled_module->module_bytes()->GetChars() + offset, length);
-}
-
} // namespace
Handle<JSArrayBuffer> wasm::NewArrayBuffer(Isolate* isolate, size_t size,
@@ -1977,19 +1969,16 @@ Handle<Script> wasm::GetScript(Handle<JSObject> instance) {
std::pair<std::string, std::vector<std::tuple<uint32_t, int, int>>>
wasm::DisassembleFunction(Handle<WasmCompiledModule> compiled_module,
int func_index) {
+ if (func_index < 0 ||
+ static_cast<uint32_t>(func_index) >=
+ compiled_module->module()->functions.size())
+ return {};
+
std::ostringstream disassembly_os;
std::vector<std::tuple<uint32_t, int, int>> offset_table;
- Vector<const uint8_t> func_bytes =
- GetFunctionBytes(compiled_module, func_index);
- DisallowHeapAllocation no_gc;
- if (func_bytes.is_empty()) return {};
-
- AccountingAllocator allocator;
- bool ok = PrintAst(
- &allocator, FunctionBodyForTesting(func_bytes.start(), func_bytes.end()),
- disassembly_os, &offset_table);
- CHECK(ok);
+ PrintWasmText(compiled_module->module(), static_cast<uint32_t>(func_index),
+ disassembly_os, &offset_table);
return {disassembly_os.str(), std::move(offset_table)};
}
@@ -2030,6 +2019,7 @@ MaybeHandle<WasmModuleObject> wasm::CreateModuleObjectFromBytes(
thrower->CompileFailed("Wasm decoding failed", result);
return nothing;
}
+
// The {module_wrapper} will take ownership of the {WasmModule} object,
// and it will be destroyed when the GC reclaims the wrapper object.
Handle<WasmModuleWrapper> module_wrapper =
« no previous file with comments | « src/wasm/wasm-module.h ('k') | src/wasm/wasm-text.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698