1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-30 05:10:38 +02:00
eda-tools/b2/param.h

120 lines
3.1 KiB
C
Raw Normal View History

2012-03-18 18:24:12 +02:00
/*
* param.h - Parameters and values
*
* 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.
*/
#ifndef PARAM_H
#define PARAM_H
#include <stdio.h>
2012-03-18 18:24:12 +02:00
#include "bitset.h"
/*
* Parameter types:
*
* "name" arbitrary name
* "set" names from an ordered list
* "abs" absolute numeric value
* "rel" numeric value relative to another parameter
*/
enum relop {
rel_lt = 1 << 0,
rel_le = 1 << 1,
rel_eq = 1 << 2,
rel_ge = 1 << 3,
rel_gt = 1 << 4,
};
struct equiv {
const char *name;
struct equiv *next;
};
struct names {
struct equiv *equiv; /* equivalent value(s) */
struct names *next; /* next/greater value */
};
struct param_ops;
struct format {
const struct param_ops *ops;
union {
const struct names *set;
const char *abs; /* unit name */
const struct format *rel;
} u;
};
struct value {
union {
const char *name;
struct bitset set;
double abs;
struct rel_value {
double plus, minus; /* rel: 100% = 1 */
2012-03-18 18:24:12 +02:00
int fract; /* 0: abs. offset; 1: fract. offs. */
} rel;
} u;
};
struct param {
union {
const char *name;
const struct field *field;
} u;
struct value value;
struct param *next;
};
2012-03-18 18:24:12 +02:00
struct param_ops {
int (*eval)(const struct format *fmt, const char *s,
struct value *res);
int (*comp)(const struct value *a, enum relop relop,
const struct value *b);
void (*dump)(FILE *file, const struct format *fmt,
const struct value *v);
2012-03-18 18:24:12 +02:00
};
void register_nameset(const char *name, const struct names *set);
const struct names *find_nameset(const char *name);
const char *nameset_rev_lookup(const struct names *first_name);
2012-03-18 18:24:12 +02:00
int eval_name(const struct format *fmt, const char *s, struct value *res);
int eval_set(const struct format *fmt, const char *s, struct value *res);
int eval_abs(const struct format *fmt, const char *s, struct value *res);
int eval_rel(const struct format *fmt, const char *s, struct value *res);
int evaluate(const struct format *fmt, const char *s, struct value *res);
int comp_name(const struct value *a, enum relop relop, const struct value *b);
int comp_set(const struct value *a, enum relop relop, const struct value *b);
int comp_abs(const struct value *a, enum relop relop, const struct value *b);
int comp_rel(const struct value *a, enum relop relop, const struct value *b);
int compare(const struct format *fmt,
const struct value *a, enum relop relop, const struct value *b);
void dump_name(FILE *file, const struct format *fmt, const struct value *v);
void dump_set(FILE *file, const struct format *fmt, const struct value *v);
void dump_abs(FILE *file, const struct format *fmt, const struct value *v);
void dump_rel(FILE *file, const struct format *fmt, const struct value *v);
void dump(FILE *file, const struct format *fmt, const struct value *v);
2012-03-18 18:24:12 +02:00
extern const struct param_ops param_ops_name;
extern const struct param_ops param_ops_set;
extern const struct param_ops param_ops_abs;
extern const struct param_ops param_ops_rel;
#endif /* !PARAM_H */