2012-04-25 23:14:39 +03:00
|
|
|
/*
|
|
|
|
* dump.c - Dump a value (for debugging)
|
|
|
|
*
|
|
|
|
* Copyright 2012 by Werner Almesberger
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "bitset.h"
|
|
|
|
#include "param.h"
|
|
|
|
|
|
|
|
|
|
|
|
void dump_name(FILE *file, const struct format *fmt, const struct value *v)
|
|
|
|
{
|
2012-05-24 00:48:59 +03:00
|
|
|
(void) fmt;
|
2012-05-21 20:44:33 +03:00
|
|
|
fprintf(file, "%s", v->u.s);
|
2012-04-25 23:14:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void dump_set(FILE *file, const struct format *fmt, const struct value *v)
|
|
|
|
{
|
|
|
|
const struct names *name;
|
|
|
|
int first = 1;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
for (name = fmt->u.set; name; name = name->next) {
|
|
|
|
if (bitset_get(&v->u.set, i)) {
|
|
|
|
fprintf(file, "%s%s", first ? "" : "|",
|
|
|
|
name->equiv->name);
|
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void dump_abs(FILE *file, const struct format *fmt, const struct value *v)
|
|
|
|
{
|
2012-06-01 06:20:31 +03:00
|
|
|
fprintf(file, "%g%s", v->u.abs, fmt->u.abs ? fmt->u.abs : "");
|
2012-04-25 23:14:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void dump_rel(FILE *file, const struct format *fmt, const struct value *v)
|
|
|
|
{
|
|
|
|
if (v->u.rel.fract)
|
2012-05-31 21:47:35 +03:00
|
|
|
fprintf(file, "-%g/+%g%%",
|
2012-04-25 23:14:39 +03:00
|
|
|
v->u.rel.minus*100, v->u.rel.plus*100);
|
|
|
|
else
|
|
|
|
fprintf(file, "-%g/+%g%s",
|
2012-06-01 06:20:31 +03:00
|
|
|
v->u.rel.minus, v->u.rel.plus,
|
|
|
|
fmt->u.rel->u.abs ? fmt->u.rel->u.abs : "");
|
2012-04-25 23:14:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-02 11:18:14 +03:00
|
|
|
void dump_param(FILE *file, const struct format *fmt, const struct value *v)
|
2012-04-25 23:14:39 +03:00
|
|
|
{
|
|
|
|
fmt->ops->dump(file, fmt, v);
|
|
|
|
}
|