本文整理汇总了C++中llvm::sys::Path::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ Path::isValid方法的具体用法?C++ Path::isValid怎么用?C++ Path::isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类llvm::sys::Path
的用法示例。
在下文中一共展示了Path::isValid方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runExecutable
int runExecutable()
{
assert(!gExePath.isEmpty());
assert(gExePath.isValid());
// build arguments
std::vector<const char*> args;
// args[0] should be the name of the executable
args.push_back(gExePath.c_str());
// Skip first argument to -run; it's a D source file.
for (size_t i = 1, length = opts::runargs.size(); i < length; i++)
{
args.push_back(opts::runargs[i].c_str());
}
// terminate args list
args.push_back(NULL);
// try to call linker!!!
std::string errstr;
int status = llvm::sys::Program::ExecuteAndWait(gExePath, &args[0], NULL, NULL, 0,0, &errstr);
if (status < 0)
{
error("program received signal %d (%s)", -status, strsignal(-status));
return -status;
}
if (!errstr.empty())
{
error("failed to execute program");
if (!errstr.empty())
error("error message: %s", errstr.c_str());
fatal();
}
return status;
}
示例2: deleteExecutable
void deleteExecutable()
{
if (!gExePath.isEmpty())
{
assert(gExePath.isValid());
assert(!gExePath.isDirectory());
gExePath.eraseFromDisk(false);
}
}
示例3: deleteExecutable
void deleteExecutable()
{
if (!gExePath.isEmpty())
{
assert(gExePath.isValid());
bool is_directory;
assert(!(!llvm::sys::fs::is_directory(gExePath.str(), is_directory) && is_directory));
gExePath.eraseFromDisk(false);
}
}
示例4: runExecutable
int runExecutable()
{
assert(!gExePath.isEmpty());
assert(gExePath.isValid());
// Run executable
int status = ExecuteToolAndWait(gExePath, opts::runargs, !quiet || global.params.verbose);
if (status < 0)
{
#if defined(_MSC_VER)
error("program received signal %d", -status);
#else
error("program received signal %d (%s)", -status, strsignal(-status));
#endif
return -status;
}
return status;
}
示例5: linkExecutable
int linkExecutable(const char* argv0)
{
Logger::println("*** Linking executable ***");
// error string
std::string errstr;
// find the llvm-ld program
llvm::sys::Path ldpath = llvm::sys::Program::FindProgramByName("llvm-ld");
if (ldpath.isEmpty())
{
ldpath.set("llvm-ld");
}
// build arguments
std::vector<const char*> args;
// first the program name ??
args.push_back("llvm-ld");
// output filename
std::string exestr;
if (global.params.exefile)
{ // explicit
exestr = global.params.exefile;
}
else
{ // inferred
// try root module name
if (Module::rootModule)
exestr = Module::rootModule->toChars();
else
exestr = "a.out";
}
if (global.params.os == OSWindows && !(exestr.substr(exestr.length()-4) == ".exe"))
exestr.append(".exe");
std::string outopt = "-o=" + exestr;
args.push_back(outopt.c_str());
// set the global gExePath
gExePath.set(exestr);
assert(gExePath.isValid());
// create path to exe
llvm::sys::Path exedir(llvm::sys::path::parent_path(gExePath.str()));
if (!llvm::sys::fs::exists(exedir.str()))
{
exedir.createDirectoryOnDisk(true, &errstr);
if (!errstr.empty())
{
error("failed to create path to linking output: %s\n%s", exedir.c_str(), errstr.c_str());
fatal();
}
}
// strip debug info
if (!global.params.symdebug)
args.push_back("-strip-debug");
// optimization level
if (!optimize())
args.push_back("-disable-opt");
else
{
switch(optLevel())
{
case 0:
args.push_back("-disable-opt");
break;
case 1:
args.push_back("-globaldce");
args.push_back("-disable-opt");
args.push_back("-globaldce");
args.push_back("-mem2reg");
case 2:
case 3:
case 4:
case 5:
// use default optimization
break;
default:
assert(0);
}
}
// inlining
if (!(global.params.useInline || doInline()))
{
args.push_back("-disable-inlining");
}
// additional linker switches
for (unsigned i = 0; i < global.params.linkswitches->dim; i++)
{
char *p = (char *)global.params.linkswitches->data[i];
args.push_back(p);
}
// native please
//.........这里部分代码省略.........
示例6: linkObjToBinary
int linkObjToBinary(bool sharedLib)
{
Logger::println("*** Linking executable ***");
// error string
std::string errstr;
// find gcc for linking
llvm::sys::Path gcc = getGcc();
// get a string version for argv[0]
const char* gccStr = gcc.c_str();
// build arguments
std::vector<const char*> args;
// first the program name ??
args.push_back(gccStr);
// object files
for (unsigned i = 0; i < global.params.objfiles->dim; i++)
{
char *p = (char *)global.params.objfiles->data[i];
args.push_back(p);
}
// output filename
std::string output;
if (!sharedLib && global.params.exefile)
{ // explicit
output = global.params.exefile;
}
else if (sharedLib && global.params.objname)
{ // explicit
output = global.params.objname;
}
else
{ // inferred
// try root module name
if (Module::rootModule)
output = Module::rootModule->toChars();
else if (global.params.objfiles->dim)
output = FileName::removeExt((char*)global.params.objfiles->data[0]);
else
output = "a.out";
if (sharedLib) {
std::string libExt = std::string(".") + global.dll_ext;
if (!endsWith(output, libExt))
{
if (global.params.os != OSWindows)
output = "lib" + output + libExt;
else
output.append(libExt);
}
args.push_back("-shared");
} else if (global.params.os == OSWindows && !endsWith(output, ".exe")) {
output.append(".exe");
}
}
args.push_back("-o");
args.push_back(output.c_str());
// set the global gExePath
gExePath.set(output);
assert(gExePath.isValid());
// create path to exe
llvm::sys::Path exedir(llvm::sys::path::parent_path(gExePath.str()));
if (!exedir.empty() && !llvm::sys::fs::exists(exedir.str()))
{
exedir.createDirectoryOnDisk(true, &errstr);
if (!errstr.empty())
{
error("failed to create path to linking output: %s\n%s", exedir.c_str(), errstr.c_str());
fatal();
}
}
// additional linker switches
for (unsigned i = 0; i < global.params.linkswitches->dim; i++)
{
char *p = (char *)global.params.linkswitches->data[i];
args.push_back("-Xlinker");
args.push_back(p);
}
// user libs
for (unsigned i = 0; i < global.params.libfiles->dim; i++)
{
char *p = (char *)global.params.libfiles->data[i];
args.push_back(p);
}
// default libs
bool addSoname = false;
switch(global.params.os) {
case OSLinux:
addSoname = true;
args.push_back("-lrt");
//.........这里部分代码省略.........
示例7: linkObjToBinaryWin
int linkObjToBinaryWin(bool sharedLib)
{
Logger::println("*** Linking executable ***");
// find link.exe for linking
llvm::sys::Path tool = getLink();
// build arguments
std::vector<std::string> args;
// be verbose if requested
if (!global.params.verbose)
args.push_back("/NOLOGO");
// specify that the image will contain a table of safe exception handlers (32bit only)
if (!global.params.is64bit)
args.push_back("/SAFESEH");
// mark executable to be compatible with Windows Data Execution Prevention feature
args.push_back("/NXCOMPAT");
// use address space layout randomization (ASLR) feature
args.push_back("/DYNAMICBASE");
// because of a LLVM bug
args.push_back("/LARGEADDRESSAWARE:NO");
// specify creation of DLL
if (sharedLib)
args.push_back("/DLL");
// output filename
std::string output;
if (!sharedLib && global.params.exefile)
{ // explicit
output = global.params.exefile;
}
else if (sharedLib && global.params.objname)
{ // explicit
output = global.params.objname;
}
else
{ // inferred
// try root module name
if (Module::rootModule)
output = Module::rootModule->toChars();
else if (global.params.objfiles->dim)
output = FileName::removeExt(static_cast<char*>(global.params.objfiles->data[0]));
else
output = "a.out";
if (sharedLib) {
std::string libExt = std::string(".") + global.dll_ext;
if (!endsWith(output, libExt))
{
if (global.params.os != OSWindows)
output = "lib" + output + libExt;
else
output.append(libExt);
}
} else if (global.params.os == OSWindows && !endsWith(output, ".exe")) {
output.append(".exe");
}
}
args.push_back("/OUT:" + output);
// object files
for (unsigned i = 0; i < global.params.objfiles->dim; i++)
{
char *p = static_cast<char *>(global.params.objfiles->data[i]);
args.push_back(p);
}
// user libs
for (unsigned i = 0; i < global.params.libfiles->dim; i++)
{
char *p = static_cast<char *>(global.params.libfiles->data[i]);
args.push_back(p);
}
// set the global gExePath
gExePath.set(output);
assert(gExePath.isValid());
// create path to exe
CreateDirectoryOnDisk(gExePath.str());
// additional linker switches
for (unsigned i = 0; i < global.params.linkswitches->dim; i++)
{
static const std::string LIBPATH("-L");
static const std::string LIB("-l");
std::string str(static_cast<char *>(global.params.linkswitches->data[i]));
if (str.length() > 2)
{
if (std::equal(LIBPATH.begin(), LIBPATH.end(), str.begin()))
str = "/LIBPATH:" + str.substr(2);
else if (std::equal(LIB.begin(), LIB.end(), str.begin()))
{
str = str.substr(2) + ".lib";
//.........这里部分代码省略.........
示例8: linkObjToBinaryGcc
int linkObjToBinaryGcc(bool sharedLib)
{
Logger::println("*** Linking executable ***");
// find gcc for linking
llvm::sys::Path gcc = getGcc();
// build arguments
std::vector<std::string> args;
// object files
for (unsigned i = 0; i < global.params.objfiles->dim; i++)
{
char *p = static_cast<char *>(global.params.objfiles->data[i]);
args.push_back(p);
}
// user libs
for (unsigned i = 0; i < global.params.libfiles->dim; i++)
{
char *p = static_cast<char *>(global.params.libfiles->data[i]);
args.push_back(p);
}
// output filename
std::string output;
if (!sharedLib && global.params.exefile)
{ // explicit
output = global.params.exefile;
}
else if (sharedLib && global.params.objname)
{ // explicit
output = global.params.objname;
}
else
{ // inferred
// try root module name
if (Module::rootModule)
output = Module::rootModule->toChars();
else if (global.params.objfiles->dim)
output = FileName::removeExt(static_cast<char*>(global.params.objfiles->data[0]));
else
output = "a.out";
if (sharedLib) {
std::string libExt = std::string(".") + global.dll_ext;
if (!endsWith(output, libExt))
{
if (global.params.os != OSWindows)
output = "lib" + output + libExt;
else
output.append(libExt);
}
} else if (global.params.os == OSWindows && !endsWith(output, ".exe")) {
output.append(".exe");
}
}
if (sharedLib)
args.push_back("-shared");
args.push_back("-o");
args.push_back(output);
// set the global gExePath
gExePath.set(output);
assert(gExePath.isValid());
// create path to exe
CreateDirectoryOnDisk(gExePath.str());
// additional linker switches
for (unsigned i = 0; i < global.params.linkswitches->dim; i++)
{
char *p = static_cast<char *>(global.params.linkswitches->data[i]);
args.push_back("-Xlinker");
args.push_back(p);
}
// default libs
bool addSoname = false;
switch(global.params.os) {
case OSLinux:
addSoname = true;
args.push_back("-lrt");
// fallthrough
case OSMacOSX:
args.push_back("-ldl");
// fallthrough
case OSFreeBSD:
addSoname = true;
args.push_back("-lpthread");
args.push_back("-lm");
break;
case OSSolaris:
args.push_back("-lm");
args.push_back("-lumem");
// solaris TODO
break;
//.........这里部分代码省略.........
示例9: linkObjToExecutable
int linkObjToExecutable(const char* argv0)
{
Logger::println("*** Linking executable ***");
// error string
std::string errstr;
// find gcc for linking
llvm::sys::Path gcc = getGcc();
// get a string version for argv[0]
const char* gccStr = gcc.c_str();
// build arguments
std::vector<const char*> args;
// first the program name ??
args.push_back(gccStr);
// object files
for (int i = 0; i < global.params.objfiles->dim; i++)
{
char *p = (char *)global.params.objfiles->data[i];
args.push_back(p);
}
// output filename
std::string exestr;
if (global.params.exefile)
{ // explicit
exestr = global.params.exefile;
}
else
{ // inferred
// try root module name
if (Module::rootModule)
exestr = Module::rootModule->toChars();
else if (global.params.objfiles->dim)
exestr = FileName::removeExt((char*)global.params.objfiles->data[0]);
else
exestr = "a.out";
}
if (global.params.os == OSWindows && !(exestr.rfind(".exe") == exestr.length()-4))
exestr.append(".exe");
args.push_back("-o");
args.push_back(exestr.c_str());
// set the global gExePath
gExePath.set(exestr);
assert(gExePath.isValid());
// create path to exe
llvm::sys::Path exedir(gExePath);
exedir.set(gExePath.getDirname());
if (!exedir.exists())
{
exedir.createDirectoryOnDisk(true, &errstr);
if (!errstr.empty())
{
error("failed to create path to linking output: %s\n%s", exedir.c_str(), errstr.c_str());
fatal();
}
}
// additional linker switches
for (int i = 0; i < global.params.linkswitches->dim; i++)
{
char *p = (char *)global.params.linkswitches->data[i];
args.push_back(p);
}
// user libs
for (int i = 0; i < global.params.libfiles->dim; i++)
{
char *p = (char *)global.params.libfiles->data[i];
args.push_back(p);
}
// default libs
switch(global.params.os) {
case OSLinux:
args.push_back("-lrt");
// fallthrough
case OSMacOSX:
args.push_back("-ldl");
// fallthrough
case OSFreeBSD:
args.push_back("-lpthread");
args.push_back("-lm");
break;
case OSSolaris:
args.push_back("-lm");
args.push_back("-lumem");
// solaris TODO
break;
case OSWindows:
// FIXME: I'd assume kernel32 etc
break;
//.........这里部分代码省略.........