abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cvrin.c File Reference
#include <ctype.h>
#include "espresso.h"

Go to the source code of this file.

Functions

void skip_line (FILE *fpin, FILE *fpout, bool echo)
 
char * get_word (FILE *fp, char *word)
 
void read_cube (FILE *fp, pPLA PLA)
 
void parse_pla (IN FILE *fp, INOUT pPLA PLA)
 
int read_pla (IN FILE *fp, IN bool needs_dcset, IN bool needs_offset, IN int pla_type, OUT pPLA *PLA_return)
 
void PLA_summary (pPLA PLA)
 
pPLA new_PLA ()
 
void PLA_labels (pPLA PLA)
 
void free_PLA (pPLA PLA)
 
int read_symbolic (FILE *fp, pPLA PLA, char *word, symbolic_t **retval)
 
int label_index (pPLA PLA, char *word, int *varp, int *ip)
 

Variables

static
ABC_NAMESPACE_IMPL_START bool 
line_length_error
 
static int lineno
 

Function Documentation

void free_PLA ( pPLA  PLA)

Definition at line 676 of file cvrin.c.

678 {
679  symbolic_list_t *p2, *p2next;
680  symbolic_t *p1, *p1next;
681  int i;
682 
683  if (PLA->F != (pcover) NULL)
684  free_cover(PLA->F);
685  if (PLA->R != (pcover) NULL)
686  free_cover(PLA->R);
687  if (PLA->D != (pcover) NULL)
688  free_cover(PLA->D);
689  if (PLA->phase != (pcube) NULL)
690  free_cube(PLA->phase);
691  if (PLA->pair != (ppair) NULL) {
692  FREE(PLA->pair->var1);
693  FREE(PLA->pair->var2);
694  FREE(PLA->pair);
695  }
696  if (PLA->label != NULL) {
697  for(i = 0; i < cube.size; i++)
698  if (PLA->label[i] != NULL)
699  FREE(PLA->label[i]);
700  FREE(PLA->label);
701  }
702  if (PLA->filename != NULL) {
703  FREE(PLA->filename);
704  }
705  for(p1 = PLA->symbolic; p1 != NIL(symbolic_t); p1 = p1next) {
706  for(p2 = p1->symbolic_list; p2 != NIL(symbolic_list_t); p2 = p2next) {
707  p2next = p2->next;
708  FREE(p2);
709  }
710  p1next = p1->next;
711  FREE(p1);
712  }
713  PLA->symbolic = NIL(symbolic_t);
714  for(p1 = PLA->symbolic_output; p1 != NIL(symbolic_t); p1 = p1next) {
715  for(p2 = p1->symbolic_list; p2 != NIL(symbolic_list_t); p2 = p2next) {
716  p2next = p2->next;
717  FREE(p2);
718  }
719  p1next = p1->next;
720  FREE(p1);
721  }
723  FREE(PLA);
724 }
ppair pair
Definition: espresso.h:320
#define free_cover(r)
Definition: espresso.h:266
#define pcover
Definition: espresso.h:264
symbolic_list_t * symbolic_list
Definition: espresso.h:306
#define free_cube(r)
Definition: espresso.h:263
int * var2
Definition: espresso.h:285
#define NIL(type)
Definition: avl.h:25
symbolic_t * symbolic
Definition: espresso.h:322
char * filename
Definition: espresso.h:317
struct symbolic_list_struct * next
Definition: espresso.h:293
#define FREE(obj)
Definition: avl.h:31
pcover F
Definition: espresso.h:316
int * var1
Definition: espresso.h:284
pcube phase
Definition: espresso.h:319
pcover D
Definition: espresso.h:316
pcover R
Definition: espresso.h:316
symbolic_t * symbolic_output
Definition: espresso.h:323
char ** label
Definition: espresso.h:321
#define pcube
Definition: espresso.h:261
struct symbolic_struct * next
Definition: espresso.h:310
char* get_word ( FILE *  fp,
char *  word 
)

Definition at line 37 of file cvrin.c.

40 {
41  register int ch, i = 0;
42  while ((ch = getc(fp)) != EOF && isspace(ch))
43  ;
44  word[i++] = ch;
45  while ((ch = getc(fp)) != EOF && ! isspace(ch))
46  word[i++] = ch;
47  word[i++] = '\0';
48  return word;
49 }
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
int label_index ( pPLA  PLA,
char *  word,
int *  varp,
int *  ip 
)

Definition at line 789 of file cvrin.c.

