mirror of
https://github.com/jeremysrand/llvm-65816.git
synced 2025-02-21 06:29:21 +00:00
Add a logging mechanism to make it easier to debug the 65816 code.
This commit is contained in:
parent
39070eb1d0
commit
6bfb66385d
@ -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 {
|
||||
|
@ -10,6 +10,9 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
|
||||
#include <sys/time.h>
|
||||
|
||||
#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<WDC65816TargetMachine> 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);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user