33#include "Util/config.h"
75 std::string bcFilePath;
77 if (path ==
"SVF_DIR")
79 const char* svfdir =
getenv(
"SVF_DIR");
85 if (!bcFilePath.empty() && bcFilePath.back() !=
'/')
86 bcFilePath.push_back(
'/');
88 bcFilePath.append(SVF_BUILD_TYPE
"-build/lib/extapi.bc");
90 else if (path ==
"npm root")
95 "command -v npm >/dev/null 2>&1 && npm root"
98 if (bcFilePath.empty())
101 if (!bcFilePath.empty() && bcFilePath.back() !=
'/')
102 bcFilePath.push_back(
'/');
104 bcFilePath.append(
"SVF/lib/extapi.bc");
121 std::vector<std::string> candidatePaths;
144 candidatePaths.push_back(SVF_BUILD_DIR
"/lib/extapi.bc");
165 candidatePaths.push_back(npmPath.empty() ?
"npm root unavailable" : npmPath);
172 std::string dir = soPath.substr(0, soPath.find_last_of(
'/'));
173 std::string candidate = dir +
"/extapi.bc";
180 candidatePaths.push_back(candidate);
185 SVFUtil::errs() <<
"ERROR: Failed to locate \"extapi.bc\". Tried the following candidate paths:" << std::endl;
186 for (
const auto& path : candidatePaths)
190 SVFUtil::errs() <<
"To override the default locations for \"extapi.bc\", you can:" << std::endl
191 <<
"\t1. Use the command line argument \"-extapi=path/to/extapi.bc\"" << std::endl
192 <<
"\t2. Use the \"setExtBcPath()\" function *BEFORE* calling \"buildSVFModule()\"" << std::endl
193 <<
"\t3. Override the paths in \"include/SVF/Util/config.h\" (WARNING: will be overwritten "
194 <<
"when rebuilding SVF (generated by CMakeLists.txt))" << std::endl;
201 assert(fun &&
"Null FunObjVar* pointer");
207 assert(fun &&
"Null FunObjVar* pointer");
211 for (
const std::string& annotation : it->second)
212 if (annotation.find(funcAnnotation) != std::string::npos)
221 assert(fun &&
"Null FunObjVar* pointer");
225 for (
const std::string& annotation : it->second)
226 if (annotation.find(funcAnnotation) != std::string::npos)
234 assert(fun &&
"Null FunObjVar* pointer");
273 assert(!allocArg.empty() &&
"Not an alloc call via argument or incorrect extern function annotation!");
276 for (
char c : allocArg)
281 assert(!
number.empty() &&
"Incorrect naming convention for svf external functions(ALLOC_HEAP_ARG + number)?");
292 assert(F &&
"Null FunObjVar* pointer");
static std::string getFilePath(const std::string &path)
const char *const const double number
bool is_alloc_stack_ret(const FunObjVar *F)
bool is_arg_alloc(const FunObjVar *F)
bool is_memcpy(const FunObjVar *F)
std::string getExtBcPath()
static std::string extBcPath
s32_t get_alloc_arg_pos(const FunObjVar *F)
static ExtAPI * getExtAPI()
bool is_ext(const FunObjVar *funObjVar)
std::string getExtFuncAnnotation(const FunObjVar *fun, const std::string &funcAnnotation)
bool is_realloc(const FunObjVar *F)
Map< const FunObjVar *, std::vector< std::string > > funObjVar2Annotations
void setExtFuncAnnotations(const FunObjVar *fun, const std::vector< std::string > &funcAnnotations)
static bool setExtBcPath(const std::string &path)
bool hasExtFuncAnnotation(const FunObjVar *fun, const std::string &funcAnnotation)
bool is_alloc(const FunObjVar *F)
const std::vector< std::string > & getExtFuncAnnotations(const FunObjVar *fun)
bool is_memset(const FunObjVar *F)
bool isDeclaration() const
static const Option< std::string > ExtAPIPath
char * getenv(const char *name)
std::ostream & errs()
Overwrite llvm::errs().
bool fileExists(const std::string &path)
Check whether a file exists at the given path.
std::string getCurrentSOPath()
Return the absolute path of the current module/executable.
std::string getStdoutFromCommand(const std::string &command)
Execute a shell command and capture its stdout output.