git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@250 6f19259b...
authorqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 24 May 2006 08:09:43 +0000 (08:09 +0000)
committerqwang12 <qwang12@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 24 May 2006 08:09:43 +0000 (08:09 +0000)
Tools/Source/GenBuild/org/tianocore/build/autogen/CommonDefinition.java
Tools/Source/GenBuild/org/tianocore/build/pcd/action/CollectPCDAction.java
Tools/Source/GenBuild/org/tianocore/build/pcd/action/PCDAutoGenAction.java
Tools/Source/GenBuild/org/tianocore/build/pcd/entity/MemoryDatabaseManager.java
Tools/Source/GenBuild/org/tianocore/build/pcd/entity/Token.java
Tools/Source/GenBuild/org/tianocore/build/pcd/entity/UsageInstance.java

index 2490d97..ce0bafe 100644 (file)
@@ -254,4 +254,29 @@ public class CommonDefinition {
       }\r
       return false;\r
     }\r
+\r
+               static public boolean isPeiPhaseComponent (int componentType) {\r
+                       if (ComponentTypePe32Peim == componentType\r
+                                       || ComponentTypePicPeim == componentType\r
+                                       || ComponentTypeCombinedPeimDriver == componentType\r
+                                       || ComponentTypePeiCore == componentType) {\r
+                               return true;\r
+                       }\r
+                       return false;\r
+               }\r
+\r
+               static public boolean isPe32PeimComponent (int componentType) {\r
+                       if (ComponentTypePe32Peim == componentType) {\r
+                               return true;\r
+                       }\r
+                       return false;\r
+               }\r
+\r
+               static public boolean isBsDriverComponent (int componentType) {\r
+                       if (ComponentTypeBsDriver == componentType) {\r
+                               return true;\r
+                       }\r
+                       return false;\r
+               }\r
+               \r
 }
\ No newline at end of file
index 4cddce2..da98801 100644 (file)
@@ -17,9 +17,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 **/\r
 package org.tianocore.build.pcd.action;\r
 \r
+import java.io.BufferedReader;\r
 import java.io.File;\r
+import java.io.FileReader;\r
 import java.io.IOException;\r
 import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.Comparator;\r
 import java.util.HashMap;\r
 import java.util.List;\r
 import java.util.Map;\r
@@ -42,6 +46,1137 @@ import org.tianocore.build.pcd.entity.Token;
 import org.tianocore.build.pcd.entity.UsageInstance;\r
 import org.tianocore.build.pcd.exception.EntityException;\r
 \r
