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

Side by Side Diff: test/cctest/wasm/test-run-wasm.cc

Issue 1616973004: [wasm] Add utilities to print out WASM ast directly from the bytes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix arm64, use AddIndirectFunctionTable() more. Created 4 years, 11 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/wasm/ast-decoder.cc ('k') | test/cctest/wasm/test-signatures.h » ('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 <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 2819 matching lines...) Expand 10 before | Expand all | Expand 10 after
2830 } 2830 }
2831 } 2831 }
2832 } 2832 }
2833 } 2833 }
2834 2834
2835 2835
2836 #endif 2836 #endif
2837 2837
2838 2838
2839 TEST(Run_Wasm_SimpleCallIndirect) { 2839 TEST(Run_Wasm_SimpleCallIndirect) {
2840 Isolate* isolate = CcTest::InitIsolateOnce();
2841
2842 WasmRunner<int32_t> r(MachineType::Int32()); 2840 WasmRunner<int32_t> r(MachineType::Int32());
2843 TestSignatures sigs; 2841 TestSignatures sigs;
2844 TestingModule module; 2842 TestingModule module;
2845 r.env()->module = &module; 2843 r.env()->module = &module;
2846 WasmFunctionCompiler t1(sigs.i_ii()); 2844 WasmFunctionCompiler t1(sigs.i_ii());
2847 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 2845 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
2848 t1.CompileAndAdd(&module); 2846 t1.CompileAndAdd(&module, /*sig_index*/ 1);
2849 2847
2850 WasmFunctionCompiler t2(sigs.i_ii()); 2848 WasmFunctionCompiler t2(sigs.i_ii());
2851 BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 2849 BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
2852 t2.CompileAndAdd(&module); 2850 t2.CompileAndAdd(&module, /*sig_index*/ 1);
2853 2851
2854 // Signature table. 2852 // Signature table.
2855 module.AddSignature(sigs.f_ff()); 2853 module.AddSignature(sigs.f_ff());
2856 module.AddSignature(sigs.i_ii()); 2854 module.AddSignature(sigs.i_ii());
2857 module.AddSignature(sigs.d_dd()); 2855 module.AddSignature(sigs.d_dd());
2858 2856
2859 // Function table. 2857 // Function table.
2860 int table_size = 2; 2858 int table[] = {0, 1};
2861 module.module->function_table = new std::vector<uint16_t>; 2859 module.AddIndirectFunctionTable(table, 2);
2862 module.module->function_table->push_back(0); 2860 module.PopulateIndirectFunctionTable();
2863 module.module->function_table->push_back(1);
2864
2865 // Function table.
2866 Handle<FixedArray> fixed = isolate->factory()->NewFixedArray(2 * table_size);
2867 fixed->set(0, Smi::FromInt(1));
2868 fixed->set(1, Smi::FromInt(1));
2869 fixed->set(2, *module.function_code->at(0));
2870 fixed->set(3, *module.function_code->at(1));
2871 module.function_table = fixed;
2872 2861
2873 // Builder the caller function. 2862 // Builder the caller function.
2874 BUILD(r, WASM_CALL_INDIRECT(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22))); 2863 BUILD(r, WASM_CALL_INDIRECT(1, WASM_GET_LOCAL(0), WASM_I8(66), WASM_I8(22)));
2875 2864
2876 CHECK_EQ(88, r.Call(0)); 2865 CHECK_EQ(88, r.Call(0));
2877 CHECK_EQ(44, r.Call(1)); 2866 CHECK_EQ(44, r.Call(1));
2878 CHECK_TRAP(r.Call(2)); 2867 CHECK_TRAP(r.Call(2));
2879 } 2868 }
2880 2869
2881 2870
2882 TEST(Run_Wasm_MultipleCallIndirect) { 2871 TEST(Run_Wasm_MultipleCallIndirect) {
2883 Isolate* isolate = CcTest::InitIsolateOnce();
2884
2885 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32(), 2872 WasmRunner<int32_t> r(MachineType::Int32(), MachineType::Int32(),
2886 MachineType::Int32()); 2873 MachineType::Int32());
2887 TestSignatures sigs; 2874 TestSignatures sigs;
2888 TestingModule module; 2875 TestingModule module;
2889 r.env()->module = &module; 2876 r.env()->module = &module;
2890 WasmFunctionCompiler t1(sigs.i_ii()); 2877 WasmFunctionCompiler t1(sigs.i_ii());
2891 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 2878 BUILD(t1, WASM_I32_ADD(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
2892 t1.CompileAndAdd(&module); 2879 t1.CompileAndAdd(&module, /*sig_index*/ 1);
2893 2880
2894 WasmFunctionCompiler t2(sigs.i_ii()); 2881 WasmFunctionCompiler t2(sigs.i_ii());
2895 BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 2882 BUILD(t2, WASM_I32_SUB(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
2896 t2.CompileAndAdd(&module); 2883 t2.CompileAndAdd(&module, /*sig_index*/ 1);
2897 2884
2898 // Signature table. 2885 // Signature table.
2899 module.AddSignature(sigs.f_ff()); 2886 module.AddSignature(sigs.f_ff());
2900 module.AddSignature(sigs.i_ii()); 2887 module.AddSignature(sigs.i_ii());
2901 module.AddSignature(sigs.d_dd()); 2888 module.AddSignature(sigs.d_dd());
2902 2889
2903 // Function table. 2890 // Function table.
2904 int table_size = 2; 2891 int table[] = {0, 1};
2905 module.module->function_table = new std::vector<uint16_t>; 2892 module.AddIndirectFunctionTable(table, 2);
2906 module.module->function_table->push_back(0); 2893 module.PopulateIndirectFunctionTable();
2907 module.module->function_table->push_back(1);
2908
2909 // Function table.
2910 Handle<FixedArray> fixed = isolate->factory()->NewFixedArray(2 * table_size);
2911 fixed->set(0, Smi::FromInt(1));
2912 fixed->set(1, Smi::FromInt(1));
2913 fixed->set(2, *module.function_code->at(0));
2914 fixed->set(3, *module.function_code->at(1));
2915 module.function_table = fixed;
2916 2894
2917 // Builder the caller function. 2895 // Builder the caller function.
2918 BUILD(r, 2896 BUILD(r,
2919 WASM_I32_ADD(WASM_CALL_INDIRECT(1, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1), 2897 WASM_I32_ADD(WASM_CALL_INDIRECT(1, WASM_GET_LOCAL(0), WASM_GET_LOCAL(1),
2920 WASM_GET_LOCAL(2)), 2898 WASM_GET_LOCAL(2)),
2921 WASM_CALL_INDIRECT(1, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2), 2899 WASM_CALL_INDIRECT(1, WASM_GET_LOCAL(1), WASM_GET_LOCAL(2),
2922 WASM_GET_LOCAL(0)))); 2900 WASM_GET_LOCAL(0))));
2923 2901
2924 CHECK_EQ(5, r.Call(0, 1, 2)); 2902 CHECK_EQ(5, r.Call(0, 1, 2));
2925 CHECK_EQ(19, r.Call(0, 1, 9)); 2903 CHECK_EQ(19, r.Call(0, 1, 9));
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
3268 3246
3269 TEST(Run_Wasm_F32CopySign) { 3247 TEST(Run_Wasm_F32CopySign) {
3270 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32()); 3248 WasmRunner<float> r(MachineType::Float32(), MachineType::Float32());
3271 BUILD(r, WASM_F32_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1))); 3249 BUILD(r, WASM_F32_COPYSIGN(WASM_GET_LOCAL(0), WASM_GET_LOCAL(1)));
3272 3250
3273 FOR_FLOAT32_INPUTS(i) { 3251 FOR_FLOAT32_INPUTS(i) {
3274 FOR_FLOAT32_INPUTS(j) { CheckFloatEq(copysign(*i, *j), r.Call(*i, *j)); } 3252 FOR_FLOAT32_INPUTS(j) { CheckFloatEq(copysign(*i, *j), r.Call(*i, *j)); }
3275 } 3253 }
3276 } 3254 }
3277 3255
3256
3278 #endif 3257 #endif
3258
3259
3260 void CompileCallIndirectMany(LocalType param) {
3261 // Make sure we don't run out of registers when compiling indirect calls
3262 // with many many parameters.
3263 TestSignatures sigs;
3264 for (byte num_params = 0; num_params < 40; num_params++) {
3265 Zone zone;
3266 HandleScope scope(CcTest::InitIsolateOnce());
3267 TestingModule module;
3268 FunctionSig* sig = sigs.many(&zone, kAstStmt, param, num_params);
3269
3270 module.AddSignature(sig);
3271 module.AddSignature(sig);
3272 module.AddIndirectFunctionTable(nullptr, 0);
3273
3274 WasmFunctionCompiler t(sig);
3275 t.env.module = &module;
3276
3277 std::vector<byte> code;
3278 ADD_CODE(code, kExprCallIndirect, 1);
3279 ADD_CODE(code, kExprI8Const, 0);
3280 for (byte p = 0; p < num_params; p++) {
3281 ADD_CODE(code, kExprGetLocal, p);
3282 }
3283
3284 t.Build(&code[0], &code[0] + code.size());
3285 t.Compile(&module);
3286 }
3287 }
3288
3289
3290 TEST(Compile_Wasm_CallIndirect_Many_i32) { CompileCallIndirectMany(kAstI32); }
3291
3292
3293 #if WASM_64
3294 TEST(Compile_Wasm_CallIndirect_Many_i64) { CompileCallIndirectMany(kAstI64); }
3295 #endif
3296
3297
3298 TEST(Compile_Wasm_CallIndirect_Many_f32) { CompileCallIndirectMany(kAstF32); }
3299
3300
3301 TEST(Compile_Wasm_CallIndirect_Many_f64) { CompileCallIndirectMany(kAstF64); }
OLDNEW
« no previous file with comments | « src/wasm/ast-decoder.cc ('k') | test/cctest/wasm/test-signatures.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698