mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-09 04:15:58 +03:00
driver/gen/ir: clang-format the world
This uses the LLVM style, which makes sense for sharing code with other LLVM projects. The DMD code we use will soon all be in D anyway.
This commit is contained in:
parent
123666cf89
commit
44b0f7b615
125 changed files with 28991 additions and 30602 deletions
160
gen/logger.cpp
160
gen/logger.cpp
|
@ -25,102 +25,92 @@
|
|||
#include "gen/logger.h"
|
||||
#include "gen/irstate.h"
|
||||
|
||||
void Stream::writeType(std::ostream& OS, const llvm::Type& Ty) {
|
||||
llvm::raw_os_ostream raw(OS);
|
||||
Ty.print(raw);
|
||||
void Stream::writeType(std::ostream &OS, const llvm::Type &Ty) {
|
||||
llvm::raw_os_ostream raw(OS);
|
||||
Ty.print(raw);
|
||||
}
|
||||
|
||||
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))
|
||||
V.printAsOperand(raw, true, &gIR->module);
|
||||
else
|
||||
V.print(raw);
|
||||
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))
|
||||
V.printAsOperand(raw, true, &gIR->module);
|
||||
else
|
||||
V.print(raw);
|
||||
}
|
||||
|
||||
namespace Logger
|
||||
{
|
||||
static std::string indent_str;
|
||||
bool _enabled;
|
||||
namespace Logger {
|
||||
static std::string indent_str;
|
||||
bool _enabled;
|
||||
|
||||
static llvm::cl::opt<bool, true> enabledopt("vv",
|
||||
llvm::cl::desc("Print front-end/glue code debug log"),
|
||||
llvm::cl::location(_enabled),
|
||||
llvm::cl::ZeroOrMore);
|
||||
static llvm::cl::opt<bool, true>
|
||||
enabledopt("vv", llvm::cl::desc("Print front-end/glue code debug log"),
|
||||
llvm::cl::location(_enabled), 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 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;
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
static inline void
|
||||
search_and_replace(std::string& str, const std::string& what, const std::string& replacement)
|
||||
{
|
||||
assert(!what.empty());
|
||||
size_t pos = str.find(what);
|
||||
while (pos != std::string::npos)
|
||||
{
|
||||
str.replace(pos, what.size(), replacement);
|
||||
pos = str.find(what, pos + replacement.size());
|
||||
}
|
||||
}
|
||||
static inline void search_and_replace(std::string &str, const std::string &what,
|
||||
const std::string &replacement) {
|
||||
assert(!what.empty());
|
||||
size_t pos = str.find(what);
|
||||
while (pos != std::string::npos) {
|
||||
str.replace(pos, what.size(), replacement);
|
||||
pos = str.find(what, pos + replacement.size());
|
||||
}
|
||||
}
|
||||
|
||||
#define WORKAROUND_C99_SPECIFIERS_BUG(f) \
|
||||
std::string tmp = f; \
|
||||
search_and_replace(tmp, std::string("%z"), std::string("%I")); \
|
||||
f = tmp.c_str();
|
||||
#define WORKAROUND_C99_SPECIFIERS_BUG(f) \
|
||||
std::string tmp = f; \
|
||||
search_and_replace(tmp, std::string("%z"), std::string("%I")); \
|
||||
f = tmp.c_str();
|
||||
#else
|
||||
#define WORKAROUND_C99_SPECIFIERS_BUG(f)
|
||||
#endif
|
||||
|
||||
void println(const char* fmt,...)
|
||||
{
|
||||
if (_enabled) {
|
||||
printf("%s", indent_str.c_str());
|
||||
va_list va;
|
||||
va_start(va,fmt);
|
||||
WORKAROUND_C99_SPECIFIERS_BUG(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);
|
||||
WORKAROUND_C99_SPECIFIERS_BUG(fmt);
|
||||
vprintf(fmt,va);
|
||||
va_end(va);
|
||||
}
|
||||
}
|
||||
void attention(Loc& loc, const char* fmt,...)
|
||||
{
|
||||
va_list va;
|
||||
va_start(va,fmt);
|
||||
vwarning(loc,fmt,va);
|
||||
va_end(va);
|
||||
}
|
||||
void println(const char *fmt, ...) {
|
||||
if (_enabled) {
|
||||
printf("%s", indent_str.c_str());
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
WORKAROUND_C99_SPECIFIERS_BUG(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);
|
||||
WORKAROUND_C99_SPECIFIERS_BUG(fmt);
|
||||
vprintf(fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
}
|
||||
void attention(Loc &loc, const char *fmt, ...) {
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
vwarning(loc, fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue