Exemplo n.º 1
0
          virtual void visit(SgNode* astNode)
             {
            // Note that the SgAsmInterpretation will be visited before the instructions (functions).
               SgAsmInterpretation* asmGlobalScope = isSgAsmInterpretation(astNode);
               if (asmGlobalScope != NULL)
                  {
                    globalScopeAnalysisAttribute = dynamic_cast<GlobalScopeAnalysisAttribute*>(asmGlobalScope->getAttribute("GlobalScopeAnalysisAttribute"));
                    ROSE_ASSERT(globalScopeAnalysisAttribute != NULL);
                  }

            // Handle functions as they are visited in the AST.

            // DQ (8/30/2013): This type was renamed and so the original function is not available (changed).
            // SgAsmFunctionDeclaration* asmFunction = isSgAsmFunctionDeclaration(astNode);
               SgAsmFunctionDeclaration* asmFunction = isSgAsmFunction(astNode);
               if (asmFunction != NULL)
                  {
                 // This was initalized from the traversal constructor.
                    ROSE_ASSERT(project != NULL);

                 // This was initalized from earlier in the traversal (preorder traversal is assumed).
                    ROSE_ASSERT(globalScopeAnalysisAttribute != NULL);
#if 0
                    string name = "function_" + StringUtility::numberToString(counter);
#else
                    string name = asmFunction->get_name();
                    if (name == "")
                       {
                         name = "unnamed_function_" + StringUtility::numberToString(counter);
                       }
#endif
                    printf ("name = %s kind = %u \n",name.c_str(),asmFunction->get_function_kind());

                 // Add a collection of predefined comments for common functions
                    addGenericCommentsAboutFunctions(asmFunction);

                    if (globalScopeAnalysisAttribute->isVirtualMemberFunction(asmFunction) == true)
                       {
                         printf ("Found a virtual function = %p \n",(void*)asmFunction->get_address());

                      // Rename the function.
                         name = "virtual_member_function_" + StringUtility::numberToString(counter);
                         MemberFunctionAnalysisAttribute* functionAnalysisAttribute = new MemberFunctionAnalysisAttribute(name,asmFunction,project);
                         ROSE_ASSERT(functionAnalysisAttribute != NULL);

                      // Add it to the AST (so it can be found later in another pass over the AST)
                         asmFunction->addNewAttribute("FunctionAnalysisAttribute",functionAnalysisAttribute);
#if 0
                         printf ("Exiting as a test! \n");
                         ROSE_ASSERT(false);
#endif
                       }
                      else
                       {
                         FunctionAnalysisAttribute* functionAnalysisAttribute = new FunctionAnalysisAttribute(name,asmFunction,project);
                         ROSE_ASSERT(functionAnalysisAttribute != NULL);

                      // Add it to the AST (so it can be found later in another pass over the AST)
                         asmFunction->addNewAttribute("FunctionAnalysisAttribute",functionAnalysisAttribute);

                      // Add the function to global scope
                         globalScopeAnalysisAttribute->associatedDeclarationList.push_back(asmFunction);
                       }

                    counter++;
                  }
             }