794 {
795  int var, i;
796 
797  if (PLA->label == NIL(char *) || PLA->label[0] == NIL(char)) {
798  if (sscanf(word, "%d", varp) == 1) {
799  *ip = *varp;
800  return TRUE;
801  }
802  } else {
803  for(var = 0; var < cube.num_vars; var++) {
804  for(i = 0; i < cube.part_size[var]; i++) {
805  if (equal(PLA->label[cube.first_part[var]+i], word)) {
806  *varp = var;
807  *ip = i;
808  return TRUE;
809  }
810  }
811  }
812  }
813  return FALSE;
814 }
#define FALSE
Definition: cudd.h:91
int var(Lit p)
Definition: SolverTypes.h:62
#define NIL(type)
Definition: avl.h:25
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
#define TRUE
Definition: cudd.h:88
char ** label
Definition: espresso.h:321
#define equal(a, b)
Definition: espresso.h:326
pPLA new_PLA ( )

Definition at line 648 of file cvrin.c.

649 {
650  pPLA PLA;
651 
652  PLA = ALLOC(PLA_t, 1);
653  PLA->F = PLA->D = PLA->R = (pcover) NULL;
654  PLA->phase = (pcube) NULL;
655  PLA->pair = (ppair) NULL;
656  PLA->label = (char **) NULL;
657  PLA->filename = (char *) NULL;
658  PLA->pla_type = 0;
659  PLA->symbolic = NIL(symbolic_t);
661  return PLA;
662 }
ppair pair
Definition: espresso.h:320
#define pcover
Definition: espresso.h:264
#define NIL(type)
Definition: avl.h:25
symbolic_t * symbolic
Definition: espresso.h:322
char * filename
Definition: espresso.h:317
#define ALLOC(type, num)
Definition: avl.h:27
pcover F
Definition: espresso.h:316
int pla_type
Definition: espresso.h:318
pcube phase
Definition: espresso.h:319
pcover D
Definition: espresso.h:316
pcover R
Definition: espresso.h:316
struct pair_struct * ppair
symbolic_t * symbolic_output
Definition: espresso.h:323
char ** label
Definition: espresso.h:321
#define pcube
Definition: espresso.h:261
void parse_pla ( IN FILE *  fp,
INOUT pPLA  PLA 
)

Definition at line 208 of file cvrin.c.

