]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/pcd/entity/UsageInstance.java
4 This class indicate an usage instance for a PCD token. This instance maybe a module
5 or platform setting. When a module produce or cosume a PCD token, then this module
6 is an usage instance for this PCD token.
8 Copyright (c) 2006, Intel Corporation
9 All rights reserved. This program and the accompanying materials
10 are licensed and made available under the terms and conditions of the BSD License
11 which accompanies this distribution. The full text of the license may be found at
12 http://opensource.org/licenses/bsd-license.php
14 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
15 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 package org
.tianocore
.build
.pcd
.entity
;
21 import java
.util
.UUID
;
22 import org
.tianocore
.ModuleTypeDef
;
23 import org
.tianocore
.build
.autogen
.CommonDefinition
;
24 import org
.tianocore
.build
.pcd
.action
.ActionMessage
;
25 import org
.tianocore
.build
.pcd
.exception
.EntityException
;
28 This class indicate an usage instance for a PCD token. This instance maybe a module
29 or platform setting. When a module produce or cosume a PCD token, then this module
30 is an usage instance for this PCD token.
32 public class UsageInstance
{
34 /// This parent that this usage instance belongs to.
36 public Token parentToken
;
39 /// The name of the module who contains this PCD.
41 public String moduleName
;
44 /// The GUID of the module who contains this PCD.
46 public UUID moduleGUID
;
49 /// The name of the package whose module contains this PCD.
51 public String packageName
;
54 /// The GUID of the package whose module contains this PCD.
56 public UUID packageGUID
;
59 /// The PCD type defined for module
61 public Token
.PCD_TYPE modulePcdType
;
64 /// The arch string of module contains this PCD
69 /// The version of module contains this PCD
71 public String version
;
74 /// The module type for this usage instance.
76 public ModuleTypeDef
.Enum moduleType
;
79 /// The value of the PCD in this usage instance.
84 /// The maxDatumSize could be different for same PCD in different module
85 /// But this case is allow for FeatureFlag, FixedAtBuild, PatchableInModule
88 public int maxDatumSize
;
91 /// Autogen string for header file.
93 public String hAutogenStr
;
96 /// Auotgen string for C code file.
98 public String cAutogenStr
;
101 Constructure function
103 @param parentToken Member variable.
104 @param moduleName Member variable.
105 @param moduleGUID Member variable.
106 @param packageName Member variable.
107 @param packageGUID Member variable.
108 @param moduleType Member variable.
109 @param modulePcdType Member variable.
110 @param arch Member variable.
111 @param version Member variable.
112 @param value Member variable.
113 @param maxDatumSize Member variable.
115 public UsageInstance (Token parentToken
,
120 ModuleTypeDef
.Enum moduleType
,
121 Token
.PCD_TYPE modulePcdType
,
126 this.parentToken
= parentToken
;
127 this.moduleName
= moduleName
;
128 this.moduleGUID
= moduleGUID
;
129 this.packageName
= packageName
;
130 this.packageGUID
= packageGUID
;
131 this.moduleType
= moduleType
;
132 this.modulePcdType
= modulePcdType
;
134 this.version
= version
;
136 this.maxDatumSize
= maxDatumSize
;
140 Get the primary key for usage instance array for every token.
142 @param moduleName the name of module
143 @param moduleGUID the GUID name of module
144 @param packageName the name of package who contains this module
145 @param packageGUID the GUID name of package
146 @param arch the archtecture string
147 @param version the version of this module
149 @return String primary key
151 public static String
getPrimaryKey(String moduleName
,
158 // Because currently transition schema not require write moduleGuid, package Name, Packge GUID in
159 // <ModuleSA> section, So currently no expect all paramter must be valid.
160 return(moduleName
+ "_" +
161 ((moduleGUID
!= null) ? moduleGUID
.toString() : "NullModuleGuid") + "_" +
162 ((packageName
!= null) ? packageName
: "NullPackageName") + "_" +
163 ((packageGUID
!= null) ? packageGUID
.toString() : "NullPackageGuid") + "_" +
164 ((arch
!= null) ? arch
: "NullArch") + "_" +
165 ((version
!= null) ? version
: "NullVersion"));
169 Get primary key string for this usage instance
171 @return String primary key string
173 public String
getPrimaryKey() {
174 return UsageInstance
.getPrimaryKey(moduleName
, moduleGUID
, packageName
, packageGUID
, arch
, version
);
178 Judget whether current module is PEI driver
182 public boolean isPeiPhaseComponent() {
183 if ((moduleType
== ModuleTypeDef
.PEI_CORE
) ||
184 (moduleType
== ModuleTypeDef
.PEIM
)) {
191 Generate autogen string for header file and C code file.
193 @throws EntityException Fail to generate.
195 @param isBuildUsedLibrary whether the autogen is for library.
197 public void generateAutoGen(boolean isBuildUsedLibrary
)
198 throws EntityException
{
199 String guidStringCName
= null;
200 boolean isByteArray
= false;
201 String printDatum
= null;
206 if (this.modulePcdType
== Token
.PCD_TYPE
.DYNAMIC_EX
) {
207 hAutogenStr
+= String
.format("#define _PCD_TOKEN_%s 0x%016x\r\n",
208 parentToken
.cName
, parentToken
.dynamicExTokenNumber
);
210 hAutogenStr
+= String
.format("#define _PCD_TOKEN_%s 0x%016x\r\n",
211 parentToken
.cName
, parentToken
.tokenNumber
);
214 if (!isBuildUsedLibrary
&& !parentToken
.isDynamicPCD
) {
215 if (datum
.trim().charAt(0) == '{') {
220 if (parentToken
.datumType
== Token
.DATUM_TYPE
.UINT64
) {
221 printDatum
= this.datum
+ "ULL";
223 printDatum
= this.datum
;
226 switch (modulePcdType
) {
228 hAutogenStr
+= String
.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
230 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
231 parentToken
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
235 if (!isBuildUsedLibrary
) {
236 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
239 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
246 hAutogenStr
+= String
.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n",
248 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s &_gPcd_FixedAtBuild_%s\r\n",
249 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
253 hAutogenStr
+= String
.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",
254 Token
.getAutogendatumTypeString(parentToken
.datumType
),
256 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
257 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
262 if (!isBuildUsedLibrary
) {
263 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
267 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = _PCD_VALUE_%s;\r\n",
271 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
272 Token
.getAutogendatumTypeString(parentToken
.datumType
),
278 case PATCHABLE_IN_MODULE
:
280 hAutogenStr
+= String
.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n",
282 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s &_gPcd_BinaryPatch_%s\r\n",
283 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
287 hAutogenStr
+= String
.format("extern %s _gPcd_BinaryPatch_%s;\r\n",
288 Token
.getAutogendatumTypeString(parentToken
.datumType
),
290 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
291 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
296 if (!isBuildUsedLibrary
) {
297 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
301 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[] = _PCD_VALUE_%s;\r\n",
305 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",
306 Token
.getAutogendatumTypeString(parentToken
.datumType
),
314 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",
315 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
317 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
321 guidStringCName
= "_gPcd_TokenSpaceGuid_" +
322 parentToken
.tokenSpaceName
.toString().replaceAll("-", "_");
324 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s LibPcdGetEx%s(&%s, _PCD_TOKEN_%s)\r\n",
325 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
327 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
336 Get the autogen string for header file.
338 @return The string of header file.
340 public String
getHAutogenStr() {
345 Get the autogen string for C code file.
347 @return The string of C Code file.
349 public String
getCAutogenStr() {