llvm.org GIT mirror llvm / a93117c
This reverts commit r234460 and r234461. Revert "Add classof implementations to the raw_ostream classes." Revert "Use the cast machinery to remove dummy uses of formatted_raw_ostream." The underlying issue can be fixed without classof. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234495 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
14 changed file(s) with 52 addition(s) and 87 deletion(s). Raw diff Collapse all Expand all
139139 uint64_t current_pos() const override { return Count; }
140140
141141 public:
142 raw_counting_ostream() : raw_ostream(SK_COUNTING), Count(0) {}
142 raw_counting_ostream() : Count(0) {}
143143 ~raw_counting_ostream() { flush(); }
144
145 static bool classof(const raw_ostream *OS) {
146 return OS->getKind() == SK_COUNTING;
147 }
148144 };
149145
150146 raw_counting_ostream OutStream;
8383 /// so it doesn't want another layer of buffering to be happening
8484 /// underneath it.
8585 ///
86 formatted_raw_ostream(raw_ostream &Stream, bool Delete = false)
87 : raw_ostream(SK_FORMATTED), TheStream(nullptr), DeleteStream(false),
88 Position(0, 0) {
86 formatted_raw_ostream(raw_ostream &Stream, bool Delete = false)
87 : raw_ostream(), TheStream(nullptr), DeleteStream(false), Position(0, 0) {
8988 setStream(Stream, Delete);
9089 }
9190 explicit formatted_raw_ostream()
92 : raw_ostream(SK_FORMATTED), TheStream(nullptr), DeleteStream(false),
93 Position(0, 0) {
91 : raw_ostream(), TheStream(nullptr), DeleteStream(false), Position(0, 0) {
9492 Scanned = nullptr;
95 }
96
97 static bool classof(const raw_ostream *OS) {
98 return OS->getKind() == SK_FORMATTED;
9993 }
10094
10195 ~formatted_raw_ostream() {
106106 /// management of it, etc.
107107 ///
108108 circular_raw_ostream(raw_ostream &Stream, const char *Header,
109 size_t BuffSize = 0, bool Owns = REFERENCE_ONLY)
110 : raw_ostream(SK_CIRCULAR, /*unbuffered*/ true), TheStream(nullptr),
111 OwnsStream(Owns), BufferSize(BuffSize), BufferArray(nullptr),
112 Filled(false), Banner(Header) {
109 size_t BuffSize = 0, bool Owns = REFERENCE_ONLY)
110 : raw_ostream(/*unbuffered*/true),
111 TheStream(nullptr),
112 OwnsStream(Owns),
113 BufferSize(BuffSize),
114 BufferArray(nullptr),
115 Filled(false),
116 Banner(Header) {
113117 if (BufferSize != 0)
114118 BufferArray = new char[BufferSize];
115119 Cur = BufferArray;
139143 ///
140144 void flushBufferWithBanner();
141145
142 static bool classof(const raw_ostream *OS) {
143 return OS->getKind() == SK_CIRCULAR;
144 }
145
146146 private:
147147 /// releaseStream - Delete the held stream if needed. Otherwise,
148148 /// transfer the buffer settings from this circular_raw_ostream
3232 uint64_t current_pos() const override;
3333
3434 public:
35 raw_os_ostream(std::ostream &O) : raw_ostream(SK_STD_OS), OS(O) {}
35 raw_os_ostream(std::ostream &O) : OS(O) {}
3636 ~raw_os_ostream();
37 static bool classof(const raw_ostream *OS) {
38 return OS->getKind() == SK_STD_OS;
39 }
4037 };
4138
4239 } // end llvm namespace
1515
1616 #include "llvm/ADT/SmallVector.h"
1717 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/Casting.h"
1918 #include "llvm/Support/DataTypes.h"
2019 #include
2120
6766 } BufferMode;
6867
6968 public:
70 enum StreamKind {
71 SK_FD,
72 SK_STRING,
73 SK_SVECTOR,
74 SK_NULL,
75 SK_STD_OS,
76 SK_CIRCULAR,
77 SK_FORMATTED,
78 SK_COUNTING
79 };
80
8169 // color order matches ANSI escape sequence, don't change
8270 enum Colors {
8371 BLACK=0,
9179 SAVEDCOLOR
9280 };
9381
94 explicit raw_ostream(StreamKind Kind, bool unbuffered = false)
95 : BufferMode(unbuffered ? Unbuffered : InternalBuffer), Kind(Kind) {
82 explicit raw_ostream(bool unbuffered=false)
83 : BufferMode(unbuffered ? Unbuffered : InternalBuffer) {
9684 // Start out ready to flush.
9785 OutBufStart = OutBufEnd = OutBufCur = nullptr;
9886 }
270258 // Subclass Interface
271259 //===--------------------------------------------------------------------===//
272260
273 StreamKind getKind() const { return Kind; }
274
275261 private:
276 StreamKind Kind;
277262 /// The is the piece of the class that is implemented by subclasses. This
278263 /// writes the \p Size bytes starting at
279264 /// \p Ptr to the underlying stream.
378363 /// this closes the file when the stream is destroyed.
379364 raw_fd_ostream(int fd, bool shouldClose, bool unbuffered=false);
380365
381 static bool classof(const raw_ostream *OS) { return OS->getKind() == SK_FD; }
382
383366 ~raw_fd_ostream();
384367
385368 /// Manually flush the stream and close the file. Note that this does not call
459442 /// currently in the buffer.
460443 uint64_t current_pos() const override { return OS.size(); }
461444 public:
462 explicit raw_string_ostream(std::string &O) : raw_ostream(SK_STRING), OS(O) {}
445 explicit raw_string_ostream(std::string &O) : OS(O) {}
463446 ~raw_string_ostream();
464
465 static bool classof(const raw_ostream *OS) {
466 return OS->getKind() == SK_STRING;
467 }
468447
469448 /// Flushes the stream contents to the target string and returns the string's
470449 /// reference.
493472 explicit raw_svector_ostream(SmallVectorImpl &O);
494473 ~raw_svector_ostream();
495474
496 static bool classof(const raw_ostream *OS) {
497 return OS->getKind() == SK_SVECTOR;
498 }
499
500475 /// This is called when the SmallVector we're appending to is changed outside
501476 /// of the raw_svector_ostream's control. It is only safe to do this if the
502477 /// raw_svector_ostream has previously been flushed.
517492 uint64_t current_pos() const override;
518493
519494 public:
520 explicit raw_null_ostream() : raw_ostream(SK_NULL) {}
495 explicit raw_null_ostream() {}
521496 ~raw_null_ostream();
522 static bool classof(const raw_ostream *OS) {
523 return OS->getKind() == SK_NULL;
524 }
525497 };
526498
527499 } // end llvm namespace
206206 /// emitted. Typically this will involve several steps of code generation.
207207 /// This method should return true if emission of this file type is not
208208 /// supported, or false on success.
209 /// If producing assembly, the stream must be a formatted_raw_ostream.
210 /// For other formats any raw_ostream will do.
211 virtual bool addPassesToEmitFile(PassManagerBase &, raw_ostream &,
209 virtual bool addPassesToEmitFile(PassManagerBase &,
210 formatted_raw_ostream &,
212211 CodeGenFileType,
213212 bool /*DisableVerify*/ = true,
214213 AnalysisID /*StartAfter*/ = nullptr,
255254 /// for generating a pipeline of CodeGen passes.
256255 virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);
257256
258 bool addPassesToEmitFile(PassManagerBase &PM, raw_ostream &Out,
257 /// Add passes to the specified pass manager to get the specified file
258 /// emitted. Typically this will involve several steps of code generation.
259 bool addPassesToEmitFile(PassManagerBase &PM, formatted_raw_ostream &Out,
259260 CodeGenFileType FileType, bool DisableVerify = true,
260261 AnalysisID StartAfter = nullptr,
261262 AnalysisID StopAfter = nullptr) override;
139139 return &MMI->getContext();
140140 }
141141
142 bool LLVMTargetMachine::addPassesToEmitFile(
143 PassManagerBase &PM, raw_ostream &Out, CodeGenFileType FileType,
144 bool DisableVerify, AnalysisID StartAfter, AnalysisID StopAfter) {
142 bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
143 formatted_raw_ostream &Out,
144 CodeGenFileType FileType,
145 bool DisableVerify,
146 AnalysisID StartAfter,
147 AnalysisID StopAfter) {
145148 // Add common CodeGen passes.
146149 MCContext *Context = addPassesToGenerateCode(this, PM, DisableVerify,
147150 StartAfter, StopAfter);
181184 MCAsmBackend *MAB = getTarget().createMCAsmBackend(MRI, getTargetTriple(),
182185 TargetCPU);
183186 MCStreamer *S = getTarget().createAsmStreamer(
184 *Context, cast(Out),
185 Options.MCOptions.AsmVerbose, Options.MCOptions.MCUseDwarfDirectory,
186 InstPrinter, MCE, MAB, Options.MCOptions.ShowMCInst);
187 *Context, Out, Options.MCOptions.AsmVerbose,
188 Options.MCOptions.MCUseDwarfDirectory, InstPrinter, MCE, MAB,
189 Options.MCOptions.ShowMCInst);
187190 AsmStreamer.reset(S);
188191 break;
189192 }
3737 #include "llvm/MC/SubtargetFeature.h"
3838 #include "llvm/Support/CommandLine.h"
3939 #include "llvm/Support/FileSystem.h"
40 #include "llvm/Support/FormattedStream.h"
4041 #include "llvm/Support/Host.h"
4142 #include "llvm/Support/MemoryBuffer.h"
4243 #include "llvm/Support/Signals.h"
572573
573574 legacy::PassManager codeGenPasses;
574575
576 formatted_raw_ostream Out(out);
577
575578 // If the bitcode files contain ARC code and were compiled with optimization,
576579 // the ObjCARCContractPass must be run, so do it unconditionally here.
577580 codeGenPasses.add(createObjCARCContractPass());
578581
579 if (TargetMach->addPassesToEmitFile(codeGenPasses, out,
582 if (TargetMach->addPassesToEmitFile(codeGenPasses, Out,
580583 TargetMachine::CGFT_ObjectFile)) {
581584 errMsg = "target file type not supported";
582585 return false;
113113 // know that debug mode is enabled and dbgs() really is a
114114 // circular_raw_ostream. If NDEBUG is defined, then dbgs() ==
115115 // errs() but this will never be invoked.
116 llvm::circular_raw_ostream &dbgout = cast(llvm::dbgs());
117 dbgout.flushBufferWithBanner();
116 llvm::circular_raw_ostream *dbgout =
117 static_cast(&llvm::dbgs());
118 dbgout->flushBufferWithBanner();
118119 }
119120
120121 /// dbgs - Return a circular-buffered debug stream.
488488
489489 raw_fd_ostream::raw_fd_ostream(StringRef Filename, std::error_code &EC,
490490 sys::fs::OpenFlags Flags)
491 : raw_ostream(SK_FD), Error(false), UseAtomicWrites(false), pos(0) {
491 : Error(false), UseAtomicWrites(false), pos(0) {
492492 EC = std::error_code();
493493 // Handle "-" as stdout. Note that when we do this, we consider ourself
494494 // the owner of stdout. This means that we can do things like close the
518518 /// raw_fd_ostream ctor - FD is the file descriptor that this writes to. If
519519 /// ShouldClose is true, this closes the file when the stream is destroyed.
520520 raw_fd_ostream::raw_fd_ostream(int fd, bool shouldClose, bool unbuffered)
521 : raw_ostream(SK_FD, unbuffered), FD(fd), ShouldClose(shouldClose),
522 Error(false), UseAtomicWrites(false) {
521 : raw_ostream(unbuffered), FD(fd),
522 ShouldClose(shouldClose), Error(false), UseAtomicWrites(false) {
523523 #ifdef O_BINARY
524524 // Setting STDOUT to binary mode is necessary in Win32
525525 // to avoid undesirable linefeed conversion.
748748 // capacity. This allows raw_ostream to write directly into the correct place,
749749 // and we only need to set the vector size when the data is flushed.
750750
751 raw_svector_ostream::raw_svector_ostream(SmallVectorImpl &O)
752 : raw_ostream(SK_SVECTOR), OS(O) {
751 raw_svector_ostream::raw_svector_ostream(SmallVectorImpl &O) : OS(O) {
753752 // Set up the initial external buffer. We make sure that the buffer has at
754753 // least 128 bytes free; raw_ostream itself only requires 64, but we want to
755754 // make sure that we don't grow the buffer unnecessarily on destruction (when
21452145 // External Interface declaration
21462146 //===----------------------------------------------------------------------===//
21472147
2148 bool CPPTargetMachine::addPassesToEmitFile(PassManagerBase &PM, raw_ostream &o,
2148 bool CPPTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
2149 formatted_raw_ostream &o,
21492150 CodeGenFileType FileType,
21502151 bool DisableVerify,
21512152 AnalysisID StartAfter,
21522153 AnalysisID StopAfter) {
2153 if (FileType != TargetMachine::CGFT_AssemblyFile)
2154 return true;
2155 PM.add(new CppWriter(cast(o)));
2154 if (FileType != TargetMachine::CGFT_AssemblyFile) return true;
2155 PM.add(new CppWriter(o));
21562156 return false;
21572157 }
2828 : TargetMachine(T, "", TT, CPU, FS, Options) {}
2929
3030 public:
31 bool addPassesToEmitFile(PassManagerBase &PM, raw_ostream &Out,
31 bool addPassesToEmitFile(PassManagerBase &PM, formatted_raw_ostream &Out,
3232 CodeGenFileType FileType, bool DisableVerify,
3333 AnalysisID StartAfter,
3434 AnalysisID StopAfter) override;
182182 }
183183
184184 static LLVMBool LLVMTargetMachineEmit(LLVMTargetMachineRef T, LLVMModuleRef M,
185 raw_ostream &OS,
186 LLVMCodeGenFileType codegen,
187 char **ErrorMessage) {
185 formatted_raw_ostream &OS, LLVMCodeGenFileType codegen, char **ErrorMessage) {
188186 TargetMachine* TM = unwrap(T);
189187 Module* Mod = unwrap(M);
190188
3030 #include "llvm/Linker/Linker.h"
3131 #include "llvm/MC/SubtargetFeature.h"
3232 #include "llvm/Object/IRObjectFile.h"
33 #include "llvm/Support/raw_ostream.h"
33 #include "llvm/Support/FormattedStream.h"
3434 #include "llvm/Support/Host.h"
3535 #include "llvm/Support/ManagedStatic.h"
3636 #include "llvm/Support/MemoryBuffer.h"
803803
804804 {
805805 raw_fd_ostream OS(FD, true);
806
807 if (TM->addPassesToEmitFile(CodeGenPasses, OS,
806 formatted_raw_ostream FOS(OS);
807
808 if (TM->addPassesToEmitFile(CodeGenPasses, FOS,
808809 TargetMachine::CGFT_ObjectFile))
809810 message(LDPL_FATAL, "Failed to setup codegen");
810811 CodeGenPasses.run(M);