celltable.c

来自「主要用于大规模的测试生成方法」· C语言 代码 · 共 708 行 · 第 1/2 页

C
708
字号
/*----------------------------------------------------------------------------		celltable.c*/#include <stdio.h>#include "defines.h"#include "keywords.h"#include "types.h"#include <sys/stat.h>#include <ctype.h>#include <math.h>/* MVMV */#include	"create.h"extern int verbose;extern int ncells;extern int debug;extern PARSETREE *parsetree;extern int keywordlevelused;extern int cell_externs;extern char *keywords[];extern char *cellname, *libraryname, *viewname;extern int currentdir;extern int get_geometry, unscale;extern char *geometry_view;extern int n_module_dirs;extern char **module_dirs;extern PARSETREE *get_array_size();int rootcell = -1;PARSETREE *rootview;static void choose_views();static void write_cell_data();static void write_comment();static void write_interface();static void write_port();static void write_contents();static void write_page_inst();static void write_page_net();static void write_instance();char *get_defname();static void write_net();static void write_joined();static void write_unsup();static void write_portref();static void write_portlist();static void convert_cell();static int cells_done;static int base_x, base_y; /* lower bound  x,y cell coordinates */void findcells() /* scan all cells for requested conversion */{	PARSETREE *cell, *lib, *locate();	void report();	char *nameof(), *realnameof(), *libname, *cname;	/****** catalogue all cells and libraries ******/	for (lib=parsetree->data.tree; lib ; lib=lib->next)	{	if (!(lib->type == Klibrary ||		     (lib->type == Kexternal && cell_externs)))			continue;		libname = nameof( lib);		DEBUG(3) "findcells(): Library '%s' seen\n", libname);		if (libraryname && (libraryname != libname))			continue; /* not the requested lib */		for (cell=lib->data.tree; cell; cell=cell->next)		{				if (cell->type == Kcell)			{				cname = nameof( cell);				if (cellname && (cellname != cname))					continue; /* not the requested cell */				DEBUG(2) "findcells(): cell '%s' lib '%s' entered\n",				         cname, libname);			                choose_views( cell);			} 		}	}        DEBUG(1) "%d EDIF cell%s translated.\n", cells_done, (cells_done==1)?"":"s");}static void choose_views( cell)PARSETREE *cell;{	static int net_view_warning = 0;	static int geo_view_warning = 0;	PARSETREE *view, *schem_view, *net_view, *geo_view;	char *vname, *viewtype;	int multiple_schem, multiple_net, multiple_geo;	schem_view = net_view = geo_view = NULL;	multiple_schem = multiple_net = multiple_geo = 0;	for (view=cell->data.tree; view; view=view->next)	{	if (view->type != Kview) continue;			vname = nameof( view);		viewtype = nameof( view->data.tree->next);		DEBUG(3) "    view '%s' type '%s' seen\n",		         vname, viewtype);				if ((viewtype == keywords[KNETLIST] ||		     viewtype == keywords[KMASKLAYOUT] ||		     viewtype == keywords[KSYMBOLIC] ||		     viewtype == keywords[KSCHEMATIC]) &&		    (!viewname || !strcmp( viewname, vname)))	        {	/* consider this view for netlist info */			if (viewtype == keywords[KNETLIST])			{	if (!net_view) net_view = view;			        else	multiple_net = 1;			} else			{	if (!schem_view) schem_view = view;				else	multiple_schem = 1;			}	        } else if (get_geometry &&                           (viewtype == keywords[KMASKLAYOUT] ||                            viewtype == keywords[KSCHEMATIC] ||		            viewtype == keywords[KSYMBOLIC]			   ) &&		           (!geometry_view ||                            !strcmp( geometry_view, vname)			   ))	        {	/* consider this view for geometric info */			if (viewtype != keywords[KSCHEMATIC])			{	if (!geo_view) geo_view = view;				else	multiple_geo = 1;			} else			{	if (!schem_view) schem_view = view;				else	multiple_schem = 1;			}		}         }			        if (multiple_net || (!net_view && multiple_schem))        {	if (!net_view) net_view = schem_view;		viewname = nameof( net_view);		if (!net_view_warning)		{	DEBUG(0) "Multiple views available for netlist, choosing '%s'!\n",			         viewname);                        DEBUG(0) "Use option '-V viewname' to select otherwise.\n");	                net_view_warning = 1;                }        }        if (multiple_geo || (!geo_view && multiple_schem))        {	if (!geo_view) geo_view = schem_view;		viewname = nameof( geo_view);		if (!geo_view_warning)		{	DEBUG(0) "Multiple views available for geometry, choosing '%s'!\n",			         viewname);                        DEBUG(0) "Use option '-G viewname' to select otherwise.\n");	                geo_view_warning = 1;                }        }        if (!net_view && schem_view)                net_view = schem_view;        if (net_view || geo_view)                convert_cell( cell, net_view, geo_view);}static void convert_cell( cell, net_view, geo_view)PARSETREE *cell, *net_view, *geo_view;{	PARSETREE *t, *contents, *net_intface, *geo_intface;	DEBUG(2)"Convert_cell: cell=%s\n",	         nameof(cell));	contents = net_intface = geo_intface = NULL;        if (net_view)	{	for (t=net_view->data.tree; t; t=t->next)		{	if (t->type == Kcontents)				contents = t;		        else if (t->type == Kinterface)				net_intface = t;		}	}        if (geo_view)	{       for (t=geo_view->data.tree; t; t=t->next)		{       if (t->type == Kinterface)				geo_intface = t;		}	}	if (!net_intface && !geo_intface)	{	DEBUG(0) "EDIF error: Cell '%s', view '%s' has no interface!\n",			nameof(cell), nameof(net_view ? net_view : geo_view));                return;        }        if (!contents && !cell_externs)                return;        if (reopen_cell_output( realnameof(cell), (contents != NULL)))                write_cell_data( cell, geo_intface, net_intface, contents);}int reopen_cell_output( cname, has_contents)char *cname;int has_contents;{	char filename[1024], *dir;	int i, r, l;	struct stat buf;	if (!currentdir)	{	/* if no contents, check presence in read-only module directories */		/* if found there, suppress overwriting by returning 0 */		if (!currentdir && !has_contents && n_module_dirs > 1)		{	for (i=1; i<n_module_dirs; i++)			{	strcpy( filename, module_dirs[i]);				if (filename[strlen(filename)-1] != '/')					strcat( filename, "/");				strcat( filename, cname);				r = stat( filename, &buf);				if (!r && S_ISDIR(buf.st_mode))				{	DEBUG(1) "Not writing cell '%s': is in MODULEPATH\n",						cname);					return(0); /* already there */			        }			}		}		/* generate cell in first directory of modulepath */	        l = strlen( module_dirs[0]);	        sprintf( filename, "%s%s%s", module_dirs[0],			(module_dirs[0][l-1]=='/')?"":"/", cname); 	        r = stat( filename, &buf);		/*	        if (r)	r = mkdir( filename,				  (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH));			        if (r)		{	DEBUG(0) "Couldn't find/create cell directory '%s'!\n", filename);	                return(0);                }		*/                l = strlen( filename);                sprintf( filename+l, "/%s.%s", cname, has_contents?"min":"io");                	} else		sprintf( filename, "%s.%s", cname, has_contents?"min":"io");        return(1);}static void  write_cell_data( cell, geo_intface, net_intface, contents)PARSETREE *cell, *geo_intface, *net_intface, *contents;{	cells_done++;	if (net_intface || geo_intface)		write_interface( net_intface, geo_intface);		if (contents)	write_contents( contents);		fflush( stdout);}static void write_comment( comment)PARSETREE *comment;{}static PARSETREE *scan4bb( parent)PARSETREE *parent;{	PARSETREE *bb;	for ( bb=parent->data.tree; bb; bb=bb->next)	{	if (bb->type == KboundingBox)			return( bb);	}	return( NULL);}static PARSETREE *find_bb( intface)PARSETREE *intface;{	PARSETREE *t;	PARSETREE *symbol = NULL;	PARSETREE *bb = NULL;	if (!intface) return( NULL);	for (t=intface->data.tree; t; t=t->next)	{			if (t->type == KprotectionFrame)		{	bb = scan4bb( t);			if (bb) break;		} else if (t->type == Ksymbol)		{	symbol = t;		}	}	if (!bb && symbol)		bb = scan4bb( symbol);	return( bb);}static void write_bb( bb)PARSETREE *bb;{	int x1, x2, y1, y2, h;	PARSETREE *pt1, *pt2;	pt1 = bb->data.tree->data.tree;	if (!pt1 || pt1->type != Kpt)	{	DEBUG(0) "Line %d: '(pt ..' expected!\n", bb->line);	        return;        }	pt2 = pt1->next;	if (!pt2 || pt2->type != Kpt)	{	DEBUG(0) "Line %d: '(pt ..' expected!\n", bb->line);	        return;        }	x1 = pt1->data.tree->data.ival;	y1 = pt1->data.tree->next->data.ival;	x2 = pt2->data.tree->data.ival;	y2 = pt2->data.tree->next->data.ival;		if (x1 > x2) h=x1, x1=x2, x2=h;	if (y1 > y2) h=y1, y1=y2, y2=h;	base_x = x1;	base_y = y1;}static void write_interface( net_intface, geo_intface)PARSETREE *net_intface, *geo_intface;{	PARSETREE *t, *bb, *intface;	bb = find_bb( net_intface);	if (!bb) bb = find_bb( geo_intface);

⌨️ 快捷键说明

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