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)
This commit is contained in:
Frits van Bommel
2009-02-26 14:51:02 +01:00
parent 58a8711bc1
commit e37c82d1ec
10 changed files with 19 additions and 25 deletions

View File

@@ -14,7 +14,6 @@
#include <cassert>
#include <deque>
#include <iostream>
#include <cstring>
//#include "d-lang.h"
@@ -260,7 +259,7 @@ AsmStatement::toIR(IRState * irs)
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 @@ assert(0);
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 @@ void AsmBlockStatement::toIR(IRState* p)
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';

View File

@@ -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;

View File

@@ -333,7 +333,7 @@ int linkObjToExecutable(const char* argv0)
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 << "'" << " ";

View File

@@ -546,7 +546,7 @@ DValue* DtoNullValue(Type* type)
}
// unknown
std::cout << "unsupported: null value for " << type->toChars() << '\n';
llvm::cout << "unsupported: null value for " << type->toChars() << '\n';
assert(0);
return 0;

View File

@@ -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 @@ namespace Logger
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,...)
{

View File

@@ -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 @@ namespace Logger
{
void indent();
void undent();
std::ostream& cout();
llvm::OStream cout();
void println(const char* fmt, ...);
void print(const char* fmt, ...);
void enable();

View File

@@ -3,7 +3,6 @@
#include <stdio.h>
#include <math.h>
#include <fstream>
#include <iostream>
#include "gen/llvm.h"
#include "llvm/InlineAsm.h"

View File

@@ -9,7 +9,6 @@
#include <stdio.h>
#include <math.h>
#include <fstream>
#include <iostream>
#include "gen/llvm.h"

View File

@@ -1,4 +1,3 @@
#include <iostream>
#include "gen/llvm.h"

View File

@@ -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 @@ void assemble(const llvm::sys::Path& asmpath, const llvm::sys::Path& objpath)
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;