Lines Matching refs:expr

27 static pseudo_t linearize_expression(struct entrypoint *ep, struct expression *expr);
113 struct expression *expr;
127 expr = sym->initializer;
129 if (expr) {
130 switch (expr->type) {
132 snprintf(buf, 64, "<symbol value: %lld>", expr->value);
135 return show_string(expr->string);
351 struct expression *expr = insn->val;
354 if (!expr) {
359 switch (expr->type) {
361 buf += sprintf(buf, "%lld", expr->value);
364 buf += sprintf(buf, "%Le", expr->fvalue);
367 buf += sprintf(buf, "%.40s", show_string(expr->string));
370 buf += sprintf(buf, "%s", show_ident(expr->symbol->ident));
373 buf += sprintf(buf, "%s", show_label(expr->symbol->bb_target));
376 buf += sprintf(buf, "SETVAL EXPR TYPE %d", expr->type);
951 struct expression *expr,
954 struct symbol *ctype = expr->ctype;
959 if (expr->type == EXPR_PREOP && expr->op == '*')
960 return linearize_simple_address(ep, expr->unop, ad);
962 warning(expr->pos, "generating address of non-lvalue (%d)", expr->type);
1095 static pseudo_t add_symbol_address(struct entrypoint *ep, struct expression *expr)
1097 struct instruction *insn = alloc_typed_instruction(OP_SYMADDR, expr->ctype);
1101 use_pseudo(insn, symbol_pseudo(ep, expr->symbol), &insn->src);
1135 static pseudo_t linearize_access(struct entrypoint *ep, struct expression *expr)
1140 if (!linearize_address_gen(ep, expr, &ad))
1146 static pseudo_t linearize_inc_dec(struct entrypoint *ep, struct expression *expr, int postop)
1150 int op = expr->op == SPECIAL_INCREMENT ? OP_ADD : OP_SUB;
1152 if (!linearize_address_gen(ep, expr->unop, &ad))
1156 op = opcode_float(op, expr->ctype);
1157 if (is_float_type(expr->ctype))
1158 one = add_setfval(ep, expr->ctype, expr->op_value);
1160 one = value_pseudo(expr->op_value);
1189 static pseudo_t linearize_slice(struct entrypoint *ep, struct expression *expr)
1191 pseudo_t pre = linearize_expression(ep, expr->base);
1192 struct instruction *insn = alloc_typed_instruction(OP_SLICE, expr->ctype);
1196 insn->from = expr->r_bitpos;
1197 insn->orig_type = expr->base->ctype;
1203 static pseudo_t linearize_regular_preop(struct entrypoint *ep, struct expression *expr)
1205 pseudo_t pre = linearize_expression(ep, expr->unop);
1206 struct symbol *ctype = expr->ctype;
1207 switch (expr->op) {
1212 return add_cmp_op(ep, ctype, OP_SET_EQ, expr->unop->ctype, pre, zero);
1222 static pseudo_t linearize_preop(struct entrypoint *ep, struct expression *expr)
1229 if (expr->op == '*')
1230 return linearize_access(ep, expr);
1231 if (expr->op == SPECIAL_INCREMENT || expr->op == SPECIAL_DECREMENT)
1232 return linearize_inc_dec(ep, expr, 0);
1233 return linearize_regular_preop(ep, expr);
1236 static pseudo_t linearize_postop(struct entrypoint *ep, struct expression *expr)
1238 return linearize_inc_dec(ep, expr, 1);
1442 static pseudo_t linearize_expression_to_bool(struct entrypoint *ep, struct expression *expr)
1445 dst = linearize_expression(ep, expr);
1446 dst = add_convert_to_bool(ep, dst, expr->ctype);
1450 static pseudo_t linearize_assignment(struct entrypoint *ep, struct expression *expr)
1453 struct expression *target = expr->left;
1454 struct expression *src = expr->right;
1461 if (expr->op != '=') {
1483 opcode = map_opcode(op_trans[expr->op - SPECIAL_BASE], ctype);
1486 value = cast_pseudo(ep, dst, ctype, expr->ctype);
1492 static pseudo_t linearize_call_expression(struct entrypoint *ep, struct expression *expr)
1501 if (!expr->ctype)
1504 fn = expr->fn;
1509 retval = fntype->op->linearize(ep, expr);
1516 insn = alloc_typed_instruction(OP_CALL, expr->ctype);
1518 FOR_EACH_PTR(expr->args, arg) {
1534 if (expr->ctype != &void_ctype)
1570 static pseudo_t linearize_binop_bool(struct entrypoint *ep, struct expression *expr)
1573 int op = (expr->op == SPECIAL_LOGICAL_OR) ? OP_OR : OP_AND;
1575 src1 = linearize_expression_to_bool(ep, expr->left);
1576 src2 = linearize_expression_to_bool(ep, expr->right);
1578 if (expr->ctype != &bool_ctype)
1579 dst = cast_pseudo(ep, dst, &bool_ctype, expr->ctype);
1583 static pseudo_t linearize_binop(struct entrypoint *ep, struct expression *expr)
1596 src1 = linearize_expression(ep, expr->left);
1597 src2 = linearize_expression(ep, expr->right);
1598 op = map_opcode(opcode[expr->op], expr->ctype);
1599 dst = add_binary_op(ep, expr->ctype, op, src1, src2);
1604 static pseudo_t linearize_logical_branch(struct entrypoint *ep, struct expression *expr, struct basic_block *bb_true, struct basic_block *bb_false);
1606 static pseudo_t linearize_cond_branch(struct entrypoint *ep, struct expression *expr, struct basic_block *bb_true, struct basic_block *bb_false);
1608 static pseudo_t linearize_select(struct entrypoint *ep, struct expression *expr)
1613 valt = linearize_expression(ep, expr->cond_true);
1614 valf = linearize_expression(ep, expr->cond_false);
1615 cond = linearize_expression(ep, expr->conditional);
1617 insn = alloc_typed_instruction(OP_SEL, expr->ctype);
1618 if (!expr->cond_true)
1630 static pseudo_t add_join_conditional(struct entrypoint *ep, struct expression *expr,
1641 phi_node = alloc_typed_instruction(OP_PHI, expr->ctype);
1649 static pseudo_t linearize_short_conditional(struct entrypoint *ep, struct expression *expr,
1662 merge = alloc_basic_block(ep, expr->pos);
1665 phi1 = alloc_phi(ep->active, src1, expr->ctype);
1670 phi2 = alloc_phi(ep->active, src2, expr->ctype);
1673 return add_join_conditional(ep, expr, phi1, phi2);
1676 static pseudo_t linearize_conditional(struct entrypoint *ep, struct expression *expr,
1689 merge = alloc_basic_block(ep, expr->pos);
1695 phi1 = alloc_phi(ep->active, src1, expr->ctype);
1700 phi2 = alloc_phi(ep->active, src2, expr->ctype);
1703 return add_join_conditional(ep, expr, phi1, phi2);
1718 static pseudo_t linearize_logical(struct entrypoint *ep, struct expression *expr)
1720 struct symbol *ctype = expr->ctype;
1725 if (!ep->active || !expr->left || !expr->right)
1728 other = alloc_basic_block(ep, expr->right->pos);
1729 merge = alloc_basic_block(ep, expr->pos);
1733 if (expr->op == SPECIAL_LOGICAL_OR) {
1734 linearize_cond_branch(ep, expr->left, merge, other);
1737 linearize_cond_branch(ep, expr->left, other, merge);
1744 src2 = linearize_expression_to_bool(ep, expr->right);
1755 static pseudo_t linearize_compare(struct entrypoint *ep, struct expression *expr)
1768 struct symbol *itype = expr->right->ctype;
1769 int op = opcode_float(cmpop[expr->op], itype);
1770 pseudo_t src1 = linearize_expression(ep, expr->left);
1771 pseudo_t src2 = linearize_expression(ep, expr->right);
1772 pseudo_t dst = add_cmp_op(ep, expr->ctype, op, itype, src1, src2);
1777 static pseudo_t linearize_cond_branch(struct entrypoint *ep, struct expression *expr, struct basic_block *bb_true, struct basic_block *bb_false)
1781 if (!expr || !valid_type(expr->ctype) || !bb_reachable(ep->active))
1784 switch (expr->type) {
1788 add_goto(ep, expr->value ? bb_true : bb_false);
1791 add_goto(ep, expr->fvalue ? bb_true : bb_false);
1794 linearize_logical_branch(ep, expr, bb_true, bb_false);
1797 cond = linearize_compare(ep, expr);
1801 if (expr->op == '!')
1802 return linearize_cond_branch(ep, expr->unop, bb_false, bb_true);
1805 cond = linearize_expression_to_bool(ep, expr);
1813 static pseudo_t linearize_logical_branch(struct entrypoint *ep, struct expression *expr, struct basic_block *bb_true, struct basic_block *bb_false)
1815 struct basic_block *next = alloc_basic_block(ep, expr->pos);
1817 if (expr->op == SPECIAL_LOGICAL_OR)
1818 linearize_cond_branch(ep, expr->left, bb_true, next);
1820 linearize_cond_branch(ep, expr->left, next, bb_false);
1822 linearize_cond_branch(ep, expr->right, bb_true, bb_false);
1826 static pseudo_t linearize_cast(struct entrypoint *ep, struct expression *expr)
1829 struct expression *orig = expr->cast_expression;
1835 return cast_pseudo(ep, src, orig->ctype, expr->ctype);
1842 struct expression *expr;
1843 FOR_EACH_PTR(initializer->expr_list, expr) {
1844 linearize_initializer(ep, expr, ad);
1845 } END_FOR_EACH_PTR(expr);
1872 static pseudo_t linearize_expression(struct entrypoint *ep, struct expression *expr)
1874 if (!expr || !valid_type(expr->ctype))
1877 current_pos = expr->pos;
1878 switch (expr->type) {
1880 linearize_one_symbol(ep, expr->symbol);
1881 return add_symbol_address(ep, expr);
1884 return value_pseudo(expr->value);
1888 return add_setval(ep, expr->ctype, expr);
1891 return add_setfval(ep, expr->ctype, expr->fvalue);
1894 return linearize_statement(ep, expr->statement);
1897 return linearize_call_expression(ep, expr);
1900 if (expr->op == SPECIAL_LOGICAL_AND || expr->op == SPECIAL_LOGICAL_OR)
1901 return linearize_binop_bool(ep, expr);
1902 return linearize_binop(ep, expr);
1905 return linearize_logical(ep, expr);
1908 return linearize_compare(ep, expr);
1911 return linearize_select(ep, expr);
1914 if (!expr->cond_true)
1915 return linearize_short_conditional(ep, expr, expr->conditional, expr->cond_false);
1917 return linearize_conditional(ep, expr, expr->conditional,
1918 expr->cond_true, expr->cond_false);
1921 linearize_expression(ep, expr->left);
1922 return linearize_expression(ep, expr->right);
1925 return linearize_assignment(ep, expr);
1928 return linearize_preop(ep, expr);
1931 return linearize_postop(ep, expr);
1936 return linearize_cast(ep, expr);
1939 return linearize_slice(ep, expr);
1943 warning(expr->pos, "unexpected initializer expression (%d %d)", expr->type, expr->op);
1946 warning(expr->pos, "unknown expression (%d %d)", expr->type, expr->op);
2063 struct expression *expr = stmt->expression;
2065 insn->increment = get_expression_value(expr);
2097 pseudo_t pseudo = linearize_expression(ep, op->expr);
2109 pseudo = linearize_expression(ep, op->expr);
2122 if (!linearize_address_gen(ep, op->expr, &ad))
2133 struct expression *expr, *clob;
2138 expr = stmt->asm_string;
2139 if (!expr || expr->type != EXPR_STRING) {
2143 insn->string = expr->string->data;
2214 struct expression *expr = stmt->expression;
2218 pseudo_t src = linearize_expression(ep, expr);
2233 struct expression *expr = stmt->switch_expression;
2237 if (!expr || !expr->ctype)
2239 pseudo = linearize_expression(ep, expr);
2246 switch_ins = alloc_typed_instruction(OP_SWITCH, expr->ctype);
2395 struct expression *expr;
2409 expr = stmt->goto_expression;
2410 if (!expr)
2414 if (expr->type == EXPR_LABEL) {
2415 add_goto(ep, get_bound_block(ep, expr->label_symbol));
2419 pseudo = linearize_expression(ep, expr);
2601 static pseudo_t linearize_fma(struct entrypoint *ep, struct expression *expr)
2603 struct instruction *insn = alloc_typed_instruction(OP_FMADD, expr->ctype);
2606 PREPARE_PTR_LIST(expr->args, arg);
2618 static pseudo_t linearize_isdigit(struct entrypoint *ep, struct expression *expr)
2624 src = linearize_expression(ep, first_expression(expr->args));