OLD | NEW |
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/macro-assembler.h" | 5 #include "src/macro-assembler.h" |
6 #include "src/objects.h" | 6 #include "src/objects.h" |
7 #include "src/v8.h" | 7 #include "src/v8.h" |
8 | 8 |
9 #include "src/simulator.h" | 9 #include "src/simulator.h" |
10 | 10 |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 195 |
196 | 196 |
197 Handle<JSArrayBuffer> NewArrayBuffer(Isolate* isolate, int size, | 197 Handle<JSArrayBuffer> NewArrayBuffer(Isolate* isolate, int size, |
198 byte** backing_store) { | 198 byte** backing_store) { |
199 void* memory = isolate->array_buffer_allocator()->Allocate(size); | 199 void* memory = isolate->array_buffer_allocator()->Allocate(size); |
200 if (!memory) return Handle<JSArrayBuffer>::null(); | 200 if (!memory) return Handle<JSArrayBuffer>::null(); |
201 *backing_store = reinterpret_cast<byte*>(memory); | 201 *backing_store = reinterpret_cast<byte*>(memory); |
202 | 202 |
203 #if DEBUG | 203 #if DEBUG |
204 // Double check the API allocator actually zero-initialized the memory. | 204 // Double check the API allocator actually zero-initialized the memory. |
205 for (uint32_t i = 0; i < size; i++) { | 205 for (int i = 0; i < size; i++) { |
206 DCHECK_EQ(0, (*backing_store)[i]); | 206 DCHECK_EQ(0, (*backing_store)[i]); |
207 } | 207 } |
208 #endif | 208 #endif |
209 | 209 |
210 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); | 210 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); |
211 JSArrayBuffer::Setup(buffer, isolate, true, memory, size); | 211 JSArrayBuffer::Setup(buffer, isolate, false, memory, size); |
212 buffer->set_is_neuterable(false); | 212 buffer->set_is_neuterable(false); |
213 return buffer; | 213 return buffer; |
214 } | 214 } |
215 } // namespace | 215 } // namespace |
216 | 216 |
217 | 217 |
| 218 WasmModule::WasmModule() |
| 219 : globals(nullptr), |
| 220 signatures(nullptr), |
| 221 functions(nullptr), |
| 222 data_segments(nullptr), |
| 223 function_table(nullptr) {} |
| 224 |
| 225 |
| 226 WasmModule::~WasmModule() { |
| 227 if (globals) delete globals; |
| 228 if (signatures) delete signatures; |
| 229 if (functions) delete functions; |
| 230 if (data_segments) delete data_segments; |
| 231 if (function_table) delete function_table; |
| 232 } |
| 233 |
| 234 |
218 // Instantiates a wasm module as a JSObject. | 235 // Instantiates a wasm module as a JSObject. |
219 // * allocates a backing store of {mem_size} bytes. | 236 // * allocates a backing store of {mem_size} bytes. |
220 // * installs a named property "memory" for that buffer if exported | 237 // * installs a named property "memory" for that buffer if exported |
221 // * installs named properties on the object for exported functions | 238 // * installs named properties on the object for exported functions |
222 // * compiles wasm code to machine code | 239 // * compiles wasm code to machine code |
223 MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate, | 240 MaybeHandle<JSObject> WasmModule::Instantiate(Isolate* isolate, |
224 Handle<JSObject> ffi, | 241 Handle<JSObject> ffi, |
225 Handle<JSArrayBuffer> memory) { | 242 Handle<JSArrayBuffer> memory) { |
226 this->shared_isolate = isolate; // TODO(titzer): have a real shared isolate. | 243 this->shared_isolate = isolate; // TODO(titzer): have a real shared isolate. |
227 ErrorThrower thrower(isolate, "WasmModule::Instantiate()"); | 244 ErrorThrower thrower(isolate, "WasmModule::Instantiate()"); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 } else { | 362 } else { |
346 // Compile the function. | 363 // Compile the function. |
347 code = compiler::CompileWasmFunction(thrower, isolate, &module_env, func, | 364 code = compiler::CompileWasmFunction(thrower, isolate, &module_env, func, |
348 index); | 365 index); |
349 if (code.is_null()) { | 366 if (code.is_null()) { |
350 thrower.Error("Compilation of #%d:%s failed.", index, cstr); | 367 thrower.Error("Compilation of #%d:%s failed.", index, cstr); |
351 return MaybeHandle<JSObject>(); | 368 return MaybeHandle<JSObject>(); |
352 } | 369 } |
353 if (func.exported) { | 370 if (func.exported) { |
354 function = compiler::CompileJSToWasmWrapper(isolate, &module_env, name, | 371 function = compiler::CompileJSToWasmWrapper(isolate, &module_env, name, |
355 code, index); | 372 code, module, index); |
356 } | 373 } |
357 } | 374 } |
358 if (!code.is_null()) { | 375 if (!code.is_null()) { |
359 // Install the code into the linker table. | 376 // Install the code into the linker table. |
360 linker.Finish(index, code); | 377 linker.Finish(index, code); |
361 code_table->set(index, *code); | 378 code_table->set(index, *code); |
362 } | 379 } |
363 if (func.exported) { | 380 if (func.exported) { |
364 // Exported functions are installed as read-only properties on the module. | 381 // Exported functions are installed as read-only properties on the module. |
365 JSObject::AddProperty(module, name, function, READ_ONLY); | 382 JSObject::AddProperty(module, name, function, READ_ONLY); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 Simulator::CallArgument args[] = {Simulator::CallArgument(0), | 488 Simulator::CallArgument args[] = {Simulator::CallArgument(0), |
472 Simulator::CallArgument::End()}; | 489 Simulator::CallArgument::End()}; |
473 return static_cast<int32_t>(simulator->CallInt64(main_code->entry(), args)); | 490 return static_cast<int32_t>(simulator->CallInt64(main_code->entry(), args)); |
474 #elif USE_SIMULATOR | 491 #elif USE_SIMULATOR |
475 // Run the main code on simulator. | 492 // Run the main code on simulator. |
476 Simulator* simulator = Simulator::current(isolate); | 493 Simulator* simulator = Simulator::current(isolate); |
477 return static_cast<int32_t>( | 494 return static_cast<int32_t>( |
478 simulator->Call(main_code->entry(), 4, 0, 0, 0, 0)); | 495 simulator->Call(main_code->entry(), 4, 0, 0, 0, 0)); |
479 #else | 496 #else |
480 // Run the main code as raw machine code. | 497 // Run the main code as raw machine code. |
481 int32_t (*raw_func)() = reinterpret_cast<int (*)()>(main_code->entry()); | 498 int32_t (*raw_func)() = reinterpret_cast<int32_t (*)()>( |
| 499 reinterpret_cast<uintptr_t>(main_code->entry())); |
482 return raw_func(); | 500 return raw_func(); |
483 #endif | 501 #endif |
484 } else { | 502 } else { |
485 // No main code was found. | 503 // No main code was found. |
486 isolate->Throw(*isolate->factory()->NewStringFromStaticChars( | 504 isolate->Throw(*isolate->factory()->NewStringFromStaticChars( |
487 "WASM.compileRun() failed: no valid main code produced.")); | 505 "WASM.compileRun() failed: no valid main code produced.")); |
488 } | 506 } |
489 return -1; | 507 return -1; |
490 } | 508 } |
491 } // namespace wasm | 509 } // namespace wasm |
492 } // namespace internal | 510 } // namespace internal |
493 } // namespace v8 | 511 } // namespace v8 |
OLD | NEW |