| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 #include <stdlib.h> | 6 #include <stdlib.h> |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include "src/wasm/wasm-macro-gen.h" | 9 #include "src/wasm/wasm-macro-gen.h" |
| 10 | 10 |
| (...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 BUILD(r, WASM_BLOCK(2, WASM_SELECT(WASM_SET_LOCAL(0, WASM_I8(0)), | 952 BUILD(r, WASM_BLOCK(2, WASM_SELECT(WASM_SET_LOCAL(0, WASM_I8(0)), |
| 953 WASM_SET_LOCAL(0, WASM_I8(1)), | 953 WASM_SET_LOCAL(0, WASM_I8(1)), |
| 954 WASM_SET_LOCAL(0, WASM_I8(2))), | 954 WASM_SET_LOCAL(0, WASM_I8(2))), |
| 955 WASM_GET_LOCAL(0))); | 955 WASM_GET_LOCAL(0))); |
| 956 FOR_INT32_INPUTS(i) { CHECK_EQ(2, r.Call(*i)); } | 956 FOR_INT32_INPUTS(i) { CHECK_EQ(2, r.Call(*i)); } |
| 957 } | 957 } |
| 958 | 958 |
| 959 | 959 |
| 960 TEST(Run_Wasm_Select_strict2) { | 960 TEST(Run_Wasm_Select_strict2) { |
| 961 WasmRunner<int32_t> r(MachineType::Int32()); | 961 WasmRunner<int32_t> r(MachineType::Int32()); |
| 962 r.env()->AddLocals(kAstI32, 2); | 962 r.AllocateLocal(kAstI32); |
| 963 r.AllocateLocal(kAstI32); |
| 963 // select(b=5, c=6, a) | 964 // select(b=5, c=6, a) |
| 964 BUILD(r, WASM_SELECT(WASM_SET_LOCAL(1, WASM_I8(5)), | 965 BUILD(r, WASM_SELECT(WASM_SET_LOCAL(1, WASM_I8(5)), |
| 965 WASM_SET_LOCAL(2, WASM_I8(6)), WASM_GET_LOCAL(0))); | 966 WASM_SET_LOCAL(2, WASM_I8(6)), WASM_GET_LOCAL(0))); |
| 966 FOR_INT32_INPUTS(i) { | 967 FOR_INT32_INPUTS(i) { |
| 967 int32_t expected = *i ? 5 : 6; | 968 int32_t expected = *i ? 5 : 6; |
| 968 CHECK_EQ(expected, r.Call(*i)); | 969 CHECK_EQ(expected, r.Call(*i)); |
| 969 } | 970 } |
| 970 } | 971 } |
| 971 | 972 |
| 972 TEST(Run_Wasm_Select_strict3) { | 973 TEST(Run_Wasm_Select_strict3) { |
| 973 WasmRunner<int32_t> r(MachineType::Int32()); | 974 WasmRunner<int32_t> r(MachineType::Int32()); |
| 974 r.env()->AddLocals(kAstI32, 2); | 975 r.AllocateLocal(kAstI32); |
| 976 r.AllocateLocal(kAstI32); |
| 975 // select(b=5, c=6, a=b) | 977 // select(b=5, c=6, a=b) |
| 976 BUILD(r, WASM_SELECT(WASM_SET_LOCAL(1, WASM_I8(5)), | 978 BUILD(r, WASM_SELECT(WASM_SET_LOCAL(1, WASM_I8(5)), |
| 977 WASM_SET_LOCAL(2, WASM_I8(6)), | 979 WASM_SET_LOCAL(2, WASM_I8(6)), |
| 978 WASM_SET_LOCAL(0, WASM_GET_LOCAL(1)))); | 980 WASM_SET_LOCAL(0, WASM_GET_LOCAL(1)))); |
| 979 FOR_INT32_INPUTS(i) { | 981 FOR_INT32_INPUTS(i) { |
| 980 int32_t expected = 5; | 982 int32_t expected = 5; |
| 981 CHECK_EQ(expected, r.Call(*i)); | 983 CHECK_EQ(expected, r.Call(*i)); |
| 982 } | 984 } |
| 983 } | 985 } |
| 984 | 986 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1251 | 1253 |
| 1252 // Build the test function. | 1254 // Build the test function. |
| 1253 TestSignatures sigs; | 1255 TestSignatures sigs; |
| 1254 TestingModule module; | 1256 TestingModule module; |
| 1255 WasmFunctionCompiler t(sigs.v_v(), &module); | 1257 WasmFunctionCompiler t(sigs.v_v(), &module); |
| 1256 BUILD(t, kExprNop); | 1258 BUILD(t, kExprNop); |
| 1257 uint32_t index = t.CompileAndAdd(); | 1259 uint32_t index = t.CompileAndAdd(); |
| 1258 | 1260 |
| 1259 const int32_t kExpected = -414444; | 1261 const int32_t kExpected = -414444; |
| 1260 // Build the calling function. | 1262 // Build the calling function. |
| 1261 WasmRunner<int32_t> r; | 1263 WasmRunner<int32_t> r(&module); |
| 1262 r.env()->module = &module; | |
| 1263 BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32(kExpected))); | 1264 BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32(kExpected))); |
| 1264 | 1265 |
| 1265 int32_t result = r.Call(); | 1266 int32_t result = r.Call(); |
| 1266 CHECK_EQ(kExpected, result); | 1267 CHECK_EQ(kExpected, result); |
| 1267 } | 1268 } |
| 1268 | 1269 |
| 1269 | 1270 |
| 1270 TEST(Run_Wasm_VoidReturn2) { | 1271 TEST(Run_Wasm_VoidReturn2) { |
| 1271 // We use a wrapper function because WasmRunner<void> does not exist. | 1272 // We use a wrapper function because WasmRunner<void> does not exist. |
| 1272 // Build the test function. | 1273 // Build the test function. |
| 1273 TestSignatures sigs; | 1274 TestSignatures sigs; |
| 1274 TestingModule module; | 1275 TestingModule module; |
| 1275 WasmFunctionCompiler t(sigs.v_v(), &module); | 1276 WasmFunctionCompiler t(sigs.v_v(), &module); |
| 1276 BUILD(t, WASM_RETURN0); | 1277 BUILD(t, WASM_RETURN0); |
| 1277 uint32_t index = t.CompileAndAdd(); | 1278 uint32_t index = t.CompileAndAdd(); |
| 1278 | 1279 |
| 1279 const int32_t kExpected = -414444; | 1280 const int32_t kExpected = -414444; |
| 1280 // Build the calling function. | 1281 // Build the calling function. |
| 1281 WasmRunner<int32_t> r; | 1282 WasmRunner<int32_t> r(&module); |
| 1282 r.env()->module = &module; | |
| 1283 BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32(kExpected))); | 1283 BUILD(r, WASM_BLOCK(2, WASM_CALL_FUNCTION0(index), WASM_I32(kExpected))); |
| 1284 | 1284 |
| 1285 int32_t result = r.Call(); | 1285 int32_t result = r.Call(); |
| 1286 CHECK_EQ(kExpected, result); | 1286 CHECK_EQ(kExpected, result); |
| 1287 } | 1287 } |
| 1288 | 1288 |
| 1289 | 1289 |
| 1290 TEST(Run_Wasm_Block_If_P) { | 1290 TEST(Run_Wasm_Block_If_P) { |
| 1291 WasmRunner<int32_t> r(MachineType::Int32()); | 1291 WasmRunner<int32_t> r(MachineType::Int32()); |
| 1292 // { if (p0) return 51; return 52; } | 1292 // { if (p0) return 51; return 52; } |
| (...skipping 737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2030 | 2030 |
| 2031 Zone zone; | 2031 Zone zone; |
| 2032 Isolate* isolate = CcTest::InitIsolateOnce(); | 2032 Isolate* isolate = CcTest::InitIsolateOnce(); |
| 2033 HandleScope scope(isolate); | 2033 HandleScope scope(isolate); |
| 2034 // Enable all optional operators. | 2034 // Enable all optional operators. |
| 2035 CommonOperatorBuilder common(&zone); | 2035 CommonOperatorBuilder common(&zone); |
| 2036 MachineOperatorBuilder machine(&zone, MachineType::PointerRepresentation(), | 2036 MachineOperatorBuilder machine(&zone, MachineType::PointerRepresentation(), |
| 2037 MachineOperatorBuilder::kAllOptionalOps); | 2037 MachineOperatorBuilder::kAllOptionalOps); |
| 2038 Graph graph(&zone); | 2038 Graph graph(&zone); |
| 2039 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); | 2039 JSGraph jsgraph(isolate, &graph, &common, nullptr, nullptr, &machine); |
| 2040 FunctionEnv env; | |
| 2041 FunctionSig* sig = WasmOpcodes::Signature(opcode); | 2040 FunctionSig* sig = WasmOpcodes::Signature(opcode); |
| 2042 init_env(&env, sig); | |
| 2043 | 2041 |
| 2044 if (sig->parameter_count() == 1) { | 2042 if (sig->parameter_count() == 1) { |
| 2045 byte code[] = {static_cast<byte>(opcode), kExprGetLocal, 0}; | 2043 byte code[] = {WASM_NO_LOCALS, static_cast<byte>(opcode), kExprGetLocal, 0}; |
| 2046 TestBuildingGraph(&zone, &jsgraph, &env, code, code + arraysize(code)); | 2044 TestBuildingGraph(&zone, &jsgraph, nullptr, sig, code, |
| 2045 code + arraysize(code)); |
| 2047 } else { | 2046 } else { |
| 2048 CHECK_EQ(2, sig->parameter_count()); | 2047 CHECK_EQ(2, sig->parameter_count()); |
| 2049 byte code[] = {static_cast<byte>(opcode), kExprGetLocal, 0, kExprGetLocal, | 2048 byte code[] = {WASM_NO_LOCALS, static_cast<byte>(opcode), |
| 2050 1}; | 2049 kExprGetLocal, 0, |
| 2051 TestBuildingGraph(&zone, &jsgraph, &env, code, code + arraysize(code)); | 2050 kExprGetLocal, 1}; |
| 2051 TestBuildingGraph(&zone, &jsgraph, nullptr, sig, code, |
| 2052 code + arraysize(code)); |
| 2052 } | 2053 } |
| 2053 } | 2054 } |
| 2054 | 2055 |
| 2055 | 2056 |
| 2056 TEST(Build_Wasm_SimpleExprs) { | 2057 TEST(Build_Wasm_SimpleExprs) { |
| 2057 // Test that the decoder can build a graph for all supported simple expressions. | 2058 // Test that the decoder can build a graph for all supported simple expressions. |
| 2058 #define GRAPH_BUILD_TEST(name, opcode, sig) \ | 2059 #define GRAPH_BUILD_TEST(name, opcode, sig) \ |
| 2059 TestBuildGraphForSimpleExpression(kExpr##name); | 2060 TestBuildGraphForSimpleExpression(kExpr##name); |
| 2060 | 2061 |
| 2061 FOREACH_SIMPLE_OPCODE(GRAPH_BUILD_TEST); | 2062 FOREACH_SIMPLE_OPCODE(GRAPH_BUILD_TEST); |
| (...skipping 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3382 | 3383 |
| 3383 #if WASM_64 | 3384 #if WASM_64 |
| 3384 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); } | 3385 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); } |
| 3385 #endif | 3386 #endif |
| 3386 | 3387 |
| 3387 | 3388 |
| 3388 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } | 3389 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); } |
| 3389 | 3390 |
| 3390 | 3391 |
| 3391 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } | 3392 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); } |
| OLD | NEW |