Skip to content

Commit

Permalink
Small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tyfkda committed Aug 31, 2023
1 parent fbc54ea commit 6cb07c7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
8 changes: 4 additions & 4 deletions src/cc/backend/codegen_expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ static VReg *gen_ternary(Expr *expr) {
BB *nbb = new_bb();
VReg *result = NULL;
if (expr->type->kind != TY_VOID) {
if (is_number(expr->type) || ptr_or_array(expr->type))
result = add_new_reg(expr->type, 0);
else
result = add_new_reg(ptrof(expr->type), 0);
Type *type = expr->type;
if (!is_number(type) && !ptr_or_array(type))
type = ptrof(type);
result = add_new_reg(type, 0);
}

gen_cond_jmp(expr->ternary.cond, false, fbb);
Expand Down
12 changes: 3 additions & 9 deletions src/cc/backend/ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,17 @@ VReg *new_ir_bop(enum IrKind kind, VReg *opr1, VReg *opr2, const VRegType *vtype
break;
case IR_BITAND:
if (opr1->fixnum == 0)
return opr1;
return opr1; // 0
break;
case IR_BITOR:
if (opr1->fixnum == 0)
return opr2;
break;
case IR_BITXOR:
if (opr1->fixnum == 0)
return opr2;
break;
case IR_LSHIFT:
case IR_RSHIFT:
if (opr1->fixnum == 0)
return opr1;
return opr1; // 0
break;
default:
break;
Expand All @@ -139,12 +136,9 @@ VReg *new_ir_bop(enum IrKind kind, VReg *opr1, VReg *opr2, const VRegType *vtype
break;
case IR_BITAND:
if (opr2->fixnum == 0)
return opr2;
return opr2; // 0
break;
case IR_BITOR:
if (opr2->fixnum == 0)
return opr1;
break;
case IR_BITXOR:
if (opr2->fixnum == 0)
return opr1;
Expand Down
2 changes: 0 additions & 2 deletions src/wcc/gen_wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ static int continue_depth;
unsigned char to_wtype(const Type *type) {
switch (type->kind) {
case TY_FIXNUM: return type_size(type) <= I32_SIZE ? WT_I32 : WT_I64;
#ifndef __NO_FLONUM
case TY_FLONUM: return type->flonum.kind == FL_FLOAT ? WT_F32 : WT_F64;
#endif
case TY_PTR:
case TY_ARRAY:
// Pointer and array is handled as an index of linear memroy.
Expand Down

0 comments on commit 6cb07c7

Please sign in to comment.