All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: sparse@chrisli.org
Cc: linux-sparse@vger.kernel.org, linux@rasmusvillemoes.dk,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH 2/4] Add support for show_data()
Date: Sun,  1 Feb 2015 03:19:44 +0100	[thread overview]
Message-ID: <1422757186-8007-3-git-send-email-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <1422757186-8007-1-git-send-email-luc.vanoostenryck@gmail.com>

The purpose of show_data() is to visualize data, more or less
like show_entry() allow to visualize the code.

The support is not complete but at least the basic types are handled.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 linearize.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 linearize.h |  1 +
 2 files changed, 87 insertions(+)

diff --git a/linearize.c b/linearize.c
index c6ada1e8..28beb271 100644
--- a/linearize.c
+++ b/linearize.c
@@ -2220,3 +2220,89 @@ struct entrypoint *linearize_symbol(struct symbol *sym)
 		return linearize_fn(sym, base_type);
 	return NULL;
 }
+
+static void do_indent(int level)
+{
+	while (level--)
+		printf("\t");
+}
+
+static void show_data_expr(struct expression *expr, int indent)
+{
+	struct expression *entry;
+	struct symbol *sym;
+
+	switch (expr->type) {
+	case EXPR_VALUE:
+		printf("%lld", expr->value);
+		break;
+	case EXPR_SYMBOL:
+		sym = expr->symbol;
+		if (sym->initializer && sym->initializer->type == EXPR_STRING)
+			return show_data_expr(sym->initializer, indent);
+		printf("%s", show_ident(expr->symbol_name));
+		break;
+	case EXPR_IMPLIED_CAST:
+		show_data_expr(expr->cast_expression, indent);
+		break;
+	case EXPR_STRING:
+		printf("%s", show_string(expr->string));
+		break;
+	case EXPR_INITIALIZER:
+		printf("{");
+		FOR_EACH_PTR(expr->expr_list, entry) {
+			switch (entry->type) {
+			case EXPR_POS:
+			case EXPR_INDEX:
+			case EXPR_IDENTIFIER:
+				continue;
+			}
+			do_indent(indent+1);
+			show_data_expr(entry, indent+1);
+			printf(",\n");
+		} END_FOR_EACH_PTR(entry);
+		do_indent(indent);
+		printf("}");
+		break;
+	case EXPR_PREOP:
+		if (expr->op == '*') {
+			show_data_expr(expr->unop, indent);
+			break;
+		}
+		// Fall through
+	default:
+		printf("!!unhandled expression type (%d)", expr->type);
+		break;
+	}
+}
+
+void show_data(struct symbol *sym)
+{
+	struct expression *expr = sym->initializer;
+
+	printf("symbol %s:\n", show_ident(sym->ident));
+	printf("\t"); show_type(sym); printf("\n");
+	printf("\tbit_size = %i\n", sym->bit_size);
+	printf("\tval = ");
+	switch (sym->ctype.base_type->type) {
+	case SYM_BASETYPE:
+	case SYM_ENUM:
+		show_data_expr(expr, 0);
+		break;
+	case SYM_PTR:
+		printf("&");
+		show_data_expr(expr, 0);
+		break;
+	case SYM_ARRAY:
+		show_data_expr(expr, 0);
+		break;
+	case SYM_STRUCT:
+	case SYM_UNION:
+		show_data_expr(expr, 1);
+		break;
+	default:
+		printf("\ttype = %d\n", sym->ctype.base_type->type);
+		break;
+	}
+	printf("\n");
+}
diff --git a/linearize.h b/linearize.h
index 61fbd831..7b2d0681 100644
--- a/linearize.h
+++ b/linearize.h
@@ -344,6 +344,7 @@ void show_entry(struct entrypoint *ep);
 const char *show_pseudo(pseudo_t pseudo);
 void show_bb(struct basic_block *bb);
 const char *show_instruction(struct instruction *insn);
+void show_data(struct symbol *sym);
 
 #endif /* LINEARIZE_H */
 
-- 
2.2.0


  parent reply	other threads:[~2015-02-01  2:20 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-30 22:16 Bad interaction between macro expansion and literal concatenation Rasmus Villemoes
2015-01-31  1:23 ` [PATCH] Avoid reuse of string buffer when concatening adjacent string litterals Luc Van Oostenryck
2015-02-03 22:38   ` Rasmus Villemoes
2015-02-04  0:32     ` Luc Van Oostenryck
2015-02-04  3:26       ` Christopher Li
2015-02-04  8:39       ` Rasmus Villemoes
2015-02-04  8:58         ` Rasmus Villemoes
2015-02-04 16:20           ` Christopher Li
2015-02-06 21:52             ` Rasmus Villemoes
2015-02-07  1:30               ` Christopher Li
2015-02-09 21:48                 ` Damien Lespiau
2015-02-04  2:01     ` [PATCH v2] Avoid reusing string buffer when doing string expansion Luc Van Oostenryck
2015-02-04  5:30       ` Christopher Li
2015-02-04  6:22         ` Luc Van Oostenryck
2015-02-04  8:01           ` Christopher Li
2015-02-04 16:38             ` Christopher Li
2015-02-04 23:38               ` Luc Van Oostenryck
2015-02-06 13:58                 ` Christopher Li
2015-02-06 20:32                   ` Rasmus Villemoes
2015-02-04 23:38             ` Luc Van Oostenryck
2015-01-31  5:16 ` Bad interaction between macro expansion and literal concatenation Christopher Li
2015-02-01  2:19   ` [PATCH 0/4] Teach sparse to display data/initial values Luc Van Oostenryck
2015-02-01  2:19     ` [PATCH 1/4] Add support for '-vdata', the equivalent of '-ventry' but for data Luc Van Oostenryck
2015-02-01  2:19     ` Luc Van Oostenryck [this message]
2015-02-02  5:30       ` [PATCH 2/4] Add support for show_data() Christopher Li
2015-02-04  0:50         ` Luc Van Oostenryck
2015-02-01  2:19     ` [PATCH 3/4] Teach sparse to display data/initial values Luc Van Oostenryck
2015-02-01  2:19     ` [PATCH 4/4] Small test/exemple for using '-vdata' Luc Van Oostenryck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1422757186-8007-3-git-send-email-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=sparse@chrisli.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.