1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-11-30 02:03:45 +02:00

b2/: assigments to can express inequalities

This commit is contained in:
Werner Almesberger 2012-05-20 23:16:51 -03:00
parent a34702cd8d
commit 6fd5313917
8 changed files with 42 additions and 20 deletions

View File

@ -1,8 +1,8 @@
REF=R[0-9]* { REF=R[0-9]* {
T=R T=R
VAL=(#R) { R=$1 } VAL=(#R) { R=$1 }
TOL = 5% TOL <= 5%
FN=*% { TOL=$$ } FN=*% { TOL<=$$ }
break REF break REF
// end break again // end break again
} }

View File

@ -16,6 +16,7 @@
#include "util.h" #include "util.h"
#include "lang.h" #include "lang.h"
#include "param.h"
#include "subex.h" #include "subex.h"
@ -33,7 +34,7 @@ static void add_var(const char *arg)
exit(1); exit(1);
} }
*eq = 0; *eq = 0;
*last_var = make_var(tmp, eq+1); *last_var = make_var(tmp, rel_eq, eq+1);
last_var = &(*last_var)->next; last_var = &(*last_var)->next;
} }
@ -44,8 +45,11 @@ static void do_substitutions(void)
const struct var *var; const struct var *var;
out = substitute(substitutions, vars); out = substitute(substitutions, vars);
for (var = out; var; var = var->next) for (var = out; var; var = var->next) {
printf("%s=%s\n", var->name, var->value); printf("%s", var->name);
dump_relop(stdout, var->op);
printf("%s\n", var->value);
}
free_vars(out); free_vars(out);
} }

View File

