| 21 | } |
| 22 | |
| 23 | TEST(ExpressionTest, SerializeExpression) { |
| 24 | std::vector<uint8_t> Expected; |
| 25 | std::vector<uint8_t> Output; |
| 26 | WasmEdge::AST::Expression Expr; |
| 27 | |
| 28 | WasmEdge::Configure ConfWASM1; |
| 29 | ConfWASM1.setWASMStandard(WasmEdge::Standard::WASM_1); |
| 30 | WasmEdge::Loader::Serializer SerWASM1(ConfWASM1); |
| 31 | |
| 32 | // 1. Test serialize expression. |
| 33 | // |
| 34 | // 1. Serialize expression with only end operation. |
| 35 | // 2. Serialize expression with instructions. |
| 36 | // 3. Serialize expression with instructions not in proposals. |
| 37 | |
| 38 | WasmEdge::AST::Instruction End(WasmEdge::OpCode::End); |
| 39 | WasmEdge::AST::Instruction I32Eqz(WasmEdge::OpCode::I32__eqz); |
| 40 | WasmEdge::AST::Instruction I32Eq(WasmEdge::OpCode::I32__eq); |
| 41 | WasmEdge::AST::Instruction I32Ne(WasmEdge::OpCode::I32__ne); |
| 42 | WasmEdge::AST::Instruction TableGet(WasmEdge::OpCode::Table__get); |
| 43 | |
| 44 | Expr.getInstrs() = {End}; |
| 45 | Output = {}; |
| 46 | EXPECT_TRUE(Ser.serializeSection(createCodeSec(Expr), Output)); |
| 47 | Expected = { |
| 48 | 0x0AU, // Code section |
| 49 | 0x04U, // Content size = 4 |
| 50 | 0x01U, // Vector length = 1 |
| 51 | 0x02U, // Code segment size = 2 |
| 52 | 0x00U, // Local vec(0) |
| 53 | 0x0BU // Expression: OpCode End. |
| 54 | }; |
| 55 | EXPECT_EQ(Output, Expected); |
| 56 | |
| 57 | Expr.getInstrs() = {I32Eqz, I32Eq, I32Ne, End}; |
| 58 | Output = {}; |
| 59 | EXPECT_TRUE(Ser.serializeSection(createCodeSec(Expr), Output)); |
| 60 | Expected = { |
| 61 | 0x0AU, // Code section |
| 62 | 0x07U, // Content size = 7 |
| 63 | 0x01U, // Vector length = 1 |
| 64 | 0x05U, // Code segment size = 5 |
| 65 | 0x00U, // Local vec(0) |
| 66 | 0x45U, 0x46U, 0x47U, // Valid OpCodes. |
| 67 | 0x0BU // OpCode End. |
| 68 | }; |
| 69 | EXPECT_EQ(Output, Expected); |
| 70 | |
| 71 | Expr.getInstrs() = {TableGet, End}; |
| 72 | EXPECT_FALSE(SerWASM1.serializeSection(createCodeSec(Expr), Output)); |
| 73 | } |
| 74 | } // namespace |
nothing calls this directly
no test coverage detected