Support HII VOID* dynamic/dynamicEx type PCD.
authorklu2 <klu2@c2973edb-eda0-4c78-bc6a-9341b269661f>
Thu, 11 Feb 2010 08:21:03 +0000 (08:21 +0000)
committerklu2 <klu2@c2973edb-eda0-4c78-bc6a-9341b269661f>
Thu, 11 Feb 2010 08:21:03 +0000 (08:21 +0000)
git-svn-id: https://edk2-buildtools.svn.sourceforge.net/svnroot/edk2-buildtools/trunk/BaseTools@1865 c2973edb-eda0-4c78-bc6a-9341b269661f

Source/Python/AutoGen/GenC.py

index 9c49129..a913cf4 100644 (file)
@@ -162,7 +162,7 @@ ${END}
   GUID               GuidTable[${PHASE}_GUID_TABLE_SIZE];
 ${BEGIN}  STRING_HEAD        ${STRING_HEAD_CNAME_DECL}_${STRING_HEAD_GUID_DECL}[${STRING_HEAD_NUMSKUS_DECL}];
 ${END}
-${BEGIN}  VARIABLE_HEAD      ${VARIABLE_HEAD_CNAME_DECL}_${VARIABLE_HEAD_GUID_DECL}[${VARIABLE_HEAD_NUMSKUS_DECL}];
+${BEGIN}  VARIABLE_HEAD      ${VARIABLE_HEAD_CNAME_DECL}_${VARIABLE_HEAD_GUID_DECL}_Variable_Header[${VARIABLE_HEAD_NUMSKUS_DECL}];
 ${END}
 ${BEGIN}  UINT8              StringTable${STRING_TABLE_INDEX}[${STRING_TABLE_LENGTH}]; /* ${STRING_TABLE_CNAME}_${STRING_TABLE_GUID} */
 ${END}
@@ -253,7 +253,7 @@ ${END}
   },
   /* LocalTokenNumberTable */
   {
-${BEGIN}    offsetof(${PHASE}_PCD_DATABASE, ${TOKEN_INIT}.${TOKEN_CNAME}_${TOKEN_GUID}) | ${TOKEN_TYPE},
+${BEGIN}    offsetof(${PHASE}_PCD_DATABASE, ${TOKEN_INIT}.${TOKEN_CNAME}_${TOKEN_GUID}${VARDEF_HEADER}) | ${TOKEN_TYPE},
 ${END}
   },
   /* GuidTable */
@@ -263,7 +263,7 @@ ${END}
   },
 ${BEGIN}  { ${STRING_HEAD_VALUE} }, /* ${STRING_HEAD_CNAME_DECL}_${STRING_HEAD_GUID_DECL}[${STRING_HEAD_NUMSKUS_DECL}] */
 ${END}
-${BEGIN}  /* ${VARIABLE_HEAD_CNAME_DECL}_${VARIABLE_HEAD_GUID_DECL}[${VARIABLE_HEAD_NUMSKUS_DECL}] */
+${BEGIN}  /* ${VARIABLE_HEAD_CNAME_DECL}_${VARIABLE_HEAD_GUID_DECL}_Variable_Header[${VARIABLE_HEAD_NUMSKUS_DECL}] */
   {
     ${VARIABLE_HEAD_VALUE}
   },
@@ -953,7 +953,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
             Const = ''
         Type = ''
         Array = ''
-        Value = Pcd.DefaultValue\r
+        Value = Pcd.DefaultValue
         Unicode = False
         ValueNumber = 0
         if Pcd.DatumType in ['UINT64', 'UINT32', 'UINT16', 'UINT8']:
@@ -1013,7 +1013,7 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
             ArraySize = int(Pcd.MaxDatumSize, 0)
             if Value[0] == '{':
                 Type = '(VOID *)'
-            else:\r
+            else:
                 if Value[0] == 'L':
                     Unicode = True
                 Value = Value.lstrip('L')   #.strip('"')
@@ -1021,15 +1021,15 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
                 NewValue = '{'
                 for Index in range(0,len(Value)):
                     if Unicode:
-                        NewValue = NewValue + str(ord(Value[Index]) % 0x10000) + ', '\r
-                    else:\r
+                        NewValue = NewValue + str(ord(Value[Index]) % 0x10000) + ', '
+                    else:
                         NewValue = NewValue + str(ord(Value[Index]) % 0x100) + ', '
