foreach (SgBasicBlock *caseBody, newBlocks) { SgStatementPtrList &stmts = caseBody->get_statements(); SgStatement *lastStmt = 0; if (!stmts.empty()) { #if 0 lastStmt = stmts.back(); #else // Skip NullStatements. for (int idx = stmts.size() - 1; idx >= 0; idx--) { if (!isSgNullStatement(stmts[idx])) { lastStmt = stmts[idx]; break; } } #endif } // Insert HtContinue for a fall-through. bool fallsThrough = (lastStmt == 0 || !isSgGotoStatement(lastStmt)); if (fallsThrough) { if (!isSgSwitchStatement(lastStmt) && !isHtThreadControlStmt(lastStmt)) { int target = (casenum == newBlocks.size()) ? -1 : casenum + 1; callStmt = SageBuilder::buildFunctionCallStmt( "HtContinue", SageBuilder::buildVoidType(), SageBuilder::buildExprListExp(SageBuilder::buildEnumVal_nfi(target, enumDecl, stateToName[target])), funcBody); SageInterface::appendStatement(callStmt, caseBody); } SgStatement *brkStmt = SageBuilder::buildBreakStmt(); SageInterface::appendStatement(brkStmt, caseBody); } // Insert HtContinue for each explicit goto. std::vector<SgGotoStatement *> gotos = SageInterface::querySubTree<SgGotoStatement>(caseBody, V_SgGotoStatement); foreach (SgGotoStatement *ngoto, gotos) { int target = labelToState[ngoto->get_label()]; callStmt = SageBuilder::buildFunctionCallStmt( "HtContinue", SageBuilder::buildVoidType(), SageBuilder::buildExprListExp(SageBuilder::buildEnumVal_nfi(target, enumDecl, stateToName[target])), funcBody); SgStatement *brkStmt = SageBuilder::buildBreakStmt(); SageInterface::insertStatementBefore(ngoto, callStmt); SageInterface::replaceStatement(ngoto, brkStmt, true); }
/** Makes a CFG edge, adding appropriate labels. */ void makeEdge(SgAsmInstruction* from, SgAsmInstruction* to, const AuxiliaryInformation* info, vector<CFGEdge>& result) { #if 0 SgAsmNode* fromNode = from.getNode(); unsigned int fromIndex = from.getIndex(); SgAsmNode* toNode = to.getNode(); unsigned int toIndex = to.getIndex(); #if 0 // Exit early if the edge should not exist because of a control flow discontinuity if (fromIndex == 1 && (isSgGotoStatement(fromNode) || isSgBreakStmt(fromNode) || isSgContinueStmt(fromNode))) { return; } if (isSgReturnStmt(fromNode) && toNode == fromNode->get_parent()) { SgReturnStmt* rs = isSgReturnStmt(fromNode); if (fromIndex == 1 || fromIndex == 0 && !rs->get_expression()) return; } if (fromIndex == 1 && isSgSwitchStatement(fromNode) && isSgSwitchStatement(fromNode)->get_body() == toNode) return; #endif #endif // Create the edge result.push_back(CFGEdge(CFGNode(from, info), CFGNode(to, info), info)); }