diff options
Diffstat (limited to 'include/llvm')
27 files changed, 110 insertions, 94 deletions
diff --git a/include/llvm/ADT/BitSetVector.h b/include/llvm/ADT/BitSetVector.h index 67e3a52..5d1fc86 100644 --- a/include/llvm/ADT/BitSetVector.h +++ b/include/llvm/ADT/BitSetVector.h @@ -29,7 +29,6 @@ #include <bitset> #include <vector> #include <functional> -#include <ostream> namespace llvm { @@ -174,11 +173,11 @@ public: /// /// Printing and debugging support /// - void print(llvm_ostream &O) const { + void print(OStream &O) const { if (O.stream()) print(*O.stream()); } void print(std::ostream &O) const; - void dump() const { print(llvm_cerr); } + void dump() const { print(cerr); } public: // @@ -235,6 +234,9 @@ public: return (I.bitvec == bitvec && I.currentWord == currentWord && I.currentBit == currentBit); } + bool operator!=(const iterator& I) { + return !(*this == I); + } protected: static iterator begin(BitSetVector& _bitvec) { return iterator(_bitvec); } @@ -252,7 +254,7 @@ inline void BitSetVector::print(std::ostream& O) const O << "<" << (*I) << ">" << (I+1 == E? "\n" : ", "); } -inline llvm_ostream& operator<< (llvm_ostream& O, const BitSetVector& bset) { +inline OStream& operator<< (OStream& O, const BitSetVector& bset) { bset.print(O); return O; } diff --git a/include/llvm/ADT/EquivalenceClasses.h b/include/llvm/ADT/EquivalenceClasses.h index b915c2a..7d305cb 100644 --- a/include/llvm/ADT/EquivalenceClasses.h +++ b/include/llvm/ADT/EquivalenceClasses.h @@ -43,8 +43,8 @@ namespace llvm { /// if (!I->isLeader()) continue; // Ignore non-leader sets. /// for (EquivalenceClasses<int>::member_iterator MI = EC.member_begin(I); /// MI != EC.member_end(); ++MI) // Loop over members in this set. -/// llvm_cerr << *MI << " "; // Print member. -/// llvm_cerr << "\n"; // Finish set. +/// cerr << *MI << " "; // Print member. +/// cerr << "\n"; // Finish set. /// } /// /// This example prints: diff --git a/include/llvm/Analysis/AliasSetTracker.h b/include/llvm/Analysis/AliasSetTracker.h index c4273ac..5fcda16 100644 --- a/include/llvm/Analysis/AliasSetTracker.h +++ b/include/llvm/Analysis/AliasSetTracker.h @@ -156,7 +156,7 @@ public: iterator end() const { return iterator(); } bool empty() const { return PtrList == 0; } - void print(llvm_ostream &OS) const { + void print(OStream &OS) const { if (OS.stream()) print(*OS.stream()); } void print(std::ostream &OS) const; @@ -248,7 +248,7 @@ private: bool aliasesCallSite(CallSite CS, AliasAnalysis &AA) const; }; -inline llvm_ostream& operator<<(llvm_ostream &OS, const AliasSet &AS) { +inline OStream& operator<<(OStream &OS, const AliasSet &AS) { AS.print(OS); return OS; } @@ -361,7 +361,7 @@ public: iterator begin() { return AliasSets.begin(); } iterator end() { return AliasSets.end(); } - void print(llvm_ostream &OS) const { + void print(OStream &OS) const { if (OS.stream()) print(*OS.stream()); } void print(std::ostream &OS) const; @@ -390,7 +390,7 @@ private: AliasSet *findAliasSetForCallSite(CallSite CS); }; -inline llvm_ostream& operator<<(llvm_ostream &OS, const AliasSetTracker &AST) { +inline OStream& operator<<(OStream &OS, const AliasSetTracker &AST) { AST.print(OS); return OS; } diff --git a/include/llvm/Analysis/CallGraph.h b/include/llvm/Analysis/CallGraph.h index f29aef3..1f737da 100644 --- a/include/llvm/Analysis/CallGraph.h +++ b/include/llvm/Analysis/CallGraph.h @@ -152,7 +152,7 @@ public: /// void initialize(Module &M); - void print(llvm_ostream &o, const Module *M) const { + void print(OStream &o, const Module *M) const { if (o.stream()) print(*o.stream(), M); } virtual void print(std::ostream &o, const Module *M) const; @@ -201,7 +201,7 @@ public: /// dump - Print out this call graph node. /// void dump() const; - void print(llvm_ostream &OS) const { + void print(OStream &OS) const { if (OS.stream()) print(*OS.stream()); } void print(std::ostream &OS) const; diff --git a/include/llvm/Analysis/DataStructure/DSGraph.h b/include/llvm/Analysis/DataStructure/DSGraph.h index 6185358..1063efa 100644 --- a/include/llvm/Analysis/DataStructure/DSGraph.h +++ b/include/llvm/Analysis/DataStructure/DSGraph.h @@ -378,12 +378,12 @@ public: /// print - Print a dot graph to the specified ostream... /// - void print(llvm_ostream &O) const { + void print(OStream &O) const { if (O.stream()) print(*O.stream()); } void print(std::ostream &O) const; - /// dump - call print(llvm_cerr), for use from the debugger... + /// dump - call print(cerr), for use from the debugger... /// void dump() const; diff --git a/include/llvm/Analysis/DataStructure/DSNode.h b/include/llvm/Analysis/DataStructure/DSNode.h index 5eb927b..abcca35 100644 --- a/include/llvm/Analysis/DataStructure/DSNode.h +++ b/include/llvm/Analysis/DataStructure/DSNode.h @@ -362,7 +362,7 @@ public: /// void forwardNode(DSNode *To, unsigned Offset); - void print(llvm_ostream &O, const DSGraph *G) const { + void print(OStream &O, const DSGraph *G) const { if (O.stream()) print(*O.stream(), G); } void print(std::ostream &O, const DSGraph *G) const; diff --git a/include/llvm/Analysis/LoopInfo.h b/include/llvm/Analysis/LoopInfo.h index 2e6d247..238a0f6 100644 --- a/include/llvm/Analysis/LoopInfo.h +++ b/include/llvm/Analysis/LoopInfo.h @@ -217,7 +217,7 @@ public: /// the mapping in the LoopInfo class. void removeBlockFromLoop(BasicBlock *BB); - void print(llvm_ostream &O, unsigned Depth = 0) const { + void print(OStream &O, unsigned Depth = 0) const { if (O.stream()) print(*O.stream(), Depth); } void print(std::ostream &O, unsigned Depth = 0) const; @@ -283,7 +283,7 @@ public: virtual bool runOnFunction(Function &F); virtual void releaseMemory(); - void print(llvm_ostream &O, const Module* = 0) const { + void print(OStream &O, const Module* = 0) const { if (O.stream()) print(*O.stream()); } void print(std::ostream &O, const Module* = 0) const; diff --git a/include/llvm/Analysis/ScalarEvolution.h b/include/llvm/Analysis/ScalarEvolution.h index f1497cd..4eb0bb3 100644 --- a/include/llvm/Analysis/ScalarEvolution.h +++ b/include/llvm/Analysis/ScalarEvolution.h @@ -97,7 +97,7 @@ namespace llvm { /// print - Print out the internal representation of this scalar to the /// specified stream. This should really only be used for debugging /// purposes. - void print(llvm_ostream &OS) const { + void print(OStream &OS) const { if (OS.stream()) print(*OS.stream()); } virtual void print(std::ostream &OS) const = 0; @@ -107,7 +107,7 @@ namespace llvm { void dump() const; }; - inline llvm_ostream &operator<<(llvm_ostream &OS, const SCEV &S) { + inline OStream &operator<<(OStream &OS, const SCEV &S) { S.print(OS); return OS; } @@ -128,7 +128,7 @@ namespace llvm { virtual bool isLoopInvariant(const Loop *L) const; virtual const Type *getType() const; virtual bool hasComputableLoopEvolution(const Loop *L) const; - void print(llvm_ostream &OS) const { + void print(OStream &OS) const { if (OS.stream()) print(*OS.stream()); } virtual void print(std::ostream &OS) const; @@ -242,7 +242,7 @@ namespace llvm { virtual bool runOnFunction(Function &F); virtual void releaseMemory(); virtual void getAnalysisUsage(AnalysisUsage &AU) const; - void print(llvm_ostream &OS, const Module* = 0) const { + void print(OStream &OS, const Module* = 0) const { if (OS.stream()) print(*OS.stream()); } virtual void print(std::ostream &OS, const Module* = 0) const; diff --git a/include/llvm/Analysis/Trace.h b/include/llvm/Analysis/Trace.h index ad4f37c..b26101d 100644 --- a/include/llvm/Analysis/Trace.h +++ b/include/llvm/Analysis/Trace.h @@ -18,11 +18,11 @@ #ifndef LLVM_ANALYSIS_TRACE_H #define LLVM_ANALYSIS_TRACE_H +#include "llvm/Support/Streams.h" #include <vector> #include <cassert> namespace llvm { - class llvm_ostream; class BasicBlock; class Function; class Module; @@ -106,7 +106,7 @@ public: /// print - Write trace to output stream. /// - void print (llvm_ostream &O) const; + void print (OStream &O) const; /// dump - Debugger convenience method; writes trace to standard error /// output stream. diff --git a/include/llvm/Assembly/PrintModulePass.h b/include/llvm/Assembly/PrintModulePass.h index 770682d..cc9bca9 100644 --- a/include/llvm/Assembly/PrintModulePass.h +++ b/include/llvm/Assembly/PrintModulePass.h @@ -25,13 +25,12 @@ namespace llvm { class PrintModulePass : public ModulePass { - llvm_ostream *Out; // ostream to print on + OStream *Out; // ostream to print on bool DeleteStream; // Delete the ostream in our dtor? public: - PrintModulePass() : Out(&llvm_cerr), DeleteStream(false) {} - PrintModulePass(llvm_ostream *o, bool DS = false) - : Out(o), DeleteStream(DS) { - } + PrintModulePass() : Out(&cerr), DeleteStream(false) {} + PrintModulePass(OStream *o, bool DS = false) + : Out(o), DeleteStream(DS) {} ~PrintModulePass() { if (DeleteStream) delete Out; @@ -49,14 +48,13 @@ public: class PrintFunctionPass : public FunctionPass { std::string Banner; // String to print before each function - llvm_ostream *Out; // ostream to print on + OStream *Out; // ostream to print on bool DeleteStream; // Delete the ostream in our dtor? public: - PrintFunctionPass() : Banner(""), Out(&llvm_cerr), DeleteStream(false) {} - PrintFunctionPass(const std::string &B, llvm_ostream *o = &llvm_cout, + PrintFunctionPass() : Banner(""), Out(&cerr), DeleteStream(false) {} + PrintFunctionPass(const std::string &B, OStream *o = &cout, bool DS = false) - : Banner(B), Out(o), DeleteStream(DS) { - } + : Banner(B), Out(o), DeleteStream(DS) {} inline ~PrintFunctionPass() { if (DeleteStream) delete Out; diff --git a/include/llvm/Bytecode/WriteBytecodePass.h b/include/llvm/Bytecode/WriteBytecodePass.h index a634812..c4e2c5d 100644 --- a/include/llvm/Bytecode/WriteBytecodePass.h +++ b/include/llvm/Bytecode/WriteBytecodePass.h @@ -17,19 +17,18 @@ #include "llvm/Pass.h" #include "llvm/Bytecode/Writer.h" +#include "llvm/Support/Streams.h" namespace llvm { -class llvm_ostream; - class WriteBytecodePass : public ModulePass { - llvm_ostream *Out; // ostream to print on + OStream *Out; // ostream to print on bool DeleteStream; bool CompressFile; public: WriteBytecodePass() - : Out(&llvm_cout), DeleteStream(false), CompressFile(true) {} - WriteBytecodePass(llvm_ostream *o, bool DS = false, bool CF = true) + : Out(&cout), DeleteStream(false), CompressFile(true) {} + WriteBytecodePass(OStream *o, bool DS = false, bool CF = true) : Out(o), DeleteStream(DS), CompressFile(CF) {} inline ~WriteBytecodePass() { diff --git a/include/llvm/Bytecode/Writer.h b/include/llvm/Bytecode/Writer.h index 374e5df..c87cc92 100644 --- a/include/llvm/Bytecode/Writer.h +++ b/include/llvm/Bytecode/Writer.h @@ -15,13 +15,14 @@ #ifndef LLVM_BYTECODE_WRITER_H #define LLVM_BYTECODE_WRITER_H +#include "llvm/Support/Streams.h" + namespace llvm { - class llvm_ostream; class Module; /// WriteBytecodeToFile - Write the specified module to the specified output /// stream. If compress is set to true, try to use compression when writing /// out the file. This can never fail if M is a well-formed module. - void WriteBytecodeToFile(const Module *M, llvm_ostream &Out, + void WriteBytecodeToFile(const Module *M, OStream &Out, bool compress = true); } // End llvm namespace diff --git a/include/llvm/CodeGen/LiveInterval.h b/include/llvm/CodeGen/LiveInterval.h index 16fcd12..03a0f57 100644 --- a/include/llvm/CodeGen/LiveInterval.h +++ b/include/llvm/CodeGen/LiveInterval.h @@ -62,7 +62,7 @@ namespace llvm { }; std::ostream& operator<<(std::ostream& os, const LiveRange &LR); - inline llvm_ostream& operator<<(llvm_ostream& os, const LiveRange &LR) { + inline OStream& operator<<(OStream& os, const LiveRange &LR) { if (os.stream()) *os.stream() << LR; return os; } @@ -258,9 +258,9 @@ namespace llvm { return beginNumber() < other.beginNumber(); } - void print(llvm_ostream OS, const MRegisterInfo *MRI = 0) const; + void print(OStream OS, const MRegisterInfo *MRI = 0) const; void print(std::ostream &OS, const MRegisterInfo *MRI = 0) const { - print(llvm_ostream(OS), MRI); + print(OStream(OS), MRI); } void dump() const; @@ -271,7 +271,7 @@ namespace llvm { LiveInterval& operator=(const LiveInterval& rhs); // DO NOT IMPLEMENT }; - inline llvm_ostream &operator<<(llvm_ostream &OS, const LiveInterval &LI) { + inline OStream &operator<<(OStream &OS, const LiveInterval &LI) { LI.print(OS); return OS; } diff --git a/include/llvm/CodeGen/MachineBasicBlock.h b/include/llvm/CodeGen/MachineBasicBlock.h index f714c73..c848b06 100644 --- a/include/llvm/CodeGen/MachineBasicBlock.h +++ b/include/llvm/CodeGen/MachineBasicBlock.h @@ -189,7 +189,7 @@ public: // Debugging methods. void dump() const; - void print(llvm_ostream &OS) const { + void print(OStream &OS) const { if (OS.stream()) print(*OS.stream()); } void print(std::ostream &OS) const; @@ -226,7 +226,7 @@ private: // Methods used to maintain doubly linked list of blocks... }; std::ostream& operator<<(std::ostream &OS, const MachineBasicBlock &MBB); -inline llvm_ostream& operator<<(llvm_ostream &OS, const MachineBasicBlock &MBB){ +inline OStream& operator<<(OStream &OS, const MachineBasicBlock &MBB){ if (OS.stream()) *OS.stream() << MBB; return OS; } diff --git a/include/llvm/CodeGen/MachineConstantPool.h b/include/llvm/CodeGen/MachineConstantPool.h index 6bb2665..bc701f6 100644 --- a/include/llvm/CodeGen/MachineConstantPool.h +++ b/include/llvm/CodeGen/MachineConstantPool.h @@ -49,14 +49,14 @@ public: /// print - Implement operator<<... /// - void print(llvm_ostream &O) const { + void print(OStream &O) const { if (O.stream()) print(*O.stream()); } virtual void print(std::ostream &O) const = 0; }; -inline llvm_ostream &operator<<(llvm_ostream &OS, - const MachineConstantPoolValue &V) { +inline OStream &operator<<(OStream &OS, + const MachineConstantPoolValue &V) { V.print(OS); return OS; } @@ -143,7 +143,7 @@ public: /// print - Used by the MachineFunction printer to print information about /// constant pool objects. Implemented in MachineFunction.cpp /// - void print(llvm_ostream &OS) const { + void print(OStream &OS) const { if (OS.stream()) print(*OS.stream()); } void print(std::ostream &OS) const; diff --git a/include/llvm/CodeGen/MachineInstr.h b/include/llvm/CodeGen/MachineInstr.h index 2185d84..daa3974 100644 --- a/include/llvm/CodeGen/MachineInstr.h +++ b/include/llvm/CodeGen/MachineInstr.h @@ -285,7 +285,7 @@ public: IsDead = false; } - friend llvm_ostream& operator<<(llvm_ostream& os, const MachineOperand& mop) { + friend OStream& operator<<(OStream& os, const MachineOperand& mop) { if (os.stream()) *os.stream() << mop; return os; } @@ -397,12 +397,12 @@ public: // // Debugging support // - void print(llvm_ostream &OS, const TargetMachine *TM) const { + void print(OStream &OS, const TargetMachine *TM) const { if (OS.stream()) print(*OS.stream(), TM); } void print(std::ostream &OS, const TargetMachine *TM) const; void dump() const; - friend llvm_ostream& operator<<(llvm_ostream& os, const MachineInstr& minstr){ + friend OStream& operator<<(OStream& os, const MachineInstr& minstr){ if (os.stream()) *os.stream() << minstr; return os; } diff --git a/include/llvm/CodeGen/SchedGraphCommon.h b/include/llvm/CodeGen/SchedGraphCommon.h index b4cee96..7da2f73 100644 --- a/include/llvm/CodeGen/SchedGraphCommon.h +++ b/include/llvm/CodeGen/SchedGraphCommon.h @@ -70,7 +70,7 @@ public: void dump(int indent=0) const; // Debugging support - void print(llvm_ostream &os) const { + void print(OStream &os) const { if (os.stream()) print(*os.stream()); } virtual void print(std::ostream &os) const = 0; @@ -96,8 +96,8 @@ protected: }; // ostream << operator for SchedGraphNode class -inline llvm_ostream &operator<<(llvm_ostream &os, - const SchedGraphNodeCommon &node) { +inline OStream &operator<<(OStream &os, + const SchedGraphNodeCommon &node) { node.print(os); return os; } @@ -188,7 +188,7 @@ public: public: // Debugging support - void print(llvm_ostream &os) const { + void print(OStream &os) const { if (os.stream()) print(*os.stream()); } void print(std::ostream &os) const; @@ -200,7 +200,7 @@ private: }; // ostream << operator for SchedGraphNode class -inline llvm_ostream &operator<<(llvm_ostream &os, const SchedGraphEdge &edge) { +inline OStream &operator<<(OStream &os, const SchedGraphEdge &edge) { edge.print(os); return os; } diff --git a/include/llvm/Module.h b/include/llvm/Module.h index 4cb6d27..35b04b1 100644 --- a/include/llvm/Module.h +++ b/include/llvm/Module.h @@ -295,12 +295,12 @@ public: /// @{ public: /// Print the module to an output stream - void print(llvm_ostream &OS) const { + void print(OStream &OS) const { if (OS.stream()) print(*OS.stream(), 0); } void print(std::ostream &OS) const { print(OS, 0); } /// Print the module to an output stream with AssemblyAnnotationWriter. - void print(llvm_ostream &OS, AssemblyAnnotationWriter *AAW) const { + void print(OStream &OS, AssemblyAnnotationWriter *AAW) const { if (OS.stream()) print(*OS.stream(), AAW); } void print(std::ostream &OS, AssemblyAnnotationWriter *AAW) const; diff --git a/include/llvm/Pass.h b/include/llvm/Pass.h index 30f1df9..4a929f0 100644 --- a/include/llvm/Pass.h +++ b/include/llvm/Pass.h @@ -101,7 +101,7 @@ public: /// provide the Module* in case the analysis doesn't need it it can just be /// ignored. /// - void print(llvm_ostream &O, const Module *M) const { + void print(OStream &O, const Module *M) const { if (O.stream()) print(*O.stream(), M); } virtual void print(std::ostream &O, const Module *M) const; diff --git a/include/llvm/Support/Casting.h b/include/llvm/Support/Casting.h index fff44f6..dc31839 100644 --- a/include/llvm/Support/Casting.h +++ b/include/llvm/Support/Casting.h @@ -245,13 +245,13 @@ private: struct foo { void ext() const; /* static bool classof(const bar *X) { - llvm_cerr << "Classof: " << X << "\n"; + cerr << "Classof: " << X << "\n"; return true; }*/ }; template <> inline bool isa_impl<foo,bar>(const bar &Val) { - llvm_cerr << "Classof: " << &Val << "\n"; + cerr << "Classof: " << &Val << "\n"; return true; } diff --git a/include/llvm/Support/ConstantRange.h b/include/llvm/Support/ConstantRange.h index 90a2990..6866ffe 100644 --- a/include/llvm/Support/ConstantRange.h +++ b/include/llvm/Support/ConstantRange.h @@ -141,7 +141,7 @@ class ConstantRange { /// print - Print out the bounds to a stream... /// - void print(llvm_ostream &OS) const { + void print(OStream &OS) const { if (OS.stream()) print(*OS.stream()); } void print(std::ostream &OS) const; diff --git a/include/llvm/Support/Debug.h b/include/llvm/Support/Debug.h index 9f0f161..09878b9 100644 --- a/include/llvm/Support/Debug.h +++ b/include/llvm/Support/Debug.h @@ -65,10 +65,10 @@ bool isCurrentDebugType(const char *Type); /// places the std::c* I/O streams into one .cpp file and relieves the whole /// program from having to have hundreds of static c'tor/d'tors for them. /// -llvm_ostream getErrorOutputStream(const char *DebugType); +OStream getErrorOutputStream(const char *DebugType); #ifdef NDEBUG -#define DOUT llvm_ostream() +#define DOUT NullStream #else #define DOUT getErrorOutputStream(DEBUG_TYPE) #endif diff --git a/include/llvm/Support/GraphWriter.h b/include/llvm/Support/GraphWriter.h index 8602e74..b9566b8 100644 --- a/include/llvm/Support/GraphWriter.h +++ b/include/llvm/Support/GraphWriter.h @@ -247,16 +247,16 @@ sys::Path WriteGraph(const GraphType &G, std::string ErrMsg; sys::Path Filename = sys::Path::GetTemporaryDirectory(&ErrMsg); if (Filename.isEmpty()) { - llvm_cerr << "Error: " << ErrMsg << "\n"; + cerr << "Error: " << ErrMsg << "\n"; return Filename; } Filename.appendComponent(Name + ".dot"); if (Filename.makeUnique(true,&ErrMsg)) { - llvm_cerr << "Error: " << ErrMsg << "\n"; + cerr << "Error: " << ErrMsg << "\n"; return sys::Path(); } - llvm_cerr << "Writing '" << Filename << "'... "; + cerr << "Writing '" << Filename << "'... "; std::ofstream O(Filename.c_str()); @@ -275,12 +275,12 @@ sys::Path WriteGraph(const GraphType &G, // Output the end of the graph W.writeFooter(); - llvm_cerr << " done. \n"; + cerr << " done. \n"; O.close(); } else { - llvm_cerr << "error opening file for writing!\n"; + cerr << "error opening file for writing!\n"; Filename.clear(); } diff --git a/include/llvm/Support/PassNameParser.h b/include/llvm/Support/PassNameParser.h index fef63c3..83653aa 100644 --- a/include/llvm/Support/PassNameParser.h +++ b/include/llvm/Support/PassNameParser.h @@ -65,8 +65,8 @@ public: virtual void passRegistered(const PassInfo *P) { if (ignorablePass(P) || !Opt) return; if (findOption(P->getPassArgument()) != getNumOptions()) { - llvm_cerr << "Two passes with the same argument (-" - << P->getPassArgument() << ") attempted to be registered!\n"; + cerr << "Two passes with the same argument (-" + << P->getPassArgument() << ") attempted to be registered!\n"; abort(); } addLiteralOption(P->getPassArgument(), P, P->getPassName()); diff --git a/include/llvm/Support/Streams.h b/include/llvm/Support/Streams.h index a422756..c4afc86 100644 --- a/include/llvm/Support/Streams.h +++ b/include/llvm/Support/Streams.h @@ -7,48 +7,64 @@ // //===----------------------------------------------------------------------===// // -// This file implements a wrapper for the std::cout and std::cerr I/O streams. -// It prevents the need to include <iostream> to each file just to get I/O. +// This file implements a wrapper for the STL I/O streams. It prevents the need +// to include <iostream> in a file just to get I/O. // //===----------------------------------------------------------------------===// #ifndef LLVM_SUPPORT_STREAMS_H #define LLVM_SUPPORT_STREAMS_H -#include <ostream> // Doesn't have static d'tors!! +#include <sstream> namespace llvm { - /// llvm_ostream - Acts like an ostream. It's a wrapper for the std::cerr and - /// std::cout ostreams. However, it doesn't require #including <iostream> in - /// every file, which increases static c'tors & d'tors in the object code. + /// BaseStream - Acts like the STL streams. It's a wrapper for the std::cerr, + /// std::cout, std::cin, etc. streams. However, it doesn't require #including + /// <iostream> in every file (doing so increases static c'tors & d'tors in the + /// object code). /// - class llvm_ostream { - std::ostream* Stream; + template <typename StreamTy> + class BaseStream { + StreamTy *Stream; public: - llvm_ostream() : Stream(0) {} - llvm_ostream(std::ostream &OStream) : Stream(&OStream) {} + BaseStream() : Stream(0) {} + BaseStream(StreamTy &S) : Stream(&S) {} + BaseStream(StreamTy *S) : Stream(S) {} - std::ostream* stream() const { return Stream; } + StreamTy *stream() const { return Stream; } - inline llvm_ostream &operator << (std::ostream& (*Func)(std::ostream&)) { + inline BaseStream &operator << (StreamTy &(*Func)(StreamTy&)) { if (Stream) *Stream << Func; return *this; } - + template <typename Ty> - llvm_ostream &operator << (const Ty &Thing) { + BaseStream &operator << (const Ty &Thing) { if (Stream) *Stream << Thing; return *this; } - bool operator == (const std::ostream &OS) { return &OS == Stream; } - bool operator == (const llvm_ostream &OS) { return OS.Stream == Stream; } + template <typename Ty> + BaseStream &operator >> (const Ty &Thing) { + if (Stream) *Stream >> Thing; + return *this; + } + + bool operator == (const StreamTy &S) { return &S == Stream; } + bool operator != (const StreamTy &S) { return !(*this == S); } + bool operator == (const BaseStream &S) { return S.Stream == Stream; } + bool operator != (const BaseStream &S) { return !(*this == S); } }; - extern llvm_ostream llvm_null; - extern llvm_ostream llvm_cout; - extern llvm_ostream llvm_cerr; + typedef BaseStream<std::ostream> OStream; + typedef BaseStream<std::istream> IStream; + typedef BaseStream<std::stringstream> StringStream; + + extern OStream NullStream; + extern OStream cout; + extern OStream cerr; + extern IStream cin; } // End llvm namespace diff --git a/include/llvm/Type.h b/include/llvm/Type.h index a69e751..4da8feb 100644 --- a/include/llvm/Type.h +++ b/include/llvm/Type.h @@ -136,7 +136,7 @@ protected: /// mutable std::vector<AbstractTypeUser *> AbstractTypeUsers; public: - void print(llvm_ostream &O) const { + void print(OStream &O) const { if (O.stream()) print(*O.stream()); } void print(std::ostream &O) const; diff --git a/include/llvm/Value.h b/include/llvm/Value.h index 5dfe63f..e8df7cd 100644 --- a/include/llvm/Value.h +++ b/include/llvm/Value.h @@ -75,7 +75,7 @@ public: /// print - Implement operator<< on Value... /// - void print(llvm_ostream &O) const { + void print(OStream &O) const { if (O.stream()) print(*O.stream()); } virtual void print(std::ostream &O) const = 0; |