Exemplo n.º 1
0
static void
get_tok(char *buffer,
	int pass,
	int doall,
	boolean *done,
	boolean *add_truth_table,
	INP t_model* inpad_model, 
	INP t_model* outpad_model, 
	INP t_model* logic_model, 
	INP t_model* latch_model,
	INP t_model* user_models)
{

/* Figures out which, if any token is at the start of this line and *
 * takes the appropriate action.                                    */

#define TOKENS " \t\n"
    char *ptr;
	char *fn;
	struct s_linked_vptr *data;

    ptr = my_strtok(buffer, TOKENS, blif, buffer);
    if(ptr == NULL)
		return;

	if(*add_truth_table) {
		if(ptr[0] == '0' || ptr[0] == '1' || ptr[0] == '-') {
			data = my_malloc(sizeof(struct s_linked_vptr));
			fn = ptr;
			ptr = my_strtok(NULL, TOKENS, blif, buffer);
			if(!ptr || strlen(ptr) != 1) {
				if(strlen(fn) == 1) {
					/* constant generator */
					data->next = logical_block[num_logical_blocks - 1].truth_table;
					data->data_vptr = my_malloc(strlen(fn) + 4);
					sprintf(data->data_vptr, " %s", fn);
					logical_block[num_logical_blocks - 1].truth_table = data;
					ptr = fn;
				} else {
					printf(ERRTAG "Unknown truth table data %s %s\n", fn, ptr);
					exit(1);
				}
			} else {
				data->next = logical_block[num_logical_blocks - 1].truth_table;
				data->data_vptr = my_malloc(strlen(fn) + 3);
				sprintf(data->data_vptr, "%s %s", fn, ptr);
				logical_block[num_logical_blocks - 1].truth_table = data;
			}
		}
	}

    if(strcmp(ptr, ".names") == 0)
	{
		*add_truth_table = FALSE;
	    if(pass == 3)
		{
		    add_lut(doall, logic_model);
			*add_truth_table = doall;
		}
	    else
		{
		    dum_parse(buffer);
		}
	    return;
	}

    if(strcmp(ptr, ".latch") == 0)
	{
		*add_truth_table = FALSE;
	    if(pass == 3)
		{
		    add_latch(doall, latch_model);
		}
	    else
		{
		    dum_parse(buffer);
		}
	    return;
	}

    if(strcmp(ptr, ".model") == 0)
	{
		*add_truth_table = FALSE;
	    ptr = my_strtok(NULL, TOKENS, blif, buffer);
		if(doall && pass == 4)
		{		
		    if(ptr != NULL)
			{
			    model = (char *)my_malloc((strlen(ptr) + 1) * sizeof(char));
			    strcpy(model, ptr);
				if(blif_circuit_name == NULL) {
					blif_circuit_name = my_strdup(model);
				}
			}
		    else
			{
			    model = (char *)my_malloc(sizeof(char));
			    model[0] = '\0';
			}
		}
		
		if(pass == 0 && model_lines > 0) {
			check_and_count_models(doall, ptr, user_models);
		} else {
			dum_parse(buffer);
		}
		model_lines++;
	    return;
	}

    if(strcmp(ptr, ".inputs") == 0)
	{
		*add_truth_table = FALSE;
		/* packing can only one fully defined model */
	    if(pass == 1 && model_lines == 1)
		{
		    io_line(DRIVER, doall, inpad_model);
		    *done = 1;
		}
	    else
		{
		    dum_parse(buffer);
		    if(pass == 4 && doall)
				ilines++;	/* Error checking only */
		}
	    return;
	}

    if(strcmp(ptr, ".outputs") == 0)
	{
		*add_truth_table = FALSE;
		/* packing can only one fully defined model */
	    if(pass == 2  && model_lines == 1)
		{
		    io_line(RECEIVER, doall, outpad_model);
		    *done = 1;
		}
	    else
		{
		    dum_parse(buffer);
		    if(pass == 4 && doall)
				olines++;	/* Make sure only one .output line */
		}		/* For error checking only */
	    return;
	}
    if(strcmp(ptr, ".end") == 0)
	{
		*add_truth_table = FALSE;
		if(pass == 4 && doall)
		{
			endlines++;	/* Error checking only */
		}
		return;
	}

	if(strcmp(ptr, ".subckt") == 0)
	{
		*add_truth_table = FALSE;
		if(pass == 3)
		{
			add_subckt(doall, user_models);
		}
	}

/* Could have numbers following a .names command, so not matching any *
 * of the tokens above is not an error.                               */

}
Exemplo n.º 2
0
static void get_tok(char* buffer, int pass, int doall, int* done,
                    int lut_size)
{
    /* Figures out which, if any token is at the start of this line and *
     * takes the appropriate action.                                    */
#define TOKENS " \t\n"
    char* ptr;
    ptr = my_strtok(buffer, TOKENS, blif, buffer);

    if (ptr == NULL) {
        return;
    }

    if (strcmp(ptr, ".names") == 0) {
        if (pass == 3) {
            add_lut(doall, lut_size);
        } else {
            dum_parse(buffer);
        }

        return;
    }

    if (strcmp(ptr, ".latch") == 0) {
        if (pass == 3) {
            add_latch(doall, lut_size);
        } else {
            dum_parse(buffer);
        }

        return;
    }

    if (strcmp(ptr, ".model") == 0) {
        ptr = my_strtok(NULL, TOKENS, blif, buffer);

        if (doall && pass == 3) { /* Only bother on main second pass. */
            if (ptr != NULL) {
                model = (char*) my_malloc((strlen(ptr) + 1) * sizeof(char));
                strcpy(model, ptr);
            } else {
                model = (char*) my_malloc(sizeof(char));
                model[0] = '\0';
            }

            model_lines++;              /* For error checking only */
        }

        return;
    }

    if (strcmp(ptr, ".inputs") == 0) {
        if (pass == 1) {
            io_line(DRIVER, doall);
            *done = 1;
        } else {
            dum_parse(buffer);

            if (pass == 3 && doall) {
                ilines++;    /* Error checking only */
            }
        }

        return;
    }

    if (strcmp(ptr, ".outputs") == 0) {
        if (pass == 2) {
            io_line(RECEIVER, doall);
            *done = 1;
        } else {
            dum_parse(buffer);

            if (pass == 3 && doall) {
                olines++;    /* Make sure only one .output line */
            }
        }                            /* For error checking only */

        return;
    }

    if (strcmp(ptr, ".end") == 0) {
        if (pass == 3 && doall) {
            endlines++;    /* Error checking only */
        }

        return;
    }

    /* Could have numbers following a .names command, so not matching any *
     * of the tokens above is not an error.                               */
}