changeset 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 27956b440c0a
children 125c09006ac6
files gen/asmstmt.cpp gen/dwarftypes.cpp gen/linker.cpp gen/llvmhelpers.cpp gen/logger.cpp gen/logger.h gen/statements.cpp gen/toir.cpp gen/tollvm.cpp gen/toobj.cpp
diffstat 10 files changed, 19 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/gen/asmstmt.cpp	Thu Feb 26 15:24:20 2009 +0100
+++ b/gen/asmstmt.cpp	Thu Feb 26 14:51:02 2009 +0100
@@ -14,7 +14,6 @@
 
 #include <cassert>
 #include <deque>
-#include <iostream>
 #include <cstring>
 
 //#include "d-lang.h"
@@ -260,7 +259,7 @@
 	    break;
 	case Arg_FrameRelative:
 // FIXME
-std::cout << "asm fixme Arg_FrameRelative" << std::endl;
+llvm::cout << "asm fixme Arg_FrameRelative" << std::endl;
 assert(0);
 /*	    if (arg->expr->op == TOKvar)
 		arg_val = ((VarExp *) arg->expr)->var->toSymbol()->Stree;
@@ -278,7 +277,7 @@
 	    break;*/
 	case Arg_LocalSize:
 // FIXME
-std::cout << "asm fixme Arg_LocalSize" << std::endl;
+llvm::cout << "asm fixme Arg_LocalSize" << std::endl;
 assert(0);
 /*	    var_frame_offset = cfun->x_frame_offset;
 	    if (var_frame_offset < 0)
@@ -711,7 +710,7 @@
         Logger::cout() << "Arguments:" << '\n';
         Logger::indent();
         for (std::vector<LLValue*>::iterator b = args.begin(), i = b, e = args.end(); i != e; ++i) {
-            std::ostream& cout = Logger::cout();
+            llvm::OStream cout = Logger::cout();
             cout << '$' << (i - b) << " ==> " << **i;
             if (llvm::isa<LLConstant>(*i))
                 cout << '\n';
--- a/gen/dwarftypes.cpp	Thu Feb 26 15:24:20 2009 +0100
+++ b/gen/dwarftypes.cpp	Thu Feb 26 14:51:02 2009 +0100
@@ -16,7 +16,6 @@
 #include <llvm/Analysis/Verifier.h>
 #include <llvm/Assembly/PrintModulePass.h>
 #include <algorithm>
-#include <iostream>
 
 void RegisterDwarfSymbols(llvm::Module* mod) {
   using namespace llvm;
--- a/gen/linker.cpp	Thu Feb 26 15:24:20 2009 +0100
+++ b/gen/linker.cpp	Thu Feb 26 14:51:02 2009 +0100
@@ -333,7 +333,7 @@
 
     Logger::println("Linking with: ");
     std::vector<const char*>::const_iterator I = args.begin(), E = args.end(); 
-    std::ostream& logstr = Logger::cout();
+    llvm::OStream logstr = Logger::cout();
     for (; I != E; ++I)
         if (*I)
             logstr << "'" << *I << "'" << " ";
--- a/gen/llvmhelpers.cpp	Thu Feb 26 15:24:20 2009 +0100
+++ b/gen/llvmhelpers.cpp	Thu Feb 26 14:51:02 2009 +0100
@@ -546,7 +546,7 @@
     }
 
     // unknown
-    std::cout << "unsupported: null value for " << type->toChars() << '\n';
+    llvm::cout << "unsupported: null value for " << type->toChars() << '\n';
     assert(0);
     return 0;
 
--- a/gen/logger.cpp	Thu Feb 26 15:24:20 2009 +0100
+++ b/gen/logger.cpp	Thu Feb 26 14:51:02 2009 +0100
@@ -2,7 +2,6 @@
 #include <cstdarg>
 #include <cstdio>
 #include <cstdlib>
-#include <iostream>
 #include <fstream>
 #include <string>
 
@@ -14,7 +13,6 @@
 namespace Logger
 {
     static std::string indent_str;
-    static std::ofstream null_out("/dev/null");
 
     llvm::cl::opt<bool> _enabled("vv",
         llvm::cl::desc("Very verbose"),
@@ -33,12 +31,12 @@
             indent_str.resize(indent_str.size()-2);
         }
     }
-    std::ostream& cout()
+    llvm::OStream cout()
     {
         if (_enabled)
-            return std::cout << indent_str;
+            return llvm::cout << indent_str;
         else
-            return null_out;
+            return 0;
     }
     void println(const char* fmt,...)
     {
--- a/gen/logger.h	Thu Feb 26 15:24:20 2009 +0100
+++ b/gen/logger.h	Thu Feb 26 14:51:02 2009 +0100
@@ -1,7 +1,7 @@
 #ifndef _llvmd_gen_logger_h_
 #define _llvmd_gen_logger_h_
 
-#include <iostream>
+#include "llvm/Support/Streams.h"
 
 struct Loc;
 
@@ -9,7 +9,7 @@
 {
     void indent();
     void undent();
-    std::ostream& cout();
+    llvm::OStream cout();
     void println(const char* fmt, ...);
     void print(const char* fmt, ...);
     void enable();
--- a/gen/statements.cpp	Thu Feb 26 15:24:20 2009 +0100
+++ b/gen/statements.cpp	Thu Feb 26 14:51:02 2009 +0100
@@ -3,7 +3,6 @@
 #include <stdio.h>
 #include <math.h>
 #include <fstream>
-#include <iostream>
 
 #include "gen/llvm.h"
 #include "llvm/InlineAsm.h"
--- a/gen/toir.cpp	Thu Feb 26 15:24:20 2009 +0100
+++ b/gen/toir.cpp	Thu Feb 26 14:51:02 2009 +0100
@@ -9,7 +9,6 @@
 #include <stdio.h>
 #include <math.h>
 #include <fstream>
-#include <iostream>
 
 #include "gen/llvm.h"
 
--- a/gen/tollvm.cpp	Thu Feb 26 15:24:20 2009 +0100
+++ b/gen/tollvm.cpp	Thu Feb 26 14:51:02 2009 +0100
@@ -1,4 +1,3 @@
-#include <iostream>
 
 #include "gen/llvm.h"
 
--- a/gen/toobj.cpp	Thu Feb 26 15:24:20 2009 +0100
+++ b/gen/toobj.cpp	Thu Feb 26 14:51:02 2009 +0100
@@ -8,7 +8,6 @@
 // See the included readme.txt for details.
 
 #include <cstddef>
-#include <iostream>
 #include <fstream>
 
 #include "gen/llvm.h"
@@ -344,13 +343,15 @@
         Args.push_back(args[i].c_str());
     Args.push_back(0);
 
-    Logger::println("Assembling with: ");
-    std::vector<const char*>::const_iterator I = Args.begin(), E = Args.end(); 
-    std::ostream& logstr = Logger::cout();
-    for (; I != E; ++I)
-        if (*I)
-            logstr << "'" << *I << "'" << " ";
-    logstr << "\n" << std::flush;
+    if (Logger::enabled()) {
+        Logger::println("Assembling with: ");
+        std::vector<const char*>::const_iterator I = Args.begin(), E = Args.end();
+        std::ostream& logstr = *Logger::cout().stream();
+        for (; I != E; ++I)
+            if (*I)
+                logstr << "'" << *I << "'" << " ";
+        logstr << "\n" << std::flush;
+    }
 
     // Run the compiler to assembly the program.
     std::string ErrMsg;