void process() { int i; for (i = 0; i < fdefList.size(); i++) { SgFunctionDefinition* fndef = fdefList.at(i); if (fndef == NULL) { return; } std::string functionName = fndef->get_declaration()->get_name().getString(); SgFunctionDeclaration *f = fndef->get_declaration(); if (!debugHooks) { SgNode *body = fndef->get_body(); // Move any preprocessing info before the function to a new // null statement preceding the function. AttachedPreprocessingInfoType save_buf; SageInterface::cutPreprocessingInfo(f, PreprocessingInfo::before, save_buf) ; if (save_buf.size()) { SgVariableDeclaration *dummy = SageBuilder::buildVariableDeclaration( "___htc_dummy_decl_for_preproc_info", SageBuilder::buildIntType(), 0, f->get_scope()); SageInterface::setExtern(dummy); SageInterface::insertStatementBefore(f, dummy); SageInterface::pastePreprocessingInfo( dummy, PreprocessingInfo::before, save_buf); } SageInterface::addTextForUnparser( f, "\n#if 0", AstUnparseAttribute::e_before); std::string CapFnName = Capitalize(functionName); std::string before_body = "\n#endif\n"; std::string macro_name = "HTC_KEEP_MODULE_" + Upper(functionName); before_body += "#ifdef " + macro_name + "\n"; before_body += "#include \"Ht.h\"\n"; before_body += "#include \"Pers" + CapFnName + ".h\"\n"; before_body += "#ifndef __htc_GW_write_addr\n"; before_body += "#define __htc_GW_write_addr(v,a) v.write_addr(a)\n"; before_body += "#endif\n"; before_body += "#ifndef __htc_GW_write_addr2\n"; before_body += "#define __htc_GW_write_addr2(v,a,b) v.write_addr(a,b)\n"; before_body += "#endif\n"; before_body += "void CPers" + CapFnName + "::Pers" + CapFnName + "()\n"; SageInterface::addTextForUnparser(body, before_body, AstUnparseAttribute::e_before); std::string after_body = "\n#endif /* " + macro_name + " */\n"; SageInterface::addTextForUnparser(body, after_body, AstUnparseAttribute::e_after); // Write the _src.cpp file generate_src_cpp_file(fndef, CapFnName, macro_name); } } for (i = 0; i < fdeclList.size(); i++) { SgFunctionDeclaration *fdecl = fdeclList.at(i); if (!debugHooks && fdecl && fdecl->get_definingDeclaration() != fdecl) { // Move any preprocessing info before the function to a new // null statement preceding the function. AttachedPreprocessingInfoType save_buf; SageInterface::cutPreprocessingInfo(fdecl, PreprocessingInfo::before, save_buf) ; if (save_buf.size()) { SgVariableDeclaration *dummy2 = SageBuilder::buildVariableDeclaration( "___htc_dummy_decl2_for_preproc_info", SageBuilder::buildIntType(), 0, fdecl->get_scope()); SageInterface::setExtern(dummy2); SageInterface::insertStatementBefore(fdecl, dummy2); SageInterface::pastePreprocessingInfo( dummy2, PreprocessingInfo::before, save_buf); } SageInterface::addTextForUnparser(fdecl, "\n/* ", AstUnparseAttribute::e_before); SageInterface::addTextForUnparser(fdecl, " */", AstUnparseAttribute::e_after); // comment out function prototypes // fdecl->setCompilerGenerated(); // fdecl->unsetOutputInCodeGeneration(); } } }
void SimpleInstrumentation::visit ( SgNode* astNode ) { switch(astNode->variantT()) { case V_SgFunctionCallExp: { SgFunctionCallExp *functionCallExp = isSgFunctionCallExp(astNode); SgExpression *function = functionCallExp->get_function(); ROSE_ASSERT(function); switch (function->variantT()) { case V_SgFunctionRefExp: { SgFunctionRefExp *functionRefExp = isSgFunctionRefExp(function); SgFunctionSymbol *symbol = functionRefExp->get_symbol(); ROSE_ASSERT(symbol != NULL); SgFunctionDeclaration *functionDeclaration = symbol->get_declaration(); ROSE_ASSERT(functionDeclaration != NULL); if (symbol == functionSymbol) { // Now we know that we have found the correct function call // (even in the presence of overloading or other forms of hidding) // Now fixup the symbol and type of the SgFunctionRefExp object to // reflect the new function to be called (after this we still have to // fixup the argument list in the SgFunctionCallExp. // We only want to build the decalration once (and insert it into the global scope) // after that we save the symbol and reuse it. if (newFunctionSymbol == NULL) { SgFunctionType* originalFunctionType = isSgFunctionType(functionSymbol->get_type()); ROSE_ASSERT(originalFunctionType != NULL); newFunctionSymbol = buildNewFunctionDeclaration (TransformationSupport::getStatement(astNode),originalFunctionType); } ROSE_ASSERT(newFunctionSymbol != NULL); ROSE_ASSERT(newFunctionSymbol->get_type() != NULL); functionRefExp->set_symbol(newFunctionSymbol); } break; } default: cerr<<"warning: unrecognized variant: "<<function->class_name(); } break; } case V_SgFunctionDeclaration: { SgFunctionDeclaration* functionDeclaration = isSgFunctionDeclaration(astNode); string functionName = functionDeclaration->get_name().str(); if (functionName == "send") { SgFunctionType *functionType = functionDeclaration->get_type(); ROSE_ASSERT(functionType != NULL); bool foundFunction = false; if (functionType->get_return_type()->unparseToString() == "ssize_t") { SgTypePtrList & argumentList = functionType->get_arguments(); SgTypePtrList::iterator i = argumentList.begin(); if ( (*i++)->unparseToString() == "int" ) if ( (*i++)->unparseToString() == "const void *" ) if ( (*i++)->unparseToString() == "size_t" ) if ( (*i++)->unparseToString() == "int" ) foundFunction = true; } if (foundFunction == true) { // Now get the sysmbol using functionType SgScopeStatement *scope = functionDeclaration->get_scope(); ROSE_ASSERT(scope != NULL); functionSymbol = scope->lookup_function_symbol (functionName,functionType); } } break; } default: { // No other special cases } } }