cvrin.c
来自「主要进行大规模的电路综合」· C语言 代码 · 共 837 行 · 第 1/2 页
C
837 行
/* .pair allows for bit-pairing input variables */ } else if (equal(word, "pair")) { int j; if (PLA->pair != NULL) { (void) fprintf(stderr, "extra .pair ignored\n"); } else { ppair pair; PLA->pair = pair = ALLOC(pair_t, 1); if (fscanf(fp, "%d", &(pair->cnt)) != 1) fatal("syntax error in .pair"); pair->var1 = ALLOC(int, pair->cnt); pair->var2 = ALLOC(int, pair->cnt); for(i = 0; i < pair->cnt; i++) { (void) get_word(fp, word); if (word[0] == '(') (void) strcpy(word, word+1); if (label_index(PLA, word, &var, &j)) { pair->var1[i] = var+1; } else { fatal("syntax error in .pair"); } (void) get_word(fp, word); if (word[strlen(word)-1] == ')') { word[strlen(word)-1]='\0'; } if (label_index(PLA, word, &var, &j)) { pair->var2[i] = var+1; } else { fatal("syntax error in .pair"); } } } } else { if (echo_unknown_commands) (void) printf("%c%s ", ch, word); skip_line(fp, stdout, echo_unknown_commands); } break; default: (void) ungetc(ch, fp); if (cube.fullset == NULL) {/* fatal("unknown PLA size, need .i/.o or .mv");*/ if (echo_comments) putchar('#'); skip_line(fp, stdout, echo_comments); break; } if (PLA->F == NULL) { PLA->F = new_cover(10); PLA->D = new_cover(10); PLA->R = new_cover(10); } read_cube(fp, PLA); } goto loop;}/* read_pla -- read a PLA from a file Input stops when ".e" is encountered in the input file, or upon reaching end of file. Returns the PLA in the variable PLA after massaging the "symbolic" representation into a positional cube notation of the ON-set, OFF-set, and the DC-set. needs_dcset and needs_offset control the computation of the OFF-set and DC-set (i.e., if either needs to be computed, then it will be computed via complement only if the corresponding option is TRUE.) pla_type specifies the interpretation to be used when reading the PLA. The phase of the output functions is adjusted according to the global option "pos" or according to an imbedded .phase option in the input file. Note that either phase option implies that the OFF-set be computed regardless of whether the caller needs it explicitly or not. Bit pairing of the binary variables is performed according to an imbedded .pair option in the input file. The global cube structure also reflects the sizes of the PLA which was just read. If these fields have already been set, then any subsequent PLA must conform to these sizes. The global flags trace and summary control the output produced during the read. Returns a status code as a result: EOF (-1) : End of file reached before any data was read > 0 : Operation successful*/int read_pla(fp, needs_dcset, needs_offset, pla_type, PLA_return)IN FILE *fp;IN bool needs_dcset, needs_offset;IN int pla_type;OUT pPLA *PLA_return;{ pPLA PLA; int i, second, third; long time; cost_t cost; /* Allocate and initialize the PLA structure */ PLA = *PLA_return = new_PLA(); PLA->pla_type = pla_type; /* Read the pla */ time = ptime(); parse_pla(fp, PLA); /* Check for nothing on the file -- implies reached EOF */ if (PLA->F == NULL) { return EOF; } /* This hack merges the next-state field with the outputs */ for(i = 0; i < cube.num_vars; i++) { cube.part_size[i] = ABS(cube.part_size[i]); } if (kiss) { third = cube.num_vars - 3; second = cube.num_vars - 2; if (cube.part_size[third] != cube.part_size[second]) { (void) fprintf(stderr," with .kiss option, third to last and second\n"); (void) fprintf(stderr, "to last variables must be the same size.\n"); return EOF; } for(i = 0; i < cube.part_size[second]; i++) { PLA->label[i + cube.first_part[second]] = util_strsav(PLA->label[i + cube.first_part[third]]); } cube.part_size[second] += cube.part_size[cube.num_vars-1]; cube.num_vars--; setdown_cube(); cube_setup(); } if (trace) { totals(time, READ_TIME, PLA->F, &cost); } /* Decide how to break PLA into ON-set, OFF-set and DC-set */ time = ptime(); if (pos || PLA->phase != NULL || PLA->symbolic_output != NIL(symbolic_t)) { needs_offset = TRUE; } if (needs_offset && (PLA->pla_type==F_type || PLA->pla_type==FD_type)) { free_cover(PLA->R); PLA->R = complement(cube2list(PLA->F, PLA->D)); } else if (needs_dcset && PLA->pla_type == FR_type) { pcover X; free_cover(PLA->D); /* hack, why not? */ X = d1merge(sf_join(PLA->F, PLA->R), cube.num_vars - 1); PLA->D = complement(cube1list(X)); free_cover(X); } else if (PLA->pla_type == R_type || PLA->pla_type == DR_type) { free_cover(PLA->F); PLA->F = complement(cube2list(PLA->D, PLA->R)); } if (trace) { totals(time, COMPL_TIME, PLA->R, &cost); } /* Check for phase rearrangement of the functions */ if (pos) { pcover onset = PLA->F; PLA->F = PLA->R; PLA->R = onset; PLA->phase = new_cube(); (void) set_diff(PLA->phase, cube.fullset, cube.var_mask[cube.num_vars-1]); } else if (PLA->phase != NULL) { (void) set_phase(PLA); } /* Setup minimization for two-bit decoders */ if (PLA->pair != (ppair) NULL) { set_pair(PLA); } if (PLA->symbolic != NIL(symbolic_t)) { EXEC(map_symbolic(PLA), "MAP-INPUT ", PLA->F); } if (PLA->symbolic_output != NIL(symbolic_t)) { EXEC(map_output_symbolic(PLA), "MAP-OUTPUT ", PLA->F); if (needs_offset) { free_cover(PLA->R);EXECUTE(PLA->R=complement(cube2list(PLA->F,PLA->D)), COMPL_TIME, PLA->R, cost); } } return 1;}void PLA_summary(PLA)pPLA PLA;{ int var, i; symbolic_list_t *p2; symbolic_t *p1; (void) printf("# PLA is %s", PLA->filename); if (cube.num_binary_vars == cube.num_vars - 1) (void) printf(" with %d inputs and %d outputs\n", cube.num_binary_vars, cube.part_size[cube.num_vars - 1]); else { (void) printf(" with %d variables (%d binary, mv sizes", cube.num_vars, cube.num_binary_vars); for(var = cube.num_binary_vars; var < cube.num_vars; var++) (void) printf(" %d", cube.part_size[var]); (void) printf(")\n"); } (void) printf("# ON-set cost is %s\n", print_cost(PLA->F)); (void) printf("# OFF-set cost is %s\n", print_cost(PLA->R)); (void) printf("# DC-set cost is %s\n", print_cost(PLA->D)); if (PLA->phase != NULL) (void) printf("# phase is %s\n", pc1(PLA->phase)); if (PLA->pair != NULL) { (void) printf("# two-bit decoders:"); for(i = 0; i < PLA->pair->cnt; i++) (void) printf(" (%d %d)", PLA->pair->var1[i], PLA->pair->var2[i]); (void) printf("\n"); } if (PLA->symbolic != NIL(symbolic_t)) { for(p1 = PLA->symbolic; p1 != NIL(symbolic_t); p1 = p1->next) { (void) printf("# symbolic: "); for(p2=p1->symbolic_list; p2!=NIL(symbolic_list_t); p2=p2->next) { (void) printf(" %d", p2->variable); } (void) printf("\n"); } } if (PLA->symbolic_output != NIL(symbolic_t)) { for(p1 = PLA->symbolic_output; p1 != NIL(symbolic_t); p1 = p1->next) { (void) printf("# output symbolic: "); for(p2=p1->symbolic_list; p2!=NIL(symbolic_list_t); p2=p2->next) { (void) printf(" %d", p2->pos); } (void) printf("\n"); } } (void) fflush(stdout);}pPLA new_PLA(){ pPLA PLA; PLA = ALLOC(PLA_t, 1); PLA->F = PLA->D = PLA->R = (pcover) NULL; PLA->phase = (pcube) NULL; PLA->pair = (ppair) NULL; PLA->label = (char **) NULL; PLA->filename = (char *) NULL; PLA->pla_type = 0; PLA->symbolic = NIL(symbolic_t); PLA->symbolic_output = NIL(symbolic_t); return PLA;}PLA_labels(PLA)pPLA PLA;{ int i; PLA->label = ALLOC(char *, cube.size); for(i = 0; i < cube.size; i++) PLA->label[i] = (char *) NULL;}void free_PLA(PLA)pPLA PLA;{ symbolic_list_t *p2, *p2next; symbolic_t *p1, *p1next; int i; if (PLA->F != (pcover) NULL) free_cover(PLA->F); if (PLA->R != (pcover) NULL) free_cover(PLA->R); if (PLA->D != (pcover) NULL) free_cover(PLA->D); if (PLA->phase != (pcube) NULL) free_cube(PLA->phase); if (PLA->pair != (ppair) NULL) { FREE(PLA->pair->var1); FREE(PLA->pair->var2); FREE(PLA->pair); } if (PLA->label != NULL) { for(i = 0; i < cube.size; i++) if (PLA->label[i] != NULL) FREE(PLA->label[i]); FREE(PLA->label); } if (PLA->filename != NULL) { FREE(PLA->filename); } for(p1 = PLA->symbolic; p1 != NIL(symbolic_t); p1 = p1next) { for(p2 = p1->symbolic_list; p2 != NIL(symbolic_list_t); p2 = p2next) { p2next = p2->next; FREE(p2); } p1next = p1->next; FREE(p1); } PLA->symbolic = NIL(symbolic_t); for(p1 = PLA->symbolic_output; p1 != NIL(symbolic_t); p1 = p1next) { for(p2 = p1->symbolic_list; p2 != NIL(symbolic_list_t); p2 = p2next) { p2next = p2->next; FREE(p2); } p1next = p1->next; FREE(p1); } PLA->symbolic_output = NIL(symbolic_t); FREE(PLA);}int read_symbolic(fp, PLA, word, retval)FILE *fp;pPLA PLA;char *word; /* scratch string for words */symbolic_t **retval;{ symbolic_list_t *listp, *prev_listp; symbolic_label_t *labelp, *prev_labelp; symbolic_t *newlist; int i, var; newlist = ALLOC(symbolic_t, 1); newlist->next = NIL(symbolic_t); newlist->symbolic_list = NIL(symbolic_list_t); newlist->symbolic_list_length = 0; newlist->symbolic_label = NIL(symbolic_label_t); newlist->symbolic_label_length = 0; prev_listp = NIL(symbolic_list_t); prev_labelp = NIL(symbolic_label_t); for(;;) { (void) get_word(fp, word); if (equal(word, ";")) break; if (label_index(PLA, word, &var, &i)) { listp = ALLOC(symbolic_list_t, 1); listp->variable = var; listp->pos = i; listp->next = NIL(symbolic_list_t); if (prev_listp == NIL(symbolic_list_t)) { newlist->symbolic_list = listp; } else { prev_listp->next = listp; } prev_listp = listp; newlist->symbolic_list_length++; } else { return FALSE; } } for(;;) { (void) get_word(fp, word); if (equal(word, ";")) break; labelp = ALLOC(symbolic_label_t, 1); labelp->label = util_strsav(word); labelp->next = NIL(symbolic_label_t); if (prev_labelp == NIL(symbolic_label_t)) { newlist->symbolic_label = labelp; } else { prev_labelp->next = labelp; } prev_labelp = labelp; newlist->symbolic_label_length++; } *retval = newlist; return TRUE;}int label_index(PLA, word, varp, ip)pPLA PLA;char *word;int *varp;int *ip;{ int var, i; if (PLA->label == NIL(char *) || PLA->label[0] == NIL(char)) { if (sscanf(word, "%d", varp) == 1) { *ip = *varp; return TRUE; } } else { for(var = 0; var < cube.num_vars; var++) { for(i = 0; i < cube.part_size[var]; i++) { if (equal(PLA->label[cube.first_part[var]+i], word)) { *varp = var; *ip = i; return TRUE; } } } } return FALSE;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?