-                if Unicode:\r
-                    ArraySize = ArraySize / 2;\r
-\r
+                if Unicode:
+                    ArraySize = ArraySize / 2;
+
                 if ArraySize < (len(Value) + 1):
                     ArraySize = len(Value) + 1
-                Value = NewValue + '0 }'\r
+                Value = NewValue + '0 }'
             Array = '[%d]' % ArraySize
         #
         # skip casting for fixed at build since it breaks ARM assembly.
@@ -1043,16 +1043,16 @@ def CreateModulePcdCode(Info, AutoGenC, AutoGenH, Pcd):
         else:
             PcdValueName = '_PCD_VALUE_' + Pcd.TokenCName
             
-        if Pcd.DatumType == 'VOID*':\r
-            #\r
-            # For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed.\r
-            #\r
-            if Unicode:\r
-                AutoGenH.Append('#define _PCD_PATCHABLE_%s_SIZE %s\n' % (Pcd.TokenCName, Pcd.MaxDatumSize))\r
-                AutoGenH.Append('#define %s  %s%s\n' %(PcdValueName, Type, PcdVariableName))\r
-                AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))\r
-                AutoGenH.Append('extern %s UINT16 %s%s;\n' %(Const, PcdVariableName, Array))\r
-                AutoGenH.Append('#define %s  %s%s\n' %(GetModeName, Type, PcdVariableName))\r
+        if Pcd.DatumType == 'VOID*':
+            #
+            # For unicode, UINT16 array will be generated, so the alignment of unicode is guaranteed.
+            #
+            if Unicode:
+                AutoGenH.Append('#define _PCD_PATCHABLE_%s_SIZE %s\n' % (Pcd.TokenCName, Pcd.MaxDatumSize))
+                AutoGenH.Append('#define %s  %s%s\n' %(PcdValueName, Type, PcdVariableName))
+                AutoGenC.Append('GLOBAL_REMOVE_IF_UNREFERENCED %s UINT16 %s%s = %s;\n' % (Const, PcdVariableName, Array, Value))
+                AutoGenH.Append('extern %s UINT16 %s%s;\n' %(Const, PcdVariableName, Array))
+                AutoGenH.Append('#define %s  %s%s\n' %(GetModeName, Type, PcdVariableName))
             else:
                 AutoGenH.Append('#define _PCD_PATCHABLE_%s_SIZE %s\n' % (Pcd.TokenCName, Pcd.MaxDatumSize))
                 AutoGenH.Append('#define %s  %s%s\n' %(PcdValueName, Type, PcdVariableName))
@@ -1179,7 +1179,7 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
         'SYSTEM_SKU_ID_VALUE'           : '0'
     }
 
-    for DatumType in ['UINT64','UINT32','UINT16','UINT8','BOOLEAN']:
+    for DatumType in ['UINT64','UINT32','UINT16','UINT8','BOOLEAN', "VOID*"]:
         Dict['VARDEF_CNAME_' + DatumType] = []
         Dict['VARDEF_GUID_' + DatumType]  = []
         Dict['VARDEF_SKUID_' + DatumType] = []
@@ -1214,7 +1214,7 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
     Dict['GUID_STRUCTURE'] = []
 
     Dict['SKUID_VALUE'] = []
-
+    Dict['VARDEF_HEADER'] = []
     if Phase == 'DXE':
         Dict['SYSTEM_SKU_ID'] = ''
         Dict['SYSTEM_SKU_ID_VALUE'] = ''
@@ -1263,7 +1263,7 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
         Pcd.InitString = 'UNINIT'
 
         if Pcd.DatumType == 'VOID*':
-            Pcd.TokenTypeList = ['PCD_DATUM_TYPE_POINTER']
+            Pcd.TokenTypeList = ['PCD_TYPE_STRING']
         elif Pcd.DatumType == 'BOOLEAN':
             Pcd.TokenTypeList = ['PCD_DATUM_TYPE_UINT8']
         else:
@@ -1310,53 +1310,65 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
                     Dict['GUID_STRUCTURE'].append(VariableGuidStructure)
                 VariableHeadGuidIndex = GuidList.index(VariableGuid)
 
-                VariableHeadValueList.append('%d, %d, %s, offsetof(%s_PCD_DATABASE, Init.%s_%s_VariableDefault_%s)' %
-                                             (VariableHeadGuidIndex, VariableHeadStringIndex, Sku.VariableOffset,
-                                              Phase, CName, TokenSpaceGuid, SkuIdIndex))
+                if "PCD_TYPE_STRING" in Pcd.TokenTypeList:
+                    VariableHeadValueList.append('%d, %d, %s, offsetof(%s_PCD_DATABASE, Init.%s_%s)' %
+                                                 (VariableHeadGuidIndex, VariableHeadStringIndex, Sku.VariableOffset,
+                                                  Phase, CName, TokenSpaceGuid))
+                else:
+                    VariableHeadValueList.append('%d, %d, %s, offsetof(%s_PCD_DATABASE, Init.%s_%s_VariableDefault_%s)' %
+                                                 (VariableHeadGuidIndex, VariableHeadStringIndex, Sku.VariableOffset,
+                                                  Phase, CName, TokenSpaceGuid, SkuIdIndex))
                 Dict['VARDEF_CNAME_'+Pcd.DatumType].append(CName)
                 Dict['VARDEF_GUID_'+Pcd.DatumType].append(TokenSpaceGuid)
                 Dict['VARDEF_SKUID_'+Pcd.DatumType].append(SkuIdIndex)
-                Dict['VARDEF_VALUE_'+Pcd.DatumType].append(Sku.HiiDefaultValue)
+                if "PCD_TYPE_STRING" in  Pcd.TokenTypeList:
+                    Dict['VARDEF_VALUE_' + Pcd.DatumType].append("%s_%s[%d]" % (Pcd.TokenCName, TokenSpaceGuid, SkuIdIndex))
+                else:
+                    Dict['VARDEF_VALUE_'+Pcd.DatumType].append(Sku.HiiDefaultValue)
             elif Sku.VpdOffset != '':
                 Pcd.TokenTypeList += ['PCD_TYPE_VPD']
                 Pcd.InitString = 'INIT'
                 VpdHeadOffsetList.append(Sku.VpdOffset)
+            
+          
+            if Pcd.DatumType == 'VOID*':
+                Pcd.TokenTypeList += ['PCD_TYPE_STRING']
+                Pcd.InitString = 'INIT'
+                if Sku.HiiDefaultValue != '' and Sku.DefaultValue == '':
+                    Sku.DefaultValue = Sku.HiiDefaultValue
+                if Sku.DefaultValue != '':
+                    NumberOfSizeItems += 1
+                    Dict['STRING_TABLE_CNAME'].append(CName)
+                    Dict['STRING_TABLE_GUID'].append(TokenSpaceGuid)
+
+                    if StringTableIndex == 0:
+                        Dict['STRING_TABLE_INDEX'].append('')
+                    else:
+                        Dict['STRING_TABLE_INDEX'].append('_%d' % StringTableIndex)
+                    if Sku.DefaultValue[0] == 'L':
+                        Size = (len(Sku.DefaultValue) - 3 + 1) * 2
+                        Dict['STRING_TABLE_VALUE'].append(StringToArray(Sku.DefaultValue))
+                    elif Sku.DefaultValue[0] == '"':
+                        Size = len(Sku.DefaultValue) - 2 + 1
+                        Dict['STRING_TABLE_VALUE'].append(StringToArray(Sku.DefaultValue))
+                    elif Sku.DefaultValue[0] == '{':
+                        Size = len(Sku.DefaultValue.replace(',',' ').split())
+                        Dict['STRING_TABLE_VALUE'].append(Sku.DefaultValue)
+
+                    StringHeadOffsetList.append(str(StringTableSize))
+                    Dict['SIZE_TABLE_CNAME'].append(CName)
+                    Dict['SIZE_TABLE_GUID'].append(TokenSpaceGuid)
+                    Dict['SIZE_TABLE_CURRENT_LENGTH'].append(Size)
+                    Dict['SIZE_TABLE_MAXIMUM_LENGTH'].append(Pcd.MaxDatumSize)
+                    if Pcd.MaxDatumSize != '':
+                        MaxDatumSize = int(Pcd.MaxDatumSize, 0)
+                        if MaxDatumSize > Size:
+                            Size = MaxDatumSize
+                    Dict['STRING_TABLE_LENGTH'].append(Size)
+                    StringTableIndex += 1
+                    StringTableSize += (Size)
             else:
