Chromium Code Reviews| 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 "src/signature.h" | 5 #include "src/signature.h" |
| 6 | 6 |
| 7 #include "src/bit-vector.h" | 7 #include "src/bit-vector.h" |
| 8 #include "src/flags.h" | 8 #include "src/flags.h" |
| 9 #include "src/handles.h" | 9 #include "src/handles.h" |
| 10 #include "src/zone/zone-containers.h" | 10 #include "src/zone/zone-containers.h" |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 return false; | 234 return false; |
| 235 } | 235 } |
| 236 | 236 |
| 237 bool Validate(const byte* pc, BranchTableOperand& operand, | 237 bool Validate(const byte* pc, BranchTableOperand& operand, |
| 238 size_t block_depth) { | 238 size_t block_depth) { |
| 239 // TODO(titzer): add extra redundant validation for br_table here? | 239 // TODO(titzer): add extra redundant validation for br_table here? |
| 240 return true; | 240 return true; |
| 241 } | 241 } |
| 242 | 242 |
| 243 unsigned OpcodeLength(const byte* pc) { | 243 unsigned OpcodeLength(const byte* pc) { |
| 244 switch (static_cast<WasmOpcode>(*pc)) { | 244 WasmOpcode opcode = ExtractWasmOpcode(pc); |
|
titzer
2016/10/12 19:06:55
Could you do the trick in the main decoder loop of
aseemgarg
2016/10/17 19:01:44
Done. Actually seems like we don't need this at al
titzer
2016/10/19 18:31:49
No, you do, since we still want to be able to iter
aseemgarg
2016/10/19 23:37:33
Done.
| |
| 245 switch (opcode) { | |
| 245 #define DECLARE_OPCODE_CASE(name, opcode, sig) case kExpr##name: | 246 #define DECLARE_OPCODE_CASE(name, opcode, sig) case kExpr##name: |
| 246 FOREACH_LOAD_MEM_OPCODE(DECLARE_OPCODE_CASE) | 247 FOREACH_LOAD_MEM_OPCODE(DECLARE_OPCODE_CASE) |
| 247 FOREACH_STORE_MEM_OPCODE(DECLARE_OPCODE_CASE) | 248 FOREACH_STORE_MEM_OPCODE(DECLARE_OPCODE_CASE) |
| 248 #undef DECLARE_OPCODE_CASE | 249 #undef DECLARE_OPCODE_CASE |
| 249 { | 250 { |
| 250 MemoryAccessOperand operand(this, pc, UINT32_MAX); | 251 MemoryAccessOperand operand(this, pc, UINT32_MAX); |
| 251 return 1 + operand.length; | 252 return 1 + operand.length; |
| 252 } | 253 } |
| 253 case kExprBr: | 254 case kExprBr: |
| 254 case kExprBrIf: { | 255 case kExprBrIf: { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 case kExprI8Const: | 302 case kExprI8Const: |
| 302 return 2; | 303 return 2; |
| 303 case kExprF32Const: | 304 case kExprF32Const: |
| 304 return 5; | 305 return 5; |
| 305 case kExprF64Const: | 306 case kExprF64Const: |
| 306 return 9; | 307 return 9; |
| 307 default: | 308 default: |
| 308 return 1; | 309 return 1; |
| 309 } | 310 } |
| 310 } | 311 } |
| 312 | |
| 313 private: | |
| 314 WasmOpcode ExtractWasmOpcode(const byte* pc) { | |
| 315 WasmOpcode opcode = static_cast<WasmOpcode>(*pc); | |
| 316 if (opcode == kSimdPrefix) { | |
| 317 opcode = static_cast<WasmOpcode>((opcode << 8) | *(pc + 1)); | |
| 318 } | |
| 319 return opcode; | |
| 320 } | |
| 311 }; | 321 }; |
| 312 | 322 |
| 313 static const int32_t kNullCatch = -1; | 323 static const int32_t kNullCatch = -1; |
| 314 | 324 |
| 315 // The full WASM decoder for bytecode. Both verifies bytecode and generates | 325 // The full WASM decoder for bytecode. Both verifies bytecode and generates |
| 316 // a TurboFan IR graph. | 326 // a TurboFan IR graph. |
| 317 class WasmFullDecoder : public WasmDecoder { | 327 class WasmFullDecoder : public WasmDecoder { |
| 318 public: | 328 public: |
| 319 WasmFullDecoder(Zone* zone, TFBuilder* builder, const FunctionBody& body) | 329 WasmFullDecoder(Zone* zone, TFBuilder* builder, const FunctionBody& body) |
| 320 : WasmDecoder(body.module, body.sig, body.start, body.end), | 330 : WasmDecoder(body.module, body.sig, body.start, body.end), |
| (...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1241 int DecodeStoreMem(LocalType type, MachineType mem_type) { | 1251 int DecodeStoreMem(LocalType type, MachineType mem_type) { |
| 1242 MemoryAccessOperand operand(this, pc_, | 1252 MemoryAccessOperand operand(this, pc_, |
| 1243 ElementSizeLog2Of(mem_type.representation())); | 1253 ElementSizeLog2Of(mem_type.representation())); |
| 1244 Value val = Pop(1, type); | 1254 Value val = Pop(1, type); |
| 1245 Value index = Pop(0, kAstI32); | 1255 Value index = Pop(0, kAstI32); |
| 1246 BUILD(StoreMem, mem_type, index.node, operand.offset, operand.alignment, | 1256 BUILD(StoreMem, mem_type, index.node, operand.offset, operand.alignment, |
| 1247 val.node, position()); | 1257 val.node, position()); |
| 1248 return 1 + operand.length; | 1258 return 1 + operand.length; |
| 1249 } | 1259 } |
| 1250 | 1260 |
| 1261 unsigned ExtractLane(WasmOpcode opcode, LocalType type) { | |
|
titzer
2016/10/12 19:06:55
Please make a LaneOperand class similar to the oth
aseemgarg
2016/10/17 19:01:44
Done.
| |
| 1262 unsigned len = 0; | |
| 1263 uint8_t lane = this->checked_read_u8(pc_, 2, "lane number"); | |
| 1264 if (lane < 0 || lane > 3) { | |
| 1265 error(pc_, pc_ + 2, "invalid extract lane value"); | |
| 1266 } | |
| 1267 TFNode* input = Pop(0, LocalType::kSimd128).node; | |
| 1268 TFNode* node = BUILD(SimdExtractLane, opcode, lane, input); | |
| 1269 Push(type, node); | |
| 1270 len++; | |
| 1271 return len; | |
| 1272 } | |
| 1273 | |
| 1251 unsigned DecodeSimdOpcode(WasmOpcode opcode) { | 1274 unsigned DecodeSimdOpcode(WasmOpcode opcode) { |
| 1252 unsigned len = 0; | 1275 unsigned len = 0; |
| 1253 switch (opcode) { | 1276 switch (opcode) { |
| 1254 case kExprI32x4ExtractLane: { | 1277 case kExprI32x4ExtractLane: { |
| 1255 uint8_t lane = this->checked_read_u8(pc_, 2, "lane number"); | 1278 len = ExtractLane(opcode, LocalType::kWord32); |
| 1256 if (lane < 0 || lane > 3) { | 1279 break; |
| 1257 error(pc_, pc_ + 2, "invalid extract lane value"); | 1280 } |
| 1258 } | 1281 case kExprF32x4ExtractLane: { |
| 1259 TFNode* input = Pop(0, LocalType::kSimd128).node; | 1282 len = ExtractLane(opcode, LocalType::kFloat32); |
| 1260 TFNode* node = BUILD(SimdExtractLane, opcode, lane, input); | |
| 1261 Push(LocalType::kWord32, node); | |
| 1262 len++; | |
| 1263 break; | 1283 break; |
| 1264 } | 1284 } |
| 1265 default: { | 1285 default: { |
| 1266 FunctionSig* sig = WasmOpcodes::Signature(opcode); | 1286 FunctionSig* sig = WasmOpcodes::Signature(opcode); |
| 1267 if (sig != nullptr) { | 1287 if (sig != nullptr) { |
| 1268 compiler::NodeVector inputs(sig->parameter_count(), zone_); | 1288 compiler::NodeVector inputs(sig->parameter_count(), zone_); |
| 1269 for (size_t i = sig->parameter_count(); i > 0; i--) { | 1289 for (size_t i = sig->parameter_count(); i > 0; i--) { |
| 1270 Value val = Pop(static_cast<int>(i - 1), sig->GetParam(i - 1)); | 1290 Value val = Pop(static_cast<int>(i - 1), sig->GetParam(i - 1)); |
| 1271 inputs[i - 1] = val.node; | 1291 inputs[i - 1] = val.node; |
| 1272 } | 1292 } |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1936 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, | 1956 BitVector* AnalyzeLoopAssignmentForTesting(Zone* zone, size_t num_locals, |
| 1937 const byte* start, const byte* end) { | 1957 const byte* start, const byte* end) { |
| 1938 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; | 1958 FunctionBody body = {nullptr, nullptr, nullptr, start, end}; |
| 1939 WasmFullDecoder decoder(zone, nullptr, body); | 1959 WasmFullDecoder decoder(zone, nullptr, body); |
| 1940 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); | 1960 return decoder.AnalyzeLoopAssignmentForTesting(start, num_locals); |
| 1941 } | 1961 } |
| 1942 | 1962 |
| 1943 } // namespace wasm | 1963 } // namespace wasm |
| 1944 } // namespace internal | 1964 } // namespace internal |
| 1945 } // namespace v8 | 1965 } // namespace v8 |
| OLD | NEW |