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

📄 librarystatistics.java

📁 The ElectricTM VLSI Design System is an open-source Electronic Design Automation (EDA) system that c
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
			{				if (!libFound)				{					System.out.println(dir.toString());					libFound = true;				}				String strippedName = isDelib ? libName + ":" + name : parentLibName != null ? parentLibName + ":" + name : stripBackup(name);				try				{					FileInstance f = new FileInstance(this, files[i].toString());					Set<FileInstance> libFiles = preLibraries.get(strippedName);					if (libFiles == null)					{						libFiles = new TreeSet<FileInstance>();						preLibraries.put(strippedName, libFiles);					}					libFiles.add(f);				} catch (IOException e)				{					System.out.println(files[i] + " FAILED " + e);				}			}		}		for (int i = 0; i < files.length; i++)		{			if (!files[i].isDirectory()) continue;            if (files[i].getName().equals("CVS")) continue;			scanDir(files[i], canonicalDirs, preLibraries, isDelib ? libName : null);		}	}	public void readHeaders(ErrorLogger errorLogger)	{		for (Iterator<LibraryName> lit = getLibraryNames(); lit.hasNext(); )		{			LibraryName libraryName = lit.next();			for (Iterator<FileContents> it = libraryName.getVersions(); it.hasNext(); )			{				FileContents fc = it.next();				if (!fc.isElib()) continue;                for (Iterator<URL> uit = fc.fileUrl(); uit.hasNext(); ) {                    URL fileUrl = uit.next();    				if (!ELIB.readStatistics(fileUrl, errorLogger, fc))                        break;                }        		if (fc.header == null) {					System.out.println(fc.fileUrl().next() + " INVALID HEADER");					continue;				}			}		}	}	public void readJelibVersions(ErrorLogger errorLogger)	{		for (Iterator<LibraryName> lit = getLibraryNames(); lit.hasNext(); )		{			LibraryName libraryName = lit.next();			for (Iterator<FileContents> it = libraryName.getVersions(); it.hasNext(); )			{				FileContents fc = it.next();				if (fc.isElib()) continue;                for (Iterator<URL> uit = fc.fileUrl(); uit.hasNext(); ) {                    URL fileUrl = uit.next();                    try {                        JelibParser parser = JelibParser.parse(libraryName.getLibId(), fileUrl, FileType.JELIB, false, errorLogger);                        fc.version = parser.version;                        TreeMap<String,ExternalCell> externalCells = new TreeMap<String,ExternalCell>();                        for (JelibParser.CellContents cc: parser.allCells.values()) {                            fc.localCells.add(cc.cellId.cellName.toString());                            for (JelibParser.NodeContents nc: cc.nodes) {                                if (!(nc.protoId instanceof CellId)) continue;                                CellId cellId = (CellId)nc.protoId;                                if (externalCells.containsKey(cellId.toString())) continue;                                String libPath = parser.externalLibIds.get(cellId.libId);                                ExternalCell ec = new ExternalCell(libPath, cellId.libId.libName, cellId.cellName.toString());                                externalCells.put(cellId.toString(), ec);                            }                        }                        fc.externalCells.addAll(externalCells.values());                        break;                    } catch (Exception e) {                        System.out.println("Error reading " + fileUrl + " " + e.getMessage());                    }                }			}		}	}    public static void checkLibraries(ErrorLogger errorLogger, File[] dirs) {        for (File dir: dirs) {            checkLibrariesInProject(errorLogger, dir);        }    }    private static void checkLibrariesInProject(ErrorLogger errorLogger, File dir) {        File[] files = dir.listFiles();        if (files == null) {            System.out.println(dir + " ACCESS DENIED");            return;        }//        System.out.println("Dir " + dir);        for (File file: files) {            String name = file.getName();            if (name.endsWith(".jelib")) {                checkJelib(errorLogger, file, FileType.JELIB);            } else if (name.endsWith(".delib")) {                checkJelib(errorLogger, file, FileType.DELIB);            }        }    }    private static void checkJelib(ErrorLogger errorLogger, File file, FileType fileType) {        try { //           System.out.println("Checking " + file);            IdManager idManager = new IdManager();            String libName = file.getName();			int extPos = libName.lastIndexOf('.');			if (extPos >= 0)    			libName = libName.substring(0, extPos);            LibId libId = idManager.newLibId(LibId.legalLibraryName(libName));            URL fileUrl = file.toURI().toURL();            JelibParser parser = JelibParser.parse(libId, fileUrl, fileType, false, errorLogger);            checkVars(parser.libVars, file);            for (JelibParser.CellContents cc: parser.allCells.values()) {                checkVars(cc.vars, file);                for (JelibParser.NodeContents nc: cc.nodes)                    checkVars(nc.vars, file);                for (JelibParser.ArcContents ac: cc.arcs)                    checkVars(ac.vars, file);                for (JelibParser.ExportContents ec: cc.exports)                    checkVars(ec.vars, file);            }            TreeMap<CellName,ArrayList<JelibParser.CellContents>> groups = new TreeMap<CellName,ArrayList<JelibParser.CellContents>>();            for (JelibParser.CellContents cc: parser.allCells.values()) {                ArrayList<JelibParser.CellContents> group = groups.get(cc.groupName);                if (group == null) {                    group = new ArrayList<JelibParser.CellContents>();                    groups.put(cc.groupName, group);                }                group.add(cc);            }            for (Map.Entry<CellName,ArrayList<JelibParser.CellContents>> e: groups.entrySet()) {                CellName groupName = e.getKey();                ArrayList<JelibParser.CellContents> cells = e.getValue();                int numParameterizedCells = 0;                for (JelibParser.CellContents cc: cells) {                    Variable[] params = getParams(cc);                    if (params.length > 0)                        numParameterizedCells++;                }                if (numParameterizedCells <= 1) continue;                System.out.println("Checking " + file);                System.out.println("***** Group " + libId + ":" + groupName + " has params");                for (JelibParser.CellContents cc: cells) {                    Variable[] params = getParams(cc);                    if (params.length == 0) continue;                    CellName cellName = cc.cellId.cellName;                    System.out.print("    " + cellName);                    for (Variable var: params) {                        System.out.print(" " + var + "(" +                                com.sun.electric.tool.io.output.JELIB.describeDescriptor(var, var.getTextDescriptor(), true) +                                ")" + var.getObject());                    }                    System.out.println();                }            }        } catch (Exception e) {            System.out.println("Error reading " + file + " " + e.getMessage());            e.printStackTrace();        }    }    private static void checkVars(Variable[] vars, File file) {        for (Variable var: vars) {            if (var.isCode() && !(var.getObject() instanceof String)) {                System.out.println("$$$$$ Variable " + var.getPureValue(-1) + " in " + file);            }        }    }    private static Variable[] getParams(JelibParser.CellContents cc) {        int count = 0;        for (Variable var: cc.vars) {            if (var.getTextDescriptor().isParam() && var.getKey() != NccCellAnnotations.NCC_ANNOTATION_KEY)                count++;        }        if (count == 0) return Variable.NULL_ARRAY;        Variable[] params = new Variable[count];        count = 0;        for (Variable var: cc.vars) {            if (var.getTextDescriptor().isParam() && var.getKey() != NccCellAnnotations.NCC_ANNOTATION_KEY)                params[count++] = var;        }        return params;    }//	public void readLibraries()//	{//		totalLibraryContents = new LibraryContents("noname", new JELIB1());////		for (Iterator lit = getLibraryNames(); lit.hasNext(); )//		{//			LibraryName libraryName = (LibraryName)lit.next();////			System.out.println(libraryName.getName());//			for (Iterator it = libraryName.getVersions(); it.hasNext(); )//			{//				FileContents fc = (FileContents)it.next();//				if (!fc.isElib()) continue;//				String fileName = fc.fileName();//				URL fileURL = TextUtils.makeURLToFile(fileName);//				ELIB1.readLibraryStat(fc, this);//				if (fc.header == null)//				{//					System.out.println(fileName + " INVALID HEADER");//					continue;//				}//			}//		}//		for (Iterator it = totalLibraryContents.variableKeyRefs.values().iterator(); it.hasNext(); )//		{//			String v = ((LibraryContents.VariableKeyRef)it.next()).getName();//			String s = (String)varStat.varNamePool.get(v);//			if (s == null)//			{//				varStat.varNamePool.put(v, v);//			}//		}//	}	public void writeList(String fileName)	{		try		{			new StatisticsOutput(fileName);		} catch (IOException e)		{			System.out.println("Error storing LibraryStatistics to " + fileName + " " + e);		}	}	public static LibraryStatistics readList(IdManager idManager, String fileName)	{		URL fileURL = TextUtils.makeURLToFile(fileName);		try		{			StatisticsInput in = new StatisticsInput(idManager, fileURL);			return in.stat;		} catch (IOException e)		{			System.out.println("Error loading LibraryStatistics from " + fileName + " " + e);		}		return null;	}	public void writeSerialized(String fileName)	{		try		{			new StatisticsOutputSerialized(fileName);		} catch (IOException e)		{			System.out.println("Error storing LibraryStatistics to " + fileName + " " + e);		}	}	public static LibraryStatistics readSerialized(String fileName)	{		URL fileURL = TextUtils.makeURLToFile(fileName);		try		{			StatisticsInputSerialized in = new StatisticsInputSerialized(fileURL);			return in.stat;		} catch (IOException e)		{			System.out.println("Error loading LibraryStatistics from " + fileName + " " + e);		}		return null;	}	public void reportFileLength()	{		int elibUniqueCount = 0;		int jelibUniqueCount = 0;		int elibCount = 0;		int jelibCount = 0;		long elibUniqueLength = 0;		long jelibUniqueLength = 0;		long elibLength = 0;		long jelibLength = 0;		TreeMap<ELIB.Header,GenMath.MutableInteger> headerCounts = new TreeMap<ELIB.Header,GenMath.MutableInteger>();		int withoutHeader = 0;		TreeMap<Version,GenMath.MutableInteger> versionCounts = new TreeMap<Version,GenMath.MutableInteger>();        int withoutVersion = 0;		for (Iterator lit = getLibraryNames(); lit.hasNext(); )		{			LibraryName libraryName = (LibraryName)lit.next();            libraryName.getLibId();			for (Iterator it = libraryName.getVersions(); it.hasNext(); )			{				FileContents fc = (FileContents)it.next();				if (fc.isElib())				{					elibUniqueCount++;					elibCount += fc.instances.size();					elibUniqueLength += fc.fileLength;					elibLength += fc.fileLength * fc.instances.size();					if (fc.header != null)						GenMath.addToBag(headerCounts, fc.header);					else						withoutHeader++;				} else				{					jelibUniqueCount++;					jelibCount += fc.instances.size();					jelibUniqueLength += fc.fileLength;					jelibLength += fc.fileLength * fc.instances.size();				}                if (fc.version != null)                    GenMath.addToBag(versionCounts, fc.version);                else                    withoutVersion++;                System.out.println(fc.getFileName() + " " + fc.version);			}		}		System.out.println("Scanned " + directories.size() + " directories. " + libraryNames.size() + " library names");		System.out.println((elibUniqueLength>>20) + "M (" + elibUniqueLength + ") in " +						   elibUniqueCount + " ELIB files ( unique )");		System.out.println((elibLength>>20) + "M (" + elibLength + ") in " +						   elibCount + " ELIB files ( with duplicates )");		System.out.println("NOHEADER:" + withoutHeader + bagReport(headerCounts));		System.out.println((jelibUniqueLength>>20) + "M (" + jelibUniqueLength + ") in " +						   jelibUniqueCount + " JELIB files ( unique )");		System.out.println((jelibLength>>20) + "M (" + jelibLength + ") in " +						   jelibCount + " JELIB files ( with duplicates )");		System.out.println("NOVERSION:" + withoutVersion + bagReport(versionCounts));	}	public void reportFilePaths() {        TreeMap<String,GenMath.MutableInteger> paths = new TreeMap<String,GenMath.MutableInteger>();        System.out.println(directories.size() + " Directories");		for (Iterator<Directory> it = getDirectories(); it.hasNext(); ) {            Directory directory = it.next();//            System.out.print(directory.dirName);            String projName = directory.dirName;            if (projName.startsWith("/import/async/cad/tools/electric/builds/svn")) continue;            if (projName.startsWith("/import/async/archive/2005/tic/gilda/TreasureIsland/electric-old/projectManagement")) continue;            if (projName.startsWith("/import/async/archive/2005/tic/jkg/projectTest")) continue;            if (projName.startsWith("/import/async/cad/cvs")) continue;            int delibPos = projName.indexOf(".delib");            if (delibPos >= 0) {                int slashPos = projName.lastIndexOf('/', delibPos);                projName = projName.substring(0, slashPos);//                System.out.print(" -> " + projName);            }            GenMath.addToBag(paths, projName);//            System.out.println();		}       System.out.println(paths.size() + " Projects");       for (Map.Entry<String,GenMath.MutableInteger> e: paths.entrySet()) {           System.out.println(e.getKey());//           System.out.println(e.getKey() + " " + e.getValue());       }	}	public void reportCells() {		for (Iterator lit = getLibraryNames(); lit.hasNext(); )		{			LibraryName libraryName = (LibraryName)lit.next();            System.out.println("LibraryName " + libraryName.getLibId() + " " + libraryName.getName());			for (Iterator it = libraryName.getVersions(); it.hasNext(); )			{				FileContents fc = (FileContents)it.next();

⌨️ 快捷键说明

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