25 register FILE *fpin, *fpout;
29 while ((ch=getc(fpin)) != EOF && ch !=
'\n')
41 register int ch, i = 0;
42 while ((ch = getc(fp)) != EOF && isspace(ch))
45 while ((ch = getc(fp)) != EOF && ! isspace(ch))
59 pcube cf = cube.temp[0], cr = cube.temp[1], cd = cube.temp[2];
62 int varx, first, last, offset;
67 for(var = 0; var < cube.num_binary_vars; var++)
73 (void) fprintf(stderr,
"product term(s) %s\n",
74 "span more than one line (warning only)");
79 case ' ':
case '|':
case '\t':
98 for(var = cube.num_binary_vars; var < cube.num_vars-1; var++)
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) {
108 set_or(cf, cf, cube.var_mask[var]);
110 }
else if (
equal(token,
"~")) {
114 if (
kiss && var == cube.num_vars - 2)
115 varx = var - 1, offset =
ABS(cube.part_size[var-1]);
117 varx =
var, offset = 0;
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);
131 (void) fprintf(stderr,
132 "declared size of variable %d (counting from variable 0) is too small\n", var);
137 }
else for(i = cube.first_part[var]; i <= cube.last_part[var]; i++)
143 (void) fprintf(stderr,
"product term(s) %s\n",
144 "span more than one line (warning only)");
149 case ' ':
case '|':
case '\t':
162 saver = savef =
TRUE;
163 (void)
set_xor(cr, cf, cube.var_mask[cube.num_vars - 2]);
167 for(i = cube.first_part[var]; i <= cube.last_part[var]; i++)
173 (void) fprintf(stderr,
"product term(s) %s\n",
174 "span more than one line (warning only)");
179 case ' ':
case '|':
case '\t':
204 (void) fprintf(stderr,
"(warning): input line #%d ignored\n",
lineno);
212 int i,
var, ch, np, last;
219 switch(ch = getc(fp)) {
226 case ' ':
case '\t':
case '\f':
case '\r':
230 (void) ungetc(ch, fp);
237 if (cube.fullset != NULL) {
238 (void) fprintf(stderr,
"extra .i ignored\n");
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);
248 }
else if (
equal(word,
"o")) {
249 if (cube.fullset != NULL) {
250 (void) fprintf(stderr,
"extra .o ignored\n");
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");
262 }
else if (
equal(word,
"mv")) {
263 if (cube.fullset != NULL) {
264 (void) fprintf(stderr,
"extra .mv ignored\n");
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)
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");
286 }
else if (
equal(word,
"p"))
287 (void) fscanf(fp,
"%d", &np);
289 else if (
equal(word,
"e") ||
equal(word,
"end")) {
290 if (cube.fullset == NULL) {
292 }
else if (PLA->F == NULL) {
300 else if (
equal(word,
"kiss"))
304 else if (
equal(word,
"type")) {
312 fatal(
"unknown type in .type command");
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)
320 for(var = 0; var < cube.num_binary_vars; var++) {
322 i = cube.first_part[
var];
323 PLA->label[i+1] = util_strsav(word);
325 (void)
sprintf(PLA->label[i],
"%s.bar", word);
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)
332 var = cube.num_vars - 1;
333 for(i = cube.first_part[var]; i <= cube.last_part[var]; i++) {
335 PLA->label[i] = util_strsav(word);
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)
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++) {
347 PLA->label[i] = util_strsav(word);
350 }
else if (
equal(word,
"symbolic")) {
354 PLA->symbolic = newlist;
362 fatal(
"error reading .symbolic");
365 }
else if (
equal(word,
"symbolic-output")) {
369 PLA->symbolic_output = newlist;
377 fatal(
"error reading .symbolic-output");
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");
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')
396 fatal(
"only 0 or 1 allowed in phase description");
400 }
else if (
equal(word,
"pair")) {
402 if (PLA->pair != NULL) {
403 (void) fprintf(stderr,
"extra .pair ignored\n");
407 if (fscanf(fp,
"%d", &(pair->
cnt)) != 1)
408 fatal(
"syntax error in .pair");
411 for(i = 0; i < pair->
cnt; i++) {
413 if (word[0] ==
'(') (void)
strcpy(word, word+1);
415 pair->
var1[i] = var+1;
417 fatal(
"syntax error in .pair");
421 if (word[
strlen(word)-1] ==
')') {
422 word[
strlen(word)-1]=
'\0';
425 pair->
var2[i] = var+1;
427 fatal(
"syntax error in .pair");
434 printf(
"%c%s ", ch, word);
439 (void) ungetc(ch, fp);
440 if (cube.fullset == NULL) {
447 if (PLA->F == NULL) {
500 int i, second, third;
513 if (PLA->
F == NULL) {
518 for(i = 0; i < cube.num_vars; i++) {
519 cube.part_size[i] =
ABS(cube.part_size[i]);
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");
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]]);
533 cube.part_size[second] += cube.part_size[cube.num_vars-1];
573 set_diff(PLA->
phase, cube.fullset, cube.var_mask[cube.num_vars-1]);
574 }
else if (PLA->
phase != NULL) {
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]);
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]);
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]);
628 printf(
"# symbolic: ");
637 printf(
"# output symbolic: ");
639 printf(
" %d", p2->
pos);
644 (void) fflush(stdout);
653 PLA->
F = PLA->
D = PLA->
R = (
pcover) NULL;
656 PLA->
label = (
char **) NULL;
671 for(i = 0; i < cube.size; i++)
672 PLA->label[i] = (
char *) NULL;
683 if (PLA->F != (
pcover) NULL)
685 if (PLA->R != (
pcover) NULL)
687 if (PLA->D != (
pcover) NULL)
689 if (PLA->phase != (
pcube) NULL)
691 if (PLA->pair != (
ppair) NULL) {
692 FREE(PLA->pair->var1);
693 FREE(PLA->pair->var2);
696 if (PLA->label != NULL) {
697 for(i = 0; i < cube.size; i++)
698 if (PLA->label[i] != NULL)
702 if (PLA->filename != NULL) {
705 for(p1 = PLA->symbolic; p1 !=
NIL(
symbolic_t); p1 = p1next) {
714 for(p1 = PLA->symbolic_output; p1 !=
NIL(
symbolic_t); p1 = p1next) {
749 if (
equal(word,
";"))
759 prev_listp->
next = listp;
770 if (
equal(word,
";"))
773 labelp->
label = util_strsav(word);
778 prev_labelp->
next = labelp;
780 prev_labelp = labelp;
797 if (PLA->label ==
NIL(
char *) || PLA->label[0] ==
NIL(
char)) {
798 if (sscanf(word,
"%d", varp) == 1) {
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)) {
void skip_line(FILE *fpin, FILE *fpout, bool echo)
void PLA_labels(pPLA PLA)
struct symbolic_label_struct * next
void PLA_summary(pPLA PLA)
symbolic_label_t * symbolic_label
void map_output_symbolic()
symbolic_list_t * symbolic_list
void parse_pla(IN FILE *fp, INOUT pPLA PLA)
pset_family d1merge(INOUT pset_family A, IN int var)
ABC_NAMESPACE_IMPL_START void cube_setup()
int read_pla(IN FILE *fp, IN bool needs_dcset, IN bool needs_offset, IN int pla_type, OUT pPLA *PLA_return)
char * get_word(FILE *fp, char *word)
pcover complement(pcube *T)
void read_cube(FILE *fp, pPLA PLA)
struct pla_types_struct pla_types[]
char * print_cost(IN pcover F)
static ABC_NAMESPACE_IMPL_START bool line_length_error
struct symbolic_list_struct * next
int symbolic_label_length
unsigned __int64 word
DECLARATIONS ///.
pcube * cube2list(pcover A, pcover B)
#define ABC_NAMESPACE_IMPL_END
int read_symbolic(FILE *fp, pPLA PLA, char *word, symbolic_t **retval)
bool echo_unknown_commands
#define ABC_NAMESPACE_IMPL_START
#define set_remove(set, e)
#define set_insert(set, e)
int label_index(pPLA PLA, char *word, int *varp, int *ip)
struct pair_struct * ppair
symbolic_t * symbolic_output
#define EXEC(fct, name, S)
void totals(long time, int i, pcover T, pcost cost)
#define EXECUTE(fct, i, S, cost)
pcube * cube1list(pcover A)
struct symbolic_struct * next