1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-25 19:41:54 +02:00
eda-tools/b2/param.h

127 lines
3.6 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"
#include "relop.h"
2012-03-18 18:24:12 +02:00
/*
* Parameter types:
*
* "name" arbitrary name
* "set" names from an ordered list
* "abs" absolute numeric value
* "rel" numeric value relative to another parameter
*/
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; NULL if dimensionless */
2012-03-18 18:24:12 +02:00
const struct format *rel;
} u;
};
struct value {
union {
const char *s;
2012-03-18 18:24:12 +02:00
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;
};
/*
* When using "struct param" to store (string) variables not associated to a
* field, then u.name contains the variable name, "op" contains the relational
* operator (default rel_eq), and value.u.s contains the variable's value.
*
* If the variable is "$", then u.name is set to NULL.
*/
struct param {
union {
const char *name;
const struct field *field;
} u;
enum relop op;
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_param(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;
struct param *make_var(const char *name, enum relop op, const char *val);
const char *var_lookup(const struct param *vars, const char *name);
struct param *merge_vars(const struct param *a, const struct param *b);
void free_vars(struct param *vars);
2012-03-18 18:24:12 +02:00
#endif /* !PARAM_H */