X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=Tools%2FSource%2FMigrationTools%2Forg%2Ftianocore%2Fmigration%2FSourceFileReplacer.java;h=9d4c85cb045fe82a8226908fd847def2ea180665;hb=e8c0c170fa983c73cab1ad6eea7333efbec74ffb;hp=2f2579e64e096b9a790ff3adae12c8eaafe5471b;hpb=d47b990060f9701ddb2e9cd0e09a9cb51378bd0b;p=mirror_edk2.git diff --git a/Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java b/Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java index 2f2579e64e..9d4c85cb04 100644 --- a/Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java +++ b/Tools/Source/MigrationTools/org/tianocore/migration/SourceFileReplacer.java @@ -35,11 +35,28 @@ public final class SourceFileReplacer implements Common.ForDoAll { "BuildResourceDescriptorHob", "BuildFvHob", "BuildCpuHob", + "BuildGuidDataHob", "BuildStackHob", "BuildBspStoreHob", "BuildMemoryAllocationHob" }; - + private static final String[] peiserviceslibfunc = { + "InstallPpi", + "ReInstallPpi", + "LocatePpi", + "NotifyPpi", + "GetBootMode", + "SetBootMode", + "GetHobList", + "CreateHob", + "FfsFindNextVolume", + "FfsFindNextFile", + "FfsFindSectionData", + "InstallPeiMemory", + "AllocatePages", + "AllocatePool", + "PeiResetSystem" + }; //---------------------------------------inner classes---------------------------------------// private static class r8tor9 { r8tor9(String r8, String r9) { @@ -52,7 +69,7 @@ public final class SourceFileReplacer implements Common.ForDoAll { private class IdleLaplace extends Common.Laplace { public String operation(String wholeline) { - return wholeline; + return replaceLibrary (wholeline, mi.hashmacro); } public boolean recognize(String filename) { @@ -87,7 +104,6 @@ public final class SourceFileReplacer implements Common.ForDoAll { private class CLaplace extends Common.Laplace { public String operation(String wholeline) { - boolean addr8 = false; // remove EFI_DRIVER_ENTRY_POINT wholeline = wholeline.replaceAll("(EFI_[A-Z]+_ENTRY_POINT\\s*\\(\\s*" + mi.entrypoint + "\\s*\\)\\s*;)", MigrationTool.MIGRATIONCOMMENT + " $1"); // redefine module entry point for some self-relocated modules @@ -104,51 +120,11 @@ public final class SourceFileReplacer implements Common.ForDoAll { if (Common.find (wholeline, "\\bgDS\\b")) { mi.hashrequiredr9libs.add ("DxeServicesTableLib"); } - // start replacing names - String r8thing; - String r9thing; - Iterator it; - // Converting non-locla function - it = mi.hashnonlocalfunc.iterator(); - while (it.hasNext()) { - r8thing = it.next(); - mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing)); // add a library here - - r8tor9 temp; - if ((r9thing = MigrationTool.db.getR9Func(r8thing)) != null) { - if (!r8thing.equals(r9thing)) { - if (wholeline.contains(r8thing)) { - wholeline = wholeline.replaceAll(r8thing, r9thing); - filefunc.add(new r8tor9(r8thing, r9thing)); - Iterator rt = filefunc.iterator(); - while (rt.hasNext()) { - temp = rt.next(); - if (MigrationTool.db.r8only.contains(temp.r8thing)) { - filer8only.add(r8thing); - mi.hashr8only.add(r8thing); - addr8 = true; - } - } - } - } - } - } //is any of the guids changed? - if (addr8 == true) { - wholeline = addincludefile(wholeline, "\"R8Lib.h\""); - } - + + wholeline = replaceLibrary (wholeline, mi.hashnonlocalfunc); + wholeline = replaceLibrary (wholeline, mi.hashmacro); // Converting macro - it = mi.hashnonlocalmacro.iterator(); - while (it.hasNext()) { //macros are all assumed MdePkg currently - r8thing = it.next(); - //mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing)); - if ((r9thing = MigrationTool.db.getR9Macro(r8thing)) != null) { - if (wholeline.contains(r8thing)) { - wholeline = wholeline.replaceAll(r8thing, r9thing); - filemacro.add(new r8tor9(r8thing, r9thing)); - } - } - } + wholeline = replaceMacro (wholeline, mi.hashnonlocalmacro); // Converting guid replaceGuid(wholeline, mi.guid, "guid", fileguid); @@ -156,55 +132,20 @@ public final class SourceFileReplacer implements Common.ForDoAll { replaceGuid(wholeline, mi.protocol, "protocol", fileprotocol); // Converting Pei - // First , find all (**PeiServices)-> or (*PeiServices). with arg "PeiServices" , change name and add #% - Pattern ptnpei = Pattern.compile("\\(\\*\\*?PeiServices\\)[.-][>]?\\s*(\\w*)(\\s*\\(\\s*PeiServices\\s*,\\s*)", Pattern.MULTILINE); if (mi.getModuleType().matches("PEIM")) { - //if (mi.moduletype.contains("PEIM")) { - Matcher mtrpei = ptnpei.matcher(wholeline); - while (mtrpei.find()) { // ! add a library here ! - wholeline = mtrpei.replaceAll("PeiServices$1#%$2"); - mi.hashrequiredr9libs.add("PeiServicesLib"); - } - mtrpei.reset(); - if (wholeline.contains("PeiServicesCopyMem")) { - wholeline = wholeline.replaceAll("PeiServicesCopyMem#%", "CopyMem"); - mi.hashrequiredr9libs.add("BaseMemoryLib"); - } - if (wholeline.contains("PeiServicesSetMem")) { - wholeline = wholeline.replaceAll("PeiServicesSetMem#%", "SetMem"); - mi.hashrequiredr9libs.add("BaseMemoryLib"); - } - - // Second , find all #% to drop the arg "PeiServices" - Pattern ptnpeiarg = Pattern.compile("#%+(\\s*\\(+\\s*)PeiServices\\s*,\\s*", Pattern.MULTILINE); - Matcher mtrpeiarg = ptnpeiarg.matcher(wholeline); - while (mtrpeiarg.find()) { - wholeline = mtrpeiarg.replaceAll("$1"); - } - } - - wholeline = hobLibFuncDropStatus(wholeline); - - Matcher mtrmac; - mtrmac = Pattern.compile("EFI_IDIV_ROUND\\((.*), (.*)\\)").matcher(wholeline); - if (mtrmac.find()) { - wholeline = mtrmac.replaceAll("\\($1 \\/ $2 \\+ \\(\\(\\(2 \\* \\($1 \\% $2\\)\\) \\< $2\\) \\? 0 \\: 1\\)\\)"); - } - mtrmac = Pattern.compile("EFI_MIN\\((.*), (.*)\\)").matcher(wholeline); - if (mtrmac.find()) { - wholeline = mtrmac.replaceAll("\\(\\($1 \\< $2\\) \\? $1 \\: $2\\)"); - } - mtrmac = Pattern.compile("EFI_MAX\\((.*), (.*)\\)").matcher(wholeline); - if (mtrmac.find()) { - wholeline = mtrmac.replaceAll("\\(\\($1 \\> $2\\) \\? $1 \\: $2\\)"); - } - mtrmac = Pattern.compile("EFI_UINTN_ALIGNED\\((.*)\\)").matcher(wholeline); - if (mtrmac.find()) { - wholeline = mtrmac.replaceAll("\\(\\(\\(UINTN\\) $1\\) \\& \\(sizeof \\(UINTN\\) \\- 1\\)\\)"); - } - if (wholeline.contains("EFI_UINTN_ALIGN_MASK")) { - wholeline = wholeline.replaceAll("EFI_UINTN_ALIGN_MASK", "(sizeof (UINTN) - 1)"); + // + // Try to remove PeiServicesTablePointer; + // + wholeline = dropPeiServicesPointer (wholeline); + // + // Drop the possible return Status of Hob building function. + // + wholeline = drophobLibReturnStatus (wholeline); } + // + // Expand obsolete R8 macro. + // + wholeline = replaceObsoleteMacro (wholeline); show(filefunc, "function"); show(filemacro, "macro"); @@ -275,7 +216,42 @@ public final class SourceFileReplacer implements Common.ForDoAll { } } - private final String hobLibFuncDropStatus(String wholeline) { // or use regex to find pattern "Status = ..." + private final String dropPeiServicesPointer (String wholeline) { + String peiServicesTablePointer; + String peiServicesTableCaller; + String regPeiServices; + Pattern ptnPei; + Matcher mtrPei; + + peiServicesTablePointer = "\\w(?:\\w|[0-9]|->)*"; + peiServicesTableCaller = "\\(\\*\\*?\\s*(" + peiServicesTablePointer + ")\\s*\\)[.-]>?\\s*"; + for (int i = 0; i < peiserviceslibfunc.length; i++) { + regPeiServices = peiServicesTableCaller + peiserviceslibfunc[i] + "\\s*\\(\\s*\\1\\s*,(\\t| )*"; + ptnPei = Pattern.compile (regPeiServices); + mtrPei = ptnPei.matcher (wholeline); + if (mtrPei.find()) { + wholeline = mtrPei.replaceAll("PeiServices" + peiserviceslibfunc[i] + " ("); + mi.hashrequiredr9libs.add("PeiServicesLib"); + } + } + regPeiServices = peiServicesTableCaller + "(CopyMem|SetMem)" + "\\s*\\((\\t| )*"; + ptnPei = Pattern.compile (regPeiServices); + mtrPei = ptnPei.matcher (wholeline); + if (mtrPei.find()) { + wholeline = mtrPei.replaceAll("$2 ("); + mi.hashrequiredr9libs.add("BaseMemoryLib"); + } + + ptnPei = Pattern.compile("#%+(\\s*\\(+\\s*)" + peiServicesTablePointer + "\\s*,\\s*", Pattern.MULTILINE); + mtrPei = ptnPei.matcher(wholeline); + while (mtrPei.find()) { + wholeline = mtrPei.replaceAll("$1"); + } + + return wholeline; + } + + private final String drophobLibReturnStatus (String wholeline) { // or use regex to find pattern "Status = ..." Pattern ptnhobstatus; Matcher mtrhobstatus; String templine = wholeline; @@ -283,12 +259,93 @@ public final class SourceFileReplacer implements Common.ForDoAll { ptnhobstatus = Pattern.compile("(Status\\s*=\\s*)?" + specialhoblibfunc[i] + "(.*?\\)\\s*;)", Pattern.DOTALL); mtrhobstatus = ptnhobstatus.matcher(templine); if (mtrhobstatus.find()) { - 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;"); + templine = mtrhobstatus.replaceAll(specialhoblibfunc[i] + mtrhobstatus.group(2) + "\n " + + MigrationTool.MIGRATIONCOMMENT + "R9 Hob-building library functions will assert if build failure.\n Status = EFI_SUCCESS;"); } } return templine; } - + + private final String replaceMacro (String wholeline, Set symbolSet) { + String r8thing; + String r9thing; + Iterator it; + + it = symbolSet.iterator(); + while (it.hasNext()) { //macros are all assumed MdePkg currently + r8thing = it.next(); + //mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing)); + if ((r9thing = MigrationTool.db.getR9Macro(r8thing)) != null) { + if (wholeline.contains(r8thing)) { + wholeline = wholeline.replaceAll(r8thing, r9thing); + filemacro.add(new r8tor9(r8thing, r9thing)); + } + } + } + return wholeline; + } + + private final String replaceLibrary (String wholeline, Set symbolSet) { + boolean addr8 = false; + // start replacing names + String r8thing; + String r9thing; + Iterator it; + // Converting non-locla function + it = symbolSet.iterator(); + while (it.hasNext()) { + r8thing = it.next(); + mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing)); // add a library here + + r8tor9 temp; + if ((r9thing = MigrationTool.db.getR9Func(r8thing)) != null) { + if (!r8thing.equals(r9thing)) { + if (wholeline.contains(r8thing)) { + wholeline = wholeline.replaceAll(r8thing, r9thing); + filefunc.add(new r8tor9(r8thing, r9thing)); + Iterator rt = filefunc.iterator(); + while (rt.hasNext()) { + temp = rt.next(); + if (MigrationTool.db.r8only.contains(temp.r8thing)) { + filer8only.add(r8thing); + mi.hashr8only.add(r8thing); + addr8 = true; + } + } + } + } + } + } //is any of the guids changed? + if (addr8 == true) { + wholeline = addincludefile(wholeline, "\"R8Lib.h\""); + } + return wholeline; + } + + private final String replaceObsoleteMacro (String wholeline) { + Matcher mtrmac; + mtrmac = Pattern.compile("EFI_IDIV_ROUND\\((.*), (.*)\\)").matcher(wholeline); + if (mtrmac.find()) { + wholeline = mtrmac.replaceAll("\\($1 \\/ $2 \\+ \\(\\(\\(2 \\* \\($1 \\% $2\\)\\) \\< $2\\) \\? 0 \\: 1\\)\\)"); + } + mtrmac = Pattern.compile("EFI_MIN\\((.*), (.*)\\)").matcher(wholeline); + if (mtrmac.find()) { + wholeline = mtrmac.replaceAll("\\(\\($1 \\< $2\\) \\? $1 \\: $2\\)"); + } + mtrmac = Pattern.compile("EFI_MAX\\((.*), (.*)\\)").matcher(wholeline); + if (mtrmac.find()) { + wholeline = mtrmac.replaceAll("\\(\\($1 \\> $2\\) \\? $1 \\: $2\\)"); + } + mtrmac = Pattern.compile("EFI_UINTN_ALIGNED\\((.*)\\)").matcher(wholeline); + if (mtrmac.find()) { + wholeline = mtrmac.replaceAll("\\(\\(\\(UINTN\\) $1\\) \\& \\(sizeof \\(UINTN\\) \\- 1\\)\\)"); + } + if (wholeline.contains("EFI_UINTN_ALIGN_MASK")) { + wholeline = wholeline.replaceAll("EFI_UINTN_ALIGN_MASK", "(sizeof (UINTN) - 1)"); + } + return wholeline; + } + private final void addr8only() throws Exception { String paragraph = null; String line = Common.file2string(MigrationTool.db.DatabasePath + File.separator + "R8Lib.c"); @@ -332,8 +389,8 @@ public final class SourceFileReplacer implements Common.ForDoAll { //-----------------------------------ForDoAll-----------------------------------// public void run(String filepath) throws Exception { - String inname = filepath.replace(mi.modulepath + File.separator, ""); - String tempinpath = mi.modulepath + File.separator + "temp" + File.separator; + String inname = filepath.replace(mi.temppath + File.separator, ""); + String tempinpath = mi.temppath + File.separator; String tempoutpath = MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator; Iterator itLaplace = Laplaces.iterator(); @@ -360,7 +417,7 @@ public final class SourceFileReplacer implements Common.ForDoAll { Laplaces.add(new CLaplace()); Laplaces.add(new IdleLaplace()); - Common.toDoAll(mi.localmodulesources, this); + Common.toDoAll(mi.temppath, this, Common.FILE); if (!mi.hashr8only.isEmpty()) { addr8only();