Static Value-Flow Analysis
Functions
llvm2svf.cpp File Reference
#include "SVF-LLVM/SVFIRBuilder.h"
#include "Util/CommandLine.h"
#include "Util/Options.h"
#include "SVFIR/SVFFileSystem.h"
#include <iostream>
#include <string>

Go to the source code of this file.

Functions

std::string replaceExtension (const std::string &path)
 
int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 54 of file llvm2svf.cpp.

55 {
56  auto moduleNameVec = OptionBase::parseOptions(
57  argc, argv, "llvm2svf", "[options] <input-bitcode...>");
58 
59  if (Options::WriteAnder() == "ir_annotator")
60  {
61  LLVMModuleSet::preProcessBCs(moduleNameVec);
62  }
63 
64  SVFModule* svfModule = LLVMModuleSet::buildSVFModule(moduleNameVec);
65  const std::string jsonPath = replaceExtension(moduleNameVec.front());
66  // PAG is borrowed from a unique_ptr, so we don't need to delete it.
67  const SVFIR* pag = SVFIRBuilder(svfModule).build();
68 
69  SVFIRWriter::writeJsonToPath(pag, jsonPath);
70  SVFUtil::outs() << "SVF IR is written to '" << jsonPath << "'\n";
71  LLVMModuleSet::releaseLLVMModuleSet();
72  return 0;
73 }
const char *const string
Definition: cJSON.h:172
static std::vector< std::string > parseOptions(int argc, char *argv[], std::string description, std::string callFormat)
Definition: CommandLine.h:75
virtual SVFIR * build()
Start building SVFIR here.
std::string replaceExtension(const std::string &path)
Definition: llvm2svf.cpp:42
std::ostream & outs()
Overwrite llvm::outs()
Definition: SVFUtil.h:50

◆ replaceExtension()

std::string replaceExtension ( const std::string path)

Definition at line 42 of file llvm2svf.cpp.

43 {
44  size_t pos = path.rfind('.');
45  if (pos == std::string::npos ||
46  (path.substr(pos) != ".bc" && path.substr(pos) != ".ll"))
47  {
48  SVFUtil::errs() << "Error: expect file with extension .bc or .ll\n";
49  exit(EXIT_FAILURE);
50  }
51  return path.substr(0, pos) + ".svf.json";
52 }
std::ostream & errs()
Overwrite llvm::errs()
Definition: SVFUtil.h:56