From 493376d8483562a85a590b9dfa890a27669ca6b4 Mon Sep 17 00:00:00 2001 From: weiyu Date: Mon, 5 Aug 2019 13:15:08 -0700 Subject: [PATCH] fix a bug and print predicate tree in xdot syntax --- funcinst.cc | 2 +- funcnode.cc | 24 ++++++++++++------------ predicate.cc | 7 ++++--- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/funcinst.cc b/funcinst.cc index 3216baee..cecaca7b 100644 --- a/funcinst.cc +++ b/funcinst.cc @@ -69,5 +69,5 @@ bool FuncInst::is_write() const void FuncInst::print() { - model_print("func inst - position: %s, location: %p, type: %d, order: %d\n", position, location, type, order); + model_print("func inst - pos: %s, loc: %p, type: %d,\n", position, location, type); } diff --git a/funcnode.cc b/funcnode.cc index 190dce8e..c24449ff 100644 --- a/funcnode.cc +++ b/funcnode.cc @@ -1,4 +1,6 @@ #include "funcnode.h" +#include +#include "common.h" FuncNode::FuncNode() : predicate_tree_initialized(false), @@ -94,10 +96,11 @@ void FuncNode::update_tree(action_list_t * act_list) inst_list.push_back(func_inst); - if (!predicate_tree_initialized) { +/* if (!predicate_tree_initialized) { model_print("position: %s ", act->get_position()); act->print(); } +*/ if (func_inst->is_read()) { read_inst_list.push_back(func_inst); @@ -106,7 +109,6 @@ void FuncNode::update_tree(action_list_t * act_list) } update_inst_tree(&inst_list); - model_print("line break\n"); init_predicate_tree(&read_inst_list, &read_val_map); } @@ -200,8 +202,6 @@ void FuncNode::init_predicate_tree(func_inst_list_t * inst_list, HashTable loc_inst_map; sllnode *it = inst_list->begin(); - sllnode *prev; - FuncInst * entry_inst = it->getVal(); /* entry instruction has no predicate expression */ @@ -222,13 +220,8 @@ void FuncNode::init_predicate_tree(func_inst_list_t * inst_list, HashTablegetNext(); while (it != NULL) { - prev = it->getPrev(); - FuncInst * curr_inst = it->getVal(); - FuncInst * prev_inst = prev->getVal(); - if ( loc_inst_map.contains(curr_inst->get_location()) ) { -// model_print("new predicate created at location: %p\n", curr_inst->get_location()); Predicate * new_pred1 = new Predicate(curr_inst); new_pred1->add_predicate(EQUALITY, curr_inst->get_location(), true); @@ -238,7 +231,9 @@ void FuncNode::init_predicate_tree(func_inst_list_t * inst_list, HashTableadd_child(new_pred1); curr_pred->add_child(new_pred2); - uint64_t last_read = read_val_map->get(prev_inst); + FuncInst * last_inst = loc_inst_map.get(curr_inst->get_location()); + + uint64_t last_read = read_val_map->get(last_inst); if ( last_read == read_val_map->get(curr_inst) ) curr_pred = new_pred1; else @@ -253,11 +248,15 @@ void FuncNode::init_predicate_tree(func_inst_list_t * inst_list, HashTablegetNext(); } + + model_print("function %s\n", func_name); + print_predicate_tree(); } void FuncNode::print_predicate_tree() { + model_print("digraph function_%s {\n", func_name); HSIterator * it; it = predicate_tree_entry.iterator(); @@ -265,6 +264,7 @@ void FuncNode::print_predicate_tree() Predicate * p = it->next(); p->print_pred_subtree(); } + model_print("}\n"); // end of graph } /* @param tid thread id diff --git a/predicate.cc b/predicate.cc index 4458e8b9..42c63100 100644 --- a/predicate.cc +++ b/predicate.cc @@ -36,7 +36,7 @@ void Predicate::add_child(Predicate * child) void Predicate::print_predicate() { - //model_print("self: %p ", this); + model_print("\"%p\" [shape=box, label=\"%p\n", this, this); func_inst->print(); PredSetIter * it = predicates.iterator(); @@ -45,8 +45,9 @@ void Predicate::print_predicate() while (it->hasNext()) { struct pred_expr * expr = it->next(); - model_print("token: %d, location: %p, value: %d\n", expr->token, expr->location, expr->value); + model_print("predicate: token: %d, location: %p, value: %d\n", expr->token, expr->location, expr->value); } + model_print("\"];\n"); } void Predicate::print_pred_subtree() @@ -54,7 +55,7 @@ void Predicate::print_pred_subtree() print_predicate(); for (uint i = 0; i < children.size(); i++) { Predicate * child = children[i]; -// model_print("parent: %p - ", this); child->print_pred_subtree(); + model_print("\"%p\" -> \"%p\"\n", this, child); } } -- 2.34.1