211 {
212  int i, var, ch, np, last;
213  char word[256];
214 
215  lineno = 1;
217 
218 loop:
219  switch(ch = getc(fp)) {
220  case EOF:
221  return;
222 
223  case '\n':
224  lineno++;
225 
226  case ' ': case '\t': case '\f': case '\r':
227  break;
228 
229  case '#':
230  (void) ungetc(ch, fp);
231  skip_line(fp, stdout, echo_comments);
232  break;
233 
234  case '.':
235  /* .i gives the cube input size (binary-functions only) */
236  if (equal(get_word(fp, word), "i")) {
237  if (cube.fullset != NULL) {
238  (void) fprintf(stderr, "extra .i ignored\n");
239  skip_line(fp, stdout, /* echo */ FALSE);
240  } else {
241  if (fscanf(fp, "%d", &cube.num_binary_vars) != 1)
242  fatal("error reading .i");
243  cube.num_vars = cube.num_binary_vars + 1;
244  cube.part_size = ALLOC(int, cube.num_vars);
245  }
246 
247  /* .o gives the cube output size (binary-functions only) */
248  } else if (equal(word, "o")) {
249  if (cube.fullset != NULL) {
250  (void) fprintf(stderr, "extra .o ignored\n");
251  skip_line(fp, stdout, /* echo */ FALSE);
252  } else {
253  if (cube.part_size == NULL)
254  fatal(".o cannot appear before .i");
255  if (fscanf(fp, "%d", &(cube.part_size[cube.num_vars-1]))!=1)
256  fatal("error reading .o");
257  cube_setup();
258  PLA_labels(PLA);
259  }
260 
261  /* .mv gives the cube size for a multiple-valued function */
262  } else if (equal(word, "mv")) {
263  if (cube.fullset != NULL) {
264  (void) fprintf(stderr, "extra .mv ignored\n");
265  skip_line(fp, stdout, /* echo */ FALSE);
266  } else {
267  if (cube.part_size != NULL)
268  fatal("cannot mix .i and .mv");
269  if (fscanf(fp,"%d %d",
270  &cube.num_vars,&cube.num_binary_vars) != 2)
271  fatal("error reading .mv");
272  if (cube.num_binary_vars < 0)
273 fatal("num_binary_vars (second field of .mv) cannot be negative");
274  if (cube.num_vars < cube.num_binary_vars)
275  fatal(
276 "num_vars (1st field of .mv) must exceed num_binary_vars (2nd field of .mv)");
277  cube.part_size = ALLOC(int, cube.num_vars);
278  for(var=cube.num_binary_vars; var < cube.num_vars; var++)
279  if (fscanf(fp, "%d", &(cube.part_size[var])) != 1)
280  fatal("error reading .mv");
281  cube_setup();
282  PLA_labels(PLA);
283  }
284 
285  /* .p gives the number of product terms -- we ignore it */
286  } else if (equal(word, "p"))
287  (void) fscanf(fp, "%d", &np);
288  /* .e and .end specify the end of the file */
289  else if (equal(word, "e") || equal(word,"end")) {
290  if (cube.fullset == NULL) {
291  /* fatal("unknown PLA size, need .i/.o or .mv");*/
292  } else if (PLA->F == NULL) {
293  PLA->F = new_cover(10);
294  PLA->D = new_cover(10);
295  PLA->R = new_cover(10);
296  }
297  return;
298  }
299  /* .kiss turns on the kiss-hack option */
300  else if (equal(word, "kiss"))
301  kiss = TRUE;
302 
303  /* .type specifies a logical type for the PLA */
304  else if (equal(word, "type")) {
305  (void) get_word(fp, word);
306  for(i = 0; pla_types[i].key != 0; i++)
307  if (equal(pla_types[i].key + 1, word)) {
308  PLA->pla_type = pla_types[i].value;
309  break;
310  }
311  if (pla_types[i].key == 0)
312  fatal("unknown type in .type command");
313 
314  /* parse the labels */
315  } else if (equal(word, "ilb")) {
316  if (cube.fullset == NULL)
317  fatal("PLA size must be declared before .ilb or .ob");
318  if (PLA->label == NULL)
319  PLA_labels(PLA);
320  for(var = 0; var < cube.num_binary_vars; var++) {
321  (void) get_word(fp, word);
322  i = cube.first_part[var];
323  PLA->label[i+1] = util_strsav(word);
324  PLA->label[i] = ALLOC(char, strlen(word) + 6);
325  (void) sprintf(PLA->label[i], "%s.bar", word);
326  }
327  } else if (equal(word, "ob")) {
328  if (cube.fullset == NULL)
329  fatal("PLA size must be declared before .ilb or .ob");
330  if (PLA->label == NULL)
331  PLA_labels(PLA);
332  var = cube.num_vars - 1;
333  for(i = cube.first_part[var]; i <= cube.last_part[var]; i++) {
334  (void) get_word(fp, word);
335  PLA->label[i] = util_strsav(word);
336  }
337  /* .label assigns labels to multiple-valued variables */
338  } else if (equal(word, "label")) {
339  if (cube.fullset == NULL)
340  fatal("PLA size must be declared before .label");
341  if (PLA->label == NULL)
342  PLA_labels(PLA);
343  if (fscanf(fp, "var=%d", &var) != 1)
344  fatal("Error reading labels");
345  for(i = cube.first_part[var]; i <= cube.last_part[var]; i++) {
346  (void) get_word(fp, word);
347  PLA->label[i] = util_strsav(word);
348  }
349 
350  } else if (equal(word, "symbolic")) {
351  symbolic_t *newlist, *p1;
352  if (read_symbolic(fp, PLA, word, &newlist)) {
353  if (PLA->symbolic == NIL(symbolic_t)) {
354  PLA->symbolic = newlist;
355  } else {
356  for(p1=PLA->symbolic;p1->next!=NIL(symbolic_t);
357  p1=p1->next){
358  }
359  p1->next = newlist;
360  }
361  } else {
362  fatal("error reading .symbolic");
363  }
364 
365  } else if (equal(word, "symbolic-output")) {
366  symbolic_t *newlist, *p1;
367  if (read_symbolic(fp, PLA, word, &newlist)) {
368  if (PLA->symbolic_output == NIL(symbolic_t)) {
369  PLA->symbolic_output = newlist;
370  } else {
371  for(p1=PLA->symbolic_output;p1->next!=NIL(symbolic_t);
372  p1=p1->next){
373  }
374  p1->next = newlist;
375  }
376  } else {
377  fatal("error reading .symbolic-output");
378  }
379 
380  /* .phase allows a choice of output phases */
381  } else if (equal(word, "phase")) {
382  if (cube.fullset == NULL)
383  fatal("PLA size must be declared before .phase");
384  if (PLA->phase != NULL) {
385  (void) fprintf(stderr, "extra .phase ignored\n");
386  skip_line(fp, stdout, /* echo */ FALSE);
387  } else {
388  do ch = getc(fp); while (ch == ' ' || ch == '\t');
389  (void) ungetc(ch, fp);
390  PLA->phase = set_save(cube.fullset);
391  last = cube.last_part[cube.num_vars - 1];
392  for(i=cube.first_part[cube.num_vars - 1]; i <= last; i++)
393  if ((ch = getc(fp)) == '0')
394  set_remove(PLA->phase, i);
395  else if (ch != '1')
396  fatal("only 0 or 1 allowed in phase description");
397  }
398 
399  /* .pair allows for bit-pairing input variables */
400  } else if (equal(word, "pair")) {
401  int j;
402  if (PLA->pair != NULL) {
403  (void) fprintf(stderr, "extra .pair ignored\n");
404  } else {
405  ppair pair;
406  PLA->pair = pair = ALLOC(pair_t, 1);
407  if (fscanf(fp, "%d", &(pair->cnt)) != 1)
408  fatal("syntax error in .pair");
409  pair->var1 = ALLOC(int, pair->cnt);
410  pair->var2 = ALLOC(int, pair->cnt);
411  for(i = 0; i < pair->cnt; i++) {
412  (void) get_word(fp, word);
413  if (word[0] == '(') (void) strcpy(word, word+1);
414  if (label_index(PLA, word, &var, &j)) {
415  pair->var1[i] = var+1;
416  } else {
417  fatal("syntax error in .pair");
418  }
419 
420  (void) get_word(fp, word);
421  if (word[strlen(word)-1] == ')') {
422  word[strlen(word)-1]='\0';
423  }
424  if (label_index(PLA, word, &var, &j)) {
425  pair->var2[i] = var+1;
426  } else {
427  fatal("syntax error in .pair");
428  }
429  }
430  }
431 
432  } else {
434  printf("%c%s ", ch, word);
435  skip_line(fp, stdout, echo_unknown_commands);
436  }
437  break;
438  default:
439  (void) ungetc(ch, fp);
440  if (cube.fullset == NULL) {
441 /* fatal("unknown PLA size, need .i/.o or .mv");*/
442  if (echo_comments)
443  putchar('#');
444  skip_line(fp, stdout, echo_comments);
445  break;
446  }
447  if (PLA->F == NULL) {
448  PLA->F = new_cover(10);
449  PLA->D = new_cover(10);
450  PLA->R = new_cover(10);
451  }
452  read_cube(fp, PLA);
453  }
454  goto loop;
455 }
void skip_line(FILE *fpin, FILE *fpout, bool echo)
Definition: cvrin.c:24
void PLA_labels(pPLA PLA)
Definition: cvrin.c:665
void fatal(char *s)
Definition: cvrmisc.c:140
#define FALSE
Definition: cudd.h:91
#define set_save(r)
Definition: espresso.h:166
int var(Lit p)
Definition: SolverTypes.h:62
ABC_NAMESPACE_IMPL_START void cube_setup()
Definition: cubestr.c:27
char * get_word(FILE *fp, char *word)
Definition: cvrin.c:37
void read_cube(FILE *fp, pPLA PLA)
Definition: cvrin.c:54
int * var2
Definition: espresso.h:285
struct pla_types_struct pla_types[]
Definition: globals.c:42
#define NIL(type)
Definition: avl.h:25
static int lineno
Definition: cvrin.c:22
static ABC_NAMESPACE_IMPL_START bool line_length_error
Definition: cvrin.c:21
#define ALLOC(type, num)
Definition: avl.h:27
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
#define new_cover(i)
Definition: espresso.h:265
char * sprintf()
int read_symbolic(FILE *fp, pPLA PLA, char *word, symbolic_t **retval)
Definition: cvrin.c:727
bool echo_unknown_commands
Definition: globals.c:26
bool echo_comments
Definition: globals.c:25
char * strcpy()
int * var1
Definition: espresso.h:284
#define set_remove(set, e)
Definition: espresso.h:171
#define TRUE
Definition: cudd.h:88
bool kiss
Definition: globals.c:29
enum keys key
int label_index(pPLA PLA, char *word, int *varp, int *ip)
Definition: cvrin.c:789
int strlen()
#define equal(a, b)
Definition: espresso.h:326
struct symbolic_struct * next
Definition: espresso.h:310
void PLA_labels ( pPLA  PLA)

