Prune #includes from llvm/Linker.h and llvm/System/Path.h,

forcing them down into various .cpp files.

This change also:
1. Renames TimeValue::toString() and Path::toString() to ::str()
   for similarity with the STL.
2. Removes all stream insertion support for sys::Path, forcing
   clients to call .str().
3. Removes a use of Config/alloca.h from bugpoint, using smallvector
   instead.
4. Weans llvm-db off <iostream>

sys::Path really needs to be gutted, but I don't have the desire to
do it at this point.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@79869 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2009-08-23 22:45:37 +00:00
parent 983c592272
commit 74382b7c69
39 changed files with 251 additions and 282 deletions

View File

@ -60,7 +60,7 @@ namespace llvm {
/// getFilename - Return the fully resolved path that this file was loaded
/// from.
const std::string &getFilename() const { return Filename.toString(); }
const std::string &getFilename() const { return Filename.str(); }
/// getSourceLine - Given a line number, return the start and end of the
/// line in the file. If the line number is invalid, or if the file could

View File

@ -14,11 +14,12 @@
#ifndef LLVM_LINKER_H
#define LLVM_LINKER_H
#include "llvm/System/Path.h"
#include <memory>
#include <vector>
#include "llvm/ADT/StringRef.h"
namespace llvm {
namespace sys { class Path; }
class Module;
class LLVMContext;
@ -64,11 +65,10 @@ class Linker {
/// Construct the Linker with an empty module which will be given the
/// name \p progname. \p progname will also be used for error messages.
/// @brief Construct with empty module
Linker(
const StringRef& progname, ///< name of tool running linker
const StringRef& modulename, ///< name of linker's end-result module
LLVMContext& C, ///< Context for global info
unsigned Flags = 0 ///< ControlFlags (one or more |'d together)
Linker(const StringRef &progname, ///< name of tool running linker
const StringRef &modulename, ///< name of linker's end-result module
LLVMContext &C, ///< Context for global info
unsigned Flags = 0 ///< ControlFlags (one or more |'d together)
);
/// Construct the Linker with a previously defined module, \p aModule. Use

View File

@ -257,10 +257,8 @@ raw_ostream &WriteGraph(raw_ostream &O, const GraphType &G,
}
template<typename GraphType>
sys::Path WriteGraph(const GraphType &G,
const std::string& Name,
bool ShortNames = false,
const std::string& Title = "") {
sys::Path WriteGraph(const GraphType &G, const std::string &Name,
bool ShortNames = false, const std::string &Title = "") {
std::string ErrMsg;
sys::Path Filename = sys::Path::GetTemporaryDirectory(&ErrMsg);
if (Filename.isEmpty()) {
@ -273,7 +271,7 @@ sys::Path WriteGraph(const GraphType &G,
return sys::Path();
}
errs() << "Writing '" << Filename << "'... ";
errs() << "Writing '" << Filename.str() << "'... ";
std::string ErrorInfo;
raw_fd_ostream O(Filename.c_str(), ErrorInfo, raw_fd_ostream::F_Force);
@ -282,7 +280,7 @@ sys::Path WriteGraph(const GraphType &G,
WriteGraph(O, G, ShortNames, Name, Title);
errs() << " done. \n";
} else {
errs() << "error opening file '" << Filename << "' for writing!\n";
errs() << "error opening file '" << Filename.str() << "' for writing!\n";
Filename.clear();
}
@ -293,16 +291,13 @@ sys::Path WriteGraph(const GraphType &G,
/// then cleanup. For use from the debugger.
///
template<typename GraphType>
void ViewGraph(const GraphType& G,
const std::string& Name,
bool ShortNames = false,
const std::string& Title = "",
void ViewGraph(const GraphType &G, const std::string &Name,
bool ShortNames = false, const std::string &Title = "",
GraphProgram::Name Program = GraphProgram::DOT) {
sys::Path Filename = WriteGraph(G, Name, ShortNames, Title);
sys::Path Filename = WriteGraph(G, Name, ShortNames, Title);
if (Filename.isEmpty()) {
if (Filename.isEmpty())
return;
}
DisplayGraph(Filename, true, Program);
}

View File

@ -15,11 +15,9 @@
#define LLVM_SYSTEM_PATH_H
#include "llvm/System/TimeValue.h"
#include "llvm/Support/raw_ostream.h"
#include <set>
#include <string>
#include <vector>
#include <iosfwd>
namespace llvm {
namespace sys {
@ -217,7 +215,7 @@ namespace sys {
/// Compares \p this Path with \p that Path for inequality.
/// @returns true if \p this and \p that refer to different things.
/// @brief Inequality Operator
bool operator!=(const Path &that) const;
bool operator!=(const Path &that) const { return !(*this == that); }
/// Determines if \p this Path is less than \p that Path. This is required
/// so that Path objects can be placed into ordered collections (e.g.
@ -249,13 +247,7 @@ namespace sys {
/// @brief Determines if the path name is empty (invalid).
bool isEmpty() const { return path.empty(); }
/// This function returns the current contents of the path as a
/// std::string. This allows the underlying path string to be manipulated.
/// @returns std::string containing the path name.
/// @brief Returns the path as a std::string.
const std::string &toString() const { return path; }
/// This function returns the last component of the path name. The last
/// This function returns the last component of the path name. The last
/// component is the file or directory name occuring after the last
/// directory separator. If no directory separator is present, the entire
/// path name is returned (i.e. same as toString).
@ -286,6 +278,8 @@ namespace sys {
/// @returns a 'C' string containing the path name.
/// @brief Returns the path as a C string.
const char *c_str() const { return path.c_str(); }
const std::string &str() const { return path; }
/// size - Return the length in bytes of this path name.
size_t size() const { return path.size(); }
@ -716,24 +710,6 @@ namespace sys {
extern const char PathSeparator;
}
inline raw_ostream& operator<<(raw_ostream& strm, const sys::Path& aPath) {
strm << aPath.toString();
return strm;
}
inline raw_ostream& operator<<(raw_ostream& strm,
const sys::PathWithStatus& aPath) {
strm << static_cast<const sys::Path&>(aPath);
return strm;
}
std::ostream& operator<<(std::ostream& strm, const sys::Path& aPath);
inline std::ostream& operator<<(std::ostream& strm,
const sys::PathWithStatus& aPath) {
strm << static_cast<const sys::Path&>(aPath);
return strm;
}
}
#endif

View File

@ -271,7 +271,7 @@ namespace sys {
/// Provides conversion of the TimeValue into a readable time & date.
/// @returns std::string containing the readable time value
/// @brief Convert time to a string.
std::string toString() const;
std::string str() const;
/// @}
/// @name Mutators

View File

@ -31,7 +31,7 @@ ArchiveMember::getMemberSize() const {
// If it has a long filename, include the name length
if (hasLongFilename())
result += path.toString().length() + 1;
result += path.str().length() + 1;
// If its now odd lengthed, include the padding byte
if (result % 2 != 0 )
@ -76,38 +76,38 @@ bool ArchiveMember::replaceWith(const sys::Path& newFile, std::string* ErrMsg) {
path = newFile;
// SVR4 symbol tables have an empty name
if (path.toString() == ARFILE_SVR4_SYMTAB_NAME)
if (path.str() == ARFILE_SVR4_SYMTAB_NAME)
flags |= SVR4SymbolTableFlag;
else
flags &= ~SVR4SymbolTableFlag;
// BSD4.4 symbol tables have a special name
if (path.toString() == ARFILE_BSD4_SYMTAB_NAME)
if (path.str() == ARFILE_BSD4_SYMTAB_NAME)
flags |= BSD4SymbolTableFlag;
else
flags &= ~BSD4SymbolTableFlag;
// LLVM symbol tables have a very specific name
if (path.toString() == ARFILE_LLVM_SYMTAB_NAME)
if (path.str() == ARFILE_LLVM_SYMTAB_NAME)
flags |= LLVMSymbolTableFlag;
else
flags &= ~LLVMSymbolTableFlag;
// String table name
if (path.toString() == ARFILE_STRTAB_NAME)
if (path.str() == ARFILE_STRTAB_NAME)
flags |= StringTableFlag;
else
flags &= ~StringTableFlag;
// If it has a slash then it has a path
bool hasSlash = path.toString().find('/') != std::string::npos;
bool hasSlash = path.str().find('/') != std::string::npos;
if (hasSlash)
flags |= HasPathFlag;
else
flags &= ~HasPathFlag;
// If it has a slash or its over 15 chars then its a long filename format
if (hasSlash || path.toString().length() > 15)
if (hasSlash || path.str().length() > 15)
flags |= HasLongFilenameFlag;
else
flags &= ~HasLongFilenameFlag;
@ -217,7 +217,7 @@ bool llvm::GetBitcodeSymbols(const sys::Path& fName,
std::auto_ptr<MemoryBuffer> Buffer(
MemoryBuffer::getFileOrSTDIN(fName.c_str()));
if (!Buffer.get()) {
if (ErrMsg) *ErrMsg = "Could not open file '" + fName.toString() + "'";
if (ErrMsg) *ErrMsg = "Could not open file '" + fName.str() + "'";
return true;
}

View File

@ -344,8 +344,8 @@ Archive::getAllModules(std::vector<Module*>& Modules,
for (iterator I=begin(), E=end(); I != E; ++I) {
if (I->isBitcode()) {
std::string FullMemberName = archPath.toString() +
"(" + I->getPath().toString() + ")";
std::string FullMemberName = archPath.str() +
"(" + I->getPath().str() + ")";
MemoryBuffer *Buffer =
MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str());
memcpy((char*)Buffer->getBufferStart(), I->getData(), I->getSize());
@ -484,8 +484,8 @@ Archive::findModuleDefiningSymbol(const std::string& symbol,
return 0;
// Now, load the bitcode module to get the ModuleProvider
std::string FullMemberName = archPath.toString() + "(" +
mbr->getPath().toString() + ")";
std::string FullMemberName = archPath.str() + "(" +
mbr->getPath().str() + ")";
MemoryBuffer *Buffer =MemoryBuffer::getNewMemBuffer(mbr->getSize(),
FullMemberName.c_str());
memcpy((char*)Buffer->getBufferStart(), mbr->getData(), mbr->getSize());
@ -534,8 +534,8 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
if (mbr->isBitcode()) {
// Get the symbols
std::vector<std::string> symbols;
std::string FullMemberName = archPath.toString() + "(" +
mbr->getPath().toString() + ")";
std::string FullMemberName = archPath.str() + "(" +
mbr->getPath().str() + ")";
ModuleProvider* MP =
GetBitcodeSymbols((const unsigned char*)At, mbr->getSize(),
FullMemberName, Context, symbols, error);
@ -552,7 +552,7 @@ Archive::findModulesDefiningSymbols(std::set<std::string>& symbols,
} else {
if (error)
*error = "Can't parse bitcode member: " +
mbr->getPath().toString() + ": " + *error;
mbr->getPath().str() + ": " + *error;
delete mbr;
return false;
}
@ -612,7 +612,7 @@ bool Archive::isBitcodeArchive() {
continue;
std::string FullMemberName =
archPath.toString() + "(" + I->getPath().toString() + ")";
archPath.str() + "(" + I->getPath().str() + ")";
MemoryBuffer *Buffer =
MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str());

View File

@ -95,7 +95,7 @@ Archive::fillHeader(const ArchiveMember &mbr, ArchiveMemberHeader& hdr,
memcpy(hdr.date,buffer,12);
// Get rid of trailing blanks in the name
std::string mbrPath = mbr.getPath().toString();
std::string mbrPath = mbr.getPath().str();
size_t mbrLen = mbrPath.length();
while (mbrLen > 0 && mbrPath[mbrLen-1] == ' ') {
mbrPath.erase(mbrLen-1,1);
@ -173,10 +173,10 @@ Archive::addFileBefore(const sys::Path& filePath, iterator where,
mbr->info = *FSInfo;
unsigned flags = 0;
bool hasSlash = filePath.toString().find('/') != std::string::npos;
bool hasSlash = filePath.str().find('/') != std::string::npos;
if (hasSlash)
flags |= ArchiveMember::HasPathFlag;
if (hasSlash || filePath.toString().length() > 15)
if (hasSlash || filePath.str().length() > 15)
flags |= ArchiveMember::HasLongFilenameFlag;
std::string magic;
mbr->path.getMagicNumber(magic,4);
@ -223,8 +223,7 @@ Archive::writeMember(
// symbol table if its a bitcode file.
if (CreateSymbolTable && member.isBitcode()) {
std::vector<std::string> symbols;
std::string FullMemberName = archPath.toString() + "(" +
member.getPath().toString()
std::string FullMemberName = archPath.str() + "(" + member.getPath().str()
+ ")";
ModuleProvider* MP =
GetBitcodeSymbols((const unsigned char*)data,fSize,
@ -249,7 +248,7 @@ Archive::writeMember(
} else {
delete mFile;
if (ErrMsg)
*ErrMsg = "Can't parse bitcode member: " + member.getPath().toString()
*ErrMsg = "Can't parse bitcode member: " + member.getPath().str()
+ ": " + *ErrMsg;
return true;
}
@ -266,8 +265,8 @@ Archive::writeMember(
// Write the long filename if its long
if (writeLongName) {
ARFile.write(member.getPath().toString().data(),
member.getPath().toString().length());
ARFile.write(member.getPath().str().data(),
member.getPath().str().length());
}
// Write the (possibly compressed) member's content to the file.
@ -371,7 +370,7 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress,
if (TmpArchive.exists())
TmpArchive.eraseFromDisk();
if (ErrMsg)
*ErrMsg = "Error opening archive file: " + archPath.toString();
*ErrMsg = "Error opening archive file: " + archPath.str();
return true;
}
@ -425,7 +424,7 @@ Archive::writeToDisk(bool CreateSymbolTable, bool TruncateNames, bool Compress,
if (TmpArchive.exists())
TmpArchive.eraseFromDisk();
if (ErrMsg)
*ErrMsg = "Error opening archive file: " + FinalFilePath.toString();
*ErrMsg = "Error opening archive file: " + FinalFilePath.str();
return true;
}

View File

@ -1343,7 +1343,7 @@ void DwarfDebug::BeginModule(Module *M, MachineModuleInfo *mmi) {
FullPath.appendComponent(getSourceFileName(Id.second));
assert(AppendOk && "Could not append filename to directory!");
AppendOk = false;
Asm->EmitFile(i, FullPath.toString());
Asm->EmitFile(i, FullPath.str());
Asm->EOL();
}
}

View File

@ -22,6 +22,7 @@
#include "llvm/Module.h"
#include "llvm/Debugger/SourceFile.h"
#include "llvm/Debugger/SourceLanguage.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/SlowOperationInformer.h"
#include "llvm/ADT/STLExtras.h"
using namespace llvm;
@ -135,7 +136,7 @@ SourceFile &SourceFileInfo::getSourceText() const {
tmpPath.set(Directory);
tmpPath.appendComponent(BaseName);
if (tmpPath.canRead())
SourceText = new SourceFile(tmpPath.toString(), Descriptor);
SourceText = new SourceFile(tmpPath.str(), Descriptor);
else
SourceText = new SourceFile(BaseName, Descriptor);
}

View File

@ -96,10 +96,10 @@ bool
Linker::LinkInArchive(const sys::Path &Filename, bool &is_native) {
// Make sure this is an archive file we're dealing with
if (!Filename.isArchive())
return error("File '" + Filename.toString() + "' is not an archive.");
return error("File '" + Filename.str() + "' is not an archive.");
// Open the archive file
verbose("Linking archive file '" + Filename.toString() + "'");
verbose("Linking archive file '" + Filename.str() + "'");
// Find all of the symbols currently undefined in the bitcode program.
// If all the symbols are defined, the program is complete, and there is
@ -108,8 +108,7 @@ Linker::LinkInArchive(const sys::Path &Filename, bool &is_native) {
GetAllUndefinedSymbols(Composite, UndefinedSymbols);
if (UndefinedSymbols.empty()) {
verbose("No symbols undefined, skipping library '" +
Filename.toString() + "'");
verbose("No symbols undefined, skipping library '" + Filename.str() + "'");
return false; // No need to link anything in!
}
@ -120,7 +119,7 @@ Linker::LinkInArchive(const sys::Path &Filename, bool &is_native) {
Archive* arch = AutoArch.get();
if (!arch)
return error("Cannot read archive '" + Filename.toString() +
return error("Cannot read archive '" + Filename.str() +
"': " + ErrMsg);
if (!arch->isBitcodeArchive()) {
is_native = true;
@ -143,7 +142,7 @@ Linker::LinkInArchive(const sys::Path &Filename, bool &is_native) {
// Find the modules we need to link into the target module
std::set<ModuleProvider*> Modules;
if (!arch->findModulesDefiningSymbols(UndefinedSymbols, Modules, &ErrMsg))
return error("Cannot find symbols in '" + Filename.toString() +
return error("Cannot find symbols in '" + Filename.str() +
"': " + ErrMsg);
// If we didn't find any more modules to link this time, we are done

View File

@ -14,10 +14,10 @@
#include "llvm/Linker.h"
#include "llvm/Module.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/System/Path.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Bitcode/ReaderWriter.h"
using namespace llvm;
// LinkItems - This function is the main entry point into linking. It takes a
@ -93,7 +93,7 @@ bool Linker::LinkInLibrary(const StringRef &Lib, bool& is_native) {
case sys::Archive_FileType:
if (LinkInArchive(Pathname, is_native))
return error("Cannot link archive '" + Pathname.toString() + "'");
return error("Cannot link archive '" + Pathname.str() + "'");
break;
case sys::ELF_Relocatable_FileType:
@ -158,7 +158,7 @@ bool Linker::LinkInFile(const sys::Path &File, bool &is_native) {
is_native = false;
// Check for a file of name "-", which means "read standard input"
if (File.toString() == "-") {
if (File.str() == "-") {
std::auto_ptr<Module> M;
if (MemoryBuffer *Buffer = MemoryBuffer::getSTDIN()) {
M.reset(ParseBitcodeFile(Buffer, Context, &Error));
@ -173,7 +173,7 @@ bool Linker::LinkInFile(const sys::Path &File, bool &is_native) {
// Make sure we can at least read the file
if (!File.canRead())
return error("Cannot find linker input '" + File.toString() + "'");
return error("Cannot find linker input '" + File.str() + "'");
// If its an archive, try to link it in
std::string Magic;
@ -181,26 +181,26 @@ bool Linker::LinkInFile(const sys::Path &File, bool &is_native) {
switch (sys::IdentifyFileType(Magic.c_str(), 64)) {
default: llvm_unreachable("Bad file type identification");
case sys::Unknown_FileType:
return warning("Ignoring file '" + File.toString() +
return warning("Ignoring file '" + File.str() +
"' because does not contain bitcode.");
case sys::Archive_FileType:
// A user may specify an ar archive without -l, perhaps because it
// is not installed as a library. Detect that and link the archive.
verbose("Linking archive file '" + File.toString() + "'");
verbose("Linking archive file '" + File.str() + "'");
if (LinkInArchive(File, is_native))
return true;
break;
case sys::Bitcode_FileType: {
verbose("Linking bitcode file '" + File.toString() + "'");
verbose("Linking bitcode file '" + File.str() + "'");
std::auto_ptr<Module> M(LoadObject(File));
if (M.get() == 0)
return error("Cannot load file '" + File.toString() + "': " + Error);
return error("Cannot load file '" + File.str() + "': " + Error);
if (LinkInModule(M.get(), &Error))
return error("Cannot link file '" + File.toString() + "': " + Error);
return error("Cannot link file '" + File.str() + "': " + Error);
verbose("Linked in file '" + File.toString() + "'");
verbose("Linked in file '" + File.str() + "'");
break;
}

View File

@ -26,6 +26,7 @@
#include "llvm/Instructions.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Path.h"
#include "llvm/ADT/DenseMap.h"
#include <sstream>

View File

@ -14,9 +14,10 @@
#include "llvm/Linker.h"
#include "llvm/Module.h"
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Config/config.h"
#include "llvm/System/Path.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Config/config.h"
using namespace llvm;
Linker::Linker(const StringRef &progname, const StringRef &modname,
@ -69,11 +70,8 @@ Linker::addPath(const sys::Path& path) {
void
Linker::addPaths(const std::vector<std::string>& paths) {
for (unsigned i = 0; i != paths.size(); ++i) {
sys::Path aPath;
aPath.set(paths[i]);
LibPaths.push_back(aPath);
}
for (unsigned i = 0, e = paths.size(); i != e; ++i)
LibPaths.push_back(sys::Path(paths[i]));
}
void
@ -100,16 +98,15 @@ Linker::LoadObject(const sys::Path &FN) {
std::string ParseErrorMessage;
Module *Result = 0;
const std::string &FNS = FN.toString();
std::auto_ptr<MemoryBuffer> Buffer(MemoryBuffer::getFileOrSTDIN(FNS.c_str()));
std::auto_ptr<MemoryBuffer> Buffer(MemoryBuffer::getFileOrSTDIN(FN.c_str()));
if (Buffer.get())
Result = ParseBitcodeFile(Buffer.get(), Context, &ParseErrorMessage);
else
ParseErrorMessage = "Error reading file '" + FNS + "'";
ParseErrorMessage = "Error reading file '" + FN.str() + "'";
if (Result)
return std::auto_ptr<Module>(Result);
Error = "Bitcode file '" + FN.toString() + "' could not be loaded";
Error = "Bitcode file '" + FN.str() + "' could not be loaded";
if (ParseErrorMessage.size())
Error += ": " + ParseErrorMessage;
return std::auto_ptr<Module>();

View File

@ -64,9 +64,10 @@ void llvm::DisplayGraph(const sys::Path &Filename, bool wait,
errs() << "Running 'Graphviz' program... ";
if (sys::Program::ExecuteAndWait(Graphviz, &args[0],0,0,0,0,&ErrMsg))
errs() << "Error viewing graph " << Filename << ": " << ErrMsg << "\n";
errs() << "Error viewing graph " << Filename.str() << ": " << ErrMsg
<< "\n";
else
Filename.eraseFromDisk();
Filename.eraseFromDisk();
#elif (HAVE_GV && (HAVE_DOT || HAVE_FDP || HAVE_NEATO || \
HAVE_TWOPI || HAVE_CIRCO))

View File

@ -15,6 +15,7 @@
#include "llvm/Support/SystemUtils.h"
#include "llvm/System/Process.h"
#include "llvm/System/Program.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
bool llvm::CheckBitcodeOutputToConsole(raw_ostream &stream_to_check,

View File

@ -29,19 +29,10 @@ bool Path::operator==(const Path &that) const {
return path == that.path;
}
bool Path::operator!=(const Path &that) const {
return path != that.path;
}
bool Path::operator<(const Path& that) const {
return path < that.path;
}
std::ostream& llvm::operator<<(std::ostream &strm, const sys::Path &aPath) {
strm << aPath.toString();
return strm;
}
Path
Path::GetLLVMConfigDir() {
Path result;

View File

@ -119,7 +119,7 @@ void Path::makeAbsolute() {
CWD.appendComponent(path);
path = CWD.toString();
path = CWD.str();
}
Path
@ -502,7 +502,7 @@ static bool AddPermissionBits(const Path &File, int bits) {
// Get the file's current mode.
struct stat buf;
if (0 != stat(File.toString().c_str(), &buf))
if (0 != stat(File.c_str(), &buf))
return false;
// Change the file to have whichever permissions bits from 'bits'
// that the umask would not disable.
@ -759,7 +759,7 @@ bool
Path::renamePathOnDisk(const Path& newName, std::string* ErrMsg) {
if (0 != ::rename(path.c_str(), newName.c_str()))
return MakeErrMsg(ErrMsg, std::string("can't rename '") + path + "' as '" +
newName.toString() + "'");
newName.str() + "'");
return false;
}
@ -781,13 +781,13 @@ sys::CopyFile(const sys::Path &Dest, const sys::Path &Src, std::string* ErrMsg){
int outFile = -1;
inFile = ::open(Src.c_str(), O_RDONLY);
if (inFile == -1)
return MakeErrMsg(ErrMsg, Src.toString() +
return MakeErrMsg(ErrMsg, Src.str() +
": can't open source file to copy");
outFile = ::open(Dest.c_str(), O_WRONLY|O_CREAT, 0666);
if (outFile == -1) {
::close(inFile);
return MakeErrMsg(ErrMsg, Dest.toString() +
return MakeErrMsg(ErrMsg, Dest.str() +
": can't create destination file for copy");
}
@ -797,7 +797,7 @@ sys::CopyFile(const sys::Path &Dest, const sys::Path &Src, std::string* ErrMsg){
if (errno != EINTR && errno != EAGAIN) {
::close(inFile);
::close(outFile);
return MakeErrMsg(ErrMsg, Src.toString()+": can't read source file");
return MakeErrMsg(ErrMsg, Src.str()+": can't read source file");
}
} else {
char *BufPtr = Buffer;
@ -807,7 +807,7 @@ sys::CopyFile(const sys::Path &Dest, const sys::Path &Src, std::string* ErrMsg){
if (errno != EINTR && errno != EAGAIN) {
::close(inFile);
::close(outFile);
return MakeErrMsg(ErrMsg, Dest.toString() +
return MakeErrMsg(ErrMsg, Dest.str() +
": can't write destination file");
}
} else {

View File

@ -97,7 +97,7 @@ static bool RedirectIO(const Path *Path, int FD, std::string* ErrMsg) {
// Redirect empty paths to /dev/null
File = "/dev/null";
else
File = Path->toString();
File = Path->str();
// Open the file
int InFD = open(File.c_str(), FD == 0 ? O_RDONLY : O_WRONLY|O_CREAT, 0666);
@ -156,7 +156,7 @@ Program::Execute(const Path& path,
{
if (!path.canExecute()) {
if (ErrMsg)
*ErrMsg = path.toString() + " is not executable";
*ErrMsg = path.str() + " is not executable";
return false;
}

View File

@ -21,7 +21,7 @@
namespace llvm {
using namespace sys;
std::string TimeValue::toString() const {
std::string TimeValue::str() const {
char buffer[32];
time_t ourTime = time_t(this->toEpochTime());

View File

@ -808,8 +808,8 @@ CopyFile(const sys::Path &Dest, const sys::Path &Src, std::string* ErrMsg) {
// Can't use CopyFile macro defined in Windows.h because it would mess up the
// above line. We use the expansion it would have in a non-UNICODE build.
if (!::CopyFileA(Src.c_str(), Dest.c_str(), false))
return MakeErrMsg(ErrMsg, "Can't copy '" + Src.toString() +
"' to '" + Dest.toString() + "': ");
return MakeErrMsg(ErrMsg, "Can't copy '" + Src.str() +
"' to '" + Dest.str() + "': ");
return false;
}

View File

@ -92,7 +92,7 @@ static HANDLE RedirectIO(const Path *path, int fd, std::string* ErrMsg) {
if (path->isEmpty())
fname = "NUL";
else
fname = path->toString().c_str();
fname = path->c_str();
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(sa);
@ -258,11 +258,10 @@ Program::Execute(const Path& path,
CloseHandle(si.hStdError);
// Now return an error if the process didn't get created.
if (!rc)
{
if (!rc) {
SetLastError(err);
MakeErrMsg(ErrMsg, std::string("Couldn't execute program '") +
path.toString() + "'");
path.str() + "'");
return false;
}
Pid_ = pi.dwProcessId;

View File

@ -30,7 +30,7 @@ TimeValue TimeValue::now() {
return t;
}
std::string TimeValue::toString() const {
std::string TimeValue::str() const {
#ifdef __MINGW32__
// This ban may be lifted by either:
// (i) a future MinGW version other than 1.0 inherents the __time64_t type, or

View File

@ -72,10 +72,10 @@ ReducePassList::doTest(std::vector<const PassInfo*> &Prefix,
PrefixOutput.set(PfxOutput);
OrigProgram = BD.Program;
BD.Program = ParseInputFile(PrefixOutput.toString(), BD.getContext());
BD.Program = ParseInputFile(PrefixOutput.str(), BD.getContext());
if (BD.Program == 0) {
errs() << BD.getToolName() << ": Error reading bitcode file '"
<< PrefixOutput << "'!\n";
<< PrefixOutput.str() << "'!\n";
exit(1);
}
PrefixOutput.eraseFromDisk();

View File

@ -18,6 +18,7 @@
#include "llvm/Support/Debug.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/SystemUtils.h"
#include "llvm/Support/raw_ostream.h"
#include <fstream>
using namespace llvm;
@ -280,9 +281,9 @@ void BugDriver::compileProgram(Module *M) {
<< "\n";
exit(1);
}
if (writeProgramToFile(BitcodeFile.toString(), M)) {
if (writeProgramToFile(BitcodeFile.str(), M)) {
errs() << ToolName << ": Error emitting bitcode to file '"
<< BitcodeFile << "'!\n";
<< BitcodeFile.str() << "'!\n";
exit(1);
}
@ -290,7 +291,7 @@ void BugDriver::compileProgram(Module *M) {
FileRemover BitcodeFileRemover(BitcodeFile, !SaveTemps);
// Actually compile the program!
Interpreter->compileProgram(BitcodeFile.toString());
Interpreter->compileProgram(BitcodeFile.str());
}
@ -315,7 +316,7 @@ std::string BugDriver::executeProgram(std::string OutputFile,
<< ErrMsg << "!\n";
exit(1);
}
BitcodeFile = uniqueFilename.toString();
BitcodeFile = uniqueFilename.str();
if (writeProgramToFile(BitcodeFile, Program)) {
errs() << ToolName << ": Error emitting bitcode to file '"
@ -338,7 +339,7 @@ std::string BugDriver::executeProgram(std::string OutputFile,
<< ErrMsg << "\n";
exit(1);
}
OutputFile = uniqueFile.toString();
OutputFile = uniqueFile.str();
// Figure out which shared objects to run, if any.
std::vector<std::string> SharedObjs(AdditionalSOs);
@ -393,7 +394,7 @@ std::string BugDriver::compileSharedObject(const std::string &BitcodeFile) {
GCC::FileType FT = SafeInterpreter->OutputCode(BitcodeFile, OutputFile);
std::string SharedObjectFile;
if (gcc->MakeSharedObject(OutputFile.toString(), FT,
if (gcc->MakeSharedObject(OutputFile.str(), FT,
SharedObjectFile, AdditionalLinkerArgs))
exit(1);
@ -447,7 +448,7 @@ bool BugDriver::diffProgram(const std::string &BitcodeFile,
std::string Error;
bool FilesDifferent = false;
if (int Diff = DiffFilesWithTolerance(sys::Path(ReferenceOutputFile),
sys::Path(Output.toString()),
sys::Path(Output.str()),
AbsTolerance, RelTolerance, &Error)) {
if (Diff == 2) {
errs() << "While diffing output: " << Error << '\n';

View File

@ -29,6 +29,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Path.h"
#include "llvm/System/Signals.h"
#include <set>

View File

@ -17,6 +17,7 @@
#include "BugDriver.h"
#include "ToolRunner.h"
#include "llvm/Pass.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <ctime>
using namespace llvm;

View File

@ -826,8 +826,9 @@ static bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe) {
<< ErrMsg << "\n";
exit(1);
}
if (BD.writeProgramToFile(TestModuleBC.toString(), Test)) {
errs() << "Error writing bitcode to `" << TestModuleBC << "'\nExiting.";
if (BD.writeProgramToFile(TestModuleBC.str(), Test)) {
errs() << "Error writing bitcode to `" << TestModuleBC.str()
<< "'\nExiting.";
exit(1);
}
delete Test;
@ -840,16 +841,17 @@ static bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe) {
exit(1);
}
if (BD.writeProgramToFile(SafeModuleBC.toString(), Safe)) {
errs() << "Error writing bitcode to `" << SafeModuleBC << "'\nExiting.";
if (BD.writeProgramToFile(SafeModuleBC.str(), Safe)) {
errs() << "Error writing bitcode to `" << SafeModuleBC.str()
<< "'\nExiting.";
exit(1);
}
std::string SharedObject = BD.compileSharedObject(SafeModuleBC.toString());
std::string SharedObject = BD.compileSharedObject(SafeModuleBC.str());
delete Safe;
// Run the code generator on the `Test' code, loading the shared library.
// The function returns whether or not the new output differs from reference.
int Result = BD.diffProgram(TestModuleBC.toString(), SharedObject, false);
int Result = BD.diffProgram(TestModuleBC.str(), SharedObject, false);
if (Result)
errs() << ": still failing!\n";
@ -899,8 +901,9 @@ bool BugDriver::debugCodeGenerator() {
exit(1);
}
if (writeProgramToFile(TestModuleBC.toString(), ToCodeGen)) {
errs() << "Error writing bitcode to `" << TestModuleBC << "'\nExiting.";
if (writeProgramToFile(TestModuleBC.str(), ToCodeGen)) {
errs() << "Error writing bitcode to `" << TestModuleBC.str()
<< "'\nExiting.";
exit(1);
}
delete ToCodeGen;
@ -913,31 +916,33 @@ bool BugDriver::debugCodeGenerator() {
exit(1);
}
if (writeProgramToFile(SafeModuleBC.toString(), ToNotCodeGen)) {
errs() << "Error writing bitcode to `" << SafeModuleBC << "'\nExiting.";
if (writeProgramToFile(SafeModuleBC.str(), ToNotCodeGen)) {
errs() << "Error writing bitcode to `" << SafeModuleBC.str()
<< "'\nExiting.";
exit(1);
}
std::string SharedObject = compileSharedObject(SafeModuleBC.toString());
std::string SharedObject = compileSharedObject(SafeModuleBC.str());
delete ToNotCodeGen;
outs() << "You can reproduce the problem with the command line: \n";
if (isExecutingJIT()) {
outs() << " lli -load " << SharedObject << " " << TestModuleBC;
outs() << " lli -load " << SharedObject << " " << TestModuleBC.str();
} else {
outs() << " llc -f " << TestModuleBC << " -o " << TestModuleBC<< ".s\n";
outs() << " gcc " << SharedObject << " " << TestModuleBC
<< ".s -o " << TestModuleBC << ".exe";
outs() << " llc -f " << TestModuleBC.str() << " -o " << TestModuleBC.str()
<< ".s\n";
outs() << " gcc " << SharedObject << " " << TestModuleBC.str()
<< ".s -o " << TestModuleBC.str() << ".exe";
#if defined (HAVE_LINK_R)
outs() << " -Wl,-R.";
#endif
outs() << "\n";
outs() << " " << TestModuleBC << ".exe";
outs() << " " << TestModuleBC.str() << ".exe";
}
for (unsigned i=0, e = InputArgv.size(); i != e; ++i)
outs() << " " << InputArgv[i];
outs() << '\n';
outs() << "The shared object was created with:\n llc -march=c "
<< SafeModuleBC << " -o temporary.c\n"
<< SafeModuleBC.str() << " -o temporary.c\n"
<< " gcc -xc temporary.c -O2 -o " << SharedObject;
if (TargetTriple.getArch() == Triple::sparc)
outs() << " -G"; // Compile a shared library, `-G' for Sparc

View File

@ -27,9 +27,9 @@
#include "llvm/Target/TargetData.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Path.h"
#include "llvm/System/Program.h"
#include "llvm/Config/alloca.h"
#define DONT_GET_PLUGIN_LOADER_OPTION
#include "llvm/Support/PluginLoader.h"
@ -136,7 +136,7 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
<< ErrMsg << "\n";
return(1);
}
OutputFilename = uniqueFilename.toString();
OutputFilename = uniqueFilename.str();
// set up the input file name
sys::Path inputFilename("bugpoint-input.bc");
@ -152,29 +152,26 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
if (!ErrInfo.empty()) {
errs() << "Error opening bitcode file: " << inputFilename << "\n";
errs() << "Error opening bitcode file: " << inputFilename.str() << "\n";
return 1;
}
WriteBitcodeToFile(Program, InFile);
InFile.close();
// setup the child process' arguments
const char** args = (const char**)
alloca(sizeof(const char*) *
(Passes.size()+13+2*PluginLoader::getNumPlugins()+NumExtraArgs));
int n = 0;
SmallVector<const char*, 8> Args;
sys::Path tool = sys::Program::FindProgramByName(ToolName);
if (UseValgrind) {
args[n++] = "valgrind";
args[n++] = "--error-exitcode=1";
args[n++] = "-q";
args[n++] = tool.c_str();
Args.push_back("valgrind");
Args.push_back("--error-exitcode=1");
Args.push_back("-q");
Args.push_back(tool.c_str());
} else
args[n++] = ToolName;
Args.push_back(ToolName);
args[n++] = "-as-child";
args[n++] = "-child-output";
args[n++] = OutputFilename.c_str();
Args.push_back("-as-child");
Args.push_back("-child-output");
Args.push_back(OutputFilename.c_str());
std::vector<std::string> pass_args;
for (unsigned i = 0, e = PluginLoader::getNumPlugins(); i != e; ++i) {
pass_args.push_back( std::string("-load"));
@ -185,11 +182,11 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
pass_args.push_back( std::string("-") + (*I)->getPassArgument() );
for (std::vector<std::string>::const_iterator I = pass_args.begin(),
E = pass_args.end(); I != E; ++I )
args[n++] = I->c_str();
args[n++] = inputFilename.c_str();
Args.push_back(I->c_str());
Args.push_back(inputFilename.c_str());
for (unsigned i = 0; i < NumExtraArgs; ++i)
args[n++] = *ExtraArgs;
args[n++] = 0;
Args.push_back(*ExtraArgs);
Args.push_back(0);
sys::Path prog;
if (UseValgrind)
@ -201,7 +198,8 @@ bool BugDriver::runPasses(const std::vector<const PassInfo*> &Passes,
sys::Path Nowhere;
const sys::Path *Redirects[3] = {0, &Nowhere, &Nowhere};
int result = sys::Program::ExecuteAndWait(prog, args, 0, (SilencePasses ? Redirects : 0),
int result = sys::Program::ExecuteAndWait(prog, Args.data(), 0,
(SilencePasses ? Redirects : 0),
Timeout, MemoryLimit, &ErrMsg);
// If we are supposed to delete the bitcode file or if the passes crashed,

View File

@ -13,11 +13,12 @@
#define DEBUG_TYPE "toolrunner"
#include "ToolRunner.h"
#include "llvm/Config/config.h" // for HAVE_LINK_R
#include "llvm/System/Program.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Config/config.h" // for HAVE_LINK_R
#include <fstream>
#include <sstream>
using namespace llvm;
@ -232,7 +233,7 @@ AbstractInterpreter *AbstractInterpreter::createLLI(const char *Argv0,
std::string &Message,
const std::vector<std::string> *ToolArgs) {
std::string LLIPath =
FindExecutable("lli", Argv0, (void *)(intptr_t)&createLLI).toString();
FindExecutable("lli", Argv0, (void *)(intptr_t)&createLLI).str();
if (!LLIPath.empty()) {
Message = "Found lli: " + LLIPath + "\n";
return new LLI(LLIPath, ToolArgs);
@ -332,7 +333,7 @@ AbstractInterpreter *AbstractInterpreter::createCustom(
pos = ExecCommandLine.find_first_of(delimiters, lastPos);
}
std::string CmdPath = sys::Program::FindProgramByName(Command).toString();
std::string CmdPath = sys::Program::FindProgramByName(Command).str();
if (CmdPath.empty()) {
Message =
std::string("Cannot find '") + Command +
@ -407,7 +408,7 @@ int LLC::ExecuteProgram(const std::string &Bitcode,
GCCArgs.insert(GCCArgs.end(), gccArgs.begin(), gccArgs.end());
// Assuming LLC worked, compile the result with GCC and run it.
return gcc->ExecuteProgram(OutputAsmFile.toString(), Args, GCC::AsmFile,
return gcc->ExecuteProgram(OutputAsmFile.str(), Args, GCC::AsmFile,
InputFile, OutputFile, GCCArgs,
Timeout, MemoryLimit);
}
@ -419,7 +420,7 @@ LLC *AbstractInterpreter::createLLC(const char *Argv0,
const std::vector<std::string> *Args,
const std::vector<std::string> *GCCArgs) {
std::string LLCPath =
FindExecutable("llc", Argv0, (void *)(intptr_t)&createLLC).toString();
FindExecutable("llc", Argv0, (void *)(intptr_t)&createLLC).str();
if (LLCPath.empty()) {
Message = "Cannot find `llc' in executable directory or PATH!\n";
return 0;
@ -505,7 +506,7 @@ int JIT::ExecuteProgram(const std::string &Bitcode,
AbstractInterpreter *AbstractInterpreter::createJIT(const char *Argv0,
std::string &Message, const std::vector<std::string> *Args) {
std::string LLIPath =
FindExecutable("lli", Argv0, (void *)(intptr_t)&createJIT).toString();
FindExecutable("lli", Argv0, (void *)(intptr_t)&createJIT).str();
if (!LLIPath.empty()) {
Message = "Found lli: " + LLIPath + "\n";
return new JIT(LLIPath, Args);
@ -572,7 +573,7 @@ int CBE::ExecuteProgram(const std::string &Bitcode,
std::vector<std::string> GCCArgs(ArgsForGCC);
GCCArgs.insert(GCCArgs.end(), SharedLibs.begin(), SharedLibs.end());
return gcc->ExecuteProgram(OutputCFile.toString(), Args, GCC::CFile,
return gcc->ExecuteProgram(OutputCFile.str(), Args, GCC::CFile,
InputFile, OutputFile, GCCArgs,
Timeout, MemoryLimit);
}
@ -591,7 +592,7 @@ CBE *AbstractInterpreter::createCBE(const char *Argv0,
return 0;
}
Message = "Found llc: " + LLCPath.toString() + "\n";
Message = "Found llc: " + LLCPath.str() + "\n";
GCC *gcc = GCC::create(Message, GCCArgs);
if (!gcc) {
errs() << Message << "\n";
@ -757,7 +758,7 @@ int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
errs() << "Error making unique filename: " << ErrMsg << "\n";
exit(1);
}
OutputFile = uniqueFilename.toString();
OutputFile = uniqueFilename.str();
std::vector<const char*> GCCArgs;
@ -839,6 +840,6 @@ GCC *GCC::create(std::string &Message,
if (!RemoteClient.empty())
RemoteClientPath = sys::Program::FindProgramByName(RemoteClient);
Message = "Found gcc: " + GCCPath.toString() + "\n";
Message = "Found gcc: " + GCCPath.str() + "\n";
return new GCC(GCCPath, RemoteClientPath, Args);
}

View File

@ -28,6 +28,7 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PluginLoader.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Process.h"
#include "llvm/System/Signals.h"
#include "llvm/Target/TargetSelect.h"

View File

@ -364,7 +364,7 @@ bool doPrint(std::string* ErrMsg) {
continue;
if (Verbose)
std::cout << "Printing " << I->getPath().toString() << "\n";
std::cout << "Printing " << I->getPath().str() << "\n";
unsigned len = I->getSize();
std::cout.write(data, len);
@ -422,11 +422,10 @@ doDisplayTable(std::string* ErrMsg) {
std::cout << " " << std::setw(4) << I->getUser();
std::cout << "/" << std::setw(4) << I->getGroup();
std::cout << " " << std::setw(8) << I->getSize();
std::cout << " " << std::setw(20) <<
I->getModTime().toString().substr(4);
std::cout << " " << I->getPath().toString() << "\n";
std::cout << " " << std::setw(20) << I->getModTime().str().substr(4);
std::cout << " " << I->getPath().str() << "\n";
} else {
std::cout << I->getPath().toString() << "\n";
std::cout << I->getPath().str() << "\n";
}
}
}
@ -528,7 +527,7 @@ doMove(std::string* ErrMsg) {
if (AddBefore || InsertBefore || AddAfter) {
for (Archive::iterator I = TheArchive->begin(), E= TheArchive->end();
I != E; ++I ) {
if (RelPos == I->getPath().toString()) {
if (RelPos == I->getPath().str()) {
if (AddAfter) {
moveto_spot = I;
moveto_spot++;
@ -616,7 +615,7 @@ doReplaceOrInsert(std::string* ErrMsg) {
std::set<sys::Path>::iterator found = remaining.end();
for (std::set<sys::Path>::iterator RI = remaining.begin(),
RE = remaining.end(); RI != RE; ++RI ) {
std::string compare(RI->toString());
std::string compare(RI->str());
if (TruncateNames && compare.length() > 15) {
const char* nm = compare.c_str();
unsigned len = compare.length();
@ -629,7 +628,7 @@ doReplaceOrInsert(std::string* ErrMsg) {
len = 15;
compare.assign(nm,len);
}
if (compare == I->getPath().toString()) {
if (compare == I->getPath().str()) {
found = RI;
break;
}
@ -661,9 +660,9 @@ doReplaceOrInsert(std::string* ErrMsg) {
}
// Determine if this is the place where we should insert
if ((AddBefore || InsertBefore) && (RelPos == I->getPath().toString()))
if ((AddBefore || InsertBefore) && RelPos == I->getPath().str())
insert_spot = I;
else if (AddAfter && (RelPos == I->getPath().toString())) {
else if (AddAfter && RelPos == I->getPath().str()) {
insert_spot = I;
insert_spot++;
}
@ -719,14 +718,14 @@ int main(int argc, char **argv) {
if (!ArchivePath.exists()) {
// Produce a warning if we should and we're creating the archive
if (!Create)
errs() << argv[0] << ": creating " << ArchivePath.toString() << "\n";
errs() << argv[0] << ": creating " << ArchivePath.str() << "\n";
TheArchive = Archive::CreateEmpty(ArchivePath, Context);
TheArchive->writeToDisk();
} else {
std::string Error;
TheArchive = Archive::OpenAndLoad(ArchivePath, Context, &Error);
if (TheArchive == 0) {
errs() << argv[0] << ": error loading '" << ArchivePath << "': "
errs() << argv[0] << ": error loading '" << ArchivePath.str() << "': "
<< Error << "!\n";
return 1;
}

View File

@ -35,6 +35,7 @@
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Signals.h"
#include <map>
#include <algorithm>

View File

@ -19,8 +19,8 @@
#include "llvm/Debugger/SourceFile.h"
#include "llvm/Debugger/InferiorProcess.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/ADT/StringExtras.h"
#include <iostream>
#include <cstdlib>
using namespace llvm;
@ -56,7 +56,7 @@ void CLIDebugger::startProgramRunning() {
if (!Status)
throw Err;
if (TheProgramInfo->getProgramTimeStamp() != Status->getTimestamp()) {
std::cout << "'" << Program << "' has changed; re-reading program.\n";
outs() << "'" << Program.str() << "' has changed; re-reading program.\n";
// Unload an existing program. This kills the program if necessary.
Dbg.unloadProgram();
@ -64,11 +64,11 @@ void CLIDebugger::startProgramRunning() {
TheProgramInfo = 0;
CurrentFile = 0;
Dbg.loadProgram(Program.toString(), Context);
Dbg.loadProgram(Program.str(), Context);
TheProgramInfo = new ProgramInfo(Dbg.getProgram());
}
std::cout << "Starting program: " << Dbg.getProgramPath() << "\n";
outs() << "Starting program: " << Dbg.getProgramPath() << "\n";
Dbg.createProgram();
// There was no current frame.
@ -83,7 +83,7 @@ bool CLIDebugger::printSourceLine(unsigned LineNo) {
const char *LineStart, *LineEnd;
CurrentFile->getSourceLine(LineNo-1, LineStart, LineEnd);
if (LineStart == 0) return true;
std::cout << LineNo;
outs() << LineNo;
// If this is the line the program is currently stopped at, print a marker.
if (Dbg.isProgramRunning()) {
@ -93,10 +93,10 @@ bool CLIDebugger::printSourceLine(unsigned LineNo) {
CurSFI);
if (CurLineNo == LineNo && CurrentFile == &CurSFI->getSourceText())
std::cout << " ->";
outs() << " ->";
}
std::cout << "\t" << std::string(LineStart, LineEnd) << "\n";
outs() << "\t" << std::string(LineStart, LineEnd) << "\n";
return false;
}
@ -117,19 +117,19 @@ void CLIDebugger::printProgramLocation(bool PrintLocation) {
if (PrintLocation) {
// FIXME: print the current function arguments
if (const GlobalVariable *FuncDesc = SF.getFunctionDesc())
std::cout << getProgramInfo().getFunction(FuncDesc).getSymbolicName();
outs() << getProgramInfo().getFunction(FuncDesc).getSymbolicName();
else
std::cout << "<unknown function>";
outs() << "<unknown function>";
CurrentFile = &FileDesc->getSourceText();
std::cout << " at " << CurrentFile->getFilename() << ":" << LineNo;
if (ColNo) std::cout << ":" << ColNo;
std::cout << "\n";
outs() << " at " << CurrentFile->getFilename() << ":" << LineNo;
if (ColNo) outs() << ":" << ColNo;
outs() << "\n";
}
if (printSourceLine(LineNo))
std::cout << "<could not load source file>\n";
outs() << "<could not load source file>\n";
else {
LineListedStart = LineNo-ListSize/2+1;
if ((int)LineListedStart < 1) LineListedStart = 1;
@ -241,14 +241,15 @@ void CLIDebugger::fileCommand(std::string &Options) {
// If requested, start the new program.
if (Prog.empty()) {
std::cout << "Unloaded program.\n";
outs() << "Unloaded program.\n";
} else {
std::cout << "Loading program... " << std::flush;
outs() << "Loading program... ";
outs().flush();
Dbg.loadProgram(Prog, Context);
assert(Dbg.isProgramLoaded() &&
"loadProgram succeeded, but not program loaded!");
TheProgramInfo = new ProgramInfo(Dbg.getProgram());
std::cout << "successfully loaded '" << Dbg.getProgramPath() << "'!\n";
outs() << "successfully loaded '" << Dbg.getProgramPath() << "'!\n";
}
}
@ -391,29 +392,29 @@ void CLIDebugger::backtraceCommand(std::string &Options) {
try {
for (unsigned i = 0; ; ++i) {
StackFrame &SF = RI.getStackFrame(i);
std::cout << "#" << i;
outs() << "#" << i;
if (i == RI.getCurrentFrameIdx())
std::cout << " ->";
std::cout << "\t" << SF.getFrameID() << " in ";
outs() << " ->";
outs() << "\t" << SF.getFrameID() << " in ";
if (const GlobalVariable *G = SF.getFunctionDesc())
std::cout << PI.getFunction(G).getSymbolicName();
outs() << PI.getFunction(G).getSymbolicName();
unsigned LineNo, ColNo;
const SourceFileInfo *SFI;
SF.getSourceLocation(LineNo, ColNo, SFI);
if (!SFI->getBaseName().empty()) {
std::cout << " at " << SFI->getBaseName();
outs() << " at " << SFI->getBaseName();
if (LineNo) {
std::cout << ":" << LineNo;
outs() << ":" << LineNo;
if (ColNo)
std::cout << ":" << ColNo;
outs() << ":" << ColNo;
}
}
// FIXME: when we support shared libraries, we should print ' from foo.so'
// if the stack frame is from a different object than the current one.
std::cout << "\n";
outs() << "\n";
}
} catch (...) {
// Stop automatically when we run off the bottom of the stack.
@ -522,11 +523,11 @@ void CLIDebugger::infoCommand(std::string &Options) {
} else if (What == "functions") {
const std::map<const GlobalVariable*, SourceFunctionInfo*> &Functions
= getProgramInfo().getSourceFunctions();
std::cout << "All defined functions:\n";
outs() << "All defined functions:\n";
// FIXME: GDB groups these by source file. We could do that I guess.
for (std::map<const GlobalVariable*, SourceFunctionInfo*>::const_iterator
I = Functions.begin(), E = Functions.end(); I != E; ++I) {
std::cout << I->second->getSymbolicName() << "\n";
outs() << I->second->getSymbolicName() << "\n";
}
} else if (What == "source") {
@ -537,30 +538,30 @@ void CLIDebugger::infoCommand(std::string &Options) {
const SourceFileInfo &SF =
getProgramInfo().getSourceFile(CurrentFile->getDescriptor());
std::cout << "Current source file is: " << SF.getBaseName() << "\n"
<< "Compilation directory is: " << SF.getDirectory() << "\n";
outs() << "Current source file is: " << SF.getBaseName() << "\n"
<< "Compilation directory is: " << SF.getDirectory() << "\n";
if (unsigned NL = CurrentFile->getNumLines())
std::cout << "Located in: " << CurrentFile->getFilename() << "\n"
<< "Contains " << NL << " lines\n";
outs() << "Located in: " << CurrentFile->getFilename() << "\n"
<< "Contains " << NL << " lines\n";
else
std::cout << "Could not find source file.\n";
std::cout << "Source language is "
<< SF.getLanguage().getSourceLanguageName() << "\n";
outs() << "Could not find source file.\n";
outs() << "Source language is "
<< SF.getLanguage().getSourceLanguageName() << "\n";
} else if (What == "sources") {
const std::map<const GlobalVariable*, SourceFileInfo*> &SourceFiles =
getProgramInfo().getSourceFiles();
std::cout << "Source files for the program:\n";
outs() << "Source files for the program:\n";
for (std::map<const GlobalVariable*, SourceFileInfo*>::const_iterator I =
SourceFiles.begin(), E = SourceFiles.end(); I != E;) {
std::cout << I->second->getDirectory() << "/"
<< I->second->getBaseName();
outs() << I->second->getDirectory() << "/"
<< I->second->getBaseName();
++I;
if (I != E) std::cout << ", ";
if (I != E) outs() << ", ";
}
std::cout << "\n";
outs() << "\n";
} else if (What == "target") {
std::cout << Dbg.getRunningProcess().getStatus();
outs() << Dbg.getRunningProcess().getStatus();
} else {
// See if this is something handled by the current language.
if (getCurrentLanguage().printInfo(What))
@ -746,7 +747,7 @@ void CLIDebugger::listCommand(std::string &Options) {
if (LineStart == 0)
throw "Could not load source file '" + CurrentFile->getFilename() + "'!";
else
std::cout << "<end of file>\n";
outs() << "<end of file>\n";
}
}
@ -762,11 +763,11 @@ void CLIDebugger::setCommand(std::string &Options) {
if (!getToken(Options).empty())
throw "set language expects one argument at most.";
if (Lang == "") {
std::cout << "The currently understood settings are:\n\n"
<< "local or auto Automatic setting based on source file\n"
<< "c Use the C language\n"
<< "c++ Use the C++ language\n"
<< "unknown Use when source language is not supported\n";
outs() << "The currently understood settings are:\n\n"
<< "local or auto Automatic setting based on source file\n"
<< "c Use the C language\n"
<< "c++ Use the C++ language\n"
<< "unknown Use when source language is not supported\n";
} else if (Lang == "local" || Lang == "auto") {
CurrentLanguage = 0;
} else if (Lang == "c") {
@ -799,28 +800,28 @@ void CLIDebugger::showCommand(std::string &Options) {
throw "show command expects one argument.";
if (What == "args") {
std::cout << "Argument list to give program when started is \"";
outs() << "Argument list to give program when started is \"";
// FIXME: This doesn't print stuff correctly if the arguments have spaces in
// them, but currently the only way to get that is to use the --args command
// line argument. This should really handle escaping all hard characters as
// needed.
for (unsigned i = 0, e = Dbg.getNumProgramArguments(); i != e; ++i)
std::cout << (i ? " " : "") << Dbg.getProgramArgument(i);
std::cout << "\"\n";
outs() << (i ? " " : "") << Dbg.getProgramArgument(i);
outs() << "\"\n";
} else if (What == "language") {
std::cout << "The current source language is '";
outs() << "The current source language is '";
if (CurrentLanguage)
std::cout << CurrentLanguage->getSourceLanguageName();
outs() << CurrentLanguage->getSourceLanguageName();
else
std::cout << "auto; currently "
<< getCurrentLanguage().getSourceLanguageName();
std::cout << "'.\n";
outs() << "auto; currently "
<< getCurrentLanguage().getSourceLanguageName();
outs() << "'.\n";
} else if (What == "listsize") {
std::cout << "Number of source lines llvm-db will list by default is "
<< ListSize << ".\n";
outs() << "Number of source lines llvm-db will list by default is "
<< ListSize << ".\n";
} else if (What == "prompt") {
std::cout << "llvm-db's prompt is \"" << Prompt << "\".\n";
outs() << "llvm-db's prompt is \"" << Prompt << "\".\n";
} else {
throw "Unknown show command '" + What + "'. Try 'help show'.";
}
@ -835,16 +836,16 @@ void CLIDebugger::helpCommand(std::string &Options) {
// Getting detailed help on a particular command?
if (!Command.empty()) {
CLICommand *C = getCommand(Command);
std::cout << C->getShortHelp() << ".\n" << C->getLongHelp();
outs() << C->getShortHelp() << ".\n" << C->getLongHelp();
// If there are aliases for this option, print them out.
const std::vector<std::string> &Names = C->getOptionNames();
if (Names.size() > 1) {
std::cout << "The '" << Command << "' command is known as: '"
<< Names[0] << "'";
outs() << "The '" << Command << "' command is known as: '"
<< Names[0] << "'";
for (unsigned i = 1, e = Names.size(); i != e; ++i)
std::cout << ", '" << Names[i] << "'";
std::cout << "\n";
outs() << ", '" << Names[i] << "'";
outs() << "\n";
}
} else {
@ -859,7 +860,7 @@ void CLIDebugger::helpCommand(std::string &Options) {
for (std::map<std::string, CLICommand*>::iterator I = CommandTable.begin(),
E = CommandTable.end(); I != E; ++I)
if (I->first == I->second->getPrimaryOptionName())
std::cout << I->first << std::string(MaxSize - I->first.size(), ' ')
<< " - " << I->second->getShortHelp() << "\n";
outs() << I->first << std::string(MaxSize - I->first.size(), ' ')
<< " - " << I->second->getShortHelp() << "\n";
}
}

View File

@ -17,8 +17,8 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Signals.h"
#include <iostream>
using namespace llvm;
namespace {
@ -57,13 +57,13 @@ int main(int argc, char **argv, char * const *envp) {
LLVMContext &Context = getGlobalContext();
llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
std::cout << "NOTE: llvm-db is known useless right now.\n";
outs() << "NOTE: llvm-db is known useless right now.\n";
try {
cl::ParseCommandLineOptions(argc, argv,
"llvm source-level debugger\n");
if (!Quiet)
std::cout << "llvm-db: The LLVM source-level debugger\n";
outs() << "llvm-db: The LLVM source-level debugger\n";
// Merge Inputfile and InputArgs into the InputArgs list...
if (!InputFile.empty() && InputArgs.empty())
@ -85,7 +85,7 @@ int main(int argc, char **argv, char * const *envp) {
try {
D.fileCommand(InputArgs[0]);
} catch (const std::string &Error) {
std::cout << "Error: " << Error << "\n";
outs() << "Error: " << Error << "\n";
}
Dbg.setProgramArguments(InputArgs.begin()+1, InputArgs.end());

View File

@ -35,6 +35,7 @@
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/SystemUtils.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Signals.h"
#include "llvm/Config/config.h"
#include <memory>
@ -466,7 +467,7 @@ static void EmitShellScript(char **argv) {
if (FullLibraryPath.isEmpty())
FullLibraryPath = sys::Path::FindLibrary(*i);
if (!FullLibraryPath.isEmpty())
Out2 << " -load=" << FullLibraryPath.toString() << " \\\n";
Out2 << " -load=" << FullLibraryPath.str() << " \\\n";
}
Out2 << " " << BitcodeOutputFilename << " ${1+\"$@\"}\n";
Out2.close();
@ -572,7 +573,7 @@ int main(int argc, char **argv, char **envp) {
sys::Path ExeFile( OutputFilename );
if (ExeFile.getSuffix() == "") {
ExeFile.appendSuffix("exe");
OutputFilename = ExeFile.toString();
OutputFilename = ExeFile.str();
}
}
#endif
@ -652,11 +653,11 @@ int main(int argc, char **argv, char **envp) {
// Generate an assembly language file for the bitcode.
std::string ErrMsg;
if (0 != GenerateAssembly(AssemblyFile.toString(), BitcodeOutputFilename,
if (0 != GenerateAssembly(AssemblyFile.str(), BitcodeOutputFilename,
llc, ErrMsg))
PrintAndExit(ErrMsg);
if (0 != GenerateNative(OutputFilename, AssemblyFile.toString(),
if (0 != GenerateNative(OutputFilename, AssemblyFile.str(),
NativeLinkItems, gcc, envp, ErrMsg))
PrintAndExit(ErrMsg);
@ -682,12 +683,11 @@ int main(int argc, char **argv, char **envp) {
// Generate an assembly language file for the bitcode.
std::string ErrMsg;
if (0 != GenerateCFile(
CFile.toString(), BitcodeOutputFilename, llc, ErrMsg))
if (GenerateCFile(CFile.str(), BitcodeOutputFilename, llc, ErrMsg))
PrintAndExit(ErrMsg);
if (0 != GenerateNative(OutputFilename, CFile.toString(),
NativeLinkItems, gcc, envp, ErrMsg))
if (GenerateNative(OutputFilename, CFile.str(),
NativeLinkItems, gcc, envp, ErrMsg))
PrintAndExit(ErrMsg);
// Remove the assembly language file.

View File

@ -21,6 +21,7 @@
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Signals.h"
#include "llvm/System/Path.h"
#include <memory>
@ -58,7 +59,7 @@ static inline std::auto_ptr<Module> LoadFile(const std::string &FN,
if (Verbose) errs() << "Loading '" << Filename.c_str() << "'\n";
Module* Result = 0;
const std::string &FNStr = Filename.toString();
const std::string &FNStr = Filename.str();
if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(FNStr,
&ErrorMessage)) {
Result = ParseBitcodeFile(Buffer, Context, &ErrorMessage);

View File

@ -202,9 +202,8 @@ const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg)
sys::RemoveFileOnSignal(uniqueObjPath);
// assemble the assembly code
const std::string& uniqueObjStr = uniqueObjPath.toString();
bool asmResult = this->assemble(uniqueAsmPath.toString(),
uniqueObjStr, errMsg);
const std::string& uniqueObjStr = uniqueObjPath.str();
bool asmResult = this->assemble(uniqueAsmPath.str(), uniqueObjStr, errMsg);
if ( !asmResult ) {
// remove old buffer if compile() called twice
delete _nativeObjectFile;

View File

@ -1330,9 +1330,9 @@ void EmitCmdLineVecFill(const Init* CmdLine, const std::string& ToolName,
O << "for (PathVector::const_iterator B = inFiles.begin()"
<< ", E = inFiles.end();\n"
<< IndentLevel << "B != E; ++B)\n"
<< IndentLevel << Indent1 << "vec.push_back(B->toString());\n";
<< IndentLevel << Indent1 << "vec.push_back(B->str());\n";
else
O << "vec.push_back(inFile.toString());\n";
O << "vec.push_back(inFile.str());\n";
}
else if (cmd == "$OUTFILE") {
O << "vec.push_back(out_file);\n";
@ -1556,7 +1556,7 @@ void EmitGenerateActionMethod (const ToolDescription& D,
O << '\n' << Indent2
<< "out_file = OutFilename(" << (IsJoin ? "sys::Path(),\n" : "inFile,\n")
<< Indent3 << "TempDir, stop_compilation, output_suffix).toString();\n\n";
<< Indent3 << "TempDir, stop_compilation, output_suffix).str();\n\n";
// cmd_line is either a string or a 'case' construct.
if (!D.CmdLine)