]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java
Change to new XML Schema.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / autogen / AutoGen.java
index 1b9c5a0e4a77de4f5a1dcb9731c3f1824edc7747..95875544b3592f9d5bb598dd771c5020fcc417b2 100644 (file)
@@ -20,12 +20,14 @@ package org.tianocore.build.autogen;
 import org.tianocore.build.global.GlobalData;\r
 import org.tianocore.build.global.Spd;\r
 import org.tianocore.build.global.SurfaceAreaQuery;\r
+import org.tianocore.build.id.ModuleIdentification;\r
+import org.tianocore.build.id.PackageIdentification;\r
 import org.tianocore.GuidsDocument;\r
 import org.tianocore.LibraryClassDocument.LibraryClass;\r
 import org.tianocore.PPIsDocument;\r
 import org.tianocore.ProtocolsDocument;\r
-import org.tianocore.build.pcd.action.PCDAutoGenAction;\r
-\r
+//import org.tianocore.build.pcd.action.PCDAutoGenAction;\r
+import org.tianocore.build.exception.*;\r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.xmlbeans.XmlObject;\r
 \r
@@ -33,78 +35,86 @@ import java.io.File;
 import java.io.FileReader;\r
 import java.io.FileWriter;\r
 import java.util.ArrayList;\r
+import java.util.HashSet;\r
+import java.util.Iterator;\r
 import java.util.List;\r
 import java.util.Map;\r
