| 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 <stdlib.h> | 5 #include <stdlib.h> |
| 6 #include <string.h> | 6 #include <string.h> |
| 7 | 7 |
| 8 #include "src/wasm/encoder.h" | 8 #include "src/wasm/encoder.h" |
| 9 #include "src/wasm/wasm-js.h" | 9 #include "src/wasm/wasm-js.h" |
| 10 #include "src/wasm/wasm-macro-gen.h" | 10 #include "src/wasm/wasm-macro-gen.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 CHECK_EQ(expected_result, result); | 31 CHECK_EQ(expected_result, result); |
| 32 } | 32 } |
| 33 } // namespace | 33 } // namespace |
| 34 | 34 |
| 35 | 35 |
| 36 // A raw test that skips the WasmModuleBuilder. | 36 // A raw test that skips the WasmModuleBuilder. |
| 37 TEST(Run_WasmModule_CallAdd_rev) { | 37 TEST(Run_WasmModule_CallAdd_rev) { |
| 38 static const byte data[] = { | 38 static const byte data[] = { |
| 39 WASM_MODULE_HEADER, | 39 WASM_MODULE_HEADER, |
| 40 // sig#0 ------------------------------------------ | 40 // sig#0 ------------------------------------------ |
| 41 WASM_SECTION_SIGNATURES_SIZE + 7, // Section size. | 41 WASM_SECTION_SIGNATURES_SIZE + 7, // Section size. |
| 42 WASM_SECTION_SIGNATURES, 2, 0, kLocalI32, // void -> int | 42 WASM_SECTION_SIGNATURES, 2, // -- |
| 43 2, kLocalI32, kLocalI32, kLocalI32, // int,int -> int | 43 0, kLocalI32, // void -> int |
| 44 2, kLocalI32, kLocalI32, kLocalI32, // int,int -> int |
| 44 // func#0 (main) ---------------------------------- | 45 // func#0 (main) ---------------------------------- |
| 45 WASM_SECTION_FUNCTIONS_SIZE + 24, WASM_SECTION_FUNCTIONS, 2, | 46 WASM_SECTION_FUNCTIONS_SIZE + 23, WASM_SECTION_FUNCTIONS, 2, |
| 46 kDeclFunctionExport, 0, 0, // sig index | 47 kDeclFunctionExport, 0, 0, // sig index |
| 47 7, 0, // body size | 48 7, 0, // body size |
| 48 0, // locals | 49 0, // locals |
| 49 kExprCallFunction, 1, // -- | |
| 50 kExprI8Const, 77, // -- | 50 kExprI8Const, 77, // -- |
| 51 kExprI8Const, 22, // -- | 51 kExprI8Const, 22, // -- |
| 52 kExprCallFunction, 1, // -- |
| 52 // func#1 ----------------------------------------- | 53 // func#1 ----------------------------------------- |
| 53 0, // no name, not exported | 54 0, // no name, not exported |
| 54 1, 0, // sig index | 55 1, 0, // sig index |
| 55 6, 0, // body size | 56 6, 0, // body size |
| 56 0, // locals | 57 0, // locals |
| 57 kExprI32Add, // -- | |
| 58 kExprGetLocal, 0, // -- | 58 kExprGetLocal, 0, // -- |
| 59 kExprGetLocal, 1, // -- | 59 kExprGetLocal, 1, // -- |
| 60 kExprI32Add, // -- |
| 60 }; | 61 }; |
| 61 | 62 |
| 62 Isolate* isolate = CcTest::InitIsolateOnce(); | 63 Isolate* isolate = CcTest::InitIsolateOnce(); |
| 63 HandleScope scope(isolate); | 64 HandleScope scope(isolate); |
| 64 WasmJs::InstallWasmFunctionMap(isolate, isolate->native_context()); | 65 WasmJs::InstallWasmFunctionMap(isolate, isolate->native_context()); |
| 65 int32_t result = | 66 int32_t result = |
| 66 CompileAndRunWasmModule(isolate, data, data + arraysize(data)); | 67 CompileAndRunWasmModule(isolate, data, data + arraysize(data)); |
| 67 CHECK_EQ(99, result); | 68 CHECK_EQ(99, result); |
| 68 } | 69 } |
| 69 | 70 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 85 | 86 |
| 86 TEST(Run_WasmModule_CallAdd) { | 87 TEST(Run_WasmModule_CallAdd) { |
| 87 Zone zone; | 88 Zone zone; |
| 88 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 89 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
| 89 uint16_t f1_index = builder->AddFunction(); | 90 uint16_t f1_index = builder->AddFunction(); |
| 90 WasmFunctionBuilder* f = builder->FunctionAt(f1_index); | 91 WasmFunctionBuilder* f = builder->FunctionAt(f1_index); |
| 91 f->ReturnType(kAstI32); | 92 f->ReturnType(kAstI32); |
| 92 uint16_t param1 = f->AddParam(kAstI32); | 93 uint16_t param1 = f->AddParam(kAstI32); |
| 93 uint16_t param2 = f->AddParam(kAstI32); | 94 uint16_t param2 = f->AddParam(kAstI32); |
| 94 byte code1[] = {WASM_I32_ADD(WASM_GET_LOCAL(param1), WASM_GET_LOCAL(param2))}; | 95 byte code1[] = {WASM_I32_ADD(WASM_GET_LOCAL(param1), WASM_GET_LOCAL(param2))}; |
| 95 uint32_t local_indices1[] = {2, 4}; | 96 f->EmitCode(code1, sizeof(code1)); |
| 96 f->EmitCode(code1, sizeof(code1), local_indices1, sizeof(local_indices1) / 4); | |
| 97 uint16_t f2_index = builder->AddFunction(); | 97 uint16_t f2_index = builder->AddFunction(); |
| 98 f = builder->FunctionAt(f2_index); | 98 f = builder->FunctionAt(f2_index); |
| 99 f->ReturnType(kAstI32); | 99 f->ReturnType(kAstI32); |
| 100 f->Exported(1); | 100 f->Exported(1); |
| 101 byte code2[] = {WASM_CALL_FUNCTION(f1_index, WASM_I8(77), WASM_I8(22))}; | 101 byte code2[] = {WASM_CALL_FUNCTION(f1_index, WASM_I8(77), WASM_I8(22))}; |
| 102 f->EmitCode(code2, sizeof(code2)); | 102 f->EmitCode(code2, sizeof(code2)); |
| 103 WasmModuleWriter* writer = builder->Build(&zone); | 103 WasmModuleWriter* writer = builder->Build(&zone); |
| 104 TestModule(writer->WriteTo(&zone), 99); | 104 TestModule(writer->WriteTo(&zone), 99); |
| 105 } | 105 } |
| 106 | 106 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 byte code2[] = {WASM_STORE_GLOBAL(global1, WASM_I32V_1(56)), | 202 byte code2[] = {WASM_STORE_GLOBAL(global1, WASM_I32V_1(56)), |
| 203 WASM_STORE_GLOBAL(global2, WASM_I32V_1(41)), | 203 WASM_STORE_GLOBAL(global2, WASM_I32V_1(41)), |
| 204 WASM_RETURN(WASM_CALL_FUNCTION0(f1_index))}; | 204 WASM_RETURN(WASM_CALL_FUNCTION0(f1_index))}; |
| 205 f->EmitCode(code2, sizeof(code2)); | 205 f->EmitCode(code2, sizeof(code2)); |
| 206 WasmModuleWriter* writer = builder->Build(&zone); | 206 WasmModuleWriter* writer = builder->Build(&zone); |
| 207 TestModule(writer->WriteTo(&zone), 97); | 207 TestModule(writer->WriteTo(&zone), 97); |
| 208 } | 208 } |
| 209 #endif | 209 #endif |
| 210 | 210 |
| 211 #endif // !V8_TARGET_ARCH_ARM64 | 211 #endif // !V8_TARGET_ARCH_ARM64 |
| OLD | NEW |