<div class="gmail_quote">On Thu, May 31, 2012 at 10:21 PM, Justin Holewinski <span dir="ltr"><<a href="mailto:justin.holewinski@gmail.com" target="_blank">justin.holewinski@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="gmail_quote"><div class="im">On Thu, May 31, 2012 at 8:06 PM, Chris Lattner <span dir="ltr"><<a href="mailto:clattner@apple.com" target="_blank">clattner@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div><br>
On May 31, 2012, at 2:39 PM, Justin Holewinski wrote:<br>
<br>
> The attached patch add the ability to programmatically re-direct outs()/errs() to an arbitrary raw_ostream instance, maintaining the raw_ostream instances in a stack structure so clients can push/pop streams at will.  The stack is also maintained in thread-local storage, so different threads can re-direct individually.  This allows for two use cases:<br>


><br>
> 1. Compilers can attach custom streams to outs()/errs() to intercept output from LLVM without needing to play with STDOUT/STDERR.<br>
> 2. Compilers can receive LLVM output from different threads individually, instead of having all diagnostics dumped to a single stream.<br>
<br>
</div>This isn't the right approach.  Nothing in the library part of the compiler should be hard coding a stream to write to.  What are you trying to accomplish?<br></blockquote><div><br></div></div><div>There are a lot of places where warning/debug information is passed directly to errs().  For example, take the Linker class.  You can tell it to omit errors/warnings, but it would be preferable to let it emit the errors/warnings to some compiler-controlled stream for message triaging.</div>

<div><br></div><div>For compilers that are (a) multi-threaded, or (b) invoked as part of an embedded library, writing any information from the core libraries directly to stderr is bad.  I want to be able to capture this output without messing with the process' stdout/stderr streams.</div>

<div><br></div><div>This patch essentially prevents LLVM library code from having to hard-code streams for error/warning/diagnostic output.  Library code can just use outs()/errs() as they do now, but the compiler process/thread now has the ability to re-direct this output as it sees fit. If no such functionality is needed, the default behavior is to write to stdout/stderr as it does now.</div>
</div></blockquote><div><br></div><div>Perhaps I'm just getting the wrong impression from the current LLVM code base.  Take this snippet from LinkModules.cpp:</div><div><br></div><div><div><font face="courier new, monospace">  if (!SrcM->getDataLayout().empty() && !DstM->getDataLayout().empty() &&</font></div>
<div><font face="courier new, monospace">      SrcM->getDataLayout() != DstM->getDataLayout())</font></div><div><font face="courier new, monospace">    errs() << "WARNING: Linking two modules of different data layouts!\n";</font></div>
<div><font face="courier new, monospace">  if (!SrcM->getTargetTriple().empty() &&</font></div><div><font face="courier new, monospace">      DstM->getTargetTriple() != SrcM->getTargetTriple()) {</font></div>
<div><font face="courier new, monospace">    errs() << "WARNING: Linking two modules of different target triples: ";</font></div><div><font face="courier new, monospace">    if (!SrcM->getModuleIdentifier().empty())</font></div>
<div><font face="courier new, monospace">      errs() << SrcM->getModuleIdentifier() << ": ";</font></div><div><font face="courier new, monospace">    errs() << "'" << SrcM->getTargetTriple() << "' and '"</font></div>
<div><font face="courier new, monospace">           << DstM->getTargetTriple() << "'\n";</font></div><div><font face="courier new, monospace">  }</font></div></div><div><br></div><div>Would I be correct in assuming that this is actually "bad" code since it's a library function that writes directly to stderr?</div>
<div><br></div><div>Is the recommended approach to pass a stream to the constructor of any pass or function that wants to emit output outside of debug mode?  My concern with this approach is that the compiler would then need to know which passes expect an output stream, and which do not.  The supplied patch allows passes to output information without having to worry about where the output is going, it is up to the compiler to specify where this output goes.  </div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><div class="im">
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
-Chris<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><br><div>Thanks,</div><div><br></div><div>Justin Holewinski</div><br>
</font></span></blockquote></div><br><br clear="all"><div><br></div>-- <br><br><div>Thanks,</div><div><br></div><div>Justin Holewinski</div><br>