comparison 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
comparison
equal deleted inserted replaced
1501:8b9f236dd051 1502:2292878925f4
2 #include <cstdarg> 2 #include <cstdarg>
3 #include <cstdio> 3 #include <cstdio>
4 #include <cstdlib> 4 #include <cstdlib>
5 #include <fstream> 5 #include <fstream>
6 #include <string> 6 #include <string>
7 #include <iostream>
7 8
8 #include "mars.h" 9 #include "mars.h"
9 10
10 #include "llvm/Support/CommandLine.h" 11 #include "llvm/Support/CommandLine.h"
12
13 #include "llvm/GlobalValue.h"
14 #include "llvm/Support/Casting.h"
15 #include "llvm/Support/raw_ostream.h"
16 #include "llvm/Assembly/Writer.h"
17
11 #include "gen/logger.h" 18 #include "gen/logger.h"
19 #include "gen/irstate.h"
20
21 void Stream::writeType(std::ostream& OS, const llvm::Type& Ty) {
22 llvm::raw_os_ostream raw(OS);
23 llvm::WriteTypeSymbolic(raw, &Ty, gIR->module);
24 }
25
26 void Stream::writeValue(std::ostream& OS, const llvm::Value& V) {
27 // Constants don't always get their types pretty-printed.
28 // (Only treat non-global constants like this, so that e.g. global variables
29 // still get their initializers printed)
30 if (llvm::isa<llvm::Constant>(V) && !llvm::isa<llvm::GlobalValue>(V))
31 llvm::WriteAsOperand(OS, &V, true, gIR->module);
32 else
33 OS << V;
34 }
12 35
13 namespace Logger 36 namespace Logger
14 { 37 {
15 static std::string indent_str; 38 static std::string indent_str;
16 39
29 if (_enabled) { 52 if (_enabled) {
30 assert(!indent_str.empty()); 53 assert(!indent_str.empty());
31 indent_str.resize(indent_str.size()-2); 54 indent_str.resize(indent_str.size()-2);
32 } 55 }
33 } 56 }
34 llvm::OStream cout() 57 Stream cout()
35 { 58 {
36 if (_enabled) 59 if (_enabled)
37 return llvm::cout << indent_str; 60 return std::cout << indent_str;
38 else 61 else
39 return 0; 62 return 0;
40 } 63 }
41 void println(const char* fmt,...) 64 void println(const char* fmt,...)
42 { 65 {