3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-23 17:15:31 +00:00

working on new parameter framework

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2012-12-01 15:54:34 -08:00
parent be5f933201
commit 589f096e6e
36 changed files with 436 additions and 377 deletions

View file

@ -26,7 +26,6 @@ struct gparams::imp {
param_descrs m_param_descrs;
dictionary<params_ref *> m_module_params;
params_ref m_params;
params_ref m_empty;
public:
imp() {
}
@ -49,28 +48,37 @@ public:
}
void register_global(param_descrs & d) {
m_param_descrs.copy(d);
#pragma omp critical (gparams)
{
m_param_descrs.copy(d);
}
}
void register_module(char const * module_name, param_descrs * d) {
symbol s(module_name);
param_descrs * old_d;
if (m_module_param_descrs.find(s, old_d)) {
old_d->copy(*d);
dealloc(d);
}
else {
m_module_param_descrs.insert(s, d);
#pragma omp critical (gparams)
{
symbol s(module_name);
param_descrs * old_d;
if (m_module_param_descrs.find(s, old_d)) {
old_d->copy(*d);
dealloc(d);
}
else {
m_module_param_descrs.insert(s, d);
}
}
}
void display(std::ostream & out, unsigned indent, bool smt2_style) {
m_param_descrs.display(out, indent, smt2_style);
dictionary<param_descrs*>::iterator it = m_module_param_descrs.begin();
dictionary<param_descrs*>::iterator end = m_module_param_descrs.end();
for (; it != end; ++it) {
out << "[module] " << it->m_key << "\n";
it->m_value->display(out, indent + 4, smt2_style);
#pragma omp critical (gparams)
{
m_param_descrs.display(out, indent, smt2_style);
dictionary<param_descrs*>::iterator it = m_module_param_descrs.begin();
dictionary<param_descrs*>::iterator end = m_module_param_descrs.end();
for (; it != end; ++it) {
out << "[module] " << it->m_key << "\n";
it->m_value->display(out, indent + 4, smt2_style);
}
}
}
@ -102,15 +110,13 @@ public:
return m_params;
}
else {
params_ref * p;
if (m_module_params.find(mod_name, p)) {
return *p;
}
else {
params_ref * p = 0;
if (!m_module_params.find(mod_name, p)) {
p = alloc(params_ref);
m_module_params.insert(mod_name, p);
return *p;
}
SASSERT(p != 0);
return *p;
}
}
@ -119,9 +125,9 @@ public:
params_ref & ps = get_params(mod_name);
if (k == CPK_INVALID) {
if (mod_name == symbol::null)
throw default_exception("unknown parameter '%s'", param_name.bare_str());
throw exception("unknown parameter '%s'", param_name.bare_str());
else
throw default_exception("unknown parameter '%s' at module '%s'", param_name.bare_str(), mod_name.bare_str());
throw exception("unknown parameter '%s' at module '%s'", param_name.bare_str(), mod_name.bare_str());
}
else if (k == CPK_UINT) {
long val = strtol(value, 0, 10);
@ -136,9 +142,9 @@ public:
}
else {
if (mod_name == symbol::null)
throw default_exception("invalid value '%s' for Boolean parameter '%s'", value, param_name.bare_str());
throw exception("invalid value '%s' for Boolean parameter '%s'", value, param_name.bare_str());
else
throw default_exception("invalid value '%s' for Boolean parameter '%s' at module '%s'", value, param_name.bare_str(), mod_name.bare_str());
throw exception("invalid value '%s' for Boolean parameter '%s' at module '%s'", value, param_name.bare_str(), mod_name.bare_str());
}
}
else if (k == CPK_SYMBOL) {
@ -149,47 +155,125 @@ public:
}
else {
if (mod_name == symbol::null)
throw default_exception("unsupported parameter type '%s'", param_name.bare_str());
throw exception("unsupported parameter type '%s'", param_name.bare_str());
else
throw default_exception("unsupported parameter type '%s' at module '%s'", param_name.bare_str(), mod_name.bare_str());
throw exception("unsupported parameter type '%s' at module '%s'", param_name.bare_str(), mod_name.bare_str());
}
}
void set(char const * name, char const * value) {
symbol m, p;
normalize(name, m, p);
if (m == symbol::null) {
set(m_param_descrs, p, value, m);
}
else {
param_descrs * d;
if (m_module_param_descrs.find(m, d)) {
set(*d, p, value, m);
bool error = false;
std::string error_msg;
#pragma omp critical (gparams)
{
try {
symbol m, p;
normalize(name, m, p);
if (m == symbol::null) {
set(m_param_descrs, p, value, m);
}
else {
param_descrs * d;
if (m_module_param_descrs.find(m, d)) {
set(*d, p, value, m);
}
else {
throw exception("invalid parameter, unknown module '%s'", m.bare_str());
}
}
}
else {
throw default_exception("invalid parameter, unknown module '%s'", m.bare_str());
catch (exception & ex) {
// Exception cannot cross critical section boundaries.
error = true;
error_msg = ex.msg();
}
}
if (error)
throw exception(error_msg);
}
std::string get_value(params_ref const & ps, symbol const & p) {
std::ostringstream buffer;
ps.display(buffer, p);
return buffer.str();
}
std::string get_default(param_descrs const & d, symbol const & p, symbol const & m) {
if (!d.contains(p)) {
if (m == symbol::null)
throw exception("unknown parameter '%s'", p.bare_str());
else
throw exception("unknown parameter '%s' at module '%s'", p.bare_str(), m.bare_str());
}
char const * r = d.get_default(p);
if (r == 0)
return "default";
return r;
}
std::string get_value(char const * name) {
// TODO
return "";
std::string r;
bool error = false;
std::string error_msg;
#pragma omp critical (gparams)
{
try {
symbol m, p;
normalize(name, m, p);
if (m == symbol::null) {
if (m_params.contains(p)) {
r = get_value(m_params, p);
}
else {
r = get_default(m_param_descrs, p, m);
}
}
else {
params_ref * ps = 0;
if (m_module_params.find(m, ps) && ps->contains(p)) {
r = get_value(*ps, p);
}
else {
param_descrs * d;
if (m_module_param_descrs.find(m, d)) {
r = get_default(*d, p, m);
}
else {
throw exception("unknown module '%s'", m.bare_str());
}
}
}
}
catch (exception & ex) {
// Exception cannot cross critical section boundaries.
error = true;
error_msg = ex.msg();
}
}
if (error)
throw exception(error_msg);
return r;
}
params_ref const & get_module(symbol const & module_name) {
params_ref get_module(symbol const & module_name) {
params_ref result;
params_ref * ps = 0;
if (m_module_params.find(module_name, ps)) {
return *ps;
}
else {
return m_empty;
#pragma omp critical (gparams)
{
if (m_module_params.find(module_name, ps)) {
result = *ps;
}
}
return result;
}
params_ref const & get() {
return m_params;
params_ref get() {
params_ref result;
#pragma omp critical (gparams)
{
result = m_params;
}
return result;
}
};
@ -226,16 +310,16 @@ void gparams::register_module(char const * module_name, param_descrs * d) {
g_imp->register_module(module_name, d);
}
params_ref const & gparams::get_module(char const * module_name) {
params_ref gparams::get_module(char const * module_name) {
return get_module(symbol(module_name));
}
params_ref const & gparams::get_module(symbol const & module_name) {
params_ref gparams::get_module(symbol const & module_name) {
SASSERT(g_imp != 0);
return g_imp->get_module(module_name);
}
params_ref const & gparams::get() {
params_ref gparams::get() {
SASSERT(g_imp != 0);
return g_imp->get();
}

View file

@ -31,7 +31,7 @@ public:
\brief Set a global parameter \c name with \c value.
The name of parameter can be composed of characters [a-z][A-Z], digits [0-9], '-' and '_'.
The character '.' is used a delimiter (more later).
The character '.' is a delimiter (more later).
The parameter names are case-insensitive. The character '-' should be viewed as an "alias" for '_'.
Thus, the following parameter names are considered equivalent: "auto-config" and "AUTO_CONFIG".
@ -90,13 +90,13 @@ public:
// In this example "p" will contain "decimal" -> true after executing this function.
params_ref const & p = get_module_params("pp")
*/
static params_ref const & get_module(char const * module_name);
static params_ref const & get_module(symbol const & module_name);
static params_ref get_module(char const * module_name);
static params_ref get_module(symbol const & module_name);
/**
\brief Return the global parameter set (i.e., parameters that are not associated with any particular module).
*/
static params_ref const & get();
static params_ref get();
/**
\brief Dump information about available parameters in the given output stream.

View file

@ -1,9 +1,9 @@
#include<iostream>
#include<stdlib.h>
#include<limits.h>
#include"trace.h"
#include"memory_manager.h"
#include"error_codes.h"
// The following two function are automatically generated by the mk_make.py script.
// The script collects ADD_INITIALIZER and ADD_FINALIZER commands in the .h files.
// For example, rational.h contains
@ -27,6 +27,7 @@ out_of_memory_error::out_of_memory_error():z3_error(ERR_MEMOUT) {
}
volatile bool g_memory_out_of_memory = false;
bool g_memory_initialized = false;
long long g_memory_alloc_size = 0;
long long g_memory_max_size = 0;
long long g_memory_max_used_size = 0;
@ -70,8 +71,20 @@ mem_usage_report g_info;
#endif
void memory::initialize(size_t max_size) {
bool initialize = false;
#pragma omp critical (z3_memory_manager)
{
// only update the maximum size if max_size != UINT_MAX
if (max_size != UINT_MAX)
g_memory_max_size = max_size;
if (!g_memory_initialized) {
g_memory_initialized = true;
initialize = true;
}
}
if (!initialize)
return;
g_memory_out_of_memory = false;
g_memory_max_size = max_size;
mem_initialize();
}
@ -108,8 +121,12 @@ void memory::set_max_size(size_t max_size) {
static bool g_finalizing = false;
void memory::finalize() {
g_finalizing = true;
mem_finalize();
if (g_memory_initialized) {
g_finalizing = true;
mem_finalize();
g_memory_initialized = false;
g_finalizing = false;
}
}
unsigned long long memory::get_allocation_size() {

View file

@ -57,6 +57,10 @@ struct param_descrs::imp {
void erase(symbol const & name) {
m_info.erase(name);
}
bool contains(symbol const & name) const {
return m_info.contains(name);
}
param_kind get_kind(symbol const & name) const {
info i;
@ -157,6 +161,14 @@ void param_descrs::insert(char const * name, param_kind k, char const * descr, c
insert(symbol(name), k, descr, def);
}
bool param_descrs::contains(char const * name) const {
return contains(symbol(name));
}
bool param_descrs::contains(symbol const & name) const {
return m_imp->contains(name);
}
char const * param_descrs::get_descr(char const * name) const {
return get_descr(symbol(name));
}
@ -345,7 +357,7 @@ public:
continue;
switch (it->second.m_kind) {
case CPK_BOOL:
out << it->second.m_bool_value;
out << (it->second.m_bool_value?"true":"false");
return;
case CPK_UINT:
out << it->second.m_uint_value;

View file

@ -109,6 +109,8 @@ public:
void copy(param_descrs & other);
void insert(char const * name, param_kind k, char const * descr, char const * def = 0);
void insert(symbol const & name, param_kind k, char const * descr, char const * def = 0);
bool contains(char const * name) const;
bool contains(symbol const & name) const;
void erase(char const * name);
void erase(symbol const & name);
param_kind get_kind(char const * name) const;