X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=Tools%2FSource%2FMigrationTools%2Forg%2Ftianocore%2Fmigration%2FModuleInfo.java;h=242b5c545026e0961f83a8d23c7afae4a98c4109;hp=2f3af0309e9c16b8fda479de182c0eab1d5bfec2;hb=821709bd1b37f1a61fe5c998530083665eb2c854;hpb=d1d10647bfa04dc45c5b19272deabbfe1bb9da95 diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java b/Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java index 2f3af0309e..242b5c5450 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java @@ -14,29 +14,27 @@ package org.tianocore.migration; import java.io.*; import java.util.*; -import java.util.regex.*; /* Class ModuleInfo is built for scanning the source files, it contains all the needed information and all the temporary data. */ -public class ModuleInfo { +public final class ModuleInfo { ModuleInfo(String modulepath) throws Exception { this.modulepath = modulepath; - ui.println("Choose where to place the result"); - if ((outputpath = ui.getFilepath()) == null) { - outputpath = modulepath; + if (ModuleInfo.defaultoutput) { + this.outputpath = this.modulepath.replaceAll(Common.strseparate, "$1"); + } else { + ModuleInfo.ui.println("Choose where to place the result"); + if ((outputpath = ModuleInfo.ui.getFilepath("Please choose where to place the output module")) == null) { + outputpath = modulepath; + } + ModuleInfo.ui.println("Output to: " + outputpath); } - ui.println(outputpath); - - moduleScan(); } - public static UI ui = null; //if MIM is still usefull, this can be given to it - public static Database db = null; //if MIM is still usefull, this can be given to it - - public String modulepath = null; + public final String modulepath; public String outputpath = null; @@ -45,252 +43,112 @@ public class ModuleInfo { public String moduletype = null; public String entrypoint = null; - public Set localmodulesources = new HashSet(); //contains both .c and .h - public Set preprocessedccodes = new HashSet(); - public Set msaorinf = new HashSet(); //only a little, hash may be too big for this - - public Set hashfuncc = new HashSet(); - public Set hashfuncd = new HashSet(); - public Set hashnonlocalfunc = new HashSet(); - public Set hashnonlocalmacro = new HashSet(); - public Set hashEFIcall = new HashSet(); - public Set hashr8only = new HashSet(); + public final Set localmodulesources = new HashSet(); //contains both .c and .h + public final Set preprocessedccodes = new HashSet(); + public final Set msaorinf = new HashSet(); //only a little, hash may be too big for this - public Set hashrequiredr9libs = new HashSet(); // hashrequiredr9libs is now all added in SourceFileReplacer - public Set guid = new HashSet(); - public Set protocol = new HashSet(); - public Set ppi = new HashSet(); + public final Set hashfuncc = new HashSet(); + public final Set hashfuncd = new HashSet(); + public final Set hashnonlocalfunc = new HashSet(); + public final Set hashnonlocalmacro = new HashSet(); + public final Set hashEFIcall = new HashSet(); + public final Set hashr8only = new HashSet(); - private static String migrationcomment = "//%$//"; - - private void moduleScan() throws Exception { - Common.toDoAll(modulepath, ModuleInfo.class.getMethod("enroll", String.class), this, null, Common.FILE); - - String filename = null; - if (msaorinf.isEmpty()) { - ui.println("No INF nor MSA file found!"); - System.exit(0); - } else { - filename = ui.choose("Found .inf or .msa file for module\n" + modulepath + "\nChoose one Please", msaorinf.toArray()); - } - //ModuleReader mr = new ModuleReader(modulepath, this, db, ui); - if (filename.contains(".inf")) { - ModuleReader.readInf(filename, this); - } else if (filename.contains(".msa")) { - ModuleReader.readMsa(filename, this); - } - - CommentOutNonLocalHFile(); - parsePreProcessedSourceCode(); + public final Set hashrequiredr9libs = new HashSet(); // hashrequiredr9libs is now all added in SourceFileReplacer + public final Set guid = new HashSet(); + public final Set protocol = new HashSet(); + public final Set ppi = new HashSet(); - new SourceFileReplacer(modulepath, outputpath, this, db, ui).flush(); // some adding library actions are taken here,so it must be put before "MsaWriter" - - // show result - if (ui.yesOrNo("Parse of the Module Information has completed. View details?")) { - ui.println("\nModule Information : "); - ui.println("Entrypoint : " + entrypoint); - show(protocol, "Protocol : "); - show(ppi, "Ppi : "); - show(guid, "Guid : "); - show(hashfuncc, "call : "); - show(hashfuncd, "def : "); - show(hashEFIcall, "EFIcall : "); - show(hashnonlocalmacro, "macro : "); - show(hashnonlocalfunc, "nonlocal : "); - show(hashr8only, "hashr8only : "); + public final void enroll(String filepath) throws Exception { + if (filepath.contains(".c") || filepath.contains(".C") || filepath.contains(".h") || + filepath.contains(".H") || filepath.contains(".dxs") || filepath.contains(".uni")) { + localmodulesources.add(filepath.replace(modulepath + "\\", "")); + } else if (filepath.contains(".inf") || filepath.contains(".msa")) { + msaorinf.add(filepath.replace(modulepath + "\\", "")); } - - new MsaWriter(modulepath, outputpath, this, db, ui).flush(); - - Common.deleteDir(modulepath + File.separator + "temp"); - //Common.toDoAll(modulepath + File.separator + "temp", Common.class.getMethod("deleteDir", String.class), null, null, Common.DIR); - - ui.println("Errors Left : " + db.error); - ui.println("Complete!"); - ui.println("Your R9 module was placed here: " + modulepath + File.separator + "result"); - ui.println("Your logfile was placed here: " + modulepath); - } - - private void show(Set hash, String show) { - ui.println(show + hash.size()); - ui.println(hash); } - - // add '//' to all non-local include lines - private void CommentOutNonLocalHFile() throws IOException { - BufferedReader rd; - String line; - String curFile; - PrintWriter outfile; - - Pattern ptninclude = Pattern.compile("[\"<](.*[.]h)[\">]"); - Matcher mtrinclude; - Iterator ii = localmodulesources.iterator(); - while ( ii.hasNext() ) { - curFile = ii.next(); - rd = new BufferedReader(new FileReader(modulepath + File.separator + curFile)); - Common.ensureDir(modulepath + File.separator + "temp" + File.separator + curFile); - outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "temp" + File.separator + curFile))); - while ((line = rd.readLine()) != null) { - if (line.contains("#include")) { - mtrinclude = ptninclude.matcher(line); - if (mtrinclude.find() && localmodulesources.contains(mtrinclude.group(1))) { - } else { - line = migrationcomment + line; - } + public static final boolean isModule(String path) { + String[] list = new File(path).list(); + for (int i = 0 ; i < list.length ; i++) { + if (!new File(list[i]).isDirectory()) { + if (list[i].contains(".inf") || list[i].contains(".msa")) { + return true; } - outfile.append(line + '\n'); } - outfile.flush(); - outfile.close(); } + return false; } - private void parsePreProcessedSourceCode() throws Exception { - //Cl cl = new Cl(modulepath); - //cl.execute("Fat.c"); - //cl.generateAll(preprocessedccodes); - // - //System.out.println("Note!!!! The CL is not implemented now , pls do it manually!!! RUN :"); - //System.out.println("cl " + modulepath + "\\temp\\*.c" + " -P"); - //String[] list = new File(modulepath + File.separator + "temp").list(); // without CL , add - BufferedReader rd = null; - String ifile = null; - String line = null; - String temp = null; - - Iterator ii = localmodulesources.iterator(); - while (ii.hasNext()) { - temp = ii.next(); - if (temp.contains(".c")) { - preprocessedccodes.add(temp); - } - } - - ii = preprocessedccodes.iterator(); - - Pattern patefifuncc = Pattern.compile("g?(BS|RT)\\s*->\\s*([a-zA-Z_]\\w*)",Pattern.MULTILINE); - Pattern patentrypoint = Pattern.compile("EFI_([A-Z]*)_ENTRY_POINT\\s*\\(([^\\(\\)]*)\\)",Pattern.MULTILINE); - Matcher matguid; - Matcher matfuncc; - Matcher matfuncd; - Matcher matenclosereplace; - Matcher matefifuncc; - Matcher matentrypoint; - Matcher matmacro; + //---------------------------------------------------------------------------// + + private static final void manipulate(ModuleInfo mi) throws Exception { - while (ii.hasNext()) { - StringBuffer wholefile = new StringBuffer(); - ifile = ii.next(); - rd = new BufferedReader(new FileReader(modulepath + File.separator + "temp" + File.separator + ifile)); - while ((line = rd.readLine()) != null) { - wholefile.append(line + '\n'); - } - line = wholefile.toString(); - - // if this is a Pei phase module , add these library class to .msa - matentrypoint = patentrypoint.matcher(line); - if (matentrypoint.find()) { - entrypoint = matentrypoint.group(2); - if (matentrypoint.group(1).matches("PEIM")) { - hashrequiredr9libs.add("PeimEntryPoint"); - } else { - hashrequiredr9libs.add("UefiDriverEntryPoint"); - } - } - - // find guid - matguid = Guid.ptnguid.matcher(line); // several ways to implement this , which one is faster ? : - while (matguid.find()) { // 1.currently , find once , then call to identify which is it - if ((temp = Guid.register(matguid, this, db)) != null) { // 2.use 3 different matchers , search 3 times to find each - //matguid.appendReplacement(result, db.getR9Guidname(temp)); // search the database for all 3 kinds of guids , high cost - } - } - //matguid.appendTail(result); - //line = result.toString(); + ModuleReader.ModuleScan(mi); + //ModuleInfo.ui.yesOrNo("go on replace?"); + SourceFileReplacer.flush(mi); // some adding library actions are taken here,so it must be put before "MsaWriter" - // find EFI call in form of '->' , many 'gUnicodeCollationInterface->' like things are not changed - // This item is not simply replaced , special operation is required. - matefifuncc = patefifuncc.matcher(line); - while (matefifuncc.find()) { - hashEFIcall.add(matefifuncc.group(2)); - } + //ModuleInfo.ui.yesOrNo("go on show?"); + // show result + if (ModuleInfo.printModuleInfo) { + ModuleInfo.ui.println("\nModule Information : "); + ModuleInfo.ui.println("Entrypoint : " + mi.entrypoint); + show(mi.protocol, "Protocol : "); + show(mi.ppi, "Ppi : "); + show(mi.guid, "Guid : "); + show(mi.hashfuncc, "call : "); + show(mi.hashfuncd, "def : "); + show(mi.hashEFIcall, "EFIcall : "); + show(mi.hashnonlocalmacro, "macro : "); + show(mi.hashnonlocalfunc, "nonlocal : "); + show(mi.hashr8only, "hashr8only : "); + } - // find function call - matfuncc = Func.ptnfuncc.matcher(line); - while (matfuncc.find()) { - if ((temp = Func.register(matfuncc, this, db)) != null) { - //ui.println(ifile + " dofunc " + temp); - //matfuncc.appendReplacement(result, db.getR9Func(temp)); - } - } - //matfuncc.appendTail(result); - //line = result.toString(); + //ModuleInfo.ui.yesOrNo("go on msawrite?"); + new MsaWriter(mi).flush(); + //ModuleInfo.ui.yesOrNo("go on critic?"); - // find macro - matmacro = Macro.ptntmacro.matcher(line); - while (matmacro.find()) { - if ((temp = Macro.register(matmacro, this, db)) != null) { - } - } - - // find function definition - // replace all {} to @ - while ((matenclosereplace = Func.ptnbrace.matcher(line)).find()) { - line = matenclosereplace.replaceAll("@"); - } - - matfuncd = Func.ptnfuncd.matcher(line); - while (matfuncd.find()) { - if ((temp = Func.register(matfuncd, this, db)) != null) { - } - } + if (ModuleInfo.doCritic) { + Critic.fireAt(mi.outputpath + File.separator + "Migration_" + mi.modulename); } + + //ModuleInfo.ui.yesOrNo("go on delete?"); + Common.deleteDir(mi.modulepath + File.separator + "temp"); - // op on hash - Iterator funcci = hashfuncc.iterator(); - while (funcci.hasNext()) { - if (!hashfuncd.contains(temp = funcci.next()) && !hashEFIcall.contains(temp)) { - hashnonlocalfunc.add(temp); // this set contains both changed and not changed items - } - } + ModuleInfo.ui.println("Errors Left : " + ModuleInfo.db.error); + ModuleInfo.ui.println("Complete!"); + //ModuleInfo.ui.println("Your R9 module was placed here: " + mi.modulepath + File.separator + "result"); + //ModuleInfo.ui.println("Your logfile was placed here: " + mi.modulepath); } - public final void enroll(String filepath) throws Exception { - String[] temp; - if (filepath.contains(".c") || filepath.contains(".C") || filepath.contains(".h") || - filepath.contains(".H") || filepath.contains(".dxs") || filepath.contains(".uni")) { - temp = filepath.split("\\\\"); - localmodulesources.add(temp[temp.length - 1]); - } else if (filepath.contains(".inf") || filepath.contains(".msa")) { - temp = filepath.split("\\\\"); - msaorinf.add(temp[temp.length - 1]); - } + private static final void show(Set hash, String show) { + ModuleInfo.ui.println(show + hash.size()); + ModuleInfo.ui.println(hash); } public static final void seekModule(String filepath) throws Exception { - if (isModule(filepath)) { - //System.out.println("I'm in"); - new ModuleInfo(filepath); + if (ModuleInfo.isModule(filepath)) { + manipulate(new ModuleInfo(filepath)); } } - private static final boolean isModule(String path) { - String[] list = new File(path).list(); - for (int i = 0 ; i < list.length ; i++) { - if (!new File(list[i]).isDirectory()) { - if (list[i].contains(".inf") || list[i].contains(".msa")) { - return true; - } - } - } - return false; + public static final void triger(String path) throws Exception { + ModuleInfo.ui.println("Project Migration"); + ModuleInfo.ui.println("Copyright (c) 2006, Intel Corporation"); + Common.toDoAll(path, ModuleInfo.class.getMethod("seekModule", String.class), null, null, Common.DIR); } -/* - public static final void main(String[] args) throws Exception { + + public static UI ui = null; + public static Database db = null; + + public static final String migrationcomment = "//%$//"; + + public static boolean printModuleInfo = false; + public static boolean doCritic = false; + public static boolean defaultoutput = false; + + public static void main(String[] args) throws Exception { ui = FirstPanel.init(); - db = new Database(); + db = Database.init(); } - */ } \ No newline at end of file