Skip to content

Commit

Permalink
Suppress adding zero
Browse files Browse the repository at this point in the history
  • Loading branch information
tyfkda committed Mar 2, 2024
1 parent 571cdd9 commit 6a604ac
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/wcc/gen_wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,9 +357,13 @@ static void gen_funcall(Expr *expr) {
if (size > 0) {
sarg_offset = ALIGN(sarg_offset, align_size(arg->type));
// _memcpy(global.sp + sarg_offset, &arg, size);
gen_expr(new_expr_bop(EX_ADD, &tySize, NULL, spvar,
new_expr_fixlit(&tySize, NULL, sarg_offset)),
true);
if (sarg_offset != 0) {
gen_expr(new_expr_bop(EX_ADD, &tySize, NULL, spvar,
new_expr_fixlit(&tySize, NULL, sarg_offset)),
true);
} else {
gen_expr(spvar, true);
}
gen_expr(arg, true);

ADD_CODE(OP_I32_CONST);
Expand All @@ -371,9 +375,14 @@ static void gen_funcall(Expr *expr) {
} else {
assert(!is_stack_param(arg->type));
// *(global.sp + sarg_siz + vaarg_offset) = arg
gen_expr(new_expr_bop(EX_ADD, &tySize, NULL, spvar,
new_expr_fixlit(&tySize, NULL, sarg_siz + vaarg_offset)),
true);
int offset = sarg_siz + vaarg_offset;
if (offset != 0) {
gen_expr(new_expr_bop(EX_ADD, &tySize, NULL, spvar,
new_expr_fixlit(&tySize, NULL, offset)),
true);
} else {
gen_expr(spvar, true);
}
const Type *t = arg->type;
assert(!(t->kind == TY_FIXNUM && t->fixnum.kind < FX_INT));
vaarg_offset += type_size(t);
Expand Down

0 comments on commit 6a604ac

Please sign in to comment.