-                if Pcd.DatumType == 'VOID*':
-                    Pcd.TokenTypeList += ['PCD_TYPE_STRING']
-                    Pcd.InitString = 'INIT'
-                    if Sku.DefaultValue != '':
-                        NumberOfSizeItems += 1
-                        Dict['STRING_TABLE_CNAME'].append(CName)
-                        Dict['STRING_TABLE_GUID'].append(TokenSpaceGuid)
-
-                        if StringTableIndex == 0:
-                            Dict['STRING_TABLE_INDEX'].append('')
-                        else:
-                            Dict['STRING_TABLE_INDEX'].append('_%d' % StringTableIndex)
-                        if Sku.DefaultValue[0] == 'L':
-                            Size = (len(Sku.DefaultValue) - 3 + 1) * 2
-                            Dict['STRING_TABLE_VALUE'].append(StringToArray(Sku.DefaultValue))
-                        elif Sku.DefaultValue[0] == '"':
-                            Size = len(Sku.DefaultValue) - 2 + 1
-                            Dict['STRING_TABLE_VALUE'].append(StringToArray(Sku.DefaultValue))
-                        elif Sku.DefaultValue[0] == '{':
-                            Size = len(Sku.DefaultValue.replace(',',' ').split())
-                            Dict['STRING_TABLE_VALUE'].append(Sku.DefaultValue)
-
-                        StringHeadOffsetList.append(str(StringTableSize))
-                        Dict['SIZE_TABLE_CNAME'].append(CName)
-                        Dict['SIZE_TABLE_GUID'].append(TokenSpaceGuid)
-                        Dict['SIZE_TABLE_CURRENT_LENGTH'].append(Size)
-                        Dict['SIZE_TABLE_MAXIMUM_LENGTH'].append(Pcd.MaxDatumSize)
-                        if Pcd.MaxDatumSize != '':
-                            MaxDatumSize = int(Pcd.MaxDatumSize, 0)
-                            if MaxDatumSize > Size:
-                                Size = MaxDatumSize
-                        Dict['STRING_TABLE_LENGTH'].append(Size)
-                        StringTableIndex += 1
-                        StringTableSize += (Size)
-                else:
+                if "PCD_TYPE_HII" not in Pcd.TokenTypeList:
                     Pcd.TokenTypeList += ['PCD_TYPE_DATA']
                     if Sku.DefaultValue == 'TRUE':
                         Pcd.InitString = 'INIT'
@@ -1366,23 +1378,27 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
                                 Pcd.InitString = 'INIT'
                         except:
                             pass
-                    
-                    #
-                    # For UNIT64 type PCD's value, ULL should be append to avoid
-                    # warning under linux building environment.
-                    #
-                    if Pcd.DatumType == "UINT64":
-                        ValueList.append(Sku.DefaultValue + "ULL")
-                    else:
-                        ValueList.append(Sku.DefaultValue)
+                
+                #
+                # For UNIT64 type PCD's value, ULL should be append to avoid
+                # warning under linux building environment.
+                #
+                if Pcd.DatumType == "UINT64":
+                    ValueList.append(Sku.DefaultValue + "ULL")
+                else:
+                    ValueList.append(Sku.DefaultValue)
 
         Pcd.TokenTypeList = list(set(Pcd.TokenTypeList))
+        
 
         if 'PCD_TYPE_HII' in Pcd.TokenTypeList:
             Dict['VARIABLE_HEAD_CNAME_DECL'].append(CName)
             Dict['VARIABLE_HEAD_GUID_DECL'].append(TokenSpaceGuid)
             Dict['VARIABLE_HEAD_NUMSKUS_DECL'].append(len(Pcd.SkuInfoList))
             Dict['VARIABLE_HEAD_VALUE'].append('{ %s }\n' % ' },\n    { '.join(VariableHeadValueList))
+            Dict['VARDEF_HEADER'].append('_Variable_Header')
+        else:
+            Dict['VARDEF_HEADER'].append('')
         if 'PCD_TYPE_VPD' in Pcd.TokenTypeList:
             Dict['VPD_HEAD_CNAME_DECL'].append(CName)
             Dict['VPD_HEAD_GUID_DECL'].append(TokenSpaceGuid)
@@ -1411,7 +1427,7 @@ def CreatePcdDatabasePhaseSpecificAutoGen (Platform, Phase):
     Dict['TOKEN_CNAME']      = ['' for x in range(NumberOfLocalTokens)]
     Dict['TOKEN_GUID']       = ['' for x in range(NumberOfLocalTokens)]
     Dict['TOKEN_TYPE']       = ['' for x in range(NumberOfLocalTokens)]
-
+    
     for Pcd in Platform.DynamicPcdList:
         CName = Pcd.TokenCName
         TokenSpaceGuidCName = Pcd.TokenSpaceGuidCName