diff --git a/lib/Target/WDC65816/WDC65816.h b/lib/Target/WDC65816/WDC65816.h index 2089bd7b..1452c6b1 100644 --- a/lib/Target/WDC65816/WDC65816.h +++ b/lib/Target/WDC65816/WDC65816.h @@ -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; diff --git a/lib/Target/WDC65816/WDC65816ISelDAGToDAG.cpp b/lib/Target/WDC65816/WDC65816ISelDAGToDAG.cpp index 9eca4add..d88c5c85 100644 --- a/lib/Target/WDC65816/WDC65816ISelDAGToDAG.cpp +++ b/lib/Target/WDC65816/WDC65816ISelDAGToDAG.cpp @@ -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); diff --git a/lib/Target/WDC65816/WDC65816ISelLowering.cpp b/lib/Target/WDC65816/WDC65816ISelLowering.cpp index 378aa7e0..2caa6944 100644 --- a/lib/Target/WDC65816/WDC65816ISelLowering.cpp +++ b/lib/Target/WDC65816/WDC65816ISelLowering.cpp @@ -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()) { diff --git a/lib/Target/WDC65816/WDC65816MachineFunctionInfo.h b/lib/Target/WDC65816/WDC65816MachineFunctionInfo.h index 53cd587a..76761e06 100644 --- a/lib/Target/WDC65816/WDC65816MachineFunctionInfo.h +++ b/lib/Target/WDC65816/WDC65816MachineFunctionInfo.h @@ -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; } diff --git a/lib/Target/WDC65816/WDC65816TargetMachine.cpp b/lib/Target/WDC65816/WDC65816TargetMachine.cpp index 9e474343..6e60112c 100644 --- a/lib/Target/WDC65816/WDC65816TargetMachine.cpp +++ b/lib/Target/WDC65816/WDC65816TargetMachine.cpp @@ -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 << " | "; }