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-macro-gen.h" | 9 #include "src/wasm/wasm-macro-gen.h" |
10 #include "src/wasm/wasm-module.h" | 10 #include "src/wasm/wasm-module.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 WasmFunctionBuilder* f = builder->FunctionAt(f_index); | 69 WasmFunctionBuilder* f = builder->FunctionAt(f_index); |
70 f->ReturnType(kAstI32); | 70 f->ReturnType(kAstI32); |
71 f->Exported(1); | 71 f->Exported(1); |
72 byte code[] = {WASM_I8(kReturnValue)}; | 72 byte code[] = {WASM_I8(kReturnValue)}; |
73 f->EmitCode(code, sizeof(code)); | 73 f->EmitCode(code, sizeof(code)); |
74 WasmModuleWriter* writer = builder->Build(&zone); | 74 WasmModuleWriter* writer = builder->Build(&zone); |
75 TestModule(writer->WriteTo(&zone), kReturnValue); | 75 TestModule(writer->WriteTo(&zone), kReturnValue); |
76 } | 76 } |
77 | 77 |
78 | 78 |
| 79 // TODO(tizer): Figure out why this crashes with PPC. |
| 80 #if !defined(V8_TARGET_ARCH_PPC) && !defined(V8_TARGET_ARCH_PPC64) |
| 81 |
79 TEST(Run_WasmModule_CallAdd) { | 82 TEST(Run_WasmModule_CallAdd) { |
80 Zone zone; | 83 Zone zone; |
81 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 84 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
82 uint16_t f1_index = builder->AddFunction(); | 85 uint16_t f1_index = builder->AddFunction(); |
83 WasmFunctionBuilder* f = builder->FunctionAt(f1_index); | 86 WasmFunctionBuilder* f = builder->FunctionAt(f1_index); |
84 f->ReturnType(kAstI32); | 87 f->ReturnType(kAstI32); |
85 uint16_t param1 = f->AddParam(kAstI32); | 88 uint16_t param1 = f->AddParam(kAstI32); |
86 uint16_t param2 = f->AddParam(kAstI32); | 89 uint16_t param2 = f->AddParam(kAstI32); |
87 byte code1[] = {WASM_I32_ADD(WASM_GET_LOCAL(param1), WASM_GET_LOCAL(param2))}; | 90 byte code1[] = {WASM_I32_ADD(WASM_GET_LOCAL(param1), WASM_GET_LOCAL(param2))}; |
88 uint32_t local_indices1[] = {2, 4}; | 91 uint32_t local_indices1[] = {2, 4}; |
89 f->EmitCode(code1, sizeof(code1), local_indices1, sizeof(local_indices1) / 4); | 92 f->EmitCode(code1, sizeof(code1), local_indices1, sizeof(local_indices1) / 4); |
90 uint16_t f2_index = builder->AddFunction(); | 93 uint16_t f2_index = builder->AddFunction(); |
91 f = builder->FunctionAt(f2_index); | 94 f = builder->FunctionAt(f2_index); |
92 f->ReturnType(kAstI32); | 95 f->ReturnType(kAstI32); |
93 f->Exported(1); | 96 f->Exported(1); |
94 byte code2[] = {WASM_CALL_FUNCTION(f1_index, WASM_I8(77), WASM_I8(22))}; | 97 byte code2[] = {WASM_CALL_FUNCTION(f1_index, WASM_I8(77), WASM_I8(22))}; |
95 f->EmitCode(code2, sizeof(code2)); | 98 f->EmitCode(code2, sizeof(code2)); |
96 WasmModuleWriter* writer = builder->Build(&zone); | 99 WasmModuleWriter* writer = builder->Build(&zone); |
97 TestModule(writer->WriteTo(&zone), 99); | 100 TestModule(writer->WriteTo(&zone), 99); |
98 } | 101 } |
99 | 102 |
| 103 #endif |
| 104 |
100 | 105 |
101 TEST(Run_WasmModule_ReadLoadedDataSegment) { | 106 TEST(Run_WasmModule_ReadLoadedDataSegment) { |
102 static const byte kDataSegmentDest0 = 12; | 107 static const byte kDataSegmentDest0 = 12; |
103 Zone zone; | 108 Zone zone; |
104 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); | 109 WasmModuleBuilder* builder = new (&zone) WasmModuleBuilder(&zone); |
105 uint16_t f_index = builder->AddFunction(); | 110 uint16_t f_index = builder->AddFunction(); |
106 WasmFunctionBuilder* f = builder->FunctionAt(f_index); | 111 WasmFunctionBuilder* f = builder->FunctionAt(f_index); |
107 f->ReturnType(kAstI32); | 112 f->ReturnType(kAstI32); |
108 f->Exported(1); | 113 f->Exported(1); |
109 byte code[] = { | 114 byte code[] = { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 f->ReturnType(kAstI32); | 204 f->ReturnType(kAstI32); |
200 f->Exported(1); | 205 f->Exported(1); |
201 byte code2[] = {WASM_STORE_GLOBAL(global1, WASM_I32(56)), | 206 byte code2[] = {WASM_STORE_GLOBAL(global1, WASM_I32(56)), |
202 WASM_STORE_GLOBAL(global2, WASM_I32(41)), | 207 WASM_STORE_GLOBAL(global2, WASM_I32(41)), |
203 WASM_RETURN(WASM_CALL_FUNCTION0(f1_index))}; | 208 WASM_RETURN(WASM_CALL_FUNCTION0(f1_index))}; |
204 f->EmitCode(code2, sizeof(code2)); | 209 f->EmitCode(code2, sizeof(code2)); |
205 WasmModuleWriter* writer = builder->Build(&zone); | 210 WasmModuleWriter* writer = builder->Build(&zone); |
206 TestModule(writer->WriteTo(&zone), 97); | 211 TestModule(writer->WriteTo(&zone), 97); |
207 } | 212 } |
208 #endif | 213 #endif |
OLD | NEW |