class DotGraph { Graph (String outputFile); long getIndex (TreeNode * n); void addNode (long index, string name); void addEdge (long fromIndex, toIndex, string label); void dump (void); } #define IF_HAS_EDGE_ADD(NODE,NAME,LABEL) if ((NODE)->hasEdgeName((NAME))) { \\ child = (NODE)->edgeName ((NAME)); \\long childIndex = graph->getIndex (child); \\graph->addEdge (nodeIndex, childIndex, "LABEL"); \\toVisit.push_front (child); \\} XAstReader *reader = new XAstReader; list < TreeNode * >*TreeNodeList; TreeNodeList = reader->readlist (GxlInputFile); // Visit one node for time for (TNLIter = TreeNodeList->begin (); (TNLIter != TreeNodeList->end ()); TNLIter++) { TreeNode *node = *TNLIter; if ((node->getCode () == FUNCTION_DECL) && node->hasEdgeName (BODY_EDGE)) { DotGraph graph = Graph ("function" + a2b::long2string (node->getId ()) + ".dot"); list < TreeNode * >toVisit; toVisit.push_front (node->edgeName (BODY_EDGE)); while (!toVisit.empty ()) { TreeNode *n = toVisit.pop_front (); long nodeIndex = graph->getIndex (n); string code = a2b::NodeCode2string (n->getCode ()); TreeNode *child; graph->addNode (nodeIndex, code); switch (n->getCode ()) { case LABEL_DECL: case BREAK_STMT: case CONTINUE_STMT: case SCOPE_STMT: case DECL_STMT: case ASM_STMT: case CASE_LABEL: case LABEL_STMT: case RETURN_STMT: // Do Nothing break; case EXPR_STMT: // Loop expr ? if (n->hasEdgeName (EXPRESSION_EDGE)) { child = n->edgeName (EXPRESSION_EDGE); if (child->getCode () == LOOP_EXPR) { long childIndex = graph->getIndex (child); graph->addEdge (nodeIndex, childIndex "next_stmt"); } } break; case GOTO_STMT: IF_HAS_EDGE_ADD (n, DESTINATION_EDGE, destination) break; case IF_STMT: IF_HAS_EDGE_ADD (n, THEN_EDGE, then) IF_HAS_EDGE_ADD (n, ELSE0_EDGE, else )break; case SWITCH_STMT: IF_HAS_EDGE_ADD (n, BODY_EDGE, body) break; case FOR_STMT: IF_HAS_EDGE_ADD (n, BODY_EDGE, body) break; case WHILE_STMT: IF_HAS_EDGE_ADD (n, BODY_EDGE, body) break; case DO_STMT: IF_HAS_EDGE_ADD (n, BODY_EDGE, body) break; case COMPOUND_STMT: IF_HAS_EDGE_ADD (n, BODY_EDGE, body) break; } if (n->getCode () == LOOP_EXPR) { IF_HAS_EDGE_ADD (n, BODY_EDGE, body)} IF_HAS_EDGE_ADD (n, NEXT_STMT_EDGE, next)} graph.dump (); } }