| 28 | class Features; |
| 29 | |
| 30 | struct Opcode { |
| 31 | // Opcode enumerations. |
| 32 | // |
| 33 | // NOTE: this enum does not match the binary encoding. |
| 34 | // |
| 35 | enum Enum : uint32_t { |
| 36 | #define WABT_OPCODE(rtype, rtype2, type1, type2, type3, mem_size, prefix, \ |
| 37 | code, Name, text, decomp) \ |
| 38 | Name, |
| 39 | #include "wabt/opcode.def" |
| 40 | #undef WABT_OPCODE |
| 41 | Invalid, |
| 42 | }; |
| 43 | |
| 44 | // Static opcode objects. |
| 45 | #define WABT_OPCODE(rtype, rtype2, type1, type2, type3, mem_size, prefix, \ |
| 46 | code, Name, text, decomp) \ |
| 47 | static Opcode Name##_Opcode; |
| 48 | #include "wabt/opcode.def" |
| 49 | #undef WABT_OPCODE |
| 50 | |
| 51 | Opcode() = default; // Provided so Opcode can be member of a union. |
| 52 | Opcode(Enum e) : enum_(e) {} |
| 53 | operator Enum() const { return enum_; } |
| 54 | |
| 55 | static Opcode FromCode(uint32_t); |
| 56 | static Opcode FromCode(uint8_t prefix, uint32_t code); |
| 57 | bool HasPrefix() const { return GetInfo().prefix != 0; } |
| 58 | uint8_t GetPrefix() const { return GetInfo().prefix; } |
| 59 | uint32_t GetCode() const { return GetInfo().code; } |
| 60 | size_t GetLength() const { return GetBytes().size(); } |
| 61 | const char* GetName() const { return GetInfo().name; } |
| 62 | const char* GetDecomp() const { |
| 63 | return *GetInfo().decomp ? GetInfo().decomp : GetInfo().name; |
| 64 | } |
| 65 | Type GetResultType() const { return GetInfo().result_type; } |
| 66 | Type GetResultType2() const { return GetInfo().result_type2; } |
| 67 | Type GetParamType1() const { return GetInfo().param_types[0]; } |
| 68 | Type GetParamType2() const { return GetInfo().param_types[1]; } |
| 69 | Type GetParamType3() const { return GetInfo().param_types[2]; } |
| 70 | Type GetParamType(int n) const { return GetInfo().param_types[n - 1]; } |
| 71 | Address GetMemorySize() const { return GetInfo().memory_size; } |
| 72 | |
| 73 | // Get the byte sequence for this opcode, including prefix. |
| 74 | std::vector<uint8_t> GetBytes() const; |
| 75 | |
| 76 | // Get the lane count of an extract/replace simd op. |
| 77 | uint32_t GetSimdLaneCount() const; |
| 78 | |
| 79 | // Return 1 if |alignment| matches the alignment of |opcode|, or if |
| 80 | // |alignment| is WABT_USE_NATURAL_ALIGNMENT. |
| 81 | bool IsNaturallyAligned(Address alignment) const; |
| 82 | |
| 83 | // If |alignment| is WABT_USE_NATURAL_ALIGNMENT, return the alignment of |
| 84 | // |opcode|, else return |alignment|. |
| 85 | Address GetAlignment(Address alignment) const; |
| 86 | |
| 87 | static bool IsPrefixByte(uint8_t byte) { |