From: alfred Date: Tue, 22 Aug 2006 08:47:40 +0000 (+0000) Subject: enhance ModuleReader X-Git-Tag: edk2-stable201903~24523 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=446e26ee9238d189475baa37eb7658a6612f9a29;hp=eee63a7bcad36a2100adb951a2f04ff18a415240 enhance ModuleReader git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1350 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/FirstPanel.java b/Tools/Source/MigrationTools/org/tianocore/migration/FirstPanel.java index 8c428087d6..de8e75f142 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/FirstPanel.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/FirstPanel.java @@ -59,12 +59,18 @@ public final class FirstPanel extends JPanel implements ActionListener, ItemList filebox = new JCheckBox("Output to logfile", true); filebox.addItemListener(this); + screenbox = new JCheckBox("Specify logfile", false); screenbox.addItemListener(this); - mibox = new JCheckBox("Show ModuleInfo", false); + + mibox = new JCheckBox("Print ModuleInfo", false); mibox.addItemListener(this); + MigrationTool.printModuleInfo = false; + criticbox = new JCheckBox("Run Critic", true); criticbox.addItemListener(this); + MigrationTool.doCritic = true; + defaultpathbox = new JCheckBox("Use Default Output Path", true); defaultpathbox.addItemListener(this); @@ -205,14 +211,16 @@ public final class FirstPanel extends JPanel implements ActionListener, ItemList } } else if (e.getSource() == mibox) { if (e.getStateChange() == ItemEvent.DESELECTED) { - System.out.println("mibox DESELECTED"); + MigrationTool.printModuleInfo = false; } else if (e.getStateChange() == ItemEvent.SELECTED) { - System.out.println("mibox SELECTED"); + MigrationTool.printModuleInfo = true; } } else if (e.getSource() == criticbox) { if (e.getStateChange() == ItemEvent.DESELECTED) { + MigrationTool.doCritic = false; System.out.println("criticbox DESELECTED"); } else if (e.getStateChange() == ItemEvent.SELECTED) { + MigrationTool.doCritic = true; System.out.println("criticbox SELECTED"); } } else if (e.getSource() == defaultpathbox) { diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/MigrationTool.java b/Tools/Source/MigrationTools/org/tianocore/migration/MigrationTool.java index d6119e6e45..9448acf766 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/MigrationTool.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/MigrationTool.java @@ -16,6 +16,11 @@ public class MigrationTool { 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 void main(String[] args) throws Exception { ui = FirstPanel.init(); db = Database.init(); diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java b/Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java index 4d59a9e953..aa6e7a2ba0 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/ModuleInfo.java @@ -14,7 +14,6 @@ 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 @@ -30,12 +29,9 @@ public class ModuleInfo { } MigrationTool.ui.println(outputpath); - moduleScan(); + mainFlow(); } - //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 String outputpath = null; @@ -61,32 +57,14 @@ public class ModuleInfo { public Set protocol = new HashSet(); public Set ppi = new HashSet(); - private static String migrationcomment = "//%$//"; - - private void moduleScan() throws Exception { - Common.toDoAll(modulepath, ModuleInfo.class.getMethod("enroll", String.class), this, null, Common.FILE); + private void mainFlow() throws Exception { - String filename = null; - if (msaorinf.isEmpty()) { - MigrationTool.ui.println("No INF nor MSA file found!"); - System.exit(0); - } else { - filename = MigrationTool.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); - } + ModuleReader.ModuleScan(this); - CommentOutNonLocalHFile(); - parsePreProcessedSourceCode(); - SourceFileReplacer.flush(this); // some adding library actions are taken here,so it must be put before "MsaWriter" // show result - if (MigrationTool.ui.yesOrNo("Parse of the Module Information has completed. View details?")) { + if (MigrationTool.printModuleInfo) { MigrationTool.ui.println("\nModule Information : "); MigrationTool.ui.println("Entrypoint : " + entrypoint); show(protocol, "Protocol : "); @@ -102,8 +80,11 @@ public class ModuleInfo { new MsaWriter(this).flush(); + if (MigrationTool.doCritic) { + Critic.fireAt(outputpath + File.separator + "Migration_" + modulename); + } + Common.deleteDir(modulepath + File.separator + "temp"); - //Common.toDoAll(modulepath + File.separator + "temp", Common.class.getMethod("deleteDir", String.class), null, null, Common.DIR); MigrationTool.ui.println("Errors Left : " + MigrationTool.db.error); MigrationTool.ui.println("Complete!"); @@ -116,147 +97,6 @@ public class ModuleInfo { MigrationTool.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; - } - } - outfile.append(line + '\n'); - } - outfile.flush(); - outfile.close(); - } - } - - 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; - - 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, MigrationTool.db.getR9Guidname(temp)); // search the database for all 3 kinds of guids , high cost - } - } - //matguid.appendTail(result); - //line = result.toString(); - - // 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)); - } - - // find function call - matfuncc = Func.ptnfuncc.matcher(line); - while (matfuncc.find()) { - if ((temp = Func.register(matfuncc, this, db)) != null) { - //MigrationTool.ui.println(ifile + " dofunc " + temp); - //matfuncc.appendReplacement(result, MigrationTool.db.getR9Func(temp)); - } - } - //matfuncc.appendTail(result); - //line = result.toString(); - - // 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) { - } - } - } - - // 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 - } - } - } - public final void enroll(String filepath) throws Exception { String[] temp; if (filepath.contains(".c") || filepath.contains(".C") || filepath.contains(".h") || @@ -286,7 +126,7 @@ public class ModuleInfo { } return false; } - + public static final void triger(String path) throws Exception { MigrationTool.ui.println("Project Migration"); MigrationTool.ui.println("Copyright (c) 2006, Intel Corporation"); diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/ModuleReader.java b/Tools/Source/MigrationTools/org/tianocore/migration/ModuleReader.java index dd8df97b5e..faa3efefb1 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/ModuleReader.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/ModuleReader.java @@ -15,14 +15,40 @@ package org.tianocore.migration; import java.io.*; import java.util.*; import java.util.regex.*; + import org.tianocore.*; public final class ModuleReader { + private static ModuleInfo mi; + private static final Pattern ptninfequation = Pattern.compile("([^\\s]*)\\s*=\\s*([^\\s]*)"); private static final Pattern ptnsection = Pattern.compile("\\[([^\\[\\]]*)\\]([^\\[\\]]*)\\n", Pattern.MULTILINE); private static final Pattern ptnfilename = Pattern.compile("[^\\s]+"); - public static final void readMsa(String name, ModuleInfo mi) throws Exception { + public static final void ModuleScan(ModuleInfo m) throws Exception { + mi = m; + + Common.toDoAll(mi.modulepath, ModuleInfo.class.getMethod("enroll", String.class), mi, null, Common.FILE); + + String filename = null; + if (mi.msaorinf.isEmpty()) { + MigrationTool.ui.println("No INF nor MSA file found!"); + System.exit(0); + } else { + filename = MigrationTool.ui.choose("Found .inf or .msa file for module\n" + mi.modulepath + "\nChoose one Please", mi.msaorinf.toArray()); + } + if (filename.contains(".inf")) { + readInf(filename); + } else if (filename.contains(".msa")) { + readMsa(filename); + } + + CommentOutNonLocalHFile(); + parsePreProcessedSourceCode(); + + } + + private static final void readMsa(String name) throws Exception { ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(mi.modulepath + File.separator + name)); ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.getModuleSurfaceArea(); MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader(); @@ -42,7 +68,7 @@ public final class ModuleReader { } } - public static final void readInf(String name, ModuleInfo mi) throws Exception { + private static final void readInf(String name) throws Exception { System.out.println("\nParsing INF file: " + name); String wholeline; Matcher mtrinfequation; @@ -89,4 +115,145 @@ public final class ModuleReader { } } } + + // add '//' to all non-local include lines + private static final void CommentOutNonLocalHFile() throws IOException { + BufferedReader rd; + String line; + String curFile; + PrintWriter outfile; + + Pattern ptninclude = Pattern.compile("[\"<](.*[.]h)[\">]"); + Matcher mtrinclude; + + Iterator ii = mi.localmodulesources.iterator(); + while ( ii.hasNext() ) { + curFile = ii.next(); + rd = new BufferedReader(new FileReader(mi.modulepath + File.separator + curFile)); + Common.ensureDir(mi.modulepath + File.separator + "temp" + File.separator + curFile); + outfile = new PrintWriter(new BufferedWriter(new FileWriter(mi.modulepath + File.separator + "temp" + File.separator + curFile))); + while ((line = rd.readLine()) != null) { + if (line.contains("#include")) { + mtrinclude = ptninclude.matcher(line); + if (mtrinclude.find() && mi.localmodulesources.contains(mtrinclude.group(1))) { + } else { + line = MigrationTool.migrationcomment + line; + } + } + outfile.append(line + '\n'); + } + outfile.flush(); + outfile.close(); + } + } + + private static final 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 = mi.localmodulesources.iterator(); + while (ii.hasNext()) { + temp = ii.next(); + if (temp.contains(".c")) { + mi.preprocessedccodes.add(temp); + } + } + + ii = mi.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; + + while (ii.hasNext()) { + StringBuffer wholefile = new StringBuffer(); + ifile = ii.next(); + rd = new BufferedReader(new FileReader(mi.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()) { + mi.entrypoint = matentrypoint.group(2); + if (matentrypoint.group(1).matches("PEIM")) { + mi.hashrequiredr9libs.add("PeimEntryPoint"); + } else { + mi.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, mi, MigrationTool.db)) != null) { // 2.use 3 different matchers , search 3 times to find each + //matguid.appendReplacement(result, MigrationTool.db.getR9Guidname(temp)); // search the database for all 3 kinds of guids , high cost + } + } + //matguid.appendTail(result); + //line = result.toString(); + + // 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()) { + mi.hashEFIcall.add(matefifuncc.group(2)); + } + + // find function call + matfuncc = Func.ptnfuncc.matcher(line); + while (matfuncc.find()) { + if ((temp = Func.register(matfuncc, mi, MigrationTool.db)) != null) { + //MigrationTool.ui.println(ifile + " dofunc " + temp); + //matfuncc.appendReplacement(result, MigrationTool.db.getR9Func(temp)); + } + } + //matfuncc.appendTail(result); + //line = result.toString(); + + // find macro + matmacro = Macro.ptntmacro.matcher(line); + while (matmacro.find()) { + if ((temp = Macro.register(matmacro, mi, MigrationTool.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, mi, MigrationTool.db)) != null) { + } + } + } + + // op on hash + Iterator funcci = mi.hashfuncc.iterator(); + while (funcci.hasNext()) { + if (!mi.hashfuncd.contains(temp = funcci.next()) && !mi.hashEFIcall.contains(temp)) { + mi.hashnonlocalfunc.add(temp); // this set contains both changed and not changed items + } + } + } }