From 6bfb66385d2efd05149c07fcca7635c37671a6f1 Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Tue, 28 Jul 2015 00:18:06 -0400 Subject: [PATCH] Add a logging mechanism to make it easier to debug the 65816 code. --- lib/Target/WDC65816/WDC65816.h | 12 +++++++++ lib/Target/WDC65816/WDC65816TargetMachine.cpp | 27 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/lib/Target/WDC65816/WDC65816.h b/lib/Target/WDC65816/WDC65816.h index 9636e28f..2089bd7b 100644 --- a/lib/Target/WDC65816/WDC65816.h +++ b/lib/Target/WDC65816/WDC65816.h @@ -19,6 +19,16 @@ #include "llvm/Support/ErrorHandling.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 + + namespace llvm { class FunctionPass; class WDC65816TargetMachine; @@ -26,6 +36,8 @@ namespace llvm { FunctionPass *createWDC65816ISelDag(WDC65816TargetMachine &TM); + void logWDCMessage(const char *file, const char *function, unsigned int linenum, const char *format, ...); + } // end namespace llvm; namespace llvm { diff --git a/lib/Target/WDC65816/WDC65816TargetMachine.cpp b/lib/Target/WDC65816/WDC65816TargetMachine.cpp index 56508293..9e474343 100644 --- a/lib/Target/WDC65816/WDC65816TargetMachine.cpp +++ b/lib/Target/WDC65816/WDC65816TargetMachine.cpp @@ -10,6 +10,9 @@ // //===----------------------------------------------------------------------===// + +#include + #include "WDC65816TargetMachine.h" #include "WDC65816.h" #include "llvm/CodeGen/Passes.h" @@ -21,6 +24,7 @@ using namespace llvm; extern "C" void LLVMInitializeWDC65816Target() { // Register the target. RegisterTargetMachine X(TheWDC65816Target); + WDC_LOG("Registered the target machine"); } /// WDC65816TargetMachine ctor @@ -70,3 +74,26 @@ bool WDC65816PassConfig::addInstSelector() { bool WDC65816PassConfig::addPreEmitPass(){ return false; } + + +void llvm::logWDCMessage(const char *file, const char *function, unsigned int linenum, const char *format, ...) +{ + char timebuf[64]; + va_list args; + struct timeval now; + const char *filename = strrchr(file, '/'); + + if (filename != NULL) + filename++; + else + filename = file; + + gettimeofday(&now, NULL); + strftime(timebuf, sizeof(timebuf), "%T", localtime(&(now.tv_sec))); + + 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); +}