Definition at line 665 of file cvrin.c.

667 {
668  int i;
669 
670  PLA->label = ALLOC(char *, cube.size);
671  for(i = 0; i < cube.size; i++)
672  PLA->label[i] = (char *) NULL;
673 }
#define ALLOC(type, num)
Definition: avl.h:27
char ** label
Definition: espresso.h:321
void PLA_summary ( pPLA  PLA)

Definition at line 597 of file cvrin.c.

599 {
600  int var, i;
601  symbolic_list_t *p2;
602  symbolic_t *p1;
603 
604  printf("# PLA is %s", PLA->filename);
605  if (cube.num_binary_vars == cube.num_vars - 1)
606  printf(" with %d inputs and %d outputs\n",
607  cube.num_binary_vars, cube.part_size[cube.num_vars - 1]);
608  else {
609  printf(" with %d variables (%d binary, mv sizes",
610  cube.num_vars, cube.num_binary_vars);
611  for(var = cube.num_binary_vars; var < cube.num_vars; var++)
612  printf(" %d", cube.part_size[var]);
613  printf(")\n");
614  }
615  printf("# ON-set cost is %s\n", print_cost(PLA->F));
616  printf("# OFF-set cost is %s\n", print_cost(PLA->R));
617  printf("# DC-set cost is %s\n", print_cost(PLA->D));
618  if (PLA->phase != NULL)
619  printf("# phase is %s\n", pc1(PLA->phase));
620  if (PLA->pair != NULL) {
621  printf("# two-bit decoders:");
622  for(i = 0; i < PLA->pair->cnt; i++)
623  printf(" (%d %d)", PLA->pair->var1[i], PLA->pair->var2[i]);
624  printf("\n");
625  }
626  if (PLA->symbolic != NIL(symbolic_t)) {
627  for(p1 = PLA->symbolic; p1 != NIL(symbolic_t); p1 = p1->next) {
628  printf("# symbolic: ");
629  for(p2=p1->symbolic_list; p2!=NIL(symbolic_list_t); p2=p2->next) {
630  printf(" %d", p2->variable);
631  }
632  printf("\n");
633  }
634  }
635  if (PLA->symbolic_output != NIL(symbolic_t)) {
636  for(p1 = PLA->symbolic_output; p1 != NIL(symbolic_t); p1 = p1->next) {
637  printf("# output symbolic: ");
638  for(p2=p1->symbolic_list; p2!=NIL(symbolic_list_t); p2=p2->next) {
639  printf(" %d", p2->pos);
640  }
641  printf("\n");
642  }
643  }
644  (void) fflush(stdout);
645 }
ppair pair
Definition: espresso.h:320
char * pc1(pcube c)
Definition: cvrout.c:379
int var(Lit p)
Definition: SolverTypes.h:62
symbolic_list_t * symbolic_list
Definition: espresso.h:306
int * var2
Definition: espresso.h:285
#define NIL(type)
Definition: avl.h:25
char * print_cost(IN pcover F)
Definition: cvrmisc.c:76
symbolic_t * symbolic
Definition: espresso.h:322
char * filename
Definition: espresso.h:317
struct symbolic_list_struct * next
Definition: espresso.h:293
pcover F
Definition: espresso.h:316
int * var1
Definition: espresso.h:284
pcube phase
Definition: espresso.h:319
pcover D
Definition: espresso.h:316
pcover R
Definition: espresso.h:316
symbolic_t * symbolic_output
Definition: espresso.h:323
struct symbolic_struct * next
Definition: espresso.h:310
void read_cube ( FILE *  fp,
pPLA  PLA 
)

