Adopt the standard LLVM debug infrastructure for WDC_LOG(). This way, debugging can be turned on/off at the command line using the "clang -mllvm -debug ..." option.

This commit is contained in:
Jeremy Rand 2015-08-28 23:11:18 -04:00
parent e7deb74a84
commit c09c887891
5 changed files with 13 additions and 21 deletions

View File

@ -17,17 +17,11 @@
#include "MCTargetDesc/WDC65816MCTargetDesc.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/Debug.h"
#include "llvm/Target/TargetMachine.h"
#define WDC_DEBUG // This is a debug build option which enables logging and perhaps more in the future.
#ifdef WDC_DEBUG
#define WDC_LOG(...) llvm::logWDCMessage(__FILE__, __func__, __LINE__, __VA_ARGS__)
#else
#define WDC_LOG(...)
#endif
#define WDC_LOG(X) DEBUG_WITH_TYPE("WDC", wdc_dbgs(__FILE__, __func__, __LINE__) << X << "\n");
namespace llvm {
class FunctionPass;
@ -36,7 +30,7 @@ namespace llvm {
FunctionPass *createWDC65816ISelDag(WDC65816TargetMachine &TM);
void logWDCMessage(const char *file, const char *function, unsigned int linenum, const char *format, ...);
raw_ostream &wdc_dbgs(const char *file, const char *function, unsigned int linenum);
} // end namespace llvm;

View File

@ -167,7 +167,7 @@ bool SparcDAGToDAGISel::SelectADDRrr(SDValue Addr, SDValue &R1, SDValue &R2) {
#endif
SDNode *WDC65816DAGToDAGISel::Select(SDNode *N) {
WDC_LOG("WDC_TODO - Unimplemented method called, opcode=%s", N->getOperationName().c_str());
WDC_LOG("WDC_TODO - Unimplemented method called, opcode=" << N);
SDLoc dl(N);
if (N->isMachineOpcode()) {
N->setNodeId(-1);

View File

@ -75,11 +75,11 @@ SDValue WDC65816TargetLowering::LowerFormalArguments(SDValue Chain,
unsigned Offset = VA.getLocMemOffset();
if (VA.needsCustom()) {
WDC_LOG("WDC_TODO - needsCustom() in memory location, offset=%u!", Offset);
WDC_LOG("WDC_TODO - needsCustom() in memory location, offset=" << Offset);
continue;
}
WDC_LOG("WDC_TODO - Write code for memory location, offset=%u", Offset);
WDC_LOG("WDC_TODO - Write code for memory location, offset=" << Offset);
}
if (MF.getFunction()->hasStructRetAttr()) {

View File

@ -46,12 +46,12 @@ namespace llvm {
unsigned getGlobalBaseReg() const {
WDC_LOG("Returning %u", GlobalBaseReg);
WDC_LOG("Returning " << GlobalBaseReg);
return GlobalBaseReg;
}
void setGlobalBaseReg(unsigned Reg) {
WDC_LOG("Setting global base register to %u", Reg);
WDC_LOG("Setting global base register to " << Reg);
GlobalBaseReg = Reg;
}

View File

@ -76,12 +76,13 @@ bool WDC65816PassConfig::addPreEmitPass(){
}
void llvm::logWDCMessage(const char *file, const char *function, unsigned int linenum, const char *format, ...)
raw_ostream &llvm::wdc_dbgs(const char *file, const char *function, unsigned int linenum)
{
char timebuf[64];
va_list args;
char fractime[16];
struct timeval now;
const char *filename = strrchr(file, '/');
raw_ostream &wdc_dbgs();
if (filename != NULL)
filename++;
@ -90,10 +91,7 @@ void llvm::logWDCMessage(const char *file, const char *function, unsigned int li
gettimeofday(&now, NULL);
strftime(timebuf, sizeof(timebuf), "%T", localtime(&(now.tv_sec)));
snprintf(fractime, sizeof(fractime), ".%06u", now.tv_usec);
va_start(args, format);
fprintf(stderr, "| WDCLog | %s.%06u | %s:%u | %s | ", timebuf, now.tv_usec, filename, linenum, function);
vfprintf(stderr, format, args);
fprintf(stderr, " |\n");
va_end (args);
return dbgs() << "| WDCLog | " << timebuf << fractime << " | " << filename << ":" << linenum << " | " << function << " | ";
}