00001 #ifndef VERTEX_PROPERTY_WRITER_H_INCLUDED_
00002 #define VERTEX_PROPERTY_WRITER_H_INCLUDED_
00003
00004 #include "rose.h"
00005
00006 #include "segment_graph.h"
00007 #include "../internal_representation/design.h"
00008 #include "../tools/variable_helper.h"
00009 namespace risc {
00010
00011 namespace sg {
00012
00013 struct VertexPropertyWriter {
00014
00015 static bool print_read_write_access;
00016
00017 VertexPropertyWriter(Graph& graph);
00018
00019 template <class Vertex>
00020 void operator() (std::ostream &out, Vertex v)
00021 {
00022 if(!PSG_MODE) out << "[shape=record,label=\"{ Segment ID: " << graph_[v].id_;
00023
00024
00025 else {
00026 if(graph_[v].is_fake_segment){
00027 if(graph_[v].fake_segment_function_call_name!="")
00028 out << "[shape=record,style=dashed,label=\"{ Node ID: " << graph_[v].node_id_;
00029 else
00030 out << "[shape=record,style=dotted,label=\"{ Node ID: " << graph_[v].node_id_;
00031 }
00032 else out << "[shape=record,style=bold,label=\"{ Node ID: " << graph_[v].node_id_;
00033 }
00034 if(graph_[v].boundary_node_) {
00035 std::string unparsed_stmt = graph_[v].boundary_node_->unparseToString();
00036
00037 replace_escape_characters(unparsed_stmt);
00038
00039 std::string temp =
00040 Rose::StringUtility::stripPathFromFileName(
00041 graph_[v].boundary_node_->get_file_info()->get_raw_filename());
00042
00043 out << " (" << temp << ":"
00044 << graph_[v].boundary_node_->get_file_info()->get_line() << ")";
00045
00046
00047
00048 const SgLocatedNode *located_node =
00049 isSgLocatedNode(graph_[v].boundary_node_);
00050
00051 AttachedPreprocessingInfoType *comments =
00052 const_cast<SgLocatedNode*>(
00053 located_node)->getAttachedPreprocessingInfo();
00054
00055 if(comments != NULL) {
00056
00057
00058
00059
00060 for(AttachedPreprocessingInfoType::iterator
00061 i = comments->begin();
00062 i != comments->end();
00063 i++) {
00064
00065 if(located_node->get_file_info()->get_line()
00066 == (*i)->getLineNumber()) {
00067
00068
00069 std::string str = (*i)->getString().substr(2,
00070 (*i)->getString().length()-2);
00071
00072
00073 str.erase(std::remove(str.begin(), str.end(), '\n'), str.end());
00074 out << " " << str;
00075 }
00076 }
00077 }
00078 } else {
00079
00080 SgNode *first_node = NULL;
00081 if(graph_[v].expressions_.size() != 0) {
00082
00083 first_node = graph_[v].expressions_.front().node_;
00084
00085 if(first_node) {
00086 SgFunctionDefinition *func_def =
00087 SageInterface::getEnclosingFunctionDefinition(first_node);
00088
00089 if(func_def) {
00090
00091 SgClassDefinition *class_def =
00092 SageInterface::getEnclosingClassDefinition(func_def);
00093
00094 if(class_def) {
00095
00096 out << " [" << SageInterface::get_name(class_def)
00097 << "::" << SageInterface::get_name(func_def) << "]";
00098 }
00099 }
00100 }
00101 }
00102
00103
00104 }
00105
00106 if(!graph_[v].pcp_.path_.empty()) {
00107
00108 std::string temp(graph_[v].pcp_.path_.front()->unparseToString());
00109 replace_escape_characters(temp);
00110 out << " -- " << temp;
00111 }
00112
00113 if(!VertexPropertyWriter::print_read_write_access) {
00114 for(Segment::Expressions::iterator
00115 expr_iter = graph_[v].expressions_.begin();
00116 expr_iter != graph_[v].expressions_.end();
00117 expr_iter++) {
00118
00119
00120 std::string unparsed_stmt = expr_iter->node_->unparseToString();
00121
00122 replace_escape_characters(unparsed_stmt);
00123
00124 std::string temp =
00125 Rose::StringUtility::stripPathFromFileName(
00126 (*expr_iter).node_->get_file_info()->get_raw_filename());
00127
00128
00129
00130 out << "|" << temp << ":"
00131
00132 << expr_iter->node_->get_file_info()->get_line() << " ";
00133
00134 if(!expr_iter->pcp_.path_.empty()) {
00135 out << " [ ";
00136
00137 for(std::list<SgFunctionCallExp*>::iterator
00138 port_call_iter = expr_iter->pcp_.path_.begin();
00139 port_call_iter != expr_iter->pcp_.path_.end();
00140 port_call_iter++) {
00141
00142 std::string temp((*port_call_iter)->unparseToString());
00143 replace_escape_characters(temp);
00144
00145 std::list<SgFunctionCallExp*>::iterator temp2 = port_call_iter;
00146 out << temp;
00147 temp2++;
00148 if(temp2 != expr_iter->pcp_.path_.end()) {
00149 out << " -> ";
00150 }
00151
00152 }
00153 out << " ] ";
00154 }
00155
00156 out << unparsed_stmt << "\\l";
00157
00158 }
00159 } else {
00160
00161 if(PSG_MODE){
00162 bool w = true;
00163
00164 std::vector<std::string> write_var_list;
00165 std::vector<std::string> read_var_list;
00166 std::vector<std::string> rw_var_list;
00167 std::map<std::string,int> var_written;
00168 std::map<std::string,int> var_read;
00169 std::map<std::string,int> var_rw;
00170
00171
00172 for(std::list<SymbolWithPath>::iterator
00173 var_symbol_iter = graph_[v].write_variables_.begin();
00174 var_symbol_iter != graph_[v].write_variables_.end();
00175 var_symbol_iter++)
00176 {
00177
00178 if(tools::is_local_variable(var_symbol_iter->symbol_)){
00179 continue;
00180 }
00181 std::string var_name = (((var_symbol_iter->symbol_)->get_declaration())->get_qualified_name()).getString ();
00182 if(var_written[var_name] == 0){
00183 write_var_list.push_back(var_name);
00184 var_written[var_name]=1;
00185 }
00186 }
00187
00188 for(std::list<SymbolWithPath>::iterator
00189 var_symbol_iter = graph_[v].read_variables_.begin();
00190 var_symbol_iter != graph_[v].read_variables_.end();
00191 var_symbol_iter++)
00192 {
00193
00194 if(tools::is_local_variable(var_symbol_iter->symbol_)){
00195 continue;
00196 }
00197 std::string var_name = (((var_symbol_iter->symbol_)->get_declaration())->get_qualified_name()).getString ();
00198 if(var_read[var_name] == 0){
00199 read_var_list.push_back(var_name);
00200 var_read[var_name]=1;
00201 }
00202 }
00203
00204 for(std::vector<std::string>::iterator
00205 iter = write_var_list.begin();
00206 iter != write_var_list.end();
00207 iter++)
00208 {
00209
00210 if(var_read[*iter]>0){
00211 rw_var_list.push_back(*iter);
00212 var_rw[*iter]=1;
00213 }
00214 }
00215
00216 for(std::vector<std::string>::iterator
00217 iter = rw_var_list.begin();
00218 iter != rw_var_list.end();
00219 iter++)
00220 {
00221 if(w) out << "\" + \n \"";
00222 out << "| (RW) "
00223 << *iter;
00224 out << "\\l";
00225 }
00226
00227 for(std::vector<std::string>::iterator
00228 iter = write_var_list.begin();
00229 iter != write_var_list.end();
00230 iter++)
00231 {
00232 if(var_rw[*iter]==1) continue;
00233
00234 if(w) out << "\" + \n \"";
00235 out << "| (W) "
00236 << *iter;
00237 out << "\\l";
00238 }
00239
00240 for(std::vector<std::string>::iterator
00241 iter = read_var_list.begin();
00242 iter != read_var_list.end();
00243 iter++)
00244 {
00245 if(var_rw[*iter]==1) continue;
00246
00247 if(w) out << "\" + \n \"";
00248 out << "| (R) "
00249 << *iter;
00250 out << "\\l";
00251 }
00252
00253
00254 std::map <std::string,int> event_notified;
00255 std::map <std::string,int> event_waited;
00256
00257
00258 for(std::vector<SgVariableSymbol*>::iterator iter = graph_[v].wait_event_symbols.begin();
00259 iter != graph_[v].wait_event_symbols.end();
00260 iter++)
00261 {
00262 if( event_waited[((*iter)->get_declaration()->get_qualified_name()).getString ()] >0) continue;
00263 event_waited[((*iter)->get_declaration()->get_qualified_name()).getString ()]=1;
00264 if(w) out << "\" + \n \"";
00265 out << "| (wait_event) " << ((*iter)->get_declaration()->get_qualified_name()).getString ();
00266 out << "\\l";
00267 w=true;
00268 }
00269
00270 for(std::vector<SgVariableSymbol*>::iterator iter = graph_[v].notify_event_symbols.begin();
00271 iter != graph_[v].notify_event_symbols.end();
00272 iter++)
00273 {
00274 if( event_notified[((*iter)->get_declaration()->get_qualified_name()).getString ()] >0) continue;
00275 event_notified[((*iter)->get_declaration()->get_qualified_name()).getString ()]=1;
00276 if(w) out << "\" + \n \"";
00277
00278 out << "| (notify_event) " << ((*iter)->get_declaration()->get_qualified_name()).getString ();
00279 out << "\\l";
00280 w=true;
00281 }
00282 if(graph_[v].is_fake_segment){
00283 if(graph_[v].fake_segment_function_call_name!=""){
00284 out << "\" + \n \"";
00285 out << "| "
00286 << graph_[v].fake_segment_function_call_name;
00287 out << "\\l";
00288 }
00289 }
00290 }
00291 else{
00292
00293
00294 for(std::list<SymbolWithPath>::iterator
00295 var_symbol_iter = graph_[v].write_variables_.begin();
00296 var_symbol_iter != graph_[v].write_variables_.end();
00297 var_symbol_iter++) {
00298
00299 out << "| (W) "
00300 << SageInterface::get_name(var_symbol_iter->symbol_).erase(
00301 SageInterface::get_name(var_symbol_iter->symbol_).length() - 8);
00302
00303 if(!var_symbol_iter->pcp_.path_.empty()) {
00304 out << " [ ";
00305
00306 for(std::list<SgFunctionCallExp*>::iterator
00307 port_call_iter = var_symbol_iter->pcp_.path_.begin();
00308 port_call_iter != var_symbol_iter->pcp_.path_.end();
00309 port_call_iter++) {
00310
00311 std::string temp((*port_call_iter)->unparseToString());
00312 replace_escape_characters(temp);
00313
00314 std::list<SgFunctionCallExp*>::iterator temp2 = port_call_iter;
00315 out << temp;
00316 temp2++;
00317 if(temp2 != var_symbol_iter->pcp_.path_.end()) {
00318 out << " -> ";
00319 }
00320
00321 }
00322 out << " ] ";
00323 }
00324
00325 out << "\\l";
00326 }
00327
00328
00329
00330 for(std::list<SymbolWithPath>::iterator
00331 var_symbol_iter = graph_[v].read_variables_.begin();
00332 var_symbol_iter != graph_[v].read_variables_.end();
00333 var_symbol_iter++) {
00334
00335 out << "| (R) "
00336 << SageInterface::get_name(var_symbol_iter->symbol_).erase(
00337 SageInterface::get_name(var_symbol_iter->symbol_).length() - 8);
00338
00339 if(!var_symbol_iter->pcp_.path_.empty()) {
00340 out << " [ ";
00341
00342 for(std::list<SgFunctionCallExp*>::iterator
00343 port_call_iter = var_symbol_iter->pcp_.path_.begin();
00344 port_call_iter != var_symbol_iter->pcp_.path_.end();
00345 port_call_iter++) {
00346
00347 std::string temp((*port_call_iter)->unparseToString());
00348 replace_escape_characters(temp);
00349
00350 std::list<SgFunctionCallExp*>::iterator temp2 = port_call_iter;
00351 out << temp;
00352 temp2++;
00353 if(temp2 != var_symbol_iter->pcp_.path_.end()) {
00354 out << " -> ";
00355 }
00356
00357 }
00358 out << " ] ";
00359 }
00360
00361 out << "\\l";
00362
00363 }
00364
00365 }
00366
00367 }
00368
00369 out << "}\"]";
00370
00371 if(PSG_MODE){
00372 out << "\n /*\n";
00373 if(graph_[v].starting_segment_for_function!="")
00374 out << " starting segment for function: " << graph_[v].starting_segment_for_function << "\n";
00375 if(graph_[v].leaving_segment_for_function!="")
00376 out << " leaving segment for function: " << graph_[v].leaving_segment_for_function << "\n";
00377
00378 if(graph_[v].is_fake_segment){
00379 if(graph_[v].fake_segment_function_call_name!="")
00380 out << " Partial Segment Type A, contains function: " << graph_[v].fake_segment_function_call_name << "\n";
00381 else
00382 out << " Partial Segment Type B, will be merged into other segments during integration\n";
00383
00384 }
00385
00386 if(graph_[v].is_simulation_process_segment)
00387 out << " starting segment for simulation process";
00388 if(graph_[v].module_name != "")
00389 out << " in module " << graph_[v].module_name <<"\n";
00390 if(graph_[v].deref_pointer_read_)
00391 out << " contains pointer read\n";
00392 if(graph_[v].deref_pointer_write_)
00393 out << " contains pointer write\n";
00394 out << "\n */\n";
00395 }
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421 }
00422
00427 void replace_escape_characters(std::string &unparsed_stmt);
00428
00429 Graph& graph_;
00430
00431 friend std::ostream& operator<< (std::ostream &out,
00432 const VertexPropertyWriter &vpw)
00433 {
00434 return out;
00435 }
00436 };
00437
00438 };
00439
00440 };
00441
00442 #endif
00443
00444