\r
import java.io.*;\r
import java.util.*;\r
-import java.util.regex.*;\r
\r
/*\r
Class ModuleInfo is built for scanning the source files, it contains all the needed\r
}\r
MigrationTool.ui.println(outputpath);\r
\r
- moduleScan();\r
+ mainFlow();\r
}\r
\r
- //public static UI ui = null; //if MIM is still usefull, this can be given to it\r
- public static Database db = null; //if MIM is still usefull, this can be given to it\r
- \r
public String modulepath = null;\r
\r
public String outputpath = null;\r
public Set<String> protocol = new HashSet<String>();\r
public Set<String> ppi = new HashSet<String>();\r
\r
- private static String migrationcomment = "//%$//";\r
- \r
- private void moduleScan() throws Exception {\r
- Common.toDoAll(modulepath, ModuleInfo.class.getMethod("enroll", String.class), this, null, Common.FILE);\r
+ private void mainFlow() throws Exception {\r
\r
- String filename = null;\r
- if (msaorinf.isEmpty()) {\r
- MigrationTool.ui.println("No INF nor MSA file found!");\r
- System.exit(0);\r
- } else {\r
- filename = MigrationTool.ui.choose("Found .inf or .msa file for module\n" + modulepath + "\nChoose one Please", msaorinf.toArray());\r
- }\r
- //ModuleReader mr = new ModuleReader(modulepath, this, db, ui);\r
- if (filename.contains(".inf")) {\r
- ModuleReader.readInf(filename, this);\r
- } else if (filename.contains(".msa")) {\r
- ModuleReader.readMsa(filename, this);\r
- }\r
+ ModuleReader.ModuleScan(this);\r
\r
- CommentOutNonLocalHFile();\r
- parsePreProcessedSourceCode();\r
-\r
SourceFileReplacer.flush(this); // some adding library actions are taken here,so it must be put before "MsaWriter"\r
\r
// show result\r
- if (MigrationTool.ui.yesOrNo("Parse of the Module Information has completed. View details?")) {\r
+ if (MigrationTool.printModuleInfo) {\r
MigrationTool.ui.println("\nModule Information : ");\r
MigrationTool.ui.println("Entrypoint : " + entrypoint);\r
show(protocol, "Protocol : ");\r
\r
new MsaWriter(this).flush();\r
\r
+ if (MigrationTool.doCritic) {\r
+ Critic.fireAt(outputpath + File.separator + "Migration_" + modulename);\r
+ }\r
+ \r
Common.deleteDir(modulepath + File.separator + "temp");\r
- //Common.toDoAll(modulepath + File.separator + "temp", Common.class.getMethod("deleteDir", String.class), null, null, Common.DIR);\r
\r
MigrationTool.ui.println("Errors Left : " + MigrationTool.db.error);\r
MigrationTool.ui.println("Complete!");\r
MigrationTool.ui.println(hash);\r
}\r
\r
- // add '//' to all non-local include lines\r
- private void CommentOutNonLocalHFile() throws IOException {\r
- BufferedReader rd;\r
- String line;\r
- String curFile;\r
- PrintWriter outfile;\r
-\r
- Pattern ptninclude = Pattern.compile("[\"<](.*[.]h)[\">]");\r
- Matcher mtrinclude;\r
-\r
- Iterator<String> ii = localmodulesources.iterator();\r
- while ( ii.hasNext() ) {\r
- curFile = ii.next();\r
- rd = new BufferedReader(new FileReader(modulepath + File.separator + curFile));\r
- Common.ensureDir(modulepath + File.separator + "temp" + File.separator + curFile);\r
- outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "temp" + File.separator + curFile)));\r
- while ((line = rd.readLine()) != null) {\r
- if (line.contains("#include")) {\r
- mtrinclude = ptninclude.matcher(line);\r
- if (mtrinclude.find() && localmodulesources.contains(mtrinclude.group(1))) {\r
- } else {\r
- line = migrationcomment + line;\r
- }\r
- }\r
- outfile.append(line + '\n');\r
- }\r
- outfile.flush();\r
- outfile.close();\r
- }\r
- }\r
-\r
- private void parsePreProcessedSourceCode() throws Exception {\r
- //Cl cl = new Cl(modulepath);\r
- //cl.execute("Fat.c");\r
- //cl.generateAll(preprocessedccodes);\r
- //\r
- //System.out.println("Note!!!! The CL is not implemented now , pls do it manually!!! RUN :");\r
- //System.out.println("cl " + modulepath + "\\temp\\*.c" + " -P");\r
- //String[] list = new File(modulepath + File.separator + "temp").list(); // without CL , add\r
- BufferedReader rd = null;\r
- String ifile = null;\r
- String line = null;\r
- String temp = null;\r
- \r
- Iterator<String> ii = localmodulesources.iterator();\r
- while (ii.hasNext()) {\r
- temp = ii.next();\r
- if (temp.contains(".c")) {\r
- preprocessedccodes.add(temp);\r
- }\r
- }\r
- \r
- ii = preprocessedccodes.iterator();\r
- \r
- Pattern patefifuncc = Pattern.compile("g?(BS|RT)\\s*->\\s*([a-zA-Z_]\\w*)",Pattern.MULTILINE);\r
- Pattern patentrypoint = Pattern.compile("EFI_([A-Z]*)_ENTRY_POINT\\s*\\(([^\\(\\)]*)\\)",Pattern.MULTILINE);\r
- Matcher matguid;\r
- Matcher matfuncc;\r
- Matcher matfuncd;\r
- Matcher matenclosereplace;\r
- Matcher matefifuncc;\r
- Matcher matentrypoint;\r
- Matcher matmacro;\r
- \r
- while (ii.hasNext()) {\r
- StringBuffer wholefile = new StringBuffer();\r
- ifile = ii.next();\r
- rd = new BufferedReader(new FileReader(modulepath + File.separator + "temp" + File.separator + ifile));\r
- while ((line = rd.readLine()) != null) {\r
- wholefile.append(line + '\n');\r
- }\r
- line = wholefile.toString();\r
- \r
- // if this is a Pei phase module , add these library class to .msa\r
- matentrypoint = patentrypoint.matcher(line);\r
- if (matentrypoint.find()) {\r
- entrypoint = matentrypoint.group(2);\r
- if (matentrypoint.group(1).matches("PEIM")) {\r
- hashrequiredr9libs.add("PeimEntryPoint");\r
- } else {\r
- hashrequiredr9libs.add("UefiDriverEntryPoint");\r
- }\r
- }\r
- \r
- // find guid\r
- matguid = Guid.ptnguid.matcher(line); // several ways to implement this , which one is faster ? :\r
- while (matguid.find()) { // 1.currently , find once , then call to identify which is it\r
- if ((temp = Guid.register(matguid, this, db)) != null) { // 2.use 3 different matchers , search 3 times to find each\r
- //matguid.appendReplacement(result, MigrationTool.db.getR9Guidname(temp)); // search the database for all 3 kinds of guids , high cost\r
- }\r
- }\r
- //matguid.appendTail(result);\r
- //line = result.toString();\r
-\r
- // find EFI call in form of '->' , many 'gUnicodeCollationInterface->' like things are not changed\r
- // This item is not simply replaced , special operation is required.\r
- matefifuncc = patefifuncc.matcher(line);\r
- while (matefifuncc.find()) {\r
- hashEFIcall.add(matefifuncc.group(2));\r
- }\r
-\r
- // find function call\r
- matfuncc = Func.ptnfuncc.matcher(line);\r
- while (matfuncc.find()) {\r
- if ((temp = Func.register(matfuncc, this, db)) != null) {\r
- //MigrationTool.ui.println(ifile + " dofunc " + temp);\r
- //matfuncc.appendReplacement(result, MigrationTool.db.getR9Func(temp));\r
- }\r
- }\r
- //matfuncc.appendTail(result);\r
- //line = result.toString();\r
-\r
- // find macro\r
- matmacro = Macro.ptntmacro.matcher(line);\r
- while (matmacro.find()) {\r
- if ((temp = Macro.register(matmacro, this, db)) != null) {\r
- }\r
- }\r
- \r
- // find function definition\r
- // replace all {} to @\r
- while ((matenclosereplace = Func.ptnbrace.matcher(line)).find()) {\r
- line = matenclosereplace.replaceAll("@");\r
- }\r
-\r
- matfuncd = Func.ptnfuncd.matcher(line);\r
- while (matfuncd.find()) {\r
- if ((temp = Func.register(matfuncd, this, db)) != null) {\r
- }\r
- }\r
- }\r
- \r
- // op on hash\r
- Iterator<String> funcci = hashfuncc.iterator();\r
- while (funcci.hasNext()) {\r
- if (!hashfuncd.contains(temp = funcci.next()) && !hashEFIcall.contains(temp)) {\r
- hashnonlocalfunc.add(temp); // this set contains both changed and not changed items\r
- }\r
- }\r
- }\r
- \r
public final void enroll(String filepath) throws Exception {\r
String[] temp;\r
if (filepath.contains(".c") || filepath.contains(".C") || filepath.contains(".h") || \r
}\r
return false;\r
}\r
- \r
+\r
public static final void triger(String path) throws Exception {\r
MigrationTool.ui.println("Project Migration");\r
MigrationTool.ui.println("Copyright (c) 2006, Intel Corporation");\r