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

Side by Side Diff: src/asmjs/asm-js.cc

Issue 2299873002: [wasm] consolidate wasm and asm.js module compilation sequence (Closed)
Patch Set: [wasm] consolidate wasm and asm.js module compilation sequence Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « src/api.cc ('k') | src/runtime/runtime-test.cc » ('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 "src/asmjs/asm-js.h" 5 #include "src/asmjs/asm-js.h"
6 6
7 #include "src/api-natives.h" 7 #include "src/api-natives.h"
8 #include "src/api.h" 8 #include "src/api.h"
9 #include "src/asmjs/asm-typer.h" 9 #include "src/asmjs/asm-typer.h"
10 #include "src/asmjs/asm-wasm-builder.h" 10 #include "src/asmjs/asm-wasm-builder.h"
(...skipping 12 matching lines...) Expand all
23 #include "src/wasm/wasm-result.h" 23 #include "src/wasm/wasm-result.h"
24 24
25 typedef uint8_t byte; 25 typedef uint8_t byte;
26 26
27 using v8::internal::wasm::ErrorThrower; 27 using v8::internal::wasm::ErrorThrower;
28 28
29 namespace v8 { 29 namespace v8 {
30 namespace internal { 30 namespace internal {
31 31
32 namespace { 32 namespace {
33 i::MaybeHandle<i::FixedArray> CompileModule(
34 i::Isolate* isolate, const byte* start, const byte* end,
35 ErrorThrower* thrower,
36 internal::wasm::ModuleOrigin origin = i::wasm::kWasmOrigin) {
37 // Decode but avoid a redundant pass over function bodies for verification.
38 // Verification will happen during compilation.
39 i::Zone zone(isolate->allocator());
40 internal::wasm::ModuleResult result = internal::wasm::DecodeWasmModule(
41 isolate, &zone, start, end, false, origin);
42
43 i::MaybeHandle<i::FixedArray> compiled_module;
44 if (result.failed() && origin == internal::wasm::kAsmJsOrigin) {
45 thrower->Error("Asm.js converted module failed to decode");
46 } else if (result.failed()) {
47 thrower->Failed("", result);
48 } else {
49 compiled_module = result.val->CompileFunctions(isolate, thrower);
50 }
51
52 if (result.val) delete result.val;
53 return compiled_module;
54 }
55
56 Handle<i::Object> StdlibMathMember(i::Isolate* isolate, 33 Handle<i::Object> StdlibMathMember(i::Isolate* isolate,
57 Handle<JSReceiver> stdlib, 34 Handle<JSReceiver> stdlib,
58 Handle<Name> name) { 35 Handle<Name> name) {
59 if (stdlib.is_null()) { 36 if (stdlib.is_null()) {
60 return Handle<i::Object>(); 37 return Handle<i::Object>();
61 } 38 }
62 Handle<i::Name> math_name( 39 Handle<i::Name> math_name(
63 isolate->factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("Math"))); 40 isolate->factory()->InternalizeOneByteString(STATIC_CHAR_VECTOR("Math")));
64 MaybeHandle<i::Object> maybe_math = i::Object::GetProperty(stdlib, math_name); 41 MaybeHandle<i::Object> maybe_math = i::Object::GetProperty(stdlib, math_name);
65 if (maybe_math.is_null()) { 42 if (maybe_math.is_null()) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 if (!typer.Validate()) { 157 if (!typer.Validate()) {
181 DCHECK(!info->isolate()->has_pending_exception()); 158 DCHECK(!info->isolate()->has_pending_exception());
182 PrintF("Validation of asm.js module failed: %s", typer.error_message()); 159 PrintF("Validation of asm.js module failed: %s", typer.error_message());
183 return MaybeHandle<FixedArray>(); 160 return MaybeHandle<FixedArray>();
184 } 161 }
185 v8::internal::wasm::AsmWasmBuilder builder(info->isolate(), info->zone(), 162 v8::internal::wasm::AsmWasmBuilder builder(info->isolate(), info->zone(),
186 info->literal(), &typer); 163 info->literal(), &typer);
187 i::Handle<i::FixedArray> foreign_globals; 164 i::Handle<i::FixedArray> foreign_globals;
188 auto module = builder.Run(&foreign_globals); 165 auto module = builder.Run(&foreign_globals);
189 166
190 i::MaybeHandle<i::FixedArray> compiled = 167 i::MaybeHandle<i::JSObject> compiled = wasm::CreateModuleObjectFromBytes(
191 CompileModule(info->isolate(), module->begin(), module->end(), &thrower, 168 info->isolate(), module->begin(), module->end(), &thrower,
192 internal::wasm::kAsmJsOrigin); 169 internal::wasm::kAsmJsOrigin);
193 DCHECK(!compiled.is_null()); 170 DCHECK(!compiled.is_null());
194 171
195 wasm::AsmTyper::StdlibSet uses = typer.StdlibUses(); 172 wasm::AsmTyper::StdlibSet uses = typer.StdlibUses();
196 Handle<FixedArray> uses_array = 173 Handle<FixedArray> uses_array =
197 info->isolate()->factory()->NewFixedArray(static_cast<int>(uses.size())); 174 info->isolate()->factory()->NewFixedArray(static_cast<int>(uses.size()));
198 int count = 0; 175 int count = 0;
199 for (auto i : uses) { 176 for (auto i : uses) {
200 uses_array->set(count++, Smi::FromInt(i)); 177 uses_array->set(count++, Smi::FromInt(i));
201 } 178 }
202 179
(...skipping 13 matching lines...) Expand all
216 return false; 193 return false;
217 } 194 }
218 } 195 }
219 return true; 196 return true;
220 } 197 }
221 198
222 MaybeHandle<Object> AsmJs::InstantiateAsmWasm(i::Isolate* isolate, 199 MaybeHandle<Object> AsmJs::InstantiateAsmWasm(i::Isolate* isolate,
223 Handle<FixedArray> wasm_data, 200 Handle<FixedArray> wasm_data,
224 Handle<JSArrayBuffer> memory, 201 Handle<JSArrayBuffer> memory,
225 Handle<JSReceiver> foreign) { 202 Handle<JSReceiver> foreign) {
226 i::Handle<i::FixedArray> compiled(i::FixedArray::cast(wasm_data->get(0))); 203 i::Handle<i::JSObject> module(i::JSObject::cast(wasm_data->get(0)));
204 i::Handle<i::FixedArray> compiled(
205 i::FixedArray::cast(module->GetInternalField(0)));
227 i::Handle<i::FixedArray> foreign_globals( 206 i::Handle<i::FixedArray> foreign_globals(
228 i::FixedArray::cast(wasm_data->get(1))); 207 i::FixedArray::cast(wasm_data->get(1)));
229 208
230 ErrorThrower thrower(isolate, "Asm.js -> WebAssembly instantiation"); 209 ErrorThrower thrower(isolate, "Asm.js -> WebAssembly instantiation");
231 210
232 i::MaybeHandle<i::JSObject> maybe_module_object = 211 i::MaybeHandle<i::JSObject> maybe_module_object =
233 i::wasm::WasmModule::Instantiate(isolate, compiled, foreign, memory); 212 i::wasm::WasmModule::Instantiate(isolate, compiled, foreign, memory);
234 if (maybe_module_object.is_null()) { 213 if (maybe_module_object.is_null()) {
235 return MaybeHandle<Object>(); 214 return MaybeHandle<Object>();
236 } 215 }
(...skipping 29 matching lines...) Expand all
266 isolate, init, undefined, foreign_globals->length(), foreign_args_array); 245 isolate, init, undefined, foreign_globals->length(), foreign_args_array);
267 delete[] foreign_args_array; 246 delete[] foreign_args_array;
268 247
269 DCHECK(!retval.is_null()); 248 DCHECK(!retval.is_null());
270 249
271 return maybe_module_object; 250 return maybe_module_object;
272 } 251 }
273 252
274 } // namespace internal 253 } // namespace internal
275 } // namespace v8 254 } // namespace v8
OLDNEW
« no previous file with comments | « src/api.cc ('k') | src/runtime/runtime-test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698