"BuildBspStoreHob",\r
"BuildMemoryAllocationHob"\r
};\r
- \r
+ private static final String[] peiserviceslibfunc = {\r
+ "InstallPpi",\r
+ "ReInstallPpi",\r
+ "LocatePpi",\r
+ "NotifyPpi",\r
+ "GetBootMode",\r
+ "SetBootMode",\r
+ "GetHobList",\r
+ "CreateHob",\r
+ "FfsFindNextVolume",\r
+ "FfsFindNextFile",\r
+ "FfsFindSectionData",\r
+ "InstallPeiMemory",\r
+ "AllocatePages",\r
+ "AllocatePool",\r
+ "PeiResetSystem"\r
+ };\r
//---------------------------------------inner classes---------------------------------------//\r
private static class r8tor9 {\r
r8tor9(String r8, String r9) {\r
\r
private class IdleLaplace extends Common.Laplace {\r
public String operation(String wholeline) {\r
- return wholeline;\r
+ return replaceLibrary (wholeline, mi.hashmacro);\r
}\r
\r
public boolean recognize(String filename) {\r
\r
private class CLaplace extends Common.Laplace {\r
public String operation(String wholeline) {\r
- boolean addr8 = false;\r
// remove EFI_DRIVER_ENTRY_POINT\r
wholeline = wholeline.replaceAll("(EFI_[A-Z]+_ENTRY_POINT\\s*\\(\\s*" + mi.entrypoint + "\\s*\\)\\s*;)", MigrationTool.MIGRATIONCOMMENT + " $1");\r
// redefine module entry point for some self-relocated modules\r
if (Common.find (wholeline, "\\bgDS\\b")) {\r
mi.hashrequiredr9libs.add ("DxeServicesTableLib");\r
}\r
- // start replacing names\r
- String r8thing;\r
- String r9thing;\r
- Iterator<String> it;\r
- // Converting non-locla function\r
- it = mi.hashnonlocalfunc.iterator();\r
- while (it.hasNext()) {\r
- r8thing = it.next();\r
- mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing)); // add a library here\r
- \r
- r8tor9 temp;\r
- if ((r9thing = MigrationTool.db.getR9Func(r8thing)) != null) {\r
- if (!r8thing.equals(r9thing)) {\r
- if (wholeline.contains(r8thing)) {\r
- wholeline = wholeline.replaceAll(r8thing, r9thing);\r
- filefunc.add(new r8tor9(r8thing, r9thing));\r
- Iterator<r8tor9> rt = filefunc.iterator();\r
- while (rt.hasNext()) {\r
- temp = rt.next();\r
- if (MigrationTool.db.r8only.contains(temp.r8thing)) {\r
- filer8only.add(r8thing);\r
- mi.hashr8only.add(r8thing);\r
- addr8 = true;\r
- }\r
- }\r
- }\r
- }\r
- }\r
- } //is any of the guids changed?\r
- if (addr8 == true) {\r
- wholeline = addincludefile(wholeline, "\"R8Lib.h\"");\r
- }\r
- \r
+\r
+ wholeline = replaceLibrary (wholeline, mi.hashnonlocalfunc);\r
+ wholeline = replaceLibrary (wholeline, mi.hashmacro);\r
// Converting macro\r
- it = mi.hashnonlocalmacro.iterator();\r
- while (it.hasNext()) { //macros are all assumed MdePkg currently\r
- r8thing = it.next();\r
- //mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing)); \r
- if ((r9thing = MigrationTool.db.getR9Macro(r8thing)) != null) {\r
- if (wholeline.contains(r8thing)) {\r
- wholeline = wholeline.replaceAll(r8thing, r9thing);\r
- filemacro.add(new r8tor9(r8thing, r9thing));\r
- }\r
- }\r
- }\r
+ wholeline = replaceMacro (wholeline, mi.hashnonlocalmacro);\r
\r
// Converting guid\r
replaceGuid(wholeline, mi.guid, "guid", fileguid);\r
replaceGuid(wholeline, mi.protocol, "protocol", fileprotocol);\r
\r
// Converting Pei\r
- // First , find all (**PeiServices)-> or (*PeiServices). with arg "PeiServices" , change name and add #%\r
- Pattern ptnpei = Pattern.compile("\\(\\*\\*?PeiServices\\)[.-][>]?\\s*(\\w*)(\\s*\\(\\s*PeiServices\\s*,\\s*)", Pattern.MULTILINE);\r
if (mi.getModuleType().matches("PEIM")) {\r
- //if (mi.moduletype.contains("PEIM")) {\r
- Matcher mtrpei = ptnpei.matcher(wholeline);\r
- while (mtrpei.find()) { // ! add a library here !\r
- wholeline = mtrpei.replaceAll("PeiServices$1#%$2");\r
- mi.hashrequiredr9libs.add("PeiServicesLib");\r
- }\r
- mtrpei.reset();\r
- if (wholeline.contains("PeiServicesCopyMem")) {\r
- wholeline = wholeline.replaceAll("PeiServicesCopyMem#%", "CopyMem");\r
- mi.hashrequiredr9libs.add("BaseMemoryLib");\r
- }\r
- if (wholeline.contains("PeiServicesSetMem")) {\r
- wholeline = wholeline.replaceAll("PeiServicesSetMem#%", "SetMem");\r
- mi.hashrequiredr9libs.add("BaseMemoryLib");\r
- }\r
-\r
- // Second , find all #% to drop the arg "PeiServices"\r
- Pattern ptnpeiarg = Pattern.compile("#%+(\\s*\\(+\\s*)PeiServices\\s*,\\s*", Pattern.MULTILINE);\r
- Matcher mtrpeiarg = ptnpeiarg.matcher(wholeline);\r
- while (mtrpeiarg.find()) {\r
- wholeline = mtrpeiarg.replaceAll("$1");\r
- }\r
- }\r
- \r
- wholeline = hobLibFuncDropStatus(wholeline);\r
- \r
- Matcher mtrmac;\r
- mtrmac = Pattern.compile("EFI_IDIV_ROUND\\((.*), (.*)\\)").matcher(wholeline);\r
- if (mtrmac.find()) {\r
- wholeline = mtrmac.replaceAll("\\($1 \\/ $2 \\+ \\(\\(\\(2 \\* \\($1 \\% $2\\)\\) \\< $2\\) \\? 0 \\: 1\\)\\)");\r
- }\r
- mtrmac = Pattern.compile("EFI_MIN\\((.*), (.*)\\)").matcher(wholeline);\r
- if (mtrmac.find()) {\r
- wholeline = mtrmac.replaceAll("\\(\\($1 \\< $2\\) \\? $1 \\: $2\\)");\r
- }\r
- mtrmac = Pattern.compile("EFI_MAX\\((.*), (.*)\\)").matcher(wholeline);\r
- if (mtrmac.find()) {\r
- wholeline = mtrmac.replaceAll("\\(\\($1 \\> $2\\) \\? $1 \\: $2\\)");\r
- }\r
- mtrmac = Pattern.compile("EFI_UINTN_ALIGNED\\((.*)\\)").matcher(wholeline);\r
- if (mtrmac.find()) {\r
- wholeline = mtrmac.replaceAll("\\(\\(\\(UINTN\\) $1\\) \\& \\(sizeof \\(UINTN\\) \\- 1\\)\\)");\r
- }\r
- if (wholeline.contains("EFI_UINTN_ALIGN_MASK")) {\r
- wholeline = wholeline.replaceAll("EFI_UINTN_ALIGN_MASK", "(sizeof (UINTN) - 1)");\r
+ //\r
+ // Try to remove PeiServicesTablePointer;\r
+ // \r
+ wholeline = dropPeiServicesPointer (wholeline);\r
+ //\r
+ // Drop the possible return Status of Hob building function.\r
+ // \r
+ wholeline = drophobLibReturnStatus (wholeline);\r
}\r
+ //\r
+ // Expand obsolete R8 macro.\r
+ // \r
+ wholeline = replaceObsoleteMacro (wholeline);\r
\r
show(filefunc, "function");\r
show(filemacro, "macro");\r
}\r
}\r
\r
- private final String hobLibFuncDropStatus(String wholeline) { // or use regex to find pattern "Status = ..."\r
+ private final String dropPeiServicesPointer (String wholeline) {\r
+ String peiServicesTablePointer;\r
+ String peiServicesTableCaller;\r
+ String regPeiServices;\r
+ Pattern ptnPei;\r
+ Matcher mtrPei;\r
+\r
+ peiServicesTablePointer = "\\w(?:\\w|[0-9]|->)*";\r
+ peiServicesTableCaller = "\\(\\*\\*?\\s*(" + peiServicesTablePointer + ")\\s*\\)[.-]>?\\s*";\r
+ for (int i = 0; i < peiserviceslibfunc.length; i++) {\r
+ regPeiServices = peiServicesTableCaller + peiserviceslibfunc[i] + "\\s*\\(\\s*\\1\\s*,(\\t| )*"; \r
+ ptnPei = Pattern.compile (regPeiServices);\r
+ mtrPei = ptnPei.matcher (wholeline);\r
+ if (mtrPei.find()) {\r
+ wholeline = mtrPei.replaceAll("PeiServices" + peiserviceslibfunc[i] + " (");\r
+ mi.hashrequiredr9libs.add("PeiServicesLib");\r
+ }\r
+ }\r
+ regPeiServices = peiServicesTableCaller + "(CopyMem|SetMem)" + "\\s*\\((\\t| )*";\r
+ ptnPei = Pattern.compile (regPeiServices);\r
+ mtrPei = ptnPei.matcher (wholeline);\r
+ if (mtrPei.find()) {\r
+ wholeline = mtrPei.replaceAll("$2 (");\r
+ mi.hashrequiredr9libs.add("BaseMemoryLib");\r
+ }\r
+\r
+ ptnPei = Pattern.compile("#%+(\\s*\\(+\\s*)" + peiServicesTablePointer + "\\s*,\\s*", Pattern.MULTILINE);\r
+ mtrPei = ptnPei.matcher(wholeline);\r
+ while (mtrPei.find()) {\r
+ wholeline = mtrPei.replaceAll("$1");\r
+ }\r
+\r
+ return wholeline;\r
+ }\r
+\r
+ private final String drophobLibReturnStatus (String wholeline) { // or use regex to find pattern "Status = ..."\r
Pattern ptnhobstatus;\r
Matcher mtrhobstatus;\r
String templine = wholeline;\r
ptnhobstatus = Pattern.compile("(Status\\s*=\\s*)?" + specialhoblibfunc[i] + "(.*?\\)\\s*;)", Pattern.DOTALL);\r
mtrhobstatus = ptnhobstatus.matcher(templine);\r
if (mtrhobstatus.find()) {\r
- templine = mtrhobstatus.replaceAll(specialhoblibfunc[i] + mtrhobstatus.group(2) + "\n //Migration comments: R9 Hob-building library functions will assert if build failure.\n Status = EFI_SUCCESS;");\r
+ templine = mtrhobstatus.replaceAll(specialhoblibfunc[i] + mtrhobstatus.group(2) + "\n " + \r
+ MigrationTool.MIGRATIONCOMMENT + "R9 Hob-building library functions will assert if build failure.\n Status = EFI_SUCCESS;");\r
}\r
}\r
return templine;\r
}\r
- \r
+\r
+ private final String replaceMacro (String wholeline, Set<String> symbolSet) {\r
+ String r8thing;\r
+ String r9thing;\r
+ Iterator<String> it;\r
+\r
+ it = symbolSet.iterator();\r
+ while (it.hasNext()) { //macros are all assumed MdePkg currently\r
+ r8thing = it.next();\r
+ //mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing)); \r
+ if ((r9thing = MigrationTool.db.getR9Macro(r8thing)) != null) {\r
+ if (wholeline.contains(r8thing)) {\r
+ wholeline = wholeline.replaceAll(r8thing, r9thing);\r
+ filemacro.add(new r8tor9(r8thing, r9thing));\r
+ }\r
+ }\r
+ }\r
+ return wholeline;\r
+ }\r
+\r
+ private final String replaceLibrary (String wholeline, Set<String> symbolSet) {\r
+ boolean addr8 = false;\r
+ // start replacing names\r
+ String r8thing;\r
+ String r9thing;\r
+ Iterator<String> it;\r
+ // Converting non-locla function\r
+ it = symbolSet.iterator();\r
+ while (it.hasNext()) {\r
+ r8thing = it.next();\r
+ mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing)); // add a library here\r
+ \r
+ r8tor9 temp;\r
+ if ((r9thing = MigrationTool.db.getR9Func(r8thing)) != null) {\r
+ if (!r8thing.equals(r9thing)) {\r
+ if (wholeline.contains(r8thing)) {\r
+ wholeline = wholeline.replaceAll(r8thing, r9thing);\r
+ filefunc.add(new r8tor9(r8thing, r9thing));\r
+ Iterator<r8tor9> rt = filefunc.iterator();\r
+ while (rt.hasNext()) {\r
+ temp = rt.next();\r
+ if (MigrationTool.db.r8only.contains(temp.r8thing)) {\r
+ filer8only.add(r8thing);\r
+ mi.hashr8only.add(r8thing);\r
+ addr8 = true;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ } //is any of the guids changed?\r
+ if (addr8 == true) {\r
+ wholeline = addincludefile(wholeline, "\"R8Lib.h\"");\r
+ }\r
+ return wholeline;\r
+ }\r
+\r
+ private final String replaceObsoleteMacro (String wholeline) {\r
+ Matcher mtrmac;\r
+ mtrmac = Pattern.compile("EFI_IDIV_ROUND\\((.*), (.*)\\)").matcher(wholeline);\r
+ if (mtrmac.find()) {\r
+ wholeline = mtrmac.replaceAll("\\($1 \\/ $2 \\+ \\(\\(\\(2 \\* \\($1 \\% $2\\)\\) \\< $2\\) \\? 0 \\: 1\\)\\)");\r
+ }\r
+ mtrmac = Pattern.compile("EFI_MIN\\((.*), (.*)\\)").matcher(wholeline);\r
+ if (mtrmac.find()) {\r
+ wholeline = mtrmac.replaceAll("\\(\\($1 \\< $2\\) \\? $1 \\: $2\\)");\r
+ }\r
+ mtrmac = Pattern.compile("EFI_MAX\\((.*), (.*)\\)").matcher(wholeline);\r
+ if (mtrmac.find()) {\r
+ wholeline = mtrmac.replaceAll("\\(\\($1 \\> $2\\) \\? $1 \\: $2\\)");\r
+ }\r
+ mtrmac = Pattern.compile("EFI_UINTN_ALIGNED\\((.*)\\)").matcher(wholeline);\r
+ if (mtrmac.find()) {\r
+ wholeline = mtrmac.replaceAll("\\(\\(\\(UINTN\\) $1\\) \\& \\(sizeof \\(UINTN\\) \\- 1\\)\\)");\r
+ }\r
+ if (wholeline.contains("EFI_UINTN_ALIGN_MASK")) {\r
+ wholeline = wholeline.replaceAll("EFI_UINTN_ALIGN_MASK", "(sizeof (UINTN) - 1)");\r
+ }\r
+ return wholeline;\r
+ }\r
+\r
private final void addr8only() throws Exception {\r
String paragraph = null;\r
String line = Common.file2string(MigrationTool.db.DatabasePath + File.separator + "R8Lib.c");\r
\r
//-----------------------------------ForDoAll-----------------------------------//\r
public void run(String filepath) throws Exception {\r
- String inname = filepath.replace(mi.modulepath + File.separator, "");\r
- String tempinpath = mi.modulepath + File.separator + "temp" + File.separator;\r
+ String inname = filepath.replace(mi.temppath + File.separator, "");\r
+ String tempinpath = mi.temppath + File.separator;\r
String tempoutpath = MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator;\r
\r
Iterator<Common.Laplace> itLaplace = Laplaces.iterator();\r
Laplaces.add(new CLaplace());\r
Laplaces.add(new IdleLaplace());\r
\r
- Common.toDoAll(mi.localmodulesources, this);\r
+ Common.toDoAll(mi.temppath, this, Common.FILE);\r
\r
if (!mi.hashr8only.isEmpty()) {\r
addr8only();\r