+import java.util.Set;\r
 \r
 /**\r
-  This class is to generate Autogen.h and Autogen.c according to module surface\r
-  area or library surface area.\r
-**/\r
* This class is to generate Autogen.h and Autogen.c according to module surface\r
* area or library surface area.\r
+ */\r
 public class AutoGen {\r
-    ///\r
-    /// The output path of Autogen.h and Autogen.c\r
-    ///\r
+    // /\r
+    // / The output path of Autogen.h and Autogen.c\r
+    // /\r
     private String outputPath;\r
 \r
-    ///\r
-    /// The base name of module or library.\r
-    ///\r
-    private String baseName;\r
+    // /\r
+    // / The base name of module or library.\r
+    // /\r
+    private ModuleIdentification moduleId;\r
 \r
-    ///\r
-    /// The build architecture\r
-    ///\r
+    // /\r
+    // / The build architecture\r
+    // /\r
     private String arch;\r
 \r
-    ///\r
-    /// PcdAutogen instance which is used to manage how to generate the PCD\r
-    /// information.\r
-    ///\r
-    private PCDAutoGenAction myPcdAutogen;\r
-\r
-    ///\r
-    /// The protocl list which records in module or library surface area and\r
-    /// it's dependence on library instance surface area.\r
-    ///\r
-    private List<String> mProtocolList = new ArrayList<String>();\r
-\r
-    ///\r
-    /// The Ppi list which recorded in module or library surface area and its\r
-    /// dependency on library instance surface area.\r
-    ///\r
-    private List<String> mPpiList = new ArrayList<String>();\r
-\r
-    ///\r
-    /// The Guid list which recoreded in module or library surface are and it's\r
-    /// dependence on library instance surface area.\r
-    ///\r
-    private List<GuidsDocument.Guids.GuidEntry> mGuidList = new ArrayList<GuidsDocument.Guids.GuidEntry>();\r
+    // /\r
+    // / PcdAutogen instance which is used to manage how to generate the PCD\r
+    // / information.\r
+    // /\r
+//    private PCDAutoGenAction myPcdAutogen;\r
+\r
+    // /\r
+    // / The protocl list which records in module or library surface area and\r
+    // / it's dependence on library instance surface area.\r
+    // /\r
+    private Set<String> mProtocolList = new HashSet<String>();\r
+\r
+    // /\r
+    // / The Ppi list which recorded in module or library surface area and its\r
+    // / dependency on library instance surface area.\r
+    // /\r
+    private Set<String> mPpiList = new HashSet<String>();\r
+\r
+    // /\r
+    // / The Guid list which recoreded in module or library surface are and it's\r
+    // / dependence on library instance surface area.\r
+    // /\r
+    private Set<String> mGuidList = new HashSet<String>();\r
 \r
     /**\r
-      Construct function\r
-      \r
-      This function mainly initialize some member variable.\r
-      \r
-      @param outputPath    Output path of AutoGen file.\r
-      @param baseName      Module base name.\r
-      @param arch          Target architecture.\r
-    **/\r
-    public AutoGen(String outputPath, String baseName, String arch) {\r
+     * Construct function\r
+     * \r
+     * This function mainly initialize some member variable.\r
+     * \r
+     * @param outputPath\r
+     *            Output path of AutoGen file.\r
+     * @param baseName\r
+     *            Module base name.\r
+     * @param arch\r
+     *            Target architecture.\r
+     */\r
+    public AutoGen(String outputPath, ModuleIdentification moduleId, String arch) {\r
         this.outputPath = outputPath;\r
-        this.baseName = baseName;\r
+        this.moduleId = moduleId;\r
         this.arch = arch;\r
 \r
     }\r
 \r
     /**\r
-      saveFile function\r
-      \r
-      This function save the content in stringBuffer to file.\r
-      \r
-      @param fileName      The name of file.\r
-      @param fileBuffer    The content of AutoGen file in buffer.\r
-      @return              "true" successful, "false" failed.\r
-    **/\r
+     * saveFile function\r
+     * \r
+     * This function save the content in stringBuffer to file.\r
+     * \r
+     * @param fileName\r
+     *            The name of file.\r
+     * @param fileBuffer\r
+     *            The content of AutoGen file in buffer.\r
+     * @return "true" successful, "false" failed.\r
+     */\r
     private boolean saveFile(String fileName, StringBuffer fileBuffer) {\r
         try {\r
             File autoGenH = new File(fileName);\r
@@ -136,13 +146,14 @@ public class AutoGen {
     }\r
 \r
     /**\r
-      genAutogen function\r
-      \r
-      This function call libGenAutoGen or moduleGenAutogen function, which\r
-      dependence on generate library autogen or module autogen.\r
-      \r
-      @throws BuildException    Failed to creat AutoGen.c & AutoGen.h.\r
-    **/\r
+     * genAutogen function\r
+     * \r
+     * This function call libGenAutoGen or moduleGenAutogen function, which\r
+     * dependence on generate library autogen or module autogen.\r
+     * \r
+     * @throws BuildException\r
+     *             Failed to creat AutoGen.c & AutoGen.h.\r
+     */\r
     public void genAutogen() throws BuildException {\r
         try {\r
             //\r
@@ -155,8 +166,7 @@ public class AutoGen {
             // Check current is library or not, then call the corresponding\r
             // function.\r
             //\r
-            if (SurfaceAreaQuery.getComponentType().equalsIgnoreCase(\r
-                    CommonDefinition.LibraryStr)) {\r
+            if (this.moduleId.isLibrary()) {\r
                 libGenAutogen();\r
             } else {\r
                 moduleGenAutogen();\r
@@ -169,13 +179,14 @@ public class AutoGen {
         }\r
     }\r
 \r
-    /** \r
-      moduleGenAutogen function\r
-    \r
-      This function generates AutoGen.c & AutoGen.h for module.\r
-     \r
-      @throws BuildException  Faile to create module AutoGen.c & AutoGen.h.\r
-    **/\r
+    /**\r
+     * moduleGenAutogen function\r
+     * \r
+     * This function generates AutoGen.c & AutoGen.h for module.\r
+     * \r
+     * @throws BuildException\r
+     *             Faile to create module AutoGen.c & AutoGen.h.\r
+     */\r
     void moduleGenAutogen() throws BuildException {\r
 \r
         try {\r
@@ -189,13 +200,13 @@ public class AutoGen {
     }\r
 \r
     /**\r
-      libGenAutogen function\r
-      \r
-      This function generates AutoGen.c & AutoGen.h for library.\r
-      \r
-      @throws BuildException\r
-                  Faile to create library AutoGen.c & AutoGen.h\r
-    **/\r
+     * libGenAutogen function\r
+     * \r
+     * This function generates AutoGen.c & AutoGen.h for library.\r
+     * \r
+     * @throws BuildException\r
+     *             Faile to create library AutoGen.c & AutoGen.h\r
+     */\r
     void libGenAutogen() throws BuildException {\r
         try {\r
             libGenAutogenC();\r
@@ -208,38 +219,42 @@ public class AutoGen {
     }\r
 \r
     /**\r
-      moduleGenAutogenH\r
-     \r
-      This function generates AutoGen.h for module.\r
-      \r
-      @throws BuildException\r
-                  Failed to generate AutoGen.h.\r
-    **/\r
-    void moduleGenAutogenH() throws BuildException {\r
-\r
-        List<String> libClassIncludeH;\r
-        String moduleType;\r
-        List<String> headerFileList;\r
+     * moduleGenAutogenH\r
+     * \r
+     * This function generates AutoGen.h for module.\r
+     * \r
+     * @throws BuildException\r
+     *             Failed to generate AutoGen.h.\r
+     */\r
+    void moduleGenAutogenH() throws AutoGenException {\r
 \r
+        Set<String> libClassIncludeH;\r
+        String moduleType;\r
+        // List<String> headerFileList;\r
+        Set<String> headerFileList;\r
+        Iterator item;\r
         StringBuffer fileBuffer = new StringBuffer(8192);\r
-        \r
+\r
         //\r
-        // Write Autogen.h header notation \r
+        // Write Autogen.h header notation\r
         //\r
         fileBuffer.append(CommonDefinition.autogenHNotation);\r
-        \r
+\r
         //\r
-        // Add #ifndef  ${BaseName}_AUTOGENH\r
-        //     #def     ${BseeName}_AUTOGENH\r
+        // Add #ifndef ${BaseName}_AUTOGENH\r
+        // #def ${BseeName}_AUTOGENH\r
         //\r
-        fileBuffer.append("#ifndef    " + this.baseName.toUpperCase() + "_AUTOGENH\r\n");\r
-        fileBuffer.append("#define    " + this.baseName.toUpperCase() + "_AUTOGENH\r\n\r\n");\r
-        \r
+        fileBuffer.append("#ifndef    " + this.moduleId.getName().toUpperCase()\r
+                + "_AUTOGENH\r\n");\r
+        fileBuffer.append("#define    " + this.moduleId.getName().toUpperCase()\r
+                + "_AUTOGENH\r\n\r\n");\r
+\r
         //\r
         // Write the specification version and release version at the begine\r
         // of autogen.h file.\r
         // Note: the specification version and release version should\r
-        // be got from module surface area instead of hard code by it's moduleType.\r
+        // be got from module surface area instead of hard code by it's\r
+        // moduleType.\r
         //\r
         moduleType = SurfaceAreaQuery.getModuleType();\r
         switch (CommonDefinition.getModuleType(moduleType)) {\r
@@ -267,7 +282,7 @@ public class AutoGen {
         }\r
 \r
         //\r
-        // Add "extern int __make_me_compile_correctly;" at begin of \r
+        // Add "extern int __make_me_compile_correctly;" at begin of\r
         // AutoGen.h.\r
         //\r
         fileBuffer.append(CommonDefinition.autoGenHbegin);\r
@@ -275,49 +290,53 @@ public class AutoGen {
         //\r
         // Write consumed package's mdouleInfo related .h file to autogen.h\r
         //\r
-        List<String> consumedPkgList = SurfaceAreaQuery\r
-                .getIncludePackageName(this.arch);\r
-        if (consumedPkgList != null) {\r
-            headerFileList = IncludesToAutogenH(consumedPkgList, moduleType);\r
-            for (int i = 0; i < headerFileList.size(); i++) {\r
-                fileBuffer.append(headerFileList.get(i));\r
+//        PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery\r
+//                .getDependencePkg(this.arch);\r
+        PackageIdentification[] consumedPkgIdList = SurfaceAreaQuery.getDependencePkg(null);\r
+        if (consumedPkgIdList != null) {\r
+            headerFileList = depPkgToAutogenH(consumedPkgIdList, moduleType);\r
+            item = headerFileList.iterator();\r
+            while (item.hasNext()){\r
+               fileBuffer.append(item.next().toString());\r
             }\r
         }\r
 \r
         //\r
         // Write library class's related *.h file to autogen.h.\r
         //\r
-        LibraryClass[] libClassList = SurfaceAreaQuery\r
-                .getLibraryClassArray(CommonDefinition.AlwaysConsumed);\r
+        String[] libClassList = SurfaceAreaQuery\r
+                .getLibraryClasses(CommonDefinition.AlwaysConsumed);\r
         if (libClassList != null) {\r
             libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
-            for (int i = 0; i < libClassIncludeH.size(); i++) {\r
-                fileBuffer.append(libClassIncludeH.get(i));\r
+            item = libClassIncludeH.iterator();\r
+            while (item.hasNext()){\r
+               fileBuffer.append(item.next().toString());\r
             }\r
         }\r
 \r
         libClassList = SurfaceAreaQuery\r
-                .getLibraryClassArray(CommonDefinition.AlwaysProduced);\r
+                .getLibraryClasses(CommonDefinition.AlwaysProduced);\r
         if (libClassList != null) {\r
             libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
-            for (int i = 0; i < libClassIncludeH.size(); i++) {\r
-                fileBuffer.append(libClassIncludeH.get(i));\r
+            item = libClassIncludeH.iterator();\r
+            while (item.hasNext()){\r
+               fileBuffer.append(item.next().toString());\r
             }\r
         }\r
         fileBuffer.append("\r\n");\r
-        \r
+\r
         //\r
         // Write PCD autogen information to AutoGen.h.\r
         //\r
-        if (this.myPcdAutogen != null) {\r
-            fileBuffer.append(this.myPcdAutogen.OutputH());\r
-        }\r
+//        if (this.myPcdAutogen != null) {\r
+//            fileBuffer.append(this.myPcdAutogen.OutputH());\r
+//        }\r
 \r
         //\r
         // Append the #endif at AutoGen.h\r
         //\r
         fileBuffer.append("#endif\r\n");\r
-        \r
+\r
         //\r
         // Save string buffer content in AutoGen.h.\r
         //\r
@@ -325,32 +344,40 @@ public class AutoGen {
             throw new BuildException("Failed to generate AutoGen.h !!!");\r
         }\r
     }\r
-    \r
+\r
     /**\r
-      moduleGenAutogenC\r
-   \r
-      This function generates AutoGen.c for module.\r
-    \r
-      @throws BuildException\r
-                Failed to generate AutoGen.c.\r
-    **/\r
-    void moduleGenAutogenC() throws BuildException {\r
+     * moduleGenAutogenC\r
+     * \r
+     * This function generates AutoGen.c for module.\r
+     * \r
+     * @throws BuildException\r
+     *             Failed to generate AutoGen.c.\r
+     */\r
+    void moduleGenAutogenC() throws AutoGenException {\r
 \r
         StringBuffer fileBuffer = new StringBuffer(8192);\r
         //\r
-        // Write Autogen.c header notation \r
+        // Write Autogen.c header notation\r
         //\r
         fileBuffer.append(CommonDefinition.autogenCNotation);\r
-        \r
+\r
         //\r
         // Write #include <AutoGen.h> at beginning of AutoGen.c\r
         //\r
         fileBuffer.append(CommonDefinition.includeAutogenH);\r
-        \r
+\r
+        //\r
+        // Get the native MSA file infomation. Since before call autogen, \r
+        // the MSA native <Externs> information were overrided. So before \r
+        // process <Externs> it should be set the DOC as the Native MSA info.\r
+        //\r
+        Map<String, XmlObject> doc  = GlobalData.getNativeMsa(this.moduleId);\r
+        SurfaceAreaQuery.push(doc);\r
         //\r
-        // Write DriverBinding/ComponentName/DriverConfiguration/DriverDialog\r
+        // Write <Extern> DriverBinding/ComponentName/DriverConfiguration/DriverDialog\r
         // to AutoGen.c\r
         //\r
+        \r
         ExternsDriverBindingToAutoGenC(fileBuffer);\r
 \r
         //\r
@@ -367,21 +394,29 @@ public class AutoGen {
             EntryPointToAutoGen(entryPointList, fileBuffer);\r
         }\r
 \r
+        //\r
+        // Restore the DOC which include the FPD module info. \r
+        //\r
+        SurfaceAreaQuery.pop();\r
+        \r
         //\r
         // Write Guid to autogen.c\r
         //\r
-        String guid = SurfaceAreaQuery.getModuleGuid();\r
+        String guid = CommonDefinition.formatGuidName(SurfaceAreaQuery.getModuleGuid());\r
+        \r
         fileBuffer\r
                 .append("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID gEfiCallerIdGuid = {");\r
         if (guid == null) {\r
-            throw new BuildException("Guid value must set!\n");\r
+            throw new AutoGenException("Guid value must set!\n");\r
         }\r
 \r
         //\r
         // Formate Guid as ANSI c form.Example:\r
-        // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24, 0xf0}}\r
+        // {0xd2b2b828, 0x826, 0x48a7,{0xb3, 0xdf, 0x98, 0x3c, 0x0, 0x60, 0x24,\r
+        // 0xf0}}\r
         //\r
-        fileBuffer.append(Spd.formatGuidName(guid));\r
+\r
+        fileBuffer.append(guid);\r
         fileBuffer.append("};\r\n");\r
 \r
         //\r
@@ -403,116 +438,119 @@ public class AutoGen {
         // Call pcd autogen. PCDAutoGenAction tool only need module name and\r
         // isPcdEmulatedDriver as parameter. Library inherits PCD and module's\r
         // PCD information has been collected in FPDParser task by\r
-        // CollectPCDAction. \r
+        // CollectPCDAction.\r
         // Note : when PCD image tool ready,\r
         // isPCDEmulatedDriver parameter will be removed.\r
         //\r
-        try {\r
-            this.myPcdAutogen = new PCDAutoGenAction(baseName,\r
-                                                     null,\r
-                                                     null,\r
-                                                     null,\r
-                                                     this.arch,\r
-                                                     null,\r
-                                                     false,\r
-                                                     SurfaceAreaQuery.getModulePcdEntryNameArray());\r
-            this.myPcdAutogen.execute();\r
-        } catch (Exception e) {\r
-            throw new BuildException("PCD Autogen for module failed:" + e.getMessage());\r
-        }\r
-\r
-        if (this.myPcdAutogen != null) {\r
-            fileBuffer.append(this.myPcdAutogen.OutputC());\r
-        }\r
+//        try {\r
+//            this.myPcdAutogen = new PCDAutoGenAction(moduleId.getName(),\r
+//                    moduleId.getName().equalsIgnoreCase("PcdEmulatorPeim"));\r
+//            this.myPcdAutogen.execute();\r
+//        } catch (Exception e) {\r
+//            throw new BuildException("PCD Autogen failed:" + e.getMessage());\r
+//        }\r
+//\r
+//        if (this.myPcdAutogen != null) {\r
+//            fileBuffer.append(this.myPcdAutogen.OutputC());\r
+//        }\r
 \r
         if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
             throw new BuildException("Failed to generate AutoGen.c !!!");\r
         }\r
 \r
     }\r
-    \r
+\r
     /**\r
-      libGenAutogenH\r
-   \r
-      This function generates AutoGen.h for library.\r
-    \r
-      @throws BuildException\r
-                Failed to generate AutoGen.c.\r
-    **/\r
-    void libGenAutogenH() throws BuildException {\r
-\r
-        List<String> libClassIncludeH;\r
+     * libGenAutogenH\r
+     * \r
+     * This function generates AutoGen.h for library.\r
+     * \r
+     * @throws BuildException\r
+     *             Failed to generate AutoGen.c.\r
+     */\r
+    void libGenAutogenH() throws AutoGenException {\r
+\r
+        Set<String> libClassIncludeH;\r
         String moduleType;\r
-        List<String> headerFileList;\r
+        Set<String> headerFileList;\r
+        Iterator item;\r
         StringBuffer fileBuffer = new StringBuffer(10240);\r
 \r
         //\r
-        // Write Autogen.h header notation \r
+        // Write Autogen.h header notation\r
         //\r
         fileBuffer.append(CommonDefinition.autogenHNotation);\r
-        \r
+\r
         //\r
-        // Add #ifndef  ${BaseName}_AUTOGENH\r
-        //     #def     ${BseeName}_AUTOGENH\r
+        // Add #ifndef ${BaseName}_AUTOGENH\r
+        // #def ${BseeName}_AUTOGENH\r
         //\r
-        fileBuffer.append("#ifndef    " + this.baseName.toUpperCase() + "_AUTOGENH\r\n");\r
-        fileBuffer.append("#define    " + this.baseName.toUpperCase() + "_AUTOGENH\r\n\r\n");\r
-        \r
+        fileBuffer.append("#ifndef    " + this.moduleId.getName().toUpperCase()\r
+                + "_AUTOGENH\r\n");\r
+        fileBuffer.append("#define    " + this.moduleId.getName().toUpperCase()\r
+                + "_AUTOGENH\r\n\r\n");\r
+\r
         //\r
-        // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION \r
+        // Write EFI_SPECIFICATION_VERSION and EDK_RELEASE_VERSION\r
         // to autogen.h file.\r
         // Note: the specification version and release version should\r
         // be get from module surface area instead of hard code.\r
         //\r
         fileBuffer.append(CommonDefinition.autoGenHbegin);\r
-        fileBuffer.append(CommonDefinition.autoGenHLine1);\r
-        fileBuffer.append(CommonDefinition.autoGenHLine2);\r
+        String[] specList = SurfaceAreaQuery.getExternSpecificaiton();\r
+        for (int i = 0; i < specList.length; i++){\r
+            fileBuffer.append(CommonDefinition.marcDefineStr + specList[i] + "\r\n");\r
+        }\r
+//        fileBuffer.append(CommonDefinition.autoGenHLine1);\r
+//        fileBuffer.append(CommonDefinition.autoGenHLine2);\r
 \r
         //\r
         // Write consumed package's mdouleInfo related *.h file to autogen.h.\r
         // \r
         moduleType = SurfaceAreaQuery.getModuleType();\r
-        List<String> cosumedPkglist = SurfaceAreaQuery\r
-                .getIncludePackageName(this.arch);\r
-        headerFileList = IncludesToAutogenH(cosumedPkglist, moduleType);\r
-        for (int i = 0; i < headerFileList.size(); i++) {\r
-            fileBuffer.append(headerFileList.get(i));\r
+        PackageIdentification[] cosumedPkglist = SurfaceAreaQuery\r
+                .getDependencePkg(this.arch);\r
+        headerFileList = depPkgToAutogenH(cosumedPkglist, moduleType);\r
+        item = headerFileList.iterator();\r
+        while (item.hasNext()){\r
+               fileBuffer.append(item.next().toString());\r
         }\r
-\r
         //\r
         // Write library class's related *.h file to autogen.h\r
         //\r
-        LibraryClass[] libClassList = SurfaceAreaQuery\r
-                .getLibraryClassArray(CommonDefinition.AlwaysConsumed);\r
+        String[] libClassList = SurfaceAreaQuery\r
+                .getLibraryClasses(CommonDefinition.AlwaysConsumed);\r
         if (libClassList != null) {\r
             libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
-            for (int i = 0; i < libClassIncludeH.size(); i++) {\r
-                fileBuffer.append(libClassIncludeH.get(i));\r
+            item = libClassIncludeH.iterator();\r
+            while (item.hasNext()){\r
+               fileBuffer.append(item.next().toString());\r
             }\r
         }\r
 \r
         libClassList = SurfaceAreaQuery\r
-                .getLibraryClassArray(CommonDefinition.AlwaysProduced);\r
+                .getLibraryClasses(CommonDefinition.AlwaysProduced);\r
         if (libClassList != null) {\r
             libClassIncludeH = LibraryClassToAutogenH(libClassList);\r
-            for (int i = 0; i < libClassIncludeH.size(); i++) {\r
-                fileBuffer.append(libClassIncludeH.get(i));\r
+            item = libClassIncludeH.iterator();\r
+            while (item.hasNext()){\r
+               fileBuffer.append(item.next().toString());\r
             }\r
         }\r
         fileBuffer.append("\r\n");\r
-        \r
+\r
         //\r
         // Write PCD information to library AutoGen.h.\r
         //\r
-        if (this.myPcdAutogen != null) {\r
-            fileBuffer.append(this.myPcdAutogen.OutputH());\r
-        }\r
+//        if (this.myPcdAutogen != null) {\r
+//            fileBuffer.append(this.myPcdAutogen.OutputH());\r
+//        }\r
 \r
         //\r
         // Append the #endif at AutoGen.h\r
         //\r
         fileBuffer.append("#endif\r\n");\r
-        \r
+\r
         //\r
         // Save content of string buffer to AutoGen.h file.\r
         //\r
@@ -522,21 +560,21 @@ public class AutoGen {
     }\r
 \r
     /**\r
-      libGenAutogenC\r
-   \r
-      This function generates AutoGen.h for library.\r
-    \r
-      @throws BuildException\r
-                Failed to generate AutoGen.c.\r
-    **/\r
+     * libGenAutogenC\r
+     * \r
+     * This function generates AutoGen.h for library.\r
+     * \r
+     * @throws BuildException\r
+     *             Failed to generate AutoGen.c.\r
+     */\r
     void libGenAutogenC() throws BuildException {\r
         StringBuffer fileBuffer = new StringBuffer(10240);\r
 \r
         //\r
-        // Write Autogen.c header notation \r
+        // Write Autogen.c header notation\r
         //\r
         fileBuffer.append(CommonDefinition.autogenCNotation);\r
-        \r
+\r
         fileBuffer.append(CommonDefinition.autoGenCLine1);\r
         fileBuffer.append("\r\n");\r
 \r
@@ -544,27 +582,22 @@ public class AutoGen {
         // Call pcd autogen. PCDAutoGenAction tool only need module name and\r
         // isPcdEmulatedDriver as parameter. Library inherit PCD and module's\r
         // PCD information has been collected in FPDParser task by\r
-        // CollectPCDAction. \r
+        // CollectPCDAction.\r
         // Note : when PCD image tool ready,\r
         // isPCDEmulatedDriver parameter will be removed.\r
         //\r
         try {\r
-            this.myPcdAutogen = new PCDAutoGenAction(baseName, \r
-                                                     null,\r
-                                                     null,\r
-                                                     null,\r
-                                                     this.arch,\r
-                                                     null,\r
-                                                     true,\r
-                                                     SurfaceAreaQuery.getModulePcdEntryNameArray());\r
-            this.myPcdAutogen.execute();\r
+//            this.myPcdAutogen = new PCDAutoGenAction(this.moduleId.getName(),\r
+//                    this.moduleId.getName().equalsIgnoreCase("PcdEmulatorPeim"));\r
+//            this.myPcdAutogen.execute();\r
+//             this.myPcdAutogen = new PCDAutoGenAction(this.moduleId,);\r
         } catch (Exception e) {\r
-            throw new BuildException("Pcd Autogen for library failed! " + e.getMessage());\r
+            throw new BuildException(e.getMessage());\r
         }\r
 \r
-        if (this.myPcdAutogen != null) {\r
-            fileBuffer.append(this.myPcdAutogen.OutputC());\r
-        }\r
+//        if (this.myPcdAutogen != null) {\r
+//            fileBuffer.append(this.myPcdAutogen.OutputC());\r
+//        }\r
 \r
         if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
             throw new BuildException("Failed to generate AutoGen.c !!!");\r
@@ -572,78 +605,97 @@ public class AutoGen {
     }\r
 \r
     /**\r
-      LibraryClassToAutogenH\r
-      \r
-      This function returns *.h files declared by library classes which are \r
-      consumed or produced by current build module or library.\r
-      \r
-      @param   libClassList     List of library class which consumed or produce\r
-                                by current build module or library.\r
-      @return  includeStrList   List of *.h file.             \r
-    **/\r
-    List<String> LibraryClassToAutogenH(LibraryClass[] libClassList) {\r
-        List<String> includStrList = new ArrayList<String>();\r
-        String includerName;\r
+     * LibraryClassToAutogenH\r
+     * \r
+     * This function returns *.h files declared by library classes which are\r
+     * consumed or produced by current build module or library.\r
+     * \r
+     * @param libClassList\r
+     *            List of library class which consumed or produce by current\r
+     *            build module or library.\r
+     * @return includeStrList List of *.h file.\r
+     */\r
+    Set<String> LibraryClassToAutogenH(String[] libClassList) throws AutoGenException{\r
+        Set<String> includStrList = new HashSet<String>();\r
+        String includerName[];\r
         String str = "";\r
-       \r
+\r
         //\r
-        // Get include file from GlobalData's SPDTable according to \r
+        // Get include file from GlobalData's SPDTable according to\r
         // library class name.\r
         //\r
+\r
         for (int i = 0; i < libClassList.length; i++) {\r
-            includerName = GlobalData.getLibClassIncluder(getStringValue((XmlObject)libClassList[i]));\r
-            if (includerName != null) {\r
-                str = CommonDefinition.include + " " + "<";\r
-                str = str + includerName + ">\r\n";\r
-                includStrList.add(str);\r
-                includerName = null;\r
+            includerName = GlobalData.getLibraryClassHeaderFiles(\r
+                    SurfaceAreaQuery.getDependencePkg(this.arch),\r
+                    libClassList[i]);\r
+            if (includerName == null){\r
+                throw new AutoGenException("Can not find library class [" + libClassList[i] + "] declaration in every packages. ");\r
+            }\r
+            for (int j = 0; j < includerName.length; j++) {\r
+                String includeNameStr = includerName[j];\r
+                if (includeNameStr != null) {\r
+                    str = CommonDefinition.include + " " + "<";\r
+                    str = str + includeNameStr + ">\r\n";\r
+                    includStrList.add(str);\r
+                    includeNameStr = null;\r
+                }\r
             }\r
         }\r
         return includStrList;\r
     }\r
 \r
     /**\r
-      IncludesToAutogenH\r
-      \r
-      This function add include file in AutoGen.h file.\r
-      @param   packageNameList   List of module depended package.\r
-      @param   moduleType        Module type.\r
-      @return \r
-    **/\r
-    List<String> IncludesToAutogenH(List<String> packageNameList,\r
-            String moduleType) {\r
-\r
-        List<String> includeStrList = new ArrayList<String>();\r
-        String packageName = "";\r
+     * IncludesToAutogenH\r
+     * \r
+     * This function add include file in AutoGen.h file.\r
+     * \r
+     * @param packageNameList\r
+     *            List of module depended package.\r
+     * @param moduleType\r
+     *            Module type.\r
+     * @return\r
+     */\r
+    Set<String> depPkgToAutogenH(PackageIdentification[] packageNameList,\r
+            String moduleType) throws AutoGenException{\r
+\r
+        Set<String> includeStrList = new HashSet<String>();\r
+        String pkgHeader;\r
         String includeStr = "";\r
 \r
         //\r
         // Get include file from moduleInfo file\r
         //\r
-        for (int i = 0; i < packageNameList.size(); i++) {\r
-            packageName = packageNameList.get(i);\r
-            includeStr = GlobalData.getModuleInfoByPackageName(packageName,\r
-                    moduleType);\r
-            includeStrList.add(includeStr);\r
+        for (int i = 0; i < packageNameList.length; i++){\r
+//             pkgHeader = GlobalData.getPackageHeaderFiles(packageNameList[i], moduleType);\r
+//            if (pkgHeader == null){\r
+//             throw new AutoGenException("Can not find package [" + packageNameList[i] + "] declaration in every packages. ");\r
+//            }else if (!pkgHeader.equalsIgnoreCase("")){\r
+//             includeStr = CommonDefinition.include + "<" + pkgHeader + ">\r\n";\r
+//                includeStrList.add(includeStr);\r
+//            }\r
         }\r
+        \r
         return includeStrList;\r
     }\r
 \r
     /**\r
-      EntryPointToAutoGen \r
-      \r
-      This function convert <ModuleEntryPoint> & <ModuleUnloadImage> information\r
-      in mas to AutoGen.c\r
-      \r
-      @param  entryPointList    List of entry point.                            \r
-      @param  fileBuffer        String buffer fo AutoGen.c.\r
-      @throws Exception\r
-    **/\r
+     * EntryPointToAutoGen\r
+     * \r
+     * This function convert <ModuleEntryPoint> & <ModuleUnloadImage>\r
+     * information in mas to AutoGen.c\r
+     * \r
+     * @param entryPointList\r
+     *            List of entry point.\r
+     * @param fileBuffer\r
+     *            String buffer fo AutoGen.c.\r
+     * @throws Exception\r
+     */\r
     void EntryPointToAutoGen(String[] entryPointList, StringBuffer fileBuffer)\r
             throws BuildException {\r
 \r
         String typeStr = SurfaceAreaQuery.getModuleType();\r
-        \r
+\r
         //\r
         // The parameters and return value of entryPoint is difference\r
         // for difference module type.\r
@@ -833,23 +885,7 @@ public class AutoGen {
             //\r
             entryPointList = SurfaceAreaQuery.getModuleUnloadImageArray();\r
             entryPointCount = 0;\r
-            if (entryPointList != null) {\r
-                for (int i = 0; i < entryPointList.length; i++) {\r
-                    if (!entryPointList[i].equals("")) {\r
-                        fileBuffer.append("EFI_STATUS\r\n");\r
-                        fileBuffer.append("EFIAPI\r\n");\r
-                        fileBuffer.append(entryPointList[i]);\r
-                        fileBuffer.append(" (\r\n");\r
-                        fileBuffer\r
-                                .append("  EFI_HANDLE        ImageHandle\r\n");\r
-                        fileBuffer.append("  );\r\n");\r
-                        entryPointCount++;\r
-                    } else {\r
-                        break;\r
-                    }\r
-                }\r
-            }\r
-\r
+            \r
             fileBuffer\r
                     .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8  _gDriverUnloadImageCount = ");\r
             fileBuffer.append(Integer.toString(entryPointCount));\r
@@ -1078,198 +1114,170 @@ public class AutoGen {
     }\r
 \r
     /**\r
-      PpiGuidToAutogenc \r
-    \r
-      This function gets GUIDs from SPD file accrodeing to <PPIs> information and \r
-      write those GUIDs to AutoGen.c.\r
-    \r
-      @param   fileBuffer         String Buffer for Autogen.c file.\r
-      @throws  BuildException     Guid must set value!\r
-    **/\r
-    void PpiGuidToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
+     * PpiGuidToAutogenc\r
+     * \r
+     * This function gets GUIDs from SPD file accrodeing to <PPIs> information\r
+     * and write those GUIDs to AutoGen.c.\r
+     * \r
+     * @param fileBuffer\r
+     *            String Buffer for Autogen.c file.\r
+     * @throws BuildException\r
+     *             Guid must set value!\r
+     */\r
+    void PpiGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r
         String[] cNameGuid = null;\r
-        boolean isEqual = false;\r
-\r
-        PPIsDocument.PPIs.Ppi[] ppiList = SurfaceAreaQuery.getPpiArray(null);\r
-        if (ppiList != null) {\r
-            for (int i = 0; i < ppiList.length; i++) {\r
-                isEqual = false;\r
-                String ppiName = getStringValue((XmlObject)ppiList[i]);\r
-                for (int j = 0; j < this.mPpiList.size(); j++) {\r
-                    if (this.mPpiList.get(j).equalsIgnoreCase(ppiName)) {\r
-                        isEqual = true;\r
-                    }\r
-                }\r
-                if (!isEqual) {\r
-                    this.mPpiList.add(ppiName);\r
-                }\r
-            }\r
+\r
+        //\r
+        // Get the all PPI adn PPI Notify from MSA file,\r
+        // then add those PPI ,and PPI Notify name to list.\r
+        //\r
+        String[] ppiList = SurfaceAreaQuery.getPpiArray(null);\r
+        for (int i = 0; i < ppiList.length; i++) {\r
+            this.mPpiList.add(ppiList[i]);\r
         }\r
 \r
-        PPIsDocument.PPIs.PpiNotify[] ppiNotifyList = SurfaceAreaQuery\r
-                .getPpiNotifyArray(null);\r
-        if (ppiNotifyList != null) {\r
-            for (int i = 0; i < ppiNotifyList.length; i++) {\r
-                isEqual = false;\r
-                String ppiNotifyName = getStringValue((XmlObject)ppiNotifyList[i]);\r
-                for (int j = 0; j < this.mPpiList.size(); j++) {\r
-                    if (this.mPpiList.get(j).equalsIgnoreCase(ppiNotifyName)) {\r
-                        isEqual = true;\r
-                    }\r
-                }\r
-                if (!isEqual) {\r
-                    this.mPpiList.add(ppiNotifyName);\r
-                }\r
-            }\r
+        String[] ppiNotifyList = SurfaceAreaQuery.getPpiNotifyArray(null);\r
+        for (int i = 0; i < ppiNotifyList.length; i++) {\r
+            this.mPpiList.add(ppiNotifyList[i]);\r
         }\r
 \r
-        for (int i = 0; i < this.mPpiList.size(); i++) {\r
-            if (this.mPpiList.get(i) != null) {\r
-                cNameGuid = GlobalData.getPpiInfoGuid(this.mPpiList.get(i));\r
-                if (cNameGuid != null) {\r
-                    fileBuffer\r
-                            .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
-                    fileBuffer.append(cNameGuid[0]);\r
-                    fileBuffer.append(" =     { ");\r
-                    fileBuffer.append(cNameGuid[1]);\r
-                    fileBuffer.append(" } ;");\r
-                }\r
+        //\r
+        // Find CNAME and GUID from dependence SPD file and write to Autogen.c\r
+        //\r
+        Iterator ppiIterator = this.mPpiList.iterator();\r
+        String ppiKeyWord = null;\r
+        while (ppiIterator.hasNext()) {\r
+               ppiKeyWord = ppiIterator.next().toString();\r
+            cNameGuid = GlobalData\r
+                    .getPpiGuid(SurfaceAreaQuery.getDependencePkg(this.arch),\r
+                            ppiKeyWord);\r
+            if (cNameGuid != null) {\r
+                fileBuffer\r
+                        .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
+                fileBuffer.append(cNameGuid[0]);\r
+                fileBuffer.append(" =     { ");\r
+                fileBuffer.append(cNameGuid[1]);\r
+                fileBuffer.append(" } ;");\r
             } else {\r
-                throw new BuildException("Guid must set value!");\r
+               //\r
+                // If can't find Ppi GUID declaration in every package\r
+                //\r
+                throw new AutoGenException("Can not find Ppi GUID [" + ppiKeyWord + "] declaration in every packages. ");\r
             }\r
         }\r
     }\r
 \r
     /**\r
-      ProtocolGuidToAutogenc \r
-    \r
-      This function gets GUIDs from SPD file accrodeing to <Protocol> \r
-      information and write those GUIDs to AutoGen.c.\r
-    \r
-      @param   fileBuffer         String Buffer for Autogen.c file.\r
-      @throws  BuildException     Protocol name must set.\r
-    **/\r
+     * ProtocolGuidToAutogenc\r
+     * \r
+     * This function gets GUIDs from SPD file accrodeing to <Protocol>\r
+     * information and write those GUIDs to AutoGen.c.\r
+     * \r
+     * @param fileBuffer\r
+     *            String Buffer for Autogen.c file.\r
+     * @throws BuildException\r
+     *             Protocol name must set.\r
+     */\r
     void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
         String[] cNameGuid = null;\r
-        boolean isEqual = false;\r
-\r
-        ProtocolsDocument.Protocols.Protocol[] protocolList = SurfaceAreaQuery\r
-                .getProtocolArray(null);\r
-        if (protocolList != null) {\r
-            for (int i = 0; i < protocolList.length; i++) {\r
-                isEqual = false;\r
-                String protocolName = getStringValue((XmlObject)protocolList[i]);\r
-                for (int j = 0; j < this.mProtocolList.size(); j++) {\r
-                    if (this.mProtocolList.get(j).equalsIgnoreCase(protocolName)) {\r
-                        isEqual = true;\r
-                    }\r
-                }\r
-                if (!isEqual) {\r
-                    this.mProtocolList.add(protocolName);\r
 \r
-                }\r
-            }\r
+        String[] protocolList = SurfaceAreaQuery.getProtocolArray(this.arch);\r
+\r
+        //\r
+        // Add result to Autogen global list.\r
+        //\r
+        for (int i = 0; i < protocolList.length; i++) {\r
+            this.mProtocolList.add(protocolList[i]);\r
         }\r
 \r
-        ProtocolsDocument.Protocols.ProtocolNotify[] protocolNotifyList = SurfaceAreaQuery\r
-                .getProtocolNotifyArray(null);\r
-        if (protocolNotifyList != null) {\r
-            for (int i = 0; i < protocolNotifyList.length; i++) {\r
-                isEqual = false;\r
-                String protocolNotifyName = getStringValue((XmlObject)protocolNotifyList[i]);\r
-                for (int j = 0; j < this.mProtocolList.size(); j++) {\r
-                    if (this.mProtocolList.get(j).equalsIgnoreCase(protocolNotifyName)) {\r
-                        isEqual = true;\r
-                    }\r
-                }\r
-                if (!isEqual) {\r
-                    this.mProtocolList.add(protocolNotifyName);\r
+        String[] protocolNotifyList = SurfaceAreaQuery\r
+                .getProtocolNotifyArray(this.arch);\r
 \r
-                }\r
-            }\r
+        for (int i = 0; i < protocolNotifyList.length; i++) {\r
+            this.mProtocolList.add(protocolNotifyList[i]);\r
         }\r
-        if (this.mProtocolList.size() > 0) {\r
-            for (int i = 0; i < this.mProtocolList.size(); i++) {\r
-                if (this.mProtocolList.get(i) != null) {\r
-                    cNameGuid = GlobalData\r
-                            .getProtocolInfoGuid(this.mProtocolList.get(i));\r
-                    if (cNameGuid != null) {\r
-                        fileBuffer\r
-                                .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
-                        fileBuffer.append(cNameGuid[0]);\r
-                        fileBuffer.append(" =     { ");\r
-                        fileBuffer.append(cNameGuid[1]);\r
-                        fileBuffer.append(" } ;");\r
-                    }\r
-                } else {\r
-                    throw new BuildException("Protocol name must set!");\r
-                }\r
+\r
+        //\r
+        // Get the NAME and GUID from dependence SPD and write to Autogen.c\r
+        //\r
+        Iterator protocolIterator = this.mPpiList.iterator();\r
+        String protocolKeyWord = null;\r
+        while (protocolIterator.hasNext()) {\r
+               protocolKeyWord = protocolIterator.next().toString();\r
+            cNameGuid = GlobalData.getProtocolGuid(SurfaceAreaQuery\r
+                    .getDependencePkg(this.arch), protocolKeyWord);\r
+            if (cNameGuid != null) {\r
+                fileBuffer\r
+                        .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
+                fileBuffer.append(cNameGuid[0]);\r
+                fileBuffer.append(" =     { ");\r
+                fileBuffer.append(cNameGuid[1]);\r
+                fileBuffer.append(" } ;");\r
+            } else {\r
+               //\r
+                // If can't find protocol GUID declaration in every package\r
+                //\r
+                throw new BuildException("Can not find protocol Guid [" + cNameGuid + "] declaration in every packages. ");\r
             }\r
         }\r
     }\r
 \r
     /**\r
-      GuidGuidToAutogenc\r
-    \r
-      This function gets GUIDs from SPD file accrodeing to <Guids> information\r
-      and write those GUIDs to AutoGen.c.\r
-    \r
-      @param  fileBuffer       String Buffer for Autogen.c file.\r
-    \r
-    **/\r
-    void GuidGuidToAutogenC(StringBuffer fileBuffer) {\r
+     * GuidGuidToAutogenc\r
+     * \r
+     * This function gets GUIDs from SPD file accrodeing to <Guids> information\r
+     * and write those GUIDs to AutoGen.c.\r
+     * \r
+     * @param fileBuffer\r
+     *            String Buffer for Autogen.c file.\r
+     * \r
+     */\r
+    void GuidGuidToAutogenC(StringBuffer fileBuffer) throws AutoGenException {\r
         String[] cNameGuid = null;\r
-        boolean isEqual = false;\r
-        GuidsDocument.Guids.GuidEntry[] guidList = SurfaceAreaQuery\r
-                .getGuidEntryArray(null);\r
-\r
-        if (guidList != null) {\r
-            for (int i = 0; i < guidList.length; i++) {\r
-                for (int j = 0; j < this.mGuidList.size(); j++) {\r
-                    isEqual = false;\r
-                    if (this.mGuidList.get(j).getCName().equalsIgnoreCase(\r
-                            guidList[i].getCName().toString())) {\r
-                        isEqual = true;\r
-                        break;\r
-                    }\r
-                }\r
-                if (!isEqual) {\r
-                    this.mGuidList.add(guidList[i]);\r
+        String   guidKeyWord = null;\r
 \r
-                }\r
+        String[] guidList = SurfaceAreaQuery.getGuidEntryArray(this.arch);\r
 \r
-            }\r
+        for (int i = 0; i < guidList.length; i++) {\r
+            this.mGuidList.add(guidList[i]);\r
         }\r
 \r
-        for (int i = 0; i < this.mGuidList.size(); i++) {\r
-            if (this.mGuidList.get(i).getCName() != null) {\r
-                cNameGuid = GlobalData.getGuidInfoGuid(this.mGuidList.get(i)\r
-                        .getCName());\r
-                if (cNameGuid != null) {\r
-                    fileBuffer\r
-                            .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
-                    fileBuffer.append(cNameGuid[0]);\r
-                    fileBuffer.append(" =     { ");\r
-                    fileBuffer.append(cNameGuid[1]);\r
-                    fileBuffer.append("} ;");\r
-                }\r
+        Iterator guidIterator = this.mGuidList.iterator();\r
+        while (guidIterator.hasNext()) {\r
+               guidKeyWord = guidIterator.next().toString();\r
+            cNameGuid = GlobalData.getGuid(SurfaceAreaQuery\r
+                    .getDependencePkg(this.arch), guidKeyWord);\r
+            \r
+            if (cNameGuid != null) {\r
+                fileBuffer\r
+                        .append("\r\nGLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID ");\r
+                fileBuffer.append(cNameGuid[0]);\r
+                fileBuffer.append(" =     { ");\r
+                fileBuffer.append(cNameGuid[1]);\r
+                fileBuffer.append("} ;");\r
+            }else {\r
+               //\r
+                // If can't find GUID declaration in every package\r
+                //\r
+                throw new AutoGenException("Can not find Guid [" + guidKeyWord + "] declaration in every packages. ");\r
             }\r
+\r
         }\r
     }\r
 \r
     /**\r
-      LibInstanceToAutogenC\r
-      \r
-      This function adds dependent library instance to autogen.c,which includeing \r
-      library's constructor, destructor, and library dependent ppi, protocol, guid,\r
-      pcd information.\r
-         \r
-      @param  fileBuffer              String buffer for AutoGen.c\r
-      @throws BuildException          \r
-    **/\r
+     * LibInstanceToAutogenC\r
+     * \r
+     * This function adds dependent library instance to autogen.c,which\r
+     * includeing library's constructor, destructor, and library dependent ppi,\r
+     * protocol, guid, pcd information.\r
+     * \r
+     * @param fileBuffer\r
+     *            String buffer for AutoGen.c\r
+     * @throws BuildException\r
+     */\r
     void LibInstanceToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
         int index;\r
-        boolean isEqual = false;\r
 \r
         String moduleType = SurfaceAreaQuery.getModuleType();\r
         List<String> libConstructList = new ArrayList<String>();\r
@@ -1277,144 +1285,83 @@ public class AutoGen {
 \r
         String libConstructName = null;\r
         String libDestructName = null;\r
-        List<String> libraryList = SurfaceAreaQuery.getLibraryInstance(\r
-                this.arch, CommonDefinition.AlwaysConsumed);\r
+        ModuleIdentification[] libraryIdList = SurfaceAreaQuery.getLibraryInstance(this.arch);\r
 \r
         try {\r
-            if (libraryList != null) {\r
+            if (libraryIdList != null) {\r
                 //\r
                 // Reorder library instance sequence.\r
                 //\r
-                AutogenLibOrder libOrder = new AutogenLibOrder(libraryList);\r
-                List orderList = libOrder.orderLibInstance();\r
-                \r
+                AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList, this.arch);\r
+                List<ModuleIdentification> orderList = libOrder.orderLibInstance();\r
+\r
                 if (orderList != null) {\r
                     //\r
                     // Process library instance one by one.\r
                     //\r
                     for (int i = 0; i < orderList.size(); i++) {\r
-                        \r
+\r
                         //\r
                         // Get library instance basename.\r
                         //\r
-                        String libInstanceName = orderList.get(i).toString();\r
-                        \r
+                        ModuleIdentification libInstanceId = orderList.get(i);\r
+\r
                         //\r
                         // Get override map\r
                         //\r
                         Map<String, XmlObject> libDoc = GlobalData\r
-                                .getDoc(libInstanceName);\r
+                                .getDoc(libInstanceId, this.arch);\r
                         SurfaceAreaQuery.push(libDoc);\r
-                        \r
+\r
                         //\r
                         // Get <PPis>, <Protocols>, <Guids> list of this library\r
                         // instance.\r
                         //\r
-                        PPIsDocument.PPIs.Ppi[] ppiList = SurfaceAreaQuery\r
+                        String[] ppiList = SurfaceAreaQuery\r
                                 .getPpiArray(null);\r
-                        PPIsDocument.PPIs.PpiNotify[] ppiNotifyList = SurfaceAreaQuery\r
+                        String[] ppiNotifyList = SurfaceAreaQuery\r
                                 .getPpiNotifyArray(null);\r
-                        ProtocolsDocument.Protocols.Protocol[] protocolList = SurfaceAreaQuery\r
+                        String[] protocolList = SurfaceAreaQuery\r
                                 .getProtocolArray(null);\r
-                        ProtocolsDocument.Protocols.ProtocolNotify[] protocolNotifyList = SurfaceAreaQuery\r
+                        String[] protocolNotifyList = SurfaceAreaQuery\r
                                 .getProtocolNotifyArray(null);\r
-                        GuidsDocument.Guids.GuidEntry[] guidList = SurfaceAreaQuery\r
+                        String[] guidList = SurfaceAreaQuery\r
                                 .getGuidEntryArray(null);\r
 \r
                         //\r
-                        // Add those ppi, protocol, guid in global ppi, protocol, guid\r
+                        // Add those ppi, protocol, guid in global ppi,\r
+                        // protocol, guid\r
                         // list.\r
                         //\r
-                        if (ppiList != null) {\r
-                            for (index = 0; index < ppiList.length; index++) {\r
-                                isEqual = false;\r
-                                String name = getStringValue((XmlObject)ppiList[index]);\r
-                                for (int j = 0; j < this.mPpiList.size(); j++) {\r
-                                    if (this.mPpiList.get(j).equalsIgnoreCase(name)) {\r
-                                        isEqual = true;\r
-                                    }\r
-                                }\r
-                                if (!isEqual) {\r
-                                    this.mPpiList.add(name);\r
-                                }\r
-                            }\r
+                        for (index = 0; index < ppiList.length; index++) {\r
+                            this.mPpiList.add(ppiList[index]);\r
                         }\r
-                        if (ppiNotifyList != null) {\r
-                            for (index = 0; index < ppiNotifyList.length; index++) {\r
-                                isEqual = false;\r
-                                String name = getStringValue((XmlObject)ppiNotifyList[index]);\r
-                                for (int j = 0; j < this.mPpiList.size(); j++) {\r
-                                    if (this.mPpiList.get(j).equalsIgnoreCase(name)) {\r
-                                        isEqual = true;\r
-                                    }\r
-                                }\r
-                                if (!isEqual) {\r
-                                    this.mPpiList.add(name);\r
-                                }\r
-                            }\r
+                        \r
+                        for (index = 0; index < ppiNotifyList.length; index++) {\r
+                            this.mPpiList.add(ppiNotifyList[index]);\r
                         }\r
-                        if (protocolList != null) {\r
-                            for (index = 0; index < protocolList.length; index++) {\r
-                                isEqual = false;\r
-                                String name = getStringValue((XmlObject)protocolList[index]);\r
-                                for (int j = 0; j < this.mProtocolList.size(); j++) {\r
-                                    if (this.mProtocolList.get(j).equalsIgnoreCase(name)) {\r
-                                        isEqual = true;\r
-                                    }\r
-                                }\r
-                                if (!isEqual) {\r
-                                    this.mProtocolList.add(name);\r
-                                }\r
-                            }\r
+                        \r
+                        for (index = 0; index < protocolList.length; index++) {\r
+                            this.mProtocolList.add(protocolList[index]);\r
                         }\r
-                        if (protocolNotifyList != null) {\r
-                            for (index = 0; index < protocolNotifyList.length; index++) {\r
-                                isEqual = false;\r
-                                String name = getStringValue((XmlObject)protocolNotifyList[index]);\r
-                                for (int j = 0; j < this.mProtocolList.size(); j++) {\r
-                                    if (this.mProtocolList.get(j).equalsIgnoreCase(name)) {\r
-                                        isEqual = true;\r
-                                    }\r
-                                }\r
-                                if (!isEqual) {\r
-                                    this.mProtocolList.add(name);\r
-                                }\r
-                            }\r
+                        \r
+                        for (index = 0; index < protocolNotifyList.length; index++) {\r
+                            this.mProtocolList.add(protocolNotifyList[index]);\r
                         }\r
-                        if (guidList != null) {\r
-                            for (index = 0; index < guidList.length; index++) {\r
-                                isEqual = false;\r
-                                for (int j = 0; j < this.mGuidList.size(); j++) {\r
-                                    if (this.mGuidList.get(j).getCName()\r
-                                            .equalsIgnoreCase(\r
-                                                    guidList[index].getCName())) {\r
-                                        isEqual = true;\r
-                                    }\r
-                                }\r
-                                if (!isEqual) {\r
-                                    this.mGuidList.add(guidList[index]);\r
-                                }\r
-                            }\r
+                        \r
+                        for (index = 0; index < guidList.length; index++) {\r
+                            this.mGuidList.add(guidList[index]);   \r
                         }\r
 \r
                         //\r
                         // If not yet parse this library instance's constructor\r
                         // element,parse it.\r
                         //\r
-                        if (!GlobalData.isHaveLibInstance(libInstanceName)) {\r
-                            libConstructName = SurfaceAreaQuery\r
+                        libConstructName = SurfaceAreaQuery\r
                                     .getLibConstructorName();\r
-                            libDestructName = SurfaceAreaQuery\r
+                        libDestructName = SurfaceAreaQuery\r
                                     .getLibDestructorName();\r
 \r
-                            GlobalData.setLibInstanceInfo(libInstanceName,\r
-                                    libConstructName, libDestructName);\r
-                        } else {\r
-                            libConstructName = GlobalData\r
-                                    .getLibInstanceConstructor(libInstanceName);\r
-                            libDestructName = GlobalData\r
-                                    .getLibInstanceDestructor(libInstanceName);\r
-                        }\r
                         SurfaceAreaQuery.pop();\r
                         //\r
                         // Add dependent library instance constructor function.\r
@@ -1440,8 +1387,7 @@ public class AutoGen {
                 //\r
                 // Add library destructor to AutoGen.c\r
                 //\r
-                LibDestructorToAutogenC(libDestructList, moduleType,\r
-                        fileBuffer/* autogenC */);\r
+                LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer/* autogenC */);\r
             }\r
 \r
         } catch (Exception e) {\r
@@ -1449,24 +1395,26 @@ public class AutoGen {
         }\r
     }\r
 \r
\r
     /**\r
-      LibConstructorToAutogenc\r
-    \r
-      This function writes library constructor list to AutoGen.c. The library \r
-      constructor's parameter and return value depend on module type.\r
-    \r
-      @param  libInstanceList        List of library construct name.\r
-      @param  moduleType             Module type.\r
-      @param  fileBuffer             String buffer for AutoGen.c\r
-      @throws Exception              \r
-    **/\r
+     * LibConstructorToAutogenc\r
+     * \r
+     * This function writes library constructor list to AutoGen.c. The library\r
+     * constructor's parameter and return value depend on module type.\r
+     * \r
+     * @param libInstanceList\r
+     *            List of library construct name.\r
+     * @param moduleType\r
+     *            Module type.\r
+     * @param fileBuffer\r
+     *            String buffer for AutoGen.c\r
+     * @throws Exception\r
+     */\r
     void LibConstructorToAutogenC(List<String> libInstanceList,\r
             String moduleType, StringBuffer fileBuffer) throws Exception {\r
         boolean isFirst = true;\r
 \r
         //\r
-        // The library constructor's parameter and return value depend on \r
+        // The library constructor's parameter and return value depend on\r
         // module type.\r
         //\r
         for (int i = 0; i < libInstanceList.size(); i++) {\r
@@ -1577,16 +1525,19 @@ public class AutoGen {
     }\r
 \r
     /**\r
-      LibDestructorToAutogenc\r
-    \r
-      This function writes library destructor list to AutoGen.c. The library \r
-      destructor's parameter and return value depend on module type.\r
-    \r
-      @param  libInstanceList        List of library destructor name.\r
-      @param  moduleType             Module type.\r
-      @param  fileBuffer             String buffer for AutoGen.c\r
-      @throws Exception              \r
-    **/\r
+     * LibDestructorToAutogenc\r
+     * \r
+     * This function writes library destructor list to AutoGen.c. The library\r
+     * destructor's parameter and return value depend on module type.\r
+     * \r
+     * @param libInstanceList\r
+     *            List of library destructor name.\r
+     * @param moduleType\r
+     *            Module type.\r
+     * @param fileBuffer\r
+     *            String buffer for AutoGen.c\r
+     * @throws Exception\r
+     */\r
     void LibDestructorToAutogenC(List<String> libInstanceList,\r
             String moduleType, StringBuffer fileBuffer) throws Exception {\r
         boolean isFirst = true;\r
@@ -1666,12 +1617,13 @@ public class AutoGen {
     }\r
 \r
     /**\r
-      ExternsDriverBindingToAutoGenC\r
-      \r
-      This function is to write DRIVER_BINDING, COMPONENT_NAME, \r
-      DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.\r
-      \r
-      @param  fileBuffer             String buffer for AutoGen.c\r
+     * ExternsDriverBindingToAutoGenC\r
+     * \r
+     * This function is to write DRIVER_BINDING, COMPONENT_NAME,\r
+     * DRIVER_CONFIGURATION, DRIVER_DIAGNOSTIC in AutoGen.c.\r
+     * \r
+     * @param fileBuffer\r
+     *            String buffer for AutoGen.c\r
      */\r
     void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer)\r
             throws BuildException {\r
@@ -1681,12 +1633,12 @@ public class AutoGen {
         // under <extern> should be same. 1. DRIVER_BINDING 2. COMPONENT_NAME\r
         // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC\r
         //\r
-        \r
+\r
         String[] drvBindList = SurfaceAreaQuery.getDriverBindingArray();\r
-        \r
+\r
         //\r
         // If component name protocol,component configuration protocol,\r
-        // component diagnostic protocol is not null or empty, check \r
+        // component diagnostic protocol is not null or empty, check\r
         // if every one have the same number of the driver binding protocol.\r
         //\r
         if (drvBindList == null || drvBindList.length == 0) {\r
@@ -1819,14 +1771,15 @@ public class AutoGen {
     }\r
 \r
     /**\r
-      ExternCallBackToAutoGenC\r
-    \r
-      This function adds <SetVirtualAddressMapCallBack> and <ExitBootServicesCallBack>\r
-      infomation to AutoGen.c\r
-    \r
-      @param  fileBuffer           String buffer for AutoGen.c\r
-      @throws BuildException\r
-    **/\r
+     * ExternCallBackToAutoGenC\r
+     * \r
+     * This function adds <SetVirtualAddressMapCallBack> and\r
+     * <ExitBootServicesCallBack> infomation to AutoGen.c\r
+     * \r
+     * @param fileBuffer\r
+     *            String buffer for AutoGen.c\r
+     * @throws BuildException\r
+     */\r
     void ExternCallBackToAutoGenC(StringBuffer fileBuffer)\r
             throws BuildException {\r
         String[] setVirtualList = SurfaceAreaQuery\r
@@ -2003,7 +1956,4 @@ public class AutoGen {
 \r
     }\r
 \r
-    private String getStringValue(XmlObject xmlDoc) {\r
-        return xmlDoc.getDomNode().getFirstChild().getNodeValue();\r
-    }\r
-}\r
+}
\ No newline at end of file