1
0
mirror of git://projects.qi-hardware.com/eda-tools.git synced 2024-12-23 06:02:03 +02:00

b2/: move relational operators to relop.[ch] (for sharing)

This also fixes a bug in dump_one_field, which switched > and >=
This commit is contained in:
Werner Almesberger 2012-05-20 23:04:41 -03:00
parent 99e5777448
commit a34702cd8d
5 changed files with 76 additions and 27 deletions

View File

@ -13,7 +13,8 @@ SHELL = /bin/bash
CFLAGS = -g -Wall $(shell pkg-config --cflags glib-2.0)
SLOPPY = -Wno-unused -Wno-implicit-function-declaration
OBJS = boom.o chr.o comp.o db.o dump.o eval.o param.o subex.o subst.o util.o \
OBJS = boom.o chr.o comp.o db.o dump.o eval.o param.o relop.o \
subex.o subst.o util.o \
vstring.o lex.yy.o y.tab.o
LDLIBS = -lfl $(shell pkg-config --libs glib-2.0)

View File

@ -14,6 +14,7 @@
#include "util.h"
#include "lang.h"
#include "relop.h"
#include "param.h"
#include "chr.h"
@ -157,24 +158,8 @@ static void dump_one_field(FILE *file, const struct field *field, int level)
for (cond = sel->cond; cond; cond = cond->next) {
if (cond != sel->cond)
fprintf(file, "|");
switch (cond->relop) {
case rel_lt:
fprintf(file, "<");
break;
case rel_le:
fprintf(file, "<=");
break;
case rel_eq:
break;
case rel_ge:
fprintf(file, ">");
break;
case rel_gt:
fprintf(file, ">=");
break;
default:
fprintf(file, "?");
}
if (cond->relop != rel_eq)
dump_relop(file, cond->relop);
dump(file, field->fmt, &cond->value);
}
fprintf(file, ": ");

View File

@ -16,6 +16,7 @@
#include <stdio.h>
#include "bitset.h"
#include "relop.h"
/*
@ -28,14 +29,6 @@
*/
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;

40
b2/relop.c Normal file
View File

@ -0,0 +1,40 @@
/*
* relop.c - Relational operators
*
* 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 <stdlib.h>
#include <stdio.h>
#include "relop.h"
void dump_relop(FILE *file, enum relop op)
{
switch (op) {
case rel_lt:
fprintf(file, "<");
break;
case rel_le:
fprintf(file, "<=");
break;
case rel_eq:
fprintf(file, "=");
break;
case rel_ge:
fprintf(file, ">=");
break;
case rel_gt:
fprintf(file, ">");
break;
default:
abort();
}
}

30
b2/relop.h Normal file
View File

@ -0,0 +1,30 @@
/*
* relop.h - Relational operators
*
* 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 RELOP_H
#define RELOP_H
#include <stdio.h>
enum relop {
rel_lt = 1 << 0,
rel_le = 1 << 1,
rel_eq = 1 << 2,
rel_ge = 1 << 3,
rel_gt = 1 << 4,
};
void dump_relop(FILE *file, enum relop op);
#endif /* !RELOP_H */