Fix a bug of unreference PCD token defined in FPD does *not* be autogened into emulat...
authorklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 17 May 2006 07:20:37 +0000 (07:20 +0000)
committerklu2 <klu2@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 17 May 2006 07:20:37 +0000 (07:20 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@181 6f19259b-4bc3-4df7-8a09-765794883524

Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java
Tools/Source/GenBuild/org/tianocore/build/pcd/action/PCDAutoGenAction.java

index 71a30b6..4cddce2 100644 (file)
@@ -489,6 +489,7 @@ public class CollectPCDAction {
             // BUGBUG: in FPD, <defaultValue> should be defined as <Value>\r
             //\r
             token.datum        = pcdBuildData.getDefaultValue();\r
+            token.tokenNumber  = Integer.decode(pcdBuildData.getToken().getStringValue());\r
             token.hiiEnabled   = pcdBuildData.getHiiEnable();\r
             token.variableGuid = Token.getGUIDFromSchemaObject(pcdBuildData.getVariableGuid());\r
             token.variableName = pcdBuildData.getVariableName();\r
index 76a1519..f3e5b17 100644 (file)
@@ -221,22 +221,27 @@ public class PCDAutoGenAction extends BuildAction {
             // 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
+                if(tokenArray[index].consumers.size() != 0) {\r
+                    usageInstance = tokenArray[index].consumers.get(0);\r
+                    try {\r
+                        usageInstance.generateAutoGen();\r
+                    } catch(EntityException exp) {\r
+                        throw new BuildActionException(exp.getMessage());\r
+                    }\r
+    \r
+                    hAutoGenString += usageInstance.getHAutogenStr();\r
+                    cAutoGenString += usageInstance.getCAutogenStr();\r
+    \r
+                    hAutoGenString += "\r\n";\r
+                    cAutoGenString += "\r\n";\r
+                } else {\r
+                    //\r
+                    // If the PCD does *not* usded by any module, also generate \r
+                    // it into autogen.h/autogen.c in Pcd driver according the\r
+                    // information in FPD file.\r
+                    //\r
+                    generateUnReferencePcdAutogenString(tokenArray[index]);\r
                 }\r
-\r
-                hAutoGenString += usageInstance.getHAutogenStr();\r
-                cAutoGenString += usageInstance.getCAutogenStr();\r
-\r
-                hAutoGenString += "\r\n";\r
-                cAutoGenString += "\r\n";\r
             }\r
         }\r
 \r
@@ -251,6 +256,111 @@ public class PCDAutoGenAction extends BuildAction {
 \r
     }\r
 \r
+    /**\r
+      Generate unreference token definition string for PCD emulated string. \r
+      \r
+      Maybe some PCD token definition in FPD but not used by any module or library, we \r
+      should also generate token definition in autoge.h/autogen.c, because maybe some\r
+      driver loaded in shell will use this PCD. \r
+\r
+     @param token   The token who want be generated autogen string.\r
+    \r
+    **/\r
+    private void generateUnReferencePcdAutogenString(Token token) {\r
+        hAutoGenString += String.format("#define _PCD_TOKEN_%s   0x%016x\r\n", \r
+                                        token.cName, token.tokenNumber);\r
+        switch (token.pcdType) {\r
+        case FEATURE_FLAG:\r
+            hAutoGenString += String.format(\r
+                                "#define _PCD_VALUE_%s   %s\r\n", \r
+                                token.cName, \r
+                                token.datum.toString()\r
+                                );\r
+            hAutoGenString += String.format(\r
+                                "extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n", \r
+                                token.cName\r
+                                );\r
+            cAutoGenString += String.format(\r
+                                "GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",\r
+                                token.cName,\r
+                                token.cName\r
+                                );\r
+            hAutoGenString += String.format(\r
+                                "#define _PCD_MODE_%s_%s  _PCD_VALUE_%s\r\n",\r
+                                Token.GetAutogenDefinedatumTypeString(token.datumType),\r
+                                token.cName,\r
+                                token.cName\r
+                                );\r
+            break;\r
+        case FIXED_AT_BUILD:\r
+            hAutoGenString += String.format(\r
+                                "#define _PCD_VALUE_%s   %s\r\n", \r
+                                token.cName, \r
+                                token.datum.toString()\r
+                                );\r
+            hAutoGenString += String.format(\r
+                                "extern const %s _gPcd_FixedAtBuild_%s;\r\n",\r
+                                Token.getAutogendatumTypeString(token.datumType),\r
+                                token.cName\r
+                                );\r
+            cAutoGenString += String.format(\r
+                                "GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",\r
+                                Token.getAutogendatumTypeString(token.datumType),\r
+                                token.cName,\r
+                                token.cName\r
+                                );\r
+            hAutoGenString += String.format(\r
+                                "#define _PCD_MODE_%s_%s  _PCD_VALUE_%s\r\n",\r
+                                Token.GetAutogenDefinedatumTypeString(token.datumType),\r
+                                token.cName,\r
+                                token.cName\r
+                                );\r
+            break;\r
+        case PATCHABLE_IN_MODULE:\r
+            hAutoGenString += String.format(\r
+                                 "#define _PCD_VALUE_%s   %s\r\n", \r
+                                 token.cName, \r
+                                 token.datum.toString()\r
+                                 );\r
+            hAutoGenString += String.format(\r
+                                 "extern %s _gPcd_BinaryPatch_%s;\r\n",\r
+                                 Token.getAutogendatumTypeString(token.datumType),\r
+                                 token.cName\r
+                                 );\r
+            cAutoGenString += String.format(\r
+                                 "GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",\r
+                                 Token.getAutogendatumTypeString(token.datumType),\r
+                                 token.cName,\r
+                                 token.cName\r
+                                 );\r
+            hAutoGenString += String.format(\r
+                                 "#define _PCD_MODE_%s_%s  _gPcd_BinaryPatch_%s\r\n",\r
+                                 Token.GetAutogenDefinedatumTypeString(token.datumType),\r
+                                 token.cName,\r
+                                 token.cName\r
+                                 );\r
+            break;\r
+        case DYNAMIC:\r
+            hAutoGenString += String.format(\r
+                                "#define _PCD_MODE_%s_%s  LibPcdGet%s(_PCD_TOKEN_%s)\r\n",\r
+                                Token.GetAutogenDefinedatumTypeString(token.datumType),\r
+                                token.cName,\r
+                                Token.getAutogenLibrarydatumTypeString(token.datumType),\r
+                                token.cName\r
+                                );\r
+            break;\r
+        case DYNAMIC_EX:\r
+            break;\r
+        default:\r
+            ActionMessage.warning(this, \r
+                                  "The PCD_TYPE setted by platform is unknown"\r
+                                  );\r
+        }\r
+\r
+        hAutoGenString += "\r\n";\r
+        cAutoGenString += "\r\n";\r
+    }\r
+        \r
     /**\r
       Generate PCDEmulated array in PCDEmulated driver for emulated runtime database.\r
       \r
@@ -274,12 +384,6 @@ public class PCDAutoGenAction extends BuildAction {
         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
             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
@@ -299,13 +403,6 @@ public class PCDAutoGenAction extends BuildAction {
         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
@@ -421,7 +518,7 @@ public class PCDAutoGenAction extends BuildAction {
       @param argv  paramter from command line\r
     **/\r
     public static void main(String argv[]) {\r
-        String logFilePath = "G:/mdk/EdkNt32Pkg/build/Nt32.fpd";\r
+        String logFilePath = "M:/tianocore/edk2/trunk/edk2/EdkNt32Pkg/Nt32.fpd";\r
 \r
         //\r
         // At first, CollectPCDAction should be invoked to collect\r
@@ -429,12 +526,12 @@ public class PCDAutoGenAction extends BuildAction {
         //\r
         CollectPCDAction collectionAction = new CollectPCDAction();\r
         GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
-                            "G:/mdk");\r
+                            "M:/tianocore/edk2/trunk/edk2");\r
 \r
         GlobalData.getPCDMemoryDBManager().setLogFileName(logFilePath + ".PCDMemroyDatabaseLog.txt");\r
 \r
         try {\r
-            collectionAction.perform("G:/mdk", \r
+            collectionAction.perform("M:/tianocore/edk2/trunk/edk2", \r
                                      logFilePath,\r
                                      ActionMessage.MAX_MESSAGE_LEVEL);\r
         } catch(Exception e) {\r
@@ -444,9 +541,12 @@ public class PCDAutoGenAction extends BuildAction {
         //\r
         // Then execute the PCDAuotoGenAction to get generated Autogen.h and Autogen.c\r
         //\r
-        PCDAutoGenAction autogenAction = new PCDAutoGenAction("HelloWorld",\r
+        PCDAutoGenAction autogenAction = new PCDAutoGenAction("PcdEmulator",\r
                                                               true\r
                                                               );\r
         autogenAction.execute();\r
+        System.out.println (autogenAction.hAutoGenString);\r
+        System.out.println (autogenAction.cAutoGenString);\r
+\r
     }\r
 }\r