⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cvrin.c

📁 主要进行大规模的电路综合
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Revision Control Information * * $Source: /projects/mvsis/Repository/mvsis-1.3/src/sis/espresso/cvrin.c,v $ * $Author: wjiang $ * $Revision: 1.1.1.1 $ * $Date: 2003/02/24 22:24:07 $ * *//*    module: cvrin.c    purpose: cube and cover input routines*/#include "sis.h"static bool line_length_error;static bool last_was_newline;static int lineno;///////////////////////////////////////////////////// A quick hack to define com_get_flag();char * com_get_flag( char * p ) { return NULL; }///////////////////////////////////////////////////static int io_getc (fp)FILE *fp;{    /*	Like getc(3s) but handles input prompt and line number. */    int c;    char *prompt2;    if (last_was_newline && fp == stdin) {	prompt2 = com_get_flag ("prompt2");	if (prompt2 != NULL) fputs (prompt2,stdout);    }    c = getc(fp);    last_was_newline = (c == '\n');    if (last_was_newline) {	lineno++;    } else if (c == EOF && fp == stdin && com_get_flag("prompt2")) {	fputs("\n",stdout);    }    return c;}void skip_line (fpin, fpout, echo)register FILE *fpin, *fpout;register bool echo;{    register int ch;    while ((ch=io_getc(fpin)) != EOF && ch != '\n')	if (echo)	    putc((char) ch, fpout);    if (echo)	putc('\n', fpout);}char *get_word(fp, word)register FILE *fp;register char *word;{    register int ch, i = 0;    while ((ch = io_getc(fp)) != EOF && isspace(ch))    	;    word[i++] = ch;    while ((ch = io_getc(fp)) != EOF && ! isspace(ch))	word[i++] = ch;    word[i++] = '\0';    return word;}/* *  Yes, I know this routine is a mess */void read_cube(fp, PLA)register FILE *fp;pPLA PLA;{    register int var, i;    pcube cf = cube.temp[0], cr = cube.temp[1], cd = cube.temp[2];    bool savef = FALSE, saved = FALSE, saver = FALSE;    char token[256]; 			/* for kiss read hack */    int varx, first, last, offset;	/* for kiss read hack */    (void) set_clear(cf, cube.size);    /* Loop and read binary variables */    for(var = 0; var < cube.num_binary_vars; var++)	switch(io_getc(fp)) {	    case EOF:		goto bad_char;	    case '\n':		if (! line_length_error)		    (void) fprintf(stderr, "product term(s) %s\n",			"span more than one line (warning only)");		line_length_error = TRUE;		var--;		break;	    case ' ': case '|': case '\t':		var--;		break;	    case '2': case '-':		set_insert(cf, var*2+1);	    case '0':		set_insert(cf, var*2);		break;	    case '1':		set_insert(cf, var*2+1);		break;	    case '?':		break;	    default:		goto bad_char;	}    /* Loop for the all but one of the multiple-valued variables */	    for(var = cube.num_binary_vars; var < cube.num_vars-1; var++)	/* Read a symbolic multiple-valued variable */	if (cube.part_size[var] < 0) {	    (void) fscanf(fp, "%s", token);	    if (equal(token, "-") || equal(token, "ANY")) {		if (kiss && var == cube.num_vars - 2) {		    /* leave it empty */		} else {		    /* make it full */		    (void) set_or(cf, cf, cube.var_mask[var]);		}	    } else if (equal(token, "~")) {		;		/* leave it empty ... (?) */	    } else {		if (kiss && var == cube.num_vars - 2)		    varx = var - 1, offset = ABS(cube.part_size[var-1]);		else		    varx = var, offset = 0;		/* Find the symbolic label in the label table */		first = cube.first_part[varx];		last = cube.last_part[varx];		for(i = first; i <= last; i++)		    if (PLA->label[i] == (char *) NULL) {			PLA->label[i] = util_strsav(token); /* add new label */			set_insert(cf, i+offset);			break;		    } else if (equal(PLA->label[i], token)) {			set_insert(cf, i+offset);	/* use column i */			break;		    }		if (i > last) {		    (void) fprintf(stderr,"declared size of variable %d (counting from variable 0) is too small\n", var);		    exit(-1);		}	    }		} else for(i = cube.first_part[var]; i <= cube.last_part[var]; i++)	    switch (io_getc(fp)) {		case EOF:		    goto bad_char;		case '\n':		    if (! line_length_error)			(void) fprintf(stderr, "product term(s) %s\n",			    "span more than one line (warning only)");		    line_length_error = TRUE;		    i--;		    break;		case ' ': case '|': case '\t':		    i--;		    break;		case '1':		    set_insert(cf, i);		case '0':		    break;		default:		    goto bad_char;	    }    /* Loop for last multiple-valued variable */    if (kiss) {	saver = savef = TRUE;	(void) set_xor(cr, cf, cube.var_mask[cube.num_vars - 2]);    } else	(void) set_copy(cr, cf);    (void) set_copy(cd, cf);    for(i = cube.first_part[var]; i <= cube.last_part[var]; i++)	switch (io_getc(fp)) {	    case EOF:		goto bad_char;	    case '\n':		if (! line_length_error)		    (void) fprintf(stderr, "product term(s) %s\n",			"span more than one line (warning only)");		line_length_error = TRUE;		i--;		break;	    case ' ': case '|': case '\t':		i--;		break;	    case '4': case '1':		if (PLA->pla_type & F_type)		    set_insert(cf, i), savef = TRUE;		break;	    case '3': case '0':		if (PLA->pla_type & R_type)		    set_insert(cr, i), saver = TRUE;		break;	    case '2': case '-':		if (PLA->pla_type & D_type)		    set_insert(cd, i), saved = TRUE;	    case '~':		break;	    default:		goto bad_char;	}    if (savef) PLA->F = sf_addset(PLA->F, cf);    if (saved) PLA->D = sf_addset(PLA->D, cd);    if (saver) PLA->R = sf_addset(PLA->R, cr);    return;bad_char:    (void) fprintf(stderr, "(warning): input line #%d ignored\n", lineno);    skip_line(fp, stdout, TRUE);    return;}void parse_pla(fp, PLA)IN FILE *fp;INOUT pPLA PLA;{    int i, var, ch, np, last;    char word[256];    lineno = 1;    last_was_newline = TRUE;    line_length_error = FALSE;loop:    switch(ch = io_getc(fp)) {	case EOF:	    return;	case '\n': case ' ': case '\t': case '\f': case '\r':	    break;	case '#':	    (void) ungetc(ch, fp);	    skip_line(fp, stdout, echo_comments);	    break;	case '.':	    /* .i gives the cube input size (binary-functions only) */	    if (equal(get_word(fp, word), "i")) {		if (cube.fullset != NULL) {		    (void) fprintf(stderr, "extra .i ignored\n");		    skip_line(fp, stdout, /* echo */ FALSE);		} else {		    if (fscanf(fp, "%d", &cube.num_binary_vars) != 1)			fatal("error reading .i");		    cube.num_vars = cube.num_binary_vars + 1;		    cube.part_size = ALLOC(int, cube.num_vars);		}	    /* .o gives the cube output size (binary-functions only) */	    } else if (equal(word, "o")) {		if (cube.fullset != NULL) {		    (void) fprintf(stderr, "extra .o ignored\n");		    skip_line(fp, stdout, /* echo */ FALSE);		} else {		    if (cube.part_size == NULL)			fatal(".o cannot appear before .i");		    if (fscanf(fp, "%d", &(cube.part_size[cube.num_vars-1]))!=1)			fatal("error reading .o");		    cube_setup();		    PLA_labels(PLA);		}	    /* .mv gives the cube size for a multiple-valued function */	    } else if (equal(word, "mv")) {		if (cube.fullset != NULL) {		    (void) fprintf(stderr, "extra .mv ignored\n");		    skip_line(fp, stdout, /* echo */ FALSE);		} else {		    if (cube.part_size != NULL)			fatal("cannot mix .i and .mv");		    if (fscanf(fp,"%d %d",			&cube.num_vars,&cube.num_binary_vars) != 2)			 fatal("error reading .mv");		    if (cube.num_binary_vars < 0)fatal("num_binary_vars (second field of .mv) cannot be negative");		    if (cube.num_vars < cube.num_binary_vars)			fatal("num_vars (1st field of .mv) must exceed num_binary_vars (2nd field of .mv)");		    cube.part_size = ALLOC(int, cube.num_vars);		    for(var=cube.num_binary_vars; var < cube.num_vars; var++)			if (fscanf(fp, "%d", &(cube.part_size[var])) != 1)			    fatal("error reading .mv");		    cube_setup();		    PLA_labels(PLA);		}	    /* .p gives the number of product terms -- we ignore it */	    } else if (equal(word, "p"))		(void) fscanf(fp, "%d", &np);	    /* .e and .end specify the end of the file */	    else if (equal(word, "e") || equal(word,"end")) {                if (cube.fullset == NULL) {                    /* fatal("unknown PLA size, need .i/.o or .mv");*/                } else if (PLA->F == NULL) {                    PLA->F = new_cover(10);                    PLA->D = new_cover(10);                    PLA->R = new_cover(10);                }                return;            }	    /* .kiss turns on the kiss-hack option */	    else if (equal(word, "kiss"))		kiss = TRUE;	    /* .type specifies a logical type for the PLA */	    else if (equal(word, "type")) {		(void) get_word(fp, word);		for(i = 0; pla_types[i].key != 0; i++)		    if (equal(pla_types[i].key + 1, word)) {			PLA->pla_type = pla_types[i].value;			break;		    }		if (pla_types[i].key == 0)		    fatal("unknown type in .type command");	    /* parse the labels */	    } else if (equal(word, "ilb")) {		if (cube.fullset == NULL)		    fatal("PLA size must be declared before .ilb or .ob");		if (PLA->label == NULL)		    PLA_labels(PLA);		for(var = 0; var < cube.num_binary_vars; var++) {		    (void) get_word(fp, word);		    i = cube.first_part[var];		    PLA->label[i+1] = util_strsav(word);		    PLA->label[i] = ALLOC(char, strlen(word) + 6);		    (void) sprintf(PLA->label[i], "%s.bar", word);		}	    } else if (equal(word, "ob")) {		if (cube.fullset == NULL)		    fatal("PLA size must be declared before .ilb or .ob");		if (PLA->label == NULL)		    PLA_labels(PLA);		var = cube.num_vars - 1;		for(i = cube.first_part[var]; i <= cube.last_part[var]; i++) {		    (void) get_word(fp, word);		    PLA->label[i] = util_strsav(word);		}	    /* .label assigns labels to multiple-valued variables */	    } else if (equal(word, "label")) {		if (cube.fullset == NULL)		    fatal("PLA size must be declared before .label");		if (PLA->label == NULL)		    PLA_labels(PLA);		if (fscanf(fp, "var=%d", &var) != 1)		    fatal("Error reading labels");		for(i = cube.first_part[var]; i <= cube.last_part[var]; i++) {		    (void) get_word(fp, word);		    PLA->label[i] = util_strsav(word);		}	    } else if (equal(word, "symbolic")) {		symbolic_t *newlist, *p1;		if (read_symbolic(fp, PLA, word, &newlist)) {		    if (PLA->symbolic == NIL(symbolic_t)) {			PLA->symbolic = newlist;		    } else {			for(p1=PLA->symbolic;p1->next!=NIL(symbolic_t);			    p1=p1->next){			}			p1->next = newlist;		    }		} else {		    fatal("error reading .symbolic");		}	    } else if (equal(word, "symbolic-output")) {		symbolic_t *newlist, *p1;		if (read_symbolic(fp, PLA, word, &newlist)) {		    if (PLA->symbolic_output == NIL(symbolic_t)) {			PLA->symbolic_output = newlist;		    } else {			for(p1=PLA->symbolic_output;p1->next!=NIL(symbolic_t);			    p1=p1->next){			}			p1->next = newlist;		    }		} else {		    fatal("error reading .symbolic-output");		}			    /* .phase allows a choice of output phases */	    } else if (equal(word, "phase")) {		if (cube.fullset == NULL)		    fatal("PLA size must be declared before .phase");		if (PLA->phase != NULL) {		    (void) fprintf(stderr, "extra .phase ignored\n");		    skip_line(fp, stdout, /* echo */ FALSE);		} else {		    do ch = io_getc(fp); while (ch == ' ' || ch == '\t');		    (void) ungetc(ch, fp);		    PLA->phase = set_save(cube.fullset);		    last = cube.last_part[cube.num_vars - 1];		    for(i=cube.first_part[cube.num_vars - 1]; i <= last; i++)			if ((ch = io_getc(fp)) == '0')			    set_remove(PLA->phase, i);			else if (ch != '1')			    fatal("only 0 or 1 allowed in phase description");		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -