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 #ifndef V8_WASM_OPCODES_H_ | 5 #ifndef V8_WASM_OPCODES_H_ |
| 6 #define V8_WASM_OPCODES_H_ | 6 #define V8_WASM_OPCODES_H_ |
| 7 | 7 |
| 8 #include "src/machine-type.h" | 8 #include "src/machine-type.h" |
| 9 #include "src/messages.h" | |
|
Michael Starzinger
2016/04/11 14:05:24
nit: Not sure about the header inclusion policy in
| |
| 9 #include "src/signature.h" | 10 #include "src/signature.h" |
| 10 | 11 |
| 11 namespace v8 { | 12 namespace v8 { |
| 12 namespace internal { | 13 namespace internal { |
| 13 namespace wasm { | 14 namespace wasm { |
| 14 | 15 |
| 15 // Binary encoding of local types. | 16 // Binary encoding of local types. |
| 16 enum LocalTypeCode { | 17 enum LocalTypeCode { |
| 17 kLocalVoid = 0, | 18 kLocalVoid = 0, |
| 18 kLocalI32 = 1, | 19 kLocalI32 = 1, |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 V(l_il, kAstI64, kAstI32, kAstI64) | 324 V(l_il, kAstI64, kAstI32, kAstI64) |
| 324 | 325 |
| 325 enum WasmOpcode { | 326 enum WasmOpcode { |
| 326 // Declare expression opcodes. | 327 // Declare expression opcodes. |
| 327 #define DECLARE_NAMED_ENUM(name, opcode, sig) kExpr##name = opcode, | 328 #define DECLARE_NAMED_ENUM(name, opcode, sig) kExpr##name = opcode, |
| 328 FOREACH_OPCODE(DECLARE_NAMED_ENUM) | 329 FOREACH_OPCODE(DECLARE_NAMED_ENUM) |
| 329 #undef DECLARE_NAMED_ENUM | 330 #undef DECLARE_NAMED_ENUM |
| 330 }; | 331 }; |
| 331 | 332 |
| 332 // The reason for a trap. | 333 // The reason for a trap. |
| 334 #define FOREACH_TRAPREASON(V) \ | |
| 335 V(TrapUnreachable) \ | |
| 336 V(TrapMemOutOfBounds) \ | |
| 337 V(TrapDivByZero) \ | |
| 338 V(TrapDivUnrepresentable) \ | |
| 339 V(TrapRemByZero) \ | |
| 340 V(TrapFloatUnrepresentable) \ | |
| 341 V(TrapFuncInvalid) \ | |
| 342 V(TrapFuncSigMismatch) | |
| 343 | |
| 333 enum TrapReason { | 344 enum TrapReason { |
| 334 kTrapUnreachable, | 345 #define DECLARE_ENUM(name) k##name, |
| 335 kTrapMemOutOfBounds, | 346 FOREACH_TRAPREASON(DECLARE_ENUM) |
| 336 kTrapDivByZero, | |
| 337 kTrapDivUnrepresentable, | |
| 338 kTrapRemByZero, | |
| 339 kTrapFloatUnrepresentable, | |
| 340 kTrapFuncInvalid, | |
| 341 kTrapFuncSigMismatch, | |
| 342 kTrapCount | 347 kTrapCount |
| 348 #undef DECLARE_ENUM | |
| 343 }; | 349 }; |
| 344 | 350 |
| 345 // A collection of opcode-related static methods. | 351 // A collection of opcode-related static methods. |
| 346 class WasmOpcodes { | 352 class WasmOpcodes { |
| 347 public: | 353 public: |
| 348 static bool IsSupported(WasmOpcode opcode); | 354 static bool IsSupported(WasmOpcode opcode); |
| 349 static const char* OpcodeName(WasmOpcode opcode); | 355 static const char* OpcodeName(WasmOpcode opcode); |
| 350 static FunctionSig* Signature(WasmOpcode opcode); | 356 static FunctionSig* Signature(WasmOpcode opcode); |
| 351 | 357 |
| 352 static byte MemSize(MachineType type) { | 358 static byte MemSize(MachineType type) { |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 502 return "f64"; | 508 return "f64"; |
| 503 case kAstStmt: | 509 case kAstStmt: |
| 504 return "<stmt>"; | 510 return "<stmt>"; |
| 505 case kAstEnd: | 511 case kAstEnd: |
| 506 return "<end>"; | 512 return "<end>"; |
| 507 default: | 513 default: |
| 508 return "<unknown>"; | 514 return "<unknown>"; |
| 509 } | 515 } |
| 510 } | 516 } |
| 511 | 517 |
| 518 static int TrapReasonToMessageId(TrapReason reason) { | |
| 519 switch (reason) { | |
| 520 #define TRAPREASON_TO_MESSAGE(name) \ | |
| 521 case k##name: \ | |
| 522 return MessageTemplate::kWasm##name; | |
| 523 FOREACH_TRAPREASON(TRAPREASON_TO_MESSAGE) | |
| 524 #undef TRAPREASON_TO_MESSAGE | |
| 525 default: | |
| 526 return MessageTemplate::kNone; | |
| 527 } | |
| 528 } | |
| 529 | |
| 512 static const char* TrapReasonName(TrapReason reason) { | 530 static const char* TrapReasonName(TrapReason reason) { |
|
Michael Starzinger
2016/04/11 14:05:24
nit/suggestion: Calling this "TrapReasonMessage" w
| |
| 513 switch (reason) { | 531 return MessageTemplate::TemplateString(TrapReasonToMessageId(reason)); |
| 514 case kTrapUnreachable: | |
| 515 return "unreachable"; | |
| 516 case kTrapMemOutOfBounds: | |
| 517 return "memory access out of bounds"; | |
| 518 case kTrapDivByZero: | |
| 519 return "divide by zero"; | |
| 520 case kTrapDivUnrepresentable: | |
| 521 return "divide result unrepresentable"; | |
| 522 case kTrapRemByZero: | |
| 523 return "remainder by zero"; | |
| 524 case kTrapFloatUnrepresentable: | |
| 525 return "integer result unrepresentable"; | |
| 526 case kTrapFuncInvalid: | |
| 527 return "invalid function"; | |
| 528 case kTrapFuncSigMismatch: | |
| 529 return "function signature mismatch"; | |
| 530 default: | |
| 531 return "<?>"; | |
| 532 } | |
| 533 } | 532 } |
| 534 }; | 533 }; |
| 535 } // namespace wasm | 534 } // namespace wasm |
| 536 } // namespace internal | 535 } // namespace internal |
| 537 } // namespace v8 | 536 } // namespace v8 |
| 538 | 537 |
| 539 #endif // V8_WASM_OPCODES_H_ | 538 #endif // V8_WASM_OPCODES_H_ |
| OLD | NEW |