--- /dev/null
+Manifest-Version: 1.0\r
+Main-Class: org.tianocore.migration.ModuleInfo\r
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>\r
+<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" >\r
+ <MsaHeader>\r
+ <ModuleName>MigrationTools</ModuleName>\r
+ <ModuleType>TOOL</ModuleType>\r
+ <GuidValue>09C77FAE-6374-408e-AB88-32822B92096E</GuidValue>\r
+ <Version>1.0</Version>\r
+ <Abstract>This is the EFI/Tiano Migration Tool Resources Module</Abstract>\r
+ <Description>\r
+ This Module provdes the entity, action and exception package for Migration\r
+ tools, This package will be shared for building tools or wizard tools.\r
+ </Description>\r
+ <Copyright>Copyright 2005-2006, Intel Corporation</Copyright>\r
+ <License>\r
+All rights reserved.\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the \r
+BSD License which accompanies this distribution. The full text of the \r
+license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ </License>\r
+ <Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>\r
+ </MsaHeader>\r
+ <ModuleDefinitions>\r
+ <SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>\r
+ <BinaryModule>false</BinaryModule>\r
+ <OutputFileBasename>NULL</OutputFileBasename>\r
+ </ModuleDefinitions>\r
+ <SourceFiles>\r
+ <Filename>build.xml</Filename>\r
+ <Filename>org/tianocore/migration/Database.java</Filename>\r
+ <Filename>org/tianocore/migration/FirstPanel.java</Filename> \r
+ <Filename>org/tianocore/migration/Func.java</Filename> \r
+ <Filename>org/tianocore/migration/Guid.java</Filename> \r
+ <Filename>org/tianocore/migration/Macro.java</Filename> \r
+ <Filename>org/tianocore/migration/ModuleInfo.java</Filename> \r
+ <Filename>org/tianocore/migration/ModuleReader.java</Filename> \r
+ <Filename>org/tianocore/migration/MsaWriter.java</Filename> \r
+ <Filename>org/tianocore/migration/SourceFileReplacer.java</Filename>\r
+ <Filename>org/tianocore/migration/UI.java</Filename>\r
+ </SourceFiles>\r
+</ModuleSurfaceArea>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0"?>\r
+<!--\r
+Copyright (c) 2006, Intel Corporation\r
+All rights reserved. This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+-->\r
+<project name="MigrationTools" default="MigrationTools" basedir=".">\r
+\r
+ <taskdef resource="net/sf/antcontrib/antlib.xml"/>\r
+ <property environment="env"/>\r
+ <property name="WORKSPACE" value="${env.WORKSPACE}"/>\r
+ <path id="classpath">\r
+ <fileset dir="${WORKSPACE}/Tools/Jars" includes="*.jar"/>\r
+ <fileset dir="${env.XMLBEANS_HOME}/lib" includes="*.jar"/>\r
+ </path>\r
+ <property name="buildDir" value="build"/>\r
+ <property name="installLocation" value="${WORKSPACE}/Tools/bin"/>\r
+ <target name="MigrationTools" depends="install"/>\r
+ <target name="source">\r
+ <mkdir dir="${buildDir}"/>\r
+ <javac srcdir="." destdir="${buildDir}">\r
+ <classpath refid="classpath"/>\r
+ <compilerarg value="-Xlint"/>\r
+ </javac>\r
+ </target>\r
+ <target name="clean">\r
+ <delete dir="${buildDir}"/>\r
+ </target>\r
+ <target name="cleanall">\r
+ <delete dir="${buildDir}"/>\r
+ <delete file="${installLocation}/MigrationTools.jar"/>\r
+ <if>\r
+ <available file="${installLocation}/MigrationTools.jar"/>\r
+ <then>\r
+ <echo message="You must manually remove the file: ${installLocation}/MigrationTools.jar"/>\r
+ <echo message="Java has already loaded the file, and cannot remove it within ANT!"/>\r
+ </then>\r
+ </if>\r
+ </target>\r
+ <target name="install" depends="source">\r
+ <jar destfile="${installLocation}/MigrationTools.jar"\r
+ basedir="${buildDir}"\r
+ includes="**"\r
+ manifest="MANIFEST.MF"\r
+ />\r
+ </target>\r
+</project>\r
--- /dev/null
+package org.tianocore.migration;\r
+\r
+import java.io.*;\r
+import java.util.*;\r
+\r
+public class Database {\r
+ Database() throws Exception {\r
+ if (System.getenv("WORKSPACE") == null) {\r
+ DatabasePath = "C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";\r
+ } else {\r
+ DatabasePath = System.getenv("WORKSPACE") + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";\r
+ }\r
+ \r
+ importDBLib("Library.csv");\r
+ importDBGuid("Guid.csv", "Guid");\r
+ importDBGuid("Ppi.csv", "Ppi");\r
+ importDBGuid("Protocol.csv", "Protocol");\r
+ importDBMacro("Macro.csv");\r
+ }\r
+ \r
+ public static String defaultpath = "C:" + File.separator + "tianocore" + File.separator + "edk2" + File.separator + "Tools" + File.separator + "Conf" + File.separator + "Migration";\r
+ \r
+ public String DatabasePath;\r
+ public Set<String> error = new HashSet<String>();\r
+ \r
+ private Map<String,Guid> hashguid = new HashMap<String,Guid>();\r
+ private Map<String,Func> hashfunc = new HashMap<String,Func>();\r
+ private Map<String,Macro> hashmacro = new HashMap<String,Macro>();\r
+ \r
+ private void importDBLib(String filename) throws Exception {\r
+ BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
+ String line;\r
+ String[] linecontext;\r
+ Func lf;\r
+ \r
+ if (rd.ready()) {\r
+ System.out.println("Found " + filename + " , Importing Library Database");\r
+ while ((line = rd.readLine()) != null) {\r
+ if (line.length() != 0) {\r
+ linecontext = line.split(",");\r
+ lf = new Func(linecontext);\r
+ hashfunc.put(lf.r8funcname,lf);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ \r
+ private void importDBGuid(String filename, String type) throws Exception {\r
+ BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
+ String line;\r
+ String[] linecontext;\r
+ Guid gu;\r
+ \r
+ if (rd.ready()) {\r
+ System.out.println("Found " + filename + " , Importing " + type + " Database");\r
+ while ((line = rd.readLine()) != null) {\r
+ if (line.length() != 0) {\r
+ linecontext = line.split(",");\r
+ gu = new Guid(linecontext, type);\r
+ hashguid.put(gu.r8name,gu);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ \r
+ private void importDBMacro(String filename) throws Exception {\r
+ BufferedReader rd = new BufferedReader(new FileReader(DatabasePath + File.separator + filename));\r
+ String line;\r
+ String[] linecontext;\r
+ Macro mc;\r
+ \r
+ if (rd.ready()) {\r
+ System.out.println("Found " + filename + " , Importing Macro Database");\r
+ while ((line = rd.readLine()) != null) {\r
+ if (line.length() != 0) {\r
+ linecontext = line.split(",");\r
+ mc = new Macro(linecontext);\r
+ hashmacro.put(mc.r8name,mc);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ \r
+ public String getR9Lib(String r8funcname) {\r
+ String temp = null;\r
+ if (hashfunc.containsKey(r8funcname)) {\r
+ temp = hashfunc.get(r8funcname).r9libname;\r
+ }\r
+ return temp;\r
+ }\r
+ \r
+ public String getR9Func(String r8funcname) {\r
+ String temp = null;\r
+ if (hashfunc.containsKey(r8funcname)) {\r
+ temp = hashfunc.get(r8funcname).r9funcname;\r
+ }\r
+ return temp;\r
+ }\r
+ \r
+ public boolean hasFunc(String r8lib) {\r
+ return hashfunc.containsKey(r8lib);\r
+ }\r
+\r
+ public boolean hasGuid(String r8guid) {\r
+ return hashguid.containsKey(r8guid);\r
+ }\r
+\r
+ public boolean hasMacro(String r8macro) {\r
+ return hashmacro.containsKey(r8macro);\r
+ }\r
+ \r
+ public String getR9Macro(String r8macro) {\r
+ return hashmacro.get(r8macro).r9name; // the verification job of if the macro exists in the database is done when registering it\r
+ }\r
+ \r
+ public String getR9Guidname(String r8Guid) {\r
+ String temp = null;\r
+ try {\r
+ temp = hashguid.get(r8Guid).r9name;\r
+ } catch (NullPointerException e) {\r
+ error.add("getR9Guidname :" + r8Guid);\r
+ }\r
+ return temp;\r
+ }\r
+ \r
+ public String getGuidType(String r8Guid) {\r
+ String temp = null;\r
+ try {\r
+ temp = hashguid.get(r8Guid).type;\r
+ } catch (NullPointerException e) {\r
+ error.add("getR9Guidname :" + r8Guid);\r
+ }\r
+ return temp;\r
+ }\r
+}\r
--- /dev/null
+package org.tianocore.migration;\r
+\r
+import java.awt.*;\r
+import java.awt.event.*;\r
+import java.io.*;\r
+import java.util.*;\r
+import javax.swing.*;\r
+\r
+public class FirstPanel extends JPanel implements ActionListener, UI {\r
+ /**\r
+ * Define class Serial Version UID\r
+ */\r
+ private static final long serialVersionUID = 207759413522910399L;\r
+ \r
+ private String modulepath;\r
+ \r
+ private JButton moduleButton , goButton;\r
+ private JTextField moduletext;\r
+ private JTextArea log;\r
+ private JFileChooser fc;\r
+ private JCheckBox filebox, screenbox;\r
+ \r
+ private boolean tofile = true, toscreen = true;\r
+ private PrintWriter logfile;\r
+\r
+ FirstPanel() throws Exception {\r
+ goButton = new JButton("Go");\r
+ goButton.addActionListener(this);\r
+ goButton.setActionCommand("go");\r
+ \r
+ moduleButton = new JButton("Choose ModulePath");\r
+ moduleButton.addActionListener(this);\r
+\r
+ moduletext = new JTextField(30);\r
+ \r
+ filebox = new JCheckBox("Output to logfile", true);\r
+ screenbox = new JCheckBox("Specify logfile", false);\r
+ \r
+ JPanel modulePanel = new JPanel();\r
+ modulePanel.add(moduleButton);\r
+ modulePanel.add(moduletext);\r
+ modulePanel.add(filebox);\r
+ modulePanel.add(screenbox);\r
+ modulePanel.add(goButton);\r
+ add(modulePanel);\r
+\r
+ log = new JTextArea(50,25);\r
+ log.setMargin(new Insets(5,5,5,5));\r
+ log.setEditable(false);\r
+ JScrollPane logScrollPane = new JScrollPane(log);\r
+ add(logScrollPane);\r
+ \r
+ fc = new JFileChooser();\r
+ fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);\r
+ }\r
+ \r
+ //---------------------------------------------------------------------------------------//\r
+ \r
+ public boolean yesOrNo(String question) {\r
+ return JOptionPane.showConfirmDialog(this, question, "Yes or No", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;\r
+ }\r
+ \r
+ public void print(String message) {\r
+ if (toscreen == true) {\r
+ log.append(message);\r
+ System.out.print(message);\r
+ }\r
+ if (tofile == true) {\r
+ logfile.append(message);\r
+ }\r
+ }\r
+ \r
+ public void println(String message) {\r
+ print(message + "\n");\r
+ }\r
+\r
+ public void println(Set<String> hash) {\r
+ if (toscreen == true) {\r
+ log.append(hash + "\n");\r
+ System.out.println(hash);\r
+ }\r
+ if (tofile == true) {\r
+ logfile.append(hash + "\n");\r
+ }\r
+ }\r
+\r
+ //---------------------------------------------------------------------------------------//\r
+ \r
+ /*\r
+ public boolean getOption(String item) {\r
+ if (item.matches("file")) {\r
+ }\r
+ }\r
+ */\r
+ \r
+ public void actionPerformed(ActionEvent e) {\r
+ if ( e.getSource() == moduleButton ) {\r
+ int ret = fc.showOpenDialog(this);\r
+ if (ret == JFileChooser.APPROVE_OPTION) {\r
+ modulepath = fc.getSelectedFile().getAbsolutePath();\r
+ moduletext.setText(modulepath);\r
+ log.append("ModulePath: " + modulepath + "\n");\r
+ }\r
+ }\r
+ if ( e.getSource() == goButton ) {\r
+ try {\r
+ logfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "migration.log")));\r
+ println("Project MsaGen");\r
+ println("Copyright (c) 2006, Intel Corporation");\r
+ new ModuleInfo(modulepath, this, new Database());\r
+ logfile.flush();\r
+ } catch (Exception en) {\r
+ println(en.getMessage());\r
+ }\r
+ }\r
+ }\r
+ \r
+ public void itemStateChanged(ItemEvent e) {\r
+ if (e.getStateChange() == ItemEvent.DESELECTED) {\r
+ System.out.println("changed");\r
+ }\r
+ }\r
+\r
+ //---------------------------------------------------------------------------------------//\r
+ \r
+ public static void init() throws Exception {\r
+ JFrame.setDefaultLookAndFeelDecorated(true);\r
+ JFrame frame = new JFrame("FrameDemo");\r
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);\r
+\r
+ FirstPanel fp = new FirstPanel();\r
+ fp.setLayout(new BoxLayout(fp, BoxLayout.Y_AXIS));\r
+ fp.setOpaque(true);\r
+ frame.setContentPane(fp);\r
+\r
+ frame.setSize(800,600);\r
+ frame.setVisible(true);\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+package org.tianocore.migration;\r
+\r
+import java.util.regex.*;\r
+\r
+public class Func {\r
+ Func(String r8func,String r8lib,String r9func,String r9lib) {\r
+ r8funcname = r8func;\r
+ r8libname = r8lib;\r
+ r9funcname = r9func;\r
+ r9libname = r9lib;\r
+ }\r
+ Func(String[] linecontext) {\r
+ r8funcname = linecontext[1];\r
+ r8libname = linecontext[0];\r
+ r9funcname = linecontext[2];\r
+ r9libname = linecontext[3];\r
+ }\r
+ public String r8funcname;\r
+ public String r8libname;\r
+ public String r9funcname;\r
+ public String r9libname;\r
+\r
+ public static Pattern ptnbrace = Pattern.compile("\\{[^\\{\\}]*\\}",Pattern.MULTILINE);\r
+ public static Pattern ptnfuncc = Pattern.compile("([a-zA-Z_]\\w*)\\s*\\([^\\)\\(]*\\)",Pattern.MULTILINE);\r
+ public static Pattern ptnfuncd = Pattern.compile("([a-zA-Z_]\\w*)\\s*\\([^\\)\\(]*\\)\\s*@",Pattern.MULTILINE);\r
+ public static Pattern ptnlowcase = Pattern.compile("[a-z]"); // must be removed\r
+ \r
+ private static String reservedwords = "if for pack while switch return sizeof";\r
+ \r
+ public static String register(Matcher mtr, ModuleInfo mi, Database db) {\r
+ String temp = null;\r
+\r
+ temp = mtr.group(1); // both changed and not changed funcc are registered , for finding all the non-local function calls\r
+ Matcher mtrlowcase = ptnlowcase.matcher(temp); // must be removed , so the two funcs can be merged\r
+ if (!reservedwords.contains(temp) && mtrlowcase.find()) {\r
+ mi.hashfuncc.add(temp);\r
+ }\r
+ return temp;\r
+ }\r
+ /*\r
+ public static String registerFuncD(Matcher mtr, ModuleInfo mi, Database db) {\r
+ String temp = null;\r
+\r
+ temp = mtr.group(1); // both changed and not changed funcd are registered , for finding all the non-local function calls\r
+ if (!reservedwords.contains(temp)) {\r
+ mi.hashfuncd.add(temp);\r
+ }\r
+ return temp;\r
+ }\r
+ */\r
+}\r
--- /dev/null
+package org.tianocore.migration;\r
+\r
+import java.util.regex.*;\r
+\r
+public class Guid {\r
+ Guid (String r8, String t, String n, String r9, String gv, String p) {\r
+ r8name = r8;\r
+ type = t;\r
+ name = n;\r
+ r9name = r9;\r
+ guidvalue = gv;\r
+ pack = p;\r
+ }\r
+ Guid (String[] linecontext, String t) {\r
+ r8name = linecontext[1];\r
+ type = t;\r
+ name = linecontext[0];\r
+ r9name = linecontext[2];\r
+ guidvalue = linecontext[3];\r
+ pack = linecontext[4];\r
+ }\r
+ public String r8name;\r
+ public String type;\r
+ public String name;\r
+ public String r9name;\r
+ public String guidvalue;\r
+ public String pack;\r
+\r
+ public static Pattern ptnguid = Pattern.compile("g\\w*Guid");\r
+\r
+ public static String register(Matcher mtr, ModuleInfo mi, Database db) {\r
+ String type = null;\r
+ String temp = null;\r
+ \r
+ temp = mtr.group();\r
+ if (db.hasGuid(temp)) { // only changed guids registered, because both changed and not changed guids are included in database\r
+ type = db.getGuidType(temp);\r
+ if (type.matches("Protocol")) {\r
+ mi.protocol.add(temp);\r
+ } else if (type.matches("Ppi")) {\r
+ mi.ppi.add(temp);\r
+ } else if (type.matches("Guid")) {\r
+ mi.guid.add(temp);\r
+ }\r
+ return temp;\r
+ }\r
+ return null;\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+package org.tianocore.migration;\r
+\r
+import java.util.regex.*;\r
+\r
+public class Macro {\r
+ Macro(String r8, String r9) {\r
+ r8name = r8;\r
+ r9name = r9;\r
+ }\r
+ Macro(String[] linecontext) {\r
+ r8name = linecontext[0];\r
+ r9name = linecontext[1];\r
+ }\r
+ \r
+ public String r8name;\r
+ public String r9name;\r
+\r
+ public static Pattern ptntmacro = Pattern.compile("\\b[A-Z_]+\\s*?\\(?\\b",Pattern.MULTILINE);\r
+\r
+ private static String unmacro = "VOID UINTN BOOLEAN ASSERT OPTIONAL STATIC NULL TRUE IN OUT FALSE";\r
+\r
+ public static String register(Matcher mtr, ModuleInfo mi, Database db) {\r
+ String temp = null;\r
+ \r
+ temp = mtr.group();\r
+ if (db.hasMacro(temp)) { // only changed macros registered, because the database of macro has only changed ones\r
+ if (!unmacro.contains(temp)) {\r
+ mi.hashnonlocalmacro.add(temp);\r
+ }\r
+ return temp;\r
+ }\r
+ return null;\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+package org.tianocore.migration;\r
+\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
+information and all the temporary data.\r
+*/\r
+public class ModuleInfo {\r
+ ModuleInfo(String modulepath, UI ui, Database db) throws Exception {\r
+ this.modulepath = modulepath;\r
+ this.ui = ui;\r
+ this.db = db;\r
+ moduleScan();\r
+ }\r
+ \r
+ private String modulepath = null;\r
+ private Database db = null;\r
+ private UI ui = null;\r
+ \r
+ public String modulename = null;\r
+ public String guidvalue = null;\r
+ public String moduletype = null;\r
+ public String entrypoint = null;\r
+ \r
+ public Set<String> localmodulesources = new HashSet<String>(); //contains both .c and .h\r
+ public Set<String> localmoduleheaders = new HashSet<String>();\r
+ public Set<String> preprocessedccodes = new HashSet<String>();\r
+ \r
+ public Set<String> hashfuncc = new HashSet<String>();\r
+ public Set<String> hashfuncd = new HashSet<String>();\r
+ public Set<String> hashnonlocalfunc = new HashSet<String>();\r
+ public Set<String> hashnonlocalmacro = new HashSet<String>();\r
+ public Set<String> hashEFIcall = new HashSet<String>();\r
+ public Set<String> hashr8only = new HashSet<String>();\r
+ \r
+ public Set<String> hashrequiredr9libs = new HashSet<String>(); // hashrequiredr9libs is now all added in SourceFileReplacer \r
+ public Set<String> guid = new HashSet<String>();\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
+ String[] list = new File(modulepath).list();\r
+ boolean hasInf = false;\r
+ String infname = null;\r
+ boolean hasMsa = false;\r
+ String msaname = null;\r
+ \r
+ for (int i = 0 ; i < list.length ; i++) {\r
+ if (new File(list[i]).isDirectory()) {\r
+ ;\r
+ } else {\r
+ if (list[i].contains(".c") || list[i].contains(".C")) {\r
+ localmodulesources.add(list[i]);\r
+ } else if (list[i].contains(".h") || list[i].contains(".H")) {\r
+ localmodulesources.add(list[i]);\r
+ localmoduleheaders.add(list[i]); //the case that several .inf or .msa found is not concerned\r
+ } else if (list[i].contains(".inf")) {\r
+ if (ui.yesOrNo("Found .inf file : " + list[i] + "\nUse this file as this module's .inf ?")) {\r
+ hasInf = true;\r
+ infname = list[i];\r
+ } else {\r
+ continue;\r
+ }\r
+ } else if (list[i].contains(".msa")) {\r
+ if (ui.yesOrNo("Found .msa file : " + list[i] + "\nUse this file as this module's .msa ?")) {\r
+ hasMsa = true;\r
+ msaname = list[i];\r
+ } else {\r
+ continue;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ \r
+ ModuleReader mr = new ModuleReader(modulepath, this, db);\r
+ if (hasInf) { // this sequence shows using .inf as default\r
+ mr.readInf(infname);\r
+ } else if (hasMsa) {\r
+ mr.readMsa(msaname);\r
+ } else {\r
+ ui.println("No Inf Nor Msa Found");\r
+ }\r
+ \r
+ CommentOutNonLocalHFile();\r
+ parsePreProcessedSourceCode();\r
+ \r
+ new SourceFileReplacer(modulepath, this, db, ui).flush(); // some adding library actions are taken here,so it must be put before "MsaWriter"\r
+ \r
+ // show result\r
+ if (ui.yesOrNo("Parse Module Information Complete . See details ?")) {\r
+ ui.println("\nModule Information : ");\r
+ ui.println("Entrypoint : " + entrypoint);\r
+ show(protocol, "Protocol : ");\r
+ show(ppi, "Ppi : ");\r
+ show(guid, "Guid : ");\r
+ show(hashfuncc, "call : ");\r
+ show(hashfuncd, "def : ");\r
+ show(hashEFIcall, "EFIcall : ");\r
+ show(hashnonlocalmacro, "macro : ");\r
+ show(hashnonlocalfunc, "nonlocal : ");\r
+ show(hashr8only, "hashr8only : ");\r
+ }\r
+ \r
+ new MsaWriter(modulepath, this, db).flush();\r
+ \r
+ // remove temp directory\r
+ //File tempdir = new File(modulepath + File.separator + "temp");\r
+ //System.out.println("Deleting Dir");\r
+ //if (tempdir.exists()) tempdir.d;\r
+ \r
+ ui.println("Errors Left : " + db.error);\r
+ ui.println("Complete!");\r
+ ui.println("Your R9 module is placed at " + modulepath + File.separator + "result");\r
+ ui.println("Your logfile is placed at " + modulepath);\r
+ }\r
+ \r
+ private void show(Set<String> hash, String show) {\r
+ ui.println(show + hash.size());\r
+ 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 mtcinclude;\r
+ \r
+ File tempdir = new File(modulepath + File.separator + "temp" + File.separator);\r
+ if (!tempdir.exists()) tempdir.mkdir();\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
+ 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
+ mtcinclude = ptninclude.matcher(line);\r
+ if (mtcinclude.find() && localmoduleheaders.contains(mtcinclude.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 search(String line, Pattern ptn, Method md) {\r
+ matmacro = Func.ptntmacro.matcher(line);\r
+ while (matmacro.find()) {\r
+ if ((temp = Func.registerMacro(matmacro, this, db)) != null) {\r
+ }\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
+ String[] list = new File(modulepath).list();\r
+ for (int i = 0 ; i < list.length ; i++) {\r
+ if (list[i].contains(".c")) { // without CL , change to .i\r
+ preprocessedccodes.add(list[i]);\r
+ }\r
+ }\r
+ //\r
+ Iterator<String> ii = preprocessedccodes.iterator();\r
+ BufferedReader rd = null;\r
+ String ifile = null;\r
+ String line = null;\r
+ String temp = null;\r
+ //StringBuffer result = new StringBuffer();\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, 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
+ //ui.println(ifile + " dofunc " + temp);\r
+ //matfuncc.appendReplacement(result, 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 static void main(String[] args) throws Exception {\r
+ FirstPanel.init();\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+package org.tianocore.migration;\r
+\r
+import java.io.*;\r
+import java.util.*;\r
+import java.util.regex.*;\r
+import org.tianocore.*;\r
+\r
+public class ModuleReader {\r
+ ModuleReader(String path, ModuleInfo moduleinfo, Database database) {\r
+ modulepath = path;\r
+ mi = moduleinfo;\r
+ db = database;\r
+ }\r
+ private String modulepath;\r
+ private ModuleInfo mi;\r
+ private Database db;\r
+ \r
+ private static Pattern ptninfequation = Pattern.compile("([^ ]*) *= *([^ ]*)");\r
+ \r
+ public void readMsa(String name) throws Exception {\r
+ ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.parse(new File(modulepath + File.separator + name));\r
+ ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.getModuleSurfaceArea();\r
+ MsaHeaderDocument.MsaHeader msaheader = msa.getMsaHeader();\r
+ \r
+ mi.modulename = msaheader.getModuleName();\r
+ mi.guidvalue = msaheader.getGuidValue();\r
+ mi.moduletype = msaheader.getModuleType().toString(); // ???\r
+ \r
+ SourceFilesDocument.SourceFiles sourcefiles = msa.getSourceFiles();\r
+ \r
+ String temp;\r
+ Iterator<FilenameDocument.Filename> li = sourcefiles.getFilenameList().iterator();\r
+ while (li.hasNext()) {\r
+ if (!mi.localmodulesources.contains(temp = li.next().toString())) {\r
+ System.out.println("Source File Missing ! : " + temp);\r
+ }\r
+ }\r
+ }\r
+ \r
+ public void readInf(String name) throws Exception {\r
+ System.out.println("Reading From Inf : " + name);\r
+ BufferedReader rd = new BufferedReader(new FileReader(modulepath + File.separator + name));\r
+ String line;\r
+ String[] linecontext;\r
+ boolean inSrc = false;\r
+ Matcher mtrinfequation;\r
+\r
+ while ((line = rd.readLine()) != null) {\r
+ if (line.length() != 0) {\r
+ if (inSrc) {\r
+ if (line.contains("[")) {\r
+ inSrc = false;\r
+ } else {\r
+ linecontext = line.split(" ");\r
+ if (linecontext[2].length() != 0) {\r
+ if (!mi.localmodulesources.contains(linecontext[2])) {\r
+ System.out.println("Source File Missing ! : " + linecontext[2]);\r
+ }\r
+ }\r
+ }\r
+ } else {\r
+ if ((mtrinfequation = ptninfequation.matcher(line)).find()) {\r
+ if (mtrinfequation.group(1).matches("BASE_NAME")) {\r
+ mi.modulename = mtrinfequation.group(2);\r
+ }\r
+ if (mtrinfequation.group(1).matches("FILE_GUID")) {\r
+ mi.guidvalue = mtrinfequation.group(2);\r
+ }\r
+ if (mtrinfequation.group(1).matches("COMPONENT_TYPE")) {\r
+ mi.moduletype = mtrinfequation.group(2);\r
+ }\r
+ if (mtrinfequation.group(1).matches("IMAGE_ENTRY_POINT")) {\r
+ mi.entrypoint = mtrinfequation.group(2);\r
+ }\r
+ }\r
+ if (line.contains("sources")) {\r
+ inSrc = true;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+package org.tianocore.migration;\r
+\r
+import java.io.*;\r
+import java.util.*;\r
+\r
+import org.tianocore.*;\r
+import org.tianocore.SupportedArchitectures.Enum;\r
+import org.apache.xmlbeans.*;\r
+\r
+public class MsaWriter {\r
+ MsaWriter(String path, ModuleInfo moduleinfo, Database database) {\r
+ modulepath = path;\r
+ mi = moduleinfo;\r
+ db = database;\r
+ }\r
+\r
+ private String modulepath;\r
+ private ModuleInfo mi;\r
+ private Database db;\r
+ \r
+ private ModuleSurfaceAreaDocument msadoc = ModuleSurfaceAreaDocument.Factory.newInstance();\r
+ \r
+ private ModuleSurfaceAreaDocument.ModuleSurfaceArea msa = msadoc.addNewModuleSurfaceArea();\r
+ private MsaHeaderDocument.MsaHeader msaheader = msa.addNewMsaHeader();\r
+ private ModuleDefinitionsDocument.ModuleDefinitions md = msa.addNewModuleDefinitions();\r
+ private SourceFilesDocument.SourceFiles sourcefiles = msa.addNewSourceFiles(); //found local .h files are not written\r
+ private GuidsDocument.Guids guids = msa.addNewGuids();\r
+ private ProtocolsDocument.Protocols protocols = msa.addNewProtocols();\r
+ private PPIsDocument.PPIs ppis = msa.addNewPPIs();\r
+ private PackageDependenciesDocument.PackageDependencies pd = msa.addNewPackageDependencies();\r
+ private LibraryClassDefinitionsDocument.LibraryClassDefinitions libclassdefs = msa.addNewLibraryClassDefinitions();\r
+ private ExternsDocument.Externs externs = msa.addNewExterns();\r
+ \r
+ private String Query (String requirement) throws Exception {\r
+ String answer;\r
+ BufferedReader rd = new BufferedReader(new InputStreamReader(System.in));\r
+ System.out.println(requirement);\r
+ while ((answer = rd.readLine()).length() == 0) ;\r
+ return answer;\r
+ }\r
+ \r
+ private ModuleSurfaceAreaDocument fulfillMsadoc() throws Exception {\r
+ Iterator<String> it;\r
+ String temp;\r
+ \r
+ if (mi.modulename != null) {\r
+ msaheader.setModuleName(mi.modulename);\r
+ } else {\r
+ msaheader.setModuleName(mi.modulename = Query("ModuleName Not Found . Please Input ModuleName"));\r
+ }\r
+ if (mi.guidvalue != null) {\r
+ msaheader.setGuidValue(mi.guidvalue);\r
+ } else {\r
+ msaheader.setGuidValue(mi.guidvalue = Query("GuidValue Not Found . Please Input GuidValue"));\r
+ }\r
+ if (mi.moduletype != null) {\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("GuidValue Not Found . Please Input GuidValue")));\r
+ }\r
+ msaheader.setCopyright("Copyright (c) 2006, Intel Corporation");\r
+ msaheader.setVersion("1.0");\r
+ msaheader.setAbstract("Component name for module " + mi.modulename);\r
+ msaheader.setDescription("FIX ME!"); //???\r
+ msaheader.addNewLicense().setStringValue("All rights reserved.\n" +\r
+ " This software and associated documentation (if any) is furnished\n" +\r
+ " under a license and may only be used or copied in accordance\n" +\r
+ " with the terms of the license. Except as permitted by such\n" +\r
+ " license, no part of this software or documentation may be\n" +\r
+ " reproduced, stored in a retrieval system, or transmitted in any\n" +\r
+ " form or by any means without the express written consent of\n" +\r
+ " Intel Corporation.");\r
+ \r
+ List<Enum> arch = new ArrayList<Enum>();\r
+ arch.add(SupportedArchitectures.IA_32);\r
+ arch.add(SupportedArchitectures.X_64);\r
+ arch.add(SupportedArchitectures.IPF);\r
+ arch.add(SupportedArchitectures.EBC);\r
+ md.setSupportedArchitectures(arch);\r
+ md.setBinaryModule(false);\r
+ md.setOutputFileBasename(mi.modulename);\r
+ \r
+ pd.addNewPackage().setPackageGuid("5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec");\r
+ externs.addNewSpecification().setStringValue("EFI_SPECIFICATION_VERSION 0x00020000");\r
+ externs.addNewSpecification().setStringValue("EDK_RELEASE_VERSION 0x00020000");\r
+ externs.addNewExtern().setModuleEntryPoint(mi.entrypoint);\r
+ \r
+ it = mi.localmodulesources.iterator();\r
+ while (it.hasNext()) {\r
+ sourcefiles.addNewFilename().setStringValue(it.next());\r
+ }\r
+ it = mi.protocol.iterator();\r
+ while (it.hasNext()) {\r
+ if ((temp = it.next()) != null) {\r
+ ProtocolsDocument.Protocols.Protocol pr = protocols.addNewProtocol();\r
+ pr.setProtocolCName(temp);\r
+ pr.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
+ }\r
+ }\r
+ it = mi.ppi.iterator();\r
+ while (it.hasNext()) {\r
+ if ((temp = it.next()) != null) {\r
+ PPIsDocument.PPIs.Ppi pp = ppis.addNewPpi();\r
+ pp.setPpiCName(temp);\r
+ pp.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
+ }\r
+ }\r
+ it = mi.guid.iterator();\r
+ while (it.hasNext()) {\r
+ if ((temp = it.next()) != null) {\r
+ GuidsDocument.Guids.GuidCNames gcn = guids.addNewGuidCNames();\r
+ gcn.setGuidCName(temp);\r
+ gcn.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
+ }\r
+ }\r
+ it = mi.hashrequiredr9libs.iterator();\r
+ while (it.hasNext()) {\r
+ if ((temp = it.next()) != null && !temp.matches("%")) {\r
+ LibraryClassDocument.LibraryClass lc = libclassdefs.addNewLibraryClass();\r
+ lc.setKeyword(temp);\r
+ lc.setUsage(UsageTypes.ALWAYS_CONSUMED);\r
+ }\r
+ }\r
+ \r
+ return msadoc;\r
+ }\r
+ \r
+ public void flush() throws Exception {\r
+ XmlOptions options = new XmlOptions();\r
+\r
+ options.setCharacterEncoding("UTF-8");\r
+ options.setSavePrettyPrint();\r
+ options.setSavePrettyPrintIndent(2);\r
+ options.setUseDefaultNamespace();\r
+ \r
+ BufferedWriter bw = new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + mi.modulename + ".msa"));\r
+ fulfillMsadoc().save(bw, options);\r
+ bw.flush();\r
+ bw.close();\r
+ }\r
+}\r
--- /dev/null
+package org.tianocore.migration;\r
+\r
+import java.io.*;\r
+import java.util.*;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
+\r
+public class SourceFileReplacer {\r
+ SourceFileReplacer(String path, ModuleInfo moduleinfo, Database database, UI fp) {\r
+ modulepath = path;\r
+ mi = moduleinfo;\r
+ db = database;\r
+ ui = fp;\r
+ }\r
+ private String modulepath;\r
+ private ModuleInfo mi;\r
+ private Database db;\r
+ private UI ui;\r
+ private boolean showdetails = false;\r
+ \r
+ private class r8tor9 {\r
+ r8tor9(String r8, String r9) {\r
+ r8thing = r8;\r
+ r9thing = r9;\r
+ }\r
+ public String r8thing;\r
+ public String r9thing;\r
+ }\r
+ \r
+ // these sets are used only for printing log of the changes in current file\r
+ private Set<r8tor9> filefunc = new HashSet<r8tor9>();\r
+ private Set<r8tor9> filemacro = new HashSet<r8tor9>();\r
+ private Set<r8tor9> fileguid = new HashSet<r8tor9>();\r
+ private Set<r8tor9> fileppi = new HashSet<r8tor9>();\r
+ private Set<r8tor9> fileprotocol = new HashSet<r8tor9>();\r
+ private Set<String> filer8only = new HashSet<String>();\r
+ \r
+ private String r8only = "EfiLibInstallDriverBinding " +\r
+ "EfiLibInstallAllDriverProtocols " +\r
+ "EfiLibCompareLanguage " +\r
+ "BufToHexString " +\r
+ "EfiStrTrim " +\r
+ "EfiValueToHexStr " +\r
+ "HexStringToBuf " +\r
+ "IsHexDigit " +\r
+ "NibbleToHexChar " +\r
+ "GetHob " +\r
+ "GetHobListSize " +\r
+ "GetHobVersion " +\r
+ "GetHobBootMode " +\r
+ "GetCpuHobInfo " +\r
+ "GetDxeCoreHobInfo " +\r
+ "GetNextFirmwareVolumeHob " +\r
+ "GetNextGuidHob " +\r
+ "GetPalEntryHobInfo " +\r
+ "GetIoPortSpaceAddressHobInfo ";\r
+ \r
+ public void flush() throws Exception {\r
+ PrintWriter outfile;\r
+ String temp = null;\r
+ if (ui.yesOrNo("Change Source Code is to be doing . See details ?")) {\r
+ showdetails = true;\r
+ }\r
+ File tempdir = new File(modulepath + File.separator + "result" + File.separator);\r
+ if (!tempdir.exists()) tempdir.mkdir();\r
+ String[] list = new File(modulepath + File.separator + "temp").list(); //what I change is the non-local .h commented-out files\r
+ for (int i = 0 ; i < list.length ; i++) {\r
+ if (list[i].contains(".c")) {\r
+ ui.println("\nModifying file : " + list[i]);\r
+ outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + list[i])));\r
+ outfile.append(sourcefilereplace(modulepath + File.separator + "temp" + File.separator + list[i]));\r
+ outfile.flush();\r
+ outfile.close();\r
+ } else {\r
+ if (list[i].contains(".h")) {\r
+ temp = list[i];\r
+ } else if (list[i].contains(".C")) {\r
+ temp = list[i].replaceFirst(".C", ".c");\r
+ } else if (list[i].contains(".H")) {\r
+ temp = list[i].replaceFirst(".H", ".h");\r
+ } else {\r
+ continue;\r
+ }\r
+ ui.println("\nCopying file : " + temp);\r
+ outfile = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + temp)));\r
+ outfile.append(sourcefiletostring(modulepath + File.separator + "temp" + File.separator + list[i]));\r
+ outfile.flush();\r
+ outfile.close();\r
+ }\r
+ }\r
+\r
+ if (!mi.hashr8only.isEmpty()) {\r
+ addr8only();\r
+ }\r
+ }\r
+ \r
+ private void addr8only() throws Exception {\r
+ String paragraph = null;\r
+ String line = sourcefiletostring(Database.defaultpath + File.separator + "R8Lib.c");\r
+ PrintWriter outfile1 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.c")));\r
+ PrintWriter outfile2 = new PrintWriter(new BufferedWriter(new FileWriter(modulepath + File.separator + "result" + File.separator + "R8Lib.h")));\r
+ //outfile1.append("#include \"R8Lib.h\"\n\n");\r
+ //outfile2.append("#include \"R8Lib.h\"\n\n");\r
+ Pattern ptnr8only = Pattern.compile("////#?(\\w*)?.*?R8_(\\w*).*?////~", Pattern.DOTALL);\r
+ Matcher mtrr8only = ptnr8only.matcher(line);\r
+ Matcher mtrr8onlyhead;\r
+ while (mtrr8only.find()) {\r
+ if (mi.hashr8only.contains(mtrr8only.group(2))) {\r
+ paragraph = mtrr8only.group();\r
+ outfile1.append(paragraph + "\n\n");\r
+ if (mtrr8only.group(1).length() != 0) {\r
+ mi.hashrequiredr9libs.add(mtrr8only.group(1));\r
+ }\r
+ //generate R8lib.h\r
+ while ((mtrr8onlyhead = Func.ptnbrace.matcher(paragraph)).find()) {\r
+ paragraph = mtrr8onlyhead.replaceAll(";");\r
+ }\r
+ outfile2.append(paragraph + "\n\n");\r
+ }\r
+ }\r
+ outfile1.flush();\r
+ outfile1.close();\r
+ outfile2.flush();\r
+ outfile2.close();\r
+ }\r
+ \r
+ private String sourcefiletostring(String filename) throws Exception {\r
+ BufferedReader rd = new BufferedReader(new FileReader(filename));\r
+ StringBuffer wholefile = new StringBuffer();\r
+ String line;\r
+ while ((line = rd.readLine()) != null) {\r
+ wholefile.append(line + "\n");\r
+ }\r
+ return wholefile.toString();\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 String sourcefilereplace(String filename) throws Exception {\r
+ BufferedReader rd = new BufferedReader(new FileReader(filename));\r
+ StringBuffer wholefile = new StringBuffer();\r
+ String line;\r
+ String r8thing;\r
+ String r9thing;\r
+ r8tor9 temp;\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
+ Matcher mat = pat.matcher(line);\r
+ if (mat.find()) { // add a library here\r
+ ui.println("Converting all BS->gBS,RT->gRT");\r
+ line = mat.replaceAll("g$1$2$3"); //unknown correctiveness\r
+ }\r
+ mat.reset();\r
+ while (mat.find()) {\r
+ if (mat.group(1).matches("BS")) {\r
+ mi.hashrequiredr9libs.add("UefiBootServicesTableLib");\r
+ }\r
+ if (mat.group(1).matches("RT")) {\r
+ mi.hashrequiredr9libs.add("UefiRuntimeServicesTableLib");\r
+ }\r
+ }\r
+ /*\r
+ // remove EFI_DRIVER_ENTRY_POINT\r
+ Pattern patentrypoint = Pattern.compile("EFI_DRIVER_ENTRY_POINT[^\\}]*\\}");\r
+ Matcher matentrypoint = patentrypoint.matcher(line);\r
+ if (matentrypoint.find()) {\r
+ ui.println("Deleting Entry_Point");\r
+ line = matentrypoint.replaceAll("");\r
+ }\r
+ */\r
+ // start replacing names\r
+ Iterator<String> it;\r
+ // Converting non-locla function\r
+ it = mi.hashnonlocalfunc.iterator();\r
+ while (it.hasNext()) {\r
+ r8thing = it.next();\r
+ if (r8thing.matches("EfiInitializeDriverLib")) { //s\r
+ mi.hashrequiredr9libs.add("UefiBootServicesTableLib"); //p\r
+ mi.hashrequiredr9libs.add("UefiRuntimeServicesTableLib"); //e\r
+ } else if (r8thing.matches("DxeInitializeDriverLib")) { //c\r
+ mi.hashrequiredr9libs.add("UefiBootServicesTableLib"); //i\r
+ mi.hashrequiredr9libs.add("UefiRuntimeServicesTableLib"); //a\r
+ mi.hashrequiredr9libs.add("DxeServicesTableLib"); //l\r
+ } else { //\r
+ mi.hashrequiredr9libs.add(db.getR9Lib(r8thing)); // add a library here\r
+ }\r
+ \r
+ if ((r9thing = db.getR9Func(r8thing)) != null) {\r
+ if (!r8thing.equals(r9thing)) {\r
+ if (line.contains(r8thing)) {\r
+ line = line.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 (r8only.contains(temp.r8thing)) {\r
+ mi.localmodulesources.add("R8Lib.h");\r
+ mi.localmodulesources.add("R8Lib.c");\r
+ mi.localmoduleheaders.add("R8Lib.h");\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
+ line = line.replaceFirst("\\*/\n", "\\*/\n#include \"R8Lib.h\"\n");\r
+ }\r
+ \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(db.getR9Lib(r8thing)); \r
+ if ((r9thing = db.getR9Macro(r8thing)) != null) {\r
+ if (line.contains(r8thing)) {\r
+ line = line.replaceAll(r8thing, r9thing);\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
+\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
+ while (mtrpei.find()) { // ! add a library here !\r
+ line = mtrpei.replaceAll("PeiServices$1#%$2");\r
+ mi.hashrequiredr9libs.add("PeiServicesLib");\r
+ }\r
+ mtrpei.reset();\r
+ if (line.contains("PeiServicesCopyMem")) {\r
+ line = line.replaceAll("PeiServicesCopyMem#%", "CopyMem");\r
+ mi.hashrequiredr9libs.add("BaseMemoryLib");\r
+ }\r
+ if (line.contains("PeiServicesSetMem")) {\r
+ line = line.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(line);\r
+ while (mtrpeiarg.find()) {\r
+ line = mtrpeiarg.replaceAll("$1");\r
+ }\r
+ }\r
+ \r
+ Matcher mtrmac;\r
+ mtrmac = Pattern.compile("EFI_IDIV_ROUND\\((.*), (.*)\\)").matcher(line);\r
+ if (mtrmac.find()) {\r
+ line = mtrmac.replaceAll("\\($1 \\/ $2 \\+ \\(\\(\\(2 \\* \\($1 \\% $2\\)\\) \\< $2\\) \\? 0 \\: 1\\)\\)");\r
+ }\r
+ mtrmac = Pattern.compile("EFI_MIN\\((.*), (.*)\\)").matcher(line);\r
+ if (mtrmac.find()) {\r
+ line = mtrmac.replaceAll("\\(\\($1 \\< $2\\) \\? $1 \\: $2\\)");\r
+ }\r
+ mtrmac = Pattern.compile("EFI_MAX\\((.*), (.*)\\)").matcher(line);\r
+ if (mtrmac.find()) {\r
+ line = mtrmac.replaceAll("\\(\\($1 \\> $2\\) \\? $1 \\: $2\\)");\r
+ }\r
+ mtrmac = Pattern.compile("EFI_UINTN_ALIGNED\\((.*)\\)").matcher(line);\r
+ if (mtrmac.find()) {\r
+ line = mtrmac.replaceAll("\\(\\(\\(UINTN\\) $1\\) \\& \\(sizeof \\(UINTN\\) \\- 1\\)\\)");\r
+ }\r
+ if (line.contains("EFI_UINTN_ALIGN_MASK")) {\r
+ line = line.replaceAll("EFI_UINTN_ALIGN_MASK", "(sizeof (UINTN) - 1)");\r
+ }\r
+\r
+ show(filefunc, "function");\r
+ show(filemacro, "macro");\r
+ show(fileguid, "guid");\r
+ show(fileppi, "ppi");\r
+ show(fileprotocol, "protocol");\r
+ if (!filer8only.isEmpty()) {\r
+ ui.println("Converting r8only : " + filer8only);\r
+ }\r
+\r
+ filefunc.clear();\r
+ filemacro.clear();\r
+ fileguid.clear();\r
+ fileppi.clear();\r
+ fileprotocol.clear();\r
+ filer8only.clear();\r
+ \r
+ return line;\r
+ }\r
+ \r
+ private void show(Set<r8tor9> hash, String sh) {\r
+ Iterator<r8tor9> it = hash.iterator();\r
+ r8tor9 temp;\r
+ if (showdetails) {\r
+ if (!hash.isEmpty()) {\r
+ ui.print("Converting " + sh + " : ");\r
+ while (it.hasNext()) {\r
+ temp = it.next();\r
+ ui.print("[" + temp.r8thing + "->" + temp.r9thing + "] ");\r
+ }\r
+ ui.println("");\r
+ }\r
+ }\r
+ }\r
+ \r
+ private void replaceGuid(String line, Set<String> hash, String kind, Set<r8tor9> filehash) {\r
+ Iterator<String> it;\r
+ String r8thing;\r
+ String r9thing;\r
+ it = hash.iterator();\r
+ while (it.hasNext()) {\r
+ r8thing = it.next();\r
+ if ((r9thing = db.getR9Guidname(r8thing)) != null) {\r
+ if (!r8thing.equals(r9thing)) {\r
+ if (line.contains(r8thing)) {\r
+ line = line.replaceAll(r8thing, r9thing);\r
+ filehash.add(new r8tor9(r8thing, r9thing));\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+}\r
--- /dev/null
+package org.tianocore.migration;\r
+\r
+import java.util.*;\r
+\r
+public interface UI {\r
+ \r
+ public boolean yesOrNo(String question);\r
+ \r
+ public void print(String message);\r
+ \r
+ public void println(String message);\r
+ \r
+ public void println(Set<String> hash);\r
+}\r