+++ /dev/null
-/** @file\r
- UsageInstance class.\r
-\r
- This class indicate an usage instance for a PCD token. This instance maybe a module\r
- or platform setting. When a module produce or cosume a PCD token, then this module\r
- is an usage instance for this PCD token.\r
-\r
-Copyright (c) 2006, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution. The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
-\r
-**/\r
-package org.tianocore.pcd.entity;\r
-\r
-import org.tianocore.pcd.entity.CommonDefinition;\r
-import org.tianocore.pcd.entity.UsageIdentification;\r
-\r
-/**\r
- This class indicate an usage instance for a PCD token. This instance maybe a module\r
- or platform setting. When a module produce or cosume a PCD token, then this module\r
- is an usage instance for this PCD token.\r
-**/\r
-public class UsageInstance {\r
- ///\r
- /// This parent that this usage instance belongs to.\r
- ///\r
- public Token parentToken;\r
-\r
- ///\r
- /// ModuleIdentification for Usage Instance\r
- ///\r
- public UsageIdentification usageId;\r
-\r
- ///\r
- /// Arch also is a key for a UsageInstance\r
- ///\r
- public String arch;\r
-\r
- ///\r
- /// The PCD type defined for module\r
- ///\r
- public Token.PCD_TYPE modulePcdType;\r
-\r
- ///\r
- /// The value of the PCD in this usage instance.\r
- ///\r
- public String datum;\r
-\r
- ///\r
- /// The maxDatumSize could be different for same PCD in different module\r
- /// But this case is allow for FeatureFlag, FixedAtBuild, PatchableInModule\r
- /// type.\r
- ///\r
- public int maxDatumSize;\r
-\r
- ///\r
- /// Autogen string for header file.\r
- ///\r
- public String hAutogenStr;\r
-\r
- ///\r
- /// Auotgen string for C code file.\r
- ///\r
- public String cAutogenStr;\r
-\r
- /**\r
- Constructure function for UsageInstance\r
-\r
- @param parentToken The token instance for this usgaInstance\r
- @param usageId The identification for usage instance\r
- @param modulePcdType The PCD type for this usage instance\r
- @param value The value of this PCD in this usage instance\r
- @param maxDatumSize The max datum size of this PCD in this usage\r
- instance.\r
- **/\r
- public UsageInstance(Token parentToken,\r
- UsageIdentification usageId,\r
- Token.PCD_TYPE modulePcdType,\r
- String value,\r
- int maxDatumSize) {\r
- this.parentToken = parentToken;\r
- this.usageId = usageId;\r
- this.modulePcdType = modulePcdType;\r
- this.datum = value;\r
- this.maxDatumSize = maxDatumSize;\r
- }\r
-\r
- /**\r
- Get the primary key for usage instance array for every token.\r
-\r
- @param usageId The identification of UsageInstance\r
-\r
- @retval String The primary key for this usage instance\r
- **/\r
- public static String getPrimaryKey(UsageIdentification usageId) {\r
- return usageId.toString();\r
- }\r
-\r
- /**\r
- Get primary key string for this usage instance\r
-\r
- @return String primary key string\r
- **/\r
- public String getPrimaryKey() {\r
- return UsageInstance.getPrimaryKey(usageId);\r
- }\r
-\r
- /**\r
- Judget whether current module is PEI driver\r
-\r
- @return boolean whether current module is PEI driver\r
- **/\r
- public boolean isPeiPhaseComponent() {\r
- int moduleType = CommonDefinition.getModuleType(usageId.moduleType);\r
-\r
- if ((moduleType == CommonDefinition.ModuleTypePeiCore) ||\r
- (moduleType == CommonDefinition.ModuleTypePeim)) {\r
- return true;\r
- }\r
- return false;\r
- }\r
-\r
- /**\r
- Judge whether current module is DXE driver.\r
-\r
- @return boolean whether current module is DXE driver\r
- **/\r
- public boolean isDxePhaseComponent() {\r
- int moduleType = CommonDefinition.getModuleType(usageId.moduleType);\r
-\r
- if ((moduleType == CommonDefinition.ModuleTypeDxeDriver) ||\r
- (moduleType == CommonDefinition.ModuleTypeDxeRuntimeDriver) ||\r
- (moduleType == CommonDefinition.ModuleTypeDxeSalDriver) ||\r
- (moduleType == CommonDefinition.ModuleTypeDxeSmmDriver) ||\r
- (moduleType == CommonDefinition.ModuleTypeUefiDriver) ||\r
- (moduleType == CommonDefinition.ModuleTypeUefiApplication)\r
- ) {\r
- return true;\r
- }\r
- return false;\r
- }\r
-\r
- /**\r
- Generate autogen string for header file and C code file.\r
-\r
- @param isBuildUsedLibrary whether the autogen is for library.\r
- **/\r
- public void generateAutoGen(boolean isBuildUsedLibrary) {\r
- String guidStringCName = null;\r
- boolean isByteArray = false;\r
- String printDatum = null;\r
- String tokenNumberString = null;\r
-\r
- hAutogenStr = "";\r
- cAutogenStr = "";\r
-\r
- if (this.modulePcdType == Token.PCD_TYPE.DYNAMIC_EX) {\r
- //\r
- // For DYNAMIC_EX type PCD, use original token number in SPD or FPD to generate autogen\r
- //\r
- tokenNumberString = Long.toString(parentToken.dynamicExTokenNumber, 16);\r
- } else {\r
- //\r
- // For Others type PCD, use autogenerated token number to generate autogen\r
- //\r
- tokenNumberString = Long.toString(parentToken.tokenNumber, 16);\r
- }\r
-\r
- hAutogenStr += String.format("#define _PCD_TOKEN_%s 0x%s\r\n", parentToken.cName, tokenNumberString);\r
-\r
- //\r
- // Judge the value of this PCD is byte array type\r
- //\r
- if (!isBuildUsedLibrary && !parentToken.isDynamicPCD) {\r
- if (datum.trim().charAt(0) == '{') {\r
- isByteArray = true;\r
- }\r
- }\r
-\r
- //\r
- // "ULL" should be added to value's tail for UINT64 value\r
- //\r
- if (parentToken.datumType == Token.DATUM_TYPE.UINT64) {\r
- printDatum = this.datum + "ULL";\r
- } else {\r
- printDatum = this.datum;\r
- }\r
-\r
- switch (modulePcdType) {\r
- case FEATURE_FLAG:\r
- //\r
- // Example autogen string for following generation:\r
- // "extern const BOOLEAN _gPcd_FixedAtBuild_PcdSampleToken";\r
- // \r
- hAutogenStr += String.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",\r
- parentToken.cName);\r
- //\r
- // Example autogen string for following generation:\r
- // "#define _PCD_GET_MODE_8_PcdSampleToken _gPcd_FixedAtBuild_PcdSampleToken";\r
- // \r
- hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",\r
- Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
- parentToken.cName,\r
- parentToken.cName);\r
- //\r
- // Example autogen string for following generation:\r
- // "//#define _PCD_SET_MODE_8_PcdSampleToken ASSERT(FALSE) If is not allowed to set value...";\r
- // \r
- hAutogenStr += String.format("//#define _PCD_SET_MODE_%s_%s ASSERT(FALSE) If is not allowed to set value for a FEATURE_FLAG PCD\r\n",\r
- Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
- parentToken.cName);\r
-\r
- if (!isBuildUsedLibrary) {\r
- //\r
- // Example autogen string for following generation:\r
- // "#define _PCD_VALUE_PcdSampleToken 0x1000"\r
- // \r
- hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n",\r
- parentToken.cName,\r
- printDatum);\r
- //\r
- // Example autogen string for following generation:\r
- // "GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_PcdSampleToken = _PCD_VALUE_PcdSampleToken;"\r
- // \r
- cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",\r
- parentToken.cName,\r
- parentToken.cName);\r
- }\r
- break;\r
- case FIXED_AT_BUILD:\r
- if (isByteArray) {\r
- //\r
- // Example autogen string for following generation:\r
- // "extern const BOOLEAN _gPcd_FixedAtBuild_PcdSampleToken";\r
- // \r
- hAutogenStr += String.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n",\r
- parentToken.cName);\r
- //\r
- // Example autogen string for following generation:\r
- // "#define _PCD_GET_MODE_8_PcdSampleToken (VOID*)_gPcd_FixedAtBuild_PcdSampleToken";\r
- // \r
- hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_FixedAtBuild_%s\r\n",\r
- Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
- parentToken.cName,\r
- parentToken.cName);\r
- } else {\r
- //\r
- // Example autogen string for following generation:\r
- // "extern const UINT8 _gPcd_FixedAtBuild_PcdSampleToken";\r
- // \r
- hAutogenStr += String.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",\r
- Token.getAutogendatumTypeString(parentToken.datumType),\r
- parentToken.cName);\r
- //\r
- // Example autogen string for following generation:\r
- // "#define _PCD_GET_MODE_8_PcdSampleToken _gPcd_FixedAtBuild_PcdSampleToken";\r
- // \r
- hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",\r
- Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
- parentToken.cName,\r
- parentToken.cName);\r
- }\r
-\r
- //\r
- // Example autogen string for following generation:\r
- // "//#define _PCD_SET_MODE_8_PcdSampleToken ASSERT(FALSE) If is not allowed to set value...";\r
- // \r
- hAutogenStr += String.format("//#define _PCD_SET_MODE_%s_%s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\r\n",\r
- Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
- parentToken.cName);\r
- if (!isBuildUsedLibrary) {\r
- if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {\r
- if (isByteArray) {\r
- //\r
- // Example autogen string for following generation:\r
- // "#define _PCD_VALUE_PcdSampleToken (VOID*)_gPcd_FixedAtBuild_PcdSampleToken"\r
- // \r
- hAutogenStr += String.format("#define _PCD_VALUE_%s (VOID*)_gPcd_FixedAtBuild_%s\r\n",\r
- parentToken.cName,\r
- parentToken.cName);\r
- //\r
- // Example autogen string for following generation:\r
- // "GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_PcdSampleToken[] = 'dfdf';"\r
- // \r
- cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = %s;\r\n",\r
- parentToken.cName,\r
- printDatum);\r
- } else {\r
- //\r
- // Example autogen string for following generation:\r
- // "#define _PCD_VALUE_PcdSampleToken 0x222"\r
- // \r
- hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n",\r
- parentToken.cName,\r
- printDatum);\r
- //\r
- // Example autogen string for following generation:\r
- // "GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_PcdSampleToken[] = _PCD_VALUE_PcdSampleToken;"\r
- // \r
- cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",\r
- Token.getAutogendatumTypeString(parentToken.datumType),\r
- parentToken.cName,\r
- parentToken.cName);\r
- }\r
- } else {\r
- //\r
- // Example autogen string for following generation:\r
- // "#define _PCD_VALUE_PcdSampleToken 0x222"\r
- // \r
- hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n",\r
- parentToken.cName,\r
- printDatum);\r
- //\r
- // Example autogen string for following generation:\r
- // "GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_PcdSampleToken[] = _PCD_VALUE_PcdSampleToken;"\r
- // \r
- cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",\r
- Token.getAutogendatumTypeString(parentToken.datumType),\r
- parentToken.cName,\r
- parentToken.cName);\r
- }\r
- }\r
- break;\r
- case PATCHABLE_IN_MODULE:\r
- if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {\r
- //\r
- // Example autogen string for following generation:\r
- // "extern UINT8 _gPcd_BinaryPatch_PcdSampleToken[];"\r
- // \r
- hAutogenStr += String.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n",\r
- parentToken.cName);\r
- //\r
- // Example autogen string for following generation:\r
- // "#define _PCD_GET_MODE_8_PcdSampleToken (VOID*)_gPcd_BinaryPatch_PcdSampleToken"\r
- // \r
- hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_BinaryPatch_%s\r\n",\r
- Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
- parentToken.cName,\r
- parentToken.cName);\r
- //\r
- // Example autogen string for following generation:\r
- // "#define _PCD_SET_MODE_8_PcdSampleToken(SizeOfBuffer, Buffer) CopyMem (_gPcd_BinaryPatch_PcdSampleToken, (Buffer), (SizeOfBuffer))"\r
- // \r
- hAutogenStr += String.format("#define _PCD_PATCHABLE_%s_SIZE %d\r\n",\r
- parentToken.cName,\r
- parentToken.datumSize);\r
- hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) "+\r
- "LibPatchPcdSetPtr (_gPcd_BinaryPatch_%s, (UINTN)_PCD_PATCHABLE_%s_SIZE, "+\r
- "(SizeOfBuffer), (Buffer))\r\n",\r
- Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
- parentToken.cName,\r
- parentToken.cName,\r
- parentToken.cName);\r
-\r
- } else {\r
- //\r
- // Example autogen string for following generation:\r
- // "extern UINT8 _gPcd_BinaryPatch_PcdSampleToken;"\r
- // \r
- hAutogenStr += String.format("extern %s _gPcd_BinaryPatch_%s;\r\n",\r
- Token.getAutogendatumTypeString(parentToken.datumType),\r
- parentToken.cName);\r
- //\r
- // Example autogen string for following generation:\r
- // "#define _PCD_GET_MODE_8_PcdSampleToken _gPcd_BinaryPatch_PcdSampleToken"\r
- // \r
- hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",\r
- Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
- parentToken.cName,\r
- parentToken.cName);\r
- //\r
- // Example autogen string for following generation:\r
- // "#define _PCD_SET_MODE_8_PcdSampleToken(Value) (_gPcd_BinaryPatch_PcdSampleToken = (Value))"\r
- // \r
- hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(Value) (_gPcd_BinaryPatch_%s = (Value))\r\n",\r
- Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
- parentToken.cName,\r
- parentToken.cName);\r
- }\r
-\r
- if (!isBuildUsedLibrary) {\r
- if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {\r
- printDatum = parentToken.getByteArrayForPointerDatum(printDatum);\r
- }\r
- //\r
- // Example autogen string for following generation:\r
- // "#define _PCD_VALUE_PcdSampleToken 0x111"\r
- // \r
- hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n",\r
- parentToken.cName,\r
- printDatum);\r
- if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {\r
- //\r
- // Example autogen string for following generation:\r
- // "GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_PcdSampleToken[] = _PCD_VALUE_PcdSampleToken;"\r
- // \r
- cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[%d] = _PCD_VALUE_%s;\r\n",\r
- parentToken.cName,\r
- parentToken.datumSize,\r
- parentToken.cName);\r
- } else {\r
- //\r
- // Example autogen string for following generation:\r
- // "GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_PcdSampleToken[] = _PCD_VALUE_PcdSampleToken;"\r
- // \r
- cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",\r
- Token.getAutogendatumTypeString(parentToken.datumType),\r
- parentToken.cName,\r
- parentToken.cName);\r
- }\r
- }\r
-\r
- break;\r
- case DYNAMIC:\r
- //\r
- // Example autogen string for following generation:\r
- // "#define _PCD_GET_MODE_8_PcdSampleToken LibPcdGet%s(_PCD_TOKEN_PcdSampleToken)"\r
- // \r
- hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",\r
- Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
- parentToken.cName,\r
- Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
- parentToken.cName);\r
- if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {\r
- //\r
- // Example autogen string for following generation:\r
- // "#define _PCD_SET_MODE_8_PcdSampleToken(SizeOfBuffer, Buffer) LibPcdSet%s(_PCD_TOKEN_PcdSampleToken, (SizeOfBuffer), (Buffer))"\r
- // \r
- hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSet%s(_PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",\r
- Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
- parentToken.cName,\r
- Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
- parentToken.cName);\r
- } else {\r
- //\r
- // Example autogen string for following generation:\r
- // "#define _PCD_SET_MODE_8_PcdSampleToken(Value) LibPcdSet%s(_PCD_TOKEN_PcdSampleToken, (Value))"\r
- // \r
- hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSet%s(_PCD_TOKEN_%s, (Value))\r\n",\r
- Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
- parentToken.cName,\r
- Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
- parentToken.cName);\r
- }\r
- break;\r
- case DYNAMIC_EX:\r
- guidStringCName = "_gPcd_TokenSpaceGuid_" +\r
- parentToken.tokenSpaceName.toString().replaceAll("-", "_");\r
-\r
- //\r
- // Example autogen string for following generation:\r
- // "#define _PCD_GET_MODE_8_PcdSampleToken LibPcdGetEx%s(&_gPcd_TokenSpaceGuid_00_00_00, _PCD_TOKEN_PcdSampleToken)"\r
- // \r
- hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s LibPcdGetEx%s(&%s, _PCD_TOKEN_%s)\r\n",\r
- Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
- parentToken.cName,\r
- Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
- guidStringCName,\r
- parentToken.cName);\r
-\r
- if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {\r
- //\r
- // Example autogen string for following generation:\r
- // "#define _PCD_SET_MODE_8_PcdSampleToken(SizeOfBuffer, Buffer) LibPcdSetEx%s(&_gPcd_TokenSpaceGuid_00_00_00, _PCD_TOKEN_PcdSampleToken, (SizeOfBuffer), (Buffer))"\r
- // \r
- hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",\r
- Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
- parentToken.cName,\r
- Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
- guidStringCName,\r
- parentToken.cName);\r
- } else {\r
- //\r
- // Example autogen string for following generation:\r
- // "#define _PCD_SET_MODE_8_PcdSampleToken(Value) LibPcdSetEx%s(&_gPcd_TokenSpaceGuid_00_00_00, _PCD_TOKEN_PcdSampleToken, (Value))"\r
- //\r
- hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (Value))\r\n",\r
- Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
- parentToken.cName,\r
- Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
- guidStringCName,\r
- parentToken.cName);\r
-\r
- }\r
- break;\r
- }\r
- }\r
-\r
- /**\r
- Get the autogen string for header file.\r
-\r
- @return The string of header file.\r
- **/\r
- public String getHAutogenStr() {\r
- return hAutogenStr;\r
- }\r
-\r
- /**\r
- Get the autogen string for C code file.\r
-\r
- @return The string of C Code file.\r
- **/\r
- public String getCAutogenStr() {\r
- return cAutogenStr;\r
- }\r
-}\r
-\r