add FILE* output
This commit is contained in:
@@ -14,29 +14,34 @@
|
|||||||
#ifndef DEBUG_H
|
#ifndef DEBUG_H
|
||||||
#define DEBUG_H
|
#define DEBUG_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#include <br.h>
|
||||||
#include <bits.h>
|
#include <bits.h>
|
||||||
|
|
||||||
#define _unused __attribute__((__unused__))
|
|
||||||
#define _printf __attribute__ ((format (printf, 6, 7)))
|
#define _printf __attribute__ ((format (printf, 6, 7)))
|
||||||
|
|
||||||
#ifdef DEBUG_DEBUG
|
#ifdef DEBUG_DEBUG
|
||||||
void debug_init(u32 level);
|
|
||||||
|
void debug_init(u32 level, FILE *stream);
|
||||||
void debug_level_set(u32 level);
|
void debug_level_set(u32 level);
|
||||||
u32 debug_level_get(void);
|
void debug_stream_set(FILE *stream);
|
||||||
void _printf debug(u32 level, bool timestamp,
|
void _printf debug(u32 level, bool timestamp,
|
||||||
u32 indent, const char *src,
|
u32 indent, const char *src,
|
||||||
u32 line, const char *fmt, ...);
|
u32 line, const char *fmt, ...);
|
||||||
#else /* DEBUG_DEBUG */
|
#else /* DEBUG_DEBUG */
|
||||||
static inline void debug_init(_unused u32 level) {}
|
|
||||||
static inline void debug_level_set(_unused u32 level) {}
|
static inline void debug_init(__unused u32 level, __unused FILE *stream) {}
|
||||||
static inline void _printf debug(_unused u32 level, _unused bool timestamp,
|
static inline void debug_level_set(__unused u32 level) {}
|
||||||
_unused u32 indent, _unused const char *src,
|
static inline void debug_stream_set(__unused FILE *stream) {}
|
||||||
_unused u32 line, _unused const char *fmt, ...) {}
|
static inline void _printf debug(__unused u32 level, __unused bool timestamp,
|
||||||
|
__unused u32 indent, __unused const char *src,
|
||||||
|
__unused u32 line, __unused const char *fmt, ...) {}
|
||||||
|
|
||||||
#endif /* DEBUG_DEBUG */
|
#endif /* DEBUG_DEBUG */
|
||||||
#undef _unused
|
|
||||||
#undef _printf
|
#undef _printf
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -26,19 +26,26 @@
|
|||||||
#define MILLISEC 1000000 /* milli sec in sec */
|
#define MILLISEC 1000000 /* milli sec in sec */
|
||||||
|
|
||||||
static long long timer_start; /* in nanosecond */
|
static long long timer_start; /* in nanosecond */
|
||||||
static u32 debug_level=0;
|
static u32 debug_level = 0;
|
||||||
|
static FILE *stream = NULL;
|
||||||
|
|
||||||
void debug_level_set(u32 level)
|
void debug_level_set(u32 level)
|
||||||
{
|
{
|
||||||
debug_level = level;
|
debug_level = level;
|
||||||
|
log(0, "debug level set to %u\n", level);
|
||||||
log(1, "debug level set to %u\n", level);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void debug_init(u32 level)
|
void debug_stream_set(FILE *_stream)
|
||||||
|
{
|
||||||
|
stream = _stream;
|
||||||
|
log(0, "stream set to %d\n", stream? fileno(stream): -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
void debug_init(u32 level, FILE *_stream)
|
||||||
{
|
{
|
||||||
struct timespec timer;
|
struct timespec timer;
|
||||||
|
|
||||||
|
debug_stream_set(_stream);
|
||||||
debug_level_set(level);
|
debug_level_set(level);
|
||||||
if (!clock_gettime(CLOCK_MONOTONIC, &timer)) {
|
if (!clock_gettime(CLOCK_MONOTONIC, &timer)) {
|
||||||
timer_start = timer.tv_sec * NANOSEC + timer.tv_nsec;
|
timer_start = timer.tv_sec * NANOSEC + timer.tv_nsec;
|
||||||
@@ -66,28 +73,28 @@ inline static long long timer_elapsed()
|
|||||||
void debug(u32 level, bool timestamp, u32 indent, const char *src,
|
void debug(u32 level, bool timestamp, u32 indent, const char *src,
|
||||||
u32 line, const char *fmt, ...)
|
u32 line, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
if (level > debug_level)
|
if (!stream || level > debug_level)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
if (indent)
|
if (indent)
|
||||||
printf("%*s", 2*(indent-1), "");
|
fprintf(stream, "%*s", 2*(indent-1), "");
|
||||||
|
|
||||||
if (timestamp) {
|
if (timestamp) {
|
||||||
long long diff = timer_elapsed();
|
long long diff = timer_elapsed();
|
||||||
printf("%lld.%03lld ", diff/NANOSEC, (diff/1000000)%1000);
|
fprintf(stream, "%lld.%03lld ", diff/NANOSEC, (diff/1000000)%1000);
|
||||||
printf("%010lld ", diff);
|
fprintf(stream, "%010lld ", diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (src) {
|
if (src) {
|
||||||
if (line)
|
if (line)
|
||||||
printf("[%s:%u] ", src, line);
|
fprintf(stream, "[%s:%u] ", src, line);
|
||||||
else
|
else
|
||||||
printf("[%s] ", src);
|
fprintf(stream, "[%s] ", src);
|
||||||
}
|
}
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vprintf(fmt, ap);
|
vfprintf(stream, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,6 +17,9 @@
|
|||||||
#include <bits.h>
|
#include <bits.h>
|
||||||
|
|
||||||
/* piece_t bits structure
|
/* piece_t bits structure
|
||||||
|
* MSB 8 7 6 5 4 3 2 1 LSB
|
||||||
|
* 1: color (0 for white)
|
||||||
|
* 2-7: bit set for pawn (2), knight, bishop, rook, queen, king (7)
|
||||||
*/
|
*/
|
||||||
typedef u8 piece_t;
|
typedef u8 piece_t;
|
||||||
|
|
||||||
|
@@ -98,7 +98,8 @@ int main(int ac, char**av)
|
|||||||
pos_t *pos;
|
pos_t *pos;
|
||||||
eval_t res;
|
eval_t res;
|
||||||
|
|
||||||
debug_init(5);
|
debug_init(5, stderr);
|
||||||
|
|
||||||
piece_pool_init();
|
piece_pool_init();
|
||||||
moves_pool_init();
|
moves_pool_init();
|
||||||
pos_pool_init();
|
pos_pool_init();
|
||||||
@@ -118,6 +119,7 @@ int main(int ac, char**av)
|
|||||||
//pos_print(pos);
|
//pos_print(pos);
|
||||||
//pos_pieces_print(pos);
|
//pos_pieces_print(pos);
|
||||||
moves_gen(pos, pos->turn, true);
|
moves_gen(pos, pos->turn, true);
|
||||||
|
pos_print(pos);
|
||||||
moves_print(pos, M_PR_SEPARATE);
|
moves_print(pos, M_PR_SEPARATE);
|
||||||
res = eval(pos);
|
res = eval(pos);
|
||||||
printf("eval=%d centipawns)\n", res);
|
printf("eval=%d centipawns)\n", res);
|
||||||
|
@@ -179,7 +179,7 @@ int main(int ac, char**av)
|
|||||||
{
|
{
|
||||||
pos_t *pos;
|
pos_t *pos;
|
||||||
|
|
||||||
debug_init(5);
|
debug_init(5, stderr);
|
||||||
piece_pool_init();
|
piece_pool_init();
|
||||||
pos_pool_init();
|
pos_pool_init();
|
||||||
pos = pos_get();
|
pos = pos_get();
|
||||||
|
@@ -119,7 +119,7 @@ int main(int ac, char**av)
|
|||||||
{
|
{
|
||||||
pos_t *pos;
|
pos_t *pos;
|
||||||
printf("zobi\n");fflush(stdout);
|
printf("zobi\n");fflush(stdout);
|
||||||
debug_level_set(6);
|
debug_init(6, stderr);
|
||||||
log_f(5, "kfsjdhg\n");
|
log_f(5, "kfsjdhg\n");
|
||||||
pos_pool_init();
|
pos_pool_init();
|
||||||
pos = pos_get();
|
pos = pos_get();
|
||||||
|
Reference in New Issue
Block a user