mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-04 23:43:43 +02:00
64 lines
1.3 KiB
C
64 lines
1.3 KiB
C
|
/*
|
||
|
* 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)
|
||
|
{
|
||
|
fprintf(file, "%s", v->u.name);
|
||
|
}
|
||
|
|
||
|
|
||
|
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)
|
||
|
{
|
||
|
fprintf(file, "%g%s", v->u.abs, fmt->u.abs);
|
||
|
}
|
||
|
|
||
|
|
||
|
void dump_rel(FILE *file, const struct format *fmt, const struct value *v)
|
||
|
{
|
||
|
if (v->u.rel.fract)
|
||
|
fprintf(file, "-%f/+%f%%",
|
||
|
v->u.rel.minus*100, v->u.rel.plus*100);
|
||
|
else
|
||
|
fprintf(file, "-%g/+%g%s",
|
||
|
v->u.rel.minus, v->u.rel.plus, fmt->u.rel->u.abs);
|
||
|
}
|
||
|
|
||
|
|
||
|
void dump(FILE *file, const struct format *fmt, const struct value *v)
|
||
|
{
|
||
|
fmt->ops->dump(file, fmt, v);
|
||
|
}
|