aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-08-27 11:43:24 -0700
committerChristopher Li <sparse@chrisli.org>2011-08-27 23:36:22 -0700
commit46352d97f3741a6415b88644e735a0ae59e0c38c (patch)
treed93893c5c31ae024ea1141888584e5265b880e29
parentcbe34a536d642fee2c0d2da5865ad09755a20652 (diff)
downloadsparse-46352d97f3741a6415b88644e735a0ae59e0c38c.tar.gz
Make 'linearize_return()' helper function
Rather than do it in that huge 'linearize_statement()' function, split out the return generation case. Avoids one level of indentation, and makes for simpler and more straightforward functions. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Christopher Li <sparse@chrisli.org>
-rw-r--r--linearize.c48
1 files changed, 26 insertions, 22 deletions
diff --git a/linearize.c b/linearize.c
index e4885475..32097274 100644
--- a/linearize.c
+++ b/linearize.c
@@ -1843,6 +1843,30 @@ static pseudo_t linearize_declaration(struct entrypoint *ep, struct statement *s
return VOID;
}
+static pseudo_t linearize_return(struct entrypoint *ep, struct statement *stmt)
+{
+ struct expression *expr = stmt->expression;
+ struct basic_block *bb_return = get_bound_block(ep, stmt->ret_target);
+ struct basic_block *active;
+ pseudo_t src = linearize_expression(ep, expr);
+ active = ep->active;
+ if (active && src != &void_pseudo) {
+ struct instruction *phi_node = first_instruction(bb_return->insns);
+ pseudo_t phi;
+ if (!phi_node) {
+ phi_node = alloc_typed_instruction(OP_PHI, expr->ctype);
+ phi_node->target = alloc_pseudo(phi_node);
+ phi_node->bb = bb_return;
+ add_instruction(&bb_return->insns, phi_node);
+ }
+ phi = alloc_phi(active, src, type_size(expr->ctype));
+ phi->ident = &return_ident;
+ use_pseudo(phi_node, phi, add_pseudo(&phi_node->phi_list, phi));
+ }
+ add_goto(ep, bb_return);
+ return VOID;
+}
+
static pseudo_t linearize_switch(struct entrypoint *ep, struct statement *stmt)
{
struct symbol *sym;
@@ -1980,28 +2004,8 @@ pseudo_t linearize_statement(struct entrypoint *ep, struct statement *stmt)
case STMT_ASM:
return linearize_asm_statement(ep, stmt);
- case STMT_RETURN: {
- struct expression *expr = stmt->expression;
- struct basic_block *bb_return = get_bound_block(ep, stmt->ret_target);
- struct basic_block *active;
- pseudo_t src = linearize_expression(ep, expr);
- active = ep->active;
- if (active && src != &void_pseudo) {
- struct instruction *phi_node = first_instruction(bb_return->insns);
- pseudo_t phi;
- if (!phi_node) {
- phi_node = alloc_typed_instruction(OP_PHI, expr->ctype);
- phi_node->target = alloc_pseudo(phi_node);
- phi_node->bb = bb_return;
- add_instruction(&bb_return->insns, phi_node);
- }
- phi = alloc_phi(active, src, type_size(expr->ctype));
- phi->ident = &return_ident;
- use_pseudo(phi_node, phi, add_pseudo(&phi_node->phi_list, phi));
- }
- add_goto(ep, bb_return);
- return VOID;
- }
+ case STMT_RETURN:
+ return linearize_return(ep, stmt);
case STMT_CASE: {
add_label(ep, stmt->case_label);