git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1462
6f19259b-4bc3-4df7-8a09-
765794883524
import java.io.*;\r
import java.util.*;\r
\r
import java.io.*;\r
import java.util.*;\r
\r
+import org.tianocore.ModuleTypeDef;\r
+\r
/*\r
Class ModuleInfo is built for scanning the source files, it contains all the needed\r
information and all the temporary data.\r
/*\r
Class ModuleInfo is built for scanning the source files, it contains all the needed\r
information and all the temporary data.\r
public final Set<String> protocol = new HashSet<String>();\r
public final Set<String> ppi = new HashSet<String>();\r
\r
public final Set<String> protocol = new HashSet<String>();\r
public final Set<String> ppi = new HashSet<String>();\r
\r
+ public final String getModuleType() {\r
+ if (moduletype.contains("PEI")) {\r
+ return "PEIM";\r
+ } else {\r
+ return "DXE_DRIVER";\r
+ }\r
+ }\r
+ \r
public final void enroll(String filepath) throws Exception {\r
String temp = null;\r
if (filepath.contains(".c") || filepath.contains(".C") || filepath.contains(".h") || \r
public final void enroll(String filepath) throws Exception {\r
String temp = null;\r
if (filepath.contains(".c") || filepath.contains(".C") || filepath.contains(".h") || \r
msaheader.setGuidValue(mi.guidvalue = Query("Guid Value Not Found! Please Input Guid Value"));\r
}\r
if (mi.moduletype != null) {\r
msaheader.setGuidValue(mi.guidvalue = Query("Guid Value Not Found! Please Input Guid Value"));\r
}\r
if (mi.moduletype != null) {\r
+ msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.getModuleType()));\r
+ /*\r
if (mi.moduletype.contains("PEI")) {\r
msaheader.setModuleType(ModuleTypeDef.Enum.forString("PEIM"));\r
} else {\r
msaheader.setModuleType(ModuleTypeDef.Enum.forString("DXE_DRIVER"));\r
}\r
if (mi.moduletype.contains("PEI")) {\r
msaheader.setModuleType(ModuleTypeDef.Enum.forString("PEIM"));\r
} else {\r
msaheader.setModuleType(ModuleTypeDef.Enum.forString("DXE_DRIVER"));\r
}\r
} else {\r
msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.moduletype = Query("Guid Value Not Found! Please Input Guid Value")));\r
}\r
} else {\r
msaheader.setModuleType(ModuleTypeDef.Enum.forString(mi.moduletype = Query("Guid Value Not Found! Please Input Guid Value")));\r
}\r
private static final Set<String> filer8only = new HashSet<String>();\r
\r
public static final void flush(ModuleInfo moduleinfo) throws Exception {\r
private static final Set<String> filer8only = new HashSet<String>();\r
\r
public static final void flush(ModuleInfo moduleinfo) throws Exception {\r
mi = moduleinfo;\r
\r
String outname = null;\r
mi = moduleinfo;\r
\r
String outname = null;\r
showdetails = true; // set this as default now, may be changed in the future\r
\r
Iterator<String> di = mi.localmodulesources.iterator();\r
showdetails = true; // set this as default now, may be changed in the future\r
\r
Iterator<String> di = mi.localmodulesources.iterator();\r
+ String tempinpath = mi.modulepath + File.separator + "temp" + File.separator;\r
+ String tempoutpath = MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator;\r
while (di.hasNext()) {\r
inname = di.next();\r
if (inname.contains(".c") || inname.contains(".C")) {\r
while (di.hasNext()) {\r
inname = di.next();\r
if (inname.contains(".c") || inname.contains(".C")) {\r
outname = inname;\r
}\r
MigrationTool.ui.println("\nModifying file: " + inname);\r
outname = inname;\r
}\r
MigrationTool.ui.println("\nModifying file: " + inname);\r
- Common.string2file(sourcefilereplace(mi.modulepath + File.separator + "temp" + File.separator + inname), MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + outname);\r
- } else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".dxs") || inname.contains(".uni")) {\r
+ Common.string2file(sourcefilereplace(Common.file2string(tempinpath + inname)), tempoutpath + outname);\r
+ } else if (inname.contains(".h") || inname.contains(".H") || inname.contains(".uni")) {\r
if (inname.contains(".H")) {\r
outname = inname.replaceFirst(".H", ".h");\r
} else {\r
outname = inname;\r
}\r
MigrationTool.ui.println("\nCopying file: " + inname);\r
if (inname.contains(".H")) {\r
outname = inname.replaceFirst(".H", ".h");\r
} else {\r
outname = inname;\r
}\r
MigrationTool.ui.println("\nCopying file: " + inname);\r
- Common.string2file(Common.file2string(mi.modulepath + File.separator + "temp" + File.separator + inname), MigrationTool.ModuleInfoMap.get(mi) + File.separator + "Migration_" + mi.modulename + File.separator + outname);\r
+ Common.string2file(Common.file2string(tempinpath + inname), tempoutpath + outname);\r
+ } else if (inname.contains(".dxs")) {\r
+ outname = inname;\r
+ MigrationTool.ui.println("\nModifying file: " + inname);\r
+ Common.string2file(convertdxs(Common.file2string(tempinpath + inname)), tempoutpath + outname);\r
+ private static final String addincludefile(String wholeline, String hfile) {\r
+ return wholeline.replaceFirst("(\\*/\\s)", "$1\n#include " + hfile + "\n");\r
+ }\r
+ \r
+ private static final String convertdxs(String wholeline) {\r
+ if (mi.getModuleType().equals("PEIM")) {\r
+ return addincludefile(wholeline, "\\<PeimDepex.h\\>");\r
+ } else {\r
+ return addincludefile(wholeline, "\\<DxeDepex.h\\>");\r
+ }\r
+ }\r
+ \r
private static final void addr8only() throws Exception {\r
String paragraph = null;\r
String line = Common.file2string(MigrationTool.db.DatabasePath + File.separator + "R8Lib.c");\r
private static final void addr8only() throws Exception {\r
String paragraph = null;\r
String line = Common.file2string(MigrationTool.db.DatabasePath + File.separator + "R8Lib.c");\r
}\r
\r
// Caution : if there is @ in file , it will be replaced with \n , so is you use Doxygen ... God Bless you!\r
}\r
\r
// Caution : if there is @ in file , it will be replaced with \n , so is you use Doxygen ... God Bless you!\r
- private static final String sourcefilereplace(String filename) throws Exception {\r
- BufferedReader rd = new BufferedReader(new FileReader(filename));\r
- StringBuffer wholefile = new StringBuffer();\r
- String line;\r
+ private static final String sourcefilereplace(String wholeline) throws Exception {\r
boolean addr8 = false;\r
\r
Pattern pat = Pattern.compile("g?(BS|RT)(\\s*->\\s*)([a-zA-Z_]\\w*)", Pattern.MULTILINE); // ! only two level () bracket allowed !\r
//Pattern ptnpei = Pattern.compile("\\(\\*\\*?PeiServices\\)[.-][>]?\\s*(\\w*[#$]*)(\\s*\\(([^\\(\\)]*(\\([^\\(\\)]*\\))?[^\\(\\)]*)*\\))", Pattern.MULTILINE);\r
\r
boolean addr8 = false;\r
\r
Pattern pat = Pattern.compile("g?(BS|RT)(\\s*->\\s*)([a-zA-Z_]\\w*)", Pattern.MULTILINE); // ! only two level () bracket allowed !\r
//Pattern ptnpei = Pattern.compile("\\(\\*\\*?PeiServices\\)[.-][>]?\\s*(\\w*[#$]*)(\\s*\\(([^\\(\\)]*(\\([^\\(\\)]*\\))?[^\\(\\)]*)*\\))", Pattern.MULTILINE);\r
\r
- while ((line = rd.readLine()) != null) {\r
- wholefile.append(line + "\n");\r
- }\r
- line = wholefile.toString();\r
- \r
// replace BS -> gBS , RT -> gRT\r
// replace BS -> gBS , RT -> gRT\r
- Matcher mat = pat.matcher(line);\r
+ Matcher mat = pat.matcher(wholeline);\r
if (mat.find()) { // add a library here\r
MigrationTool.ui.println("Converting all BS->gBS, RT->gRT");\r
if (mat.find()) { // add a library here\r
MigrationTool.ui.println("Converting all BS->gBS, RT->gRT");\r
- line = mat.replaceAll("g$1$2$3"); //unknown correctiveness\r
+ wholeline = mat.replaceAll("g$1$2$3"); //unknown correctiveness\r
}\r
mat.reset();\r
while (mat.find()) {\r
}\r
mat.reset();\r
while (mat.find()) {\r
r8tor9 temp;\r
if ((r9thing = MigrationTool.db.getR9Func(r8thing)) != null) {\r
if (!r8thing.equals(r9thing)) {\r
r8tor9 temp;\r
if ((r9thing = MigrationTool.db.getR9Func(r8thing)) != null) {\r
if (!r8thing.equals(r9thing)) {\r
- if (line.contains(r8thing)) {\r
- line = line.replaceAll(r8thing, 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
filefunc.add(new r8tor9(r8thing, r9thing));\r
Iterator<r8tor9> rt = filefunc.iterator();\r
while (rt.hasNext()) {\r
}\r
} //is any of the guids changed?\r
if (addr8 == true) {\r
}\r
} //is any of the guids changed?\r
if (addr8 == true) {\r
- line = line.replaceFirst("\\*/\n", "\\*/\n#include \"R8Lib.h\"\n");\r
+ wholeline = addincludefile(wholeline, "\"R8Lib.h\"");\r
}\r
\r
// Converting macro\r
}\r
\r
// Converting macro\r
r8thing = it.next();\r
//mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing)); \r
if ((r9thing = MigrationTool.db.getR9Macro(r8thing)) != null) {\r
r8thing = it.next();\r
//mi.hashrequiredr9libs.add(MigrationTool.db.getR9Lib(r8thing)); \r
if ((r9thing = MigrationTool.db.getR9Macro(r8thing)) != null) {\r
- if (line.contains(r8thing)) {\r
- line = line.replaceAll(r8thing, r9thing);\r
+ if (wholeline.contains(r8thing)) {\r
+ wholeline = wholeline.replaceAll(r8thing, r9thing);\r
filemacro.add(new r8tor9(r8thing, r9thing));\r
}\r
}\r
}\r
\r
// Converting guid\r
filemacro.add(new r8tor9(r8thing, r9thing));\r
}\r
}\r
}\r
\r
// Converting guid\r
- replaceGuid(line, mi.guid, "guid", fileguid);\r
- replaceGuid(line, mi.ppi, "ppi", fileppi);\r
- replaceGuid(line, mi.protocol, "protocol", fileprotocol);\r
+ replaceGuid(wholeline, mi.guid, "guid", fileguid);\r
+ replaceGuid(wholeline, mi.ppi, "ppi", fileppi);\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.moduletype.contains("PEIM")) {\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.moduletype.contains("PEIM")) {\r
- Matcher mtrpei = ptnpei.matcher(line);\r
+ Matcher mtrpei = ptnpei.matcher(wholeline);\r
while (mtrpei.find()) { // ! add a library here !\r
while (mtrpei.find()) { // ! add a library here !\r
- line = mtrpei.replaceAll("PeiServices$1#%$2");\r
+ wholeline = mtrpei.replaceAll("PeiServices$1#%$2");\r
mi.hashrequiredr9libs.add("PeiServicesLib");\r
}\r
mtrpei.reset();\r
mi.hashrequiredr9libs.add("PeiServicesLib");\r
}\r
mtrpei.reset();\r
- if (line.contains("PeiServicesCopyMem")) {\r
- line = line.replaceAll("PeiServicesCopyMem#%", "CopyMem");\r
+ if (wholeline.contains("PeiServicesCopyMem")) {\r
+ wholeline = wholeline.replaceAll("PeiServicesCopyMem#%", "CopyMem");\r
mi.hashrequiredr9libs.add("BaseMemoryLib");\r
}\r
mi.hashrequiredr9libs.add("BaseMemoryLib");\r
}\r
- if (line.contains("PeiServicesSetMem")) {\r
- line = line.replaceAll("PeiServicesSetMem#%", "SetMem");\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
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(line);\r
+ Matcher mtrpeiarg = ptnpeiarg.matcher(wholeline);\r
while (mtrpeiarg.find()) {\r
while (mtrpeiarg.find()) {\r
- line = mtrpeiarg.replaceAll("$1");\r
+ wholeline = mtrpeiarg.replaceAll("$1");\r
}\r
}\r
\r
Matcher mtrmac;\r
}\r
}\r
\r
Matcher mtrmac;\r
- mtrmac = Pattern.compile("EFI_IDIV_ROUND\\((.*), (.*)\\)").matcher(line);\r
+ mtrmac = Pattern.compile("EFI_IDIV_ROUND\\((.*), (.*)\\)").matcher(wholeline);\r
- line = mtrmac.replaceAll("\\($1 \\/ $2 \\+ \\(\\(\\(2 \\* \\($1 \\% $2\\)\\) \\< $2\\) \\? 0 \\: 1\\)\\)");\r
+ wholeline = mtrmac.replaceAll("\\($1 \\/ $2 \\+ \\(\\(\\(2 \\* \\($1 \\% $2\\)\\) \\< $2\\) \\? 0 \\: 1\\)\\)");\r
- mtrmac = Pattern.compile("EFI_MIN\\((.*), (.*)\\)").matcher(line);\r
+ mtrmac = Pattern.compile("EFI_MIN\\((.*), (.*)\\)").matcher(wholeline);\r
- line = mtrmac.replaceAll("\\(\\($1 \\< $2\\) \\? $1 \\: $2\\)");\r
+ wholeline = mtrmac.replaceAll("\\(\\($1 \\< $2\\) \\? $1 \\: $2\\)");\r
- mtrmac = Pattern.compile("EFI_MAX\\((.*), (.*)\\)").matcher(line);\r
+ mtrmac = Pattern.compile("EFI_MAX\\((.*), (.*)\\)").matcher(wholeline);\r
- line = mtrmac.replaceAll("\\(\\($1 \\> $2\\) \\? $1 \\: $2\\)");\r
+ wholeline = mtrmac.replaceAll("\\(\\($1 \\> $2\\) \\? $1 \\: $2\\)");\r
- mtrmac = Pattern.compile("EFI_UINTN_ALIGNED\\((.*)\\)").matcher(line);\r
+ mtrmac = Pattern.compile("EFI_UINTN_ALIGNED\\((.*)\\)").matcher(wholeline);\r
- line = mtrmac.replaceAll("\\(\\(\\(UINTN\\) $1\\) \\& \\(sizeof \\(UINTN\\) \\- 1\\)\\)");\r
+ wholeline = mtrmac.replaceAll("\\(\\(\\(UINTN\\) $1\\) \\& \\(sizeof \\(UINTN\\) \\- 1\\)\\)");\r
- if (line.contains("EFI_UINTN_ALIGN_MASK")) {\r
- line = line.replaceAll("EFI_UINTN_ALIGN_MASK", "(sizeof (UINTN) - 1)");\r
+ if (wholeline.contains("EFI_UINTN_ALIGN_MASK")) {\r
+ wholeline = wholeline.replaceAll("EFI_UINTN_ALIGN_MASK", "(sizeof (UINTN) - 1)");\r
}\r
\r
show(filefunc, "function");\r
}\r
\r
show(filefunc, "function");\r
fileprotocol.clear();\r
filer8only.clear();\r
\r
fileprotocol.clear();\r
filer8only.clear();\r
\r
}\r
\r
private static final void show(Set<r8tor9> hash, String sh) {\r
}\r
\r
private static final void show(Set<r8tor9> hash, String sh) {\r