mkgdummy.c 1.93 KB
/* mkgdummy.c v1 Frank Berndt
 * process gate-level netlist for dummy wrappers;
 */

#include <stdio.h>

char *Cmd;
char *Gate;
FILE *Fp;
char Line[1024];

/*
 * print usage message and exit;
 */
void
Usage(void)
{
	printf("Usage: %s gate.v\n", Cmd);
	exit(1);
}

/*
 * skip white space;
 */
char *
SkipSpc(char *s)
{
	while((*s == ' ') || (*s == '\t'))
		s++;
	return(s);
}

/*
 * match line pattern;
 */
int
MatchLine(char *str)
{
	char *s;
	int len;

	s = SkipSpc(Line);
	len = strlen(str);
	if( !strncmp(s, str, len))
		return(1);
	return(0);
}

/*
 * pass module to output;
 */
void
PassModule(char *str)
{
	fputs(Line, stdout);
	while(fgets(Line, sizeof(Line), Fp)) {
		fputs(Line, stdout);
		if(MatchLine("endmodule")) {
			printf(str);
			return;
		}
	}
}

/*
 * replace module instance;
 */
void
ReplaceModule(char *str)
{
	char *s;

	s = SkipSpc(Line);
	while((*s != ' ') & (*s != '\t'))
		s++;
	printf("    %s %s", str, s);
}

/*
 * make_gdummy.c gate.v
 * output to stdout;
 */
int
main(int argc, char **argv)
{
	Cmd = argv[0];
	if(argc != 2)
		Usage();
	Gate = argv[1];
	if( !(Fp = fopen(argv[1], "r"))) {
		printf("%s: cannot open '%s'\n", Cmd, Gate);
		exit(2);
	}
	while(fgets(Line, sizeof(Line), Fp)) {
		if(MatchLine("module rsp")) {
			printf("`ifdef\tRSP_DUMMY\n`else\n");
			PassModule("`endif\t// RSP_DUMMY\n");
		} else if(MatchLine("module rdp")) {
			printf("`ifdef\tRDP_DUMMY\n`else\n");
			PassModule("`endif\t// RDP_DUMMY\n");
		} else if(MatchLine("module ai")) {
			printf("`ifdef\tAI_DUMMY\n`else\n");
			PassModule("`endif\t// AI_DUMMY\n");
		} else if(MatchLine("module vi")) {
			printf("`ifdef\tVI_DUMMY\n`else\n");
			PassModule("`endif\t// VI_DUMMY\n");
		} else if(MatchLine("rsp rsp")) {
			ReplaceModule("`RSP");
		} else if(MatchLine("rdp rdp")) {
			ReplaceModule("`RDP");
		} else if(MatchLine("ai ai")) {
			ReplaceModule("`AI");
		} else if(MatchLine("vi vi")) {
			ReplaceModule("`VI");
		} else
			fputs(Line, stdout);
	}
}