static bool RenderBinaryOperator(WasmRenderContext& c, AstBinaryOperator& op) { if (!c.buffer.append("(")) return false; const char* opStr; switch (op.expr()) { case Expr::I32Add: opStr = "i32.add"; break; case Expr::I32Sub: opStr = "i32.sub"; break; case Expr::I32Mul: opStr = "i32.mul"; break; case Expr::I32DivS: opStr = "i32.div_s"; break; case Expr::I32DivU: opStr = "i32.div_u"; break; case Expr::I32RemS: opStr = "i32.rem_s"; break; case Expr::I32RemU: opStr = "i32.rem_u"; break; case Expr::I32And: opStr = "i32.and"; break; case Expr::I32Or: opStr = "i32.or"; break; case Expr::I32Xor: opStr = "i32.xor"; break; case Expr::I32Shl: opStr = "i32.shl"; break; case Expr::I32ShrS: opStr = "i32.shr_s"; break; case Expr::I32ShrU: opStr = "i32.shr_u"; break; case Expr::I64Add: opStr = "i64.add"; break; case Expr::I64Sub: opStr = "i64.sub"; break; case Expr::I64Mul: opStr = "i64.mul"; break; case Expr::I64DivS: opStr = "i64.div_s"; break; case Expr::I64DivU: opStr = "i64.div_u"; break; case Expr::I64RemS: opStr = "i64.rem_s"; break; case Expr::I64RemU: opStr = "i64.rem_u"; break; case Expr::I64And: opStr = "i64.and"; break; case Expr::I64Or: opStr = "i64.or"; break; case Expr::I64Xor: opStr = "i64.xor"; break; case Expr::I64Shl: opStr = "i64.shl"; break; case Expr::I64ShrS: opStr = "i64.shr_s"; break; case Expr::I64ShrU: opStr = "i64.shr_u"; break; case Expr::F32Add: opStr = "f32.add"; break; case Expr::F32Sub: opStr = "f32.sub"; break; case Expr::F32Mul: opStr = "f32.mul"; break; case Expr::F32Div: opStr = "f32.div"; break; case Expr::F32Min: opStr = "f32.min"; break; case Expr::F32Max: opStr = "f32.max"; break; case Expr::F32CopySign: opStr = "f32.copysign"; break; case Expr::F64Add: opStr = "f64.add"; break; case Expr::F64Sub: opStr = "f64.sub"; break; case Expr::F64Mul: opStr = "f64.mul"; break; case Expr::F64Div: opStr = "f64.div"; break; case Expr::F64Min: opStr = "f64.min"; break; case Expr::F64Max: opStr = "f64.max"; break; default: return false; } if (!c.buffer.append(opStr, strlen(opStr))) return false; if (!c.buffer.append(" ")) return false; if (!RenderExpr(c, *op.lhs())) return false; if (!c.buffer.append(" ")) return false; if (!RenderExpr(c, *op.rhs())) return false; if (!c.buffer.append(")")) return false; return true; }
static bool RenderBinaryOperator(WasmRenderContext& c, AstBinaryOperator& binary) { if (!RenderExpr(c, *binary.lhs())) return false; if (!RenderExpr(c, *binary.rhs())) return false; if (!RenderIndent(c)) return false; MAP_AST_EXPR(c, binary); const char* opStr; switch (binary.op()) { case Op::I32Add: opStr = "i32.add"; break; case Op::I32Sub: opStr = "i32.sub"; break; case Op::I32Mul: opStr = "i32.mul"; break; case Op::I32DivS: opStr = "i32.div_s"; break; case Op::I32DivU: opStr = "i32.div_u"; break; case Op::I32RemS: opStr = "i32.rem_s"; break; case Op::I32RemU: opStr = "i32.rem_u"; break; case Op::I32And: opStr = "i32.and"; break; case Op::I32Or: opStr = "i32.or"; break; case Op::I32Xor: opStr = "i32.xor"; break; case Op::I32Shl: opStr = "i32.shl"; break; case Op::I32ShrS: opStr = "i32.shr_s"; break; case Op::I32ShrU: opStr = "i32.shr_u"; break; case Op::I32Rotl: opStr = "i32.rotl"; break; case Op::I32Rotr: opStr = "i32.rotr"; break; case Op::I64Add: opStr = "i64.add"; break; case Op::I64Sub: opStr = "i64.sub"; break; case Op::I64Mul: opStr = "i64.mul"; break; case Op::I64DivS: opStr = "i64.div_s"; break; case Op::I64DivU: opStr = "i64.div_u"; break; case Op::I64RemS: opStr = "i64.rem_s"; break; case Op::I64RemU: opStr = "i64.rem_u"; break; case Op::I64And: opStr = "i64.and"; break; case Op::I64Or: opStr = "i64.or"; break; case Op::I64Xor: opStr = "i64.xor"; break; case Op::I64Shl: opStr = "i64.shl"; break; case Op::I64ShrS: opStr = "i64.shr_s"; break; case Op::I64ShrU: opStr = "i64.shr_u"; break; case Op::I64Rotl: opStr = "i64.rotl"; break; case Op::I64Rotr: opStr = "i64.rotr"; break; case Op::F32Add: opStr = "f32.add"; break; case Op::F32Sub: opStr = "f32.sub"; break; case Op::F32Mul: opStr = "f32.mul"; break; case Op::F32Div: opStr = "f32.div"; break; case Op::F32Min: opStr = "f32.min"; break; case Op::F32Max: opStr = "f32.max"; break; case Op::F32CopySign: opStr = "f32.copysign"; break; case Op::F64Add: opStr = "f64.add"; break; case Op::F64Sub: opStr = "f64.sub"; break; case Op::F64Mul: opStr = "f64.mul"; break; case Op::F64Div: opStr = "f64.div"; break; case Op::F64Min: opStr = "f64.min"; break; case Op::F64Max: opStr = "f64.max"; break; case Op::F64CopySign: opStr = "f64.copysign"; break; default: return Fail(c, "unexpected binary operator"); } return c.buffer.append(opStr, strlen(opStr)); }