llvm.org GIT mirror llvm / 68fe61d
Replacing std::iostreams with llvm iostreams. Some of these changes involve adding a temporary wrapper around the ostream to make it friendly to functions expecting an LLVM stream. This should be fixed in the future. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@31990 91177308-0d34-0410-b5e6-96231b3b80d8 Bill Wendling 12 years ago
25 changed file(s) with 220 addition(s) and 182 deletion(s). Raw diff Collapse all Expand all
1717 #include "llvm/Constants.h"
1818 #include "llvm/Instructions.h"
1919 #include "llvm/Bytecode/Writer.h"
20 #include
21
20 #include "llvm/Support/Streams.h"
2221 using namespace llvm;
2322
2423 int main() {
5352 BB->getInstList().push_back(new ReturnInst(Add));
5453
5554 // Output the bytecode file to stdout
56 WriteBytecodeToFile(M, std::cout);
55 WriteBytecodeToFile(M, llvm_cout);
5756
5857 // Delete the module and all of its contents.
5958 delete M;
151151 ///
152152 void initialize(Module &M);
153153
154 void print(llvm_ostream &o, const Module *M) const {
155 if (o.stream()) print(*o.stream(), M);
156 }
154157 virtual void print(std::ostream &o, const Module *M) const;
155158 void dump() const;
156159
197200 /// dump - Print out this call graph node.
198201 ///
199202 void dump() const;
203 void print(llvm_ostream &OS) const {
204 if (OS.stream()) print(*OS.stream());
205 }
200206 void print(std::ostream &OS) const;
201207
202208 //===---------------------------------------------------------------------
1616
1717 #include "llvm/Pass.h"
1818 #include "llvm/Bytecode/Writer.h"
19 #include
2019
2120 namespace llvm {
2221
22 class llvm_ostream;
23
2324 class WriteBytecodePass : public ModulePass {
24 std::ostream *Out; // ostream to print on
25 llvm_ostream *Out; // ostream to print on
2526 bool DeleteStream;
2627 bool CompressFile;
2728 public:
2829 WriteBytecodePass()
29 : Out(&std::cout), DeleteStream(false), CompressFile(true) {}
30 WriteBytecodePass(std::ostream *o, bool DS = false, bool CF = true)
30 : Out(&llvm_cout), DeleteStream(false), CompressFile(true) {}
31 WriteBytecodePass(llvm_ostream *o, bool DS = false, bool CF = true)
3132 : Out(o), DeleteStream(DS), CompressFile(CF) {}
3233
3334 inline ~WriteBytecodePass() {
1414 #ifndef LLVM_BYTECODE_WRITER_H
1515 #define LLVM_BYTECODE_WRITER_H
1616
17 #include
18
1917 namespace llvm {
18 class llvm_ostream;
2019 class Module;
2120 /// WriteBytecodeToFile - Write the specified module to the specified output
2221 /// stream. If compress is set to true, try to use compression when writing
2322 /// out the file. This can never fail if M is a well-formed module.
24 void WriteBytecodeToFile(const Module *M, std::ostream &Out,
23 void WriteBytecodeToFile(const Module *M, llvm_ostream &Out,
2524 bool compress = true);
2625 } // End llvm namespace
2726
6969 ///
7070 FunctionPass *createLinearScanRegisterAllocator();
7171
72 /// PriorityBasedGraphColoringRegisterAllocator Pass - This pass implements
73 /// the priority-based graph coloring register allocator by Chow & Hennessey,
74 /// a global register allocator.
75 FunctionPass *createGraphColoringRegisterAllocator();
76
7277 /// PrologEpilogCodeInserter Pass - This pass inserts prolog and epilog code,
7378 /// and eliminates abstract frame references.
7479 ///
4242 }
4343
4444 bool operator == (const std::ostream &OS) { return &OS == Stream; }
45 bool operator == (const llvm_ostream &OS) { return OS.Stream == Stream; }
4546 };
4647
4748 extern llvm_ostream llvm_null;
2323 #include "llvm/Support/CommandLine.h"
2424 #include "llvm/Support/Debug.h"
2525 #include "llvm/Support/Timer.h"
26 #include
2726
2827 // FIXME: This should eventually be a FunctionPass that is automatically
2928 // aggregated into a Pass.
434433 // Variable index into a node. We must merge all of the elements of the
435434 // sequential type here.
436435 if (isa(STy))
437 std::cerr << "Pointer indexing not handled yet!\n";
436 llvm_cerr << "Pointer indexing not handled yet!\n";
438437 else {
439438 const ArrayType *ATy = cast(STy);
440439 unsigned ElSize = TD.getTypeSize(CurTy);
10611060 if (DisableDirectCallOpt || !isa(Callee)) {
10621061 CalleeNode = getValueDest(*Callee).getNode();
10631062 if (CalleeNode == 0) {
1064 std::cerr << "WARNING: Program is calling through a null pointer?\n"<< *I;
1063 llvm_cerr << "WARNING: Program is calling through a null pointer?\n"<< *I;
10651064 return; // Calling a null pointer?
10661065 }
10671066 }
1818 #include "llvm/Assembly/Writer.h"
1919 #include "llvm/Support/CommandLine.h"
2020 #include "llvm/Support/GraphWriter.h"
21 #include "llvm/Support/Streams.h"
2122 #include "llvm/ADT/Statistic.h"
2223 #include "llvm/Config/config.h"
23 #include <iostream>
24 #include <ostream>
2425 #include
2526 #include
2627 using namespace llvm;
3536 Statistic<> NumFoldedNodes ("dsa", "Number of folded nodes (in final graph)");
3637 }
3738
38 void DSNode::dump() const { print(std::cerr, 0); }
39 void DSNode::dump() const { print(llvm_cerr, 0); }
3940
4041 static std::string getCaption(const DSNode *N, const DSGraph *G) {
4142 std::stringstream OS;
1919 #include "llvm/Analysis/Passes.h"
2020 #include "llvm/Module.h"
2121 #include "llvm/Support/Debug.h"
22 #include <iostream>
22 #include <ostream>
2323 using namespace llvm;
2424
2525 namespace {
5252 }
5353
5454 // print - Implement the Pass::print method...
55 void print(llvm_ostream O, const Module *M) const {
56 if (O.stream()) print(*O.stream(), M);
57 }
5558 void print(std::ostream &O, const Module *M) const {
5659 assert(ResultGraph && "Result graph has not yet been computed!");
5760 ResultGraph->writeGraphToFile(O, "steensgaards");
187190 // FIXME: We should be able to disable the globals graph for steens!
188191 //ResultGraph->removeDeadNodes(DSGraph::KeepUnreachableGlobals);
189192
190 DEBUG(print(std::cerr, &M));
193 print(DOUT, &M);
191194 return false;
192195 }
193196
6161 #include "llvm/Support/Debug.h"
6262 #include "llvm/ADT/Statistic.h"
6363 #include
64 #include
6564 using namespace llvm;
6665
6766 namespace {
533532 case Instruction::BitCast:
534533 return getNodeForConstantPointer(CE->getOperand(0));
535534 default:
536 std::cerr << "Constant Expr not yet handled: " << *CE << "\n";
535 llvm_cerr << "Constant Expr not yet handled: " << *CE << "\n";
537536 assert(0);
538537 }
539538 } else {
560559 case Instruction::BitCast:
561560 return getNodeForConstantPointerTarget(CE->getOperand(0));
562561 default:
563 std::cerr << "Constant Expr not yet handled: " << *CE << "\n";
562 llvm_cerr << "Constant Expr not yet handled: " << *CE << "\n";
564563 assert(0);
565564 }
566565 } else {
786785 return;
787786 default:
788787 // Is this something we aren't handling yet?
789 std::cerr << "Unknown instruction: " << I;
788 llvm_cerr << "Unknown instruction: " << I;
790789 abort();
791790 }
792791 }
11041103
11051104 void Andersens::PrintNode(Node *N) {
11061105 if (N == &GraphNodes[UniversalSet]) {
1107 std::cerr << "";
1106 llvm_cerr << "";
11081107 return;
11091108 } else if (N == &GraphNodes[NullPtr]) {
1110 std::cerr << "";
1109 llvm_cerr << "";
11111110 return;
11121111 } else if (N == &GraphNodes[NullObject]) {
1113 std::cerr << "";
1112 llvm_cerr << "";
11141113 return;
11151114 }
11161115
11191118 if (Function *F = dyn_cast(V)) {
11201119 if (isa(F->getFunctionType()->getReturnType()) &&
11211120 N == getReturnNode(F)) {
1122 std::cerr << F->getName() << ":retval";
1121 llvm_cerr << F->getName() << ":retval";
11231122 return;
11241123 } else if (F->getFunctionType()->isVarArg() && N == getVarargNode(F)) {
1125 std::cerr << F->getName() << ":vararg";
1124 llvm_cerr << F->getName() << ":vararg";
11261125 return;
11271126 }
11281127 }
11291128
11301129 if (Instruction *I = dyn_cast(V))
1131 std::cerr << I->getParent()->getParent()->getName() << ":";
1130 llvm_cerr << I->getParent()->getParent()->getName() << ":";
11321131 else if (Argument *Arg = dyn_cast(V))
1133 std::cerr << Arg->getParent()->getName() << ":";
1132 llvm_cerr << Arg->getParent()->getName() << ":";
11341133
11351134 if (V->hasName())
1136 std::cerr << V->getName();
1135 llvm_cerr << V->getName();
11371136 else
1138 std::cerr << "(unnamed)";
1137 llvm_cerr << "(unnamed)";
11391138
11401139 if (isa(V) || isa(V))
11411140 if (N == getObject(V))
1142 std::cerr << "";
1141 llvm_cerr << "";
11431142 }
11441143
11451144 void Andersens::PrintConstraints() {
1146 std::cerr << "Constraints:\n";
1145 llvm_cerr << "Constraints:\n";
11471146 for (unsigned i = 0, e = Constraints.size(); i != e; ++i) {
1148 std::cerr << " #" << i << ": ";
1147 llvm_cerr << " #" << i << ": ";
11491148 Constraint &C = Constraints[i];
11501149 if (C.Type == Constraint::Store)
1151 std::cerr << "*";
1150 llvm_cerr << "*";
11521151 PrintNode(C.Dest);
1153 std::cerr << " = ";
1152 llvm_cerr << " = ";
11541153 if (C.Type == Constraint::Load)
1155 std::cerr << "*";
1154 llvm_cerr << "*";
11561155 PrintNode(C.Src);
1157 std::cerr << "\n";
1156 llvm_cerr << "\n";
11581157 }
11591158 }
11601159
11611160 void Andersens::PrintPointsToGraph() {
1162 std::cerr << "Points-to graph:\n";
1161 llvm_cerr << "Points-to graph:\n";
11631162 for (unsigned i = 0, e = GraphNodes.size(); i != e; ++i) {
11641163 Node *N = &GraphNodes[i];
1165 std::cerr << "[" << (N->end() - N->begin()) << "] ";
1164 llvm_cerr << "[" << (N->end() - N->begin()) << "] ";
11661165 PrintNode(N);
1167 std::cerr << "\t--> ";
1166 llvm_cerr << "\t--> ";
11681167 for (Node::iterator I = N->begin(), E = N->end(); I != E; ++I) {
1169 if (I != N->begin()) std::cerr << ", ";
1168 if (I != N->begin()) llvm_cerr << ", ";
11701169 PrintNode(*I);
11711170 }
1172 std::cerr << "\n";
1173 }
1174 }
1171 llvm_cerr << "\n";
1172 }
1173 }
1515 #include "llvm/Module.h"
1616 #include "llvm/Instructions.h"
1717 #include "llvm/Support/CallSite.h"
18 #include
18 #include "llvm/Support/Streams.h"
19 #include
1920 using namespace llvm;
2021
2122 static bool isOnlyADirectCall(Function *F, CallSite CS) {
7172 AU.setPreservesAll();
7273 }
7374
75 void print(llvm_ostream &o, const Module *M) const {
76 if (o.stream()) print(*o.stream(), M);
77 }
78
7479 virtual void print(std::ostream &o, const Module *M) const {
7580 o << "CallGraph Root is: ";
7681 if (Function *F = getRoot()->getFunction())
8893 /// dump - Print out this call graph.
8994 ///
9095 inline void dump() const {
91 print(std::cerr, Mod);
96 print(llvm_cerr, Mod);
9297 }
9398
9499 CallGraphNode* getExternalCallingNode() const { return ExternalCallingNode; }
206211 }
207212
208213 void CallGraph::dump() const {
209 print(std::cerr, 0);
214 print(llvm_cerr, 0);
210215 }
211216
212217 //===----------------------------------------------------------------------===//
269274 OS << "\n";
270275 }
271276
272 void CallGraphNode::dump() const { print(std::cerr); }
277 void CallGraphNode::dump() const { print(llvm_cerr); }
273278
274279 void CallGraphNode::removeCallEdgeTo(CallGraphNode *Callee) {
275280 for (unsigned i = CalledFunctions.size(); ; --i) {
173173 SCEVHandle IH = SCEVUnknown::get(I); // Get I as a "symbolic" SCEV.
174174
175175 SCEVHandle V = S->evaluateAtIteration(IH);
176 //std::cerr << "Evaluated: " << *this << "\n to: " << *V << "\n";
176 //llvm_cerr << "Evaluated: " << *this << "\n to: " << *V << "\n";
177177
178178 return expandInTy(V, Ty);
179179 }
3030 using namespace llvm;
3131
3232 #if 0
33 #include
34 #define SC_DEBUG(X) std::cerr << X
33 #include "llvm/Support/Streams.h"
34 #define SC_DEBUG(X) llvm_cerr << X
3535 #else
3636 #define SC_DEBUG(X)
3737 #endif
799799
800800 // Used for debugging DefSlot=-1 assertion...
801801 //if (Typ == Type::TypeTy)
802 // cerr << "Inserting type '" << cast(D)->getDescription() << "'!\n";
802 // llvm_cerr << "Inserting type '"<(D)->getDescription() <<"'!\n";
803803
804804 if (Typ->isDerivedType()) {
805805 int ValSlot;
2828 #include "llvm/Support/GetElementPtrTypeIterator.h"
2929 #include "llvm/Support/Compressor.h"
3030 #include "llvm/Support/MathExtras.h"
31 #include "llvm/Support/Streams.h"
3132 #include "llvm/System/Program.h"
3233 #include "llvm/ADT/STLExtras.h"
3334 #include "llvm/ADT/Statistic.h"
274275 break;
275276
276277 default:
277 std::cerr << __FILE__ << ":" << __LINE__ << ": Don't know how to serialize"
278 llvm_cerr << __FILE__ << ":" << __LINE__ << ": Don't know how to serialize"
278279 << " Type '" << T->getDescription() << "'\n";
279280 break;
280281 }
383384 case Type::VoidTyID:
384385 case Type::LabelTyID:
385386 default:
386 std::cerr << __FILE__ << ":" << __LINE__ << ": Don't know how to serialize"
387 llvm_cerr << __FILE__ << ":" << __LINE__ << ": Don't know how to serialize"
387388 << " type '" << *CPV->getType() << "'\n";
388389 break;
389390 }
12241225 }
12251226 }
12261227
1227 void llvm::WriteBytecodeToFile(const Module *M, std::ostream &Out,
1228 void llvm::WriteBytecodeToFile(const Module *M, llvm_ostream &Out,
12281229 bool compress) {
12291230 assert(M && "You can't write a null module!!");
12301231
12311232 // Make sure that std::cout is put into binary mode for systems
12321233 // that care.
1233 if (&Out == std::cout)
1234 if (Out == llvm_cout)
12341235 sys::Program::ChangeStdoutToBinary();
12351236
12361237 // Create a vector of unsigned char for the bytecode output. We
12631264 compressed_magic[2] = 'v';
12641265 compressed_magic[3] = 'c';
12651266
1266 Out.write(compressed_magic,4);
1267 Out.stream()->write(compressed_magic,4);
12671268
12681269 // Compress everything after the magic number (which we altered)
12691270 Compressor::compressToStream(
12701271 (char*)(FirstByte+4), // Skip the magic number
12711272 Buffer.size()-4, // Skip the magic number
1272 Out // Where to write compressed data
1273 *Out.stream() // Where to write compressed data
12731274 );
12741275
12751276 } else {
12761277
12771278 // We're not compressing, so just write the entire block.
1278 Out.write((char*)FirstByte, Buffer.size());
1279 Out.stream()->write((char*)FirstByte, Buffer.size());
12791280 }
12801281
12811282 // make sure it hits disk now
1282 Out.flush();
1283 }
1283 Out.stream()->flush();
1284 }
2121 #include "llvm/Bytecode/Writer.h"
2222 #include "llvm/Analysis/Verifier.h"
2323 #include "llvm/Support/CommandLine.h"
24 #include "llvm/Support/Streams.h"
2425 #include "llvm/System/Signals.h"
2526 #include
2627 #include
2728 #include
28
2929 using namespace llvm;
3030
3131 static cl::opt
114114 }
115115
116116 if (DumpAsm)
117 std::cerr << "Here's the assembly:" << M.get();
117 llvm_cerr << "Here's the assembly:" << M.get();
118118
119119 if (OutputFilename != "") { // Specified an output filename?
120120 if (OutputFilename != "-") { // Not stdout?
162162 throw std::string("error opening ") + OutputFilename + "!";
163163 }
164164
165 WriteBytecodeToFile(M.get(), *Out);
165 llvm_ostream L(*Out);
166 WriteBytecodeToFile(M.get(), L);
166167 } catch (const ParseError &E) {
167 std::cerr << argv[0] << ": " << E.getMessage() << "\n";
168 llvm_cerr << argv[0] << ": " << E.getMessage() << "\n";
168169 return 1;
169170 }
170171 }
171172 catch (const std::string& msg ) {
172 std::cerr << argv[0] << ": " << msg << "\n";
173 llvm_cerr << argv[0] << ": " << msg << "\n";
173174 return 1;
174175 }
175176
2626 #include "llvm/Target/TargetData.h"
2727 #include "llvm/Support/FileUtilities.h"
2828 #include "llvm/Support/CommandLine.h"
29 #include "llvm/Support/Streams.h"
2930 #include "llvm/System/Path.h"
3031 #include "llvm/System/Program.h"
3132 #include "llvm/Config/alloca.h"
5455 std::ofstream Out(Filename.c_str(), io_mode);
5556 if (!Out.good()) return true;
5657 try {
57 WriteBytecodeToFile(M ? M : Program, Out, /*compression=*/true);
58 llvm_ostream L(Out);
59 WriteBytecodeToFile(M ? M : Program, L, /*compression=*/true);
5860 } catch (...) {
5961 return true;
6062 }
7173 //
7274 std::string Filename = "bugpoint-" + ID + ".bc";
7375 if (writeProgramToFile(Filename)) {
74 std::cerr << "Error opening file '" << Filename << "' for writing!\n";
76 llvm_cerr << "Error opening file '" << Filename << "' for writing!\n";
7577 return;
7678 }
7779
78 std::cout << "Emitted bytecode to '" << Filename << "'\n";
80 llvm_cout << "Emitted bytecode to '" << Filename << "'\n";
7981 if (NoFlyer || PassesToRun.empty()) return;
80 std::cout << "\n*** You can reproduce the problem with: ";
81 std::cout << "opt " << Filename << " ";
82 std::cout << getPassesString(PassesToRun) << "\n";
82 llvm_cout << "\n*** You can reproduce the problem with: ";
83 llvm_cout << "opt " << Filename << " ";
84 llvm_cout << getPassesString(PassesToRun) << "\n";
8385 }
8486
8587 int BugDriver::runPassesAsChild(const std::vector &Passes) {
8890 std::ios::binary;
8991 std::ofstream OutFile(ChildOutput.c_str(), io_mode);
9092 if (!OutFile.good()) {
91 std::cerr << "Error opening bytecode file: " << ChildOutput << "\n";
93 llvm_cerr << "Error opening bytecode file: " << ChildOutput << "\n";
9294 return 1;
9395 }
9496
100102 if (Passes[i]->getNormalCtor())
101103 PM.add(Passes[i]->getNormalCtor()());
102104 else
103 std::cerr << "Cannot create pass yet: " << Passes[i]->getPassName()
105 llvm_cerr << "Cannot create pass yet: " << Passes[i]->getPassName()
104106 << "\n";
105107 }
106108 // Check that the module is well formed on completion of optimization
107109 PM.add(createVerifierPass());
108110
109111 // Write bytecode out to disk as the last step...
110 PM.add(new WriteBytecodePass(&OutFile));
112 llvm_ostream L(OutFile);
113 PM.add(new WriteBytecodePass(&L));
111114
112115 // Run all queued passes.
113116 PM.run(*Program);
127130 std::string &OutputFilename, bool DeleteOutput,
128131 bool Quiet) const {
129132 // setup the output file name
130 std::cout << std::flush;
133 llvm_cout << std::flush;
131134 sys::Path uniqueFilename("bugpoint-output.bc");
132135 std::string ErrMsg;
133136 if (uniqueFilename.makeUnique(true, &ErrMsg)) {
134 std::cerr << getToolName() << ": Error making unique filename: "
137 llvm_cerr << getToolName() << ": Error making unique filename: "
135138 << ErrMsg << "\n";
136139 return(1);
137140 }
140143 // set up the input file name
141144 sys::Path inputFilename("bugpoint-input.bc");
142145 if (inputFilename.makeUnique(true, &ErrMsg)) {
143 std::cerr << getToolName() << ": Error making unique filename: "
146 llvm_cerr << getToolName() << ": Error making unique filename: "
144147 << ErrMsg << "\n";
145148 return(1);
146149 }
148151 std::ios::binary;
149152 std::ofstream InFile(inputFilename.c_str(), io_mode);
150153 if (!InFile.good()) {
151 std::cerr << "Error opening bytecode file: " << inputFilename << "\n";
154 llvm_cerr << "Error opening bytecode file: " << inputFilename << "\n";
152155 return(1);
153156 }
154 WriteBytecodeToFile(Program,InFile,false);
157 llvm_ostream L(InFile);
158 WriteBytecodeToFile(Program,L,false);
155159 InFile.close();
156160
157161 // setup the child process' arguments
202206
203207 if (!Quiet) {
204208 if (result == 0)
205 std::cout << "Success!\n";
209 llvm_cout << "Success!\n";
206210 else if (result > 0)
207 std::cout << "Exited with error code '" << result << "'\n";
211 llvm_cout << "Exited with error code '" << result << "'\n";
208212 else if (result < 0) {
209213 if (result == -1)
210 std::cout << "Execute failed: " << ErrMsg << "\n";
214 llvm_cout << "Execute failed: " << ErrMsg << "\n";
211215 else
212 std::cout << "Crashed with signal #" << abs(result) << "\n";
216 llvm_cout << "Crashed with signal #" << abs(result) << "\n";
213217 }
214218 if (result & 0x01000000)
215 std::cout << "Dumped core\n";
219 llvm_cout << "Dumped core\n";
216220 }
217221
218222 // Was the child successful?
230234 std::string BytecodeResult;
231235 if (runPasses(Passes, BytecodeResult, false/*delete*/, true/*quiet*/)) {
232236 if (AutoDebugCrashes) {
233 std::cerr << " Error running this sequence of passes"
237 llvm_cerr << " Error running this sequence of passes"
234238 << " on the input program!\n";
235239 delete OldProgram;
236240 EmitProgressBytecode("pass-error", false);
245249
246250 Module *Ret = ParseInputFile(BytecodeResult);
247251 if (Ret == 0) {
248 std::cerr << getToolName() << ": Error reading bytecode file '"
252 llvm_cerr << getToolName() << ": Error reading bytecode file '"
249253 << BytecodeResult << "'!\n";
250254 exit(1);
251255 }
2222 #include "llvm/Transforms/IPO.h"
2323 #include "llvm/Transforms/Scalar.h"
2424 #include "llvm/Support/CommandLine.h"
25 #include "llvm/Support/Streams.h"
2526 #include "llvm/System/Signals.h"
27 #include
2628 #include
2729 #include
28
2930 using namespace llvm;
3031
3132 namespace {
139140 ParseError Err;
140141 std::auto_ptr M(ParseAssemblyFile(InputFilename,&Err));
141142 if (M.get() == 0) {
142 std::cerr << argv[0] << ": " << Err.getMessage() << "\n";
143 llvm_cerr << argv[0] << ": " << Err.getMessage() << "\n";
143144 return 1;
144145 }
145146
174175
175176
176177 if (!Out->good()) {
177 std::cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
178 llvm_cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
178179 return 1;
179180 }
180181
193194 Passes.add(createVerifierPass());
194195
195196 // Write bytecode to file...
196 Passes.add(new WriteBytecodePass(Out,false,!NoCompress));
197 llvm_ostream L(*Out);
198 Passes.add(new WriteBytecodePass(&L,false,!NoCompress));
197199
198200 // Run our queue of passes all at once now, efficiently.
199201 Passes.run(*M.get());
201203 if (Out != &std::cout) delete Out;
202204 return 0;
203205 } catch (const std::string& msg) {
204 std::cerr << argv[0] << ": " << msg << "\n";
206 llvm_cerr << argv[0] << ": " << msg << "\n";
205207 } catch (...) {
206 std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
208 llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
207209 }
208210 return 1;
209211 }
2626 #include "llvm/Transforms/Scalar.h"
2727 #include "llvm/Support/SystemUtils.h"
2828 #include "llvm/Support/CommandLine.h"
29
29 #include "llvm/Support/Streams.h"
3030 using namespace llvm;
3131
3232 namespace {
122122 }
123123
124124 static void dumpArgs(const char **args) {
125 std::cerr << *args++;
125 llvm_cerr << *args++;
126126 while (*args)
127 std::cerr << ' ' << *args++;
128 std::cerr << '\n' << std::flush;
127 llvm_cerr << ' ' << *args++;
128 llvm_cerr << '\n' << std::flush;
129129 }
130130
131131 static inline void addPass(PassManager &PM, Pass *P) {
282282 Passes.add(createVerifierPass());
283283
284284 // Add the pass that writes bytecode to the output file...
285 addPass(Passes, new WriteBytecodePass(Out, false, !NoCompress));
285 llvm_ostream L(*Out);
286 addPass(Passes, new WriteBytecodePass(&L, false, !NoCompress));
286287
287288 // Run our queue of passes all at once now, efficiently.
288289 Passes.run(*M);
3030 #include "llvm/Transforms/Scalar.h"
3131 #include "llvm/Support/CommandLine.h"
3232 #include "llvm/Support/FileUtilities.h"
33 #include "llvm/Support/Streams.h"
3334 #include "llvm/System/Signals.h"
3435 #include "llvm/Support/SystemUtils.h"
3536 #include
125126 /// Message - The message to print to standard error.
126127 ///
127128 static int PrintAndReturn(const char *progname, const std::string &Message) {
128 std::cerr << progname << ": " << Message << "\n";
129 llvm_cerr << progname << ": " << Message << "\n";
129130 return 1;
130131 }
131132
139140 std::string ErrMsg;
140141 sys::Path llvmstub = FindExecutable("llvm-stub.exe", argv[0]);
141142 if (llvmstub.isEmpty()) {
142 std::cerr << "Could not find llvm-stub.exe executable!\n";
143 llvm_cerr << "Could not find llvm-stub.exe executable!\n";
143144 exit(1);
144145 }
145146 if (0 != sys::CopyFile(sys::Path(OutputFilename), llvmstub, &ErrMsg)) {
146 std::cerr << argv[0] << ": " << ErrMsg << "\n";
147 llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
147148 exit(1);
148149 }
149150
323324 return PrintAndReturn(argv[0], "Failed to find gcc");
324325
325326 // Generate an assembly language file for the bytecode.
326 if (Verbose) std::cout << "Generating Assembly Code\n";
327 if (Verbose) llvm_cout << "Generating Assembly Code\n";
327328 std::string ErrMsg;
328329 if (0 != GenerateAssembly(
329330 AssemblyFile.toString(), RealBytecodeOutput, llc, ErrMsg, Verbose)) {
330 std::cerr << argv[0] << ": " << ErrMsg << "\n";
331 llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
331332 return 2;
332333 }
333 if (Verbose) std::cout << "Generating Native Code\n";
334 if (Verbose) llvm_cout << "Generating Native Code\n";
334335 if (0 != GenerateNative(OutputFilename, AssemblyFile.toString(),
335336 LibPaths, Libraries, gcc, envp, LinkAsLibrary,
336337 NoInternalize, RPath, SOName, ErrMsg, Verbose) ) {
337 std::cerr << argv[0] << ": " << ErrMsg << "\n";
338 llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
338339 return 2;
339340 }
340341
363364 return PrintAndReturn(argv[0], "Failed to find gcc");
364365
365366 // Generate an assembly language file for the bytecode.
366 if (Verbose) std::cout << "Generating C Source Code\n";
367 if (Verbose) llvm_cout << "Generating C Source Code\n";
367368 std::string ErrMsg;
368369 if (0 != GenerateCFile(
369370 CFile.toString(), RealBytecodeOutput, llc, ErrMsg, Verbose)) {
370 std::cerr << argv[0] << ": " << ErrMsg << "\n";
371 llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
371372 return 2;
372373 }
373 if (Verbose) std::cout << "Generating Native Code\n";
374 if (Verbose) llvm_cout << "Generating Native Code\n";
374375 if (0 != GenerateNative(OutputFilename, CFile.toString(),
375376 LibPaths, Libraries, gcc, envp, LinkAsLibrary,
376377 NoInternalize, RPath, SOName, ErrMsg, Verbose)) {
377 std::cerr << argv[0] << ": " << ErrMsg << "\n";
378 llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
378379 return 2;
379380 }
380381
391392 // Make the bytecode file readable and directly executable in LLEE
392393 std::string ErrMsg;
393394 if (sys::Path(RealBytecodeOutput).makeExecutableOnDisk(&ErrMsg)) {
394 std::cerr << argv[0] << ": " << ErrMsg << "\n";
395 llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
395396 return 1;
396397 }
397398 if (sys::Path(RealBytecodeOutput).makeReadableOnDisk(&ErrMsg)) {
398 std::cerr << argv[0] << ": " << ErrMsg << "\n";
399 llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
399400 return 1;
400401 }
401402 }
403404 // Make the output, whether native or script, executable as well...
404405 std::string ErrMsg;
405406 if (sys::Path(OutputFilename).makeExecutableOnDisk(&ErrMsg)) {
406 std::cerr << argv[0] << ": " << ErrMsg << "\n";
407 llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
407408 return 1;
408409 }
409410 } catch (const char*msg) {
410 std::cerr << argv[0] << ": " << msg << "\n";
411 llvm_cerr << argv[0] << ": " << msg << "\n";
411412 exitCode = 1;
412413 } catch (const std::string& msg) {
413 std::cerr << argv[0] << ": " << msg << "\n";
414 llvm_cerr << argv[0] << ": " << msg << "\n";
414415 exitCode = 2;
415416 } catch (...) {
416417 // This really shouldn't happen, but just in case ....
417 std::cerr << argv[0] << ": An unexpected unknown exception occurred.\n";
418 llvm_cerr << argv[0] << ": An unexpected unknown exception occurred.\n";
418419 exitCode = 3;
419420 }
420421
1919 #include "llvm/Bytecode/Writer.h"
2020 #include "llvm/Analysis/Verifier.h"
2121 #include "llvm/Support/CommandLine.h"
22 #include "llvm/Support/Streams.h"
2223 #include "llvm/Support/SystemUtils.h"
2324 #include "llvm/System/Signals.h"
2425 #include
2526 #include
2627 #include
27
2828 using namespace llvm;
2929
3030 static cl::opt
5959 ParseError Err;
6060 std::auto_ptr M(ParseAssemblyFile(InputFilename,&Err));
6161 if (M.get() == 0) {
62 std::cerr << argv[0] << ": " << Err.getMessage() << "\n";
62 llvm_cerr << argv[0] << ": " << Err.getMessage() << "\n";
6363 return 1;
6464 }
6565
6666 if (!DisableVerify) {
6767 std::string Err;
6868 if (verifyModule(*M.get(), ReturnStatusAction, &Err)) {
69 std::cerr << argv[0]
69 llvm_cerr << argv[0]
7070 << ": assembly parsed, but does not verify as correct!\n";
71 std::cerr << Err;
71 llvm_cerr << Err;
7272 return 1;
7373 }
7474 }
7575
76 if (DumpAsm) std::cerr << "Here's the assembly:\n" << *M.get();
76 if (DumpAsm) llvm_cerr << "Here's the assembly:\n" << *M.get();
7777
7878 if (OutputFilename != "") { // Specified an output filename?
7979 if (OutputFilename != "-") { // Not stdout?
8080 if (!Force && std::ifstream(OutputFilename.c_str())) {
8181 // If force is not specified, make sure not to overwrite a file!
82 std::cerr << argv[0] << ": error opening '" << OutputFilename
82 llvm_cerr << argv[0] << ": error opening '" << OutputFilename
8383 << "': file exists!\n"
8484 << "Use -f command line argument to force output\n";
8585 return 1;
107107
108108 if (!Force && std::ifstream(OutputFilename.c_str())) {
109109 // If force is not specified, make sure not to overwrite a file!
110 std::cerr << argv[0] << ": error opening '" << OutputFilename
110 llvm_cerr << argv[0] << ": error opening '" << OutputFilename
111111 << "': file exists!\n"
112112 << "Use -f command line argument to force output\n";
113113 return 1;
122122 }
123123
124124 if (!Out->good()) {
125 std::cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
125 llvm_cerr << argv[0] << ": error opening " << OutputFilename << "!\n";
126126 return 1;
127127 }
128128
129129 if (Force || !CheckBytecodeOutputToConsole(Out,true)) {
130 WriteBytecodeToFile(M.get(), *Out, !NoCompress);
130 llvm_ostream L(*Out);
131 WriteBytecodeToFile(M.get(), L, !NoCompress);
131132 }
132133 } catch (const std::string& msg) {
133 std::cerr << argv[0] << ": " << msg << "\n";
134 llvm_cerr << argv[0] << ": " << msg << "\n";
134135 exitCode = 1;
135136 } catch (...) {
136 std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
137 llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
137138 exitCode = 1;
138139 }
139140
1818 #include "llvm/Transforms/IPO.h"
1919 #include "llvm/Target/TargetData.h"
2020 #include "llvm/Support/CommandLine.h"
21 #include "llvm/Support/Streams.h"
2122 #include "llvm/System/Signals.h"
23 #include
2224 #include
2325 #include
2426 using namespace llvm;
5052
5153 std::auto_ptr M(ParseBytecodeFile(InputFilename));
5254 if (M.get() == 0) {
53 std::cerr << argv[0] << ": bytecode didn't read correctly.\n";
55 llvm_cerr << argv[0] << ": bytecode didn't read correctly.\n";
5456 return 1;
5557 }
5658
5759 // Figure out which function we should extract
5860 Function *F = M.get()->getNamedFunction(ExtractFunc);
5961 if (F == 0) {
60 std::cerr << argv[0] << ": program doesn't contain function named '"
62 llvm_cerr << argv[0] << ": program doesn't contain function named '"
6163 << ExtractFunc << "'!\n";
6264 return 1;
6365 }
7779 if (OutputFilename != "-") { // Not stdout?
7880 if (!Force && std::ifstream(OutputFilename.c_str())) {
7981 // If force is not specified, make sure not to overwrite a file!
80 std::cerr << argv[0] << ": error opening '" << OutputFilename
82 llvm_cerr << argv[0] << ": error opening '" << OutputFilename
8183 << "': file exists!\n"
8284 << "Use -f command line argument to force output\n";
8385 return 1;
9092 Out = &std::cout;
9193 }
9294
93 Passes.add(new WriteBytecodePass(Out)); // Write bytecode to file...
95 llvm_ostream L(*Out);
96 Passes.add(new WriteBytecodePass(&L)); // Write bytecode to file...
9497 Passes.run(*M.get());
9598
9699 if (Out != &std::cout)
97100 delete Out;
98101 return 0;
99102 } catch (const std::string& msg) {
100 std::cerr << argv[0] << ": " << msg << "\n";
103 llvm_cerr << argv[0] << ": " << msg << "\n";
101104 } catch (...) {
102 std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
105 llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
103106 }
104107 return 1;
105108 }
3131 #include "llvm/Target/TargetMachineRegistry.h"
3232 #include "llvm/Support/CommandLine.h"
3333 #include "llvm/Support/FileUtilities.h"
34 #include "llvm/Support/Streams.h"
3435 #include "llvm/Support/SystemUtils.h"
3536 #include "llvm/System/Signals.h"
3637 #include
37 #include
3838 #include
39
4039 using namespace llvm;
4140
4241 // Input/Output Options
108107 /// Message - The message to print to standard error.
109108 ///
110109 static int PrintAndReturn(const std::string &Message) {
111 std::cerr << progname << ": " << Message << "\n";
110 llvm_cerr << progname << ": " << Message << "\n";
112111 return 1;
113112 }
114113
207206 sys::RemoveFileOnSignal(sys::Path(FileName));
208207
209208 // Write it out
210 WriteBytecodeToFile(M, Out, !DisableCompression);
209 llvm_ostream L(Out);
210 WriteBytecodeToFile(M, L, !DisableCompression);
211211
212212 // Close the bytecode file.
213213 Out.close();
350350 std::string ErrMsg;
351351 sys::Path llvmstub = FindExecutable("llvm-stub.exe", argv[0]);
352352 if (llvmstub.isEmpty()) {
353 std::cerr << "Could not find llvm-stub.exe executable!\n";
353 llvm_cerr << "Could not find llvm-stub.exe executable!\n";
354354 exit(1);
355355 }
356356
357357 if (0 != sys::CopyFile(sys::Path(OutputFilename), llvmstub, &ErrMsg)) {
358 std::cerr << argv[0] << ": " << ErrMsg << "\n";
358 llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
359359 exit(1);
360360 }
361361
517517 sys::Path target(RealBytecodeOutput);
518518 target.eraseFromDisk();
519519 if (tmp_output.renamePathOnDisk(target, &ErrMsg)) {
520 std::cerr << argv[0] << ": " << ErrMsg << "\n";
520 llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
521521 return 2;
522522 }
523523 } else
524524 return PrintAndReturn(
525525 "Post-link optimization output is not bytecode");
526526 } else {
527 std::cerr << argv[0] << ": " << ErrMsg << "\n";
527 llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
528528 return 2;
529529 }
530530 }
553553 return PrintAndReturn("Failed to find gcc");
554554
555555 // Generate an assembly language file for the bytecode.
556 if (Verbose) std::cout << "Generating Assembly Code\n";
556 if (Verbose) llvm_cout << "Generating Assembly Code\n";
557557 std::string ErrMsg;
558558 if (0 != GenerateAssembly(AssemblyFile.toString(), RealBytecodeOutput,
559559 llc, ErrMsg)) {
560 std::cerr << argv[0] << ": " << ErrMsg << "\n";
560 llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
561561 return 1;
562562 }
563563
564 if (Verbose) std::cout << "Generating Native Code\n";
564 if (Verbose) llvm_cout << "Generating Native Code\n";
565565 if (0 != GenerateNative(OutputFilename, AssemblyFile.toString(),
566566 LinkItems,gcc,envp,ErrMsg)) {
567 std::cerr << argv[0] << ": " << ErrMsg << "\n";
567 llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
568568 return 1;
569569 }
570570
588588 return PrintAndReturn("Failed to find gcc");
589589
590590 // Generate an assembly language file for the bytecode.
591 if (Verbose) std::cout << "Generating Assembly Code\n";
591 if (Verbose) llvm_cout << "Generating Assembly Code\n";
592592 std::string ErrMsg;
593593 if (0 != GenerateCFile(
594594 CFile.toString(), RealBytecodeOutput, llc, ErrMsg)) {
595 std::cerr << argv[0] << ": " << ErrMsg << "\n";
595 llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
596596 return 1;
597597 }
598598
599 if (Verbose) std::cout << "Generating Native Code\n";
599 if (Verbose) llvm_cout << "Generating Native Code\n";
600600 if (0 != GenerateNative(OutputFilename, CFile.toString(), LinkItems,
601601 gcc, envp, ErrMsg)) {
602 std::cerr << argv[0] << ": " << ErrMsg << "\n";
602 llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
603603 return 1;
604604 }
605605
613613 // Make the script executable...
614614 std::string ErrMsg;
615615 if (sys::Path(OutputFilename).makeExecutableOnDisk(&ErrMsg)) {
616 std::cerr << argv[0] << ": " << ErrMsg << "\n";
616 llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
617617 return 1;
618618 }
619619
620620 // Make the bytecode file readable and directly executable in LLEE as well
621621 if (sys::Path(RealBytecodeOutput).makeExecutableOnDisk(&ErrMsg)) {
622 std::cerr << argv[0] << ": " << ErrMsg << "\n";
622 llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
623623 return 1;
624624 }
625625 if (sys::Path(RealBytecodeOutput).makeReadableOnDisk(&ErrMsg)) {
626 std::cerr << argv[0] << ": " << ErrMsg << "\n";
626 llvm_cerr << argv[0] << ": " << ErrMsg << "\n";
627627 return 1;
628628 }
629629 }
630630
631631 return 0;
632632 } catch (const std::string& msg) {
633 std::cerr << argv[0] << ": " << msg << "\n";
633 llvm_cerr << argv[0] << ": " << msg << "\n";
634634 } catch (...) {
635 std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
635 llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
636636 }
637637 return 1;
638638 }
1717 #include "llvm/Bytecode/Reader.h"
1818 #include "llvm/Bytecode/Writer.h"
1919 #include "llvm/Support/CommandLine.h"
20 #include "llvm/Support/Streams.h"
2021 #include "llvm/System/Signals.h"
2122 #include "llvm/System/Path.h"
2223 #include
2324 #include
2425 #include
25
2626 using namespace llvm;
2727
2828 static cl::list
5050 static inline std::auto_ptr LoadFile(const std::string &FN) {
5151 sys::Path Filename;
5252 if (!Filename.set(FN)) {
53 std::cerr << "Invalid file name: '" << FN << "'\n";
53 llvm_cerr << "Invalid file name: '" << FN << "'\n";
5454 return std::auto_ptr();
5555 }
5656
5757 std::string ErrorMessage;
5858 if (Filename.exists()) {
59 if (Verbose) std::cerr << "Loading '" << Filename.c_str() << "'\n";
59 if (Verbose) llvm_cerr << "Loading '" << Filename.c_str() << "'\n";
6060 Module* Result = ParseBytecodeFile(Filename.toString(), &ErrorMessage);
6161 if (Result) return std::auto_ptr(Result); // Load successful!
6262
6363 if (Verbose) {
64 std::cerr << "Error opening bytecode file: '" << Filename.c_str() << "'";
65 if (ErrorMessage.size()) std::cerr << ": " << ErrorMessage;
66 std::cerr << "\n";
64 llvm_cerr << "Error opening bytecode file: '" << Filename.c_str() << "'";
65 if (ErrorMessage.size()) llvm_cerr << ": " << ErrorMessage;
66 llvm_cerr << "\n";
6767 }
6868 } else {
69 std::cerr << "Bytecode file: '" << Filename.c_str()
69 llvm_cerr << "Bytecode file: '" << Filename.c_str()
7070 << "' does not exist.\n";
7171 }
7272
8484
8585 std::auto_ptr Composite(LoadFile(InputFilenames[BaseArg]));
8686 if (Composite.get() == 0) {
87 std::cerr << argv[0] << ": error loading file '"
87 llvm_cerr << argv[0] << ": error loading file '"
8888 << InputFilenames[BaseArg] << "'\n";
8989 return 1;
9090 }
9292 for (unsigned i = BaseArg+1; i < InputFilenames.size(); ++i) {
9393 std::auto_ptr M(LoadFile(InputFilenames[i]));
9494 if (M.get() == 0) {
95 std::cerr << argv[0] << ": error loading file '"
95 llvm_cerr << argv[0] << ": error loading file '"
9696 << InputFilenames[i] << "'\n";
9797 return 1;
9898 }
9999
100 if (Verbose) std::cerr << "Linking in '" << InputFilenames[i] << "'\n";
100 if (Verbose) llvm_cerr << "Linking in '" << InputFilenames[i] << "'\n";
101101
102102 if (Linker::LinkModules(Composite.get(), M.get(), &ErrorMessage)) {
103 std::cerr << argv[0] << ": link error in '" << InputFilenames[i]
103 llvm_cerr << argv[0] << ": link error in '" << InputFilenames[i]
104104 << "': " << ErrorMessage << "\n";
105105 return 1;
106106 }
109109 // TODO: Iterate over the -l list and link in any modules containing
110110 // global symbols that have not been resolved so far.
111111
112 if (DumpAsm) std::cerr << "Here's the assembly:\n" << *Composite.get();
112 if (DumpAsm) llvm_cerr << "Here's the assembly:\n" << *Composite.get();
113113
114114 // FIXME: cout is not binary!
115115 std::ostream *Out = &std::cout; // Default to printing to stdout...
116116 if (OutputFilename != "-") {
117117 if (!Force && std::ifstream(OutputFilename.c_str())) {
118118 // If force is not specified, make sure not to overwrite a file!
119 std::cerr << argv[0] << ": error opening '" << OutputFilename
119 llvm_cerr << argv[0] << ": error opening '" << OutputFilename
120120 << "': file exists!\n"
121121 << "Use -f command line argument to force output\n";
122122 return 1;
125125 std::ios::binary;
126126 Out = new std::ofstream(OutputFilename.c_str(), io_mode);
127127 if (!Out->good()) {
128 std::cerr << argv[0] << ": error opening '" << OutputFilename << "'!\n";
128 llvm_cerr << argv[0] << ": error opening '" << OutputFilename << "'!\n";
129129 return 1;
130130 }
131131
135135 }
136136
137137 if (verifyModule(*Composite.get())) {
138 std::cerr << argv[0] << ": linked module is broken!\n";
138 llvm_cerr << argv[0] << ": linked module is broken!\n";
139139 return 1;
140140 }
141141
142 if (Verbose) std::cerr << "Writing bytecode...\n";
143 WriteBytecodeToFile(Composite.get(), *Out, !NoCompress);
142 if (Verbose) llvm_cerr << "Writing bytecode...\n";
143 llvm_ostream L(*Out);
144 WriteBytecodeToFile(Composite.get(), L, !NoCompress);
144145
145146 if (Out != &std::cout) delete Out;
146147 return 0;
147148 } catch (const std::string& msg) {
148 std::cerr << argv[0] << ": " << msg << "\n";
149 llvm_cerr << argv[0] << ": " << msg << "\n";
149150 } catch (...) {
150 std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
151 llvm_cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
151152 }
152153 return 1;
153154 }
3636 #include "llvm/Transforms/Scalar.h"
3737 #include "llvm/Analysis/LoadValueNumbering.h"
3838 #include "llvm/Support/MathExtras.h"
39 #include "llvm/Support/Streams.h"
3940 #include "llvm/LinkTimeOptimizer.h"
4041 #include
41 #include
42
42 #include
4343 using namespace llvm;
4444
4545 extern "C"
360360 std::string tempFileName(FinalOutputPath.c_str());
361361 tempFileName += "0.bc";
362362 std::ofstream Out(tempFileName.c_str(), io_mode);
363 WriteBytecodeToFile(bigOne, Out, true);
363 llvm_ostream L(Out);
364 WriteBytecodeToFile(bigOne, L, true);
364365 }
365366
366367 // Strip leading underscore because it was added to match names
376377 std::string ErrMsg;
377378 sys::Path TempDir = sys::Path::GetTemporaryDirectory(&ErrMsg);
378379 if (TempDir.isEmpty()) {
379 std::cerr << "lto: " << ErrMsg << "\n";
380 llvm_cerr << "lto: " << ErrMsg << "\n";
380381 return LTO_WRITE_FAILURE;
381382 }
382383 sys::Path tmpAsmFilePath(TempDir);
383384 if (!tmpAsmFilePath.appendComponent("lto")) {
384 std::cerr << "lto: " << ErrMsg << "\n";
385 llvm_cerr << "lto: " << ErrMsg << "\n";
385386 TempDir.eraseFromDisk(true);
386387 return LTO_WRITE_FAILURE;
387388 }
388389 if (tmpAsmFilePath.createTemporaryFileOnDisk(&ErrMsg)) {
389 std::cerr << "lto: " << ErrMsg << "\n";
390 llvm_cerr << "lto: " << ErrMsg << "\n";
390391 TempDir.eraseFromDisk(true);
391392 return LTO_WRITE_FAILURE;
392393 }
413414 std::string tempFileName(FinalOutputPath.c_str());
414415 tempFileName += "1.bc";
415416 std::ofstream Out(tempFileName.c_str(), io_mode);
416 WriteBytecodeToFile(bigOne, Out, true);
417 llvm_ostream L(Out);
418 WriteBytecodeToFile(bigOne, L, true);
417419 }
418420
419421 targetTriple = bigOne->getTargetTriple();
442444 args.push_back(0);
443445
444446 if (sys::Program::ExecuteAndWait(gcc, &args[0], 0, 0, 1, &ErrMsg)) {
445 std::cerr << "lto: " << ErrMsg << "\n";
447 llvm_cerr << "lto: " << ErrMsg << "\n";
446448 return LTO_ASM_FAILURE;
447449 }
448450
2727 #include "llvm/Support/Timer.h"
2828 #include "llvm/LinkAllPasses.h"
2929 #include "llvm/LinkAllVMCore.h"
30 #include
3031 #include
3132 #include
3233 #include
250251 Passes.add(createVerifierPass());
251252
252253 // Write bytecode out to disk or cout as the last step...
253 if (!NoOutput && !AnalyzeOnly)
254 Passes.add(new WriteBytecodePass(Out, Out != &std::cout, !NoCompress));
254 if (!NoOutput && !AnalyzeOnly) {
255 llvm_ostream L(*Out);
256 Passes.add(new WriteBytecodePass(&L, Out != &std::cout, !NoCompress));
257 }
255258
256259 // Now that we have all of the passes ready, run them.
257260 Passes.run(*M.get());