|
From: <sv...@va...> - 2017-03-22 23:40:52
|
Author: iraisr
Date: Wed Mar 22 23:40:44 2017
New Revision: 3324
Log:
Support pretty printing IRStmt's with proper indentation depth.
Modified:
branches/VEX_JIT_HACKS/priv/guest_generic_bb_to_IR.c
branches/VEX_JIT_HACKS/priv/guest_x86_toIR.c
branches/VEX_JIT_HACKS/priv/ir_defs.c
branches/VEX_JIT_HACKS/pub/libvex_ir.h
branches/VEX_JIT_HACKS/useful/test_main.c
Modified: branches/VEX_JIT_HACKS/priv/guest_generic_bb_to_IR.c
==============================================================================
--- branches/VEX_JIT_HACKS/priv/guest_generic_bb_to_IR.c (original)
+++ branches/VEX_JIT_HACKS/priv/guest_generic_bb_to_IR.c Wed Mar 22 23:40:44 2017
@@ -392,10 +392,9 @@
imark->Ist.IMark.len = dres.len;
/* Print the resulting IR, if needed. */
- if (vex_traceflags & VEX_TRACE_FE) {
+ if (debug_print) {
for (i = first_stmt_idx; i < irsb->stmts->stmts_used; i++) {
- vex_printf(" ");
- ppIRStmt(irsb->stmts->stmts[i]);
+ ppIRStmt_wrk(irsb->stmts->stmts[i], 3);
vex_printf("\n");
}
}
@@ -753,7 +752,7 @@
Print it if necessary.*/
vassert(irsb->next != NULL);
if (debug_print) {
- vex_printf(" ");
+ vex_printf(" ");
vex_printf( "PUT(%d) = ", irsb->offsIP);
ppIRExpr( irsb->next );
vex_printf( "; exit-");
Modified: branches/VEX_JIT_HACKS/priv/guest_x86_toIR.c
==============================================================================
--- branches/VEX_JIT_HACKS/priv/guest_x86_toIR.c (original)
+++ branches/VEX_JIT_HACKS/priv/guest_x86_toIR.c Wed Mar 22 23:40:44 2017
@@ -15475,8 +15475,7 @@
callback_opaque,
delta, archinfo, abiinfo, sigill_diag_IN );
for (i = x1; i < x2; i++) {
- vex_printf("\t\t");
- ppIRStmt(irsb_IN->stmts->stmts[i]);
+ ppIRStmt_wrk(irsb_IN->stmts->stmts[i], 4);
vex_printf("\n");
}
/* Failure of this assertion is serious and denotes a bug in
Modified: branches/VEX_JIT_HACKS/priv/ir_defs.c
==============================================================================
--- branches/VEX_JIT_HACKS/priv/ir_defs.c (original)
+++ branches/VEX_JIT_HACKS/priv/ir_defs.c Wed Mar 22 23:40:44 2017
@@ -1579,17 +1579,30 @@
vex_printf(")");
}
-void ppIRPhiVec(const IRPhiVec* phis)
+static void print_depth(UInt depth) {
+ for (UInt i = 0; i < depth; i++) {
+ vex_printf(" ");
+ }
+}
+
+static void ppIRPhiVec_wrk(const IRPhiVec* phis, UInt depth)
{
for (UInt i = 0; i < phis->phis_used; i++) {
- vex_printf(" ");
+ print_depth(depth);
ppIRPhi(phis->phis[i]);
vex_printf("\n");
}
}
-void ppIRStmt ( const IRStmt* s )
+void ppIRPhiVec(const IRPhiVec* phis)
{
+ ppIRPhiVec_wrk(phis, 0);
+}
+
+void ppIRStmt_wrk(const IRStmt* s, UInt depth)
+{
+ print_depth(depth);
+
if (!s) {
vex_printf("!!! IRStmt* which is NULL !!!");
return;
@@ -1674,13 +1687,15 @@
vex_printf("if (");
ppIRExpr(s->Ist.IfThenElse.cond);
vex_printf(") then {\n");
- ppIRStmtVec(s->Ist.IfThenElse.then_leg); // TODO-JIT: indent properly
+ ppIRStmtVec_wrk(s->Ist.IfThenElse.then_leg, depth + 1);
+ print_depth(depth);
vex_printf("} else {\n");
- ppIRStmtVec(s->Ist.IfThenElse.else_leg); // TODO-JIT: indent properly
+ ppIRStmtVec_wrk(s->Ist.IfThenElse.else_leg, depth + 1);
+ print_depth(depth);
vex_printf("}\n");
IRPhiVec* phi_nodes = s->Ist.IfThenElse.phi_nodes;
if (phi_nodes != NULL) {
- ppIRPhiVec(phi_nodes);
+ ppIRPhiVec_wrk(phi_nodes, depth);
}
break;
default:
@@ -1688,11 +1703,16 @@
}
}
-void ppIRTypeEnv ( const IRTypeEnv* env )
+void ppIRStmt(const IRStmt* s)
+{
+ ppIRStmt_wrk(s, 0);
+}
+
+static void ppIRTypeEnv_wrk(const IRTypeEnv* env, UInt depth)
{
for (UInt i = 0; i < env->types_used; i++) {
if (i % 8 == 0)
- vex_printf( " ");
+ print_depth(depth);
IRTemp temp = mkIRTemp(env->id, i);
ppIRTemp(temp);
vex_printf("=");
@@ -1706,23 +1726,34 @@
vex_printf( "\n");
}
-/* TODO-JIT: account for indentation */
-void ppIRStmtVec(const IRStmtVec* stmts)
+void ppIRTypeEnv(const IRTypeEnv* env)
+{
+ ppIRTypeEnv_wrk(env, 0);
+}
+
+void ppIRStmtVec_wrk(const IRStmtVec* stmts, UInt depth)
{
- ppIRTypeEnv(stmts->tyenv);
+ ppIRTypeEnv_wrk(stmts->tyenv, depth);
vex_printf("\n");
for (UInt i = 0; i < stmts->stmts_used; i++) {
- vex_printf( " ");
- ppIRStmt(stmts->stmts[i]);
+ ppIRStmt_wrk(stmts->stmts[i], depth);
vex_printf("\n");
}
}
+void ppIRStmtVec(const IRStmtVec* stmts)
+{
+ ppIRStmtVec_wrk(stmts, 0);
+}
+
void ppIRSB ( const IRSB* bb )
{
+ UInt depth = 0;
+
vex_printf("IRSB {\n");
- ppIRStmtVec(bb->stmts);
- vex_printf( " PUT(%d) = ", bb->offsIP );
+ ppIRStmtVec_wrk(bb->stmts, depth + 1);
+ print_depth(depth + 1);
+ vex_printf("PUT(%d) = ", bb->offsIP);
ppIRExpr( bb->next );
vex_printf( "; exit-");
ppIRJumpKind(bb->jumpkind);
@@ -4053,7 +4084,7 @@
ppIRSB(bb);
if (stmt) {
vex_printf("\nIN STATEMENT:\n\n");
- ppIRStmt(stmt);
+ ppIRStmt_wrk(stmt, 1);
}
vex_printf("\n\nERROR = %s\n\n", what );
vpanic("sanityCheckFail: exiting due to bad IR");
Modified: branches/VEX_JIT_HACKS/pub/libvex_ir.h
==============================================================================
--- branches/VEX_JIT_HACKS/pub/libvex_ir.h (original)
+++ branches/VEX_JIT_HACKS/pub/libvex_ir.h Wed Mar 22 23:40:44 2017
@@ -2822,6 +2822,7 @@
IRStmtVec;
extern void ppIRStmtVec(const IRStmtVec*);
+extern void ppIRStmtVec_wrk(const IRStmtVec*, UInt depth);
/* Allocates an empty IRStmtVec with an invalid IRTyEnvID.
Such an IRStmtVec needs to have a valid IRTyEnvId - get it from
@@ -3155,6 +3156,7 @@
/* Pretty-print an IRStmt. */
extern void ppIRStmt ( const IRStmt* );
+extern void ppIRStmt_wrk(const IRStmt*, UInt depth);
/* ------------------ Basic Blocks ------------------ */
Modified: branches/VEX_JIT_HACKS/useful/test_main.c
==============================================================================
--- branches/VEX_JIT_HACKS/useful/test_main.c (original)
+++ branches/VEX_JIT_HACKS/useful/test_main.c Wed Mar 22 23:40:44 2017
@@ -2715,8 +2715,7 @@
if (verboze) {
for (UInt j = first_stmt; j < bb->stmts->stmts_used; j++) {
- VG_(printf)(" ");
- ppIRStmt(bb->stmts->stmts[j]);
+ ppIRStmt_wrk(bb->stmts->stmts[j], 1);
VG_(printf)("\n");
}
VG_(printf)("\n");
@@ -2739,8 +2738,7 @@
if (verboze) {
for (UInt j = first_stmt; j < bb->stmts->stmts_used; j++) {
- VG_(printf)(" ");
- ppIRStmt(bb->stmts->stmts[j]);
+ ppIRStmt_wrk(bb->stmts->stmts[j], 1);
VG_(printf)("\n");
}
VG_(printf)("\n");
|