[llvm-commits] [LLVMdev] [PATCH] Allow per-thread re-direction of outs()/errs()

Chris Lattner clattner at apple.com
Sun Jun 3 12:12:06 PDT 2012


On Jun 2, 2012, at 11:01 AM, Mikael Lyngvig wrote:

> If I may add my two cents: 
> 
> I am planning to use LLVM as the backend for a compiler I am working on.  And I wholeheartedly agree with Justin that it is a problem, if LLVM is allowed to freely write to stdout and stderr as it is a component which can be used in all sorts of code, be it a GUI IDE, a CLI driver, or whatever.

LLVM should not be doing this.

> Also, I have a number of times wondered about the somewhat unusual use of error strings in LLVM (that you pass in a string, which can be assigned a descriptive error message).  Better would be, IMHO, to provide an interface along the lines of this:
> 
> class ErrorHandler
> {
> public:
>         virtual void Report(ErrorKind kind, uint code, const Position &position, const unichar *text, ...) = 0;
> };
> 
> And then let the client, i.e. the frontend, derive from it and handle all the output in whichever way it wants to.  The above example is probably too complex for LLVM, but that's what I use in my compiler.  ErrorKind is ErrorKind_Fatal, ErrorKind_Error, etc.  Position is simply a filename, a line number, and a character position.  unichar is either char or wchar_t, depending on the build mode and target environment.

You're right, this would be better.  We have even already have it :)

  llvm/Support/ErrorHandling.h

-Chris




More information about the llvm-commits mailing list