]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java
Fixed EDKT318
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / autogen / AutoGen.java
index 08b44f9eb47a871d398ef64e32972f805e06cc2a..5b6620b50dfc8d5f3672bcb012fe825a4fd482ed 100644 (file)
@@ -34,14 +34,16 @@ import java.util.Set;
 \r
 import org.apache.tools.ant.BuildException;\r
 import org.apache.xmlbeans.XmlObject;\r
-import org.tianocore.build.exception.*;\r
+import org.tianocore.build.exception.AutoGenException;\r
 import org.tianocore.build.global.GlobalData;\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.build.pcd.action.PCDAutoGenAction;\r
-import org.tianocore.common.logger.EdkLog;\r
 import org.tianocore.common.definitions.ToolDefinitions;\r
+import org.tianocore.common.definitions.EdkDefinitions;\r
+import org.tianocore.common.exception.EdkException;\r
+import org.tianocore.common.logger.EdkLog;\r
 \r
 /**\r
   This class is to generate Autogen.h and Autogen.c according to module surface\r
@@ -105,10 +107,11 @@ public class AutoGen {
 \r
     ///\r
     ///  For non library module, add its library instance's construct and destructor to\r
-    ///  list.\r
+    ///  list. String[0] recode LibConstructor name, String[1] recode Lib instance \r
+       ///  module type.\r
     ///\r
-    private List<String> libConstructList = new ArrayList<String>();\r
-    private List<String> libDestructList = new ArrayList<String>();\r
+    private List<String[]> libConstructList = new ArrayList<String[]>();\r
+    private List<String[]> libDestructList = new ArrayList<String[]>();\r
 \r
     ///\r
     /// List to store SetVirtalAddressMapCallBack, ExitBootServiceCallBack\r
@@ -117,6 +120,8 @@ public class AutoGen {
     private List<String> exitBootServiceList = new ArrayList<String>();\r
 \r
     private SurfaceAreaQuery saq = null;\r
+    \r
+    private ModuleIdentification parentId = null;\r
 \r
     /**\r
       Construct function\r
@@ -132,12 +137,13 @@ public class AutoGen {
       @param arch\r
                  Target architecture.\r
     **/\r
