]> git.proxmox.com Git - mirror_edk2.git/blobdiff - Tools/Source/GenBuild/org/tianocore/build/pcd/action/PCDAutoGenAction.java
Changed spelling to manifest
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / pcd / action / PCDAutoGenAction.java
index ca65c7546c5666db3b0d523d306971d9d7b17a1d..a2f1c6a1bf83bb2f5c8a26709f7f13e18c9a38b6 100644 (file)
 \r
   This class is to manage how to generate the PCD information into Autogen.c and\r
   Autogen.h.\r
\r
+\r
 Copyright (c) 2006, Intel Corporation\r
 All rights reserved. This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
 http://opensource.org/licenses/bsd-license.php\r
\r
+\r
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
 **/\r
 package org.tianocore.build.pcd.action;\r
 \r
-import java.io.File;\r
+import java.util.ArrayList;\r
 import java.util.List;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
 \r
+import org.tianocore.build.FrameworkBuildTask;\r
+import org.tianocore.build.autogen.CommonDefinition;\r
 import org.tianocore.build.global.GlobalData;\r
-import org.tianocore.build.pcd.entity.MemoryDatabaseManager;\r
-import org.tianocore.build.pcd.entity.Token;\r
-import org.tianocore.build.pcd.entity.UsageInstance;\r
-import org.tianocore.build.pcd.exception.BuildActionException;\r
-import org.tianocore.build.pcd.exception.EntityException;\r
-\r
-/** This class is to manage how to generate the PCD information into Autogen.c and\r
-    Autogen.h.\r
+import org.tianocore.build.id.ModuleIdentification;\r
+import org.tianocore.common.logger.EdkLog;\r
+import org.tianocore.pcd.action.BuildAction;\r
+import org.tianocore.pcd.entity.MemoryDatabaseManager;\r
+import org.tianocore.pcd.entity.Token;\r
+import org.tianocore.pcd.entity.UsageIdentification;\r
+import org.tianocore.pcd.entity.UsageInstance;\r
+import org.tianocore.pcd.exception.BuildActionException;\r
+\r
+/**\r
+    This class is to manage how to generate the PCD information into Autogen.c\r
+    and Autogen.h.\r
 **/\r
 public class PCDAutoGenAction extends BuildAction {\r
     ///\r
     /// The reference of DBManager in GlobalData class.\r
     ///\r
     private MemoryDatabaseManager dbManager;\r
+\r
     ///\r
-    /// The name of module which is analysised currently.\r
+    /// The identification for a UsageInstance.\r
     ///\r
-    private String                moduleName;\r
+    private UsageIdentification   usageId;\r
+\r
     ///\r
-    /// Wheter current module is PCD emulated driver. It is only for \r
-    /// emulated PCD driver and will be kept until PCD IMAGE tool ready.\r
+    /// Whether current autogen is for building library used by current module.\r
     ///\r
-    private boolean               isEmulatedPCDDriver;\r
+    private boolean               isBuildUsedLibrary;\r
+\r
+    ///\r
+    /// One of PEI_PCD_DRIVER, DXE_PCD_DRIVER, NOT_PCD_DRIVER \r
+    /// \r
+    private CommonDefinition.PCD_DRIVER_TYPE pcdDriverType;\r
+\r
     ///\r
     /// The generated string for header file.\r
     ///\r
     private String                hAutoGenString;\r
+\r
     ///\r
     /// The generated string for C code file.\r
     ///\r
-    private String                cAutoGenString;       \r
+    private String                cAutoGenString;\r
 \r
+    ///\r
+    /// The name array of <PcdCoded> in a module.\r
+    ///\r
+    private String[]              pcdNameArrayInMsa;\r
+\r
+    private UsageIdentification parentId = null;\r
     /**\r
-      Set parameter ModuleName\r
-  \r
+      Set parameter moduleId\r
+\r
       @param moduleName   the module name parameter.\r
     **/\r
-    public void setModuleName(String moduleName) {\r
-        this.moduleName = moduleName;\r
+    public void setUsageId(UsageIdentification usageId) {\r
+        this.usageId = usageId;\r
     }\r
 \r
     /**\r
-      Set parameter isEmulatedPCDDriver\r
-  \r
-      @param isEmulatedPCDDriver  whether this module is PeiEmulatedPCD driver\r
+       Set paramter pcdDriverType\r
+       \r
+       @param pcdDriverType the driver type for PCD\r
+    **/\r
+    public void setPcdDriverType(CommonDefinition.PCD_DRIVER_TYPE pcdDriverType) {\r
+        this.pcdDriverType = pcdDriverType;\r
+    }\r
+    /**\r
+       set isBuildUsedLibrary parameter.\r
+\r
+       @param isBuildUsedLibrary\r
     **/\r
-    public void setIsEmulatedPCDDriver(boolean isEmulatedPCDDriver) {\r
-        this.isEmulatedPCDDriver = isEmulatedPCDDriver;\r
+    public void setIsBuildUsedLibrary(boolean isBuildUsedLibrary) {\r
+        this.isBuildUsedLibrary = isBuildUsedLibrary;\r
+    }\r
+\r
+    /**\r
+       set pcdNameArrayInMsa parameter.\r
+\r
+       @param pcdNameArrayInMsa\r
+     */\r
+    public void setPcdNameArrayInMsa(String[] pcdNameArrayInMsa) {\r
+        this.pcdNameArrayInMsa = pcdNameArrayInMsa;\r
     }\r
 \r
     /**\r
       Get the output of generated string for header file.\r
-  \r
+\r
       @return the string of header file for PCD\r
     **/\r
-    public String OutputH() {\r
+    public String getHAutoGenString() {\r
         return hAutoGenString;\r
     }\r
 \r
     /**\r
       Get the output of generated string for C Code file.\r
-  \r
+\r
       @return the string of C code file for PCD\r
     **/\r
-    public String OutputC() {\r
+    public String getCAutoGenString() {\r
         return cAutoGenString;\r
     }\r
 \r
-    /**\r
-      Construct function\r
-  \r
-      This function mainly initialize some member variable.\r
-     \r
-      @param moduleName            Parameter of this action class.\r
-      @param isEmulatedPCDDriver   Parameter of this action class.\r
-    **/\r
-    public PCDAutoGenAction(String moduleName, boolean isEmulatedPCDDriver) {\r
-        dbManager = null;\r
-        setIsEmulatedPCDDriver(isEmulatedPCDDriver);\r
-        setModuleName(moduleName);\r
-    }\r
 \r
     /**\r
-      check the parameter for action class.\r
-      \r
-      @throws BuildActionException Bad parameter.\r
-    **/\r
-    void checkParameter() throws BuildActionException {\r
-        if(!isEmulatedPCDDriver &&(moduleName == null)) {\r
-            throw new BuildActionException("Wrong module name parameter for PCDAutoGenAction tool!");\r
-        }\r
+        Construct function\r
 \r
-        if(!isEmulatedPCDDriver && moduleName.length() == 0) {\r
-            throw new BuildActionException("Wrong module name parameter for PCDAutoGenAction tool!");\r
-        }\r
+        This function mainly initialize some member variable.\r
 \r
-        //\r
-        // Check the PCD memory database manager is valid.\r
-        //\r
-        if(GlobalData.getPCDMemoryDBManager() == null) {\r
-            throw new BuildActionException("Memory database has not been initlizated!");\r
+        @param moduleId             the identification for module\r
+        @param arch                 the architecture for module\r
+        @param isBuildUsedLibary    Is the current module library.\r
+        @param pcdNameArrayInMsa    the pcd name array got from MSA file.\r
+        @param pcdDriverType        one of PEI_PCD_DRIVER, DXE_PCD_DRIVER,\r
+                                    NOT_PCD_DRIVER\r
+    **/\r
+    public PCDAutoGenAction(ModuleIdentification moduleId,\r
+                            String               arch,\r
+                            boolean              isBuildUsedLibrary,\r
+                            String[]             pcdNameArrayInMsa,\r
+                            CommonDefinition.PCD_DRIVER_TYPE pcdDriverType,\r
+                            ModuleIdentification parentId) {\r
+        dbManager       = null;\r
+        hAutoGenString  = "";\r
+        cAutoGenString  = "";\r
+\r
+        setUsageId(new UsageIdentification(moduleId.getName(),\r
+                                           moduleId.getGuid(),\r
+                                           moduleId.getPackage().getName(),\r
+                                           moduleId.getPackage().getGuid(),\r
+                                           arch,\r
+                                           moduleId.getVersion(),\r
+                                           moduleId.getModuleType()));\r
+        if (parentId != null) {\r
+            this.parentId = new UsageIdentification(parentId.getName(),\r
+                        parentId.getGuid(),\r
+                        parentId.getPackage().getName(),\r
+                        parentId.getPackage().getGuid(),\r
+                        arch,\r
+                        parentId.getVersion(),\r
+                        parentId.getModuleType());\r
         }\r
+        setIsBuildUsedLibrary(isBuildUsedLibrary);\r
+        setPcdNameArrayInMsa(pcdNameArrayInMsa);\r
+        setPcdDriverType(pcdDriverType);\r
+    }\r
 \r
-        dbManager = GlobalData.getPCDMemoryDBManager();\r
-\r
-        if(dbManager.getDBSize() == 0) {\r
-            throw new BuildActionException("Memory database does not contain any record!");\r
-        }\r
+    /**\r
+      Override function: check the parameter for action class.\r
 \r
-        ActionMessage.debug(this,\r
-                            "PCD memory database contains " + dbManager.getDBSize() + " PCD tokens");\r
+      @throws BuildActionException Bad parameter.\r
+    **/\r
+    public void checkParameter() {\r
     }\r
 \r
     /**\r
       Core execution function for this action class.\r
-     \r
+\r
       All PCD information of this module comes from memory dabase. The collection\r
       work should be done before this action execution.\r
-      Currently, we should generated all PCD information(maybe all dynamic) as array \r
-      in Pei emulated driver for simulating PCD runtime database. \r
-      \r
+      Currently, we should generated all PCD information(maybe all dynamic) as array\r
+      in Pei emulated driver for simulating PCD runtime database.\r
+\r
       @throws BuildActionException Failed to execute this aciton class.\r
     **/\r
-    void performAction() throws BuildActionException {\r
-        ActionMessage.debug(this, \r
-                            "Starting PCDAutoGenAction to generate autogen.h and autogen.c!...");\r
+    public void performAction() {\r
+        EdkLog.log(EdkLog.EDK_DEBUG, "Starting PCDAutoGenAction to generate autogen.h and autogen.c!...");\r
 \r
-        hAutoGenString = "";\r
-        cAutoGenString = "";\r
+        dbManager = GlobalData.getPCDMemoryDBManager();\r
 \r
-        if(isEmulatedPCDDriver) {\r
-            generateAutogenForPCDEmulatedDriver();\r
-        } else {\r
-            generateAutogenForModule();\r
+        if(dbManager.getDBSize() == 0) {\r
+            return;\r
         }\r
+\r
+        EdkLog.log(EdkLog.EDK_DEBUG, "PCD memory database contains " + dbManager.getDBSize() + " PCD tokens.");\r
+\r
+        generateAutogenForModule();\r
     }\r
 \r
     /**\r
       Generate the autogen string for a common module.\r
-     \r
+\r
       All PCD information of this module comes from memory dabase. The collection\r
       work should be done before this action execution.\r
     **/\r
     private void generateAutogenForModule()\r
     {\r
-        int                   index;\r
-        List<UsageInstance>   usageInstanceArray;\r
-\r
-        usageInstanceArray  = dbManager.getUsageInstanceArrayByModuleName(moduleName);\r
-\r
-        if(usageInstanceArray.size() != 0) {\r
-            //\r
-            // Add "#include 'PcdLib.h'" for Header file\r
-            //\r
-            hAutoGenString = "#include <MdePkg/Include/Library/PcdLib.h>\r\n";\r
-        }\r
-\r
-        for(index = 0; index < usageInstanceArray.size(); index ++) {\r
-            ActionMessage.debug(this,\r
-                                "Module " + moduleName + "'s PCD [" + Integer.toHexString(index) + \r
-                                "]: " + usageInstanceArray.get(index).parentToken.cName);\r
-            try {\r
-                usageInstanceArray.get(index).generateAutoGen();\r
-                hAutoGenString += usageInstanceArray.get(index).getHAutogenStr() + "\r\n";\r
-                cAutoGenString += usageInstanceArray.get(index).getCAutogenStr() + "\r\n";\r
-            } catch(EntityException exp) {\r
-                throw new BuildActionException(exp.getMessage());\r
-            }\r
-        }\r
-\r
-        ActionMessage.debug(this,\r
-                            "Module " + moduleName + "'s PCD header file:\r\n" + hAutoGenString + "\r\n"\r
-                           );\r
-        ActionMessage.debug(this,\r
-                             "Module " + moduleName + "'s PCD C file:\r\n" + cAutoGenString + "\r\n"\r
-                            );\r
-    }\r
-\r
-    /**\r
-      Generate all PCD autogen string and the emulated PCD IMAGE array for emulated driver.\r
-      \r
-      Currently, we should generated all PCD information(maybe all dynamic) as array \r
-      in Pei emulated driver for simulating PCD runtime database. \r
-      \r
-    **/\r
-    private void generateAutogenForPCDEmulatedDriver() {\r
-        int           index;\r
-        Token[]       tokenArray;\r
-        UsageInstance usageInstance;\r
-\r
-        //\r
-        // Add "#include 'PcdLib.h'" for Header file\r
-        //\r
-        hAutoGenString = "#include <MdePkg/Include/Library/PcdLib.h>\r\n";\r
-\r
-        tokenArray = dbManager.getRecordArray();\r
-        for(index = 0; index < tokenArray.length; index ++) {\r
-            //\r
-            // Get one consumer instance and generate autogen for this token.\r
-            //\r
-            if(tokenArray[index].consumers != null ) {\r
-                if(tokenArray[index].consumers.size() == 0) {\r
-                    continue;\r
-                }\r
-\r
-                usageInstance = tokenArray[index].consumers.get(0);\r
-                try {\r
-                    usageInstance.generateAutoGen();\r
-                } catch(EntityException exp) {\r
-                    throw new BuildActionException(exp.getMessage());\r
+        int                   index, index2;\r
+        List<UsageInstance>   usageInstanceArray, usageContext;\r
+        String[]              guidStringArray = null;\r
+        String                guidStringCName = null;\r
+        String                guidString      = null;\r
+        String                moduleName      = usageId.moduleName;\r
+        UsageInstance         usageInstance   = null;\r
+        boolean               found           = false;\r
+\r
+        usageInstanceArray = null;\r
+        \r
+        if (FrameworkBuildTask.multithread) {\r
+            if (parentId == null) {\r
+                usageInstanceArray  = dbManager.getUsageInstanceArrayById(usageId);\r
+            } else if ((pcdNameArrayInMsa != null) && (pcdNameArrayInMsa.length > 0)) {\r
+                usageContext = dbManager.getUsageInstanceArrayById(parentId);\r
+                //\r
+                // For building library package, although all module are library, but PCD entries of\r
+                // these library should be used to autogen.\r
+                //\r
+                if (usageContext == null) {\r
+                    usageInstanceArray  = dbManager.getUsageInstanceArrayById(usageId);\r
+                } else {\r
+                    usageInstanceArray = new ArrayList<UsageInstance>();\r
+\r
+                    //\r
+                    // Try to find all PCD defined in library's PCD in all <PcdEntry> in module's\r
+                    // <ModuleSA> in FPD file.\r
+                    //\r
+                    for (index = 0; index < pcdNameArrayInMsa.length; index++) {\r
+                        found = false;\r
+                        for (index2 = 0; index2 < usageContext.size(); index2 ++) {\r
+                            if (pcdNameArrayInMsa[index].equalsIgnoreCase(usageContext.get(index2).parentToken.cName)) {\r
+                                usageInstanceArray.add(usageContext.get(index2));\r
+                                found = true;\r
+                                break;\r
+                            }\r
+                        }\r
+\r
+                        if (!found) {\r
+                            //\r
+                            // All library's PCD should instanted in module's <ModuleSA> who\r
+                            // use this library instance. If not, give errors.\r
+                            //\r
+                            throw new BuildActionException (String.format("Module %s using library instance %s; the PCD %s " +\r
+                                                                          "is required by this library instance, but can not be found " +\r
+                                                                          "in the %s's <ModuleSA> in the FPD file!",\r
+                                                                          MemoryDatabaseManager.CurrentModuleName,\r
+                                                                          moduleName,\r
+                                                                          pcdNameArrayInMsa[index],\r
+                                                                          MemoryDatabaseManager.CurrentModuleName\r
+                                                                          ));\r
+                        }\r
+                    }\r
                 }\r
-\r
-                hAutoGenString += usageInstance.getHAutogenStr();\r
-                cAutoGenString += usageInstance.getCAutogenStr();\r
-\r
-                hAutoGenString += "\r\n";\r
-                cAutoGenString += "\r\n";\r
             }\r
-        }\r
-\r
-        generatePCDEmulatedArray(tokenArray);\r
-\r
-        ActionMessage.debug(this,\r
-                             "PCD emulated driver's header: \r\n" + hAutoGenString + "\r\n"\r
-                            );\r
-        ActionMessage.debug(this,\r
-                             "PCD emulated driver's C code: \r\n" + cAutoGenString + "\r\n"\r
-                            );\r
-\r
-    }\r
-\r
-    /**\r
-      Generate PCDEmulated array in PCDEmulated driver for emulated runtime database.\r
-      \r
-      @param tokenArray  All PCD token in memory database.\r
-      \r
-      @throws BuildActionException  Unknown PCD_TYPE\r
-    **/\r
-    private void generatePCDEmulatedArray(Token[] tokenArray)\r
-        throws BuildActionException {\r
-        int       index;\r
-        Token     token;\r
-        String[]  guidStrArray;\r
-        String    value;\r
-\r
-        //\r
-        // The value of String type of PCD entry maybe use byte array but not string direcly\r
-        // such as {0x1, 0x2, 0x3}, and define PCD1_STRING_Value as L"string define here"\r
-        // For this case, we should generate a string array to C output and use the address\r
-        // of generated string array.\r
-        //\r
-        for(index = 0; index < tokenArray.length; index ++) {\r
-            token = tokenArray[index];\r
-\r
-            if((token.producers.size() == 0) &&(token.consumers.size() == 0)) {\r
+        } else {\r
+            if (!isBuildUsedLibrary) {\r
+                usageInstanceArray  = dbManager.getUsageInstanceArrayById(usageId);\r
+                MemoryDatabaseManager.UsageInstanceContext = usageInstanceArray;\r
+                MemoryDatabaseManager.CurrentModuleName    = moduleName;\r
+            } else if ((pcdNameArrayInMsa != null) && (pcdNameArrayInMsa.length > 0)) {\r
+                usageContext = MemoryDatabaseManager.UsageInstanceContext;\r
                 //\r
-                // If no one use this PCD token, it will not generated in emulated array.\r
+                // For building library package, although all module are library, but PCD entries of\r
+                // these library should be used to autogen.\r
                 //\r
-                continue;\r
-            }\r
-            value = token.datum.toString();\r
-            if(token.datumType == Token.DATUM_TYPE.POINTER) {\r
-                if(!((value.charAt(0) == 'L' && value.charAt(1) == '"') ||(value.charAt(0) == '"'))) {\r
-                    cAutoGenString += String.format("UINT8 _mPcdArray%08x[] = %s;\r\n", \r
-                                                     index, \r
-                                                     value\r
-                                                     );\r
+                if (usageContext == null) {\r
+                    usageInstanceArray  = dbManager.getUsageInstanceArrayById(usageId);\r
+                } else {\r
+                    usageInstanceArray = new ArrayList<UsageInstance>();\r
+    \r
+                    //\r
+                    // Try to find all PCD defined in library's PCD in all <PcdEntry> in module's\r
+                    // <ModuleSA> in FPD file.\r
+                    //\r
+                    for (index = 0; index < pcdNameArrayInMsa.length; index++) {\r
+                        found = false;\r
+                        for (index2 = 0; index2 < usageContext.size(); index2 ++) {\r
+                            if (pcdNameArrayInMsa[index].equalsIgnoreCase(usageContext.get(index2).parentToken.cName)) {\r
+                                usageInstanceArray.add(usageContext.get(index2));\r
+                                found = true;\r
+                                break;\r
+                            }\r
+                        }\r
+    \r
+                        if (!found) {\r
+                            //\r
+                            // All library's PCD should instanted in module's <ModuleSA> who\r
+                            // use this library instance. If not, give errors.\r
+                            //\r
+                            throw new BuildActionException (String.format("Module %s using library instance %s; the PCD %s " +\r
+                                                                          "is required by this library instance, but can not be found " +\r
+                                                                          "in the %s's <ModuleSA> in the FPD file!",\r
+                                                                          MemoryDatabaseManager.CurrentModuleName,\r
+                                                                          moduleName,\r
+                                                                          pcdNameArrayInMsa[index],\r
+                                                                          MemoryDatabaseManager.CurrentModuleName\r
+                                                                          ));\r
+                        }\r
+                    }\r
                 }\r
             }\r
         }\r
+        if (usageInstanceArray == null) {\r
+            return;\r
+        }\r
 \r
         //\r
-        // Output emulated PCD entry array\r
+        // Generate all PCD entry for a module.\r
         //\r
-        cAutoGenString += "\r\nEMULATED_PCD_ENTRY gEmulatedPcdEntry[] = {\r\n";\r
-\r
-        for(index = 0; index < tokenArray.length; index ++) {\r
-            token = tokenArray[index];\r
-\r
-            if((token.producers.size() == 0) &&(token.consumers.size() == 0)) {\r
-                //\r
-                // If no one use this PCD token, it will not generated in emulated array.\r
-                //\r
-                continue;\r
-            }\r
-\r
-            if(index != 0) {\r
-                cAutoGenString += ",\r\n";\r
-            }\r
-\r
-            //\r
-            // Print Start "{" for a Token item in array\r
-            //\r
-            cAutoGenString += "  {\r\n";\r
-\r
-            //\r
-            // Print Token Name\r
-            //\r
-            cAutoGenString += String.format("    _PCD_TOKEN_%s,\r\n", token.cName);\r
-\r
-            //\r
-            // Print Hii information\r
-            //\r
-            if(token.hiiEnabled) {\r
-                cAutoGenString += String.format("    TRUE,\r\n");\r
-            } else {\r
-                cAutoGenString += String.format("    FALSE,\r\n");\r
-            }\r
-\r
-            //\r
-            // Print sku information\r
-            //\r
-            if(token.skuEnabled) {\r
-                cAutoGenString += String.format("    TRUE,\r\n");\r
-            } else {\r
-                cAutoGenString += String.format("    FALSE,\r\n");\r
-            }\r
-\r
+        for(index = 0; index < usageInstanceArray.size(); index ++) {\r
+            usageInstance = usageInstanceArray.get(index);\r
             //\r
-            // Print maxSkuCount\r
+            // Before generate any PCD information into autogen.h/autogen.c for a module,\r
+            // generate TokenSpaceGuid array variable firstly. For every dynamicEx type\r
+            // PCD in this module the token, they are all reference to TokenSpaceGuid\r
+            // array.\r
             //\r
-            cAutoGenString += String.format("    %d,\r\n", token.maxSkuCount);\r
-\r
-            cAutoGenString += String.format("    %d,\r\n", token.skuId);\r
-\r
-            if(token.variableGuid == null) {\r
-                cAutoGenString += "    { 0x00000000, 0x0000, 0x0000, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } },\r\n";\r
-            } else {\r
-                guidStrArray =(token.variableGuid.toString()).split("-");\r
-\r
-                cAutoGenString += String.format("    { 0x%s, 0x%s, 0x%s, { 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s } },\r\n",\r
-                                                 guidStrArray[0],\r
-                                                 guidStrArray[1],\r
-                                                 guidStrArray[2],\r
-                                                (guidStrArray[3].substring(0, 2)),\r
-                                                (guidStrArray[3].substring(2, 4)),\r
-                                                (guidStrArray[4].substring(0, 2)),\r
-                                                (guidStrArray[4].substring(2, 4)),\r
-                                                (guidStrArray[4].substring(4, 6)),\r
-                                                (guidStrArray[4].substring(6, 8)),\r
-                                                (guidStrArray[4].substring(8, 10)),\r
-                                                (guidStrArray[4].substring(10, 12))\r
-                                                );\r
-\r
-            }\r
-\r
-            value = token.datum.toString();\r
-            if(token.datumType == Token.DATUM_TYPE.POINTER) {\r
-                if((value.charAt(0) == 'L' && value.charAt(1) == '"') || value.charAt(0) == '"') {\r
-                    cAutoGenString += String.format("    sizeof(_PCD_VALUE_%s),\r\n", token.cName);\r
-                    cAutoGenString += String.format("    0, %s, %s,\r\n", token.variableName, value);\r
-                } else {\r
-                    cAutoGenString += String.format("    sizeof(_mPcdArray%08x),\r\n", index);\r
-                    cAutoGenString += String.format("    0, &_mPcdArray%08x, %s,\r\n", index, token.variableName);\r
-                }\r
-            } else {\r
-                switch(token.datumType) {\r
-                case UINT8:\r
-                    cAutoGenString += "    1,\r\n";\r
-                    break;\r
-                case UINT16:\r
-                    cAutoGenString += "    2,\r\n";\r
-                    break;\r
-                case UINT32:\r
-                    cAutoGenString += "    4,\r\n";\r
-                    break;\r
-                case UINT64:\r
-                    cAutoGenString += "    8,\r\n";\r
-                    break;\r
-                case BOOLEAN:\r
-                    cAutoGenString += "    1,\r\n";\r
-                    break;\r
-                default:\r
-                    throw new BuildActionException("Unknown datum size");\r
+            if (usageInstanceArray.get(index).modulePcdType == Token.PCD_TYPE.DYNAMIC_EX) {\r
+                guidStringArray = usageInstance.parentToken.tokenSpaceName.split("-");\r
+                guidStringCName = "_gPcd_TokenSpaceGuid_" +\r
+                                  usageInstance.parentToken.tokenSpaceName.replaceAll("-", "_");\r
+                guidString      = String.format("{ 0x%s, 0x%s, 0x%s, {0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s}}",\r
+                                                guidStringArray[0],\r
+                                                guidStringArray[1],\r
+                                                guidStringArray[2],\r
+                                                (guidStringArray[3].substring(0, 2)),\r
+                                                (guidStringArray[3].substring(2, 4)),\r
+                                                (guidStringArray[4].substring(0, 2)),\r
+                                                (guidStringArray[4].substring(2, 4)),\r
+                                                (guidStringArray[4].substring(4, 6)),\r
+                                                (guidStringArray[4].substring(6, 8)),\r
+                                                (guidStringArray[4].substring(8, 10)),\r
+                                                (guidStringArray[4].substring(10, 12)));\r
+\r
+                Pattern pattern = Pattern.compile("(" + guidStringCName + ")+?");\r
+                Matcher matcher = pattern.matcher(cAutoGenString + " ");\r
+                //\r
+                // Find whether this guid array variable has been generated into autogen.c\r
+                // For different DyanmicEx pcd token who use same token space guid, the token space\r
+                // guid array should be only generated once.\r
+                //\r
+                if (!matcher.find()) {\r
+                    hAutoGenString += String.format("extern EFI_GUID %s;\r\n", guidStringCName);\r
+                    if (!isBuildUsedLibrary) {\r
+                        cAutoGenString += String.format("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID %s = %s;\r\n",\r
+                                                        guidStringCName,\r
+                                                        guidString);\r
+                    }\r
                 }\r
-                cAutoGenString += String.format("    %s, %s, NULL,\r\n", value, token.variableName);\r
             }\r
 \r
+            usageInstance.generateAutoGen(isBuildUsedLibrary);\r
             //\r
-            // Print end "}" for a token item in array\r
+            // For every PCD entry for this module(usage instance), autogen string would\r
+            // be appand.\r
             //\r
-            cAutoGenString += "  }";\r
+            hAutoGenString += usageInstance.getHAutogenStr() + "\r\n";\r
+            cAutoGenString += usageInstance.getCAutogenStr();\r
         }\r
 \r
-        cAutoGenString += "\r\n};\r\n";\r
-        cAutoGenString += "\r\n";\r
-        cAutoGenString += "UINTN\r\n";\r
-        cAutoGenString += "GetPcdDataBaseSize(\r\n";\r
-        cAutoGenString += "  VOID\r\n";\r
-        cAutoGenString += "  )\r\n";\r
-        cAutoGenString += "{\r\n";\r
-        cAutoGenString += "  return sizeof(gEmulatedPcdEntry);\r\n";\r
-        cAutoGenString += "}\r\n";\r
-    }\r
-\r
-    /**\r
-      Test case function\r
-\r
-      @param argv  paramter from command line\r
-    **/\r
-    public static void main(String argv[]) {\r
-        String logFilePath = "G:/mdk/EdkNt32Pkg/build/Nt32.fpd";\r
-\r
-        //\r
-        // At first, CollectPCDAction should be invoked to collect\r
-        // all PCD information from SPD, MSA, FPD.\r
-        //\r
-        CollectPCDAction collectionAction = new CollectPCDAction();\r
-        GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
-                            "G:/mdk");\r
-\r
-        GlobalData.getPCDMemoryDBManager().setLogFileName(logFilePath + ".PCDMemroyDatabaseLog.txt");\r
-\r
-        try {\r
-            collectionAction.perform("G:/mdk", \r
-                                     logFilePath,\r
-                                     ActionMessage.MAX_MESSAGE_LEVEL);\r
-        } catch(Exception e) {\r
-            e.printStackTrace();\r
+        if (pcdDriverType == CommonDefinition.PCD_DRIVER_TYPE.PEI_PCD_DRIVER) {\r
+            hAutoGenString += MemoryDatabaseManager.PcdPeimHString;\r
+            cAutoGenString += MemoryDatabaseManager.PcdPeimCString;\r
+        } else if (pcdDriverType == CommonDefinition.PCD_DRIVER_TYPE.DXE_PCD_DRIVER) {\r
+            hAutoGenString += MemoryDatabaseManager.PcdDxeHString;\r
+            cAutoGenString += MemoryDatabaseManager.PcdDxeCString;\r
         }\r
-\r
-        //\r
-        // Then execute the PCDAuotoGenAction to get generated Autogen.h and Autogen.c\r
-        //\r
-        PCDAutoGenAction autogenAction = new PCDAutoGenAction("HelloWorld",\r
-                                                              true\r
-                                                              );\r
-        autogenAction.execute();\r
     }\r
 }\r