aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@home.transmeta.com>2003-05-17 11:32:13 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:00:41 -0700
commitec69546dc4d1d3fd8853544d0c39af00799dadf3 (patch)
tree822c80719566e856de0f78e1fd75c1aafd8a4f8a
parent143649c4678106e5cc95db5c70c64c6393ad08cf (diff)
downloadsparse-ec69546dc4d1d3fd8853544d0c39af00799dadf3.tar.gz
sparse-ec69546dc4d1d3fd8853544d0c39af00799dadf3.tar.xz
sparse-ec69546dc4d1d3fd8853544d0c39af00799dadf3.zip
Fix switch/case statement show-parse.
-rw-r--r--parse.c1
-rw-r--r--parse.h1
-rw-r--r--show-parse.c33
3 files changed, 19 insertions, 16 deletions
diff --git a/parse.c b/parse.c
index 404a851..7f03dc8 100644
--- a/parse.c
+++ b/parse.c
@@ -671,6 +671,7 @@ static void add_case_statement(struct statement *stmt)
sym = alloc_symbol(stmt->pos, SYM_NODE);
add_symbol(&target->symbol_list, sym);
sym->stmt = stmt;
+ stmt->case_label = sym;
}
struct token *statement(struct token *token, struct statement **tree)
diff --git a/parse.h b/parse.h
index 4d3a519..b5de862 100644
--- a/parse.h
+++ b/parse.h
@@ -51,6 +51,7 @@ struct statement {
struct expression *case_expression;
struct expression *case_to;
struct statement *case_statement;
+ struct symbol *case_label;
};
struct switch_struct {
struct expression *switch_expression;
diff --git a/show-parse.c b/show-parse.c
index f0f54ab..fdceb4b 100644
--- a/show-parse.c
+++ b/show-parse.c
@@ -344,32 +344,42 @@ static void show_switch_statement(struct statement *stmt)
struct symbol *sym;
printf("\tswitch v%d\n", val);
+ /*
+ * Debugging only: Check that the case list is correct
+ * by printing it out.
+ *
+ * This is where a _real_ back-end would go through the
+ * cases to decide whether to use a lookup table or a
+ * series of comparisons etc
+ */
+ printf("case list:\n");
FOR_EACH_PTR(stmt->switch_case->symbol_list, sym) {
struct statement *case_stmt = sym->stmt;
struct expression *expr = case_stmt->case_expression;
struct expression *to = case_stmt->case_to;
+ printf(" .L%p: ", sym);
if (!expr) {
- printf("default:\n");
+ printf(" default");
} else {
if (expr->type == EXPR_VALUE) {
- printf("case %lld", expr->value);
+ printf(" %lld", expr->value);
if (to) {
if (to->type == EXPR_VALUE) {
printf(" .. %lld", to->value);
} else {
- printf(" .. what");
+ printf(" .. what?");
}
}
- printf(":\n");
} else
- printf("case what:\n");
+ printf(" what?");
}
- show_statement(case_stmt->case_statement);
+ printf("\n");
} END_FOR_EACH_PTR;
if (stmt->switch_break->used)
printf(".L%p:\n", stmt->switch_break);
+ show_statement(stmt->switch_statement);
}
/*
@@ -429,16 +439,7 @@ int show_statement(struct statement *stmt)
break;
case STMT_CASE:
- if (!stmt->case_expression)
- printf("default");
- else {
- printf("case %lld", stmt->case_expression->value);
- if (stmt->case_to) {
- printf("...%lld", stmt->case_to->value);
- }
-
- }
- printf(":\n");
+ printf(".L%p:\n", stmt->case_label);
show_statement(stmt->case_statement);
break;