+class StringTable {\r
+    private ArrayList<String>   al; \r
+               private ArrayList<String>   alComments;\r
+    private String              phase;\r
+    int                         len; \r
+               int                                                                                                     bodyStart;\r
+               int                                                                                                     bodyLineNum;\r
+\r
+    public StringTable (String phase) {\r
+        this.phase = phase;\r
+        al = new ArrayList<String>();\r
+                               alComments = new ArrayList<String>();\r
+        len = 0;\r
+                               bodyStart = 0;\r
+                               bodyLineNum = 0;\r
+    }\r
+\r
+    public String getSizeMacro () {\r
+        return String.format(PcdDatabase.StringTableSizeMacro, phase, getSize());\r
+    }\r
+\r
+    private int getSize () {\r
+                               //\r
+                               // We have at least one Unicode Character in the table.\r
+                               //\r
+        return len == 0 ? 1 : len;\r
+    }\r
+\r
+               public int getTableLen () {\r
+                               return al.size() == 0 ? 1 : al.size();\r
+               }\r
+\r
+    public String getExistanceMacro () {\r
+        return String.format(PcdDatabase.StringTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
+    }\r
+\r
+    public String getTypeDeclaration () {\r
+\r
+                               String output;\r
+\r
+                               final String stringTable = "StringTable";\r
+                               final String tab = "\t";\r
+                               final String newLine = ";\r\n";\r
+\r
+                               output =  "/* StringTable */\r\n";\r
+\r
+                               if (al.size() == 0) {\r
+                                               output += tab + String.format("UINT16 %s[1] /* StringTable is Empty */", stringTable) + newLine;\r
+                               }\r
+\r
+                               for (int i = 0; i < al.size(); i++) {\r
+                                               String str = al.get(i);\r
+\r
+                                               if (i == 0) {\r
+                                                               //\r
+                                                               // StringTable is a well-known name in the PCD DXE driver\r
+                                                               //\r
+                                                               output += tab + String.format("UINT16                   %s[%d] /* %s */", stringTable, str.length() + 1, alComments.get(i)) + newLine;\r
+                                               } else {\r
+                                                               output += tab + String.format("UINT16                   %s_%d[%d] /* %s */", stringTable, i, str.length() + 1, alComments.get(i)) + newLine;\r
+                                               }\r
+                               }\r
+\r
+                               return output;\r
+\r
+    }\r
+\r
+    public ArrayList<String> getInstantiation () {\r
+                               ArrayList<String> output = new ArrayList<String>();\r
+\r
+                               output.add("/* StringTable */"); \r
+\r
+                               if (al.size() == 0) {\r
+                                               output.add("{ 0 }");\r
+                               } else {\r
+                                               String str;\r
+\r
+                                               for (int i = 0; i < al.size(); i++) {\r
+                                                               str = String.format("L\"%s\" /* %s */", al.get(i), alComments.get(i));\r
+                                                               if (i != al.size() - 1) {\r
+                                                                               str += ",";\r
+                                                               }\r
+                                                               output.add(str);\r
+                                               }\r
+                               }\r
+\r
+        return output;\r
+    }\r
+\r
+    public int add (String str, Token token) {\r
+        int i;\r
+\r
+        i = len;\r
+        //\r
+        // Include the NULL character at the end of String\r
+        //\r
+        len += str.length() + 1; \r
+        al.add(str);\r
+                               alComments.add(token.getPrimaryKeyString());\r
+\r
+        return i;\r
+    }\r
+}\r
+\r
+class SizeTable {\r
+    private ArrayList<Integer>  al;\r
+               private ArrayList<String>   alComments;\r
+    private String              phase;\r
+    private int                 len;\r
+               private int                                                     bodyStart;\r
+               private int                                                     bodyLineNum;\r
+\r
+    public SizeTable (String phase) {\r
+        this.phase = phase;\r
+        al = new ArrayList<Integer>();\r
+                               alComments = new ArrayList<String>();\r
+        len = 0;\r
+                               bodyStart = 0;\r
+                               bodyLineNum = 0;\r
+    }\r
+\r
+    public String getTypeDeclaration () {\r
+        return String.format(PcdDatabase.SizeTableDeclaration, phase);\r
+    }\r
+\r
+    public ArrayList<String> getInstantiation () {\r
+                               ArrayList<String> Output = new ArrayList<String>();\r
+\r
+        Output.add("/* SizeTable */");\r
+        Output.add("{");\r
+                               bodyStart = 2;\r
+\r
+                               if (al.size() == 0) {\r
+                                               Output.add("0");\r
+                               } else {\r
+                                               for (int index = 0; index < al.size(); index++) {\r
+                                                               Integer n = al.get(index);\r
+                                                               String str = n.toString();\r
+\r
+                                                               if (index != (al.size() - 1)) {\r
+                                                                               str += ",";\r
+                                                               }\r
+\r
+                                                               str += " /* " + alComments.get(index) + " */"; \r
+                                                               Output.add(str);\r
+                                                               bodyLineNum++;\r
+               \r
+                                               }\r
+                               }\r
+                               Output.add("}");\r
+\r
+        return Output;\r
+    }\r
+\r
+               public int getBodyStart() {\r
+                               return bodyStart;\r
+               }\r
+\r
+               public int getBodyLineNum () {\r
+                               return bodyLineNum;\r
+               }\r
+\r
+    public int add (Token token) {\r
+        int index = len;\r
+\r
+        len++; \r
+        al.add(token.datumSize);\r
+                               alComments.add(token.getPrimaryKeyString());\r
+\r
+        return index;\r
+    }\r
+\r
+               private int getDatumSize(Token token) {\r
+                               /*\r
+                               switch (token.datumType) {\r
+                               case Token.DATUM_TYPE.UINT8:\r
+                                               return 1;\r
+                               default:\r
+                                               return 0;\r
+                               }\r
+                               */\r
+                               return 0;\r
+               }\r
+\r
+               public int getTableLen () {\r
+                               return al.size() == 0 ? 1 : al.size();\r
+               }\r
+\r
+}\r
+\r
+class GuidTable {\r
+    private ArrayList<UUID> al;\r
+               private ArrayList<String> alComments;\r
+    private String          phase;\r
+    private int             len;\r
+               private int                                                     bodyStart;\r
+               private int                                                     bodyLineNum;\r
+\r
+    public GuidTable (String phase) {\r
+        this.phase = phase;\r
+        al = new ArrayList<UUID>();\r
+                               alComments = new ArrayList<String>();\r
+        len = 0;\r
+                               bodyStart = 0;\r
+                               bodyLineNum = 0;\r
+    }\r
+\r
+    public String getSizeMacro () {\r
+        return String.format(PcdDatabase.GuidTableSizeMacro, phase, getSize());\r
+    }\r
+\r
+    private int getSize () {\r
+        return (al.size() == 0)? 1 : al.size();\r
+    }\r
+\r
+    public String getExistanceMacro () {\r
+        return String.format(PcdDatabase.GuidTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
+    }\r
+\r
+    public String getTypeDeclaration () {\r
+        return String.format(PcdDatabase.GuidTableDeclaration, phase);\r
+    }\r
+\r
+               private String getUuidCString (UUID uuid) {\r
+                               String[]  guidStrArray;\r
+\r
+                               guidStrArray =(uuid.toString()).split("-");\r
+\r
+                               return 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
+                                                                                                                                                                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
+    public ArrayList<String> getInstantiation () {\r
+                               ArrayList<String> Output = new ArrayList<String>();\r
+\r
+        Output.add("/* GuidTable */");\r
+        Output.add("{");\r
+                               bodyStart = 2;\r
+\r
+                               if (al.size() == 0) {\r
+                                               Output.add(getUuidCString(new UUID(0, 0)));\r
+                               }\r
+        \r
+        for (Object u : al) {\r
+            UUID uuid = (UUID)u;\r
+                                               String str = getUuidCString(uuid);\r
+\r
+                                               if (al.indexOf(u) != (al.size() - 1)) {\r
+                                                               str += ",";\r
+                                               }\r
+            Output.add(str);\r
+                                               bodyLineNum++;\r
+\r
+        }\r
+                               Output.add("}");\r
+\r
+        return Output;\r
+    }\r
+\r
+               public int getBodyStart() {\r
+                               return bodyStart;\r
+               }\r
+\r
+               public int getBodyLineNum () {\r
+                               return bodyLineNum;\r
+               }\r
+\r
+    public int add (UUID uuid, String name) {\r
+        int index = len;\r
+        //\r
+        // Include the NULL character at the end of String\r
+        //\r
+        len++; \r
+        al.add(uuid);\r
+\r
+        return index;\r
+    }\r
+\r
+               public int getTableLen () {\r
+                               return al.size() == 0 ? 0 : al.size();\r
+               }\r
+\r
+}\r
+\r
+class SkuIdTable {\r
+    private ArrayList<Integer[]> al;\r
+               private ArrayList<String>    alComment;\r
+    private String               phase;\r
+    private int                  len;\r
+               private int                                                                             bodyStart;\r
+               private int                                                                             bodyLineNum;\r
+\r
+    public SkuIdTable (String phase) {\r
+        this.phase = phase;\r
+        al = new ArrayList<Integer[]>();\r
+                               alComment = new ArrayList<String>();\r
+                               bodyStart = 0;\r
+                               bodyLineNum = 0;\r
+        len = 0;\r
+    }\r
+\r
+    public String getSizeMacro () {\r
+        return String.format(PcdDatabase.SkuIdTableSizeMacro, phase, getSize());\r
+    }\r
+\r
+    private int getSize () {\r
+        return (al.size() == 0)? 1 : al.size();\r
+    }\r
+\r
+    public String getExistanceMacro () {\r
+        return String.format(PcdDatabase.SkuTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
+    }\r
+\r
+    public String getTypeDeclaration () {\r
+        return String.format(PcdDatabase.SkuIdTableDeclaration, phase);\r
+    }\r
+\r
+    public ArrayList<String> getInstantiation () {\r
+                               ArrayList<String> Output = new ArrayList<String> ();\r
+\r
+        Output.add("/* SkuIdTable */");\r
+        Output.add("{");\r
+                               bodyStart = 2;\r
+\r
+                               if (al.size() == 0) {\r
+                                               Output.add("0");\r
+                               }\r
+        \r
+        for (int index = 0; index < al.size(); index++) {\r
+                                               String str;\r
+\r
+                                               str = "/* " + alComment.get(index) + "*/ ";\r
+                                               str += "/* MaxSku */ ";\r
+\r
+\r
+                                               Integer[] ia = al.get(index);\r
+\r
+                                               str += ia[0].toString() + ", ";\r
+                                               for (int index2 = 1; index2 < ia.length; index2++) {\r
+                                                        str += ia[index2].toString();\r
+                                                        if (index != al.size() - 1) {\r
+                                                                        str += ", ";\r
+                                                        }\r
+                                               }\r
+\r
+            Output.add(str);\r
+                                               bodyLineNum++;\r
+\r
+        }\r
+\r
+                               Output.add("}");\r
+\r
+        return Output;\r
+    }\r
+\r
+    public int add (Token token) {\r
+\r
+                               int index;\r
+\r
+                               Integer [] skuIds = new Integer[token.maxSkuCount + 1];\r
+                               skuIds[0] = new Integer(token.maxSkuCount);\r
+                               for (index = 1; index < skuIds.length; index++) {\r
+                                               skuIds[index] = new Integer(token.skuData.get(index - 1).id);\r
+                               }\r
+\r
+        index = len;\r
+\r
+        len += skuIds.length; \r
+        al.add(skuIds);\r
+                               alComment.add(token.getPrimaryKeyString());\r
+\r
+        return index;\r
+    }\r
+\r
+               public int getTableLen () {\r
+                               return al.size() == 0 ? 1 : al.size();\r
+               }\r
+\r
+}\r
+\r
+class LocalTokenNumberTable {\r
+    private ArrayList<String>    al;\r
+               private ArrayList<String>    alComment;\r
+    private String               phase;\r
+    private int                  len;\r
+               private int                                                                     bodyStart;\r
+               private int                                                                             bodyLineNum;\r
+\r
+    public LocalTokenNumberTable (String phase) {\r
+        this.phase = phase;\r
+        al = new ArrayList<String>();\r
+                               alComment = new ArrayList<String>();\r
+                               bodyStart = 0;\r
+                               bodyLineNum = 0;\r
+\r
+        len = 0;\r
+    }\r
+\r
+    public String getSizeMacro () {\r
+        return String.format(PcdDatabase.LocalTokenNumberTableSizeMacro, phase, getSize());\r
+    }\r
+\r
+    public int getSize () {\r
+        return (al.size() == 0)? 1 : al.size();\r
+    }\r
+\r
+    public String getExistanceMacro () {\r
+        return String.format(PcdDatabase.DatabaseExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
+    }\r
+\r
+    public String getTypeDeclaration () {\r
+        return String.format(PcdDatabase.LocalTokenNumberTableDeclaration, phase);\r
+    }\r
+\r
+    public ArrayList<String> getInstantiation () {\r
+                               ArrayList<String> output = new ArrayList<String>();\r
+\r
+        output.add("/* LocalTokenNumberTable */");\r
+        output.add("{");\r
+                               bodyStart = 2;\r
+\r
+                               if (al.size() == 0) {\r
+                                               output.add("0");\r
+                               }\r
+        \r
+        for (int index = 0; index < al.size(); index++) {\r
+                                               String str;\r
+\r
+                                               str = (String)al.get(index);\r
+\r
+                                               str += " /* " + alComment.get(index) + " */ ";\r
+\r
+\r
+                                               if (index != (al.size() - 1)) {\r
+                                                               str += ",";\r
+                                               }\r
+\r
+            output.add(str);\r
+\r
+        }\r
+\r
+                               bodyLineNum = al.size();\r
+\r
+                               output.add("}");\r
+\r
+        return output;\r
+    }\r
+\r
+    public int add (Token token) {\r
+        int index = len;\r
+                               String str;\r
+\r
+        len++; \r
+\r
+                               str =  String.format(PcdDatabase.offsetOfStrTemplate, phase, token.hasDefaultValue() ? "Init" : "Uninit", token.getPrimaryKeyString());\r
+\r
+                               if (token.isStringType()) {\r
+                                               str += " | PCD_TYPE_STRING";\r
+                               }\r
+\r
+                               if (token.skuEnabled) {\r
+                                               str += " | PCD_TYPE_SKU_ENABLED";\r
+                               }\r
+\r
+                               if (token.hiiEnabled) {\r
+                                               str += " | PCD_TYPE_HII";\r
+                               }\r
+\r
+                               if (token.vpdEnabled) {\r
+                                               str += " | PCD_TYPE_VPD";\r
+                               }\r
+                               \r
+        al.add(str);\r
+                               alComment.add(token.getPrimaryKeyString());\r
+\r
+        return index;\r
+    }\r
+}\r
+\r
+class ExMapTable {\r
+\r
+               class ExTriplet {\r
+                               public Integer guidTableIdx;\r
+                               public Long exTokenNumber;\r
+                               public Long localTokenIdx;\r
+               \r
+                               public ExTriplet (int guidTableIdx, long exTokenNumber, long localTokenIdx) {\r
+                                               this.guidTableIdx = new Integer(guidTableIdx);\r
+                                               this.exTokenNumber = new Long(exTokenNumber);\r
+                                               this.localTokenIdx = new Long(localTokenIdx);\r
+                               }\r
+               }\r
+\r
+    private ArrayList<ExTriplet> al;\r
+               private ArrayList<String>    alComment;\r
+    private String               phase;\r
+    private int                  len;\r
+               private int                                                                             bodyStart;\r
+               private int                                                                             bodyLineNum;\r
+               private int                                                                             base;\r
+\r
+    public ExMapTable (String phase) {\r
+        this.phase = phase;\r
+        al = new ArrayList<ExTriplet>();\r
+                               alComment = new ArrayList<String>();\r
+                               bodyStart = 0;\r
+                               bodyLineNum = 0;\r
+        len = 0;\r
+    }\r
+\r
+    public String getSizeMacro () {\r
+        return String.format(PcdDatabase.ExMapTableSizeMacro, phase, getTableLen())\r
+                                                + String.format(PcdDatabase.ExTokenNumber, phase, al.size());\r
+    }\r
+\r
+    private int getSize () {\r
+        return (al.size() == 0)? 1 : al.size();\r
+    }\r
+\r
+    public String getExistanceMacro () {\r
+        return String.format(PcdDatabase.ExMapTableExistenceMacro, phase, (al.size() == 0)? "TRUE":"FALSE");\r
+    }\r
+\r
+    public String getTypeDeclaration () {\r
+        return String.format(PcdDatabase.ExMapTableDeclaration, phase);\r
+    }\r
+\r
+    public ArrayList<String> getInstantiation () {\r
+                               ArrayList<String> Output = new ArrayList<String>();\r
+\r
+        Output.add("/* ExMapTable */");\r
+        Output.add("{");\r
+                               bodyStart = 2;\r
+\r
+                               if (al.size() == 0) {\r
+                                               Output.add("{0, 0, 0}");\r
+                               }\r
+        \r
+                               int index;\r
+        for (index = 0; index < al.size(); index++) {\r
+                                               String str;\r
+\r
+                                               ExTriplet e = (ExTriplet)al.get(index);\r
+\r
+                                               str = "{ " + e.exTokenNumber.toString() + ", ";\r
+                                               str += e.localTokenIdx.toString() + ", ";\r
+                                               str += e.guidTableIdx.toString();\r
+\r
+                                               str += " /* " + alComment.get(index) + " */";\r
+\r
+                                               if (index != al.size() - 1) {\r
+                                                               str += ",";\r
+                                               }\r
+\r
+            Output.add(str);\r
+                                               bodyLineNum++;\r
+\r
+        }\r
+\r
+                               Output.add("}");\r
+\r
+        return Output;\r
+    }\r
+\r
+    public int add (int localTokenIdx, long exTokenNum, int guidTableIdx, String name) {\r
+        int index = len;\r
+\r
+        len++; \r
+        al.add(new ExTriplet(guidTableIdx, exTokenNum, localTokenIdx));\r
+                               alComment.add(name);\r
+\r
+        return index;\r
+    }\r
+\r
+               public int getTableLen () {\r
+                               return al.size() == 0 ? 1 : al.size();\r
+               }\r
+\r
+}\r
+\r
+class PcdDatabase {\r
+\r
+    public final static String ExMapTableDeclaration            = "DYNAMICEX_MAPPING ExMapTable[%s_EXMAPPING_TABLE_SIZE];\r\n";\r
+    public final static String GuidTableDeclaration             = "EFI_GUID          GuidTable[%s_GUID_TABLE_SIZE];\r\n";\r
+    public final static String LocalTokenNumberTableDeclaration = "UINT32            LocalTokenNumberTable[%s_LOCAL_TOKEN_NUMBER];\r\n";\r
+    public final static String StringTableDeclaration           = "UINT16            StringTable[%s_STRING_TABLE_SIZE];\r\n";\r
+    public final static String SizeTableDeclaration             = "UINT16            SizeTable[%s_LOCAL_TOKEN_NUMBER];\r\n";\r
+    public final static String SkuIdTableDeclaration              = "UINT8             SkuIdTable[%s_SKUID_TABLE_SIZE];\r\n";\r
+\r
+\r
+    public final static String ExMapTableSizeMacro              = "#define %s_EXMAPPING_TABLE_SIZE  %d\r\n";\r
+               public final static String ExTokenNumber                                                                                = "#define %s_EX_TOKEN_NUMBER                           %d\r\n";\r
+    public final static String GuidTableSizeMacro               = "#define %s_GUID_TABLE_SIZE         %d\r\n";\r
+    public final static String LocalTokenNumberTableSizeMacro   = "#define %s_LOCAL_TOKEN_NUMBER            %d\r\n";\r
+    public final static String StringTableSizeMacro             = "#define %s_STRING_TABLE_SIZE       %d\r\n";\r
+    public final static String SkuIdTableSizeMacro              = "#define %s_SKUID_TABLE_SIZE        %d\r\n";\r
+\r
+\r
+    public final static String ExMapTableExistenceMacro         = "#define %s_EXMAP_TABLE_EMPTY    %s\r\n"; \r
+    public final static String GuidTableExistenceMacro          = "#define %s_GUID_TABLE_EMPTY     %s\r\n";\r
+    public final static String DatabaseExistenceMacro           = "#define %s_DATABASE_EMPTY       %s\r\n";\r
+    public final static String StringTableExistenceMacro        = "#define %s_STRING_TABLE_EMPTY   %s\r\n";\r
+    public final static String SkuTableExistenceMacro           = "#define %s_SKUID_TABLE_EMPTY    %s\r\n";\r
+\r
+               public final static String offsetOfSkuHeadStrTemplate                   = "offsetof(%s_PCD_DATABASE, %s.%s_SkuDataTable)";\r
+               public final static String offsetOfStrTemplate              = "offsetof(%s_PCD_DATABASE, %s.%s)";\r
+\r
+               private StringTable stringTable;\r
+               private GuidTable               guidTable;\r
+               private LocalTokenNumberTable localTokenNumberTable;\r
+               private SkuIdTable      skuIdTable;\r
+               private SizeTable   sizeTable;\r
+               private ExMapTable  exMapTable;\r
+\r
+               private ArrayList<Token> alTokens;\r
+               private String phase;\r
+               private int assignedTokenNumber;\r
+\r
+               private String hString;\r
+               private String cString;\r
+\r
+\r
+               class AlignmentSizeComp implements Comparator<Token> {\r
+        public int compare (Token a, Token b) {\r
+                                               return getAlignmentSize(b) \r
+                                                                               - getAlignmentSize(a);\r
+                               }\r
+               }\r
+\r
+               public PcdDatabase (ArrayList<Token> alTokens, String exePhase, int startLen) {\r
+                        phase = exePhase;\r
+\r
+                        stringTable = new StringTable(phase);\r
+                        guidTable = new GuidTable(phase);\r
+                        localTokenNumberTable = new LocalTokenNumberTable(phase);\r
+                        skuIdTable = new SkuIdTable(phase);\r
+                        sizeTable = new SizeTable(phase);\r
+                        exMapTable = new ExMapTable(phase); \r
+\r
+                        assignedTokenNumber = startLen;\r
+                        this.alTokens = alTokens;\r
+               }\r
+\r
+               private void getTwoGroupsOfTokens (ArrayList<Token> alTokens, List<Token> initTokens, List<Token> uninitTokens) {\r
+                               for (int i = 0; i < alTokens.size(); i++) {\r
+                                               Token t = (Token)alTokens.get(i);\r
+                                               if (t.hasDefaultValue()) {\r
+                                                               initTokens.add(t);\r
+                                               } else {\r
+                                                               uninitTokens.add(t);\r
+                                               }\r
+                               }\r
+\r
+                               return;\r
+               }\r
+\r
+               private int getAlignmentSize (Token token) {\r
+                               if (token.hiiEnabled) {\r
+                                               return 2;\r
+                               }\r
+\r
+                               if (token.vpdEnabled) {\r
+                                               return 4;\r
+                               }\r
+\r
+                               if (token.isStringType()) {\r
+                                               return 2;\r
+                               }\r
+\r
+                               switch (token.datumType) {\r
+                                               case UINT8:\r
+                                                               return 1;\r
+                                               case UINT16:\r
+                                                               return 2;\r
+                                               case UINT32:\r
+                                                               return 4;\r
+                                               case UINT64:\r
+                                                               return 8;\r
+                                               case POINTER:\r
+                                                               return 1;\r
+                                               case BOOLEAN:\r
+                                                               return 1;\r
+                                               }\r
+                                               return 1;\r
+                }\r
+\r
+               public String getCString () {\r
+                               return cString;\r
+               }\r
+\r
+               public String getHString () {\r
+                               return hString;\r
+               }\r
+\r
+     public void genCode () {\r
+\r
+                               final String newLine                        = "\r\n";\r
+                               final String instNewLine                                                                                = "\\\r\n";\r
+                               final String declNewLine                    = ";\r\n";\r
+                               final String tab                            = "\t";\r
+                               final String commaInstNewLine                                                                           = "\t,\\\r\n";\r
+                               final String commaNewLine                                                                               = ", \r\n";\r
+\r
+                               int i;\r
+                               ArrayList<String> decla;\r
+                               ArrayList<String> inst;\r
+\r
+                               String macroStr   = "";\r
+                               String initDeclStr = "";\r
+                               String initInstStr = "";\r
+                               String uninitDeclStr = "";\r
+\r
+                               List<Token> initTokens = new ArrayList<Token> ();\r
+                               List<Token> uninitTokens = new ArrayList<Token> ();\r
+                               \r
+                               HashMap <String, ArrayList<String>> initCode = new HashMap<String, ArrayList<String>> ();\r
+                               HashMap <String, ArrayList<String>> uninitCode = new HashMap<String, ArrayList<String>> ();\r
+\r
+                               getTwoGroupsOfTokens (alTokens, initTokens, uninitTokens);\r
+\r
+                               //\r
+                               // Generate Structure Declaration for PcdTokens without Default Value\r
+                               // PEI_PCD_DATABASE_INIT\r
+                               //\r
+                               java.util.Comparator comparator = new AlignmentSizeComp();\r
+                               List<Token> list = initTokens;\r
+                               java.util.Collections.sort(list, comparator);\r
+                               initCode = processTokens(initTokens);\r
+\r
+                               //\r
+                               // Generate Structure Declaration for PcdTokens without Default Value\r
+                               // PEI_PCD_DATABASE_UNINIT\r
+                               //\r
+                               java.util.Collections.sort(uninitTokens, comparator);\r
+                               uninitCode = processTokens(uninitTokens);\r
+\r
+                               //\r
+                               // Generate size info Macro for all Tables\r
+                               //\r
+                               macroStr += guidTable.getSizeMacro();\r
+                               macroStr += stringTable.getSizeMacro();\r
+                               macroStr += skuIdTable.getSizeMacro();\r
+                               macroStr += localTokenNumberTable.getSizeMacro();\r
+                               macroStr += exMapTable.getSizeMacro();\r
+\r
+                               //\r
+                               // Generate existance info Macro for all Tables\r
+                               //\r
+                         macroStr += guidTable.getExistanceMacro();\r
+                               macroStr += stringTable.getExistanceMacro();\r
+                               macroStr += skuIdTable.getExistanceMacro();\r
+                               macroStr += localTokenNumberTable.getExistanceMacro();\r
+                               macroStr += exMapTable.getExistanceMacro();\r
+\r
+                               //\r
+                               // Generate Structure Declaration for PcdTokens with Default Value\r
+                               // for example PEI_PCD_DATABASE_INIT\r
+                               //\r
+                               initDeclStr += "typedef struct {" + newLine;\r
+                                               {\r
+                                                               initDeclStr += tab + exMapTable.getTypeDeclaration();\r
+                                                               initDeclStr += tab + guidTable.getTypeDeclaration();\r
+                                                               initDeclStr += tab + localTokenNumberTable.getTypeDeclaration();\r
+                                                               initDeclStr += tab + stringTable.getTypeDeclaration();\r
+                                                               initDeclStr += tab + sizeTable.getTypeDeclaration();\r
+                                                               initDeclStr += tab + skuIdTable.getTypeDeclaration();\r
+                                                               if (phase.equalsIgnoreCase("PEI")) {\r
+                                                                               initDeclStr += tab + "SKU_ID            SystemSkuId;" + newLine;\r
+                                                               }\r
+\r
+                                                               decla = initCode.get(new String("Declaration"));\r
+                                                               for (i = 0; i < decla.size(); i++)  {\r
+                                                                               initDeclStr += tab + decla.get(i) + declNewLine;\r
+                                                               }\r
+\r
+                                                               //\r
+                                                               // Generate Structure Declaration for PcdToken with SkuEnabled\r
+                                                               //\r
+                                                               decla = initCode.get("DeclarationForSku");\r
+\r
+                                                               for (i = 0; i < decla.size(); i++) {\r
+                                                                               initDeclStr += tab + decla.get(i) + declNewLine;\r
+                                                               }\r
+                                               }\r
+                         initDeclStr += String.format("} %s_PCD_DATABASE_INIT;\r\n\r\n", phase);\r
+\r
+                               //\r
+                               // Generate MACRO for structure intialization of PCDTokens with Default Value\r
+                               // The sequence must match the sequence of declaration of the memembers in the structure\r
+                               String tmp = String.format("%s_PCD_DATABASE_INIT g%sPcdDbInit = { ", phase.toUpperCase(), phase.toUpperCase());\r
+                               initInstStr +=  tmp + newLine;\r
+                               initInstStr += tab + genInstantiationStr(exMapTable.getInstantiation()) + commaNewLine;\r
+                               initInstStr += tab + genInstantiationStr(guidTable.getInstantiation()) + commaNewLine;\r
+                               initInstStr += tab + genInstantiationStr(localTokenNumberTable.getInstantiation()) + commaNewLine; \r
+                               /*\r
+                               inst = stringTable.getInstantiation();\r
+                               for (i = 0; i < inst.size(); i++ ) {\r
+                                               initInstStr += tab + inst.get(i) + commaNewLine; \r
+                               }\r
+                               */\r
+                               initInstStr += tab + genInstantiationStr(stringTable.getInstantiation()) + commaNewLine;\r
+                               initInstStr += tab + genInstantiationStr(sizeTable.getInstantiation()) + commaNewLine;\r
+                               initInstStr += tab + genInstantiationStr(skuIdTable.getInstantiation()) + commaNewLine;\r
+                               //\r
+                               // For SystemSkuId\r
+                               //\r
+                               if (phase.equalsIgnoreCase("PEI")) {\r
+                                               initInstStr += tab + "0" + tab + "/* SystemSkuId */" + commaNewLine;\r
+                               }\r
+\r
+                               inst = initCode.get("Instantiation");\r
+                               for (i = 0; i < inst.size(); i++) {\r
+                                               initInstStr += tab + inst.get(i) + commaNewLine;\r
+                               }\r
+\r
+                               inst = initCode.get("InstantiationForSku");\r
+                               for (i = 0; i < inst.size(); i++) {\r
+                                               initInstStr += tab + inst.get(i);\r
+                                               if (i != inst.size() - 1) {\r
+                                                               initInstStr += commaNewLine;\r
+                                               }\r
+                               }\r
+\r
+                               initInstStr += "};";\r
+\r
+                               uninitDeclStr += "typedef struct {" + newLine;\r
+                                               {\r
+                                                               decla = uninitCode.get("Declaration");\r
+                                                               if (decla.size() == 0) {\r
+                                                                               uninitDeclStr += "UINT8 dummy /* The UINT struct is empty */" + declNewLine;\r
+                                                               } else {\r
+               \r
+                                                                               for (i = 0; i < decla.size(); i++) {\r
+                                                                                               uninitDeclStr += tab + decla.get(i) + declNewLine;\r
+                                                                               }\r
+               \r
+                                                                               decla = uninitCode.get("DeclarationForSku");\r
+               \r
+                                                                               for (i = 0; i < decla.size(); i++) {\r
+                                                                                               uninitDeclStr += tab + decla.get(i) + declNewLine;\r
+                                                                               }\r
+                                                               }\r
+                                               }\r
+                               uninitDeclStr += String.format("} %s_PCD_DATABASE_UNINIT;\r\n\r\n", phase);\r
+\r
+                               cString = initInstStr + newLine;\r
+                               hString = macroStr      + newLine  \r
+                                                 + initDeclStr         + newLine\r
+                                                       + uninitDeclStr + newLine\r
+                                                 + newLine;\r
+\r
+               }\r
+\r
+               private String genInstantiationStr (ArrayList<String> alStr) {\r
+                               String str = "";\r
+                               for (int i = 0; i< alStr.size(); i++) {\r
+                                               str += "\t" + alStr.get(i);\r
+                                               if (i != alStr.size() - 1) {\r
+                                                               str += "\r\n";\r
+                                               }\r
+                               }\r
+\r
+                               return str;\r
+               }\r
+\r
+               private HashMap<String, ArrayList<String>> processTokens (List<Token> alToken) {\r
+\r
+                               ArrayList[]  output = new ArrayList[4];\r
+                               HashMap <String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();\r
+\r
+                               ArrayList<String> decl = new ArrayList<String>();\r
+                               ArrayList<String> declForSkuEnableType = new ArrayList<String>();\r
+                               ArrayList<String> inst = new ArrayList<String>();\r
+                               ArrayList<String> instForSkuEnableType = new ArrayList<String>();\r
+\r
+                               for (int index = 0; index < alToken.size(); index++) {\r
+                                               Token token = alToken.get(index);\r
+\r
+                                               if (token.skuEnabled) {\r
+                                                               //\r
+                                                               // BugBug: Schema only support Data type now\r
+                                                               //\r
+                                                               int tableIdx;\r
+\r
+                                                               tableIdx = skuIdTable.add(token);\r
+\r
+                                                               decl.add(getSkuEnabledTypeDeclaration(token));\r
+                                                               if (token.hasDefaultValue()) {\r
+                                                                               inst.add(getSkuEnabledTypeInstantiaion(token, tableIdx)); \r
+                                                               }\r
+\r
+                                                               declForSkuEnableType.add(getDataTypeDeclarationForSkuEnabled(token));\r
+                                                               if (token.hasDefaultValue()) {\r
+                                                                               instForSkuEnableType.add(getDataTypeInstantiationForSkuEnabled(token));\r
+                                                               }\r
+\r
+                                               } else {\r
+                                                               if (token.hiiEnabled) {\r
+                                                                               decl.add(getVariableEnableTypeDeclaration(token));\r
+                                                                               inst.add(getVariableEnableInstantiation(token));\r
+                                                               } else if (token.vpdEnabled) {\r
+                                                                               decl.add(getVpdEnableTypeDeclaration(token));\r
+                                                                               inst.add(getVpdEnableTypeInstantiation(token));\r
+                                                               } else if (token.isStringType()) {\r
+                                                                               decl.add(getStringTypeDeclaration(token));\r
+                                                                               inst.add(getStringTypeInstantiation(stringTable.add(token.getStringTypeString(), token), token));\r
+                                                               }\r
+                                                               else {\r
+                                                                               decl.add(getDataTypeDeclaration(token));\r
+                                                                               if (token.hasDefaultValue()) {\r
+                                                                                               inst.add(getDataTypeInstantiation(token));\r
+                                                                               }\r
+                                                               }\r
+                                               }\r
+\r
+                                               sizeTable.add(token);\r
+                                               localTokenNumberTable.add(token);\r
+                                               token.assignedtokenNumber = assignedTokenNumber++;\r
+\r
+                               }\r
+\r
+                               map.put("Declaration",  decl);\r
+                               map.put("DeclarationForSku", declForSkuEnableType);\r
+                               map.put("Instantiation", inst);\r
+                               map.put("InstantiationForSku", instForSkuEnableType);\r
+\r
+                               return map;\r
+               }\r
+\r
+               private String getSkuEnabledTypeDeclaration (Token token) {\r
+                               return String.format("SKU_HEAD %s;\r\n", token.getPrimaryKeyString());\r
+               }\r
+\r
+               private String getSkuEnabledTypeInstantiaion (Token token, int SkuTableIdx) {\r
+\r
+                               String offsetof = String.format(PcdDatabase.offsetOfSkuHeadStrTemplate, phase, token.hasDefaultValue()? "Init" : "Uninit", token.getPrimaryKeyString());\r
+                               return String.format("{ %s, %d }", offsetof, SkuTableIdx);\r
+               }\r
+\r
+               private String getDataTypeDeclarationForSkuEnabled (Token token) {\r
+                               String typeStr = "";\r
+\r
+                               if (token.datumType == Token.DATUM_TYPE.UINT8) {\r
+                                               typeStr = "UINT8 %s_%s[%d];\r\n";\r
+                               } else if (token.datumType == Token.DATUM_TYPE.UINT16) {\r
+                                               typeStr = "UINT16 %s_%s[%d];\r\n";\r
+                               } else if (token.datumType == Token.DATUM_TYPE.UINT32) {\r
+                                               typeStr = "UINT32 %s_%s[%d];\r\n";\r
+                               } else if (token.datumType == Token.DATUM_TYPE.UINT64) {\r
+                                               typeStr = "UINT64 %s_%s[%d];\r\n";\r
+                               } else if (token.datumType == Token.DATUM_TYPE.BOOLEAN) {\r
+                                               typeStr = "BOOLEAN %s_%s[%d];\r\n";\r
+                               } else if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
+                                               return String.format("UINT8 %s_s[%d];\r\n", token.getPrimaryKeyString(), "SkuDataTable", token.datumSize * token.maxSkuCount);\r
+                               } \r
+\r
+                               return String.format(typeStr, token.getPrimaryKeyString(), "SkuDataTable", token.maxSkuCount);\r
+\r
+               }\r
+\r
+               private String getDataTypeInstantiationForSkuEnabled (Token token) {\r
+                               String str = "";\r
+\r
+                               if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
+                                               return String.format("UINT8 %s_s[%d]", token.getPrimaryKeyString(), "SkuDataTable", token.datumSize * token.maxSkuCount);\r
+                               } else {\r
+                                               str = "{ ";\r
+                                               for (int idx = 0; idx < token.maxSkuCount; idx++) {\r
+                                                               str += token.skuData.get(idx).toString();\r
+                                                               if (idx != token.maxSkuCount - 1) {\r
+                                                                               str += ", ";\r
+                                                               }\r
+                                               }\r
+                                               str += "}";\r
+\r
+                                               return str;\r
+                               }\r
+\r
+               }\r
+\r
+               private String getDataTypeInstantiation (Token token) {\r
+\r
+                               String typeStr = "";\r
+\r
+                               if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
+                                               return String.format("%s /* %s */", token.datum.toString(), token.getPrimaryKeyString());\r
+                               } else {\r
+                                               return String.format("%s /* %s */", token.datum.toString(), token.getPrimaryKeyString());\r
+                               }\r
+               }\r
+\r
+\r
+               private String getDataTypeDeclaration (Token token) {\r
+\r
+                               String typeStr = "";\r
+\r
+                               if (token.datumType == Token.DATUM_TYPE.UINT8) {\r
+                                               typeStr = "UINT8";\r
+                               } else if (token.datumType == Token.DATUM_TYPE.UINT16) {\r
+                                               typeStr = "UINT16";\r
+                               } else if (token.datumType == Token.DATUM_TYPE.UINT32) {\r
+                                               typeStr = "UINT32";\r
+                               } else if (token.datumType == Token.DATUM_TYPE.UINT64) {\r
+                                               typeStr = "UINT64";\r
+                               } else if (token.datumType == Token.DATUM_TYPE.BOOLEAN) {\r
+                                               typeStr = "BOOLEAN";\r
+                               } else if (token.datumType == Token.DATUM_TYPE.POINTER) {\r
+                                               return String.format("UINT8 %s[%d]", token.getPrimaryKeyString(), token.datumSize);\r
+                               } else {\r
+                               }\r
+\r
+                               return String.format("%s                %s", typeStr, token.getPrimaryKeyString());\r
+               }\r
+\r
+               private String getVpdEnableTypeDeclaration (Token token) {\r
+                               return String.format("VPD_HEAD %s", token.getPrimaryKeyString());\r
+               }\r
+\r
+               private String getVpdEnableTypeInstantiation (Token token) {\r
+                               return String.format("{ %d } /* %s */", token.vpdOffset,\r
+                                                                                                                                                                                               token.getPrimaryKeyString());\r
+               }\r
+\r
+               private String getStringTypeDeclaration (Token token) {\r
+                               return String.format("UINT16    %s", token.getPrimaryKeyString());\r
+               }\r
+\r
+               private String getStringTypeInstantiation (int StringTableIdx, Token token) {\r
+                               return String.format ("%d /* %s */", StringTableIdx,\r
+                                                                                                                                                                                token.getPrimaryKeyString()); \r
+               }\r
+\r
+\r
+               private String getVariableEnableTypeDeclaration (Token token) {\r
+                       return String.format("VARIABLE_HEAD  %s", token.getPrimaryKeyString());\r
+               }\r
+\r
+               private String getVariableEnableInstantiation (Token token) {\r
+                               return String.format("{ %d, %d, %d } /* %s */", guidTable.add(token.variableGuid, token.getPrimaryKeyString()),\r
+                                                                                                                                                                                                                               stringTable.add(token.variableName, token),\r
+                                                                                                                                                                                                                               token.variableOffset, \r
+                                                                                                                                                                                                                               token.getPrimaryKeyString());\r
+               }\r
+\r
+               public int getTotalTokenNumber () {\r
+                               return sizeTable.getTableLen();\r
+               }\r
+\r
+    public static String getPcdDatabaseCommonDefinitions () \r
+        throws EntityException {\r
+\r
+        String retStr = "";\r
+        try {\r
+                                               File file = new File(GlobalData.getWorkspacePath() + File.separator + \r
+                                                                                                                                "Tools" + File.separator + \r
+                                                                                                                                "Conf" + File.separator +\r
+                                                                                                                                "Pcd" + File.separator +\r
+                                                                                                                                "PcdDatabaseCommonDefinitions.sample");\r
+                                               System.out.println(GlobalData.getWorkspacePath());\r
+            FileReader reader = new FileReader(file);\r
+            BufferedReader  in = new BufferedReader(reader);\r
+            String str;\r
+            while ((str = in.readLine()) != null) {\r
+                retStr = retStr +"\r\n" + str;\r
+            }\r
+        } catch (Exception ex) {\r
+            throw new EntityException("Fatal error when generating PcdDatabase Common Definitions");\r
+        }\r
+\r
+        return retStr;\r
+    }\r
+\r
+               public static String getPcdDxeDatabaseDefinitions () \r
+                               throws EntityException {\r
+\r
+                               String retStr = "";\r
+                               try {\r
+                                               File file = new File(GlobalData.getWorkspacePath() + File.separator + \r
+                                                                                                                                "Tools" + File.separator + \r
+                                                                                                                                "Conf" + File.separator +\r
+                                                                                                                                "Pcd" + File.separator +\r
+                                                                                                                                "PcdDatabaseDxeDefinitions.sample");\r
+                                               FileReader reader = new FileReader(file);\r
+                                               BufferedReader  in = new BufferedReader(reader);\r
+                                               String str;\r
+                                               while ((str = in.readLine()) != null) {\r
+                                                               retStr = retStr +"\r\n" + str;\r
+                                               }\r
+                               } catch (Exception ex) {\r
+                                               throw new EntityException("Fatal error when generating PcdDatabase Dxe Definitions");\r
+                               }\r
+\r
+                               return retStr;\r
+               }\r
+\r
+               public static String getPcdPeiDatabaseDefinitions () \r
+                               throws EntityException {\r
+\r
+                               String retStr = "";\r
+                               try {\r
+                                               File file = new File(GlobalData.getWorkspacePath() + File.separator + \r
+                                                                                                                                "Tools" + File.separator + \r
+                                                                                                                                "Conf" + File.separator +\r
+                                                                                                                                "Pcd" + File.separator +\r
+                                                                                                                                "PcdDatabasePeiDefinitions.sample");\r
+                                               FileReader reader = new FileReader(file);\r
+                                               BufferedReader  in = new BufferedReader(reader);\r
+                                               String str;\r
+                                               while ((str = in.readLine()) != null) {\r
+                                                               retStr = retStr +"\r\n" + str;\r
+                                               }\r
+                               } catch (Exception ex) {\r
+                                               throw new EntityException("Fatal error when generating PcdDatabase Pei Definitions");\r
+                               }\r
+\r
+                               return retStr;\r
+               }\r
+\r
+}\r
+\r
 /** This action class is to collect PCD information from MSA, SPD, FPD xml file.\r
     This class will be used for wizard and build tools, So it can *not* inherit\r
     from buildAction or UIAction.\r
@@ -120,6 +1255,10 @@ public class CollectPCDAction {
          for module who consume this library and create usage instance for library for building.\r
       4) Collect token's package information from SPD, update these information for token in memory\r
          database.\r
+      5) Generate 3 strings for a) All modules using Dynamic(Ex) PCD entry. (Token Number)\r
+                                b) PEI PCD Database (C Structure) for PCD Service PEIM\r
+                                c) DXE PCD Database (C structure) for PCD Service DXE\r
+                                \r
       \r
       @throws  EntityException Exception indicate failed to execute this action.\r
       \r
@@ -207,9 +1346,48 @@ public class CollectPCDAction {
                 }\r
             }\r
         }\r
+        \r
+        //\r
+        // Call Private function genPcdDatabaseSourceCode (void); ComponentTypeBsDriver\r
+        // 1) Generate for PEI, DXE PCD DATABASE's definition and initialization.\r
+                               //\r
+                               genPcdDatabaseSourceCode ();\r
+                               \r
     }\r
 \r
-    /**\r
+               /**\r
+                       This function generates source code for PCD Database.\r
+                \r
+                       @param void\r
+                       @throws EntityException  If the token does *not* exist in memory database.\r
+\r
+               **/\r
+\r
+    private void genPcdDatabaseSourceCode                      ()\r
+                       throws EntityException {\r
+                               String PcdCommonHeaderString = PcdDatabase.getPcdDatabaseCommonDefinitions ();\r
+\r
+                               ArrayList<Token> alPei = new ArrayList<Token> ();\r
+                               ArrayList<Token> alDxe = new ArrayList<Token> ();\r
+\r
+                               dbManager.getTwoPhaseDynamicRecordArray(alPei, alDxe);\r
+        PcdDatabase pcdPeiDatabase = new PcdDatabase (alPei, "PEI", 0);\r
+                               pcdPeiDatabase.genCode();\r
+                               dbManager.PcdPeimHString        = PcdCommonHeaderString + pcdPeiDatabase.getHString()\r
+                                                                                                                                                                               + PcdDatabase.getPcdPeiDatabaseDefinitions();\r
+                               dbManager.PcdPeimCString                                = pcdPeiDatabase.getCString();\r
+\r
+        PcdDatabase pcdDxeDatabase = new PcdDatabase (alDxe, \r
+                                                                                                                                                                                                                       "DXE",\r
+                                                                                                                                                                                                                       alPei.size()\r
+                                                                                                                                                                                                                       );\r
+                               pcdDxeDatabase.genCode();\r
+                               dbManager.PcdDxeHString   = dbManager.PcdPeimHString + pcdDxeDatabase.getHString()\r
+                                                                                                                                                       + PcdDatabase.getPcdDxeDatabaseDefinitions();\r
+                               dbManager.PcdDxeCString         = pcdDxeDatabase.getCString();\r
+               }\r
+\r
+               /**\r
       This function will collect inherit PCD information from library for a module.\r
      \r
       This function will create two usage instance for inherited PCD token, one is \r
@@ -501,6 +1679,7 @@ public class CollectPCDAction {
             token.assignedtokenNumber  = Integer.decode(pcdBuildData.getToken().getStringValue());\r
             skuDataArray               = pcdBuildData.getSkuDataArray1();\r
             token.datumType    = Token.getdatumTypeFromString(pcdBuildData.getDatumType().toString());\r
+                                               token.datumSize    = pcdBuildData.getDatumSize();\r
 \r
             if(skuDataArray != null) {\r
                 for(skuIndex = 0; skuIndex < skuDataArray.size(); skuIndex ++) {\r
index f3e5b17..3d1f1ba 100644 (file)
@@ -190,6 +190,14 @@ public class PCDAutoGenAction extends BuildAction {
             }\r
         }\r
 \r
+                               if (moduleName.equalsIgnoreCase("PcdPeim")) {\r
+                                               hAutoGenString += dbManager.PcdPeimHString;\r
+                                               cAutoGenString += dbManager.PcdPeimCString;\r
+                               } else if (moduleName.equalsIgnoreCase("PcdDxe")) {\r
+                                               hAutoGenString += dbManager.PcdDxeHString;\r
+                                               cAutoGenString += dbManager.PcdDxeCString;\r
+                               }\r
+\r
         ActionMessage.debug(this,\r
                             "Module " + moduleName + "'s PCD header file:\r\n" + hAutoGenString + "\r\n"\r
                            );\r
@@ -518,7 +526,9 @@ public class PCDAutoGenAction extends BuildAction {
       @param argv  paramter from command line\r
     **/\r
     public static void main(String argv[]) {\r
-        String logFilePath = "M:/tianocore/edk2/trunk/edk2/EdkNt32Pkg/Nt32.fpd";\r
+\r
+                               String WorkSpace = "G:/edk2";\r
+        String logFilePath = WorkSpace  + "/EdkNt32Pkg/Nt32.fpd";\r
 \r
         //\r
         // At first, CollectPCDAction should be invoked to collect\r
@@ -526,12 +536,12 @@ public class PCDAutoGenAction extends BuildAction {
         //\r
         CollectPCDAction collectionAction = new CollectPCDAction();\r
         GlobalData.initInfo("Tools" + File.separator + "Conf" + File.separator + "FrameworkDatabase.db",\r
-                            "M:/tianocore/edk2/trunk/edk2");\r
+                            WorkSpace);\r
 \r
         GlobalData.getPCDMemoryDBManager().setLogFileName(logFilePath + ".PCDMemroyDatabaseLog.txt");\r
 \r
         try {\r
-            collectionAction.perform("M:/tianocore/edk2/trunk/edk2"\r
+            collectionAction.perform(WorkSpace\r
                                      logFilePath,\r
                                      ActionMessage.MAX_MESSAGE_LEVEL);\r
         } catch(Exception e) {\r
@@ -541,10 +551,16 @@ public class PCDAutoGenAction extends BuildAction {
         //\r
         // Then execute the PCDAuotoGenAction to get generated Autogen.h and Autogen.c\r
         //\r
-        PCDAutoGenAction autogenAction = new PCDAutoGenAction("PcdEmulator",\r
-                                                              true\r
+        PCDAutoGenAction autogenAction = new PCDAutoGenAction("PcdDxe",\r
+                                                                                                                                                                                                                                                       false\r
                                                               );\r
-        autogenAction.execute();\r
+                               autogenAction.execute();\r
+\r
+                               System.out.println(autogenAction.OutputH());\r
+                               System.out.println("WQWQWQWQWQ");\r
+                               System.out.println(autogenAction.OutputC());\r
+\r
+\r
         System.out.println (autogenAction.hAutoGenString);\r
         System.out.println (autogenAction.cAutoGenString);\r
 \r
index 6f4f894..2c2433a 100644 (file)
@@ -20,13 +20,26 @@ import java.io.File;
 import java.io.FileWriter;\r
 import java.io.IOException;\r
 import java.util.ArrayList;\r
+import java.util.Collections;\r
+import java.util.Comparator;\r
 import java.util.HashMap;\r
+import java.util.Hashtable;\r
 import java.util.List;\r
 import java.util.Map;\r
 \r
 import org.tianocore.build.autogen.CommonDefinition;\r
 import org.tianocore.build.pcd.action.ActionMessage;\r
 \r
+class AlignmentSizeComp implements Comparator {\r
+    public int compare (Object a, Object b) {\r
+        Token tA = (Token) a;\r
+        Token tB = (Token) b;\r
+\r
+        return Token.getAutogendatumTypeAlignmentSize(tA.datumType) \r
+                - Token.getAutogendatumTypeAlignmentSize(tB.datumType);\r
+    }\r
+}\r
+\r
 /** Database hold all PCD information comes from SPD, MSA, FPD file in memory.\r
 **/\r
 public class MemoryDatabaseManager {\r
@@ -40,6 +53,11 @@ public class MemoryDatabaseManager {
     ///\r
     private static String              logFileName    = null;\r
 \r
+    public static String PcdPeimHString       = "";\r
+               public static String PcdPeimCString                             = "";\r
+    public static String PcdDxeHString                         = "";\r
+    public static String PcdDxeCString                         = "";\r
+\r
     /**\r
       Constructure function\r
     **/\r
@@ -135,7 +153,81 @@ public class MemoryDatabaseManager {
         return tokenArray;\r
     }\r
 \r
+\r
+    private ArrayList getDynamicRecordArray() {\r
+        Token[]     tokenArray  =   getRecordArray();\r
+        int         index       =   0;\r
+        int         count       =   0;\r
+        ArrayList   al          =   new ArrayList();\r
+\r
+        for (index = 0; index < tokenArray.length; index++) {\r
+            if (tokenArray[index].pcdType == Token.PCD_TYPE.DYNAMIC ||\r
+                tokenArray[index].pcdType == Token.PCD_TYPE.DYNAMIC_EX) {\r
+                al.add(tokenArray[index]);\r
+            }\r
+        }\r
+\r
+        return al;\r
+    }\r
+\r
+\r
     /**\r
+      Get the token record array contained all PCD token referenced by PEI phase.\r
+          The output array is sorted based on descending order of the size of alignment for each feilds.\r
+\r
+      @return the token record array contained all PCD token referenced in PEI phase.\r
+    **/\r
+    public void getTwoPhaseDynamicRecordArray(ArrayList<Token> pei, ArrayList<Token> dxe) {\r
+        int                     usageInstanceIndex  =   0;\r
+        int                     index               =   0;\r
+        ArrayList               tokenArrayList      =   getDynamicRecordArray();\r
+        List<UsageInstance>     usageInstanceArray  =   null;\r
+        UsageInstance           usageInstance       =   null;\r
+\r
+                               //pei = new ArrayList<Token>();\r
+                               //dxe = new ArrayList<Token>();\r
+\r
+        for (index = 0; index < tokenArrayList.size(); index++) {\r
+            boolean found   =   false;\r
+            Token       token = (Token) tokenArrayList.get(index);\r
+            if (token.producers != null) {\r
+                usageInstanceArray = token.producers;\r
+                for (usageInstanceIndex = 0; usageInstanceIndex < usageInstanceArray.size(); usageInstanceIndex++) {\r
+                    usageInstance = (UsageInstance) usageInstanceArray.get(usageInstanceIndex);\r
+                    if (CommonDefinition.isPeiPhaseComponent(usageInstance.componentType)) {\r
+                        pei.add(token);\r
+                        found = true;\r
+                        break;\r
+                    }\r
+                }\r
+\r
+            }\r
+            if (!found) {\r
+                if (token.consumers != null) {\r
+                    usageInstanceArray = token.consumers;\r
+                    for (usageInstanceIndex = 0; usageInstanceIndex < usageInstanceArray.size(); usageInstanceIndex ++) {\r
+                        usageInstance =(UsageInstance) usageInstanceArray.get(usageInstanceIndex);\r
+                        if (CommonDefinition.isPeiPhaseComponent(usageInstance.componentType)) {\r
+                            pei.add(token);\r
+                                                                                                               found = true;\r
+                            break;\r
+                        }\r
+                    }\r
+                }\r
+            }\r
+\r
+                                               //\r
+                                               // If no PEI components reference the PCD entry, we insert it to DXE list\r
+                                               //\r
+                                               if (!found) {\r
+                                                               dxe.add(token);\r
+                                               }\r
+        }\r
+\r
+                               return;\r
+    }\r
+\r
+               /**\r
       Get all PCD record for a module according to module's name.\r
      \r
       @param moduleName  the name of module.\r
index e4ecfc0..b40e244 100644 (file)
@@ -252,12 +252,16 @@ public class Token {
         UUID  nullUUID = new UUID(0, 0);\r
 \r
         if (platformtokenSpaceName == nullUUID) {\r
-            return cName + "-" + tokenSpaceName.toString();\r
+            return cName + "_" + tokenSpaceName.toString().replace('-', '_');\r
         } else {\r
-            return cName + "-" + platformtokenSpaceName.toString();\r
+            return cName + "_" + platformtokenSpaceName.toString().replace('-', '_');\r
         }\r
     }\r
 \r
+               public String getPrimaryKeyString () {\r
+                               return cName + "_" + tokenSpaceName.toString().replace('-', '_');\r
+               }\r
+\r
     /**\r
       Judge datumType is valid\r
       \r
@@ -634,6 +638,43 @@ public class Token {
 \r
         return uuid;\r
     }\r
+\r
+    //\r
+    // BugBug: We need change this algorithm accordingly when schema is updated\r
+    //          to support no default value.\r
+    //\r
+    public boolean hasDefaultValue () {\r
+\r
+                               if (hiiEnabled) {\r
+                                               return true;\r
+                               }\r
+\r
+                               if (vpdEnabled) {\r
+                                               return true;\r
+                               }\r
+\r
+        if (datum.toString().compareTo("NoDefault") == 0) {\r
+            return false;\r
+        }\r
+\r
+        return true;\r
+    }\r
+\r
+               public boolean isStringType () {\r
+                               String str = datum.toString();\r
+\r
+                               if (datumType == Token.DATUM_TYPE.POINTER &&\r
+                                               str.startsWith("L\"") && \r
+                                               str.endsWith("\"")) {\r
+                                               return true;\r
+                               }\r
+\r
+                               return false;\r
+               }\r
+\r
+               public String getStringTypeString () {                       \r
+                               return datum.toString().substring(2, datum.toString().length() - 1);\r
+               }\r
 }\r
 \r
 \r
index a11633d..2bd704d 100644 (file)
@@ -328,7 +328,7 @@ public class UsageInstance {
             )\r
           );\r
       }\r
\r
+\r
       switch(parentToken.pcdType) {\r
         case FEATURE_FLAG:\r
           if(CommonDefinition.isLibraryComponent(componentType)) {\r
@@ -429,7 +429,8 @@ public class UsageInstance {
                            parentToken.cName\r
                            );\r
           break;\r
-        case DYNAMIC:\r
+                       case DYNAMIC:\r
+                                       hAutogenStr += "\r\n";\r
           hAutogenStr += String.format(\r
                            "#define _PCD_MODE_%s_%s  LibPcdGet%s(_PCD_TOKEN_%s)\r\n",\r
                            Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r