本文整理汇总了C++中llvm::sys::Path::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ Path::c_str方法的具体用法?C++ Path::c_str怎么用?C++ Path::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类llvm::sys::Path
的用法示例。
在下文中一共展示了Path::c_str方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ExecuteToolAndWait
static int ExecuteToolAndWait(llvm::sys::Path tool, std::vector<std::string> args, bool verbose = false)
{
// Construct real argument list.
// First entry is the tool itself, last entry must be NULL.
std::vector<const char *> realargs;
realargs.reserve(args.size() + 2);
realargs.push_back(tool.c_str());
for (std::vector<std::string>::const_iterator it = args.begin(); it != args.end(); ++it)
{
realargs.push_back((*it).c_str());
}
realargs.push_back(NULL);
// Print command line if requested
if (verbose)
{
// Print it
for (int i = 0; i < realargs.size()-1; i++)
printf("%s ", realargs[i]);
printf("\n");
fflush(stdout);
}
// Execute tool.
std::string errstr;
if (int status = llvm::sys::Program::ExecuteAndWait(tool, &realargs[0], NULL, NULL, 0, 0, &errstr))
{
error("%s failed with status: %d", tool.c_str(), status);
if (!errstr.empty())
error("message: %s", errstr.c_str());
return status;
}
return 0;
}
示例2: 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;
}
示例3: printUsage
/**
* Prints usage information to stdout.
*/
void printUsage(const char* argv0, ls::Path ldcPath)
{
// Print version information by actually invoking ldc -version.
const char* args[] = { ldcPath.c_str(), "-version", NULL };
execute(ldcPath, args);
printf("\n\
Usage:\n\
%s files.d ... { -switch }\n\
示例4: execute
/**
* Runs the given executable, returning its error code.
*/
int execute(ls::Path exePath, const char** args)
{
std::string errorMsg;
int rc = ls::Program::ExecuteAndWait(exePath, args, NULL, NULL,
0, 0, &errorMsg);
if (!errorMsg.empty())
{
error("Could not execute %s: %s", exePath.c_str(), errorMsg.c_str());
}
return rc;
}
示例5: LoadSerializedDiagnostics
void clang::LoadSerializedDiagnostics(const llvm::sys::Path &DiagnosticsPath,
unsigned num_unsaved_files,
struct CXUnsavedFile *unsaved_files,
FileManager &FileMgr,
SourceManager &SourceMgr,
SmallVectorImpl<StoredDiagnostic> &Diags) {
using llvm::MemoryBuffer;
using llvm::StringRef;
MemoryBuffer *F = MemoryBuffer::getFile(DiagnosticsPath.c_str());
if (!F)
return;
// Enter the unsaved files into the file manager.
for (unsigned I = 0; I != num_unsaved_files; ++I) {
const FileEntry *File = FileMgr.getVirtualFile(unsaved_files[I].Filename,
unsaved_files[I].Length,
0);
if (!File) {
// FIXME: Hard to localize when we have no diagnostics engine!
Diags.push_back(StoredDiagnostic(Diagnostic::Fatal,
(Twine("could not remap from missing file ") +
unsaved_files[I].Filename).str()));
delete F;
return;
}
MemoryBuffer *Buffer
= MemoryBuffer::getMemBuffer(unsaved_files[I].Contents,
unsaved_files[I].Contents + unsaved_files[I].Length);
if (!Buffer) {
delete F;
return;
}
SourceMgr.overrideFileContents(File, Buffer);
SourceMgr.createFileID(File, SourceLocation(), SrcMgr::C_User);
}
// Parse the diagnostics, emitting them one by one until we've
// exhausted the data.
StringRef Buffer = F->getBuffer();
const char *Memory = Buffer.data(), *MemoryEnd = Memory + Buffer.size();
while (Memory != MemoryEnd) {
StoredDiagnostic Stored = StoredDiagnostic::Deserialize(FileMgr, SourceMgr,
Memory, MemoryEnd);
if (!Stored)
break;
Diags.push_back(Stored);
}
delete F;
}
示例6: generateBinary
static bool generateBinary(llvm::Module *module,
const string &outputFile,
const llvm::sys::Path &gccPath,
unsigned optLevel,
bool /*exceptions*/,
bool sharedLib,
bool genPIC,
const vector<string> &arguments)
{
llvm::sys::Path tempAsm("clayasm");
string errMsg;
if (tempAsm.createTemporaryFileOnDisk(false, &errMsg)) {
cerr << "error: " << errMsg << '\n';
return false;
}
llvm::sys::RemoveFileOnSignal(tempAsm);
errMsg.clear();
llvm::raw_fd_ostream asmOut(tempAsm.c_str(),
errMsg,
llvm::raw_fd_ostream::F_Binary);
if (!errMsg.empty()) {
cerr << "error: " << errMsg << '\n';
return false;
}
generateAssembly(module, &asmOut, false, optLevel, sharedLib, genPIC);
asmOut.close();
vector<const char *> gccArgs;
gccArgs.push_back(gccPath.c_str());
switch (llvmTargetData->getPointerSizeInBits()) {
case 32 :
gccArgs.push_back("-m32");
break;
case 64 :
gccArgs.push_back("-m64");
break;
default :
assert(false);
}
if (sharedLib)
gccArgs.push_back("-shared");
gccArgs.push_back("-o");
gccArgs.push_back(outputFile.c_str());
gccArgs.push_back("-x");
gccArgs.push_back("assembler");
gccArgs.push_back(tempAsm.c_str());
for (unsigned i = 0; i < arguments.size(); ++i)
gccArgs.push_back(arguments[i].c_str());
gccArgs.push_back(NULL);
int result = llvm::sys::Program::ExecuteAndWait(gccPath, &gccArgs[0]);
if (tempAsm.eraseFromDisk(false, &errMsg)) {
cerr << "error: " << errMsg << '\n';
return false;
}
return (result == 0);
}