Mercurial > projects > ldc
comparison gen/logger.cpp @ 994:18ad5601dff7
Use LLVM OStream wrapper instead of <iostream> in the logger.
llvm::OStream provides all std::ostream functionality (by holding a
std::ostream* internally), but
* doesn't include <iostream>, avoiding per-file overhead.
* allows the stream pointer to be null, and the (inlined) operators do nothing
when that's the case. (This also allows removal of the ofstream("/dev/null")
hack Logger used when disabled, which presumably wasn't very portable)
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Thu, 26 Feb 2009 14:51:02 +0100 |
parents | a8cb25d478c4 |
children | e7f0c2b48047 |
comparison
equal
deleted
inserted
replaced
993:27956b440c0a | 994:18ad5601dff7 |
---|---|
1 #include <cassert> | 1 #include <cassert> |
2 #include <cstdarg> | 2 #include <cstdarg> |
3 #include <cstdio> | 3 #include <cstdio> |
4 #include <cstdlib> | 4 #include <cstdlib> |
5 #include <iostream> | |
6 #include <fstream> | 5 #include <fstream> |
7 #include <string> | 6 #include <string> |
8 | 7 |
9 #include "mars.h" | 8 #include "mars.h" |
10 | 9 |
12 #include "gen/logger.h" | 11 #include "gen/logger.h" |
13 | 12 |
14 namespace Logger | 13 namespace Logger |
15 { | 14 { |
16 static std::string indent_str; | 15 static std::string indent_str; |
17 static std::ofstream null_out("/dev/null"); | |
18 | 16 |
19 llvm::cl::opt<bool> _enabled("vv", | 17 llvm::cl::opt<bool> _enabled("vv", |
20 llvm::cl::desc("Very verbose"), | 18 llvm::cl::desc("Very verbose"), |
21 llvm::cl::ZeroOrMore); | 19 llvm::cl::ZeroOrMore); |
22 | 20 |
31 if (_enabled) { | 29 if (_enabled) { |
32 assert(!indent_str.empty()); | 30 assert(!indent_str.empty()); |
33 indent_str.resize(indent_str.size()-2); | 31 indent_str.resize(indent_str.size()-2); |
34 } | 32 } |
35 } | 33 } |
36 std::ostream& cout() | 34 llvm::OStream cout() |
37 { | 35 { |
38 if (_enabled) | 36 if (_enabled) |
39 return std::cout << indent_str; | 37 return llvm::cout << indent_str; |
40 else | 38 else |
41 return null_out; | 39 return 0; |
42 } | 40 } |
43 void println(const char* fmt,...) | 41 void println(const char* fmt,...) |
44 { | 42 { |
45 if (_enabled) { | 43 if (_enabled) { |
46 printf("%s", indent_str.c_str()); | 44 printf("%s", indent_str.c_str()); |