Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/arm.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,12 @@ int __blx(arm_cond_t cond, arm_reg rd)
return arm_encode(cond, 18, 15, 15, rd + 3888);
}

int __bx(arm_cond_t cond, arm_reg rm)
{
/* BX: Branch and Exchange */
return (cond << 28) | 0x012FFF10 | rm;
}

int __mul(arm_cond_t cond, arm_reg rd, arm_reg r1, arm_reg r2)
{
return arm_encode(cond, 0, rd, 0, (r1 << 8) + 144 + r2);
Expand Down
58 changes: 46 additions & 12 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1750,18 +1750,40 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)
read_expr_operand(parent, bb);

rs1 = opstack_pop();
vd = require_var(parent);
gen_name_to(vd->var_name);
opstack_push(vd);
add_insn(parent, *bb, OP_log_not, vd, rs1, NULL, 0, NULL);

/* Constant folding for logical NOT */
if (rs1 && rs1->is_const && !rs1->ptr_level && !rs1->is_global) {
vd = require_var(parent);
gen_name_to(vd->var_name);
vd->is_const = true;
vd->init_val = !rs1->init_val;
opstack_push(vd);
add_insn(parent, *bb, OP_load_constant, vd, NULL, NULL, 0, NULL);
} else {
vd = require_var(parent);
gen_name_to(vd->var_name);
opstack_push(vd);
add_insn(parent, *bb, OP_log_not, vd, rs1, NULL, 0, NULL);
}
Comment on lines +1755 to +1767
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

require_var() and gen_name_to() can be moved to before the if statement to improve code reusability. That is:

vd = require_var(parent);
gen_name_to(vd->var_name);
if (rs1 && rs1->is_const && !rs1->ptr_level && !rs1->is_global) {
    vd->is_const = true;
    ...
} else {
    opstack_push(vd);
    add_insn(...);
}

} else if (lex_accept(T_bit_not)) {
read_expr_operand(parent, bb);

rs1 = opstack_pop();
vd = require_var(parent);
gen_name_to(vd->var_name);
opstack_push(vd);
add_insn(parent, *bb, OP_bit_not, vd, rs1, NULL, 0, NULL);

/* Constant folding for bitwise NOT */
if (rs1 && rs1->is_const && !rs1->ptr_level && !rs1->is_global) {
vd = require_var(parent);
gen_name_to(vd->var_name);
vd->is_const = true;
vd->init_val = ~rs1->init_val;
opstack_push(vd);
add_insn(parent, *bb, OP_load_constant, vd, NULL, NULL, 0, NULL);
} else {
vd = require_var(parent);
gen_name_to(vd->var_name);
opstack_push(vd);
add_insn(parent, *bb, OP_bit_not, vd, rs1, NULL, 0, NULL);
}
Comment on lines +1774 to +1786
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

} else if (lex_accept(T_ampersand)) {
handle_address_of_operator(parent, bb);
} else if (lex_accept(T_asterisk)) {
Expand Down Expand Up @@ -2179,10 +2201,22 @@ void read_expr_operand(block_t *parent, basic_block_t **bb)

if (is_neg) {
rs1 = opstack_pop();
vd = require_var(parent);
gen_name_to(vd->var_name);
opstack_push(vd);
add_insn(parent, *bb, OP_negate, vd, rs1, NULL, 0, NULL);

/* Constant folding for negation */
if (rs1 && rs1->is_const && !rs1->ptr_level && !rs1->is_global) {
vd = require_var(parent);
gen_name_to(vd->var_name);
vd->is_const = true;
vd->init_val = -rs1->init_val;
opstack_push(vd);
add_insn(parent, *bb, OP_load_constant, vd, NULL, NULL, 0,
NULL);
} else {
vd = require_var(parent);
gen_name_to(vd->var_name);
opstack_push(vd);
add_insn(parent, *bb, OP_negate, vd, rs1, NULL, 0, NULL);
}
Comment on lines +2205 to +2219
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

}
}
}
Expand Down
Loading