static bool RenderComparisonOperator(WasmRenderContext& c, AstComparisonOperator& op) { if (!c.buffer.append("(")) return false; const char* opStr; switch (op.expr()) { case Expr::I32Eq: opStr = "i32.eq"; break; case Expr::I32Ne: opStr = "i32.ne"; break; case Expr::I32LtS: opStr = "i32.lt_s"; break; case Expr::I32LtU: opStr = "i32.lt_u"; break; case Expr::I32LeS: opStr = "i32.le_s"; break; case Expr::I32LeU: opStr = "i32.le_u"; break; case Expr::I32GtS: opStr = "i32.gt_s"; break; case Expr::I32GtU: opStr = "i32.gt_u"; break; case Expr::I32GeS: opStr = "i32.ge_s"; break; case Expr::I32GeU: opStr = "i32.ge_u"; break; case Expr::I64Eq: opStr = "i64.eq"; break; case Expr::I64Ne: opStr = "i64.ne"; break; case Expr::I64LtS: opStr = "i64.lt_s"; break; case Expr::I64LtU: opStr = "i64.lt_u"; break; case Expr::I64LeS: opStr = "i64.le_s"; break; case Expr::I64LeU: opStr = "i64.le_u"; break; case Expr::I64GtS: opStr = "i64.gt_s"; break; case Expr::I64GtU: opStr = "i64.gt_u"; break; case Expr::I64GeS: opStr = "i64.ge_s"; break; case Expr::I64GeU: opStr = "i64.ge_u"; break; case Expr::F32Eq: opStr = "f32.eq"; break; case Expr::F32Ne: opStr = "f32.ne"; break; case Expr::F32Lt: opStr = "f32.lt"; break; case Expr::F32Le: opStr = "f32.le"; break; case Expr::F32Gt: opStr = "f32.gt"; break; case Expr::F32Ge: opStr = "f32.ge"; break; case Expr::F64Eq: opStr = "f64.eq"; break; case Expr::F64Ne: opStr = "f64.ne"; break; case Expr::F64Lt: opStr = "f64.lt"; break; case Expr::F64Le: opStr = "f64.le"; break; case Expr::F64Gt: opStr = "f64.gt"; break; case Expr::F64Ge: opStr = "f64.ge"; 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 RenderComparisonOperator(WasmRenderContext& c, AstComparisonOperator& comp) { if (!RenderExpr(c, *comp.lhs())) return false; if (!RenderExpr(c, *comp.rhs())) return false; if (!RenderIndent(c)) return false; MAP_AST_EXPR(c, comp); const char* opStr; switch (comp.op()) { case Op::I32Eq: opStr = "i32.eq"; break; case Op::I32Ne: opStr = "i32.ne"; break; case Op::I32LtS: opStr = "i32.lt_s"; break; case Op::I32LtU: opStr = "i32.lt_u"; break; case Op::I32LeS: opStr = "i32.le_s"; break; case Op::I32LeU: opStr = "i32.le_u"; break; case Op::I32GtS: opStr = "i32.gt_s"; break; case Op::I32GtU: opStr = "i32.gt_u"; break; case Op::I32GeS: opStr = "i32.ge_s"; break; case Op::I32GeU: opStr = "i32.ge_u"; break; case Op::I64Eq: opStr = "i64.eq"; break; case Op::I64Ne: opStr = "i64.ne"; break; case Op::I64LtS: opStr = "i64.lt_s"; break; case Op::I64LtU: opStr = "i64.lt_u"; break; case Op::I64LeS: opStr = "i64.le_s"; break; case Op::I64LeU: opStr = "i64.le_u"; break; case Op::I64GtS: opStr = "i64.gt_s"; break; case Op::I64GtU: opStr = "i64.gt_u"; break; case Op::I64GeS: opStr = "i64.ge_s"; break; case Op::I64GeU: opStr = "i64.ge_u"; break; case Op::F32Eq: opStr = "f32.eq"; break; case Op::F32Ne: opStr = "f32.ne"; break; case Op::F32Lt: opStr = "f32.lt"; break; case Op::F32Le: opStr = "f32.le"; break; case Op::F32Gt: opStr = "f32.gt"; break; case Op::F32Ge: opStr = "f32.ge"; break; case Op::F64Eq: opStr = "f64.eq"; break; case Op::F64Ne: opStr = "f64.ne"; break; case Op::F64Lt: opStr = "f64.lt"; break; case Op::F64Le: opStr = "f64.le"; break; case Op::F64Gt: opStr = "f64.gt"; break; case Op::F64Ge: opStr = "f64.ge"; break; default: return Fail(c, "unexpected comparison operator"); } return c.buffer.append(opStr, strlen(opStr)); }