llvm.org GIT mirror llvm / 74382b7
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 Chris Lattner 10 years ago
39 changed file(s) with 262 addition(s) and 293 deletion(s). Raw diff Collapse all Expand all
5959
6060 /// getFilename - Return the fully resolved path that this file was loaded
6161 /// from.
62 const std::string &getFilename() const { return Filename.toString(); }
62 const std::string &getFilename() const { return Filename.str(); }
6363
6464 /// getSourceLine - Given a line number, return the start and end of the
6565 /// line in the file. If the line number is invalid, or if the file could
1313 #ifndef LLVM_LINKER_H
1414 #define LLVM_LINKER_H
1515
16 #include "llvm/System/Path.h"
1716 #include
1817 #include
18 #include "llvm/ADT/StringRef.h"
1919
2020 namespace llvm {
21 namespace sys { class Path; }
2122
2223 class Module;
2324 class LLVMContext;
6364 /// Construct the Linker with an empty module which will be given the
6465 /// name \p progname. \p progname will also be used for error messages.
6566 /// @brief Construct with empty module
66 Linker(
67 const StringRef& progname, ///< name of tool running linker
68 const StringRef& modulename, ///< name of linker's end-result module
69 LLVMContext& C, ///< Context for global info
70 unsigned Flags = 0 ///< ControlFlags (one or more |'d together)
67 Linker(const StringRef &progname, ///< name of tool running linker
68 const StringRef &modulename, ///< name of linker's end-result module
69 LLVMContext &C, ///< Context for global info
70 unsigned Flags = 0 ///< ControlFlags (one or more |'d together)
7171 );
7272
7373 /// Construct the Linker with a previously defined module, \p aModule. Use
256256 }
257257
258258 template
259 sys::Path WriteGraph(const GraphType &G,
260 const std::string& Name,
261 bool ShortNames = false,
262 const std::string& Title = "") {
259 sys::Path WriteGraph(const GraphType &G, const std::string &Name,
260 bool ShortNames = false, const std::string &Title = "") {
263261 std::string ErrMsg;
264262 sys::Path Filename = sys::Path::GetTemporaryDirectory(&ErrMsg);
265263 if (Filename.isEmpty()) {
272270 return sys::Path();
273271 }
274272
275 errs() << "Writing '" << Filename << "'... ";
273 errs() << "Writing '" << Filename.str() << "'... ";
276274
277275 std::string ErrorInfo;
278276 raw_fd_ostream O(Filename.c_str(), ErrorInfo, raw_fd_ostream::F_Force);
281279 WriteGraph(O, G, ShortNames, Name, Title);
282280 errs() << " done. \n";
283281 } else {
284 errs() << "error opening file '" << Filename << "' for writing!\n";
282 errs() << "error opening file '" << Filename.str() << "' for writing!\n";
285283 Filename.clear();
286284 }
287285
292290 /// then cleanup. For use from the debugger.
293291 ///
294292 template
295 void ViewGraph(const GraphType& G,
296 const std::string& Name,
297 bool ShortNames = false,
298 const std::string& Title = "",
293 void ViewGraph(const GraphType &G, const std::string &Name,
294 bool ShortNames = false, const std::string &Title = "",
299295 GraphProgram::Name Program = GraphProgram::DOT) {
300 sys::Path Filename = WriteGraph(G, Name, ShortNames, Title);
301
302 if (Filename.isEmpty()) {
296 sys::Path Filename = WriteGraph(G, Name, ShortNames, Title);
297
298 if (Filename.isEmpty())
303299 return;
304 }
305300
306301 DisplayGraph(Filename, true, Program);
307302 }
1414 #define LLVM_SYSTEM_PATH_H
1515
1616 #include "llvm/System/TimeValue.h"
17 #include "llvm/Support/raw_ostream.h"
1817 #include
1918 #include
2019 #include
21 #include
2220
2321 namespace llvm {
2422 namespace sys {
216214 /// Compares \p this Path with \p that Path for inequality.
217215 /// @returns true if \p this and \p that refer to different things.
218216 /// @brief Inequality Operator
219 bool operator!=(const Path &that) const;
217 bool operator!=(const Path &that) const { return !(*this == that); }
220218
221219 /// Determines if \p this Path is less than \p that Path. This is required
222220 /// so that Path objects can be placed into ordered collections (e.g.
248246 /// @brief Determines if the path name is empty (invalid).
249247 bool isEmpty() const { return path.empty(); }
250248
251 /// This function returns the current contents of the path as a
252 /// std::string. This allows the underlying path string to be manipulated.
253 /// @returns std::string containing the path name.
254 /// @brief Returns the path as a std::string.
255 const std::string &toString() const { return path; }
256
257 /// This function returns the last component of the path name. The last
249 /// This function returns the last component of the path name. The last
258250 /// component is the file or directory name occuring after the last
259251 /// directory separator. If no directory separator is present, the entire
260252 /// path name is returned (i.e. same as toString).
285277 /// @returns a 'C' string containing the path name.
286278 /// @brief Returns the path as a C string.
287279 const char *c_str() const { return path.c_str(); }
280 const std::string &str() const { return path; }
281
288282
289283 /// size - Return the length in bytes of this path name.
290284 size_t size() const { return path.size(); }
715709 extern const char PathSeparator;
716710 }
717711
718 inline raw_ostream& operator<<(raw_ostream& strm, const sys::Path& aPath) {
719 strm << aPath.toString();
720 return strm;
721712 }
722713
723 inline raw_ostream& operator<<(raw_ostream& strm,
724 const sys::PathWithStatus& aPath) {
725 strm << static_cast(aPath);
726 return strm;
727 }
728
729 std::ostream& operator<<(std::ostream& strm, const sys::Path& aPath);
730 inline std::ostream& operator<<(std::ostream& strm,
731 const sys::PathWithStatus& aPath) {
732 strm << static_cast(aPath);
733 return strm;
734 }
735
736 }
737
738714 #endif
270270 /// Provides conversion of the TimeValue into a readable time & date.
271271 /// @returns std::string containing the readable time value
272272 /// @brief Convert time to a string.
273 std::string toString() const;
273 std::string str() const;
274274
275275 /// @}
276276 /// @name Mutators
3030
3131 // If it has a long filename, include the name length
3232 if (hasLongFilename())
33 result += path.toString().length() + 1;
33 result += path.str().length() + 1;
3434
3535 // If its now odd lengthed, include the padding byte
3636 if (result % 2 != 0 )
7575 path = newFile;
7676
7777 // SVR4 symbol tables have an empty name
78 if (path.toString() == ARFILE_SVR4_SYMTAB_NAME)
78 if (path.str() == ARFILE_SVR4_SYMTAB_NAME)
7979 flags |= SVR4SymbolTableFlag;
8080 else
8181 flags &= ~SVR4SymbolTableFlag;
8282
8383 // BSD4.4 symbol tables have a special name
84 if (path.toString() == ARFILE_BSD4_SYMTAB_NAME)
84 if (path.str() == ARFILE_BSD4_SYMTAB_NAME)
8585 flags |= BSD4SymbolTableFlag;
8686 else
8787 flags &= ~BSD4SymbolTableFlag;
8888
8989 // LLVM symbol tables have a very specific name
90 if (path.toString() == ARFILE_LLVM_SYMTAB_NAME)
90 if (path.str() == ARFILE_LLVM_SYMTAB_NAME)
9191 flags |= LLVMSymbolTableFlag;
9292 else
9393 flags &= ~LLVMSymbolTableFlag;
9494
9595 // String table name
96 if (path.toString() == ARFILE_STRTAB_NAME)
96 if (path.str() == ARFILE_STRTAB_NAME)
9797 flags |= StringTableFlag;
9898 else
9999 flags &= ~StringTableFlag;
100100
101101 // If it has a slash then it has a path
102 bool hasSlash = path.toString().find('/') != std::string::npos;
102 bool hasSlash = path.str().find('/') != std::string::npos;
103103 if (hasSlash)
104104 flags |= HasPathFlag;
105105 else
106106 flags &= ~HasPathFlag;
107107
108108 // If it has a slash or its over 15 chars then its a long filename format
109 if (hasSlash || path.toString().length() > 15)
109 if (hasSlash || path.str().length() > 15)
110110 flags |= HasLongFilenameFlag;
111111 else
112112 flags &= ~HasLongFilenameFlag;
216216 std::auto_ptr Buffer(
217217 MemoryBuffer::getFileOrSTDIN(fName.c_str()));
218218 if (!Buffer.get()) {
219 if (ErrMsg) *ErrMsg = "Could not open file '" + fName.toString() + "'";
219 if (ErrMsg) *ErrMsg = "Could not open file '" + fName.str() + "'";
220220 return true;
221221 }
222222
343343
344344 for (iterator I=begin(), E=end(); I != E; ++I) {
345345 if (I->isBitcode()) {
346 std::string FullMemberName = archPath.toString() +
347 "(" + I->getPath().toString() + ")";
346 std::string FullMemberName = archPath.str() +
347 "(" + I->getPath().str() + ")";
348348 MemoryBuffer *Buffer =
349349 MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str());
350350 memcpy((char*)Buffer->getBufferStart(), I->getData(), I->getSize());
483483 return 0;
484484
485485 // Now, load the bitcode module to get the ModuleProvider
486 std::string FullMemberName = archPath.toString() + "(" +
487 mbr->getPath().toString() + ")";
486 std::string FullMemberName = archPath.str() + "(" +
487 mbr->getPath().str() + ")";
488488 MemoryBuffer *Buffer =MemoryBuffer::getNewMemBuffer(mbr->getSize(),
489489 FullMemberName.c_str());
490490 memcpy((char*)Buffer->getBufferStart(), mbr->getData(), mbr->getSize());
533533 if (mbr->isBitcode()) {
534534 // Get the symbols
535535 std::vector symbols;
536 std::string FullMemberName = archPath.toString() + "(" +
537 mbr->getPath().toString() + ")";
536 std::string FullMemberName = archPath.str() + "(" +
537 mbr->getPath().str() + ")";
538538 ModuleProvider* MP =
539539 GetBitcodeSymbols((const unsigned char*)At, mbr->getSize(),
540540 FullMemberName, Context, symbols, error);
551551 } else {
552552 if (error)
553553 *error = "Can't parse bitcode member: " +
554 mbr->getPath().toString() + ": " + *error;
554 mbr->getPath().str() + ": " + *error;
555555 delete mbr;
556556 return false;
557557 }
611611 continue;
612612
613613 std::string FullMemberName =
614 archPath.toString() + "(" + I->getPath().toString() + ")";
614 archPath.str() + "(" + I->getPath().str() + ")";
615615
616616 MemoryBuffer *Buffer =
617617 MemoryBuffer::getNewMemBuffer(I->getSize(), FullMemberName.c_str());
9494 memcpy(hdr.date,buffer,12);
9595
9696 // Get rid of trailing blanks in the name
97 std::string mbrPath = mbr.getPath().toString();
97 std::string mbrPath = mbr.getPath().str();
9898 size_t mbrLen = mbrPath.length();
9999 while (mbrLen > 0 && mbrPath[mbrLen-1] == ' ') {
100100 mbrPath.erase(mbrLen-1,1);
172172 mbr->info = *FSInfo;
173173
174174 unsigned flags = 0;
175 bool hasSlash = filePath.toString().find('/') != std::string::npos;
175 bool hasSlash = filePath.str().find('/') != std::string::npos;
176176 if (hasSlash)
177177 flags |= ArchiveMember::HasPathFlag;
178 if (hasSlash || filePath.toString().length() > 15)
178 if (hasSlash || filePath.str().length() > 15)
179179 flags |= ArchiveMember::HasLongFilenameFlag;
180180 std::string magic;
181181 mbr->path.getMagicNumber(magic,4);
222222 // symbol table if its a bitcode file.
223223 if (CreateSymbolTable && member.isBitcode()) {
224224 std::vector symbols;
225 std::string FullMemberName = archPath.toString() + "(" +
226 member.getPath().toString()
225 std::string FullMemberName = archPath.str() + "(" + member.getPath().str()
227226 + ")";
228227 ModuleProvider* MP =
229228 GetBitcodeSymbols((const unsigned char*)data,fSize,
248247 } else {
249248 delete mFile;
250249 if (ErrMsg)
251 *ErrMsg = "Can't parse bitcode member: " + member.getPath().toString()
250 *ErrMsg = "Can't parse bitcode member: " + member.getPath().str()
252251 + ": " + *ErrMsg;
253252 return true;
254253 }
265264
266265 // Write the long filename if its long
267266 if (writeLongName) {
268 ARFile.write(member.getPath().toString().data(),
269 member.getPath().toString().length());
267 ARFile.write(member.getPath().str().data(),
268 member.getPath().str().length());
270269 }
271270
272271 // Write the (possibly compressed) member's content to the file.
370369 if (TmpArchive.exists())
371370 TmpArchive.eraseFromDisk();
372371 if (ErrMsg)
373 *ErrMsg = "Error opening archive file: " + archPath.toString();
372 *ErrMsg = "Error opening archive file: " + archPath.str();
374373 return true;
375374 }
376375
424423 if (TmpArchive.exists())
425424 TmpArchive.eraseFromDisk();
426425 if (ErrMsg)
427 *ErrMsg = "Error opening archive file: " + FinalFilePath.toString();
426 *ErrMsg = "Error opening archive file: " + FinalFilePath.str();
428427 return true;
429428 }
430429
13421342 FullPath.appendComponent(getSourceFileName(Id.second));
13431343 assert(AppendOk && "Could not append filename to directory!");
13441344 AppendOk = false;
1345 Asm->EmitFile(i, FullPath.toString());
1345 Asm->EmitFile(i, FullPath.str());
13461346 Asm->EOL();
13471347 }
13481348 }
2121 #include "llvm/Module.h"
2222 #include "llvm/Debugger/SourceFile.h"
2323 #include "llvm/Debugger/SourceLanguage.h"
24 #include "llvm/Support/raw_ostream.h"
2425 #include "llvm/Support/SlowOperationInformer.h"
2526 #include "llvm/ADT/STLExtras.h"
2627 using namespace llvm;
134135 tmpPath.set(Directory);
135136 tmpPath.appendComponent(BaseName);
136137 if (tmpPath.canRead())
137 SourceText = new SourceFile(tmpPath.toString(), Descriptor);
138 SourceText = new SourceFile(tmpPath.str(), Descriptor);
138139 else
139140 SourceText = new SourceFile(BaseName, Descriptor);
140141 }
9595 Linker::LinkInArchive(const sys::Path &Filename, bool &is_native) {
9696 // Make sure this is an archive file we're dealing with
9797 if (!Filename.isArchive())
98 return error("File '" + Filename.toString() + "' is not an archive.");
98 return error("File '" + Filename.str() + "' is not an archive.");
9999
100100 // Open the archive file
101 verbose("Linking archive file '" + Filename.toString() + "'");
101 verbose("Linking archive file '" + Filename.str() + "'");
102102
103103 // Find all of the symbols currently undefined in the bitcode program.
104104 // If all the symbols are defined, the program is complete, and there is
107107 GetAllUndefinedSymbols(Composite, UndefinedSymbols);
108108
109109 if (UndefinedSymbols.empty()) {
110 verbose("No symbols undefined, skipping library '" +
111 Filename.toString() + "'");
110 verbose("No symbols undefined, skipping library '" + Filename.str() + "'");
112111 return false; // No need to link anything in!
113112 }
114113
119118 Archive* arch = AutoArch.get();
120119
121120 if (!arch)
122 return error("Cannot read archive '" + Filename.toString() +
121 return error("Cannot read archive '" + Filename.str() +
123122 "': " + ErrMsg);
124123 if (!arch->isBitcodeArchive()) {
125124 is_native = true;
142141 // Find the modules we need to link into the target module
143142 std::set Modules;
144143 if (!arch->findModulesDefiningSymbols(UndefinedSymbols, Modules, &ErrMsg))
145 return error("Cannot find symbols in '" + Filename.toString() +
144 return error("Cannot find symbols in '" + Filename.str() +
146145 "': " + ErrMsg);
147146
148147 // If we didn't find any more modules to link this time, we are done
1313
1414 #include "llvm/Linker.h"
1515 #include "llvm/Module.h"
16 #include "llvm/Bitcode/ReaderWriter.h"
17 #include "llvm/System/Path.h"
1618 #include "llvm/Support/ErrorHandling.h"
1719 #include "llvm/Support/MemoryBuffer.h"
18 #include "llvm/Bitcode/ReaderWriter.h"
19
2020 using namespace llvm;
2121
2222 // LinkItems - This function is the main entry point into linking. It takes a
9292
9393 case sys::Archive_FileType:
9494 if (LinkInArchive(Pathname, is_native))
95 return error("Cannot link archive '" + Pathname.toString() + "'");
95 return error("Cannot link archive '" + Pathname.str() + "'");
9696 break;
9797
9898 case sys::ELF_Relocatable_FileType:
157157 is_native = false;
158158
159159 // Check for a file of name "-", which means "read standard input"
160 if (File.toString() == "-") {
160 if (File.str() == "-") {
161161 std::auto_ptr M;
162162 if (MemoryBuffer *Buffer = MemoryBuffer::getSTDIN()) {
163163 M.reset(ParseBitcodeFile(Buffer, Context, &Error));
172172
173173 // Make sure we can at least read the file
174174 if (!File.canRead())
175 return error("Cannot find linker input '" + File.toString() + "'");
175 return error("Cannot find linker input '" + File.str() + "'");
176176
177177 // If its an archive, try to link it in
178178 std::string Magic;
180180 switch (sys::IdentifyFileType(Magic.c_str(), 64)) {
181181 default: llvm_unreachable("Bad file type identification");
182182 case sys::Unknown_FileType:
183 return warning("Ignoring file '" + File.toString() +
183 return warning("Ignoring file '" + File.str() +
184184 "' because does not contain bitcode.");
185185
186186 case sys::Archive_FileType:
187187 // A user may specify an ar archive without -l, perhaps because it
188188 // is not installed as a library. Detect that and link the archive.
189 verbose("Linking archive file '" + File.toString() + "'");
189 verbose("Linking archive file '" + File.str() + "'");
190190 if (LinkInArchive(File, is_native))
191191 return true;
192192 break;
193193
194194 case sys::Bitcode_FileType: {
195 verbose("Linking bitcode file '" + File.toString() + "'");
195 verbose("Linking bitcode file '" + File.str() + "'");
196196 std::auto_ptr M(LoadObject(File));
197197 if (M.get() == 0)
198 return error("Cannot load file '" + File.toString() + "': " + Error);
198 return error("Cannot load file '" + File.str() + "': " + Error);
199199 if (LinkInModule(M.get(), &Error))
200 return error("Cannot link file '" + File.toString() + "': " + Error);
201
202 verbose("Linked in file '" + File.toString() + "'");
200 return error("Cannot link file '" + File.str() + "': " + Error);
201
202 verbose("Linked in file '" + File.str() + "'");
203203 break;
204204 }
205205
2525 #include "llvm/Instructions.h"
2626 #include "llvm/Assembly/Writer.h"
2727 #include "llvm/Support/ErrorHandling.h"
28 #include "llvm/Support/raw_ostream.h"
2829 #include "llvm/System/Path.h"
2930 #include "llvm/ADT/DenseMap.h"
3031 #include
1313 #include "llvm/Linker.h"
1414 #include "llvm/Module.h"
1515 #include "llvm/Bitcode/ReaderWriter.h"
16 #include "llvm/Config/config.h"
16 #include "llvm/System/Path.h"
1717 #include "llvm/Support/MemoryBuffer.h"
1818 #include "llvm/Support/raw_ostream.h"
19 #include "llvm/Config/config.h"
1920 using namespace llvm;
2021
2122 Linker::Linker(const StringRef &progname, const StringRef &modname,
6869
6970 void
7071 Linker::addPaths(const std::vector& paths) {
71 for (unsigned i = 0; i != paths.size(); ++i) {
72 sys::Path aPath;
73 aPath.set(paths[i]);
74 LibPaths.push_back(aPath);
75 }
72 for (unsigned i = 0, e = paths.size(); i != e; ++i)
73 LibPaths.push_back(sys::Path(paths[i]));
7674 }
7775
7876 void
9997 std::string ParseErrorMessage;
10098 Module *Result = 0;
10199
102 const std::string &FNS = FN.toString();
103 std::auto_ptr Buffer(MemoryBuffer::getFileOrSTDIN(FNS.c_str()));
100 std::auto_ptr Buffer(MemoryBuffer::getFileOrSTDIN(FN.c_str()));
104101 if (Buffer.get())
105102 Result = ParseBitcodeFile(Buffer.get(), Context, &ParseErrorMessage);
106103 else
107 ParseErrorMessage = "Error reading file '" + FNS + "'";
104 ParseErrorMessage = "Error reading file '" + FN.str() + "'";
108105
109106 if (Result)
110107 return std::auto_ptr(Result);
111 Error = "Bitcode file '" + FN.toString() + "' could not be loaded";
108 Error = "Bitcode file '" + FN.str() + "' could not be loaded";
112109 if (ParseErrorMessage.size())
113110 Error += ": " + ParseErrorMessage;
114111 return std::auto_ptr();
6363
6464 errs() << "Running 'Graphviz' program... ";
6565 if (sys::Program::ExecuteAndWait(Graphviz, &args[0],0,0,0,0,&ErrMsg))
66 errs() << "Error viewing graph " << Filename << ": " << ErrMsg << "\n";
66 errs() << "Error viewing graph " << Filename.str() << ": " << ErrMsg
67 << "\n";
6768 else
68 Filename.eraseFromDisk();
69 Filename.eraseFromDisk();
6970
7071 #elif (HAVE_GV && (HAVE_DOT || HAVE_FDP || HAVE_NEATO || \
7172 HAVE_TWOPI || HAVE_CIRCO))
1414 #include "llvm/Support/SystemUtils.h"
1515 #include "llvm/System/Process.h"
1616 #include "llvm/System/Program.h"
17 #include "llvm/Support/raw_ostream.h"
1718 using namespace llvm;
1819
1920 bool llvm::CheckBitcodeOutputToConsole(raw_ostream &stream_to_check,
2828 return path == that.path;
2929 }
3030
31 bool Path::operator!=(const Path &that) const {
32 return path != that.path;
33 }
34
3531 bool Path::operator<(const Path& that) const {
3632 return path < that.path;
37 }
38
39 std::ostream& llvm::operator<<(std::ostream &strm, const sys::Path &aPath) {
40 strm << aPath.toString();
41 return strm;
4233 }
4334
4435 Path
118118
119119 CWD.appendComponent(path);
120120
121 path = CWD.toString();
121 path = CWD.str();
122122 }
123123
124124 Path
501501
502502 // Get the file's current mode.
503503 struct stat buf;
504 if (0 != stat(File.toString().c_str(), &buf))
504 if (0 != stat(File.c_str(), &buf))
505505 return false;
506506 // Change the file to have whichever permissions bits from 'bits'
507507 // that the umask would not disable.
758758 Path::renamePathOnDisk(const Path& newName, std::string* ErrMsg) {
759759 if (0 != ::rename(path.c_str(), newName.c_str()))
760760 return MakeErrMsg(ErrMsg, std::string("can't rename '") + path + "' as '" +
761 newName.toString() + "'");
761 newName.str() + "'");
762762 return false;
763763 }
764764
780780 int outFile = -1;
781781 inFile = ::open(Src.c_str(), O_RDONLY);
782782 if (inFile == -1)
783 return MakeErrMsg(ErrMsg, Src.toString() +
783 return MakeErrMsg(ErrMsg, Src.str() +
784784 ": can't open source file to copy");
785785
786786 outFile = ::open(Dest.c_str(), O_WRONLY|O_CREAT, 0666);
787787 if (outFile == -1) {
788788 ::close(inFile);
789 return MakeErrMsg(ErrMsg, Dest.toString() +
789 return MakeErrMsg(ErrMsg, Dest.str() +
790790 ": can't create destination file for copy");
791791 }
792792
796796 if (errno != EINTR && errno != EAGAIN) {
797797 ::close(inFile);
798798 ::close(outFile);
799 return MakeErrMsg(ErrMsg, Src.toString()+": can't read source file");
799 return MakeErrMsg(ErrMsg, Src.str()+": can't read source file");
800800 }
801801 } else {
802802 char *BufPtr = Buffer;
806806 if (errno != EINTR && errno != EAGAIN) {
807807 ::close(inFile);
808808 ::close(outFile);
809 return MakeErrMsg(ErrMsg, Dest.toString() +
809 return MakeErrMsg(ErrMsg, Dest.str() +
810810 ": can't write destination file");
811811 }
812812 } else {
9696 // Redirect empty paths to /dev/null
9797 File = "/dev/null";
9898 else
99 File = Path->toString();
99 File = Path->str();
100100
101101 // Open the file
102102 int InFD = open(File.c_str(), FD == 0 ? O_RDONLY : O_WRONLY|O_CREAT, 0666);
155155 {
156156 if (!path.canExecute()) {
157157 if (ErrMsg)
158 *ErrMsg = path.toString() + " is not executable";
158 *ErrMsg = path.str() + " is not executable";
159159 return false;
160160 }
161161
2020 namespace llvm {
2121 using namespace sys;
2222
23 std::string TimeValue::toString() const {
23 std::string TimeValue::str() const {
2424 char buffer[32];
2525
2626 time_t ourTime = time_t(this->toEpochTime());
807807 // Can't use CopyFile macro defined in Windows.h because it would mess up the
808808 // above line. We use the expansion it would have in a non-UNICODE build.
809809 if (!::CopyFileA(Src.c_str(), Dest.c_str(), false))
810 return MakeErrMsg(ErrMsg, "Can't copy '" + Src.toString() +
811 "' to '" + Dest.toString() + "': ");
810 return MakeErrMsg(ErrMsg, "Can't copy '" + Src.str() +
811 "' to '" + Dest.str() + "': ");
812812 return false;
813813 }
814814
9191 if (path->isEmpty())
9292 fname = "NUL";
9393 else
94 fname = path->toString().c_str();
94 fname = path->c_str();
9595
9696 SECURITY_ATTRIBUTES sa;
9797 sa.nLength = sizeof(sa);
257257 CloseHandle(si.hStdError);
258258
259259 // Now return an error if the process didn't get created.
260 if (!rc)
261 {
260 if (!rc) {
262261 SetLastError(err);
263262 MakeErrMsg(ErrMsg, std::string("Couldn't execute program '") +
264 path.toString() + "'");
263 path.str() + "'");
265264 return false;
266265 }
267266 Pid_ = pi.dwProcessId;
2929 return t;
3030 }
3131
32 std::string TimeValue::toString() const {
32 std::string TimeValue::str() const {
3333 #ifdef __MINGW32__
3434 // This ban may be lifted by either:
3535 // (i) a future MinGW version other than 1.0 inherents the __time64_t type, or
7171 PrefixOutput.set(PfxOutput);
7272 OrigProgram = BD.Program;
7373
74 BD.Program = ParseInputFile(PrefixOutput.toString(), BD.getContext());
74 BD.Program = ParseInputFile(PrefixOutput.str(), BD.getContext());
7575 if (BD.Program == 0) {
7676 errs() << BD.getToolName() << ": Error reading bitcode file '"
77 << PrefixOutput << "'!\n";
77 << PrefixOutput.str() << "'!\n";
7878 exit(1);
7979 }
8080 PrefixOutput.eraseFromDisk();
1717 #include "llvm/Support/Debug.h"
1818 #include "llvm/Support/FileUtilities.h"
1919 #include "llvm/Support/SystemUtils.h"
20 #include "llvm/Support/raw_ostream.h"
2021 #include
2122
2223 using namespace llvm;
279280 << "\n";
280281 exit(1);
281282 }
282 if (writeProgramToFile(BitcodeFile.toString(), M)) {
283 if (writeProgramToFile(BitcodeFile.str(), M)) {
283284 errs() << ToolName << ": Error emitting bitcode to file '"
284 << BitcodeFile << "'!\n";
285 << BitcodeFile.str() << "'!\n";
285286 exit(1);
286287 }
287288
289290 FileRemover BitcodeFileRemover(BitcodeFile, !SaveTemps);
290291
291292 // Actually compile the program!
292 Interpreter->compileProgram(BitcodeFile.toString());
293 Interpreter->compileProgram(BitcodeFile.str());
293294 }
294295
295296
314315 << ErrMsg << "!\n";
315316 exit(1);
316317 }
317 BitcodeFile = uniqueFilename.toString();
318 BitcodeFile = uniqueFilename.str();
318319
319320 if (writeProgramToFile(BitcodeFile, Program)) {
320321 errs() << ToolName << ": Error emitting bitcode to file '"
337338 << ErrMsg << "\n";
338339 exit(1);
339340 }
340 OutputFile = uniqueFile.toString();
341 OutputFile = uniqueFile.str();
341342
342343 // Figure out which shared objects to run, if any.
343344 std::vector SharedObjs(AdditionalSOs);
392393 GCC::FileType FT = SafeInterpreter->OutputCode(BitcodeFile, OutputFile);
393394
394395 std::string SharedObjectFile;
395 if (gcc->MakeSharedObject(OutputFile.toString(), FT,
396 if (gcc->MakeSharedObject(OutputFile.str(), FT,
396397 SharedObjectFile, AdditionalLinkerArgs))
397398 exit(1);
398399
446447 std::string Error;
447448 bool FilesDifferent = false;
448449 if (int Diff = DiffFilesWithTolerance(sys::Path(ReferenceOutputFile),
449 sys::Path(Output.toString()),
450 sys::Path(Output.str()),
450451 AbsTolerance, RelTolerance, &Error)) {
451452 if (Diff == 2) {
452453 errs() << "While diffing output: " << Error << '\n';
2828 #include "llvm/Support/CommandLine.h"
2929 #include "llvm/Support/Debug.h"
3030 #include "llvm/Support/FileUtilities.h"
31 #include "llvm/Support/raw_ostream.h"
3132 #include "llvm/System/Path.h"
3233 #include "llvm/System/Signals.h"
3334 #include
1616 #include "BugDriver.h"
1717 #include "ToolRunner.h"
1818 #include "llvm/Pass.h"
19 #include "llvm/Support/raw_ostream.h"
1920 #include
2021 #include
2122 using namespace llvm;
825825 << ErrMsg << "\n";
826826 exit(1);
827827 }
828 if (BD.writeProgramToFile(TestModuleBC.toString(), Test)) {
829 errs() << "Error writing bitcode to `" << TestModuleBC << "'\nExiting.";
828 if (BD.writeProgramToFile(TestModuleBC.str(), Test)) {
829 errs() << "Error writing bitcode to `" << TestModuleBC.str()
830 << "'\nExiting.";
830831 exit(1);
831832 }
832833 delete Test;
839840 exit(1);
840841 }
841842
842 if (BD.writeProgramToFile(SafeModuleBC.toString(), Safe)) {
843 errs() << "Error writing bitcode to `" << SafeModuleBC << "'\nExiting.";
844 exit(1);
845 }
846 std::string SharedObject = BD.compileSharedObject(SafeModuleBC.toString());
843 if (BD.writeProgramToFile(SafeModuleBC.str(), Safe)) {
844 errs() << "Error writing bitcode to `" << SafeModuleBC.str()
845 << "'\nExiting.";
846 exit(1);
847 }
848 std::string SharedObject = BD.compileSharedObject(SafeModuleBC.str());
847849 delete Safe;
848850
849851 // Run the code generator on the `Test' code, loading the shared library.
850852 // The function returns whether or not the new output differs from reference.
851 int Result = BD.diffProgram(TestModuleBC.toString(), SharedObject, false);
853 int Result = BD.diffProgram(TestModuleBC.str(), SharedObject, false);
852854
853855 if (Result)
854856 errs() << ": still failing!\n";
898900 exit(1);
899901 }
900902
901 if (writeProgramToFile(TestModuleBC.toString(), ToCodeGen)) {
902 errs() << "Error writing bitcode to `" << TestModuleBC << "'\nExiting.";
903 if (writeProgramToFile(TestModuleBC.str(), ToCodeGen)) {
904 errs() << "Error writing bitcode to `" << TestModuleBC.str()
905 << "'\nExiting.";
903906 exit(1);
904907 }
905908 delete ToCodeGen;
912915 exit(1);
913916 }
914917
915 if (writeProgramToFile(SafeModuleBC.toString(), ToNotCodeGen)) {
916 errs() << "Error writing bitcode to `" << SafeModuleBC << "'\nExiting.";
917 exit(1);
918 }
919 std::string SharedObject = compileSharedObject(SafeModuleBC.toString());
918 if (writeProgramToFile(SafeModuleBC.str(), ToNotCodeGen)) {
919 errs() << "Error writing bitcode to `" << SafeModuleBC.str()
920 << "'\nExiting.";
921 exit(1);
922 }
923 std::string SharedObject = compileSharedObject(SafeModuleBC.str());
920924 delete ToNotCodeGen;
921925
922926 outs() << "You can reproduce the problem with the command line: \n";
923927 if (isExecutingJIT()) {
924 outs() << " lli -load " << SharedObject << " " << TestModuleBC;
928 outs() << " lli -load " << SharedObject << " " << TestModuleBC.str();
925929 } else {
926 outs() << " llc -f " << TestModuleBC << " -o " << TestModuleBC<< ".s\n";
927 outs() << " gcc " << SharedObject << " " << TestModuleBC
928 << ".s -o " << TestModuleBC << ".exe";
930 outs() << " llc -f " << TestModuleBC.str() << " -o " << TestModuleBC.str()
931 << ".s\n";
932 outs() << " gcc " << SharedObject << " " << TestModuleBC.str()
933 << ".s -o " << TestModuleBC.str() << ".exe";
929934 #if defined (HAVE_LINK_R)
930935 outs() << " -Wl,-R.";
931936 #endif
932937 outs() << "\n";
933 outs() << " " << TestModuleBC << ".exe";
938 outs() << " " << TestModuleBC.str() << ".exe";
934939 }
935940 for (unsigned i=0, e = InputArgv.size(); i != e; ++i)
936941 outs() << " " << InputArgv[i];
937942 outs() << '\n';
938943 outs() << "The shared object was created with:\n llc -march=c "
939 << SafeModuleBC << " -o temporary.c\n"
944 << SafeModuleBC.str() << " -o temporary.c\n"
940945 << " gcc -xc temporary.c -O2 -o " << SharedObject;
941946 if (TargetTriple.getArch() == Triple::sparc)
942947 outs() << " -G"; // Compile a shared library, `-G' for Sparc
2626 #include "llvm/Target/TargetData.h"
2727 #include "llvm/Support/FileUtilities.h"
2828 #include "llvm/Support/CommandLine.h"
29 #include "llvm/Support/raw_ostream.h"
2930 #include "llvm/System/Path.h"
3031 #include "llvm/System/Program.h"
31 #include "llvm/Config/alloca.h"
3232
3333 #define DONT_GET_PLUGIN_LOADER_OPTION
3434 #include "llvm/Support/PluginLoader.h"
135135 << ErrMsg << "\n";
136136 return(1);
137137 }
138 OutputFilename = uniqueFilename.toString();
138 OutputFilename = uniqueFilename.str();
139139
140140 // set up the input file name
141141 sys::Path inputFilename("bugpoint-input.bc");
151151
152152
153153 if (!ErrInfo.empty()) {
154 errs() << "Error opening bitcode file: " << inputFilename << "\n";
154 errs() << "Error opening bitcode file: " << inputFilename.str() << "\n";
155155 return 1;
156156 }
157157 WriteBitcodeToFile(Program, InFile);
158158 InFile.close();
159159
160160 // setup the child process' arguments
161 const char** args = (const char**)
162 alloca(sizeof(const char*) *
163 (Passes.size()+13+2*PluginLoader::getNumPlugins()+NumExtraArgs));
164 int n = 0;
161 SmallVector Args;
165162 sys::Path tool = sys::Program::FindProgramByName(ToolName);
166163 if (UseValgrind) {
167 args[n++] = "valgrind";
168 args[n++] = "--error-exitcode=1";
169 args[n++] = "-q";
170 args[n++] = tool.c_str();
164 Args.push_back("valgrind");
165 Args.push_back("--error-exitcode=1");
166 Args.push_back("-q");
167 Args.push_back(tool.c_str());
171168 } else
172 args[n++] = ToolName;
173
174 args[n++] = "-as-child";
175 args[n++] = "-child-output";
176 args[n++] = OutputFilename.c_str();
169 Args.push_back(ToolName);
170
171 Args.push_back("-as-child");
172 Args.push_back("-child-output");
173 Args.push_back(OutputFilename.c_str());
177174 std::vector pass_args;
178175 for (unsigned i = 0, e = PluginLoader::getNumPlugins(); i != e; ++i) {
179176 pass_args.push_back( std::string("-load"));
184181 pass_args.push_back( std::string("-") + (*I)->getPassArgument() );
185182 for (std::vector::const_iterator I = pass_args.begin(),
186183 E = pass_args.end(); I != E; ++I )
187 args[n++] = I->c_str();
188 args[n++] = inputFilename.c_str();
184 Args.push_back(I->c_str());
185 Args.push_back(inputFilename.c_str());
189186 for (unsigned i = 0; i < NumExtraArgs; ++i)
190 args[n++] = *ExtraArgs;
191 args[n++] = 0;
187 Args.push_back(*ExtraArgs);
188 Args.push_back(0);
192189
193190 sys::Path prog;
194191 if (UseValgrind)
200197 sys::Path Nowhere;
201198 const sys::Path *Redirects[3] = {0, &Nowhere, &Nowhere};
202199
203 int result = sys::Program::ExecuteAndWait(prog, args, 0, (SilencePasses ? Redirects : 0),
200 int result = sys::Program::ExecuteAndWait(prog, Args.data(), 0,
201 (SilencePasses ? Redirects : 0),
204202 Timeout, MemoryLimit, &ErrMsg);
205203
206204 // If we are supposed to delete the bitcode file or if the passes crashed,
1212
1313 #define DEBUG_TYPE "toolrunner"
1414 #include "ToolRunner.h"
15 #include "llvm/Config/config.h" // for HAVE_LINK_R
1615 #include "llvm/System/Program.h"
1716 #include "llvm/Support/CommandLine.h"
1817 #include "llvm/Support/Debug.h"
1918 #include "llvm/Support/FileUtilities.h"
19 #include "llvm/Support/raw_ostream.h"
20 #include "llvm/Config/config.h" // for HAVE_LINK_R
2021 #include
2122 #include
2223 using namespace llvm;
231232 std::string &Message,
232233 const std::vector *ToolArgs) {
233234 std::string LLIPath =
234 FindExecutable("lli", Argv0, (void *)(intptr_t)&createLLI).toString();
235 FindExecutable("lli", Argv0, (void *)(intptr_t)&createLLI).str();
235236 if (!LLIPath.empty()) {
236237 Message = "Found lli: " + LLIPath + "\n";
237238 return new LLI(LLIPath, ToolArgs);
331332 pos = ExecCommandLine.find_first_of(delimiters, lastPos);
332333 }
333334
334 std::string CmdPath = sys::Program::FindProgramByName(Command).toString();
335 std::string CmdPath = sys::Program::FindProgramByName(Command).str();
335336 if (CmdPath.empty()) {
336337 Message =
337338 std::string("Cannot find '") + Command +
406407 GCCArgs.insert(GCCArgs.end(), gccArgs.begin(), gccArgs.end());
407408
408409 // Assuming LLC worked, compile the result with GCC and run it.
409 return gcc->ExecuteProgram(OutputAsmFile.toString(), Args, GCC::AsmFile,
410 return gcc->ExecuteProgram(OutputAsmFile.str(), Args, GCC::AsmFile,
410411 InputFile, OutputFile, GCCArgs,
411412 Timeout, MemoryLimit);
412413 }
418419 const std::vector *Args,
419420 const std::vector *GCCArgs) {
420421 std::string LLCPath =
421 FindExecutable("llc", Argv0, (void *)(intptr_t)&createLLC).toString();
422 FindExecutable("llc", Argv0, (void *)(intptr_t)&createLLC).str();
422423 if (LLCPath.empty()) {
423424 Message = "Cannot find `llc' in executable directory or PATH!\n";
424425 return 0;
504505 AbstractInterpreter *AbstractInterpreter::createJIT(const char *Argv0,
505506 std::string &Message, const std::vector *Args) {
506507 std::string LLIPath =
507 FindExecutable("lli", Argv0, (void *)(intptr_t)&createJIT).toString();
508 FindExecutable("lli", Argv0, (void *)(intptr_t)&createJIT).str();
508509 if (!LLIPath.empty()) {
509510 Message = "Found lli: " + LLIPath + "\n";
510511 return new JIT(LLIPath, Args);
571572 std::vector GCCArgs(ArgsForGCC);
572573 GCCArgs.insert(GCCArgs.end(), SharedLibs.begin(), SharedLibs.end());
573574
574 return gcc->ExecuteProgram(OutputCFile.toString(), Args, GCC::CFile,
575 return gcc->ExecuteProgram(OutputCFile.str(), Args, GCC::CFile,
575576 InputFile, OutputFile, GCCArgs,
576577 Timeout, MemoryLimit);
577578 }
590591 return 0;
591592 }
592593
593 Message = "Found llc: " + LLCPath.toString() + "\n";
594 Message = "Found llc: " + LLCPath.str() + "\n";
594595 GCC *gcc = GCC::create(Message, GCCArgs);
595596 if (!gcc) {
596597 errs() << Message << "\n";
756757 errs() << "Error making unique filename: " << ErrMsg << "\n";
757758 exit(1);
758759 }
759 OutputFile = uniqueFilename.toString();
760 OutputFile = uniqueFilename.str();
760761
761762 std::vector GCCArgs;
762763
838839 if (!RemoteClient.empty())
839840 RemoteClientPath = sys::Program::FindProgramByName(RemoteClient);
840841
841 Message = "Found gcc: " + GCCPath.toString() + "\n";
842 Message = "Found gcc: " + GCCPath.str() + "\n";
842843 return new GCC(GCCPath, RemoteClientPath, Args);
843844 }
2727 #include "llvm/Support/MemoryBuffer.h"
2828 #include "llvm/Support/PluginLoader.h"
2929 #include "llvm/Support/PrettyStackTrace.h"
30 #include "llvm/Support/raw_ostream.h"
3031 #include "llvm/System/Process.h"
3132 #include "llvm/System/Signals.h"
3233 #include "llvm/Target/TargetSelect.h"
363363 continue;
364364
365365 if (Verbose)
366 std::cout << "Printing " << I->getPath().toString() << "\n";
366 std::cout << "Printing " << I->getPath().str() << "\n";
367367
368368 unsigned len = I->getSize();
369369 std::cout.write(data, len);
421421 std::cout << " " << std::setw(4) << I->getUser();
422422 std::cout << "/" << std::setw(4) << I->getGroup();
423423 std::cout << " " << std::setw(8) << I->getSize();
424 std::cout << " " << std::setw(20) <<
425 I->getModTime().toString().substr(4);
426 std::cout << " " << I->getPath().toString() << "\n";
424 std::cout << " " << std::setw(20) << I->getModTime().str().substr(4);
425 std::cout << " " << I->getPath().str() << "\n";
427426 } else {
428 std::cout << I->getPath().toString() << "\n";
427 std::cout << I->getPath().str() << "\n";
429428 }
430429 }
431430 }
527526 if (AddBefore || InsertBefore || AddAfter) {
528527 for (Archive::iterator I = TheArchive->begin(), E= TheArchive->end();
529528 I != E; ++I ) {
530 if (RelPos == I->getPath().toString()) {
529 if (RelPos == I->getPath().str()) {
531530 if (AddAfter) {
532531 moveto_spot = I;
533532 moveto_spot++;
615614 std::set::iterator found = remaining.end();
616615 for (std::set::iterator RI = remaining.begin(),
617616 RE = remaining.end(); RI != RE; ++RI ) {
618 std::string compare(RI->toString());
617 std::string compare(RI->str());
619618 if (TruncateNames && compare.length() > 15) {
620619 const char* nm = compare.c_str();
621620 unsigned len = compare.length();
628627 len = 15;
629628 compare.assign(nm,len);
630629 }
631 if (compare == I->getPath().toString()) {
630 if (compare == I->getPath().str()) {
632631 found = RI;
633632 break;
634633 }
660659 }
661660
662661 // Determine if this is the place where we should insert
663 if ((AddBefore || InsertBefore) && (RelPos == I->getPath().toString()))
662 if ((AddBefore || InsertBefore) && RelPos == I->getPath().str())
664663 insert_spot = I;
665 else if (AddAfter && (RelPos == I->getPath().toString())) {
664 else if (AddAfter && RelPos == I->getPath().str()) {
666665 insert_spot = I;
667666 insert_spot++;
668667 }
718717 if (!ArchivePath.exists()) {
719718 // Produce a warning if we should and we're creating the archive
720719 if (!Create)
721 errs() << argv[0] << ": creating " << ArchivePath.toString() << "\n";
720 errs() << argv[0] << ": creating " << ArchivePath.str() << "\n";
722721 TheArchive = Archive::CreateEmpty(ArchivePath, Context);
723722 TheArchive->writeToDisk();
724723 } else {
725724 std::string Error;
726725 TheArchive = Archive::OpenAndLoad(ArchivePath, Context, &Error);
727726 if (TheArchive == 0) {
728 errs() << argv[0] << ": error loading '" << ArchivePath << "': "
727 errs() << argv[0] << ": error loading '" << ArchivePath.str() << "': "
729728 << Error << "!\n";
730729 return 1;
731730 }
3434 #include "llvm/Support/ManagedStatic.h"
3535 #include "llvm/Support/MemoryBuffer.h"
3636 #include "llvm/Support/PrettyStackTrace.h"
37 #include "llvm/Support/raw_ostream.h"
3738 #include "llvm/System/Signals.h"
3839 #include
3940 #include
1818 #include "llvm/Debugger/SourceFile.h"
1919 #include "llvm/Debugger/InferiorProcess.h"
2020 #include "llvm/Support/FileUtilities.h"
21 #include "llvm/Support/raw_ostream.h"
2122 #include "llvm/ADT/StringExtras.h"
22 #include
2323 #include
2424 using namespace llvm;
2525
5555 if (!Status)
5656 throw Err;
5757 if (TheProgramInfo->getProgramTimeStamp() != Status->getTimestamp()) {
58 std::cout << "'" << Program << "' has changed; re-reading program.\n";
58 outs() << "'" << Program.str() << "' has changed; re-reading program.\n";
5959
6060 // Unload an existing program. This kills the program if necessary.
6161 Dbg.unloadProgram();
6363 TheProgramInfo = 0;
6464 CurrentFile = 0;
6565
66 Dbg.loadProgram(Program.toString(), Context);
66 Dbg.loadProgram(Program.str(), Context);
6767 TheProgramInfo = new ProgramInfo(Dbg.getProgram());
6868 }
6969
70 std::cout << "Starting program: " << Dbg.getProgramPath() << "\n";
70 outs() << "Starting program: " << Dbg.getProgramPath() << "\n";
7171 Dbg.createProgram();
7272
7373 // There was no current frame.
8282 const char *LineStart, *LineEnd;
8383 CurrentFile->getSourceLine(LineNo-1, LineStart, LineEnd);
8484 if (LineStart == 0) return true;
85 std::cout << LineNo;
85 outs() << LineNo;
8686
8787 // If this is the line the program is currently stopped at, print a marker.
8888 if (Dbg.isProgramRunning()) {
9292 CurSFI);
9393
9494 if (CurLineNo == LineNo && CurrentFile == &CurSFI->getSourceText())
95 std::cout << " ->";
96 }
97
98 std::cout << "\t" << std::string(LineStart, LineEnd) << "\n";
95 outs() << " ->";
96 }
97
98 outs() << "\t" << std::string(LineStart, LineEnd) << "\n";
9999 return false;
100100 }
101101
116116 if (PrintLocation) {
117117 // FIXME: print the current function arguments
118118 if (const GlobalVariable *FuncDesc = SF.getFunctionDesc())
119 std::cout << getProgramInfo().getFunction(FuncDesc).getSymbolicName();
119 outs() << getProgramInfo().getFunction(FuncDesc).getSymbolicName();
120120 else
121 std::cout << "";
121 outs() << "";
122122
123123 CurrentFile = &FileDesc->getSourceText();
124124
125 std::cout << " at " << CurrentFile->getFilename() << ":" << LineNo;
126 if (ColNo) std::cout << ":" << ColNo;
127 std::cout << "\n";
125 outs() << " at " << CurrentFile->getFilename() << ":" << LineNo;
126 if (ColNo) outs() << ":" << ColNo;
127 outs() << "\n";
128128 }
129129
130130 if (printSourceLine(LineNo))
131 std::cout << "\n";
131 outs() << "\n";
132132 else {
133133 LineListedStart = LineNo-ListSize/2+1;
134134 if ((int)LineListedStart < 1) LineListedStart = 1;
240240
241241 // If requested, start the new program.
242242 if (Prog.empty()) {
243 std::cout << "Unloaded program.\n";
243 outs() << "Unloaded program.\n";
244244 } else {
245 std::cout << "Loading program... " << std::flush;
245 outs() << "Loading program... ";
246 outs().flush();
246247 Dbg.loadProgram(Prog, Context);
247248 assert(Dbg.isProgramLoaded() &&
248249 "loadProgram succeeded, but not program loaded!");
249250 TheProgramInfo = new ProgramInfo(Dbg.getProgram());
250 std::cout << "successfully loaded '" << Dbg.getProgramPath() << "'!\n";
251 outs() << "successfully loaded '" << Dbg.getProgramPath() << "'!\n";
251252 }
252253 }
253254
390391 try {
391392 for (unsigned i = 0; ; ++i) {
392393 StackFrame &SF = RI.getStackFrame(i);
393 std::cout << "#" << i;
394 outs() << "#" << i;
394395 if (i == RI.getCurrentFrameIdx())
395 std::cout << " ->";
396 std::cout << "\t" << SF.getFrameID() << " in ";
396 outs() << " ->";
397 outs() << "\t" << SF.getFrameID() << " in ";
397398 if (const GlobalVariable *G = SF.getFunctionDesc())
398 std::cout << PI.getFunction(G).getSymbolicName();
399 outs() << PI.getFunction(G).getSymbolicName();
399400
400401 unsigned LineNo, ColNo;
401402 const SourceFileInfo *SFI;
402403 SF.getSourceLocation(LineNo, ColNo, SFI);
403404 if (!SFI->getBaseName().empty()) {
404 std::cout << " at " << SFI->getBaseName();
405 outs() << " at " << SFI->getBaseName();
405406 if (LineNo) {
406 std::cout << ":" << LineNo;
407 outs() << ":" << LineNo;
407408 if (ColNo)
408 std::cout << ":" << ColNo;
409 outs() << ":" << ColNo;
409410 }
410411 }
411412
412413 // FIXME: when we support shared libraries, we should print ' from foo.so'
413414 // if the stack frame is from a different object than the current one.
414415
415 std::cout << "\n";
416 outs() << "\n";
416417 }
417418 } catch (...) {
418419 // Stop automatically when we run off the bottom of the stack.
521522 } else if (What == "functions") {
522523 const std::map &Functions
523524 = getProgramInfo().getSourceFunctions();
524 std::cout << "All defined functions:\n";
525 outs() << "All defined functions:\n";
525526 // FIXME: GDB groups these by source file. We could do that I guess.
526527 for (std::map::const_iterator
527528 I = Functions.begin(), E = Functions.end(); I != E; ++I) {
528 std::cout << I->second->getSymbolicName() << "\n";
529 outs() << I->second->getSymbolicName() << "\n";
529530 }
530531
531532 } else if (What == "source") {
536537 const SourceFileInfo &SF =
537538 getProgramInfo().getSourceFile(CurrentFile->getDescriptor());
538539
539 std::cout << "Current source file is: " << SF.getBaseName() << "\n"
540 << "Compilation directory is: " << SF.getDirectory() << "\n";
540 outs() << "Current source file is: " << SF.getBaseName() << "\n"
541 << "Compilation directory is: " << SF.getDirectory() << "\n";
541542 if (unsigned NL = CurrentFile->getNumLines())
542 std::cout << "Located in: " << CurrentFile->getFilename() << "\n"
543 << "Contains " << NL << " lines\n";
543 outs() << "Located in: " << CurrentFile->getFilename() << "\n"
544 << "Contains " << NL << " lines\n";
544545 else
545 std::cout << "Could not find source file.\n";
546 std::cout << "Source language is "
547 << SF.getLanguage().getSourceLanguageName() << "\n";
546 outs() << "Could not find source file.\n";
547 outs() << "Source language is "
548 << SF.getLanguage().getSourceLanguageName() << "\n";
548549
549550 } else if (What == "sources") {
550551 const std::map &SourceFiles =
551552 getProgramInfo().getSourceFiles();
552 std::cout << "Source files for the program:\n";
553 outs() << "Source files for the program:\n";
553554 for (std::map::const_iterator I =
554555 SourceFiles.begin(), E = SourceFiles.end(); I != E;) {
555 std::cout << I->second->getDirectory() << "/"
556 << I->second->getBaseName();
556 outs() << I->second->getDirectory() << "/"
557 << I->second->getBaseName();
557558 ++I;
558 if (I != E) std::cout << ", ";
559 if (I != E) outs() << ", ";
559560 }
560 std::cout << "\n";
561 outs() << "\n";
561562 } else if (What == "target") {
562 std::cout << Dbg.getRunningProcess().getStatus();
563 outs() << Dbg.getRunningProcess().getStatus();
563564 } else {
564565 // See if this is something handled by the current language.
565566 if (getCurrentLanguage().printInfo(What))
745746 if (LineStart == 0)
746747 throw "Could not load source file '" + CurrentFile->getFilename() + "'!";
747748 else
748 std::cout << "\n";
749 outs() << "\n";
749750 }
750751 }
751752
761762 if (!getToken(Options).empty())
762763 throw "set language expects one argument at most.";
763764 if (Lang == "") {
764 std::cout << "The currently understood settings are:\n\n"
765 << "local or auto Automatic setting based on source file\n"
766 << "c Use the C language\n"
767 << "c++ Use the C++ language\n"
768 << "unknown Use when source language is not supported\n";
765 outs() << "The currently understood settings are:\n\n"
766 << "local or auto Automatic setting based on source file\n"
767 << "c Use the C language\n"
768 << "c++ Use the C++ language\n"
769 << "unknown Use when source language is not supported\n";
769770 } else if (Lang == "local" || Lang == "auto") {
770771 CurrentLanguage = 0;
771772 } else if (Lang == "c") {
798799 throw "show command expects one argument.";
799800
800801 if (What == "args") {
801 std::cout << "Argument list to give program when started is \"";
802 outs() << "Argument list to give program when started is \"";
802803 // FIXME: This doesn't print stuff correctly if the arguments have spaces in
803804 // them, but currently the only way to get that is to use the --args command
804805 // line argument. This should really handle escaping all hard characters as
805806 // needed.
806807 for (unsigned i = 0, e = Dbg.getNumProgramArguments(); i != e; ++i)
807 std::cout << (i ? " " : "") << Dbg.getProgramArgument(i);
808 std::cout << "\"\n";
808 outs() << (i ? " " : "") << Dbg.getProgramArgument(i);
809 outs() << "\"\n";
809810
810811 } else if (What == "language") {
811 std::cout << "The current source language is '";
812 outs() << "The current source language is '";
812813 if (CurrentLanguage)
813 std::cout << CurrentLanguage->getSourceLanguageName();
814 outs() << CurrentLanguage->getSourceLanguageName();
814815 else
815 std::cout << "auto; currently "
816 << getCurrentLanguage().getSourceLanguageName();
817 std::cout << "'.\n";
816 outs() << "auto; currently "
817 << getCurrentLanguage().getSourceLanguageName();
818 outs() << "'.\n";
818819 } else if (What == "listsize") {
819 std::cout << "Number of source lines llvm-db will list by default is "
820 << ListSize << ".\n";
820 outs() << "Number of source lines llvm-db will list by default is "
821 << ListSize << ".\n";
821822 } else if (What == "prompt") {
822 std::cout << "llvm-db's prompt is \"" << Prompt << "\".\n";
823 outs() << "llvm-db's prompt is \"" << Prompt << "\".\n";
823824 } else {
824825 throw "Unknown show command '" + What + "'. Try 'help show'.";
825826 }
834835 // Getting detailed help on a particular command?
835836 if (!Command.empty()) {
836837 CLICommand *C = getCommand(Command);
837 std::cout << C->getShortHelp() << ".\n" << C->getLongHelp();
838 outs() << C->getShortHelp() << ".\n" << C->getLongHelp();
838839
839840 // If there are aliases for this option, print them out.
840841 const std::vector &Names = C->getOptionNames();
841842 if (Names.size() > 1) {
842 std::cout << "The '" << Command << "' command is known as: '"
843 << Names[0] << "'";
843 outs() << "The '" << Command << "' command is known as: '"
844 << Names[0] << "'";
844845 for (unsigned i = 1, e = Names.size(); i != e; ++i)
845 std::cout << ", '" << Names[i] << "'";
846 std::cout << "\n";
846 outs() << ", '" << Names[i] << "'";
847 outs() << "\n";
847848 }
848849
849850 } else {
858859 for (std::map::iterator I = CommandTable.begin(),
859860 E = CommandTable.end(); I != E; ++I)
860861 if (I->first == I->second->getPrimaryOptionName())
861 std::cout << I->first << std::string(MaxSize - I->first.size(), ' ')
862 << " - " << I->second->getShortHelp() << "\n";
863 }
864 }
862 outs() << I->first << std::string(MaxSize - I->first.size(), ' ')
863 << " - " << I->second->getShortHelp() << "\n";
864 }
865 }
1616 #include "llvm/Support/CommandLine.h"
1717 #include "llvm/Support/ManagedStatic.h"
1818 #include "llvm/Support/PrettyStackTrace.h"
19 #include "llvm/Support/raw_ostream.h"
1920 #include "llvm/System/Signals.h"
20 #include
2121 using namespace llvm;
2222
2323 namespace {
5656
5757 LLVMContext &Context = getGlobalContext();
5858 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
59 std::cout << "NOTE: llvm-db is known useless right now.\n";
59 outs() << "NOTE: llvm-db is known useless right now.\n";
6060 try {
6161 cl::ParseCommandLineOptions(argc, argv,
6262 "llvm source-level debugger\n");
6363
6464 if (!Quiet)
65 std::cout << "llvm-db: The LLVM source-level debugger\n";
65 outs() << "llvm-db: The LLVM source-level debugger\n";
6666
6767 // Merge Inputfile and InputArgs into the InputArgs list...
6868 if (!InputFile.empty() && InputArgs.empty())
8484 try {
8585 D.fileCommand(InputArgs[0]);
8686 } catch (const std::string &Error) {
87 std::cout << "Error: " << Error << "\n";
87 outs() << "Error: " << Error << "\n";
8888 }
8989
9090 Dbg.setProgramArguments(InputArgs.begin()+1, InputArgs.end());
3434 #include "llvm/Support/MemoryBuffer.h"
3535 #include "llvm/Support/PrettyStackTrace.h"
3636 #include "llvm/Support/SystemUtils.h"
37 #include "llvm/Support/raw_ostream.h"
3738 #include "llvm/System/Signals.h"
3839 #include "llvm/Config/config.h"
3940 #include
465466 if (FullLibraryPath.isEmpty())
466467 FullLibraryPath = sys::Path::FindLibrary(*i);
467468 if (!FullLibraryPath.isEmpty())
468 Out2 << " -load=" << FullLibraryPath.toString() << " \\\n";
469 Out2 << " -load=" << FullLibraryPath.str() << " \\\n";
469470 }
470471 Out2 << " " << BitcodeOutputFilename << " ${1+\"$@\"}\n";
471472 Out2.close();
571572 sys::Path ExeFile( OutputFilename );
572573 if (ExeFile.getSuffix() == "") {
573574 ExeFile.appendSuffix("exe");
574 OutputFilename = ExeFile.toString();
575 OutputFilename = ExeFile.str();
575576 }
576577 }
577578 #endif
651652
652653 // Generate an assembly language file for the bitcode.
653654 std::string ErrMsg;
654 if (0 != GenerateAssembly(AssemblyFile.toString(), BitcodeOutputFilename,
655 if (0 != GenerateAssembly(AssemblyFile.str(), BitcodeOutputFilename,
655656 llc, ErrMsg))
656657 PrintAndExit(ErrMsg);
657658
658 if (0 != GenerateNative(OutputFilename, AssemblyFile.toString(),
659 if (0 != GenerateNative(OutputFilename, AssemblyFile.str(),
659660 NativeLinkItems, gcc, envp, ErrMsg))
660661 PrintAndExit(ErrMsg);
661662
681682
682683 // Generate an assembly language file for the bitcode.
683684 std::string ErrMsg;
684 if (0 != GenerateCFile(
685 CFile.toString(), BitcodeOutputFilename, llc, ErrMsg))
685 if (GenerateCFile(CFile.str(), BitcodeOutputFilename, llc, ErrMsg))
686686 PrintAndExit(ErrMsg);
687687
688 if (0 != GenerateNative(OutputFilename, CFile.toString(),
689 NativeLinkItems, gcc, envp, ErrMsg))
688 if (GenerateNative(OutputFilename, CFile.str(),
689 NativeLinkItems, gcc, envp, ErrMsg))
690690 PrintAndExit(ErrMsg);
691691
692692 // Remove the assembly language file.
2020 #include "llvm/Support/ManagedStatic.h"
2121 #include "llvm/Support/MemoryBuffer.h"
2222 #include "llvm/Support/PrettyStackTrace.h"
23 #include "llvm/Support/raw_ostream.h"
2324 #include "llvm/System/Signals.h"
2425 #include "llvm/System/Path.h"
2526 #include
5758 if (Verbose) errs() << "Loading '" << Filename.c_str() << "'\n";
5859 Module* Result = 0;
5960
60 const std::string &FNStr = Filename.toString();
61 const std::string &FNStr = Filename.str();
6162 if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(FNStr,
6263 &ErrorMessage)) {
6364 Result = ParseBitcodeFile(Buffer, Context, &ErrorMessage);
201201 sys::RemoveFileOnSignal(uniqueObjPath);
202202
203203 // assemble the assembly code
204 const std::string& uniqueObjStr = uniqueObjPath.toString();
205 bool asmResult = this->assemble(uniqueAsmPath.toString(),
206 uniqueObjStr, errMsg);
204 const std::string& uniqueObjStr = uniqueObjPath.str();
205 bool asmResult = this->assemble(uniqueAsmPath.str(), uniqueObjStr, errMsg);
207206 if ( !asmResult ) {
208207 // remove old buffer if compile() called twice
209208 delete _nativeObjectFile;
13291329 O << "for (PathVector::const_iterator B = inFiles.begin()"
13301330 << ", E = inFiles.end();\n"
13311331 << IndentLevel << "B != E; ++B)\n"
1332 << IndentLevel << Indent1 << "vec.push_back(B->toString());\n";
1332 << IndentLevel << Indent1 << "vec.push_back(B->str());\n";
13331333 else
1334 O << "vec.push_back(inFile.toString());\n";
1334 O << "vec.push_back(inFile.str());\n";
13351335 }
13361336 else if (cmd == "$OUTFILE") {
13371337 O << "vec.push_back(out_file);\n";
15551555
15561556 O << '\n' << Indent2
15571557 << "out_file = OutFilename(" << (IsJoin ? "sys::Path(),\n" : "inFile,\n")
1558 << Indent3 << "TempDir, stop_compilation, output_suffix).toString();\n\n";
1558 << Indent3 << "TempDir, stop_compilation, output_suffix).str();\n\n";
15591559
15601560 // cmd_line is either a string or a 'case' construct.
15611561 if (!D.CmdLine)