Mercurial > projects > ldc
diff gen/logger.cpp @ 1502:2292878925f4
Add an `llvm::OStream` workalike class for use with `Logger::cout()`, with the
crucial difference being special handling of `llvm::Type`s so they get printed
by name rather than printing their full representation (which can be positively
*huge*).
This allows re-enabling some logger calls that were disabled due to extreme
verbosity.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Tue, 16 Jun 2009 19:31:10 +0200 |
parents | e7f0c2b48047 |
children | 40bd4a0d4870 |
line wrap: on
line diff
--- a/gen/logger.cpp Tue Jun 16 15:37:40 2009 +0200 +++ b/gen/logger.cpp Tue Jun 16 19:31:10 2009 +0200 @@ -4,11 +4,34 @@ #include <cstdlib> #include <fstream> #include <string> +#include <iostream> #include "mars.h" #include "llvm/Support/CommandLine.h" + +#include "llvm/GlobalValue.h" +#include "llvm/Support/Casting.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Assembly/Writer.h" + #include "gen/logger.h" +#include "gen/irstate.h" + +void Stream::writeType(std::ostream& OS, const llvm::Type& Ty) { + llvm::raw_os_ostream raw(OS); + llvm::WriteTypeSymbolic(raw, &Ty, gIR->module); +} + +void Stream::writeValue(std::ostream& OS, const llvm::Value& V) { + // Constants don't always get their types pretty-printed. + // (Only treat non-global constants like this, so that e.g. global variables + // still get their initializers printed) + if (llvm::isa<llvm::Constant>(V) && !llvm::isa<llvm::GlobalValue>(V)) + llvm::WriteAsOperand(OS, &V, true, gIR->module); + else + OS << V; +} namespace Logger { @@ -31,10 +54,10 @@ indent_str.resize(indent_str.size()-2); } } - llvm::OStream cout() + Stream cout() { if (_enabled) - return llvm::cout << indent_str; + return std::cout << indent_str; else return 0; }