z3-z3-4.13.0.src.api.api_log.cpp Maven / Gradle / Ivy
The newest version!
/*++
Copyright (c) 2012 Microsoft Corporation
Module Name:
api_log.cpp
Abstract:
API for creating logs
Author:
Leonardo de Moura (leonardo) 2012-02-29.
Revision History:
--*/
#include
#include "api/z3.h"
#include "api/api_log_macros.h"
#include "api/z3_logger.h"
#include "util/util.h"
#include "util/z3_version.h"
#include "util/mutex.h"
static std::ostream * g_z3_log = nullptr;
atomic g_z3_log_enabled;
#ifdef Z3_LOG_SYNC
static mutex g_log_mux;
#define SCOPED_LOCK() lock_guard lock(g_log_mux)
#else
#define SCOPED_LOCK() {}
#endif
// functions called from api_log_macros.*
void SetR(void * obj) {
*g_z3_log << "= " << obj << '\n';
}
void SetO(void * obj, unsigned pos) {
*g_z3_log << "* " << obj << ' ' << pos << '\n';
}
void SetAO(void * obj, unsigned pos, unsigned idx) {
*g_z3_log << "@ " << obj << ' ' << pos << ' ' << idx << '\n';
}
namespace {
struct ll_escaped { char const * m_str; };
std::ostream & operator<<(std::ostream & out, ll_escaped const & d) {
char const * s = d.m_str;
while (*s) {
unsigned char c = *s;
if (('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') ||
c == '~' || c == '!' || c == '@' || c == '#' || c == '$' || c == '%' || c == '^' || c == '&' ||
c == '*' || c == '-' || c == '_' || c == '+' || c == '.' || c == '?' || c == '/' || c == ' ' ||
c == '<' || c == '>') {
out << c;
}
else {
unsigned char str[4] = {'0', '0', '0', 0};
str[2] = '0' + (c % 10);
c /= 10;
str[1] = '0' + (c % 10);
c /= 10;
str[0] = '0' + c;
out << '\\' << str;
}
s++;
}
return out;
}
}
void R() { *g_z3_log << 'R' << std::endl; }
void P(void * obj) { *g_z3_log << "P " << obj <bad() || g_z3_log->fail()) {
dealloc(g_z3_log);
g_z3_log = nullptr;
res = false;
}
else {
*g_z3_log << "V \"" << Z3_MAJOR_VERSION << "." << Z3_MINOR_VERSION << "." << Z3_BUILD_NUMBER << "." << Z3_REVISION_NUMBER << '"' << std::endl;
res = true;
}
g_z3_log_enabled = res;
return res;
}
void Z3_API Z3_append_log(Z3_string str) {
if (!g_z3_log_enabled)
return;
SCOPED_LOCK();
if (g_z3_log != nullptr)
_Z3_append_log(static_cast(str));
}
void Z3_API Z3_close_log(void) {
SCOPED_LOCK();
Z3_close_log_unsafe();
}
}