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

📄 create_supp.c

📁 主要用于大规模的测试生成方法
💻 C
📖 第 1 页 / 共 3 页
字号:
/*----------------------------------------------------------------------------	create_supp.c	Funzioni per la creazione della struttura dati.*/#define		STRONG_DEBUG	1#define		VERBOSE		1#define		TRACE		0#include <ctype.h>#include <stdio.h>#include <string.h>#include <malloc.h>#include "create.h"#include "library.h"void	init_create_memory();void	dump_descr();void	dump_netlist();void	dump_pinlist();char	get_descr_type();int	get_descr_pos( char *s);void	add_assoc();int	get_assoc( char *s );char	get_pin_type();void	create_netlist();void	find_clock_tree( void );extern	void init_library( void );int 	compute_level(int n_pi,int n_ff,int *pi_array,int *ppi_array);int	Hfun( char *s, int tablen );int	find_clock_descr( void );int	find_reset_descr( void );int	find_preset_descr( void );/*int    *pi_array;*//*int      *ppi_array;*//*int      n_ff;*/int	n_sub_descr = 0;	/* numero di descrittori eliminati */int	reset_pos = -1;		/* posizione del descrittore di reset */int	preset_pos = -1;	/* posizione del descrittore di preset */char	library_just_init = 0;	/* mi serve per inizializzare la libreria */void	init_create_memory(){	int	i;	#if TRACE == 1		printf( "[init_create_memory]\n" );	#endif	Descr_Def_Size = DESCR_DEF_SIZE;	n_descr	= 0;	descr = (DESCRIPTOR *)malloc( sizeof( DESCRIPTOR )*Descr_Def_Size ); 	/* quando realloca deve creare lo spazio per i nuovi dati */	for( i = 0; i < Descr_Def_Size; i++ )	{		descr[i].fanin = 0;		descr[i].fanout = 0;		descr[i].to = NULL;		descr[i].from = malloc( sizeof( int )*MAX_FANIN );		if( descr[i].from == NULL )		{			printf( "(create_init_memory) Memory error, quitting...\n" );			exit( 1 );		}	}	n_pi = 0;	n_po = 0;	max_level = 0;		/* OCCHIO */	n_assoc = 0;		/* indica che non ci sono ancora associazioni				   nome componente -> descrittore */ 	list_of_assoc = (ASSOC *)malloc( sizeof( ASSOC )*MAXASSOC );	if( list_of_assoc == NULL )	{		printf( "(init_create_memory) Memory error, quitting...\n" );		return;	}	/* azzera la lista */	for( i = 0; i < MAXASSOC; i++ )		list_of_assoc[i].name = NULL;	l_net = 0;		/* ultima net introdotta */}void    dump_descr(){        int     i, j;        FILE    *fp; 	#if TRACE == 1		printf( "[dump_descr]\n" );	#endif        fp = fopen( "result.log", "w" );         fprintf( fp, "\n\n" );        for( i = 0; i < n_descr; i++ )        {                switch( descr[i].attr )                {                        case PI :                                fprintf( fp, "%d:\tPI\t", i );                                break;                        case PO :                                fprintf( fp, "%d:\tPO\t", i );                                break;                        case INTERNAL :                                fprintf( fp, "%d:\tINTERNAL", i );                                switch( descr[i].type )                                {                                        case FF:					switch(descr[i].ff_type)					{					case FFD:   fprintf(fp, "(FF:D)\t"); break ;					case FFDR:  fprintf(fp, "(FF:DR)\t"); break ;					case FFDP:  fprintf(fp, "(FF:DP)\t"); break ;					case FFDRP: fprintf(fp, "(FF:DRP)\t"); break ;					default:    fprintf(fp, "(FF:??)\t"); break ;					}					break;                                        case OR:                                                fprintf( fp, "(OR)\t" );                                                break;                                        case NOT:                                                fprintf( fp, "(NOT)\t" );                                                break;                                        case NAND:                                                fprintf( fp, "(NAND)\t" );                                                break;                                        case AND:                                                fprintf( fp, "(AND)\t" );                                                break;                                        case NOR:                                                fprintf( fp, "(NOR)\t" );                                                break;                                        case EXOR:                                                fprintf( fp, "(EXOR)\t" );                                                break;                                        case EXNOR:                                                fprintf( fp, "(EXNOR)\t" );                                                break;                                        case BUFF:                                                fprintf( fp, "(BUFF)\t" );                                                break;                                        case LOGIC0:                                                fprintf( fp, "(LOGIC0)\t" );						break;                                        case LOGIC1:                                                fprintf( fp, "(LOGIC1)\t" );						break;                                        default:                                                fprintf( fp, "????\t" );                                                break;                                }                                break;                        default:                                break;                }                fprintf( fp, "%s\n\tlevel = %d\n", descr[i].name, descr[i].level );                fprintf( fp, "\tfanout = %d : ", descr[i].fanout );                for( j = 0; j < descr[i].fanout; j++ )                        fprintf( fp, "%d, ", descr[i].to[j] );                fprintf( fp, "\n" );		if( descr[i].fanout != 0 )			fprintf( fp, "\toutput net = %s\n", descr[i].to_name );                fprintf( fp, "\tfanin = %d : ", descr[i].fanin );                for( j = 0; j < descr[i].fanin; j++ )                        fprintf( fp, "%d, ", descr[i].from[j] );                fprintf( fp, "\n-------------------------------\n" );        }	fclose( fp );}char	get_pin_type( char *s )/* char	*s;	nome del pin */{	/* determina il verso del pin sulla base del suo nome */	#if TRACE == 1		printf( "[get_pin_type]\n" );	#endif	if( strcmp( s, pin_name[0] ) == 0 )		return( IN );	if( strcmp( s, pin_name[1] ) == 0 )		return( IN );	if( strcmp( s, pin_name[2] ) == 0 )		return( IN );	if( strcmp( s, pin_name[3] ) == 0 )		return( IN );	if( strcmp( s, pin_name[4] ) == 0 )		return( IN );	if( strcmp( s, pin_name_ffd[0] ) == 0 )		return( IN );	if( strcmp( s, pin_name_ffd[1] ) == 0 )		return( IN );	if( strcmp( s, pin_name_ffr[2] ) == 0 )		return( IN );	if( strcmp( s, pin_name_ffp[2] ) == 0 )		return( IN );	if( strcmp( s, "LOGIC_0_PIN" ) == 0 )		return( OUT );	if( strcmp( s, "LOGIC_1_PIN" ) == 0 )		return( OUT );	if( strcmp( s, "O" ) == 0 )		return( OUT );	if( strcmp( s, "Q" ) == 0 )		return( OUT );	printf( "(get_pin_type) Unresolved reference, quitting...\n" );	exit( 1 );}char	get_descr_type( s )char	*s;	/* nome del componente */{	/* determina il tipo del componente sulla base del suo nome */	#if TRACE == 1		printf( "[get_descr_type]\n" );	#endif	if( !library_just_init )	{		init_library();		library_just_init = 1;	}	if( strcmp( s, library[AND2].name ) == 0 )		return AND;	if( strcmp( s, library[AND3].name ) == 0 )		return AND;	if( strcmp( s, library[AND4].name ) == 0 )		return AND;	if( strcmp( s, library[AND5].name ) == 0 )		return AND;	if( strcmp( s, library[NAND2].name ) == 0 )		return NAND;	if( strcmp( s, library[NAND3].name ) == 0 )		return NAND;	if( strcmp( s, library[NAND4].name ) == 0 )		return NAND;	if( strcmp( s, library[NAND5].name ) == 0 )		return NAND;	if( strcmp( s, library[OR2].name ) == 0 )		return OR;	if( strcmp( s, library[OR3].name ) == 0 )		return OR;	if( strcmp( s, library[OR4].name ) == 0 )		return OR;	if( strcmp( s, library[OR5].name ) == 0 )		return OR;	if( strcmp( s, library[NOR2].name ) == 0 )		return NOR;	if( strcmp( s, library[NOR3].name ) == 0 )		return NOR;	if( strcmp( s, library[NOR4].name ) == 0 )		return NOR;	if( strcmp( s, library[NOR5].name ) == 0 )		return NOR;	if( strcmp( s, library[XOR2].name ) == 0 )		return EXOR;	if( strcmp( s, library[XOR3].name ) == 0 )		return EXOR;	if( strcmp( s, library[XOR4].name ) == 0 )		return EXOR;	if( strcmp( s, library[XOR5].name ) == 0 )		return EXOR;	if( strcmp( s, library[XNOR2].name ) == 0 )		return EXNOR;	if( strcmp( s, library[XNOR3].name ) == 0 )		return EXNOR;	if( strcmp( s, library[XNOR4].name ) == 0 )		return EXNOR;	if( strcmp( s, library[XNOR5].name ) == 0 )		return EXNOR;	if( strcmp( s, library[INV].name ) == 0 )		return NOT;	if( strcmp( s, library[BUFF].name ) == 0 )		return BUF;	if( strcmp( s, library[FFDG].name ) == 0 )		return FF;	if( strcmp( s, library[FFDRG].name ) == 0 )		return FF;	if( strcmp( s, library[FFDPG].name ) == 0 )		return FF;	if( strcmp( s, library[FFDRPG].name ) == 0 )		return FF;	if( strcmp( s, library[LOGIC_0].name ) == 0 )		return LOGIC0;	if( strcmp( s, library[LOGIC_1].name ) == 0 )		return LOGIC1;	printf( "(get_descr_type) Unresolved reference %s, quitting...\n", s );	exit( 1 );}	 void	add_assoc( int nd, char *name )/* int	nd;	numero di descrittore *//* char	*name;	nome del componente */{	int	pos;	#if TRACE == 1		printf( "[add_assoc]\n" );	#endif	/* calcola la posizione in cui mettere il nuovo elemento */	pos = Hfun( name, MAXASSOC );	if( list_of_assoc[pos].name == NULL )	{		/* non c'e` collisione */		list_of_assoc[pos].name = strdup( name );		list_of_assoc[pos].n_descr = nd;		list_of_assoc[pos].list = NULL;		list_of_assoc[pos].n_el = 0;	}	else	{		/* c'e` collisione */		if( list_of_assoc[pos].n_el == 0 )		{			/* prima collisione */			list_of_assoc[pos].list = malloc( sizeof( LASSOC )*(list_of_assoc[pos].n_el+1) );			if( list_of_assoc[pos].list == NULL )			{				printf( "(add_assoc) Memory error, quitting...\n" );				exit( 1 );			}			list_of_assoc[pos].list[0].name = strdup( name );			list_of_assoc[pos].list[0].n_descr = nd;			list_of_assoc[pos].n_el++;		}		else		{			/* altra collisione */			list_of_assoc[pos].list = realloc( list_of_assoc[pos].list, sizeof( LASSOC )*(list_of_assoc[pos].n_el+1) );			if( list_of_assoc[pos].list == NULL )			{				printf( "(add_assoc) Memory error, quitting...\n" );				exit( 1 );			}			list_of_assoc[pos].list[list_of_assoc[pos].n_el].name = strdup( name );			list_of_assoc[pos].list[list_of_assoc[pos].n_el].n_descr = nd;			list_of_assoc[pos].n_el++;		}	}}	int	get_assoc( char *s ){	int	i, pos;	#if TRACE == 1		printf( "[get_assoc]\n" );	#endif	pos = Hfun( s, MAXASSOC );		if( list_of_assoc[pos].name == NULL )		return( -1 );	if( strcmp( list_of_assoc[pos].name, s ) == 0 )		return( list_of_assoc[pos].n_descr );	else	{		for( i = 0; i < list_of_assoc[pos].n_el; i++ )			if( strcmp( list_of_assoc[pos].list[i].name, s ) == 0 )				return( list_of_assoc[pos].list[i].n_descr );	}	return( -1 );}int	get_descr_pos( char *s){	int	i;	i = get_assoc( s );	if( i == -1 )		return( -1 );	if( reset_pos != -1 && i >= reset_pos )	{		if( preset_pos != -1 && i >= preset_pos )			return( i-2 );		else			return( i-1 );	}	if( preset_pos != -1 && i >= preset_pos )		return( i-1 );	/*	for( i = 0; i < n_descr; i++ )		if( strcmp( s, descr[i].name ) == 0 )			return( i );	return( -1 );	*/}void	add_net( s, fp )char	*s;	/* nome della netlist */int	fp;	/* primo pin della lista */{	/* aggiunge una net al vettore */	#if TRACE == 1		printf( "[add_net]\n" );	#endif	netlist[l_net].netname = strdup( s );	netlist[l_net].n_info = 0;	netlist[l_net].list = fp;		l_net++;}	void	add_net_info( char *nn, char *in, char *pn )/* char	*nn;	nome della net *//* char	*in;	nome instanza del componente *//* char	*pn;	nome del pin */{	#if TRACE == 1		printf( "[add_net_info]\n" );	#endif	if( *in == '-' )	{	/* ho un PI o un PO */		pinlist[n_pin].n_descr = get_assoc( pn );				if( descr[pinlist[n_pin].n_descr].attr == PI )			pinlist[n_pin].dir = OUT;		else			pinlist[n_pin].dir = IN;	}	else	{	/* ho un instanza di un componente */		pinlist[n_pin].n_descr = get_assoc( in );		pinlist[n_pin].dir = get_pin_type( pn );	}			/* salva il nome del pin */	pinlist[n_pin].pin_name = strdup( pn );	/* collego il pin con la net corrispondente */	pinlist[n_pin].net_index = l_net-1;	/* identifico se e` il pin di reset */	netlist[l_net-1].n_info++;	n_pin++;	if( n_pin >= pinlist_size )	{		if(!create_silent) printf( "(add_net_info) Stretching pinlist\n" );		pinlist_size *= 2;		pinlist = realloc( pinlist, sizeof( PIN )*pinlist_size );	}}void	dump_pinlist(){	int	i;	#if TRACE == 1		printf( "[dump_pinlist]\n" );	#endif	printf( "\nPIN found\n" );	for( i = 0; i < n_pin; i++ )	{		printf( "%d: %d, ", i, pinlist[i].n_descr );		if( pinlist[i].dir == OUT )			printf( "OUT\n" );		else			printf( "IN\n" );	}}void	dump_netlist(){	int	i;	FILE	*fp;	#if TRACE == 1		printf( "[dump_netlist]\n" );	#endif	fp = fopen( "netlist.log", "w" );		fprintf( fp, "\nNET identificate\n" );	for( i = 0; i < n_net; i++ )	{		fprintf( fp, "%d: %s\t", i, netlist[i].netname );		fprintf( fp, "n_info = %d\t", netlist[i].n_info );		fprintf( fp, "s = %d\n", netlist[i].list );	}	fclose( fp );}		void	check_netlist( void ){	int	i, j, k, found, err;	if(!create_silent) printf( "\nCecking netlist\n" );	if(!create_silent) printf( "----------------\n" );	err = 0;	for( i = 0; i < n_descr; i++ )	{		for( j = 0; j < descr[i].fanout; j++ )		{		    found = 0;		    for( k = 0; k < descr[descr[i].to[j]].fanin; k++ )			if( descr[descr[i].to[j]].from[k] == i )			    found = 1;		    if( !found && descr[i].attr != PO )		    {			err++;			printf( "(check_netlist) WARNING checking from field: %d, %s \n", i, descr[i].name );		    }		}	}	if(!create_silent) printf( "Fanout: check " );	if( err == 0 )		if(!create_silent) printf( "passed\n" );	else		if(!create_silent) printf( "failed, %d warning\n", err );

⌨️ 快捷键说明

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