void InstrumentationFunction::buildDeclaration(SgProject* project) { // ***************************************************** // Create the functionDeclaration // ***************************************************** Sg_File_Info * file_info = Sg_File_Info::generateDefaultFileInfoForTransformationNode(); SgType *function_return_type = new SgTypeVoid(); type = new SgFunctionType(function_return_type, false); SgFunctionDeclaration *functionDeclaration = new SgFunctionDeclaration(file_info, name, type); // ******************************************************************** // Create the InitializedName for a parameter within the parameter list // ******************************************************************** /* SgName var1_name = "textString"; SgTypeChar * var1_type = new SgTypeChar(); SgPointerType *pointer_type = new SgPointerType(var1_type); SgInitializer * var1_initializer = NULL; SgInitializedName *var1_init_name = new SgInitializedName(var1_name, pointer_type, var1_initializer, NULL); // Insert argument in function parameter list ROSE_ASSERT(functionDeclaration != NULL); ROSE_ASSERT(functionDeclaration->get_parameterList() != NULL); ROSE_ASSERT(functionDeclaration->get_parameterList() != NULL); functionDeclaration->get_parameterList()->append_arg(var1_init_name); */ SgSourceFile* sourceFile = isSgSourceFile(project->get_fileList()[0]); ROSE_ASSERT(sourceFile != NULL); SgGlobal* globalScope = sourceFile->get_globalScope(); ROSE_ASSERT(globalScope != NULL); // Set the parent node in the AST (this could be done by the AstPostProcessing functionDeclaration->set_parent(globalScope); // Set the scope explicitly (since it could be different from the parent?) // This can't be done by the AstPostProcessing (unless we relax some constraints) functionDeclaration->set_scope(globalScope); // If it is not a forward declaration then the unparser will skip the ";" at the end (need to fix this better) functionDeclaration->setForward(); ROSE_ASSERT(functionDeclaration->isForward() == true); // Mark function as extern "C" functionDeclaration->get_declarationModifier().get_storageModifier().setExtern(); functionDeclaration->set_linkage("C"); // This mechanism could be improved! // Add function declaration to global scope globalScope->prepend_declaration(functionDeclaration); symbol = new SgFunctionSymbol(functionDeclaration); // All any modifications to be fixed up (parents etc) // AstPostProcessing(project); // This is not allowed and should be fixed! AstPostProcessing(globalScope); }
SgFunctionSymbol* SimpleInstrumentation::buildNewFunctionDeclaration ( SgStatement* statementLocation, SgFunctionType* previousFunctionType ) { // ***************************************************** // Create the functionDeclaration // ***************************************************** // Must mark the newly built node to be a part of a transformation so that it will be unparsed! Sg_File_Info * file_info = new Sg_File_Info(); ROSE_ASSERT(file_info != NULL); file_info->set_isPartOfTransformation(true); SgName function_name = "contest_call"; ROSE_ASSERT(previousFunctionType != NULL); SgFunctionDeclaration* functionDeclaration = new SgFunctionDeclaration(file_info, function_name, previousFunctionType); ROSE_ASSERT(functionDeclaration != NULL); ROSE_ASSERT(functionDeclaration->get_parameterList() != NULL); // ******************************************************************** // Create the InitializedName for a parameter within the parameter list // ******************************************************************** SgTypePtrList & argList = previousFunctionType->get_arguments(); SgTypePtrList::iterator i = argList.begin(); while ( i != argList.end() ) { SgName var_name = ""; SgInitializer* var_initializer = NULL; SgInitializedName *var_init_name = new SgInitializedName(var_name, *i, var_initializer, NULL); functionDeclaration->get_parameterList()->append_arg(var_init_name); i++; } // Add any additional function arguments here! Make sure that the function type is consistant. // Get the scope SgScopeStatement* scope = statementLocation->get_scope(); // Set the parent node in the AST (this could be done by the AstPostProcessing functionDeclaration->set_parent(scope); // Set the scope explicitly (since it could be different from the parent?) functionDeclaration->set_scope(scope); // If it is not a forward declaration then the unparser will skip the ";" at the end (need to fix this better) functionDeclaration->setForward(); ROSE_ASSERT(functionDeclaration->isForward() == true); // Mark function as extern "C" functionDeclaration->get_declarationModifier().get_storageModifier().setExtern(); functionDeclaration->set_linkage("C"); // This mechanism could be improved! bool inFront = true; SgGlobal* globalScope = TransformationSupport::getGlobalScope(statementLocation); SgFunctionDeclaration* functionDeclarationInGlobalScope = TransformationSupport::getFunctionDeclaration(statementLocation); ROSE_ASSERT(globalScope != NULL); ROSE_ASSERT(functionDeclarationInGlobalScope != NULL); globalScope->insert_statement(functionDeclarationInGlobalScope,functionDeclaration,inFront); SgFunctionSymbol* functionSymbol = new SgFunctionSymbol(functionDeclaration); ROSE_ASSERT(functionSymbol != NULL); ROSE_ASSERT(functionSymbol->get_type() != NULL); return functionSymbol; }