Definition at line 54 of file cvrin.c.

57 {
58  register int var, i;
59  pcube cf = cube.temp[0], cr = cube.temp[1], cd = cube.temp[2];
60  bool savef = FALSE, saved = FALSE, saver = FALSE;
61  char token[256]; /* for kiss read hack */
62  int varx, first, last, offset; /* for kiss read hack */
63 
64  set_clear(cf, cube.size);
65 
66  /* Loop and read binary variables */
67  for(var = 0; var < cube.num_binary_vars; var++)
68  switch(getc(fp)) {
69  case EOF:
70  goto bad_char;
71  case '\n':
72  if (! line_length_error)
73  (void) fprintf(stderr, "product term(s) %s\n",
74  "span more than one line (warning only)");
76  lineno++;
77  var--;
78  break;
79  case ' ': case '|': case '\t':
80  var--;
81  break;
82  case '2': case '-':
83  set_insert(cf, var*2+1);
84  case '0':
85  set_insert(cf, var*2);
86  break;
87  case '1':
88  set_insert(cf, var*2+1);
89  break;
90  case '?':
91  break;
92  default:
93  goto bad_char;
94  }
95 
96 
97  /* Loop for the all but one of the multiple-valued variables */
98  for(var = cube.num_binary_vars; var < cube.num_vars-1; var++)
99 
100  /* Read a symbolic multiple-valued variable */
101  if (cube.part_size[var] < 0) {
102  (void) fscanf(fp, "%s", token);
103  if (equal(token, "-") || equal(token, "ANY")) {
104  if (kiss && var == cube.num_vars - 2) {
105  /* leave it empty */
106  } else {
107  /* make it full */
108  set_or(cf, cf, cube.var_mask[var]);
109  }
110  } else if (equal(token, "~")) {
111  ;
112  /* leave it empty ... (?) */
113  } else {
114  if (kiss && var == cube.num_vars - 2)
115  varx = var - 1, offset = ABS(cube.part_size[var-1]);
116  else
117  varx = var, offset = 0;
118  /* Find the symbolic label in the label table */
119  first = cube.first_part[varx];
120  last = cube.last_part[varx];
121  for(i = first; i <= last; i++)
122  if (PLA->label[i] == (char *) NULL) {
123  PLA->label[i] = util_strsav(token); /* add new label */
124  set_insert(cf, i+offset);
125  break;
126  } else if (equal(PLA->label[i], token)) {
127  set_insert(cf, i+offset); /* use column i */
128  break;
129  }
130  if (i > last) {
131  (void) fprintf(stderr,
132 "declared size of variable %d (counting from variable 0) is too small\n", var);
133  exit(-1);
134  }
135  }
136 
137  } else for(i = cube.first_part[var]; i <= cube.last_part[var]; i++)
138  switch (getc(fp)) {
139  case EOF:
140  goto bad_char;
141  case '\n':
142  if (! line_length_error)
143  (void) fprintf(stderr, "product term(s) %s\n",
144  "span more than one line (warning only)");
146  lineno++;
147  i--;
148  break;
149  case ' ': case '|': case '\t':
150  i--;
151  break;
152  case '1':
153  set_insert(cf, i);
154  case '0':
155  break;
156  default:
157  goto bad_char;
158  }
159 
160  /* Loop for last multiple-valued variable */
161  if (kiss) {
162  saver = savef = TRUE;
163  (void) set_xor(cr, cf, cube.var_mask[cube.num_vars - 2]);
164  } else
165  set_copy(cr, cf);
166  set_copy(cd, cf);
167  for(i = cube.first_part[var]; i <= cube.last_part[var]; i++)
168  switch (getc(fp)) {
169  case EOF:
170  goto bad_char;
171  case '\n':
172  if (! line_length_error)
173  (void) fprintf(stderr, "product term(s) %s\n",
174  "span more than one line (warning only)");
176  lineno++;
177  i--;
178  break;
179  case ' ': case '|': case '\t':
180  i--;
181  break;
182  case '4': case '1':
183  if (PLA->pla_type & F_type)
184  set_insert(cf, i), savef = TRUE;
185  break;
186  case '3': case '0':
187  if (PLA->pla_type & R_type)
188  set_insert(cr, i), saver = TRUE;
189  break;
190  case '2': case '-':
191  if (PLA->pla_type & D_type)
192  set_insert(cd, i), saved = TRUE;
193  case '~':
194  break;
195  default:
196  goto bad_char;
197  }
198  if (savef) PLA->F = sf_addset(PLA->F, cf);
199  if (saved) PLA->D = sf_addset(PLA->D, cd);
200  if (saver) PLA->R = sf_addset(PLA->R, cr);
201  return;
202 
203 bad_char:
204  (void) fprintf(stderr, "(warning): input line #%d ignored\n", lineno);
205  skip_line(fp, stdout, TRUE);
206  return;
207 }
pset set_or()
VOID_HACK exit()
void skip_line(FILE *fpin, FILE *fpout, bool echo)
Definition: cvrin.c:24
#define FALSE
Definition: cudd.h:91
pset set_clear()
pset set_copy()
int var(Lit p)
Definition: SolverTypes.h:62
#define ABS(a)
Definition: util_old.h:250
static int lineno
Definition: cvrin.c:22
static ABC_NAMESPACE_IMPL_START bool line_length_error
Definition: cvrin.c:21
pset_family sf_addset()
pset set_xor()
pcover F
Definition: espresso.h:316
#define TRUE
Definition: cudd.h:88
int pla_type
Definition: espresso.h:318
bool kiss
Definition: globals.c:29
#define set_insert(set, e)
Definition: espresso.h:172
pcover D
Definition: espresso.h:316
pcover R
Definition: espresso.h:316
#define D_type
Definition: espresso.h:338
char ** label
Definition: espresso.h:321
#define F_type
Definition: espresso.h:337
#define R_type
Definition: espresso.h:339
#define equal(a, b)
Definition: espresso.h:326
#define pcube
Definition: espresso.h:261
int read_pla ( IN FILE *  fp,
IN bool  needs_dcset,
IN bool  needs_offset,
IN int  pla_type,
OUT pPLA PLA_return 
)

