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

Side by Side Diff: src/wasm/wasm-module.cc

Issue 2520943002: [wasm] Implement official wasm text format (Closed)
Patch Set: Address comments Created 4 years 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 unified diff | Download patch
« no previous file with comments | « src/wasm/wasm-module.h ('k') | src/wasm/wasm-text.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <memory> 5 #include <memory>
6 6
7 #include "src/base/atomic-utils.h" 7 #include "src/base/atomic-utils.h"
8 #include "src/code-stubs.h" 8 #include "src/code-stubs.h"
9 9
10 #include "src/macro-assembler.h" 10 #include "src/macro-assembler.h"
11 #include "src/objects.h" 11 #include "src/objects.h"
12 #include "src/property-descriptor.h" 12 #include "src/property-descriptor.h"
13 #include "src/simulator.h" 13 #include "src/simulator.h"
14 #include "src/snapshot/snapshot.h" 14 #include "src/snapshot/snapshot.h"
15 #include "src/v8.h" 15 #include "src/v8.h"
16 16
17 #include "src/wasm/ast-decoder.h" 17 #include "src/wasm/ast-decoder.h"
18 #include "src/wasm/module-decoder.h" 18 #include "src/wasm/module-decoder.h"
19 #include "src/wasm/wasm-js.h" 19 #include "src/wasm/wasm-js.h"
20 #include "src/wasm/wasm-module.h" 20 #include "src/wasm/wasm-module.h"
21 #include "src/wasm/wasm-objects.h" 21 #include "src/wasm/wasm-objects.h"
22 #include "src/wasm/wasm-result.h" 22 #include "src/wasm/wasm-result.h"
23 #include "src/wasm/wasm-text.h"
23 24
24 #include "src/compiler/wasm-compiler.h" 25 #include "src/compiler/wasm-compiler.h"
25 26
26 using namespace v8::internal; 27 using namespace v8::internal;
27 using namespace v8::internal::wasm; 28 using namespace v8::internal::wasm;
28 namespace base = v8::base; 29 namespace base = v8::base;
29 30
30 #define TRACE(...) \ 31 #define TRACE(...) \
31 do { \ 32 do { \
32 if (FLAG_trace_wasm_instances) PrintF(__VA_ARGS__); \ 33 if (FLAG_trace_wasm_instances) PrintF(__VA_ARGS__); \
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 WasmModule* module = compiled_module->module(); 628 WasmModule* module = compiled_module->module();
628 if (func_index < 0 || 629 if (func_index < 0 ||
629 static_cast<size_t>(func_index) > module->functions.size()) { 630 static_cast<size_t>(func_index) > module->functions.size()) {
630 return {0, 0}; 631 return {0, 0};
631 } 632 }
632 WasmFunction& func = module->functions[func_index]; 633 WasmFunction& func = module->functions[func_index];
633 return {static_cast<int>(func.code_start_offset), 634 return {static_cast<int>(func.code_start_offset),
634 static_cast<int>(func.code_end_offset - func.code_start_offset)}; 635 static_cast<int>(func.code_end_offset - func.code_start_offset)};
635 } 636 }
636 637
637 Vector<const uint8_t> GetFunctionBytes(
638 Handle<WasmCompiledModule> compiled_module, int func_index) {
639 int offset, length;
640 std::tie(offset, length) =
641 GetFunctionOffsetAndLength(compiled_module, func_index);
642 return Vector<const uint8_t>(
643 compiled_module->module_bytes()->GetChars() + offset, length);
644 }
645
646 } // namespace 638 } // namespace
647 639
648 Handle<JSArrayBuffer> wasm::NewArrayBuffer(Isolate* isolate, size_t size, 640 Handle<JSArrayBuffer> wasm::NewArrayBuffer(Isolate* isolate, size_t size,
649 bool enable_guard_regions) { 641 bool enable_guard_regions) {
650 if (size > (WasmModule::kV8MaxPages * WasmModule::kPageSize)) { 642 if (size > (WasmModule::kV8MaxPages * WasmModule::kPageSize)) {
651 // TODO(titzer): lift restriction on maximum memory allocated here. 643 // TODO(titzer): lift restriction on maximum memory allocated here.
652 return Handle<JSArrayBuffer>::null(); 644 return Handle<JSArrayBuffer>::null();
653 } 645 }
654 646
655 enable_guard_regions = enable_guard_regions && kGuardRegionsSupported; 647 enable_guard_regions = enable_guard_regions && kGuardRegionsSupported;
(...skipping 1314 matching lines...) Expand 10 before | Expand all | Expand 10 after
1970 Handle<Script> wasm::GetScript(Handle<JSObject> instance) { 1962 Handle<Script> wasm::GetScript(Handle<JSObject> instance) {
1971 WasmCompiledModule* compiled_module = 1963 WasmCompiledModule* compiled_module =
1972 WasmInstanceObject::cast(*instance)->get_compiled_module(); 1964 WasmInstanceObject::cast(*instance)->get_compiled_module();
1973 DCHECK(compiled_module->has_script()); 1965 DCHECK(compiled_module->has_script());
1974 return compiled_module->script(); 1966 return compiled_module->script();
1975 } 1967 }
1976 1968
1977 std::pair<std::string, std::vector<std::tuple<uint32_t, int, int>>> 1969 std::pair<std::string, std::vector<std::tuple<uint32_t, int, int>>>
1978 wasm::DisassembleFunction(Handle<WasmCompiledModule> compiled_module, 1970 wasm::DisassembleFunction(Handle<WasmCompiledModule> compiled_module,
1979 int func_index) { 1971 int func_index) {
1972 if (func_index < 0 ||
1973 static_cast<uint32_t>(func_index) >=
1974 compiled_module->module()->functions.size())
1975 return {};
1976
1980 std::ostringstream disassembly_os; 1977 std::ostringstream disassembly_os;
1981 std::vector<std::tuple<uint32_t, int, int>> offset_table; 1978 std::vector<std::tuple<uint32_t, int, int>> offset_table;
1982 1979
1983 Vector<const uint8_t> func_bytes = 1980 PrintWasmText(compiled_module->module(), static_cast<uint32_t>(func_index),
1984 GetFunctionBytes(compiled_module, func_index); 1981 disassembly_os, &offset_table);
1985 DisallowHeapAllocation no_gc;
1986 if (func_bytes.is_empty()) return {};
1987
1988 AccountingAllocator allocator;
1989 bool ok = PrintAst(
1990 &allocator, FunctionBodyForTesting(func_bytes.start(), func_bytes.end()),
1991 disassembly_os, &offset_table);
1992 CHECK(ok);
1993 1982
1994 return {disassembly_os.str(), std::move(offset_table)}; 1983 return {disassembly_os.str(), std::move(offset_table)};
1995 } 1984 }
1996 1985
1997 int wasm::GetAsmWasmSourcePosition(Handle<JSObject> instance, int func_index, 1986 int wasm::GetAsmWasmSourcePosition(Handle<JSObject> instance, int func_index,
1998 int byte_offset) { 1987 int byte_offset) {
1999 return WasmDebugInfo::GetAsmJsSourcePosition(GetDebugInfo(instance), 1988 return WasmDebugInfo::GetAsmJsSourcePosition(GetDebugInfo(instance),
2000 func_index, byte_offset); 1989 func_index, byte_offset);
2001 } 1990 }
2002 1991
(...skipping 20 matching lines...) Expand all
2023 ModuleOrigin origin, Handle<Script> asm_js_script, 2012 ModuleOrigin origin, Handle<Script> asm_js_script,
2024 const byte* asm_js_offset_tables_start, 2013 const byte* asm_js_offset_tables_start,
2025 const byte* asm_js_offset_tables_end) { 2014 const byte* asm_js_offset_tables_end) {
2026 MaybeHandle<WasmModuleObject> nothing; 2015 MaybeHandle<WasmModuleObject> nothing;
2027 ModuleResult result = DecodeWasmModule(isolate, start, end, false, origin); 2016 ModuleResult result = DecodeWasmModule(isolate, start, end, false, origin);
2028 if (result.failed()) { 2017 if (result.failed()) {
2029 if (result.val) delete result.val; 2018 if (result.val) delete result.val;
2030 thrower->CompileFailed("Wasm decoding failed", result); 2019 thrower->CompileFailed("Wasm decoding failed", result);
2031 return nothing; 2020 return nothing;
2032 } 2021 }
2022
2033 // The {module_wrapper} will take ownership of the {WasmModule} object, 2023 // The {module_wrapper} will take ownership of the {WasmModule} object,
2034 // and it will be destroyed when the GC reclaims the wrapper object. 2024 // and it will be destroyed when the GC reclaims the wrapper object.
2035 Handle<WasmModuleWrapper> module_wrapper = 2025 Handle<WasmModuleWrapper> module_wrapper =
2036 WasmModuleWrapper::New(isolate, const_cast<WasmModule*>(result.val)); 2026 WasmModuleWrapper::New(isolate, const_cast<WasmModule*>(result.val));
2037 2027
2038 // Compile the functions of the module, producing a compiled module. 2028 // Compile the functions of the module, producing a compiled module.
2039 MaybeHandle<WasmCompiledModule> maybe_compiled_module = 2029 MaybeHandle<WasmCompiledModule> maybe_compiled_module =
2040 result.val->CompileFunctions(isolate, module_wrapper, thrower); 2030 result.val->CompileFunctions(isolate, module_wrapper, thrower);
2041 2031
2042 if (maybe_compiled_module.is_null()) return nothing; 2032 if (maybe_compiled_module.is_null()) return nothing;
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
2305 MaybeHandle<String> WasmCompiledModule::GetFunctionName( 2295 MaybeHandle<String> WasmCompiledModule::GetFunctionName(
2306 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { 2296 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) {
2307 DCHECK_LT(func_index, compiled_module->module()->functions.size()); 2297 DCHECK_LT(func_index, compiled_module->module()->functions.size());
2308 WasmFunction& function = compiled_module->module()->functions[func_index]; 2298 WasmFunction& function = compiled_module->module()->functions[func_index];
2309 Isolate* isolate = compiled_module->GetIsolate(); 2299 Isolate* isolate = compiled_module->GetIsolate();
2310 MaybeHandle<String> string = ExtractStringFromModuleBytes( 2300 MaybeHandle<String> string = ExtractStringFromModuleBytes(
2311 isolate, compiled_module, function.name_offset, function.name_length); 2301 isolate, compiled_module, function.name_offset, function.name_length);
2312 if (!string.is_null()) return string.ToHandleChecked(); 2302 if (!string.is_null()) return string.ToHandleChecked();
2313 return {}; 2303 return {};
2314 } 2304 }
OLDNEW
« 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