Beispiel #1
0
VariableValuePair FIConstAnalysis::analyzeVariableDeclaration(SgVariableDeclaration* decl,VariableIdMapping& varIdMapping) {
    SgNode* initName0=decl->get_traversalSuccessorByIndex(1); // get-InitializedName
    if(initName0) {
        if(SgInitializedName* initName=isSgInitializedName(initName0)) {
            SgSymbol* initDeclVar=initName->search_for_symbol_from_symbol_table();
            assert(initDeclVar);
            VariableId initDeclVarId=varIdMapping.variableId(initDeclVar);
            SgInitializer* initializer=initName->get_initializer();
            SgAssignInitializer* assignInitializer=0;
            if(initializer && (assignInitializer=isSgAssignInitializer(initializer))) {
                if(detailedOutput) cout << "initializer found:"<<endl;
                SgExpression* rhs=assignInitializer->get_operand_i();
                assert(rhs);
                return VariableValuePair(initDeclVarId,analyzeAssignRhs(rhs));
            } else {
                if(detailedOutput) cout << "no initializer (OK)."<<endl;
                return VariableValuePair(initDeclVarId,AType::Top());
            }
        } else {
            cerr << "Error: in declaration (@initializedName) no variable found ... bailing out."<<endl;
            exit(1);
        }
    } else {
        cerr << "Error: in declaration: no variable found ... bailing out."<<endl;
        exit(1);
    }
}
VariableIdSet AnalysisAbstractionLayer::astSubTreeVariables(SgNode* node, VariableIdMapping& vidm) {
  VariableIdSet vset;
  RoseAst ast(node);
  for(RoseAst::iterator i=ast.begin();i!=ast.end();++i) {
    VariableId vid; // default creates intentionally an invalid id.
    if(SgVariableDeclaration* varDecl=isSgVariableDeclaration(*i)) {
      vid=vidm.variableId(varDecl);
    } else if(SgVarRefExp* varRefExp=isSgVarRefExp(*i)) {
      vid=vidm.variableId(varRefExp);
    } else if(SgInitializedName* initName=isSgInitializedName(*i)) {
      vid=vidm.variableId(initName);
    }
    if(vid.isValid())
      vset.insert(vid);
  }
  return vset;
}
Beispiel #3
0
bool FIConstAnalysis::determineVariable(SgNode* node, VariableId& varId, VariableIdMapping& _variableIdMapping) {
    assert(node);
    if(SgVarRefExp* varref=isSgVarRefExp(node)) {
        // found variable
        //assert(_variableIdMapping);
#if 1
        SgSymbol* sym=varref->get_symbol();
        ROSE_ASSERT(sym);
        varId=_variableIdMapping.variableId(sym);
#else
        // MS: to investigate: even with the new var-sym-only case this does not work
        // MS: investigage getSymbolOfVariable
        varId=_variableIdMapping.variableId(varref);
#endif
        return true;
    } else {
        VariableId defaultVarId;
        varId=defaultVarId;
        return false;
    }
}
Beispiel #4
0
void DefUseVarsInfo::addAllArrayElements(SgInitializedName* array_name, VariableIdMapping& vidm, bool def)
{
  assert(array_name);
  VariableId array_var_id = vidm.variableId(array_name);
  SgArrayType* array_type = isSgArrayType(array_name->get_type());
  if (!array_type)
    return;
  int elements = vidm.getArrayElementCount(array_type);
  if (!elements)
    elements = vidm.getArrayDimensionsFromInitializer(isSgAggregateInitializer(array_name->get_initializer()));
  VarsInfo& info = (def ? def_vars_info : use_vars_info);
  VariableIdTypeInfo sgn_type_info_elem = getVariableIdTypeInfo(array_var_id, vidm);
  for (int e = 0; e < elements; e++) {
    VariableId element_id = vidm.variableIdOfArrayElement(array_var_id, e);
    info.first.insert(VariableIdInfo(element_id, sgn_type_info_elem));
  }
}
Beispiel #5
0
VarConstSetMap FIConstAnalysis::computeVarConstValues(SgProject* project, SgFunctionDefinition* mainFunctionRoot, VariableIdMapping& variableIdMapping) {
    VarConstSetMap varConstIntMap;

    VariableIdSet varIdSet=AnalysisAbstractionLayer::usedVariablesInsideFunctions(project,&variableIdMapping);

    // initialize map such that it is resized to number of variables of interest
    for(VariableIdSet::iterator i=varIdSet.begin(); i!=varIdSet.end(); ++i) {
        set<CppCapsuleConstIntLattice> emptySet;
        varConstIntMap[*i]=emptySet;
    }
    cout<<"STATUS: Initialized const map for "<<varConstIntMap.size()<< " variables."<<endl;

    cout << "STATUS: Number of global variables: ";
    list<SgVariableDeclaration*> globalVars=SgNodeHelper::listOfGlobalVars(project);
    cout << globalVars.size()<<endl;
    VariableIdSet setOfUsedVars=AnalysisAbstractionLayer::usedVariablesInsideFunctions(project,&variableIdMapping);
    cout << "STATUS: Number of used variables: "<<setOfUsedVars.size()<<endl;
#if 0
    int filteredVars=0;
    set<CppCapsuleConstIntLattice> emptySet;
    for(list<SgVariableDeclaration*>::iterator i=globalVars.begin(); i!=globalVars.end(); ++i) {
        VariableId globalVarId=variableIdMapping.variableId(*i);
        if(setOfUsedVars.find(globalVarId)!=setOfUsedVars.end()) {
            VariableValuePair p=analyzeVariableDeclaration(*i,variableIdMapping);
            ConstIntLattice varValue=p.varValue;
            varConstIntMap[p.varId]=emptySet; // create mapping
            varConstIntMap[p.varId].insert(CppCapsuleConstIntLattice(varValue));
            variablesOfInterest.insert(p.varId);
            //set<CppCapsuleConstIntLattice>& myset=varConstIntMap[p.varId];
        } else {
            filteredVars++;
        }
    }
    cout << "STATUS: Number of filtered variables for initial state: "<<filteredVars<<endl;
#endif
    variablesOfInterest=setOfUsedVars;
    if(mainFunctionRoot!=0) {
        determineVarConstValueSet(mainFunctionRoot,variableIdMapping,varConstIntMap);
    } else {
        // compute value-sets for entire program (need to cover all functions without inlining)
        determineVarConstValueSet(project,variableIdMapping,varConstIntMap);
    }
    return varConstIntMap;
}