Definition at line 493 of file cvrin.c.

498 {
499  pPLA PLA;
500  int i, second, third;
501  long time;
502  cost_t cost;
503 
504  /* Allocate and initialize the PLA structure */
505  PLA = *PLA_return = new_PLA();
506  PLA->pla_type = pla_type;
507 
508  /* Read the pla */
509  time = ptime();
510  parse_pla(fp, PLA);
511 
512  /* Check for nothing on the file -- implies reached EOF */
513  if (PLA->F == NULL) {
514  return EOF;
515  }
516 
517  /* This hack merges the next-state field with the outputs */
518  for(i = 0; i < cube.num_vars; i++) {
519  cube.part_size[i] = ABS(cube.part_size[i]);
520  }
521  if (kiss) {
522  third = cube.num_vars - 3;
523  second = cube.num_vars - 2;
524  if (cube.part_size[third] != cube.part_size[second]) {
525  (void) fprintf(stderr," with .kiss option, third to last and second\n");
526  (void) fprintf(stderr, "to last variables must be the same size.\n");
527  return EOF;
528  }
529  for(i = 0; i < cube.part_size[second]; i++) {
530  PLA->label[i + cube.first_part[second]] =
531  util_strsav(PLA->label[i + cube.first_part[third]]);
532  }
533  cube.part_size[second] += cube.part_size[cube.num_vars-1];
534  cube.num_vars--;
535  setdown_cube();
536  cube_setup();
537  }
538 
539  if (trace) {
540  totals(time, READ_TIME, PLA->F, &cost);
541  }
542 
543  /* Decide how to break PLA into ON-set, OFF-set and DC-set */
544  time = ptime();
545  if (pos || PLA->phase != NULL || PLA->symbolic_output != NIL(symbolic_t)) {
546  needs_offset = TRUE;
547  }
548  if (needs_offset && (PLA->pla_type==F_type || PLA->pla_type==FD_type)) {
549  free_cover(PLA->R);
550  PLA->R = complement(cube2list(PLA->F, PLA->D));
551  } else if (needs_dcset && PLA->pla_type == FR_type) {
552  pcover X;
553  free_cover(PLA->D);
554  /* hack, why not? */
555  X = d1merge(sf_join(PLA->F, PLA->R), cube.num_vars - 1);
556  PLA->D = complement(cube1list(X));
557  free_cover(X);
558  } else if (PLA->pla_type == R_type || PLA->pla_type == DR_type) {
559  free_cover(PLA->F);
560  PLA->F = complement(cube2list(PLA->D, PLA->R));
561  }
562 
563  if (trace) {
564  totals(time, COMPL_TIME, PLA->R, &cost);
565  }
566 
567  /* Check for phase rearrangement of the functions */
568  if (pos) {
569  pcover onset = PLA->F;
570  PLA->F = PLA->R;
571  PLA->R = onset;
572  PLA->phase = new_cube();
573  set_diff(PLA->phase, cube.fullset, cube.var_mask[cube.num_vars-1]);
574  } else if (PLA->phase != NULL) {
575  (void) set_phase(PLA);
576  }
577 
578  /* Setup minimization for two-bit decoders */
579  if (PLA->pair != (ppair) NULL) {
580  set_pair(PLA);
581  }
582 
583  if (PLA->symbolic != NIL(symbolic_t)) {
584  EXEC(map_symbolic(PLA), "MAP-INPUT ", PLA->F);
585  }
586  if (PLA->symbolic_output != NIL(symbolic_t)) {
587  EXEC(map_output_symbolic(PLA), "MAP-OUTPUT ", PLA->F);
588  if (needs_offset) {
589  free_cover(PLA->R);
590 EXECUTE(PLA->R=complement(cube2list(PLA->F,PLA->D)), COMPL_TIME, PLA->R, cost);
591  }
592  }
593 
594  return 1;
595 }
ppair pair
Definition: espresso.h:320
#define FD_type
Definition: espresso.h:345
#define new_cube()
Definition: espresso.h:262
#define free_cover(r)
Definition: espresso.h:266
#define pcover
Definition: espresso.h:264
void map_output_symbolic()
void map_symbolic()
pPLA set_phase()
bool pos
Definition: globals.c:30
bool trace
Definition: globals.c:36
void parse_pla(IN FILE *fp, INOUT pPLA PLA)
Definition: cvrin.c:208
pset_family d1merge(INOUT pset_family A, IN int var)
Definition: contain.c:161
ABC_NAMESPACE_IMPL_START void cube_setup()
Definition: cubestr.c:27
bool needs_offset
pcover complement(pcube *T)
Definition: compl.c:49
#define ABS(a)
Definition: util_old.h:250
#define NIL(type)
Definition: avl.h:25
symbolic_t * symbolic
Definition: espresso.h:322
pset_family sf_join()
pset set_diff()
void setdown_cube()
Definition: cubestr.c:95
pcube * cube2list(pcover A, pcover B)
Definition: cofactor.c:306
pcover F
Definition: espresso.h:316
void set_pair()
#define ptime()
Definition: util_old.h:283
#define READ_TIME
Definition: espresso.h:372
#define FR_type
Definition: espresso.h:346
#define TRUE
Definition: cudd.h:88
int pla_type
Definition: espresso.h:318
pcube phase
Definition: espresso.h:319
bool kiss
Definition: globals.c:29
pcover D
Definition: espresso.h:316
pcover R
Definition: espresso.h:316
pPLA new_PLA()
Definition: cvrin.c:648
symbolic_t * symbolic_output
Definition: espresso.h:323
char ** label
Definition: espresso.h:321
#define F_type
Definition: espresso.h:337
#define EXEC(fct, name, S)
Definition: espresso.h:418
void totals(long time, int i, pcover T, pcost cost)
Definition: cvrmisc.c:121
#define R_type
Definition: espresso.h:339
#define COMPL_TIME
Definition: espresso.h:373
bool needs_dcset
#define EXECUTE(fct, i, S, cost)
Definition: espresso.h:422
pcube * cube1list(pcover A)
Definition: cofactor.c:289
#define DR_type
Definition: espresso.h:347
int read_symbolic ( FILE *  fp,
pPLA  PLA,
char *  word,
symbolic_t **  retval 
)

