aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
authorLinus Torvalds <torvalds@penguin.transmeta.com>2003-04-07 14:26:36 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:00:18 -0700
commit93917f1761f5f1d1eb9ce7a5c867ef6f6e98db38 (patch)
treee45b39c270e62bddb512866d961ac8405e9ce67f
parenta808a8996cf0f3fad8d5d06429142c93bebf79a8 (diff)
downloadsparse-dev-93917f1761f5f1d1eb9ce7a5c867ef6f6e98db38.tar.gz
Add function to show types as strings (instead of just printing them out).
Show (simple) initializers properly.
-rw-r--r--show-parse.c49
-rw-r--r--symbol.h1
2 files changed, 42 insertions, 8 deletions
diff --git a/show-parse.c b/show-parse.c
index a7c9a6a3..21a36691 100644
--- a/show-parse.c
+++ b/show-parse.c
@@ -237,6 +237,17 @@ void show_type(struct symbol *sym)
printf("%s", name.start);
}
+const char *show_typename(struct symbol *sym)
+{
+ static char array[200];
+ struct type_name name;
+
+ name.start = name.end = array+100;
+ do_show_type(sym, &name);
+ *name.end = 0;
+ return name.start;
+}
+
void show_symbol(struct symbol *sym)
{
struct symbol *type;
@@ -289,6 +300,8 @@ static int show_return_stmt(struct statement *stmt)
return 0;
}
+static int show_symbol_init(struct symbol *sym);
+
/*
* Print out a statement
*/
@@ -300,14 +313,14 @@ int show_statement(struct statement *stmt)
case STMT_RETURN:
return show_return_stmt(stmt);
case STMT_COMPOUND: {
+ struct symbol *sym;
struct statement *s;
int last;
- if (stmt->syms) {
- printf("\t");
- show_symbol_list(stmt->syms, "\n\t");
- printf("\n\n");
- }
+ FOR_EACH_PTR(stmt->syms, sym) {
+ show_symbol_init(sym);
+ } END_FOR_EACH_PTR;
+
FOR_EACH_PTR(stmt->stmts, s) {
last = show_statement(s);
} END_FOR_EACH_PTR;
@@ -464,6 +477,11 @@ static int show_call_expression(struct expression *expr)
int fncall, retval;
int framesize;
+ if (!expr->ctype) {
+ warn(expr->pos, "\tcall with no type!");
+ return 0;
+ }
+
framesize = 0;
FOR_EACH_PTR_REVERSE(expr->args, arg) {
int new = show_expression(arg);
@@ -610,13 +628,28 @@ static int show_postop(struct expression *expr)
return show_inc_dec(expr, 1);
}
-static int show_symbol_expr(struct expression *expr)
+static int show_symbol_expr(struct symbol *sym)
{
int new = new_pseudo();
- printf("\tmovi.%d\t\tv%d,$%s\n", BITS_IN_POINTER, new, show_ident(expr->symbol_name));
+ printf("\tmovi.%d\t\tv%d,$%s\n", BITS_IN_POINTER, new, show_ident(sym->ident));
return new;
}
+static int show_symbol_init(struct symbol *sym)
+{
+ struct expression *expr = sym->initializer;
+
+ if (expr) {
+ int val, addr, bits;
+
+ bits = expr->ctype->bit_size;
+ val = show_expression(expr);
+ addr = show_symbol_expr(sym);
+ show_store_gen(bits, val, NULL, addr);
+ }
+ return 0;
+}
+
static int type_is_signed(struct symbol *sym)
{
if (sym->type == SYM_NODE)
@@ -716,7 +749,7 @@ int show_expression(struct expression *expr)
case EXPR_POSTOP:
return show_postop(expr);
case EXPR_SYMBOL:
- return show_symbol_expr(expr);
+ return show_symbol_expr(expr->symbol);
case EXPR_DEREF:
case EXPR_SIZEOF:
warn(expr->pos, "invalid expression after evaluation");
diff --git a/symbol.h b/symbol.h
index c254aa49..b009f1cf 100644
--- a/symbol.h
+++ b/symbol.h
@@ -176,5 +176,6 @@ extern void bind_symbol(struct symbol *, struct ident *, enum namespace);
extern struct symbol *examine_symbol_type(struct symbol *);
extern void examine_simple_symbol_type(struct symbol *);
+extern const char *show_typename(struct symbol *sym);
#endif /* SEMANTIC_H */