[PATCH] show_label: add (and use) show_label()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add an helper to display labels.
This allow us to:
*) abstract away the details of how to display them
*) gracefully handle abnormal cases of a null label.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 linearize.c  | 41 +++++++++++++++++++++++++----------------
 linearize.h  |  1 +
 test-unssa.c |  2 +-
 3 files changed, 27 insertions(+), 17 deletions(-)

diff --git a/linearize.c b/linearize.c
index 58da7ceb3..a0cce0373 100644
--- a/linearize.c
+++ b/linearize.c
@@ -95,6 +95,18 @@ static inline int regno(pseudo_t n)
 	return retval;
 }
 
+const char *show_label(struct basic_block *bb)
+{
+	static int n;
+	static char buffer[4][16];
+	char *buf = buffer[3 & ++n];
+
+	if (!bb)
+		return ".L???";
+	snprintf(buf, 64, ".L%u", bb->nr);
+	return buf;
+}
+
 const char *show_pseudo(pseudo_t pseudo)
 {
 	static int n;
@@ -117,7 +129,7 @@ const char *show_pseudo(pseudo_t pseudo)
 			break;
 		}
 		if (sym->bb_target) {
-			snprintf(buf, 64, ".L%u", sym->bb_target->nr);
+			snprintf(buf, 64, "%s", show_label(sym->bb_target));
 			break;
 		}
 		if (sym->ident) {
@@ -325,11 +337,11 @@ const char *show_instruction(struct instruction *insn)
 		break;
 
 	case OP_CBR:
-		buf += sprintf(buf, "%s, .L%u, .L%u", show_pseudo(insn->cond), insn->bb_true->nr, insn->bb_false->nr);
+		buf += sprintf(buf, "%s, %s, %s", show_pseudo(insn->cond), show_label(insn->bb_true), show_label(insn->bb_false));
 		break;
 
 	case OP_BR:
-		buf += sprintf(buf, ".L%u", insn->bb_true->nr);
+		buf += sprintf(buf, "%s", show_label(insn->bb_true));
 		break;
 
 	case OP_SYMADDR:
@@ -339,7 +351,6 @@ const char *show_instruction(struct instruction *insn)
 
 	case OP_SETVAL: {
 		struct expression *expr = insn->val;
-		struct symbol *sym;
 		buf += sprintf(buf, "%s <- ", show_pseudo(insn->target));
 
 		if (!expr) {
@@ -361,9 +372,7 @@ const char *show_instruction(struct instruction *insn)
 			buf += sprintf(buf, "%s", show_ident(expr->symbol->ident));
 			break;
 		case EXPR_LABEL:
-			sym = expr->symbol;
-			if (sym->bb_target)
-				buf += sprintf(buf, ".L%u", sym->bb_target->nr);
+			buf += sprintf(buf, "%s", show_label(expr->symbol->bb_target));
 			break;
 		default:
 			buf += sprintf(buf, "SETVAL EXPR TYPE %d", expr->type);
@@ -380,11 +389,11 @@ const char *show_instruction(struct instruction *insn)
 		buf += sprintf(buf, "%s", show_pseudo(insn->cond));
 		FOR_EACH_PTR(insn->multijmp_list, jmp) {
 			if (jmp->begin == jmp->end)
-				buf += sprintf(buf, ", %lld -> .L%u", jmp->begin, jmp->target->nr);
+				buf += sprintf(buf, ", %lld -> %s", jmp->begin, show_label(jmp->target));
 			else if (jmp->begin < jmp->end)
-				buf += sprintf(buf, ", %lld ... %lld -> .L%u", jmp->begin, jmp->end, jmp->target->nr);
+				buf += sprintf(buf, ", %lld ... %lld -> %s", jmp->begin, jmp->end, show_label(jmp->target));
 			else
-				buf += sprintf(buf, ", default -> .L%u", jmp->target->nr);
+				buf += sprintf(buf, ", default -> %s", show_label(jmp->target));
 		} END_FOR_EACH_PTR(jmp);
 		break;
 	}
@@ -392,7 +401,7 @@ const char *show_instruction(struct instruction *insn)
 		struct multijmp *jmp;
 		buf += sprintf(buf, "%s", show_pseudo(insn->src));
 		FOR_EACH_PTR(insn->multijmp_list, jmp) {
-			buf += sprintf(buf, ", .L%u", jmp->target->nr);
+			buf += sprintf(buf, ", %s", show_label(jmp->target));
 		} END_FOR_EACH_PTR(jmp);
 		break;
 	}
@@ -497,7 +506,7 @@ void show_bb(struct basic_block *bb)
 {
 	struct instruction *insn;
 
-	printf(".L%u:\n", bb->nr);
+	printf("%s:\n", show_label(bb));
 	if (verbose) {
 		pseudo_t needs, defines;
 		printf("%s:%d\n", stream_name(bb->pos.stream), bb->pos.line);
@@ -505,7 +514,7 @@ void show_bb(struct basic_block *bb)
 		FOR_EACH_PTR(bb->needs, needs) {
 			struct instruction *def = needs->def;
 			if (def->opcode != OP_PHI) {
-				printf("  **uses %s (from .L%u)**\n", show_pseudo(needs), def->bb->nr);
+				printf("  **uses %s (from %s)**\n", show_pseudo(needs), show_label(def->bb));
 			} else {
 				pseudo_t phi;
 				const char *sep = " ";
@@ -513,7 +522,7 @@ void show_bb(struct basic_block *bb)
 				FOR_EACH_PTR(def->phi_list, phi) {
 					if (phi == VOID)
 						continue;
-					printf("%s(%s:.L%u)", sep, show_pseudo(phi), phi->def->bb->nr);
+					printf("%s(%s:%s)", sep, show_pseudo(phi), show_label(phi->def->bb));
 					sep = ", ";
 				} END_FOR_EACH_PTR(phi);		
 				printf(")**\n");
@@ -527,7 +536,7 @@ void show_bb(struct basic_block *bb)
 		if (bb->parents) {
 			struct basic_block *from;
 			FOR_EACH_PTR(bb->parents, from) {
-				printf("  **from .L%u (%s:%d:%d)**\n", from->nr,
+				printf("  **from %s (%s:%d:%d)**\n", show_label(from),
 					stream_name(from->pos.stream), from->pos.line, from->pos.pos);
 			} END_FOR_EACH_PTR(from);
 		}
@@ -535,7 +544,7 @@ void show_bb(struct basic_block *bb)
 		if (bb->children) {
 			struct basic_block *to;
 			FOR_EACH_PTR(bb->children, to) {
-				printf("  **to .L%u (%s:%d:%d)**\n", to->nr,
+				printf("  **to %s (%s:%d:%d)**\n", show_label(to),
 					stream_name(to->pos.stream), to->pos.line, to->pos.pos);
 			} END_FOR_EACH_PTR(to);
 		}
diff --git a/linearize.h b/linearize.h
index 79c0c09b5..57c9173f1 100644
--- a/linearize.h
+++ b/linearize.h
@@ -367,6 +367,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);
+const char *show_label(struct basic_block *bb);
 
 #endif /* LINEARIZE_H */
 
diff --git a/test-unssa.c b/test-unssa.c
index 80752f432..57959be2b 100644
--- a/test-unssa.c
+++ b/test-unssa.c
@@ -12,7 +12,7 @@ static void output_bb(struct basic_block *bb, unsigned long generation)
 	struct instruction *insn;
 
 	bb->generation = generation;
-	printf(".L%u\n", bb->nr);
+	printf("%s\n", show_label(bb));
 
 	FOR_EACH_PTR(bb->insns, insn) {
 		if (!insn->bb)
-- 
2.16.2

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux