mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-12-23 17:55:31 +02:00
100 lines
2.5 KiB
C
100 lines
2.5 KiB
C
/*
|
|
* 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 "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;
|
|
int fract; /* 0: abs. offset; 1: fract. offs. */
|
|
} rel;
|
|
} u;
|
|
};
|
|
|
|
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 register_nameset(const char *name, const struct names *set);
|
|
const struct names *find_nameset(const char *name);
|
|
|
|
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);
|
|
|
|
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 */
|