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