-    public AutoGen(String fvDir, String outputPath, ModuleIdentification moduleId, String arch, SurfaceAreaQuery saq) {\r
+    public AutoGen(String fvDir, String outputPath, ModuleIdentification moduleId, String arch, SurfaceAreaQuery saq, ModuleIdentification parentId) {\r
         this.outputPath = outputPath;\r
         this.moduleId = moduleId;\r
         this.arch = arch;\r
         this.fvDir = fvDir;\r
         this.saq = saq;\r
+        this.parentId = parentId;\r
     }\r
 \r
     /**\r
@@ -207,29 +213,28 @@ public class AutoGen {
       @throws BuildException\r
                   Failed to creat AutoGen.c & AutoGen.h.\r
     **/\r
-    public void genAutogen() throws BuildException {\r
+    public void genAutogen() throws EdkException {\r
         try {\r
             //\r
             // If outputPath do not exist, create it.\r
             //\r
             File path = new File(outputPath);\r
             path.mkdirs();\r
-\r
-            //\r
-            // Check current is library or not, then call the corresponding\r
-            // function.\r
-            //\r
-            if (this.moduleId.isLibrary()) {\r
-                libGenAutogen();\r
-            } else {\r
-                moduleGenAutogen();\r
-            }\r
-\r
-        } catch (Exception e) {\r
-            throw new BuildException(\r
-                                    "Failed to create AutoGen.c & AutoGen.h!\n"\r
-                                    + e.getMessage());\r
+               } catch (Exception e) {\r
+            throw new AutoGenException(\r
+                                    "Failed to create "\r
+                                    + outputPath + " directory");\r
         }\r
+            \r
+               //\r
+               // Check current is library or not, then call the corresponding\r
+               // function.\r
+               //\r
+               if (this.moduleId.isLibrary()) {\r
+                       libGenAutogen();\r
+               } else {\r
+                       moduleGenAutogen();\r
+               }\r
     }\r
 \r
     /**\r
@@ -240,17 +245,10 @@ public class AutoGen {
       @throws BuildException\r
                   Faile to create module AutoGen.c & AutoGen.h.\r
     **/\r
-    void moduleGenAutogen() throws BuildException {\r
-\r
-        try {\r
-            collectLibInstanceInfo();\r
-            moduleGenAutogenC();\r
-            moduleGenAutogenH();\r
-        } catch (Exception e) {\r
-            throw new BuildException(\r
-                                    "Faile to create module AutoGen.c & AutoGen.h!\n"\r
-                                    + e.getMessage());\r
-        }\r
+    void moduleGenAutogen() throws EdkException {\r
+               collectLibInstanceInfo();\r
+               moduleGenAutogenC();\r
+               moduleGenAutogenH();\r
     }\r
 \r
     /**\r
@@ -261,15 +259,9 @@ public class AutoGen {
       @throws BuildException\r
                   Faile to create library AutoGen.c & AutoGen.h\r
     **/\r
-    void libGenAutogen() throws BuildException {\r
-        try {\r
-            libGenAutogenC();\r
-            libGenAutogenH();\r
-        } catch (Exception e) {\r
-            throw new BuildException(\r
-                                    "Failed to create library AutoGen.c & AutoGen.h!\n"\r
-                                    + e.getMessage());\r
-        }\r
+    void libGenAutogen() throws EdkException {\r
+               libGenAutogenC();\r
+               libGenAutogenH();\r
     }\r
 \r
     /**\r
@@ -280,7 +272,7 @@ public class AutoGen {
       @throws BuildException\r
                   Failed to generate AutoGen.h.\r
     **/\r
-    void moduleGenAutogenH() throws AutoGenException {\r
+    void moduleGenAutogenH() throws EdkException {\r
 \r
         Set<String> libClassIncludeH;\r
         String moduleType;\r
@@ -394,7 +386,7 @@ public class AutoGen {
         // Save string buffer content in AutoGen.h.\r
         //\r
         if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) {\r
-            throw new BuildException("Failed to generate AutoGen.h !!!");\r
+            throw new AutoGenException("Failed to generate AutoGen.h !!!");\r
         }\r
     }\r
 \r
@@ -406,7 +398,7 @@ public class AutoGen {
       @throws BuildException\r
                   Failed to generate AutoGen.c.\r
     **/\r
-    void moduleGenAutogenC() throws AutoGenException {\r
+    void moduleGenAutogenC() throws EdkException {\r
 \r
         StringBuffer fileBuffer = new StringBuffer(8192);\r
         //\r
@@ -509,20 +501,17 @@ public class AutoGen {
                                                  arch, \r
                                                  false, \r
                                                  null,\r
-                                                 pcdDriverType);\r
-        try {\r
-            this.myPcdAutogen.execute();\r
-        } catch (Exception exp) {\r
-            throw new PcdAutogenException (exp.getMessage());\r
-        }\r
-\r
+                                                 pcdDriverType, \r
+                                                 parentId);\r
+        \r
+        this.myPcdAutogen.execute();\r
         if (this.myPcdAutogen != null) {\r
             fileBuffer.append("\r\n");\r
             fileBuffer.append(this.myPcdAutogen.getCAutoGenString());\r
         }\r
 \r
         if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
-            throw new BuildException("Failed to generate AutoGen.c !!!");\r
+            throw new AutoGenException("Failed to generate AutoGen.c !!!");\r
         }\r
 \r
     }\r
@@ -535,7 +524,7 @@ public class AutoGen {
       @throws BuildException\r
                   Failed to generate AutoGen.c.\r
     **/\r
-    void libGenAutogenH() throws AutoGenException {\r
+    void libGenAutogenH() throws EdkException {\r
 \r
         Set<String> libClassIncludeH;\r
         String moduleType;\r
@@ -640,7 +629,7 @@ public class AutoGen {
         // Save content of string buffer to AutoGen.h file.\r
         //\r
         if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) {\r
-            throw new BuildException("Failed to generate AutoGen.h !!!");\r
+            throw new AutoGenException("Failed to generate AutoGen.h !!!");\r
         }\r
     }\r
 \r
@@ -652,7 +641,7 @@ public class AutoGen {
       @throws BuildException\r
                   Failed to generate AutoGen.c.\r
     **/\r
-    void libGenAutogenC() throws BuildException, PcdAutogenException {\r
+    void libGenAutogenC() throws EdkException {\r
         StringBuffer fileBuffer = new StringBuffer(10240);\r
 \r
         //\r
@@ -670,20 +659,16 @@ public class AutoGen {
                                                  arch,\r
                                                  true,\r
                                                  saq.getModulePcdEntryNameArray(),\r
-                                                 pcdDriverType);\r
-        try {\r
-            this.myPcdAutogen.execute();\r
-        } catch (Exception e) {\r
-            throw new PcdAutogenException(e.getMessage());\r
-        }\r
-\r
+                                                 pcdDriverType, \r
+                                                 parentId);\r
+        this.myPcdAutogen.execute();\r
         if (this.myPcdAutogen != null) {\r
             fileBuffer.append(ToolDefinitions.LINE_SEPARATOR);\r
             fileBuffer.append(this.myPcdAutogen.getCAutoGenString());\r
         }\r
 \r
         if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) {\r
-            throw new BuildException("Failed to generate AutoGen.c !!!");\r
+            throw new AutoGenException("Failed to generate AutoGen.c !!!");\r
         }\r
     }\r
 \r
@@ -699,7 +684,7 @@ public class AutoGen {
       @return includeStrList List of *.h file.\r
     **/\r
     Set<String> LibraryClassToAutogenH(String[] libClassList)\r
-    throws AutoGenException {\r
+    throws EdkException {\r
         Set<String> includeStrList = new LinkedHashSet<String>();\r
         String includeName[];\r
         String str = "";\r
@@ -780,7 +765,7 @@ public class AutoGen {
       @throws Exception\r
     **/\r
     void EntryPointToAutoGen(String[] entryPointList, String[] unloadImageList, StringBuffer fileBuffer)\r
-    throws BuildException {\r
+    throws EdkException {\r
 \r
         String typeStr = saq.getModuleType();\r
                int unloadImageCount = 0;\r
@@ -794,11 +779,10 @@ public class AutoGen {
         \r
         case CommonDefinition.ModuleTypePeiCore:\r
             if (entryPointList == null ||entryPointList.length != 1 ) {\r
-                throw new BuildException(\r
+                throw new AutoGenException(\r
                                         "Module type = 'PEI_CORE', can have only one module entry point!");\r
             } else {\r
                 fileBuffer.append("EFI_STATUS\r\n");\r
-                fileBuffer.append("EFIAPI\r\n");\r
                 fileBuffer.append(entryPointList[0]);\r
                 fileBuffer.append(" (\r\n");\r
                 fileBuffer\r
@@ -826,12 +810,11 @@ public class AutoGen {
         case CommonDefinition.ModuleTypeDxeCore:\r
             fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n");\r
             if (entryPointList == null || entryPointList.length != 1) {\r
-                throw new BuildException(\r
+                throw new AutoGenException(\r
                                         "Module type = 'DXE_CORE', can have only one module entry point!");\r
             } else {\r
 \r
                 fileBuffer.append("VOID\r\n");\r
-                fileBuffer.append("EFIAPI\r\n");\r
                 fileBuffer.append(entryPointList[0]);\r
                 fileBuffer.append(" (\n");\r
                 fileBuffer.append("  IN VOID  *HobStart\r\n");\r
@@ -868,7 +851,6 @@ public class AutoGen {
             }\r
             for (int i = 0; i < entryPointList.length; i++) {\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
@@ -937,7 +919,6 @@ public class AutoGen {
             } else {\r
                 for (int i = 0; i < entryPointList.length; i++) {\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.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
@@ -1004,7 +985,6 @@ public class AutoGen {
             if (unloadImageList != null) {\r
                 for (int i = 0; i < unloadImageList.length; i++) {\r
                     fileBuffer.append("EFI_STATUS\r\n");\r
-                    fileBuffer.append("EFIAPI\r\n");\r
                     fileBuffer.append(unloadImageList[i]);\r
                     fileBuffer.append(" (\r\n");\r
                     fileBuffer\r
@@ -1084,7 +1064,6 @@ public class AutoGen {
                 for (int i = 0; i < entryPointList.length; i++) {\r
 \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.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
@@ -1293,7 +1272,7 @@ public class AutoGen {
       @throws BuildException\r
                   Protocol name must set.\r
     **/\r
-    void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
+    void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws EdkException {\r
         String[] cNameGuid = null;\r
 \r
         String[] protocolList = saq.getProtocolArray(this.arch);\r
@@ -1333,7 +1312,7 @@ public class AutoGen {
                 //\r
                 // If can't find protocol GUID declaration in every package\r
                 //\r
-                throw new BuildException("Can not find protocol Guid ["\r
+                throw new AutoGenException("Can not find protocol Guid ["\r
                                          + protocolKeyWord + "] declaration in any SPD package!");\r
             }\r
         }\r
@@ -1394,21 +1373,17 @@ public class AutoGen {
                  String buffer for AutoGen.c\r
       @throws BuildException\r
     **/\r
-    void LibInstanceToAutogenC(StringBuffer fileBuffer) throws BuildException {\r
-        try {\r
-            String moduleType = this.moduleId.getModuleType();\r
-            //\r
-            // Add library constructor to AutoGen.c\r
-            //\r
-            LibConstructorToAutogenC(libConstructList, moduleType,\r
-                                     fileBuffer/* autogenC */);\r
-            //\r
-            // Add library destructor to AutoGen.c\r
-            //\r
-            LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer/* autogenC */);\r
-        } catch (Exception e) {\r
-            throw new BuildException(e.getMessage());\r
-        }\r
+    void LibInstanceToAutogenC(StringBuffer fileBuffer) throws EdkException {\r
+               String moduleType = this.moduleId.getModuleType();\r
+               //\r
+               // Add library constructor to AutoGen.c\r
+               //\r
+               LibConstructorToAutogenC(libConstructList, moduleType,\r
+                                                                fileBuffer/* autogenC */);\r
+               //\r
+               // Add library destructor to AutoGen.c\r
+               //\r
+               LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer/* autogenC */);\r
     }\r
 \r
     /**\r
@@ -1425,8 +1400,8 @@ public class AutoGen {
                  String buffer for AutoGen.c\r
       @throws Exception\r
     **/\r
-    void LibConstructorToAutogenC(List<String> libInstanceList,\r
-                                  String moduleType, StringBuffer fileBuffer) throws Exception {\r
+    void LibConstructorToAutogenC(List<String[]> libInstanceList,\r
+                                  String moduleType, StringBuffer fileBuffer) throws EdkException {\r
         boolean isFirst = true;\r
 \r
         //\r
@@ -1434,44 +1409,54 @@ public class AutoGen {
         // module type.\r
         //\r
         for (int i = 0; i < libInstanceList.size(); i++) {\r
-            switch (CommonDefinition.getModuleType(moduleType)) {\r
-            case CommonDefinition.ModuleTypeBase:\r
-                fileBuffer.append("RETURN_STATUS\r\n");\r
+                       if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r
+                               fileBuffer.append("RETURN_STATUS\r\n");\r
                 fileBuffer.append("EFIAPI\r\n");\r
-                fileBuffer.append(libInstanceList.get(i));\r
+                fileBuffer.append(libInstanceList.get(i)[0]);\r
                 fileBuffer.append(" (\r\n");\r
                 fileBuffer.append("  VOID\r\n");\r
                 fileBuffer.append("  );\r\n");\r
-                break;\r
-\r
-            case CommonDefinition.ModuleTypePeiCore:\r
-            case CommonDefinition.ModuleTypePeim:\r
-                fileBuffer.append("EFI_STATUS\r\n");\r
-                fileBuffer.append("EFIAPI\r\n");\r
-                fileBuffer.append(libInstanceList.get(i));\r
-                fileBuffer.append(" (\r\n");\r
-                fileBuffer\r
-                .append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
-                fileBuffer\r
-                .append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
-                fileBuffer.append("  );\r\n");\r
-                break;\r
+                       } else {\r
+                               switch (CommonDefinition.getModuleType(moduleType)) {\r
+                case CommonDefinition.ModuleTypeBase:\r
+                    fileBuffer.append("RETURN_STATUS\r\n");\r
+                    fileBuffer.append("EFIAPI\r\n");\r
+                    fileBuffer.append(libInstanceList.get(i)[0]);\r
+                    fileBuffer.append(" (\r\n");\r
+                    fileBuffer.append("  VOID\r\n");\r
+                    fileBuffer.append("  );\r\n");\r
+                    break;\r
 \r
-            case CommonDefinition.ModuleTypeDxeCore:\r
-            case CommonDefinition.ModuleTypeDxeDriver:\r
-            case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
-            case CommonDefinition.ModuleTypeDxeSmmDriver:\r
-            case CommonDefinition.ModuleTypeDxeSalDriver:\r
-            case CommonDefinition.ModuleTypeUefiDriver:\r
-            case CommonDefinition.ModuleTypeUefiApplication:\r
-                fileBuffer.append("EFI_STATUS\r\n");\r
-                fileBuffer.append("EFIAPI\r\n");\r
-                fileBuffer.append(libInstanceList.get(i));\r
-                fileBuffer.append(" (\r\n");\r
-                fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
-                fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
-                fileBuffer.append("  );\r\n");\r
-                break;\r
+                case CommonDefinition.ModuleTypePeiCore:\r
+                case CommonDefinition.ModuleTypePeim:\r
+                                       fileBuffer.append("EFI_STATUS\r\n");\r
+                                       fileBuffer.append("EFIAPI\r\n");\r
+                                       fileBuffer.append(libInstanceList.get(i)[0]);\r
+                                       fileBuffer.append(" (\r\n");\r
+                                       fileBuffer\r
+                                       .append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
+                                       fileBuffer\r
+                                       .append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
+                                       fileBuffer.append("  );\r\n");\r
+                                       break;\r
+       \r
+                               case CommonDefinition.ModuleTypeDxeCore:\r
+                               case CommonDefinition.ModuleTypeDxeDriver:\r
+                               case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
+                               case CommonDefinition.ModuleTypeDxeSmmDriver:\r
+                               case CommonDefinition.ModuleTypeDxeSalDriver:\r
+                               case CommonDefinition.ModuleTypeUefiDriver:\r
+                               case CommonDefinition.ModuleTypeUefiApplication:\r
+                                       fileBuffer.append("EFI_STATUS\r\n");\r
+                                       fileBuffer.append("EFIAPI\r\n");\r
+                                       fileBuffer.append(libInstanceList.get(i)[0]);\r
+                                       fileBuffer.append(" (\r\n");\r
+                                       fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
+                                       fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+                                       fileBuffer.append("  );\r\n");\r
+                                       break;\r
+\r
+                           }\r
             }\r
         }\r
 \r
@@ -1520,32 +1505,40 @@ public class AutoGen {
                 fileBuffer.append("\r\n");\r
                 isFirst = false;\r
             }\r
-            switch (CommonDefinition.getModuleType(moduleType)) {\r
-            case CommonDefinition.ModuleTypeBase:\r
+                       if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r
                 fileBuffer.append("  Status = ");\r
-                fileBuffer.append(libInstanceList.get(i));\r
+                fileBuffer.append(libInstanceList.get(i)[0]);\r
                 fileBuffer.append("();\r\n");\r
                 fileBuffer.append("  VOID\r\n");\r
-                break;\r
-            case CommonDefinition.ModuleTypePeiCore:\r
-            case CommonDefinition.ModuleTypePeim:\r
-                fileBuffer.append("  Status = ");\r
-                fileBuffer.append(libInstanceList.get(i));\r
-                fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r
-                break;\r
-            case CommonDefinition.ModuleTypeDxeCore:\r
-            case CommonDefinition.ModuleTypeDxeDriver:\r
-            case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
-            case CommonDefinition.ModuleTypeDxeSmmDriver:\r
-            case CommonDefinition.ModuleTypeDxeSalDriver:\r
-            case CommonDefinition.ModuleTypeUefiDriver:\r
-            case CommonDefinition.ModuleTypeUefiApplication:\r
-                fileBuffer.append("  Status = ");\r
-                fileBuffer.append(libInstanceList.get(i));\r
-                fileBuffer.append(" (ImageHandle, SystemTable);\r\n");\r
-                break;\r
-            default:\r
-                EdkLog.log(EdkLog.EDK_INFO,"Autogen doesn't know how to deal with module type - " + moduleType + "!");\r
+                       } else {\r
+                               switch (CommonDefinition.getModuleType(moduleType)) {\r
+                                       case CommonDefinition.ModuleTypeBase:\r
+                                               fileBuffer.append("  Status = ");\r
+                                               fileBuffer.append(libInstanceList.get(i)[0]);\r
+                                               fileBuffer.append("();\r\n");\r
+                                               fileBuffer.append("  VOID\r\n");\r
+                                               break;\r
+                                       case CommonDefinition.ModuleTypePeiCore:\r
+                                       case CommonDefinition.ModuleTypePeim:\r
+                                               fileBuffer.append("  Status = ");\r
+                                               fileBuffer.append(libInstanceList.get(i)[0]);\r
+                                               fileBuffer.append(" (FfsHeader, PeiServices);\r\n");\r
+                                               break;\r
+                                       case CommonDefinition.ModuleTypeDxeCore:\r
+                                       case CommonDefinition.ModuleTypeDxeDriver:\r
+                                       case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
+                                       case CommonDefinition.ModuleTypeDxeSmmDriver:\r
+                                       case CommonDefinition.ModuleTypeDxeSalDriver:\r
+                                       case CommonDefinition.ModuleTypeUefiDriver:\r
+                                       case CommonDefinition.ModuleTypeUefiApplication:\r
+                                               fileBuffer.append("  Status = ");\r
+                                               fileBuffer.append(libInstanceList.get(i)[0]);\r
+                                               fileBuffer.append(" (ImageHandle, SystemTable);\r\n");\r
+                                               break;\r
+                                       default:\r
+                                               EdkLog.log(EdkLog.EDK_INFO,"Autogen doesn't know how to deal with module type - " + moduleType + "!");\r
+                          }\r
+            \r
             }\r
             fileBuffer.append("  ASSERT_EFI_ERROR (Status);\r\n");\r
         }\r
@@ -1566,46 +1559,55 @@ public class AutoGen {
                  String buffer for AutoGen.c\r
       @throws Exception\r
     **/\r
-    void LibDestructorToAutogenC(List<String> libInstanceList,\r
-                                 String moduleType, StringBuffer fileBuffer) throws Exception {\r
+    void LibDestructorToAutogenC(List<String[]> libInstanceList,\r
+                                 String moduleType, StringBuffer fileBuffer) throws EdkException {\r
         boolean isFirst = true;\r
         for (int i = 0; i < libInstanceList.size(); i++) {\r
-            switch (CommonDefinition.getModuleType(moduleType)) {\r
-            case CommonDefinition.ModuleTypeBase:\r
+                       if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r
                 fileBuffer.append("RETURN_STATUS\r\n");\r
                 fileBuffer.append("EFIAPI\r\n");\r
-                fileBuffer.append(libInstanceList.get(i));\r
+                fileBuffer.append(libInstanceList.get(i)[0]);\r
                 fileBuffer.append(" (\r\n");\r
                 fileBuffer.append("  VOID\r\n");\r
                 fileBuffer.append("  );\r\n");\r
-                break;\r
-            case CommonDefinition.ModuleTypePeiCore:\r
-            case CommonDefinition.ModuleTypePeim:\r
-                fileBuffer.append("EFI_STATUS\r\n");\r
-                fileBuffer.append("EFIAPI\r\n");\r
-                fileBuffer.append(libInstanceList.get(i));\r
-                fileBuffer.append(" (\r\n");\r
-                fileBuffer\r
-                .append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
-                fileBuffer\r
-                .append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
-                fileBuffer.append("  );\r\n");\r
-                break;\r
-            case CommonDefinition.ModuleTypeDxeCore:\r
-            case CommonDefinition.ModuleTypeDxeDriver:\r
-            case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
-            case CommonDefinition.ModuleTypeDxeSmmDriver:\r
-            case CommonDefinition.ModuleTypeDxeSalDriver:\r
-            case CommonDefinition.ModuleTypeUefiDriver:\r
-            case CommonDefinition.ModuleTypeUefiApplication:\r
-                fileBuffer.append("EFI_STATUS\r\n");\r
-                fileBuffer.append("EFIAPI\r\n");\r
-                fileBuffer.append(libInstanceList.get(i));\r
-                fileBuffer.append(" (\r\n");\r
-                fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
-                fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
-                fileBuffer.append("  );\r\n");\r
-                break;\r
+                       } else {\r
+                               switch (CommonDefinition.getModuleType(moduleType)) {\r
+                                       case CommonDefinition.ModuleTypeBase:\r
+                                               fileBuffer.append("RETURN_STATUS\r\n");\r
+                                               fileBuffer.append("EFIAPI\r\n");\r
+                                               fileBuffer.append(libInstanceList.get(i)[0]);\r
+                                               fileBuffer.append(" (\r\n");\r
+                                               fileBuffer.append("  VOID\r\n");\r
+                                               fileBuffer.append("  );\r\n");\r
+                                               break;\r
+                                       case CommonDefinition.ModuleTypePeiCore:\r
+                                       case CommonDefinition.ModuleTypePeim:\r
+                                               fileBuffer.append("EFI_STATUS\r\n");\r
+                                               fileBuffer.append("EFIAPI\r\n");\r
+                                               fileBuffer.append(libInstanceList.get(i)[0]);\r
+                                               fileBuffer.append(" (\r\n");\r
+                                               fileBuffer\r
+                                               .append("  IN EFI_FFS_FILE_HEADER       *FfsHeader,\r\n");\r
+                                               fileBuffer\r
+                                               .append("  IN EFI_PEI_SERVICES          **PeiServices\r\n");\r
+                                               fileBuffer.append("  );\r\n");\r
+                                               break;\r
+                                       case CommonDefinition.ModuleTypeDxeCore:\r
+                                       case CommonDefinition.ModuleTypeDxeDriver:\r
+                                       case CommonDefinition.ModuleTypeDxeRuntimeDriver:\r
+                                       case CommonDefinition.ModuleTypeDxeSmmDriver:\r
+                                       case CommonDefinition.ModuleTypeDxeSalDriver:\r
+                                       case CommonDefinition.ModuleTypeUefiDriver:\r
+                                       case CommonDefinition.ModuleTypeUefiApplication:\r
+                                               fileBuffer.append("EFI_STATUS\r\n");\r
+                                               fileBuffer.append("EFIAPI\r\n");\r
+                                               fileBuffer.append(libInstanceList.get(i)[0]);\r
+                                               fileBuffer.append(" (\r\n");\r
+                                               fileBuffer.append("  IN EFI_HANDLE        ImageHandle,\r\n");\r
+                                               fileBuffer.append("  IN EFI_SYSTEM_TABLE  *SystemTable\r\n");\r
+                                               fileBuffer.append("  );\r\n");\r
+                                               break;\r
+                           }\r
             }\r
         }\r
 \r
@@ -1642,10 +1644,17 @@ public class AutoGen {
                     fileBuffer.append("\r\n");\r
                     isFirst = false;\r
                 }\r
-                fileBuffer.append("  Status = ");\r
-                fileBuffer.append(libInstanceList.get(i));\r
-                fileBuffer.append("(ImageHandle, SystemTable);\r\n");\r
-                fileBuffer.append("  ASSERT_EFI_ERROR (Status);\r\n");\r
+                               if (libInstanceList.get(i)[1].equalsIgnoreCase(EdkDefinitions.MODULE_TYPE_BASE)) {\r
+                    fileBuffer.append("  Status = ");\r
+                    fileBuffer.append(libInstanceList.get(i)[0]);\r
+                    fileBuffer.append("();\r\n");\r
+                    fileBuffer.append("  VOID\r\n");\r
+                               } else {\r
+                                       fileBuffer.append("  Status = ");\r
+                                       fileBuffer.append(libInstanceList.get(i)[0]);\r
+                                       fileBuffer.append("(ImageHandle, SystemTable);\r\n");\r
+                                       fileBuffer.append("  ASSERT_EFI_ERROR (Status);\r\n");\r
+                               }\r
             }\r
             fileBuffer.append("}\r\n");\r
             break;\r
@@ -1662,91 +1671,79 @@ public class AutoGen {
                  String buffer for AutoGen.c\r
     **/\r
     void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer)\r
-    throws BuildException {\r
+    throws EdkException {\r
 \r
         //\r
-        // Check what <extern> contains. And the number of following elements\r
-        // under <extern> should be same. 1. DRIVER_BINDING 2. COMPONENT_NAME\r
-        // 3.DRIVER_CONFIGURATION 4. DRIVER_DIAGNOSTIC\r
-        //\r
+        // Get the arry of extern. The driverBindingGroup is a 2 dimension array.\r
+               // The second dimension is include following element: DriverBinding, \r
+               // ComponentName, DriverConfiguration, DriverDiag;\r
+               // \r
+        String[][] driverBindingGroup = this.saq.getExternProtocolGroup();\r
 \r
-        String[] drvBindList = saq.getDriverBindingArray();\r
-\r
-        //\r
-        // If component name protocol,component configuration protocol,\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
-            return;\r
-        }\r
-\r
-        String[] compNamList = saq.getComponentNameArray();\r
-        String[] compConfList = saq.getDriverConfigArray();\r
-        String[] compDiagList = saq.getDriverDiagArray();\r
-\r
+        // inital BitMask;\r
+               // \r
         int BitMask = 0;\r
 \r
         //\r
         // Write driver binding protocol extern to autogen.c\r
         //\r
-        for (int i = 0; i < drvBindList.length; i++) {\r
-            fileBuffer.append("extern EFI_DRIVER_BINDING_PROTOCOL ");\r
-            fileBuffer.append(drvBindList[i]);\r
-            fileBuffer.append(";\r\n");\r
+        for (int i = 0; i < driverBindingGroup.length; i++) {\r
+                       if (driverBindingGroup[i][0] != null) {\r
+                               fileBuffer.append("extern EFI_DRIVER_BINDING_PROTOCOL ");\r
+                fileBuffer.append(driverBindingGroup[i][0]);\r
+                fileBuffer.append(";\r\n");\r
+                       } \r
         }\r
 \r
         //\r
         // Write component name protocol extern to autogen.c\r
         //\r
-        if (compNamList != null && compNamList.length != 0) {\r
-            if (drvBindList.length != compNamList.length) {\r
-                throw new BuildException(\r
-                                        "Different number of Driver Binding and Component Name protocols!");\r
-            }\r
-\r
-            BitMask |= 0x01;\r
-            for (int i = 0; i < compNamList.length; i++) {\r
-                fileBuffer.append("extern EFI_COMPONENT_NAME_PROTOCOL ");\r
-                fileBuffer.append(compNamList[i]);\r
-                fileBuffer.append(";\r\n");\r
-            }\r
-        }\r
+               for (int i = 0; i < driverBindingGroup.length; i++) {\r
+                       if (driverBindingGroup[i][1]!= null) {\r
+                               if (driverBindingGroup[i][0] != null) {\r
+                                       BitMask |= 0x01;\r
+                                   fileBuffer.append("extern EFI_COMPONENT_NAME_PROTOCOL ");\r
+                    fileBuffer.append(driverBindingGroup[i][1]);\r
+                    fileBuffer.append(";\r\n");\r
+                               } else {\r
+                    throw new AutoGenException("DriverBinding can't be empty!!");\r
+                               }\r
+                       }\r
+               }\r
 \r
         //\r
         // Write driver configration protocol extern to autogen.c\r
         //\r
-        if (compConfList != null && compConfList.length != 0) {\r
-            if (drvBindList.length != compConfList.length) {\r
-                throw new BuildException(\r
-                                        "Different number of Driver Binding and Driver Configuration protocols!");\r
-            }\r
-\r
-            BitMask |= 0x02;\r
-            for (int i = 0; i < compConfList.length; i++) {\r
-                fileBuffer.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");\r
-                fileBuffer.append(compConfList[i]);\r
-                fileBuffer.append(";\r\n");\r
-            }\r
-        }\r
-\r
+               for (int i = 0; i < driverBindingGroup.length; i++) {\r
+                       if (driverBindingGroup[i][2] != null) {\r
+                               if (driverBindingGroup[i][0] != null) {\r
+                    BitMask |= 0x02;\r
+                                   fileBuffer.append("extern EFI_DRIVER_CONFIGURATION_PROTOCOL ");\r
+                    fileBuffer.append(driverBindingGroup[i][2]);\r
+                    fileBuffer.append(";\r\n");\r
+                               } else {\r
+                    throw new AutoGenException("DriverBinding can't be empty!!");\r
+                               }\r
+                       }\r
+               }\r
+        \r
         //\r
         // Write driver dignastic protocol extern to autogen.c\r
         //\r
-        if (compDiagList != null && compDiagList.length != 0) {\r
-            if (drvBindList.length != compDiagList.length) {\r
-                throw new BuildException(\r
-                                        "Different number of Driver Binding and Driver Diagnosis protocols!");\r
-            }\r
-\r
-            BitMask |= 0x04;\r
-            for (int i = 0; i < compDiagList.length; i++) {\r
-                fileBuffer.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");\r
-                fileBuffer.append(compDiagList[i]);\r
-                fileBuffer.append(";\r\n");\r
-            }\r
-        }\r
-\r
+               for (int i = 0; i < driverBindingGroup.length; i++) {\r
+                       if (driverBindingGroup[i][3] != null) {\r
+                               if (driverBindingGroup[i][0] != null) {\r
+                    BitMask |= 0x04;\r
+                    fileBuffer.append("extern EFI_DRIVER_DIAGNOSTICS_PROTOCOL ");\r
+                    fileBuffer.append(driverBindingGroup[i][3]);\r
+                    fileBuffer.append(";\r\n");\r
+                               } else {\r
+                    throw new AutoGenException("DriverBinding can't be empty!!");\r
+                               }\r
+                       }\r
+               }\r
+      \r
         //\r
         // Write driver module protocol bitmask.\r
         //\r
@@ -1761,49 +1758,58 @@ public class AutoGen {
         fileBuffer\r
         .append("GLOBAL_REMOVE_IF_UNREFERENCED const UINTN  _gDriverModelProtocolListEntries = ");\r
 \r
-        fileBuffer.append(Integer.toString(drvBindList.length));\r
+        fileBuffer.append(Integer.toString(driverBindingGroup.length));\r
         fileBuffer.append(";\r\n");\r
 \r
         //\r
         // Write drive module protocol list to autogen.c\r
         //\r
-        fileBuffer\r
+               if (driverBindingGroup.length > 0) {\r
+                       fileBuffer\r
         .append("GLOBAL_REMOVE_IF_UNREFERENCED const EFI_DRIVER_MODEL_PROTOCOL_LIST  _gDriverModelProtocolList[] = {");\r
-        for (int i = 0; i < drvBindList.length; i++) {\r
+               }\r
+        \r
+               \r
+        for (int i = 0; i < driverBindingGroup.length; i++) {\r
             if (i != 0) {\r
                 fileBuffer.append(",");\r
             }\r
-            fileBuffer.append("\r\n {\r\n");\r
+                       \r
+                       fileBuffer.append("\r\n {\r\n");\r
             fileBuffer.append("  &");\r
-            fileBuffer.append(drvBindList[i]);\r
+            fileBuffer.append(driverBindingGroup[i][0]);\r
             fileBuffer.append(", \r\n");\r
+                       \r
 \r
-            if (compNamList != null) {\r
+            if (driverBindingGroup[i][1] != null) {\r
                 fileBuffer.append("  &");\r
-                fileBuffer.append(compNamList[i]);\r
+                fileBuffer.append(driverBindingGroup[i][1]);\r
                 fileBuffer.append(", \r\n");\r
             } else {\r
                 fileBuffer.append("  NULL, \r\n");\r
             }\r
 \r
-            if (compConfList != null) {\r
+            if (driverBindingGroup[i][2] != null) {\r
                 fileBuffer.append("  &");\r
-                fileBuffer.append(compConfList[i]);\r
+                fileBuffer.append(driverBindingGroup[i][2]);\r
                 fileBuffer.append(", \r\n");\r
             } else {\r
                 fileBuffer.append("  NULL, \r\n");\r
             }\r
 \r
-            if (compDiagList != null) {\r
+            if (driverBindingGroup[i][3] != null) {\r
                 fileBuffer.append("  &");\r
-                fileBuffer.append(compDiagList[i]);\r
+                fileBuffer.append(driverBindingGroup[i][3]);\r
                 fileBuffer.append(", \r\n");\r
             } else {\r
                 fileBuffer.append("  NULL, \r\n");\r
             }\r
             fileBuffer.append("  }");\r
         }\r
-        fileBuffer.append("\r\n};\r\n");\r
+\r
+               if (driverBindingGroup.length > 0) {\r
+                       fileBuffer.append("\r\n};\r\n");\r
+               }\r
     }\r
 \r
     /**\r
@@ -1817,7 +1823,7 @@ public class AutoGen {
       @throws BuildException\r
     **/\r
     void ExternCallBackToAutoGenC(StringBuffer fileBuffer)\r
-    throws BuildException {\r
+    throws EdkException {\r
         //\r
         // Collect module's <SetVirtualAddressMapCallBack> and\r
         // <ExitBootServiceCallBack> and add to setVirtualAddList\r
@@ -1878,20 +1884,21 @@ public class AutoGen {
         //  do nothing.\r
         //\r
         if ((!outFile.exists()) ||(inFile.lastModified() - outFile.lastModified()) >= 0) {\r
-            try {\r
-                if (inFile.exists()) {\r
-                    FileInputStream fis = new FileInputStream (inFile);\r
-                    fis.read(buffer);\r
-                    FileOutputStream fos = new FileOutputStream(outFile);\r
-                    fos.write(buffer);\r
-                    fis.close();\r
-                    fos.close();\r
-                } else {\r
-                    throw new AutoGenException("The file, flashMap.h doesn't exist!");\r
-                }\r
-            } catch (Exception e) {\r
-                throw new AutoGenException(e.getMessage());\r
-            }\r
+                       if (inFile.exists()) {\r
+                               try{\r
+                                       FileInputStream fis = new FileInputStream (inFile);\r
+                                   fis.read(buffer);\r
+                                   FileOutputStream fos = new FileOutputStream(outFile);\r
+                                   fos.write(buffer);\r
+                                   fis.close();\r
+                                   fos.close();\r
+                               } catch (IOException e){\r
+                    throw new AutoGenException("The file, flashMap.h can't be open!");\r
+                               }\r
+                               \r
+                       } else {\r
+                               throw new AutoGenException("The file, flashMap.h doesn't exist!");\r
+                       }\r
         }\r
     }\r
 \r
@@ -1904,128 +1911,125 @@ public class AutoGen {
       @param\r
       @return    \r
     **/\r
-    private void collectLibInstanceInfo(){\r
+    private void collectLibInstanceInfo() throws EdkException{\r
         int index;\r
 \r
         String libConstructName = null;\r
         String libDestructName = null;\r
+               String libModuleType   = null;\r
         String[] setVirtuals = null;\r
         String[] exitBoots = null;\r
 \r
         ModuleIdentification[] libraryIdList = saq.getLibraryInstance(this.arch);\r
-        try {\r
-            if (libraryIdList != null) {\r
-                //\r
-                // Reorder library instance sequence.\r
-                //\r
-                AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList,\r
-                                                               this.arch);\r
-                List<ModuleIdentification> orderList = libOrder\r
-                                                       .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
-                        // Get library instance basename.\r
-                        //\r
-                        ModuleIdentification libInstanceId = orderList.get(i);\r
-\r
-                        //\r
-                        // Get override map\r
-                        //\r
-\r
-                        Map<String, XmlObject> libDoc = GlobalData.getDoc(libInstanceId, this.arch);\r
-                        saq.push(libDoc);\r
-                        //\r
-                        // Get <PPis>, <Protocols>, <Guids> list of this library\r
-                        // instance.\r
-                        //\r
-                        String[] ppiList = saq.getPpiArray(this.arch);\r
-                        String[] ppiNotifyList = saq.getPpiNotifyArray(this.arch);\r
-                        String[] protocolList = saq.getProtocolArray(this.arch);\r
-                        String[] protocolNotifyList = saq.getProtocolNotifyArray(this.arch);\r
-                        String[] guidList = saq.getGuidEntryArray(this.arch);\r
-                        PackageIdentification[] pkgList = saq.getDependencePkg(this.arch);\r
-\r
-                        //\r
-                        // Add those ppi, protocol, guid in global ppi,\r
-                        // protocol, guid\r
-                        // list.\r
-                        //\r
-                        for (index = 0; index < ppiList.length; index++) {\r
-                            this.mPpiList.add(ppiList[index]);\r
-                        }\r
-\r
-                        for (index = 0; index < ppiNotifyList.length; index++) {\r
-                            this.mPpiList.add(ppiNotifyList[index]);\r
-                        }\r
-\r
-                        for (index = 0; index < protocolList.length; index++) {\r
-                            this.mProtocolList.add(protocolList[index]);\r
-                        }\r
-\r
-                        for (index = 0; index < protocolNotifyList.length; index++) {\r
-                            this.mProtocolList.add(protocolNotifyList[index]);\r
-                        }\r
-\r
-                        for (index = 0; index < guidList.length; index++) {\r
-                            this.mGuidList.add(guidList[index]);\r
-                        }\r
-                        for (index = 0; index < pkgList.length; index++) {\r
-                            if (!this.mDepPkgList.contains(pkgList[index])) {\r
-                                this.mDepPkgList.add(pkgList[index]);\r
-                            }\r
-                        }\r
-\r
-                        //\r
-                        // If not yet parse this library instance's constructor\r
-                        // element,parse it.\r
-                        //\r
-                        libConstructName = saq.getLibConstructorName();\r
-                        libDestructName = saq.getLibDestructorName();\r
-\r
-                        //\r
-                        // Collect SetVirtualAddressMapCallBack and\r
-                        // ExitBootServiceCallBack.\r
-                        //\r
-                        setVirtuals = saq.getSetVirtualAddressMapCallBackArray();\r
-                        exitBoots = saq.getExitBootServicesCallBackArray();\r
-                        if (setVirtuals != null) {\r
-                            for (int j = 0; j < setVirtuals.length; j++) {\r
-                                this.setVirtalAddList.add(setVirtuals[j]);\r
-                            }\r
-                        }\r
-                        if (exitBoots != null) {\r
-                            for (int k = 0; k < exitBoots.length; k++) {\r
-                                this.exitBootServiceList.add(exitBoots[k]);\r
-                            }\r
-                        }\r
-                        saq.pop();\r
-                        //\r
-                        // Add dependent library instance constructor function.\r
-                        //\r
-                        if (libConstructName != null) {\r
-                            this.libConstructList.add(libConstructName);\r
-                        }\r
-                        //\r
-                        // Add dependent library instance destructor fuction.\r
-                        //\r
-                        if (libDestructName != null) {\r
-                            this.libDestructList.add(libDestructName);\r
-                        }\r
-                    }\r
-                }\r
 \r
-            }\r
+               if (libraryIdList != null) {\r
+                       //\r
+                       // Reorder library instance sequence.\r
+                       //\r
+                       AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList,\r
+                                                                                                                  this.arch);\r
+                       List<ModuleIdentification> orderList = libOrder\r
+                                                                                                  .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
+                                       // Get library instance basename.\r
+                                       //\r
+                                       ModuleIdentification libInstanceId = orderList.get(i);\r
+\r
+                                       //\r
+                                       // Get override map\r
+                                       //\r
+\r
+                                       Map<String, XmlObject> libDoc = GlobalData.getDoc(libInstanceId, this.arch);\r
+                                       saq.push(libDoc);\r
+                                       //\r
+                                       // Get <PPis>, <Protocols>, <Guids> list of this library\r
+                                       // instance.\r
+                                       //\r
+                                       String[] ppiList = saq.getPpiArray(this.arch);\r
+                                       String[] ppiNotifyList = saq.getPpiNotifyArray(this.arch);\r
+                                       String[] protocolList = saq.getProtocolArray(this.arch);\r
+                                       String[] protocolNotifyList = saq.getProtocolNotifyArray(this.arch);\r
+                                       String[] guidList = saq.getGuidEntryArray(this.arch);\r
+                                       PackageIdentification[] pkgList = saq.getDependencePkg(this.arch);\r
+\r
+                                       //\r
+                                       // Add those ppi, protocol, guid in global ppi,\r
+                                       // protocol, guid\r
+                                       // list.\r
+                                       //\r
+                                       for (index = 0; index < ppiList.length; index++) {\r
+                                               this.mPpiList.add(ppiList[index]);\r
+                                       }\r
+\r
+                                       for (index = 0; index < ppiNotifyList.length; index++) {\r
+                                               this.mPpiList.add(ppiNotifyList[index]);\r
+                                       }\r
+\r
+                                       for (index = 0; index < protocolList.length; index++) {\r
+                                               this.mProtocolList.add(protocolList[index]);\r
+                                       }\r
+\r
+                                       for (index = 0; index < protocolNotifyList.length; index++) {\r
+                                               this.mProtocolList.add(protocolNotifyList[index]);\r
+                                       }\r
+\r
+                                       for (index = 0; index < guidList.length; index++) {\r
+                                               this.mGuidList.add(guidList[index]);\r
+                                       }\r
+                                       for (index = 0; index < pkgList.length; index++) {\r
+                                               if (!this.mDepPkgList.contains(pkgList[index])) {\r
+                                                       this.mDepPkgList.add(pkgList[index]);\r
+                                               }\r
+                                       }\r
+\r
+                                       //\r
+                                       // If not yet parse this library instance's constructor\r
+                                       // element,parse it.\r
+                                       //\r
+                                       libConstructName = saq.getLibConstructorName();\r
+                                       libDestructName = saq.getLibDestructorName();\r
+                                       libModuleType = saq.getModuleType();\r
+\r
+                                       //\r
+                                       // Collect SetVirtualAddressMapCallBack and\r
+                                       // ExitBootServiceCallBack.\r
+                                       //\r
+                                       setVirtuals = saq.getSetVirtualAddressMapCallBackArray();\r
+                                       exitBoots = saq.getExitBootServicesCallBackArray();\r
+                                       if (setVirtuals != null) {\r
+                                               for (int j = 0; j < setVirtuals.length; j++) {\r
+                                                       this.setVirtalAddList.add(setVirtuals[j]);\r
+                                               }\r
+                                       }\r
+                                       if (exitBoots != null) {\r
+                                               for (int k = 0; k < exitBoots.length; k++) {\r
+                                                       this.exitBootServiceList.add(exitBoots[k]);\r
+                                               }\r
+                                       }\r
+                                       saq.pop();\r
+                                       //\r
+                                       // Add dependent library instance constructor function.\r
+                                       //\r
+                                       if (libConstructName != null) {\r
+                                               this.libConstructList.add(new String[] {libConstructName, libModuleType});\r
+                                       }\r
+                                       //\r
+                                       // Add dependent library instance destructor fuction.\r
+                                       //\r
+                                       if (libDestructName != null) {\r
+                                               this.libDestructList.add(new String[] {libDestructName, libModuleType});\r
+                                       }\r
+                               }\r
+                       }\r
 \r
-        } catch (Exception e) {\r
-            System.out.println(e.getMessage());\r
-            System.out.println("Collect library instance failed!");\r
-        }\r
+               }\r
     }\r
        private void setVirtualAddressToAutogenC(StringBuffer fileBuffer){\r
         //\r