mirror of
https://github.com/xomboverlord/ldc.git
synced 2026-01-12 10:53:14 +01:00
Removed use of dyn_cast, llvm no compiles without exceptions and rtti by default. We do need exceptions for the libconfig stuff, but rtti isn't necessary (anymore). Debug info needs to be rewritten, as in LLVM 2.7 the format has completely changed. To have something to look at while rewriting, the old code has been wrapped inside #ifndef DISABLE_DEBUG_INFO , this means that you have to define this to compile at the moment. Updated tango 0.99.9 patch to include updated EH runtime code, which is needed for LLVM 2.7 as well.
106 lines
2.3 KiB
C++
106 lines
2.3 KiB
C++
#include <cassert>
|
|
#include <cstdarg>
|
|
#include <cstdio>
|
|
#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_os_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)
|
|
llvm::raw_os_ostream raw(OS);
|
|
if (llvm::isa<llvm::Constant>(V) && !llvm::isa<llvm::GlobalValue>(V))
|
|
llvm::WriteAsOperand(raw, &V, true, gIR->module);
|
|
else
|
|
V.print(raw);
|
|
}
|
|
|
|
namespace Logger
|
|
{
|
|
static std::string indent_str;
|
|
|
|
llvm::cl::opt<bool> _enabled("vv",
|
|
llvm::cl::desc("Very verbose"),
|
|
llvm::cl::ZeroOrMore);
|
|
|
|
void indent()
|
|
{
|
|
if (_enabled) {
|
|
indent_str += "* ";
|
|
}
|
|
}
|
|
void undent()
|
|
{
|
|
if (_enabled) {
|
|
assert(!indent_str.empty());
|
|
indent_str.resize(indent_str.size()-2);
|
|
}
|
|
}
|
|
Stream cout()
|
|
{
|
|
if (_enabled)
|
|
return std::cout << indent_str;
|
|
else
|
|
return 0;
|
|
}
|
|
void println(const char* fmt,...)
|
|
{
|
|
if (_enabled) {
|
|
printf("%s", indent_str.c_str());
|
|
va_list va;
|
|
va_start(va,fmt);
|
|
vprintf(fmt,va);
|
|
va_end(va);
|
|
printf("\n");
|
|
}
|
|
}
|
|
void print(const char* fmt,...)
|
|
{
|
|
if (_enabled) {
|
|
printf("%s", indent_str.c_str());
|
|
va_list va;
|
|
va_start(va,fmt);
|
|
vprintf(fmt,va);
|
|
va_end(va);
|
|
}
|
|
}
|
|
void enable()
|
|
{
|
|
_enabled = true;
|
|
}
|
|
void disable()
|
|
{
|
|
_enabled = false;
|
|
}
|
|
bool enabled()
|
|
{
|
|
return _enabled;
|
|
}
|
|
void attention(Loc loc, const char* fmt,...)
|
|
{
|
|
va_list va;
|
|
va_start(va,fmt);
|
|
vwarning(loc,fmt,va);
|
|
va_end(va);
|
|
}
|
|
}
|