Use errs() instead of std::cerr.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75791 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dan Gohman
2009-07-15 16:35:29 +00:00
parent 6ca5f9360c
commit 65f57c233c
20 changed files with 246 additions and 239 deletions

View File

@ -117,13 +117,13 @@ bool BugDriver::addSources(const std::vector<std::string> &Filenames) {
std::cout << "Linking in input file: '" << Filenames[i] << "'\n"; std::cout << "Linking in input file: '" << Filenames[i] << "'\n";
std::string ErrorMessage; std::string ErrorMessage;
if (Linker::LinkModules(Program, M.get(), &ErrorMessage)) { if (Linker::LinkModules(Program, M.get(), &ErrorMessage)) {
std::cerr << ToolName << ": error linking in '" << Filenames[i] << "': " errs() << ToolName << ": error linking in '" << Filenames[i] << "': "
<< ErrorMessage << '\n'; << ErrorMessage << '\n';
return true; return true;
} }
} }
} catch (const std::string &Error) { } catch (const std::string &Error) {
std::cerr << ToolName << ": error reading input '" << Error << "'\n"; errs() << ToolName << ": error reading input '" << Error << "'\n";
return true; return true;
} }
@ -209,7 +209,7 @@ bool BugDriver::run() {
return debugMiscompilation(); return debugMiscompilation();
} }
} catch (ToolExecutionError &TEE) { } catch (ToolExecutionError &TEE) {
std::cerr << TEE.what(); errs() << TEE.what();
return debugCodeGeneratorCrash(); return debugCodeGeneratorCrash();
} }
@ -218,7 +218,7 @@ bool BugDriver::run() {
try { try {
return debugCodeGenerator(); return debugCodeGenerator();
} catch (ToolExecutionError &TEE) { } catch (ToolExecutionError &TEE) {
std::cerr << TEE.what(); errs() << TEE.what();
return debugCodeGeneratorCrash(); return debugCodeGeneratorCrash();
} }
} }

View File

