Skip to content

Commit

Permalink
fix write and read err
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonZhongZexin authored and JasonZhongZexin committed Jul 16, 2023
1 parent b47a66f commit 567cb9a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 25 deletions.
2 changes: 1 addition & 1 deletion svf/include/MemoryModel/PointerAnalysisImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class BVDataPTAImpl : public PointerAnalysis
/// Interface for analysis result storage on filesystem.
//@{
virtual void writeToFile(const std::string& filename);
virtual void writeObjVarToFile(const std::string& filename, std::fstream& f);
virtual void writeObjVarToFile(const std::string& filename);
virtual bool readFromFile(const std::string& filename);
//@}

Expand Down
2 changes: 2 additions & 0 deletions svf/include/WPA/Andersen.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ class AndersenBase: public WPAConstraintSolver, public BVDataPTAImpl

NodeBS redundantGepNodes;

void solveConstraints();

/// Statistics
//@{
static u32_t numOfProcessedAddr; /// Number of processed Addr edge
Expand Down
24 changes: 18 additions & 6 deletions svf/lib/MemoryModel/PointerAnalysisImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,17 @@ void BVDataPTAImpl::remapPointsToSets(void)
getPTDataTy()->remapAllPts();
}

void BVDataPTAImpl::writeObjVarToFile(const string& filename, std::fstream& f)
void BVDataPTAImpl::writeObjVarToFile(const string& filename)
{
outs() << "Storing ObjVar to '" << filename << "'...";

error_code err;
std::fstream f(filename.c_str(), std::ios_base::out);
if (!f.good())
{
outs() << " error opening file for writing!\n";
return;
}

// Write BaseNodes insensitivity to file
NodeBS NodeIDs;
for (auto it = pag->begin(), ie = pag->end(); it != ie; ++it)
Expand All @@ -178,6 +185,14 @@ void BVDataPTAImpl::writeObjVarToFile(const string& filename, std::fstream& f)

f << "------\n";

f.close();
if (f.good())
{
outs() << "\n";
return;
}


}

/*!
Expand All @@ -191,16 +206,13 @@ void BVDataPTAImpl::writeToFile(const string& filename)
outs() << "Storing pointer analysis results to '" << filename << "'...";

error_code err;
std::fstream f(filename.c_str(), std::ios_base::out);
std::fstream f(filename.c_str(), std::ios_base::app);
if (!f.good())
{
outs() << " error opening file for writing!\n";
return;
}

if (!Options::WriteAnder().empty())
this->writeObjVarToFile(filename, f);

// Write analysis results to file
for (auto it = pag->begin(), ie = pag->end(); it != ie; ++it)
{
Expand Down
41 changes: 23 additions & 18 deletions svf/lib/WPA/Andersen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,9 @@ void AndersenBase::finalize()
BVDataPTAImpl::finalize();
}

/*!
* Andersen analysis
*/
void AndersenBase::analyze()
void AndersenBase::solveConstraints()
{
/// Initialization for the Solver
initialize();

bool readResultsFromFile = false;
if(!Options::ReadAnder().empty())
{
readResultsFromFile = this->readFromFile(Options::ReadAnder());
// Finalize the analysis
PointerAnalysis::finalize();
}

if(!readResultsFromFile)
{
// Start solving constraints
// Start solving constraints
DBOUT(DGENERAL, outs() << SVFUtil::pasMsg("Start Solving Constraints\n"));

bool limitTimerSet = SVFUtil::startAnalysisLimitTimer(Options::AnderTimeLimit());
Expand All @@ -141,9 +125,30 @@ void AndersenBase::analyze()
SVFUtil::stopAnalysisLimitTimer(limitTimerSet);

DBOUT(DGENERAL, outs() << SVFUtil::pasMsg("Finish Solving Constraints\n"));
}

/*!
* Andersen analysis
*/
void AndersenBase::analyze()
{
/// Initialization for the Solver
initialize();

bool readResultsFromFile = false;
if(!Options::ReadAnder().empty())
{
readResultsFromFile = this->readFromFile(Options::ReadAnder());
// Finalize the analysis
PointerAnalysis::finalize();
}

if (!Options::WriteAnder().empty())
this->writeObjVarToFile(Options::WriteAnder());

if(!readResultsFromFile)
solveConstraints();

if (!Options::WriteAnder().empty())
{
this->writeToFile(Options::WriteAnder());
Expand Down

0 comments on commit 567cb9a

Please sign in to comment.