OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef WASM_RUN_UTILS_H | 5 #ifndef WASM_RUN_UTILS_H |
6 #define WASM_RUN_UTILS_H | 6 #define WASM_RUN_UTILS_H |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 CHECK_EQ(index, static_cast<uint32_t>(interpreter_index)); | 179 CHECK_EQ(index, static_cast<uint32_t>(interpreter_index)); |
180 } | 180 } |
181 DCHECK_LT(index, kMaxFunctions); // limited for testing. | 181 DCHECK_LT(index, kMaxFunctions); // limited for testing. |
182 return index; | 182 return index; |
183 } | 183 } |
184 | 184 |
185 uint32_t AddJsFunction(FunctionSig* sig, const char* source) { | 185 uint32_t AddJsFunction(FunctionSig* sig, const char* source) { |
186 Handle<JSFunction> jsfunc = Handle<JSFunction>::cast(v8::Utils::OpenHandle( | 186 Handle<JSFunction> jsfunc = Handle<JSFunction>::cast(v8::Utils::OpenHandle( |
187 *v8::Local<v8::Function>::Cast(CompileRun(source)))); | 187 *v8::Local<v8::Function>::Cast(CompileRun(source)))); |
188 uint32_t index = AddFunction(sig, Handle<Code>::null()); | 188 uint32_t index = AddFunction(sig, Handle<Code>::null()); |
189 WasmName module_name = ArrayVector("test"); | 189 Handle<Code> code = |
190 WasmName function_name; | 190 CompileWasmToJSWrapper(isolate_, jsfunc, sig, index, |
191 Handle<Code> code = CompileWasmToJSWrapper(isolate_, jsfunc, sig, | 191 Handle<String>::null(), Handle<String>::null()); |
192 module_name, function_name); | |
193 instance->function_code[index] = code; | 192 instance->function_code[index] = code; |
194 return index; | 193 return index; |
195 } | 194 } |
196 | 195 |
197 Handle<JSFunction> WrapCode(uint32_t index) { | 196 Handle<JSFunction> WrapCode(uint32_t index) { |
198 // Wrap the code so it can be called as a JS function. | 197 // Wrap the code so it can be called as a JS function. |
199 Handle<String> name = isolate_->factory()->NewStringFromStaticChars("main"); | 198 Handle<String> name = isolate_->factory()->NewStringFromStaticChars("main"); |
200 Handle<JSObject> module_object = Handle<JSObject>(0, isolate_); | 199 Handle<JSObject> module_object = Handle<JSObject>(0, isolate_); |
201 Handle<Code> code = instance->function_code[index]; | 200 Handle<Code> code = instance->function_code[index]; |
202 WasmJs::InstallWasmFunctionMap(isolate_, isolate_->native_context()); | 201 WasmJs::InstallWasmFunctionMap(isolate_, isolate_->native_context()); |
203 return compiler::CompileJSToWasmWrapper(isolate_, this, name, code, | 202 Handle<JSFunction> ret = |
204 module_object, index); | 203 compiler::CompileJSToWasmWrapper(isolate_, this, name, code, index); |
| 204 ret->SetInternalField(0, *module_object); |
| 205 return ret; |
205 } | 206 } |
206 | 207 |
207 void SetFunctionCode(uint32_t index, Handle<Code> code) { | 208 void SetFunctionCode(uint32_t index, Handle<Code> code) { |
208 instance->function_code[index] = code; | 209 instance->function_code[index] = code; |
209 } | 210 } |
210 | 211 |
211 void AddIndirectFunctionTable(int* functions, int table_size) { | 212 void AddIndirectFunctionTable(int* functions, int table_size) { |
212 Handle<FixedArray> fixed = | 213 Handle<FixedArray> fixed = |
213 isolate_->factory()->NewFixedArray(2 * table_size); | 214 isolate_->factory()->NewFixedArray(2 * table_size); |
214 instance->function_table = fixed; | 215 instance->function_table = fixed; |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
754 // interpreter. | 755 // interpreter. |
755 #define WASM_EXEC_TEST(name) \ | 756 #define WASM_EXEC_TEST(name) \ |
756 void RunWasm_##name(WasmExecutionMode execution_mode); \ | 757 void RunWasm_##name(WasmExecutionMode execution_mode); \ |
757 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ | 758 TEST(RunWasmCompiled_##name) { RunWasm_##name(kExecuteCompiled); } \ |
758 TEST(RunWasmInterpreted_##name) { RunWasm_##name(kExecuteInterpreted); } \ | 759 TEST(RunWasmInterpreted_##name) { RunWasm_##name(kExecuteInterpreted); } \ |
759 void RunWasm_##name(WasmExecutionMode execution_mode) | 760 void RunWasm_##name(WasmExecutionMode execution_mode) |
760 | 761 |
761 } // namespace | 762 } // namespace |
762 | 763 |
763 #endif | 764 #endif |
OLD | NEW |