@ -28,6 +28,7 @@
#include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Transforms/Utils/Cloning.h"
#include "llvm/Support/FileUtilities.h" #include "llvm/Support/FileUtilities.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include <iostream>
#include <fstream> #include <fstream>
#include <set> #include <set>
using namespace llvm; using namespace llvm;
@ -75,8 +76,8 @@ ReducePassList::doTest(std::vector<const PassInfo*> &Prefix,
BD.Program = ParseInputFile(PrefixOutput.toString(), BD.getContext()); BD.Program = ParseInputFile(PrefixOutput.toString(), BD.getContext());
if (BD.Program == 0) { if (BD.Program == 0) {
std::cerr << BD.getToolName() << ": Error reading bitcode file '" errs() << BD.getToolName() << ": Error reading bitcode file '"
<< PrefixOutput << "'!\n"; << PrefixOutput << "'!\n";
exit(1); exit(1);
} }
PrefixOutput.eraseFromDisk(); PrefixOutput.eraseFromDisk();
@ -631,10 +632,10 @@ bool BugDriver::debugOptimizerCrash(const std::string &ID) {
static bool TestForCodeGenCrash(BugDriver &BD, Module *M) { static bool TestForCodeGenCrash(BugDriver &BD, Module *M) {
try { try {
BD.compileProgram(M); BD.compileProgram(M);
std::cerr << '\n'; errs() << '\n';
return false; return false;
} catch (ToolExecutionError &) { } catch (ToolExecutionError &) {
std::cerr << "<crash>\n"; errs() << "<crash>\n";
return true; // Tool is still crashing. return true; // Tool is still crashing.
} }
} }
@ -643,7 +644,7 @@ static bool TestForCodeGenCrash(BugDriver &BD, Module *M) {
/// crashes on an input. It attempts to reduce the input as much as possible /// crashes on an input. It attempts to reduce the input as much as possible
/// while still causing the code generator to crash. /// while still causing the code generator to crash.
bool BugDriver::debugCodeGeneratorCrash() { bool BugDriver::debugCodeGeneratorCrash() {
std::cerr << "*** Debugging code generator crash!\n"; errs() << "*** Debugging code generator crash!\n";
return DebugACrash(*this, TestForCodeGenCrash); return DebugACrash(*this, TestForCodeGenCrash);
} }

View File

@ -186,7 +186,7 @@ bool BugDriver::initializeExecutionEnvironment() {
break; break;
} }
if (!Interpreter) if (!Interpreter)
std::cerr << Message; errs() << Message;
else // Display informational messages on stdout instead of stderr else // Display informational messages on stdout instead of stderr
std::cout << Message; std::cout << Message;
@ -278,13 +278,13 @@ void BugDriver::compileProgram(Module *M) {
sys::Path BitcodeFile ("bugpoint-test-program.bc"); sys::Path BitcodeFile ("bugpoint-test-program.bc");
std::string ErrMsg; std::string ErrMsg;
if (BitcodeFile.makeUnique(true,&ErrMsg)) { if (BitcodeFile.makeUnique(true,&ErrMsg)) {
std::cerr << ToolName << ": Error making unique filename: " << ErrMsg errs() << ToolName << ": Error making unique filename: " << ErrMsg
<< "\n"; << "\n";
exit(1); exit(1);
} }
if (writeProgramToFile(BitcodeFile.toString(), M)) { if (writeProgramToFile(BitcodeFile.toString(), M)) {
std::cerr << ToolName << ": Error emitting bitcode to file '" errs() << ToolName << ": Error emitting bitcode to file '"
<< BitcodeFile << "'!\n"; << BitcodeFile << "'!\n";
exit(1); exit(1);
} }
@ -313,15 +313,15 @@ std::string BugDriver::executeProgram(std::string OutputFile,
// Emit the program to a bitcode file... // Emit the program to a bitcode file...
sys::Path uniqueFilename("bugpoint-test-program.bc"); sys::Path uniqueFilename("bugpoint-test-program.bc");
if (uniqueFilename.makeUnique(true, &ErrMsg)) { if (uniqueFilename.makeUnique(true, &ErrMsg)) {
std::cerr << ToolName << ": Error making unique filename: " errs() << ToolName << ": Error making unique filename: "
<< ErrMsg << "!\n"; << ErrMsg << "!\n";
exit(1); exit(1);
} }
BitcodeFile = uniqueFilename.toString(); BitcodeFile = uniqueFilename.toString();
if (writeProgramToFile(BitcodeFile, Program)) { if (writeProgramToFile(BitcodeFile, Program)) {
std::cerr << ToolName << ": Error emitting bitcode to file '" errs() << ToolName << ": Error emitting bitcode to file '"
<< BitcodeFile << "'!\n"; << BitcodeFile << "'!\n";
exit(1); exit(1);
} }
CreatedBitcode = true; CreatedBitcode = true;
@ -336,8 +336,8 @@ std::string BugDriver::executeProgram(std::string OutputFile,
// Check to see if this is a valid output filename... // Check to see if this is a valid output filename...
sys::Path uniqueFile(OutputFile); sys::Path uniqueFile(OutputFile);
if (uniqueFile.makeUnique(true, &ErrMsg)) { if (uniqueFile.makeUnique(true, &ErrMsg)) {
std::cerr << ToolName << ": Error making unique filename: " errs() << ToolName << ": Error making unique filename: "
<< ErrMsg << "\n"; << ErrMsg << "\n";
exit(1); exit(1);
} }
OutputFile = uniqueFile.toString(); OutputFile = uniqueFile.toString();
@ -352,7 +352,7 @@ std::string BugDriver::executeProgram(std::string OutputFile,
Timeout, MemoryLimit); Timeout, MemoryLimit);
if (RetVal == -1) { if (RetVal == -1) {
std::cerr << "<timeout>"; errs() << "<timeout>";
static bool FirstTimeout = true; static bool FirstTimeout = true;
if (FirstTimeout) { if (FirstTimeout) {
std::cout << "\n" std::cout << "\n"
@ -420,12 +420,12 @@ bool BugDriver::createReferenceFile(Module *M, const std::string &Filename) {
ReferenceOutputFile = executeProgramSafely(Filename); ReferenceOutputFile = executeProgramSafely(Filename);
std::cout << "\nReference output is: " << ReferenceOutputFile << "\n\n"; std::cout << "\nReference output is: " << ReferenceOutputFile << "\n\n";
} catch (ToolExecutionError &TEE) { } catch (ToolExecutionError &TEE) {
std::cerr << TEE.what(); errs() << TEE.what();
if (Interpreter != SafeInterpreter) { if (Interpreter != SafeInterpreter) {
std::cerr << "*** There is a bug running the \"safe\" backend. Either" errs() << "*** There is a bug running the \"safe\" backend. Either"
<< " debug it (for example with the -run-cbe bugpoint option," << " debug it (for example with the -run-cbe bugpoint option,"
<< " if CBE is being used as the \"safe\" backend), or fix the" << " if CBE is being used as the \"safe\" backend), or fix the"
<< " error some other way.\n"; << " error some other way.\n";
} }
return false; return false;
} }
@ -452,7 +452,7 @@ bool BugDriver::diffProgram(const std::string &BitcodeFile,
sys::Path(Output.toString()), sys::Path(Output.toString()),
AbsTolerance, RelTolerance, &Error)) { AbsTolerance, RelTolerance, &Error)) {
if (Diff == 2) { if (Diff == 2) {
std::cerr << "While diffing output: " << Error << '\n'; errs() << "While diffing output: " << Error << '\n';
exit(1); exit(1);
} }
FilesDifferent = true; FilesDifferent = true;

View File

@ -127,7 +127,7 @@ Module *BugDriver::performFinalCleanups(Module *M, bool MayModifySemantics) {
Module *New = runPassesOn(M, CleanupPasses); Module *New = runPassesOn(M, CleanupPasses);
if (New == 0) { if (New == 0) {
std::cerr << "Final cleanups failed. Sorry. :( Please report a bug!\n"; errs() << "Final cleanups failed. Sorry. :( Please report a bug!\n";
return M; return M;
} }
delete M; delete M;
@ -288,9 +288,9 @@ llvm::SplitFunctionsOutOfModule(Module *M,
std::set<Function *> TestFunctions; std::set<Function *> TestFunctions;
for (unsigned i = 0, e = F.size(); i != e; ++i) { for (unsigned i = 0, e = F.size(); i != e; ++i) {
Function *TNOF = cast<Function>(ValueMap[F[i]]); Function *TNOF = cast<Function>(ValueMap[F[i]]);
DEBUG(std::cerr << "Removing function "); DEBUG(errs() << "Removing function ");
DEBUG(WriteAsOperand(std::cerr, TNOF, false)); DEBUG(WriteAsOperand(errs(), TNOF, false));
DEBUG(std::cerr << "\n"); DEBUG(errs() << "\n");
TestFunctions.insert(cast<Function>(NewValueMap[TNOF])); TestFunctions.insert(cast<Function>(NewValueMap[TNOF]));
DeleteFunctionBody(TNOF); // Function is now external in this module! DeleteFunctionBody(TNOF); // Function is now external in this module!
} }
@ -328,7 +328,7 @@ Module *BugDriver::ExtractMappedBlocksFromModule(const
std::string ErrMsg; std::string ErrMsg;
if (uniqueFilename.createTemporaryFileOnDisk(true, &ErrMsg)) { if (uniqueFilename.createTemporaryFileOnDisk(true, &ErrMsg)) {
std::cout << "*** Basic Block extraction failed!\n"; std::cout << "*** Basic Block extraction failed!\n";
std::cerr << "Error creating temporary file: " << ErrMsg << "\n"; errs() << "Error creating temporary file: " << ErrMsg << "\n";
M = swapProgramIn(M); M = swapProgramIn(M);
EmitProgressBitcode("basicblockextractfail", true); EmitProgressBitcode("basicblockextractfail", true);
swapProgramIn(M); swapProgramIn(M);
@ -339,8 +339,8 @@ Module *BugDriver::ExtractMappedBlocksFromModule(const
std::ofstream BlocksToNotExtractFile(uniqueFilename.c_str()); std::ofstream BlocksToNotExtractFile(uniqueFilename.c_str());
if (!BlocksToNotExtractFile) { if (!BlocksToNotExtractFile) {
std::cout << "*** Basic Block extraction failed!\n"; std::cout << "*** Basic Block extraction failed!\n";
std::cerr << "Error writing list of blocks to not extract: " << ErrMsg errs() << "Error writing list of blocks to not extract: " << ErrMsg
<< "\n"; << "\n";
M = swapProgramIn(M); M = swapProgramIn(M);
EmitProgressBitcode("basicblockextractfail", true); EmitProgressBitcode("basicblockextractfail", true);
swapProgramIn(M); swapProgramIn(M);

View File

@ -97,7 +97,7 @@ bool BugDriver::runManyPasses(const std::vector<const PassInfo*> &AllPasses) {
std::cout << "\n*** diff'd output matches!\n"; std::cout << "\n*** diff'd output matches!\n";
} }
} catch (ToolExecutionError &TEE) { } catch (ToolExecutionError &TEE) {
std::cerr << TEE.what(); errs() << TEE.what();
debugCodeGeneratorCrash(); debugCodeGeneratorCrash();
return true; return true;
} }

View File

@ -15,8 +15,8 @@
#ifndef BUGPOINT_LIST_REDUCER_H #ifndef BUGPOINT_LIST_REDUCER_H
#define BUGPOINT_LIST_REDUCER_H #define BUGPOINT_LIST_REDUCER_H
#include "llvm/Support/raw_ostream.h"
#include <vector> #include <vector>
#include <iostream>
#include <cstdlib> #include <cstdlib>
#include <algorithm> #include <algorithm>
@ -58,7 +58,7 @@ struct ListReducer {
case KeepSuffix: case KeepSuffix:
// cannot be reached! // cannot be reached!
std::cerr << "bugpoint ListReducer internal error: selected empty set.\n"; errs() << "bugpoint ListReducer internal error: selected empty set.\n";
abort(); abort();
case NoFailure: case NoFailure:
@ -77,7 +77,7 @@ Backjump:
while (MidTop > 1) { // Binary split reduction loop while (MidTop > 1) { // Binary split reduction loop
// Halt if the user presses ctrl-c. // Halt if the user presses ctrl-c.
if (BugpointIsInterrupted) { if (BugpointIsInterrupted) {
std::cerr << "\n\n*** Reduction Interrupted, cleaning up...\n\n"; errs() << "\n\n*** Reduction Interrupted, cleaning up...\n\n";
return true; return true;
} }
@ -88,7 +88,7 @@ Backjump:
NumOfIterationsWithoutProgress > MaxIterations) { NumOfIterationsWithoutProgress > MaxIterations) {
std::vector<ElTy> ShuffledList(TheList); std::vector<ElTy> ShuffledList(TheList);
std::random_shuffle(ShuffledList.begin(), ShuffledList.end()); std::random_shuffle(ShuffledList.begin(), ShuffledList.end());
std::cerr << "\n\n*** Testing shuffled set...\n\n"; errs() << "\n\n*** Testing shuffled set...\n\n";
// Check that random shuffle doesn't loose the bug // Check that random shuffle doesn't loose the bug
if (doTest(ShuffledList, empty) == KeepPrefix) { if (doTest(ShuffledList, empty) == KeepPrefix) {
// If the bug is still here, use the shuffled list. // If the bug is still here, use the shuffled list.
@ -97,10 +97,10 @@ Backjump:
// Must increase the shuffling treshold to avoid the small // Must increase the shuffling treshold to avoid the small
// probability of inifinite looping without making progress. // probability of inifinite looping without making progress.
MaxIterations += 2; MaxIterations += 2;
std::cerr << "\n\n*** Shuffling does not hide the bug...\n\n"; errs() << "\n\n*** Shuffling does not hide the bug...\n\n";
} else { } else {
ShufflingEnabled = false; // Disable shuffling further on ShufflingEnabled = false; // Disable shuffling further on
std::cerr << "\n\n*** Shuffling hides the bug...\n\n"; errs() << "\n\n*** Shuffling hides the bug...\n\n";
} }
NumOfIterationsWithoutProgress = 0; NumOfIterationsWithoutProgress = 0;
} }
@ -160,7 +160,7 @@ Backjump:
for (unsigned i = 1; i < TheList.size()-1; ++i) { // Check interior elts for (unsigned i = 1; i < TheList.size()-1; ++i) { // Check interior elts
if (BugpointIsInterrupted) { if (BugpointIsInterrupted) {
std::cerr << "\n\n*** Reduction Interrupted, cleaning up...\n\n"; errs() << "\n\n*** Reduction Interrupted, cleaning up...\n\n";
return true; return true;
} }

View File

@ -26,6 +26,7 @@
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileUtilities.h" #include "llvm/Support/FileUtilities.h"
#include "llvm/Config/config.h" // for HAVE_LINK_R #include "llvm/Config/config.h" // for HAVE_LINK_R
#include <iostream>
using namespace llvm; using namespace llvm;
namespace llvm { namespace llvm {
@ -61,8 +62,8 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
std::string BitcodeResult; std::string BitcodeResult;
if (BD.runPasses(Suffix, BitcodeResult, false/*delete*/, true/*quiet*/)) { if (BD.runPasses(Suffix, BitcodeResult, false/*delete*/, true/*quiet*/)) {
std::cerr << " Error running this sequence of passes" errs() << " Error running this sequence of passes"
<< " on the input program!\n"; << " on the input program!\n";
BD.setPassesToRun(Suffix); BD.setPassesToRun(Suffix);
BD.EmitProgressBitcode("pass-error", false); BD.EmitProgressBitcode("pass-error", false);
exit(BD.debugOptimizerCrash()); exit(BD.debugOptimizerCrash());
@ -72,8 +73,8 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
if (BD.diffProgram(BitcodeResult, "", true /*delete bitcode*/)) { if (BD.diffProgram(BitcodeResult, "", true /*delete bitcode*/)) {
std::cout << " nope.\n"; std::cout << " nope.\n";
if (Suffix.empty()) { if (Suffix.empty()) {
std::cerr << BD.getToolName() << ": I'm confused: the test fails when " errs() << BD.getToolName() << ": I'm confused: the test fails when "
<< "no passes are run, nondeterministic program?\n"; << "no passes are run, nondeterministic program?\n";
exit(1); exit(1);
} }
return KeepSuffix; // Miscompilation detected! return KeepSuffix; // Miscompilation detected!
@ -94,8 +95,8 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
// prefix passes, then discard the prefix passes. // prefix passes, then discard the prefix passes.
// //
if (BD.runPasses(Prefix, BitcodeResult, false/*delete*/, true/*quiet*/)) { if (BD.runPasses(Prefix, BitcodeResult, false/*delete*/, true/*quiet*/)) {
std::cerr << " Error running this sequence of passes" errs() << " Error running this sequence of passes"
<< " on the input program!\n"; << " on the input program!\n";
BD.setPassesToRun(Prefix); BD.setPassesToRun(Prefix);
BD.EmitProgressBitcode("pass-error", false); BD.EmitProgressBitcode("pass-error", false);
exit(BD.debugOptimizerCrash()); exit(BD.debugOptimizerCrash());
@ -114,8 +115,8 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
// //
Module *PrefixOutput = ParseInputFile(BitcodeResult, BD.getContext()); Module *PrefixOutput = ParseInputFile(BitcodeResult, BD.getContext());
if (PrefixOutput == 0) { if (PrefixOutput == 0) {
std::cerr << BD.getToolName() << ": Error reading bitcode file '" errs() << BD.getToolName() << ": Error reading bitcode file '"
<< BitcodeResult << "'!\n"; << BitcodeResult << "'!\n";
exit(1); exit(1);
} }
sys::Path(BitcodeResult).eraseFromDisk(); // No longer need the file on disk sys::Path(BitcodeResult).eraseFromDisk(); // No longer need the file on disk
@ -130,8 +131,8 @@ ReduceMiscompilingPasses::doTest(std::vector<const PassInfo*> &Prefix,
Module *OriginalInput = BD.swapProgramIn(PrefixOutput); Module *OriginalInput = BD.swapProgramIn(PrefixOutput);
if (BD.runPasses(Suffix, BitcodeResult, false/*delete*/, true/*quiet*/)) { if (BD.runPasses(Suffix, BitcodeResult, false/*delete*/, true/*quiet*/)) {
std::cerr << " Error running this sequence of passes" errs() << " Error running this sequence of passes"
<< " on the input program!\n"; << " on the input program!\n";
BD.setPassesToRun(Suffix); BD.setPassesToRun(Suffix);
BD.EmitProgressBitcode("pass-error", false); BD.EmitProgressBitcode("pass-error", false);
exit(BD.debugOptimizerCrash()); exit(BD.debugOptimizerCrash());
@ -187,8 +188,8 @@ static bool TestMergedProgram(BugDriver &BD, Module *M1, Module *M2,
M2 = CloneModule(M2); M2 = CloneModule(M2);
} }
if (Linker::LinkModules(M1, M2, &ErrorMsg)) { if (Linker::LinkModules(M1, M2, &ErrorMsg)) {
std::cerr << BD.getToolName() << ": Error linking modules together:" errs() << BD.getToolName() << ": Error linking modules together:"
<< ErrorMsg << '\n'; << ErrorMsg << '\n';
exit(1); exit(1);
} }
delete M2; // We are done with this module. delete M2; // We are done with this module.
@ -279,7 +280,7 @@ static bool ExtractLoops(BugDriver &BD,
return MadeChange; return MadeChange;
} }
std::cerr << "Extracted a loop from the breaking portion of the program.\n"; errs() << "Extracted a loop from the breaking portion of the program.\n";
// Bugpoint is intentionally not very trusting of LLVM transformations. In // Bugpoint is intentionally not very trusting of LLVM transformations. In
// particular, we're not going to assume that the loop extractor works, so // particular, we're not going to assume that the loop extractor works, so
@ -291,16 +292,16 @@ static bool ExtractLoops(BugDriver &BD,
BD.switchToInterpreter(AI); BD.switchToInterpreter(AI);
// Merged program doesn't work anymore! // Merged program doesn't work anymore!
std::cerr << " *** ERROR: Loop extraction broke the program. :(" errs() << " *** ERROR: Loop extraction broke the program. :("
<< " Please report a bug!\n"; << " Please report a bug!\n";
std::cerr << " Continuing on with un-loop-extracted version.\n"; errs() << " Continuing on with un-loop-extracted version.\n";
BD.writeProgramToFile("bugpoint-loop-extract-fail-tno.bc", ToNotOptimize); BD.writeProgramToFile("bugpoint-loop-extract-fail-tno.bc", ToNotOptimize);
BD.writeProgramToFile("bugpoint-loop-extract-fail-to.bc", ToOptimize); BD.writeProgramToFile("bugpoint-loop-extract-fail-to.bc", ToOptimize);
BD.writeProgramToFile("bugpoint-loop-extract-fail-to-le.bc", BD.writeProgramToFile("bugpoint-loop-extract-fail-to-le.bc",
ToOptimizeLoopExtracted); ToOptimizeLoopExtracted);
std::cerr << "Please submit the bugpoint-loop-extract-fail-*.bc files.\n"; errs() << "Please submit the bugpoint-loop-extract-fail-*.bc files.\n";
delete ToOptimize; delete ToOptimize;
delete ToNotOptimize; delete ToNotOptimize;
delete ToOptimizeLoopExtracted; delete ToOptimizeLoopExtracted;
@ -339,8 +340,8 @@ static bool ExtractLoops(BugDriver &BD,
// extract another loop. // extract another loop.
std::string ErrorMsg; std::string ErrorMsg;
if (Linker::LinkModules(ToNotOptimize, ToOptimizeLoopExtracted, &ErrorMsg)){ if (Linker::LinkModules(ToNotOptimize, ToOptimizeLoopExtracted, &ErrorMsg)){
std::cerr << BD.getToolName() << ": Error linking modules together:" errs() << BD.getToolName() << ": Error linking modules together:"
<< ErrorMsg << '\n'; << ErrorMsg << '\n';
exit(1); exit(1);
} }
delete ToOptimizeLoopExtracted; delete ToOptimizeLoopExtracted;
@ -462,7 +463,7 @@ static bool ExtractBlocks(BugDriver &BD,
Module *Extracted = BD.ExtractMappedBlocksFromModule(Blocks, ToExtract); Module *Extracted = BD.ExtractMappedBlocksFromModule(Blocks, ToExtract);
if (Extracted == 0) { if (Extracted == 0) {
// Weird, extraction should have worked. // Weird, extraction should have worked.
std::cerr << "Nondeterministic problem extracting blocks??\n"; errs() << "Nondeterministic problem extracting blocks??\n";
delete ProgClone; delete ProgClone;
delete ToExtract; delete ToExtract;
return false; return false;
@ -481,8 +482,8 @@ static bool ExtractBlocks(BugDriver &BD,
std::string ErrorMsg; std::string ErrorMsg;
if (Linker::LinkModules(ProgClone, Extracted, &ErrorMsg)) { if (Linker::LinkModules(ProgClone, Extracted, &ErrorMsg)) {
std::cerr << BD.getToolName() << ": Error linking modules together:" errs() << BD.getToolName() << ": Error linking modules together:"
<< ErrorMsg << '\n'; << ErrorMsg << '\n';
exit(1); exit(1);
} }
delete Extracted; delete Extracted;
@ -606,8 +607,8 @@ bool BugDriver::debugMiscompilation() {
// Make sure something was miscompiled... // Make sure something was miscompiled...
if (!BugpointIsInterrupted) if (!BugpointIsInterrupted)
if (!ReduceMiscompilingPasses(*this).reduceList(PassesToRun)) { if (!ReduceMiscompilingPasses(*this).reduceList(PassesToRun)) {
std::cerr << "*** Optimized program matches reference output! No problem" errs() << "*** Optimized program matches reference output! No problem"
<< " detected...\nbugpoint can't help you with your problem!\n"; << " detected...\nbugpoint can't help you with your problem!\n";
return false; return false;
} }
@ -796,7 +797,7 @@ static void CleanupAndPrepareModules(BugDriver &BD, Module *&Test,
} }
if (verifyModule(*Test) || verifyModule(*Safe)) { if (verifyModule(*Test) || verifyModule(*Safe)) {
std::cerr << "Bugpoint has a bug, which corrupted a module!!\n"; errs() << "Bugpoint has a bug, which corrupted a module!!\n";
abort(); abort();
} }
} }
@ -813,12 +814,12 @@ static bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe) {
sys::Path TestModuleBC("bugpoint.test.bc"); sys::Path TestModuleBC("bugpoint.test.bc");
std::string ErrMsg; std::string ErrMsg;
if (TestModuleBC.makeUnique(true, &ErrMsg)) { if (TestModuleBC.makeUnique(true, &ErrMsg)) {
std::cerr << BD.getToolName() << "Error making unique filename: " errs() << BD.getToolName() << "Error making unique filename: "
<< ErrMsg << "\n"; << ErrMsg << "\n";
exit(1); exit(1);
} }
if (BD.writeProgramToFile(TestModuleBC.toString(), Test)) { if (BD.writeProgramToFile(TestModuleBC.toString(), Test)) {
std::cerr << "Error writing bitcode to `" << TestModuleBC << "'\nExiting."; errs() << "Error writing bitcode to `" << TestModuleBC << "'\nExiting.";
exit(1); exit(1);
} }
delete Test; delete Test;
@ -826,13 +827,13 @@ static bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe) {
// Make the shared library // Make the shared library
sys::Path SafeModuleBC("bugpoint.safe.bc"); sys::Path SafeModuleBC("bugpoint.safe.bc");
if (SafeModuleBC.makeUnique(true, &ErrMsg)) { if (SafeModuleBC.makeUnique(true, &ErrMsg)) {
std::cerr << BD.getToolName() << "Error making unique filename: " errs() << BD.getToolName() << "Error making unique filename: "
<< ErrMsg << "\n"; << ErrMsg << "\n";
exit(1); exit(1);
} }
if (BD.writeProgramToFile(SafeModuleBC.toString(), Safe)) { if (BD.writeProgramToFile(SafeModuleBC.toString(), Safe)) {
std::cerr << "Error writing bitcode to `" << SafeModuleBC << "'\nExiting."; errs() << "Error writing bitcode to `" << SafeModuleBC << "'\nExiting.";
exit(1); exit(1);
} }
std::string SharedObject = BD.compileSharedObject(SafeModuleBC.toString()); std::string SharedObject = BD.compileSharedObject(SafeModuleBC.toString());
@ -843,9 +844,9 @@ static bool TestCodeGenerator(BugDriver &BD, Module *Test, Module *Safe) {
int Result = BD.diffProgram(TestModuleBC.toString(), SharedObject, false); int Result = BD.diffProgram(TestModuleBC.toString(), SharedObject, false);
if (Result) if (Result)
std::cerr << ": still failing!\n"; errs() << ": still failing!\n";
else else
std::cerr << ": didn't fail.\n"; errs() << ": didn't fail.\n";
TestModuleBC.eraseFromDisk(); TestModuleBC.eraseFromDisk();
SafeModuleBC.eraseFromDisk(); SafeModuleBC.eraseFromDisk();
sys::Path(SharedObject).eraseFromDisk(); sys::Path(SharedObject).eraseFromDisk();
@ -885,13 +886,13 @@ bool BugDriver::debugCodeGenerator() {
sys::Path TestModuleBC("bugpoint.test.bc"); sys::Path TestModuleBC("bugpoint.test.bc");
std::string ErrMsg; std::string ErrMsg;
if (TestModuleBC.makeUnique(true, &ErrMsg)) { if (TestModuleBC.makeUnique(true, &ErrMsg)) {
std::cerr << getToolName() << "Error making unique filename: " errs() << getToolName() << "Error making unique filename: "
<< ErrMsg << "\n"; << ErrMsg << "\n";
exit(1); exit(1);
} }
if (writeProgramToFile(TestModuleBC.toString(), ToCodeGen)) { if (writeProgramToFile(TestModuleBC.toString(), ToCodeGen)) {
std::cerr << "Error writing bitcode to `" << TestModuleBC << "'\nExiting."; errs() << "Error writing bitcode to `" << TestModuleBC << "'\nExiting.";
exit(1); exit(1);
} }
delete ToCodeGen; delete ToCodeGen;
@ -899,13 +900,13 @@ bool BugDriver::debugCodeGenerator() {
// Make the shared library // Make the shared library
sys::Path SafeModuleBC("bugpoint.safe.bc"); sys::Path SafeModuleBC("bugpoint.safe.bc");
if (SafeModuleBC.makeUnique(true, &ErrMsg)) { if (SafeModuleBC.makeUnique(true, &ErrMsg)) {
std::cerr << getToolName() << "Error making unique filename: " errs() << getToolName() << "Error making unique filename: "
<< ErrMsg << "\n"; << ErrMsg << "\n";
exit(1); exit(1);
} }
if (writeProgramToFile(SafeModuleBC.toString(), ToNotCodeGen)) { if (writeProgramToFile(SafeModuleBC.toString(), ToNotCodeGen)) {
std::cerr << "Error writing bitcode to `" << SafeModuleBC << "'\nExiting."; errs() << "Error writing bitcode to `" << SafeModuleBC << "'\nExiting.";
exit(1); exit(1);
} }
std::string SharedObject = compileSharedObject(SafeModuleBC.toString()); std::string SharedObject = compileSharedObject(SafeModuleBC.toString());

View File

@ -63,10 +63,10 @@ static int RunProgramWithTimeout(const sys::Path &ProgramPath,
redirects[2] = &StdErrFile; redirects[2] = &StdErrFile;
if (0) { if (0) {
std::cerr << "RUN:"; errs() << "RUN:";
for (unsigned i = 0; Args[i]; ++i) for (unsigned i = 0; Args[i]; ++i)
std::cerr << " " << Args[i]; errs() << " " << Args[i];
std::cerr << "\n"; errs() << "\n";
} }
return return
@ -87,7 +87,7 @@ static void ProcessFailure(sys::Path ProgPath, const char** Args) {
sys::Path ErrorFilename("bugpoint.program_error_messages"); sys::Path ErrorFilename("bugpoint.program_error_messages");
std::string ErrMsg; std::string ErrMsg;
if (ErrorFilename.makeUnique(true, &ErrMsg)) { if (ErrorFilename.makeUnique(true, &ErrMsg)) {
std::cerr << "Error making unique filename: " << ErrMsg << "\n"; errs() << "Error making unique filename: " << ErrMsg << "\n";
exit(1); exit(1);
} }
RunProgramWithTimeout(ProgPath, Args, sys::Path(""), ErrorFilename, RunProgramWithTimeout(ProgPath, Args, sys::Path(""), ErrorFilename,
@ -159,10 +159,10 @@ int LLI::ExecuteProgram(const std::string &Bitcode,
LLIArgs.push_back(0); LLIArgs.push_back(0);
std::cout << "<lli>" << std::flush; std::cout << "<lli>" << std::flush;
DEBUG(std::cerr << "\nAbout to run:\t"; DEBUG(errs() << "\nAbout to run:\t";
for (unsigned i=0, e = LLIArgs.size()-1; i != e; ++i) for (unsigned i=0, e = LLIArgs.size()-1; i != e; ++i)
std::cerr << " " << LLIArgs[i]; errs() << " " << LLIArgs[i];
std::cerr << "\n"; errs() << "\n";
); );
return RunProgramWithTimeout(sys::Path(LLIPath), &LLIArgs[0], return RunProgramWithTimeout(sys::Path(LLIPath), &LLIArgs[0],
sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile), sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
@ -295,7 +295,7 @@ GCC::FileType LLC::OutputCode(const std::string &Bitcode,
sys::Path uniqueFile(Bitcode+".llc.s"); sys::Path uniqueFile(Bitcode+".llc.s");
std::string ErrMsg; std::string ErrMsg;
if (uniqueFile.makeUnique(true, &ErrMsg)) { if (uniqueFile.makeUnique(true, &ErrMsg)) {
std::cerr << "Error making unique filename: " << ErrMsg << "\n"; errs() << "Error making unique filename: " << ErrMsg << "\n";
exit(1); exit(1);
} }
OutputAsmFile = uniqueFile; OutputAsmFile = uniqueFile;
@ -313,10 +313,10 @@ GCC::FileType LLC::OutputCode(const std::string &Bitcode,
LLCArgs.push_back (0); LLCArgs.push_back (0);
std::cout << "<llc>" << std::flush; std::cout << "<llc>" << std::flush;
DEBUG(std::cerr << "\nAbout to run:\t"; DEBUG(errs() << "\nAbout to run:\t";
for (unsigned i=0, e = LLCArgs.size()-1; i != e; ++i) for (unsigned i=0, e = LLCArgs.size()-1; i != e; ++i)
std::cerr << " " << LLCArgs[i]; errs() << " " << LLCArgs[i];
std::cerr << "\n"; errs() << "\n";
); );
if (RunProgramWithTimeout(sys::Path(LLCPath), &LLCArgs[0], if (RunProgramWithTimeout(sys::Path(LLCPath), &LLCArgs[0],
sys::Path(), sys::Path(), sys::Path())) sys::Path(), sys::Path(), sys::Path()))
@ -369,7 +369,7 @@ LLC *AbstractInterpreter::createLLC(const std::string &ProgramPath,
Message = "Found llc: " + LLCPath + "\n"; Message = "Found llc: " + LLCPath + "\n";
GCC *gcc = GCC::create(ProgramPath, Message, GCCArgs); GCC *gcc = GCC::create(ProgramPath, Message, GCCArgs);
if (!gcc) { if (!gcc) {
std::cerr << Message << "\n"; errs() << Message << "\n";
exit(1); exit(1);
} }
return new LLC(LLCPath, gcc, Args, GCCArgs); return new LLC(LLCPath, gcc, Args, GCCArgs);
@ -430,12 +430,12 @@ int JIT::ExecuteProgram(const std::string &Bitcode,
JITArgs.push_back(0); JITArgs.push_back(0);
std::cout << "<jit>" << std::flush; std::cout << "<jit>" << std::flush;
DEBUG(std::cerr << "\nAbout to run:\t"; DEBUG(errs() << "\nAbout to run:\t";
for (unsigned i=0, e = JITArgs.size()-1; i != e; ++i) for (unsigned i=0, e = JITArgs.size()-1; i != e; ++i)
std::cerr << " " << JITArgs[i]; errs() << " " << JITArgs[i];
std::cerr << "\n"; errs() << "\n";
); );
DEBUG(std::cerr << "\nSending output to " << OutputFile << "\n"); DEBUG(errs() << "\nSending output to " << OutputFile << "\n");
return RunProgramWithTimeout(sys::Path(LLIPath), &JITArgs[0], return RunProgramWithTimeout(sys::Path(LLIPath), &JITArgs[0],
sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile), sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
Timeout, MemoryLimit); Timeout, MemoryLimit);
@ -460,7 +460,7 @@ GCC::FileType CBE::OutputCode(const std::string &Bitcode,
sys::Path uniqueFile(Bitcode+".cbe.c"); sys::Path uniqueFile(Bitcode+".cbe.c");
std::string ErrMsg; std::string ErrMsg;
if (uniqueFile.makeUnique(true, &ErrMsg)) { if (uniqueFile.makeUnique(true, &ErrMsg)) {
std::cerr << "Error making unique filename: " << ErrMsg << "\n"; errs() << "Error making unique filename: " << ErrMsg << "\n";
exit(1); exit(1);
} }
OutputCFile = uniqueFile; OutputCFile = uniqueFile;
@ -479,10 +479,10 @@ GCC::FileType CBE::OutputCode(const std::string &Bitcode,
LLCArgs.push_back (0); LLCArgs.push_back (0);
std::cout << "<cbe>" << std::flush; std::cout << "<cbe>" << std::flush;
DEBUG(std::cerr << "\nAbout to run:\t"; DEBUG(errs() << "\nAbout to run:\t";
for (unsigned i=0, e = LLCArgs.size()-1; i != e; ++i) for (unsigned i=0, e = LLCArgs.size()-1; i != e; ++i)
std::cerr << " " << LLCArgs[i]; errs() << " " << LLCArgs[i];
std::cerr << "\n"; errs() << "\n";
); );
if (RunProgramWithTimeout(LLCPath, &LLCArgs[0], sys::Path(), sys::Path(), if (RunProgramWithTimeout(LLCPath, &LLCArgs[0], sys::Path(), sys::Path(),
sys::Path())) sys::Path()))
@ -533,7 +533,7 @@ CBE *AbstractInterpreter::createCBE(const std::string &ProgramPath,
Message = "Found llc: " + LLCPath.toString() + "\n"; Message = "Found llc: " + LLCPath.toString() + "\n";
GCC *gcc = GCC::create(ProgramPath, Message, GCCArgs); GCC *gcc = GCC::create(ProgramPath, Message, GCCArgs);
if (!gcc) { if (!gcc) {
std::cerr << Message << "\n"; errs() << Message << "\n";
exit(1); exit(1);
} }
return new CBE(LLCPath, gcc, Args); return new CBE(LLCPath, gcc, Args);
@ -599,7 +599,7 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
sys::Path OutputBinary (ProgramFile+".gcc.exe"); sys::Path OutputBinary (ProgramFile+".gcc.exe");
std::string ErrMsg; std::string ErrMsg;
if (OutputBinary.makeUnique(true, &ErrMsg)) { if (OutputBinary.makeUnique(true, &ErrMsg)) {
std::cerr << "Error making unique filename: " << ErrMsg << "\n"; errs() << "Error making unique filename: " << ErrMsg << "\n";
exit(1); exit(1);
} }
GCCArgs.push_back(OutputBinary.c_str()); // Output to the right file... GCCArgs.push_back(OutputBinary.c_str()); // Output to the right file...
@ -622,10 +622,10 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
GCCArgs.push_back(0); // NULL terminator GCCArgs.push_back(0); // NULL terminator
std::cout << "<gcc>" << std::flush; std::cout << "<gcc>" << std::flush;
DEBUG(std::cerr << "\nAbout to run:\t"; DEBUG(errs() << "\nAbout to run:\t";
for (unsigned i=0, e = GCCArgs.size()-1; i != e; ++i) for (unsigned i=0, e = GCCArgs.size()-1; i != e; ++i)
std::cerr << " " << GCCArgs[i]; errs() << " " << GCCArgs[i];
std::cerr << "\n"; errs() << "\n";
); );
if (RunProgramWithTimeout(GCCPath, &GCCArgs[0], sys::Path(), sys::Path(), if (RunProgramWithTimeout(GCCPath, &GCCArgs[0], sys::Path(), sys::Path(),
sys::Path())) { sys::Path())) {
@ -666,16 +666,16 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
// Now that we have a binary, run it! // Now that we have a binary, run it!
std::cout << "<program>" << std::flush; std::cout << "<program>" << std::flush;
DEBUG(std::cerr << "\nAbout to run:\t"; DEBUG(errs() << "\nAbout to run:\t";
for (unsigned i=0, e = ProgramArgs.size()-1; i != e; ++i) for (unsigned i=0, e = ProgramArgs.size()-1; i != e; ++i)
std::cerr << " " << ProgramArgs[i]; errs() << " " << ProgramArgs[i];
std::cerr << "\n"; errs() << "\n";
); );
FileRemover OutputBinaryRemover(OutputBinary); FileRemover OutputBinaryRemover(OutputBinary);
if (RemoteClientPath.isEmpty()) { if (RemoteClientPath.isEmpty()) {
DEBUG(std::cerr << "<run locally>" << std::flush;); DEBUG(errs() << "<run locally>";);
return RunProgramWithTimeout(OutputBinary, &ProgramArgs[0], return RunProgramWithTimeout(OutputBinary, &ProgramArgs[0],
sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile), sys::Path(InputFile), sys::Path(OutputFile), sys::Path(OutputFile),
Timeout, MemoryLimit); Timeout, MemoryLimit);
@ -685,8 +685,8 @@ int GCC::ExecuteProgram(const std::string &ProgramFile,
&ProgramArgs[0], sys::Path(InputFile), sys::Path(OutputFile), &ProgramArgs[0], sys::Path(InputFile), sys::Path(OutputFile),
sys::Path(OutputFile), Timeout, MemoryLimit); sys::Path(OutputFile), Timeout, MemoryLimit);
if (RemoteClientStatus != 0) { if (RemoteClientStatus != 0) {
std::cerr << "Remote Client failed with an error: " << errs() << "Remote Client failed with an error: " <<
RemoteClientStatus << ".\n" << std::flush; RemoteClientStatus << ".\n";
} }
} }
@ -699,7 +699,7 @@ int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
sys::Path uniqueFilename(InputFile+LTDL_SHLIB_EXT); sys::Path uniqueFilename(InputFile+LTDL_SHLIB_EXT);
std::string ErrMsg; std::string ErrMsg;
if (uniqueFilename.makeUnique(true, &ErrMsg)) { if (uniqueFilename.makeUnique(true, &ErrMsg)) {
std::cerr << "Error making unique filename: " << ErrMsg << "\n"; errs() << "Error making unique filename: " << ErrMsg << "\n";
exit(1); exit(1);
} }
OutputFile = uniqueFilename.toString(); OutputFile = uniqueFilename.toString();
@ -757,10 +757,10 @@ int GCC::MakeSharedObject(const std::string &InputFile, FileType fileType,
std::cout << "<gcc>" << std::flush; std::cout << "<gcc>" << std::flush;
DEBUG(std::cerr << "\nAbout to run:\t"; DEBUG(errs() << "\nAbout to run:\t";
for (unsigned i=0, e = GCCArgs.size()-1; i != e; ++i) for (unsigned i=0, e = GCCArgs.size()-1; i != e; ++i)
std::cerr << " " << GCCArgs[i]; errs() << " " << GCCArgs[i];
std::cerr << "\n"; errs() << "\n";
); );
if (RunProgramWithTimeout(GCCPath, &GCCArgs[0], sys::Path(), sys::Path(), if (RunProgramWithTimeout(GCCPath, &GCCArgs[0], sys::Path(), sys::Path(),
sys::Path())) { sys::Path())) {

View File

@ -87,20 +87,20 @@ int main(int argc, char **argv) {
try { try {
return D.run(); return D.run();
} catch (ToolExecutionError &TEE) { } catch (ToolExecutionError &TEE) {
std::cerr << "Tool execution error: " << TEE.what() << '\n'; errs() << "Tool execution error: " << TEE.what() << '\n';
} catch (const std::string& msg) { } catch (const std::string& msg) {
std::cerr << argv[0] << ": " << msg << "\n"; errs() << argv[0] << ": " << msg << "\n";
} catch (const std::bad_alloc &e) { } catch (const std::bad_alloc &e) {
std::cerr << "Oh no, a bugpoint process ran out of memory!\n" errs() << "Oh no, a bugpoint process ran out of memory!\n"
"To increase the allocation limits for bugpoint child\n" "To increase the allocation limits for bugpoint child\n"
"processes, use the -mlimit option.\n"; "processes, use the -mlimit option.\n";
} catch (const std::exception &e) { } catch (const std::exception &e) {
std::cerr << "Whoops, a std::exception leaked out of bugpoint: " errs() << "Whoops, a std::exception leaked out of bugpoint: "
<< e.what() << "\n" << e.what() << "\n"
<< "This is a bug in bugpoint!\n"; << "This is a bug in bugpoint!\n";
} catch (...) { } catch (...) {
std::cerr << "Whoops, an exception leaked out of bugpoint. " errs() << "Whoops, an exception leaked out of bugpoint. "
<< "This is a bug in bugpoint!\n"; << "This is a bug in bugpoint!\n";
} }
return 1; return 1;
} }

View File

@ -137,9 +137,9 @@ static formatted_raw_ostream *GetOutputStream(const char *TargetName,
// Specified an output filename? // Specified an output filename?
if (!Force && std::ifstream(OutputFilename.c_str())) { if (!Force && std::ifstream(OutputFilename.c_str())) {
// If force is not specified, make sure not to overwrite a file! // If force is not specified, make sure not to overwrite a file!
std::cerr << ProgName << ": error opening '" << OutputFilename errs() << ProgName << ": error opening '" << OutputFilename
<< "': file exists!\n" << "': file exists!\n"
<< "Use -f command line argument to force output\n"; << "Use -f command line argument to force output\n";
return 0; return 0;
} }
// Make sure that the Out file gets unlinked from the disk if we get a // Make sure that the Out file gets unlinked from the disk if we get a
@ -152,7 +152,7 @@ static formatted_raw_ostream *GetOutputStream(const char *TargetName,
formatted_raw_ostream *Out = formatted_raw_ostream *Out =
new formatted_raw_ostream(*FDOut, formatted_raw_ostream::DELETE_STREAM); new formatted_raw_ostream(*FDOut, formatted_raw_ostream::DELETE_STREAM);
if (!error.empty()) { if (!error.empty()) {
std::cerr << error << '\n'; errs() << error << '\n';
delete Out; delete Out;
return 0; return 0;
} }
@ -192,9 +192,9 @@ static formatted_raw_ostream *GetOutputStream(const char *TargetName,
if (!Force && std::ifstream(OutputFilename.c_str())) { if (!Force && std::ifstream(OutputFilename.c_str())) {
// If force is not specified, make sure not to overwrite a file! // If force is not specified, make sure not to overwrite a file!
std::cerr << ProgName << ": error opening '" << OutputFilename errs() << ProgName << ": error opening '" << OutputFilename
<< "': file exists!\n" << "': file exists!\n"
<< "Use -f command line argument to force output\n"; << "Use -f command line argument to force output\n";
return 0; return 0;
} }
@ -208,7 +208,7 @@ static formatted_raw_ostream *GetOutputStream(const char *TargetName,
formatted_raw_ostream *Out = formatted_raw_ostream *Out =
new formatted_raw_ostream(*FDOut, formatted_raw_ostream::DELETE_STREAM); new formatted_raw_ostream(*FDOut, formatted_raw_ostream::DELETE_STREAM);
if (!error.empty()) { if (!error.empty()) {
std::cerr << error << '\n'; errs() << error << '\n';
delete Out; delete Out;
return 0; return 0;
} }
@ -237,8 +237,8 @@ int main(int argc, char **argv) {
if (Buffer.get()) if (Buffer.get())
M.reset(ParseBitcodeFile(Buffer.get(), Context, &ErrorMessage)); M.reset(ParseBitcodeFile(Buffer.get(), Context, &ErrorMessage));
if (M.get() == 0) { if (M.get() == 0) {
std::cerr << argv[0] << ": bitcode didn't read correctly.\n"; errs() << argv[0] << ": bitcode didn't read correctly.\n";
std::cerr << "Reason: " << ErrorMessage << "\n"; errs() << "Reason: " << ErrorMessage << "\n";
return 1; return 1;
} }
Module &mod = *M.get(); Module &mod = *M.get();
@ -256,9 +256,9 @@ int main(int argc, char **argv) {
std::string Err; std::string Err;
TheTarget = TargetRegistry::getClosestStaticTargetForModule(mod, Err); TheTarget = TargetRegistry::getClosestStaticTargetForModule(mod, Err);
if (TheTarget == 0) { if (TheTarget == 0) {
std::cerr << argv[0] << ": error auto-selecting target for module '" errs() << argv[0] << ": error auto-selecting target for module '"
<< Err << "'. Please use the -march option to explicitly " << Err << "'. Please use the -march option to explicitly "
<< "pick a target.\n"; << "pick a target.\n";
return 1; return 1;
} }
} }
@ -285,7 +285,7 @@ int main(int argc, char **argv) {
CodeGenOpt::Level OLvl = CodeGenOpt::Default; CodeGenOpt::Level OLvl = CodeGenOpt::Default;
switch (OptLevel) { switch (OptLevel) {
default: default:
std::cerr << argv[0] << ": invalid optimization level.\n"; errs() << argv[0] << ": invalid optimization level.\n";
return 1; return 1;
case ' ': break; case ' ': break;
case '0': OLvl = CodeGenOpt::None; break; case '0': OLvl = CodeGenOpt::None; break;
@ -304,8 +304,8 @@ int main(int argc, char **argv) {
// Ask the target to add backend passes as necessary. // Ask the target to add backend passes as necessary.
if (Target.addPassesToEmitWholeFile(PM, *Out, FileType, OLvl)) { if (Target.addPassesToEmitWholeFile(PM, *Out, FileType, OLvl)) {
std::cerr << argv[0] << ": target does not support generation of this" errs() << argv[0] << ": target does not support generation of this"
<< " file type!\n"; << " file type!\n";
if (Out != &fouts()) delete Out; if (Out != &fouts()) delete Out;
// And the Out file is empty and useless, so remove it now. // And the Out file is empty and useless, so remove it now.
sys::Path(OutputFilename).eraseFromDisk(); sys::Path(OutputFilename).eraseFromDisk();
@ -334,8 +334,8 @@ int main(int argc, char **argv) {
assert(0 && "Invalid file model!"); assert(0 && "Invalid file model!");
return 1; return 1;
case FileModel::Error: case FileModel::Error:
std::cerr << argv[0] << ": target does not support generation of this" errs() << argv[0] << ": target does not support generation of this"
<< " file type!\n"; << " file type!\n";
if (Out != &fouts()) delete Out; if (Out != &fouts()) delete Out;
// And the Out file is empty and useless, so remove it now. // And the Out file is empty and useless, so remove it now.
sys::Path(OutputFilename).eraseFromDisk(); sys::Path(OutputFilename).eraseFromDisk();
@ -351,8 +351,8 @@ int main(int argc, char **argv) {
} }
if (Target.addPassesToEmitFileFinish(Passes, OCE, OLvl)) { if (Target.addPassesToEmitFileFinish(Passes, OCE, OLvl)) {
std::cerr << argv[0] << ": target does not support generation of this" errs() << argv[0] << ": target does not support generation of this"
<< " file type!\n"; << " file type!\n";
if (Out != &fouts()) delete Out; if (Out != &fouts()) delete Out;
// And the Out file is empty and useless, so remove it now. // And the Out file is empty and useless, so remove it now.
sys::Path(OutputFilename).eraseFromDisk(); sys::Path(OutputFilename).eraseFromDisk();

View File

@ -112,8 +112,8 @@ int main(int argc, char **argv, char * const *envp) {
} }
if (!MP) { if (!MP) {
std::cerr << argv[0] << ": error loading program '" << InputFile << "': " errs() << argv[0] << ": error loading program '" << InputFile << "': "
<< ErrorMsg << "\n"; << ErrorMsg << "\n";
exit(1); exit(1);
} }
@ -121,8 +121,8 @@ int main(int argc, char **argv, char * const *envp) {
Module *Mod = NoLazyCompilation Module *Mod = NoLazyCompilation
? MP->materializeModule(&ErrorMsg) : MP->getModule(); ? MP->materializeModule(&ErrorMsg) : MP->getModule();
if (!Mod) { if (!Mod) {
std::cerr << argv[0] << ": bitcode didn't read correctly.\n"; errs() << argv[0] << ": bitcode didn't read correctly.\n";
std::cerr << "Reason: " << ErrorMsg << "\n"; errs() << "Reason: " << ErrorMsg << "\n";
exit(1); exit(1);
} }
@ -133,7 +133,7 @@ int main(int argc, char **argv, char * const *envp) {
CodeGenOpt::Level OLvl = CodeGenOpt::Default; CodeGenOpt::Level OLvl = CodeGenOpt::Default;
switch (OptLevel) { switch (OptLevel) {
default: default:
std::cerr << argv[0] << ": invalid optimization level.\n"; errs() << argv[0] << ": invalid optimization level.\n";
return 1; return 1;
case ' ': break; case ' ': break;
case '0': OLvl = CodeGenOpt::None; break; case '0': OLvl = CodeGenOpt::None; break;
@ -149,9 +149,9 @@ int main(int argc, char **argv, char * const *envp) {
EE = ExecutionEngine::create(MP, ForceInterpreter, &ErrorMsg, OLvl); EE = ExecutionEngine::create(MP, ForceInterpreter, &ErrorMsg, OLvl);
if (!EE) { if (!EE) {
if (!ErrorMsg.empty()) if (!ErrorMsg.empty())
std::cerr << argv[0] << ": error creating EE: " << ErrorMsg << "\n"; errs() << argv[0] << ": error creating EE: " << ErrorMsg << "\n";
else else
std::cerr << argv[0] << ": unknown error creating EE!\n"; errs() << argv[0] << ": unknown error creating EE!\n";
exit(1); exit(1);
} }
@ -182,7 +182,7 @@ int main(int argc, char **argv, char * const *envp) {
// //
Function *EntryFn = Mod->getFunction(EntryFunc); Function *EntryFn = Mod->getFunction(EntryFunc);
if (!EntryFn) { if (!EntryFn) {
std::cerr << '\'' << EntryFunc << "\' function not found in module.\n"; errs() << '\'' << EntryFunc << "\' function not found in module.\n";
return -1; return -1;
} }
@ -219,10 +219,10 @@ int main(int argc, char **argv, char * const *envp) {
ResultGV.IntVal = APInt(32, Result); ResultGV.IntVal = APInt(32, Result);
Args.push_back(ResultGV); Args.push_back(ResultGV);
EE->runFunction(ExitF, Args); EE->runFunction(ExitF, Args);
std::cerr << "ERROR: exit(" << Result << ") returned!\n"; errs() << "ERROR: exit(" << Result << ") returned!\n";
abort(); abort();
} else { } else {
std::cerr << "ERROR: exit defined with wrong prototype!\n"; errs() << "ERROR: exit defined with wrong prototype!\n";
abort(); abort();
} }
} }

View File

@ -18,6 +18,7 @@
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Signals.h" #include "llvm/System/Signals.h"
#include <iostream> #include <iostream>
#include <algorithm> #include <algorithm>
@ -718,15 +719,15 @@ int main(int argc, char **argv) {
if (!ArchivePath.exists()) { if (!ArchivePath.exists()) {
// Produce a warning if we should and we're creating the archive // Produce a warning if we should and we're creating the archive
if (!Create) if (!Create)
std::cerr << argv[0] << ": creating " << ArchivePath.toString() << "\n"; errs() << argv[0] << ": creating " << ArchivePath.toString() << "\n";
TheArchive = Archive::CreateEmpty(ArchivePath, Context); TheArchive = Archive::CreateEmpty(ArchivePath, Context);
TheArchive->writeToDisk(); TheArchive->writeToDisk();
} else { } else {
std::string Error; std::string Error;
TheArchive = Archive::OpenAndLoad(ArchivePath, Context, &Error); TheArchive = Archive::OpenAndLoad(ArchivePath, Context, &Error);
if (TheArchive == 0) { if (TheArchive == 0) {
std::cerr << argv[0] << ": error loading '" << ArchivePath << "': " errs() << argv[0] << ": error loading '" << ArchivePath << "': "
<< Error << "!\n"; << Error << "!\n";
return 1; return 1;
} }
} }
@ -749,27 +750,27 @@ int main(int argc, char **argv) {
case DisplayTable: haveError = doDisplayTable(&ErrMsg); break; case DisplayTable: haveError = doDisplayTable(&ErrMsg); break;
case Extract: haveError = doExtract(&ErrMsg); break; case Extract: haveError = doExtract(&ErrMsg); break;
case NoOperation: case NoOperation:
std::cerr << argv[0] << ": No operation was selected.\n"; errs() << argv[0] << ": No operation was selected.\n";
break; break;
} }
if (haveError) { if (haveError) {
std::cerr << argv[0] << ": " << ErrMsg << "\n"; errs() << argv[0] << ": " << ErrMsg << "\n";
return 1; return 1;
} }
} catch (const char*msg) { } catch (const char*msg) {
// These errors are usage errors, thrown only by the various checks in the // These errors are usage errors, thrown only by the various checks in the
// code above. // code above.
std::cerr << argv[0] << ": " << msg << "\n\n"; errs() << argv[0] << ": " << msg << "\n\n";
cl::PrintHelpMessage(); cl::PrintHelpMessage();
exitCode = 1; exitCode = 1;
} catch (const std::string& msg) { } catch (const std::string& msg) {
// These errors are thrown by LLVM libraries (e.g. lib System) and represent // These errors are thrown by LLVM libraries (e.g. lib System) and represent
// a more serious error so we bump the exitCode and don't print the usage. // a more serious error so we bump the exitCode and don't print the usage.
std::cerr << argv[0] << ": " << msg << "\n"; errs() << argv[0] << ": " << msg << "\n";
exitCode = 2; exitCode = 2;
} catch (...) { } catch (...) {
// This really shouldn't happen, but just in case .... // This really shouldn't happen, but just in case ....
std::cerr << argv[0] << ": An unexpected unknown exception occurred.\n"; errs() << argv[0] << ": An unexpected unknown exception occurred.\n";
exitCode = 3; exitCode = 3;
} }

View File

@ -289,7 +289,7 @@ static std::map<unsigned, PerBlockIDStats> BlockIDStats;
/// Error - All bitcode analysis errors go through this function, making this a /// Error - All bitcode analysis errors go through this function, making this a
/// good place to breakpoint if debugging. /// good place to breakpoint if debugging.
static bool Error(const std::string &Err) { static bool Error(const std::string &Err) {
std::cerr << Err << "\n"; errs() << Err << "\n";
return true; return true;
} }
@ -306,7 +306,7 @@ static bool ParseBlock(BitstreamCursor &Stream, unsigned IndentLevel) {
// BLOCKINFO is a special part of the stream. // BLOCKINFO is a special part of the stream.
if (BlockID == bitc::BLOCKINFO_BLOCK_ID) { if (BlockID == bitc::BLOCKINFO_BLOCK_ID) {
if (Dump) std::cerr << Indent << "<BLOCKINFO_BLOCK/>\n"; if (Dump) errs() << Indent << "<BLOCKINFO_BLOCK/>\n";
if (Stream.ReadBlockInfoBlock()) if (Stream.ReadBlockInfoBlock())
return Error("Malformed BlockInfoBlock"); return Error("Malformed BlockInfoBlock");
uint64_t BlockBitEnd = Stream.GetCurrentBitNo(); uint64_t BlockBitEnd = Stream.GetCurrentBitNo();
@ -320,17 +320,17 @@ static bool ParseBlock(BitstreamCursor &Stream, unsigned IndentLevel) {
const char *BlockName = 0; const char *BlockName = 0;
if (Dump) { if (Dump) {
std::cerr << Indent << "<"; errs() << Indent << "<";
if ((BlockName = GetBlockName(BlockID, *Stream.getBitStreamReader()))) if ((BlockName = GetBlockName(BlockID, *Stream.getBitStreamReader())))
std::cerr << BlockName; errs() << BlockName;
else else
std::cerr << "UnknownBlock" << BlockID; errs() << "UnknownBlock" << BlockID;
if (NonSymbolic && BlockName) if (NonSymbolic && BlockName)
std::cerr << " BlockID=" << BlockID; errs() << " BlockID=" << BlockID;
std::cerr << " NumWords=" << NumWords errs() << " NumWords=" << NumWords
<< " BlockCodeSize=" << Stream.GetAbbrevIDWidth() << ">\n"; << " BlockCodeSize=" << Stream.GetAbbrevIDWidth() << ">\n";
} }
SmallVector<uint64_t, 64> Record; SmallVector<uint64_t, 64> Record;
@ -351,11 +351,11 @@ static bool ParseBlock(BitstreamCursor &Stream, unsigned IndentLevel) {
uint64_t BlockBitEnd = Stream.GetCurrentBitNo(); uint64_t BlockBitEnd = Stream.GetCurrentBitNo();
BlockStats.NumBits += BlockBitEnd-BlockBitStart; BlockStats.NumBits += BlockBitEnd-BlockBitStart;
if (Dump) { if (Dump) {
std::cerr << Indent << "</"; errs() << Indent << "</";
if (BlockName) if (BlockName)
std::cerr << BlockName << ">\n"; errs() << BlockName << ">\n";
else else
std::cerr << "UnknownBlock" << BlockID << ">\n"; errs() << "UnknownBlock" << BlockID << ">\n";
} }
return false; return false;
} }
@ -397,25 +397,25 @@ static bool ParseBlock(BitstreamCursor &Stream, unsigned IndentLevel) {
BlockStats.CodeFreq[Code].NumAbbrev++; BlockStats.CodeFreq[Code].NumAbbrev++;
if (Dump) { if (Dump) {
std::cerr << Indent << " <"; errs() << Indent << " <";
if (const char *CodeName = if (const char *CodeName =
GetCodeName(Code, BlockID, *Stream.getBitStreamReader())) GetCodeName(Code, BlockID, *Stream.getBitStreamReader()))
std::cerr << CodeName; errs() << CodeName;
else else
std::cerr << "UnknownCode" << Code; errs() << "UnknownCode" << Code;
if (NonSymbolic && if (NonSymbolic &&
GetCodeName(Code, BlockID, *Stream.getBitStreamReader())) GetCodeName(Code, BlockID, *Stream.getBitStreamReader()))
std::cerr << " codeid=" << Code; errs() << " codeid=" << Code;
if (AbbrevID != bitc::UNABBREV_RECORD) if (AbbrevID != bitc::UNABBREV_RECORD)
std::cerr << " abbrevid=" << AbbrevID; errs() << " abbrevid=" << AbbrevID;
for (unsigned i = 0, e = Record.size(); i != e; ++i) for (unsigned i = 0, e = Record.size(); i != e; ++i)
std::cerr << " op" << i << "=" << (int64_t)Record[i]; errs() << " op" << i << "=" << (int64_t)Record[i];
std::cerr << "/>"; errs() << "/>";
if (BlobStart) { if (BlobStart) {
std::cerr << " blob data = "; errs() << " blob data = ";
bool BlobIsPrintable = true; bool BlobIsPrintable = true;
for (unsigned i = 0; i != BlobLen; ++i) for (unsigned i = 0; i != BlobLen; ++i)
if (!isprint(BlobStart[i])) { if (!isprint(BlobStart[i])) {
@ -424,12 +424,12 @@ static bool ParseBlock(BitstreamCursor &Stream, unsigned IndentLevel) {
} }
if (BlobIsPrintable) if (BlobIsPrintable)
std::cerr << "'" << std::string(BlobStart, BlobStart+BlobLen) <<"'"; errs() << "'" << std::string(BlobStart, BlobStart+BlobLen) <<"'";
else else
std::cerr << "unprintable, " << BlobLen << " bytes."; errs() << "unprintable, " << BlobLen << " bytes.";
} }
std::cerr << "\n"; errs() << "\n";
} }
break; break;
@ -499,58 +499,58 @@ static int AnalyzeBitcode() {
++NumTopBlocks; ++NumTopBlocks;
} }
if (Dump) std::cerr << "\n\n"; if (Dump) errs() << "\n\n";
uint64_t BufferSizeBits = (EndBufPtr-BufPtr)*CHAR_BIT; uint64_t BufferSizeBits = (EndBufPtr-BufPtr)*CHAR_BIT;
// Print a summary of the read file. // Print a summary of the read file.
std::cerr << "Summary of " << InputFilename << ":\n"; errs() << "Summary of " << InputFilename << ":\n";
std::cerr << " Total size: "; errs() << " Total size: ";
PrintSize(BufferSizeBits); PrintSize(BufferSizeBits);
std::cerr << "\n"; errs() << "\n";
std::cerr << " Stream type: "; errs() << " Stream type: ";
switch (CurStreamType) { switch (CurStreamType) {
default: assert(0 && "Unknown bitstream type"); default: assert(0 && "Unknown bitstream type");
case UnknownBitstream: std::cerr << "unknown\n"; break; case UnknownBitstream: errs() << "unknown\n"; break;
case LLVMIRBitstream: std::cerr << "LLVM IR\n"; break; case LLVMIRBitstream: errs() << "LLVM IR\n"; break;
} }
std::cerr << " # Toplevel Blocks: " << NumTopBlocks << "\n"; errs() << " # Toplevel Blocks: " << NumTopBlocks << "\n";
std::cerr << "\n"; errs() << "\n";
// Emit per-block stats. // Emit per-block stats.
std::cerr << "Per-block Summary:\n"; errs() << "Per-block Summary:\n";
for (std::map<unsigned, PerBlockIDStats>::iterator I = BlockIDStats.begin(), for (std::map<unsigned, PerBlockIDStats>::iterator I = BlockIDStats.begin(),
E = BlockIDStats.end(); I != E; ++I) { E = BlockIDStats.end(); I != E; ++I) {
std::cerr << " Block ID #" << I->first; errs() << " Block ID #" << I->first;
if (const char *BlockName = GetBlockName(I->first, StreamFile)) if (const char *BlockName = GetBlockName(I->first, StreamFile))
std::cerr << " (" << BlockName << ")"; errs() << " (" << BlockName << ")";
std::cerr << ":\n"; errs() << ":\n";
const PerBlockIDStats &Stats = I->second; const PerBlockIDStats &Stats = I->second;
std::cerr << " Num Instances: " << Stats.NumInstances << "\n"; errs() << " Num Instances: " << Stats.NumInstances << "\n";
std::cerr << " Total Size: "; errs() << " Total Size: ";
PrintSize(Stats.NumBits); PrintSize(Stats.NumBits);
std::cerr << "\n"; errs() << "\n";
std::cerr << " % of file: " errs() << " % of file: "
<< Stats.NumBits/(double)BufferSizeBits*100 << "\n"; << Stats.NumBits/(double)BufferSizeBits*100 << "\n";
if (Stats.NumInstances > 1) { if (Stats.NumInstances > 1) {
std::cerr << " Average Size: "; errs() << " Average Size: ";
PrintSize(Stats.NumBits/(double)Stats.NumInstances); PrintSize(Stats.NumBits/(double)Stats.NumInstances);
std::cerr << "\n"; errs() << "\n";
std::cerr << " Tot/Avg SubBlocks: " << Stats.NumSubBlocks << "/" errs() << " Tot/Avg SubBlocks: " << Stats.NumSubBlocks << "/"
<< Stats.NumSubBlocks/(double)Stats.NumInstances << "\n"; << Stats.NumSubBlocks/(double)Stats.NumInstances << "\n";
std::cerr << " Tot/Avg Abbrevs: " << Stats.NumAbbrevs << "/" errs() << " Tot/Avg Abbrevs: " << Stats.NumAbbrevs << "/"
<< Stats.NumAbbrevs/(double)Stats.NumInstances << "\n"; << Stats.NumAbbrevs/(double)Stats.NumInstances << "\n";
std::cerr << " Tot/Avg Records: " << Stats.NumRecords << "/" errs() << " Tot/Avg Records: " << Stats.NumRecords << "/"
<< Stats.NumRecords/(double)Stats.NumInstances << "\n"; << Stats.NumRecords/(double)Stats.NumInstances << "\n";
} else { } else {
std::cerr << " Num SubBlocks: " << Stats.NumSubBlocks << "\n"; errs() << " Num SubBlocks: " << Stats.NumSubBlocks << "\n";
std::cerr << " Num Abbrevs: " << Stats.NumAbbrevs << "\n"; errs() << " Num Abbrevs: " << Stats.NumAbbrevs << "\n";
std::cerr << " Num Records: " << Stats.NumRecords << "\n"; errs() << " Num Records: " << Stats.NumRecords << "\n";
} }
if (Stats.NumRecords) if (Stats.NumRecords)
std::cerr << " % Abbrev Recs: " << (Stats.NumAbbreviatedRecords/ errs() << " % Abbrev Recs: " << (Stats.NumAbbreviatedRecords/
(double)Stats.NumRecords)*100 << "\n"; (double)Stats.NumRecords)*100 << "\n";
std::cerr << "\n"; errs() << "\n";
// Print a histogram of the codes we see. // Print a histogram of the codes we see.
if (!NoHistogram && !Stats.CodeFreq.empty()) { if (!NoHistogram && !Stats.CodeFreq.empty()) {
@ -561,7 +561,7 @@ static int AnalyzeBitcode() {
std::stable_sort(FreqPairs.begin(), FreqPairs.end()); std::stable_sort(FreqPairs.begin(), FreqPairs.end());
std::reverse(FreqPairs.begin(), FreqPairs.end()); std::reverse(FreqPairs.begin(), FreqPairs.end());
std::cerr << "\tRecord Histogram:\n"; errs() << "\tRecord Histogram:\n";
fprintf(stderr, "\t\t Count # Bits %% Abv Record Kind\n"); fprintf(stderr, "\t\t Count # Bits %% Abv Record Kind\n");
for (unsigned i = 0, e = FreqPairs.size(); i != e; ++i) { for (unsigned i = 0, e = FreqPairs.size(); i != e; ++i) {
const PerRecordStats &RecStats = Stats.CodeFreq[FreqPairs[i].second]; const PerRecordStats &RecStats = Stats.CodeFreq[FreqPairs[i].second];
@ -581,7 +581,7 @@ static int AnalyzeBitcode() {
else else
fprintf(stderr, "UnknownCode%d\n", FreqPairs[i].second); fprintf(stderr, "UnknownCode%d\n", FreqPairs[i].second);
} }
std::cerr << "\n"; errs() << "\n";
} }
} }

View File

@ -500,7 +500,7 @@ void CLIDebugger::breakCommand(std::string &Options) {
if (File == 0) if (File == 0)
throw "Unknown file to place breakpoint!"; throw "Unknown file to place breakpoint!";
std::cerr << "Break: " << File->getFilename() << ":" << LineNo << "\n"; errs() << "Break: " << File->getFilename() << ":" << LineNo << "\n";
throw "breakpoints not implemented yet!"; throw "breakpoints not implemented yet!";
} }

View File

@ -94,9 +94,9 @@ int main(int argc, char **argv, char * const *envp) {
// Now that we have initialized the debugger, run it. // Now that we have initialized the debugger, run it.
return D.run(); return D.run();
} catch (const std::string& msg) { } catch (const std::string& msg) {
std::cerr << argv[0] << ": " << msg << "\n"; errs() << argv[0] << ": " << msg << "\n";
} catch (...) { } catch (...) {
std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n"; errs() << argv[0] << ": Unexpected unknown exception occurred.\n";
} }
return 1; return 1;
} }

View File

@ -18,6 +18,7 @@
#include "llvm/Analysis/Verifier.h" #include "llvm/Analysis/Verifier.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/StandardPasses.h" #include "llvm/Support/StandardPasses.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/DynamicLibrary.h" #include "llvm/System/DynamicLibrary.h"
#include "llvm/Target/TargetData.h" #include "llvm/Target/TargetData.h"
#include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetMachine.h"
@ -109,8 +110,8 @@ void Optimize(Module* M) {
if (Opt->getNormalCtor()) if (Opt->getNormalCtor())
addPass(Passes, Opt->getNormalCtor()()); addPass(Passes, Opt->getNormalCtor()());
else else
std::cerr << "llvm-ld: cannot create pass: " << Opt->getPassName() errs() << "llvm-ld: cannot create pass: " << Opt->getPassName()
<< "\n"; << "\n";
} }
// The user's passes may leave cruft around. Clean up after them them but // The user's passes may leave cruft around. Clean up after them them but

View File

@ -24,6 +24,7 @@
#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Signals.h" #include "llvm/System/Signals.h"
#include <algorithm> #include <algorithm>
#include <cctype> #include <cctype>
@ -147,7 +148,7 @@ static void DumpSymbolNamesFromFile(std::string &Filename) {
if (Result) if (Result)
DumpSymbolNamesFromModule(Result); DumpSymbolNamesFromModule(Result);
else { else {
std::cerr << ToolName << ": " << Filename << ": " << ErrorMessage << "\n"; errs() << ToolName << ": " << Filename << ": " << ErrorMessage << "\n";
return; return;
} }
@ -156,17 +157,17 @@ static void DumpSymbolNamesFromFile(std::string &Filename) {
Archive* archive = Archive::OpenAndLoad(sys::Path(Filename), Context, Archive* archive = Archive::OpenAndLoad(sys::Path(Filename), Context,
&ErrorMessage); &ErrorMessage);
if (!archive) if (!archive)
std::cerr << ToolName << ": " << Filename << ": " << ErrorMessage << "\n"; errs() << ToolName << ": " << Filename << ": " << ErrorMessage << "\n";
std::vector<Module *> Modules; std::vector<Module *> Modules;
if (archive->getAllModules(Modules, &ErrorMessage)) { if (archive->getAllModules(Modules, &ErrorMessage)) {
std::cerr << ToolName << ": " << Filename << ": " << ErrorMessage << "\n"; errs() << ToolName << ": " << Filename << ": " << ErrorMessage << "\n";
return; return;
} }
MultipleFiles = true; MultipleFiles = true;
std::for_each (Modules.begin(), Modules.end(), DumpSymbolNamesFromModule); std::for_each (Modules.begin(), Modules.end(), DumpSymbolNamesFromModule);
} else { } else {
std::cerr << ToolName << ": " << Filename << ": " errs() << ToolName << ": " << Filename << ": "
<< "unrecognizable file type\n"; << "unrecognizable file type\n";
return; return;
} }
} }

View File

@ -270,7 +270,7 @@ int main(int argc, char **argv) {
delete Buffer; delete Buffer;
} }
if (M == 0) { if (M == 0) {
std::cerr << argv[0] << ": " << BitcodeFile << ": " errs() << argv[0] << ": " << BitcodeFile << ": "
<< ErrorMessage << "\n"; << ErrorMessage << "\n";
return 1; return 1;
} }
@ -289,9 +289,9 @@ int main(int argc, char **argv) {
return 0; return 0;
} catch (const std::string& msg) { } catch (const std::string& msg) {
std::cerr << argv[0] << ": " << msg << "\n"; errs() << argv[0] << ": " << msg << "\n";
} catch (...) { } catch (...) {
std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n"; errs() << argv[0] << ": Unexpected unknown exception occurred.\n";
} }
return 1; return 1;

View File

@ -17,6 +17,7 @@
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/Signals.h" #include "llvm/System/Signals.h"
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
@ -87,13 +88,13 @@ int main(int argc, char **argv) {
printSymbolTable(TheArchive); printSymbolTable(TheArchive);
} catch (const char* msg) { } catch (const char* msg) {
std::cerr << argv[0] << ": " << msg << "\n\n"; errs() << argv[0] << ": " << msg << "\n\n";
exitCode = 1; exitCode = 1;
} catch (const std::string& msg) { } catch (const std::string& msg) {
std::cerr << argv[0] << ": " << msg << "\n"; errs() << argv[0] << ": " << msg << "\n";
exitCode = 2; exitCode = 2;
} catch (...) { } catch (...) {
std::cerr << argv[0] << ": An unexpected unknown exception occurred.\n"; errs() << argv[0] << ": An unexpected unknown exception occurred.\n";
exitCode = 3; exitCode = 3;
} }
return exitCode; return exitCode;

View File

@ -21,6 +21,7 @@
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "llvm/Support/CallSite.h" #include "llvm/Support/CallSite.h"
#include "llvm/Analysis/CallGraph.h" #include "llvm/Analysis/CallGraph.h"
#include "llvm/Support/raw_ostream.h"
#include <iostream> #include <iostream>
using namespace llvm; using namespace llvm;
@ -45,10 +46,10 @@ namespace {
E = CS.arg_end(); AI != E; ++AI) E = CS.arg_end(); AI != E; ++AI)
if (isa<Constant>(*AI)) { if (isa<Constant>(*AI)) {
if (!PrintedFn) { if (!PrintedFn) {
std::cerr << "Function '" << I->getName() << "':\n"; errs() << "Function '" << I->getName() << "':\n";
PrintedFn = true; PrintedFn = true;
} }
std::cerr << *User; errs() << *User;
break; break;
} }
} }