add new method to param object - dump_param
the method dumps param to the FILE use new method do dump param tree during save/restore also make more use of parse_param methods which initialize param from a string
This commit is contained in:
parent
5903673b3d
commit
e05e6f58b0
@ -279,29 +279,71 @@ void bx_param_num_c::set_enabled(int en)
|
||||
update_dependents();
|
||||
}
|
||||
|
||||
int bx_param_num_c::parse_param(const char *value)
|
||||
int bx_param_num_c::parse_param(const char *ptr)
|
||||
{
|
||||
if (value != NULL) {
|
||||
if ((value[0] == '0') && (value[1] == 'x')) {
|
||||
set(strtoul(value, NULL, 16));
|
||||
if (ptr != NULL) {
|
||||
Bit64u value;
|
||||
if (get_base() == BASE_DOUBLE) {
|
||||
double f2value = strtod(ptr, NULL);
|
||||
memcpy(&value, &f2value, sizeof(double));
|
||||
set(value);
|
||||
} else if (get_base() == BASE_FLOAT) {
|
||||
float f1value = (float)strtod(ptr, NULL);
|
||||
memcpy(&value, &f1value, sizeof(float));
|
||||
set(value);
|
||||
} else if ((ptr[0] == '0') && (ptr[1] == 'x')) {
|
||||
set(strtoull(ptr, NULL, 16));
|
||||
} else {
|
||||
if (value[strlen(value)-1] == 'K') {
|
||||
set(1000 * strtoul(value, NULL, 10));
|
||||
if (ptr[strlen(ptr)-1] == 'K') {
|
||||
set(1000 * strtoul(ptr, NULL, 10));
|
||||
}
|
||||
else if (value[strlen(value)-1] == 'M') {
|
||||
set(1000000 * strtoul(value, NULL, 10));
|
||||
else if (ptr[strlen(ptr)-1] == 'M') {
|
||||
set(1000000 * strtoul(ptr, NULL, 10));
|
||||
}
|
||||
else {
|
||||
set(strtoul(value, NULL, 10));
|
||||
set(strtoul(ptr, NULL, 10));
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bx_param_num_c::dump_param(FILE *fp)
|
||||
{
|
||||
Bit64s value = get64();
|
||||
if (get_base() == BASE_DOUBLE) {
|
||||
double f2value;
|
||||
memcpy(&f2value, &value, sizeof(double));
|
||||
fprintf(fp, "%f", f2value);
|
||||
} else if (get_base() == BASE_FLOAT) {
|
||||
float f1value;
|
||||
memcpy(&f1value, &value, sizeof(float));
|
||||
fprintf(fp, "%f", f1value);
|
||||
} else if (get_base() == BASE_DEC) {
|
||||
if (get_min() >= BX_MIN_BIT64U) {
|
||||
if ((Bit64u) get_max() > BX_MAX_BIT32U) {
|
||||
fprintf(fp, FMT_LL"u", value);
|
||||
} else {
|
||||
fprintf(fp, "%u", (Bit32u) value);
|
||||
}
|
||||
} else {
|
||||
fprintf(fp, "%d", (Bit32s) value);
|
||||
}
|
||||
} else {
|
||||
if (get_format()) {
|
||||
fprintf(fp, get_format(), value);
|
||||
} else {
|
||||
if ((Bit64u)get_max() > BX_MAX_BIT32U) {
|
||||
fprintf(fp, "0x" FMT_LL "x", (Bit64u) value);
|
||||
} else {
|
||||
fprintf(fp, "0x%x", (Bit32u) value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Signed 64 bit
|
||||
bx_shadow_num_c::bx_shadow_num_c(bx_param_c *parent,
|
||||
const char *name,
|
||||
@ -552,13 +594,13 @@ bx_param_bool_c::bx_param_bool_c(bx_param_c *parent,
|
||||
set_type(BXT_PARAM_BOOL);
|
||||
}
|
||||
|
||||
int bx_param_bool_c::parse_param(const char *value)
|
||||
int bx_param_bool_c::parse_param(const char *ptr)
|
||||
{
|
||||
if (value != NULL) {
|
||||
if (!strcmp(value, "0") || !stricmp(value, "false")) {
|
||||
if (ptr != NULL) {
|
||||
if (!strcmp(ptr, "0") || !stricmp(ptr, "false")) {
|
||||
set(0); return 1;
|
||||
}
|
||||
if (!strcmp(value, "1") || !stricmp(value, "true")) {
|
||||
if (!strcmp(ptr, "1") || !stricmp(ptr, "true")) {
|
||||
set(1); return 1;
|
||||
}
|
||||
}
|
||||
@ -566,6 +608,11 @@ int bx_param_bool_c::parse_param(const char *value)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bx_param_bool_c::dump_param(FILE *fp)
|
||||
{
|
||||
fprintf(fp, "%s", get()?"true":"false");
|
||||
}
|
||||
|
||||
bx_shadow_bool_c::bx_shadow_bool_c(bx_param_c *parent,
|
||||
const char *name,
|
||||
const char *label,
|
||||
@ -718,15 +765,20 @@ void bx_param_enum_c::set_enabled(int en)
|
||||
update_dependents();
|
||||
}
|
||||
|
||||
int bx_param_enum_c::parse_param(const char *value)
|
||||
int bx_param_enum_c::parse_param(const char *ptr)
|
||||
{
|
||||
if (value != NULL) {
|
||||
return set_by_name(value);
|
||||
if (ptr != NULL) {
|
||||
return set_by_name(ptr);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bx_param_enum_c::dump_param(FILE *fp)
|
||||
{
|
||||
fprintf(fp, "%s", get_selected());
|
||||
}
|
||||
|
||||
bx_param_string_c::bx_param_string_c(bx_param_c *parent,
|
||||
const char *name,
|
||||
const char *label,
|
||||
@ -890,10 +942,10 @@ bx_bool bx_param_string_c::isempty()
|
||||
}
|
||||
}
|
||||
|
||||
int bx_param_string_c::parse_param(const char *value)
|
||||
int bx_param_string_c::parse_param(const char *ptr)
|
||||
{
|
||||
if (value != NULL) {
|
||||
set(value);
|
||||
if (ptr != NULL) {
|
||||
set(ptr);
|
||||
} else {
|
||||
set("");
|
||||
}
|
||||
@ -901,6 +953,13 @@ int bx_param_string_c::parse_param(const char *value)
|
||||
return 1;
|
||||
}
|
||||
|
||||
void bx_param_string_c::dump_param(FILE *fp)
|
||||
{
|
||||
char tmpstr[BX_PATHNAME_LEN+1];
|
||||
sprint(tmpstr, BX_PATHNAME_LEN, 0);
|
||||
fputs(tmpstr, fp);
|
||||
}
|
||||
|
||||
int bx_param_string_c::sprint(char *buf, int len, bx_bool dquotes)
|
||||
{
|
||||
char tmpbyte[4];
|
||||
|
@ -173,6 +173,8 @@ public:
|
||||
#endif
|
||||
|
||||
virtual int parse_param(const char *value) { return -1; }
|
||||
|
||||
virtual void dump_param(FILE *fp) {}
|
||||
};
|
||||
|
||||
typedef Bit64s (*param_event_handler)(class bx_param_c *, int set, Bit64s val);
|
||||
@ -236,6 +238,7 @@ public:
|
||||
virtual int text_ask();
|
||||
#endif
|
||||
virtual int parse_param(const char *value);
|
||||
virtual void dump_param(FILE *fp);
|
||||
};
|
||||
|
||||
// a bx_shadow_num_c is like a bx_param_num_c except that it doesn't
|
||||
@ -323,6 +326,7 @@ public:
|
||||
virtual int text_ask();
|
||||
#endif
|
||||
virtual int parse_param(const char *value);
|
||||
virtual void dump_param(FILE *fp);
|
||||
};
|
||||
|
||||
// a bx_shadow_bool_c is a shadow param based on bx_param_bool_c.
|
||||
@ -372,6 +376,7 @@ public:
|
||||
virtual int text_ask();
|
||||
#endif
|
||||
virtual int parse_param(const char *value);
|
||||
virtual void dump_param(FILE *fp);
|
||||
};
|
||||
|
||||
typedef const char* (*param_string_event_handler)(class bx_param_string_c *,
|
||||
@ -421,6 +426,7 @@ public:
|
||||
virtual int text_ask();
|
||||
#endif
|
||||
virtual int parse_param(const char *value);
|
||||
virtual void dump_param(FILE *fp);
|
||||
};
|
||||
|
||||
// Declare a filename class. It is identical to a string, except that
|
||||
|
@ -1205,9 +1205,6 @@ bx_bool bx_real_sim_c::restore_bochs_param(bx_list_c *root, const char *sr_path,
|
||||
char *ptr;
|
||||
int i, j, p;
|
||||
unsigned n;
|
||||
float f1value;
|
||||
double f2value;
|
||||
Bit64u value;
|
||||
bx_param_c *param = NULL;
|
||||
FILE *fp, *fp2;
|
||||
|
||||
@ -1247,25 +1244,9 @@ bx_bool bx_real_sim_c::restore_bochs_param(bx_list_c *root, const char *sr_path,
|
||||
}
|
||||
switch (param->get_type()) {
|
||||
case BXT_PARAM_NUM:
|
||||
if (((bx_param_num_c*)param)->get_base() == BASE_DOUBLE) {
|
||||
f2value = strtod(ptr, NULL);
|
||||
memcpy(&value, &f2value, sizeof(double));
|
||||
((bx_param_num_c*)param)->set(value);
|
||||
} else if (((bx_param_num_c*)param)->get_base() == BASE_FLOAT) {
|
||||
f1value = (float)strtod(ptr, NULL);
|
||||
memcpy(&value, &f1value, sizeof(float));
|
||||
((bx_param_num_c*)param)->set(value);
|
||||
} else if ((ptr[0] == '0') && (ptr[1] == 'x')) {
|
||||
((bx_param_num_c*)param)->set(strtoull(ptr, NULL, 16));
|
||||
} else {
|
||||
((bx_param_num_c*)param)->set(strtoull(ptr, NULL, 10));
|
||||
}
|
||||
break;
|
||||
case BXT_PARAM_BOOL:
|
||||
((bx_param_bool_c*)param)->set(!strcmp(ptr, "true"));
|
||||
break;
|
||||
case BXT_PARAM_ENUM:
|
||||
((bx_param_enum_c*)param)->set_by_name(ptr);
|
||||
param->parse_param(ptr);
|
||||
break;
|
||||
case BXT_PARAM_STRING:
|
||||
{
|
||||
@ -1373,9 +1354,6 @@ bx_bool bx_real_sim_c::restore_hardware()
|
||||
bx_bool bx_real_sim_c::save_sr_param(FILE *fp, bx_param_c *node, const char *sr_path, int level)
|
||||
{
|
||||
int i, j;
|
||||
Bit64s value;
|
||||
float f1value;
|
||||
double f2value;
|
||||
char pname[BX_PATHNAME_LEN], tmpstr[BX_PATHNAME_LEN];
|
||||
FILE *fp2;
|
||||
|
||||
@ -1388,45 +1366,11 @@ bx_bool bx_real_sim_c::save_sr_param(FILE *fp, bx_param_c *node, const char *sr_
|
||||
fprintf(fp, "%s = ", node->get_name());
|
||||
switch (node->get_type()) {
|
||||
case BXT_PARAM_NUM:
|
||||
value = ((bx_param_num_c*)node)->get64();
|
||||
if (((bx_param_num_c*)node)->get_base() == BASE_DOUBLE) {
|
||||
memcpy(&f2value, &value, sizeof(double));
|
||||
fprintf(fp, "%f\n", f2value);
|
||||
} else if (((bx_param_num_c*)node)->get_base() == BASE_FLOAT) {
|
||||
memcpy(&f1value, &value, sizeof(float));
|
||||
fprintf(fp, "%f\n", f1value);
|
||||
} else if (((bx_param_num_c*)node)->get_base() == BASE_DEC) {
|
||||
if (((bx_param_num_c*)node)->get_min() >= BX_MIN_BIT64U) {
|
||||
if ((Bit64u)((bx_param_num_c*)node)->get_max() > BX_MAX_BIT32U) {
|
||||
fprintf(fp, FMT_LL"u\n", value);
|
||||
} else {
|
||||
fprintf(fp, "%u\n", (Bit32u) value);
|
||||
}
|
||||
} else {
|
||||
fprintf(fp, "%d\n", (Bit32s) value);
|
||||
}
|
||||
} else {
|
||||
if (node->get_format()) {
|
||||
fprintf(fp, node->get_format(), value);
|
||||
} else {
|
||||
if ((Bit64u)((bx_param_num_c*)node)->get_max() > BX_MAX_BIT32U) {
|
||||
fprintf(fp, "0x" FMT_LL "x", (Bit64u) value);
|
||||
} else {
|
||||
fprintf(fp, "0x%x", (Bit32u) value);
|
||||
}
|
||||
}
|
||||
fprintf(fp, "\n");
|
||||
}
|
||||
break;
|
||||
case BXT_PARAM_BOOL:
|
||||
fprintf(fp, "%s\n", ((bx_param_bool_c*)node)->get()?"true":"false");
|
||||
break;
|
||||
case BXT_PARAM_ENUM:
|
||||
fprintf(fp, "%s\n", ((bx_param_enum_c*)node)->get_selected());
|
||||
break;
|
||||
case BXT_PARAM_STRING:
|
||||
((bx_param_string_c*)node)->sprint(tmpstr, BX_PATHNAME_LEN, 0);
|
||||
fprintf(fp, "%s\n", tmpstr);
|
||||
node->dump_param(fp);
|
||||
fprintf(fp, "\n");
|
||||
break;
|
||||
case BXT_PARAM_DATA:
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user