Definition at line 727 of file cvrin.c.

732 {
733  symbolic_list_t *listp, *prev_listp;
734  symbolic_label_t *labelp, *prev_labelp;
735  symbolic_t *newlist;
736  int i, var;
737 
738  newlist = ALLOC(symbolic_t, 1);
739  newlist->next = NIL(symbolic_t);
740  newlist->symbolic_list = NIL(symbolic_list_t);
741  newlist->symbolic_list_length = 0;
742  newlist->symbolic_label = NIL(symbolic_label_t);
743  newlist->symbolic_label_length = 0;
744  prev_listp = NIL(symbolic_list_t);
745  prev_labelp = NIL(symbolic_label_t);
746 
747  for(;;) {
748  (void) get_word(fp, word);
749  if (equal(word, ";"))
750  break;
751  if (label_index(PLA, word, &var, &i)) {
752  listp = ALLOC(symbolic_list_t, 1);
753  listp->variable = var;
754  listp->pos = i;
755  listp->next = NIL(symbolic_list_t);
756  if (prev_listp == NIL(symbolic_list_t)) {
757  newlist->symbolic_list = listp;
758  } else {
759  prev_listp->next = listp;
760  }
761  prev_listp = listp;
762  newlist->symbolic_list_length++;
763  } else {
764  return FALSE;
765  }
766  }
767 
768  for(;;) {
769  (void) get_word(fp, word);
770  if (equal(word, ";"))
771  break;
772  labelp = ALLOC(symbolic_label_t, 1);
773  labelp->label = util_strsav(word);
774  labelp->next = NIL(symbolic_label_t);
775  if (prev_labelp == NIL(symbolic_label_t)) {
776  newlist->symbolic_label = labelp;
777  } else {
778  prev_labelp->next = labelp;
779  }
780  prev_labelp = labelp;
781  newlist->symbolic_label_length++;
782  }
783 
784  *retval = newlist;
785  return TRUE;
786 }
struct symbolic_label_struct * next
Definition: espresso.h:300
#define FALSE
Definition: cudd.h:91
symbolic_label_t * symbolic_label
Definition: espresso.h:308
int var(Lit p)
Definition: SolverTypes.h:62
symbolic_list_t * symbolic_list
Definition: espresso.h:306
char * get_word(FILE *fp, char *word)
Definition: cvrin.c:37
#define NIL(type)
Definition: avl.h:25
#define ALLOC(type, num)
Definition: avl.h:27
struct symbolic_list_struct * next
Definition: espresso.h:293
int symbolic_label_length
Definition: espresso.h:309
unsigned __int64 word
DECLARATIONS ///.
Definition: kitPerm.c:36
int symbolic_list_length
Definition: espresso.h:307
#define TRUE
Definition: cudd.h:88
int label_index(pPLA PLA, char *word, int *varp, int *ip)
Definition: cvrin.c:789
#define equal(a, b)
Definition: espresso.h:326
struct symbolic_struct * next
Definition: espresso.h:310
void skip_line ( FILE *  fpin,
FILE *  fpout,
bool  echo 
)

Definition at line 24 of file cvrin.c.

27 {
28  register int ch;
29  while ((ch=getc(fpin)) != EOF && ch != '\n')
30  if (echo)
31  putc(ch, fpout);
32  if (echo)
33  putc('\n', fpout);
34  lineno++;
35 }
static int lineno
Definition: cvrin.c:22

Variable Documentation

ABC_NAMESPACE_IMPL_START bool line_length_error
static

Definition at line 21 of file cvrin.c.

int lineno
static

Definition at line 22 of file cvrin.c.