@ -126,12 +126,16 @@ PAT "\\"[^\t\n]|[^ \t\n\\]
yylval.s = stralloc(yytext); yylval.s = stralloc(yytext);
return PATTERN; } return PATTERN; }
"=" { if (pattern) [<>=] { if (pattern)
BEGIN(PAT); BEGIN(PAT);
return '='; } return *yytext; }
"<=" return TOK_LE; "<=" { if (pattern)
">=" return TOK_GE; BEGIN(PAT);
return TOK_LE; }
">=" { if (pattern)
BEGIN(PAT);
return TOK_GE; }
"//"[^\n]* ; "//"[^\n]* ;
"/*"([^*]|("*"+([^*/])))*"*"+"/" { const char *s = yytext; "/*"([^*]|("*"+([^*/])))*"*"+"/" { const char *s = yytext;

View File

@ -587,13 +587,15 @@ block:
{ {
$$ = NULL; $$ = NULL;
} }
| WORD '=' PATTERN opt_block block | WORD relop PATTERN opt_block block
{ {
if ($4) { if ($4) {
if ($2 != rel_eq)
yyerror("only = allow for matching");
$$ = subst_match($1, $3); $$ = subst_match($1, $3);
$$->u.match.block = $4; $$->u.match.block = $4;
} else { } else {
$$ = subst_assign($1, $3); $$ = subst_assign($1, $2, $3);
} }
free((void *) $3); free((void *) $3);
$$->next = $5; $$->next = $5;

View File

@ -21,6 +21,7 @@
#include "util.h" #include "util.h"
#include "vstring.h" #include "vstring.h"
#include "lang.h" #include "lang.h"
#include "relop.h"
#include "subst.h" #include "subst.h"
#include "subex.h" #include "subex.h"
@ -138,19 +139,21 @@ static char *compose(const struct chunk *c,
} }
struct var *make_var(const char *name, const char *val) struct var *make_var(const char *name, enum relop op, const char *val)
{ {
struct var *var; struct var *var;
var = alloc_type(struct var); var = alloc_type(struct var);
var->name = unique(name); var->name = unique(name);
var->op = op;
var->value = unique(val); var->value = unique(val);
var->next = NULL; var->next = NULL;
return var; return var;
} }
static void do_assign(const char *name, struct var **out, const char *val) static void do_assign(const char *name, struct var **out, enum relop op,
const char *val)
{ {
while (*out) { while (*out) {
if ((*out)->name == name) if ((*out)->name == name)
@ -161,7 +164,7 @@ static void do_assign(const char *name, struct var **out, const char *val)
free((void *) (*out)->value); free((void *) (*out)->value);
(*out)->value = val; (*out)->value = val;
} else { } else {
*out = make_var(name, val); *out = make_var(name, op, val);
} }
} }
@ -217,7 +220,8 @@ static const struct subst *recurse_sub(const struct subst *sub,
case st_assign: case st_assign:
tmp = compose(sub->u.assign.pat, in, *out, s, match, tmp = compose(sub->u.assign.pat, in, *out, s, match,
units); units);
do_assign(sub->u.assign.dst, out, tmp); do_assign(sub->u.assign.dst, out, sub->u.assign.op,
tmp);
break; break;
case st_end: case st_end:
return &jump_end; return &jump_end;

View File

@ -13,18 +13,20 @@
#ifndef SUBEX_H #ifndef SUBEX_H
#define SUBEX_H #define SUBEX_H
#include "relop.h"
#include "subst.h" #include "subst.h"
struct var { struct var {
const char *name; const char *name;
enum relop op;
const char *value; const char *value;
struct var *next; struct var *next;
}; };
struct var *substitute(const struct subst *sub, const struct var *in); struct var *substitute(const struct subst *sub, const struct var *in);
struct var *make_var(const char *name, const char *val); struct var *make_var(const char *name, enum relop op, const char *val);
const char *var_lookup(const struct var *vars, const char *name); const char *var_lookup(const struct var *vars, const char *name);
void free_vars(struct var *vars); void free_vars(struct var *vars);

View File

@ -21,6 +21,7 @@
#include "util.h" #include "util.h"
#include "vstring.h" #include "vstring.h"
#include "lang.h" #include "lang.h"
#include "relop.h"
#include "subst.h" #include "subst.h"
@ -226,12 +227,13 @@ static struct chunk *parse_pattern(const char *s)
} }
struct subst *subst_assign(const char *dst, const char *pat) struct subst *subst_assign(const char *dst, enum relop op, const char *pat)
{ {
struct subst *sub; struct subst *sub;
sub = alloc_subst(st_assign); sub = alloc_subst(st_assign);
sub->u.assign.dst = dst; sub->u.assign.dst = dst;
sub->u.assign.op = op;
sub->u.assign.pat = parse_pattern(pat); sub->u.assign.pat = parse_pattern(pat);
return sub; return sub;
} }
@ -358,7 +360,8 @@ static void recurse_dump(FILE *file, const struct subst *sub, int level)
fprintf(file, "%*s}\n", INDENT*level, ""); fprintf(file, "%*s}\n", INDENT*level, "");
break; break;
case st_assign: case st_assign:
fprintf(file, "%s=", sub->u.assign.dst); fprintf(file, "%s", sub->u.assign.dst);
dump_relop(file, sub->u.assign.op);
dump_chunks(file, sub->u.assign.pat); dump_chunks(file, sub->u.assign.pat);
fprintf(file, "\n"); fprintf(file, "\n");
break; break;

View File

@ -17,6 +17,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <regex.h> #include <regex.h>
#include "relop.h"
enum chunk_type { enum chunk_type {
ct_string, ct_string,
@ -53,6 +55,7 @@ struct subst {
} match; } match;
struct { struct {
const char *dst; const char *dst;
enum relop op;
struct chunk *pat; struct chunk *pat;
} assign; } assign;
const struct subst *jump; const struct subst *jump;
@ -66,7 +69,7 @@ struct subst {
struct subst *subst_match(const char *src, const char *re); struct subst *subst_match(const char *src, const char *re);
struct subst *subst_assign(const char *dst, const char *pat); struct subst *subst_assign(const char *dst, enum relop op, const char *pat);
struct subst *subst_end(void); struct subst *subst_end(void);
struct subst *subst_break(const char *block); struct subst *subst_break(const char *block);
struct subst *subst_again(const char *block); struct subst *subst_again(const char *block);