]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/pcd/entity/UsageInstance.java
a11633d91b617a5641d039f617a05f79445ef47d
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 org
.tianocore
.build
.pcd
.exception
.EntityException
;
22 import org
.tianocore
.build
.pcd
.action
.ActionMessage
;
24 import org
.tianocore
.build
.autogen
.CommonDefinition
;
27 This class indicate an usage instance for a PCD token. This instance maybe a module
28 or platform setting. When a module produce or cosume a PCD token, then this module
29 is an usage instance for this PCD token.
31 public class UsageInstance
{
33 /// This parent that this usage instance belongs to.
35 public Token parentToken
;
37 /// The usage of this token for platform or module.
39 public Token
.PCD_USAGE usage
;
41 /// Whether this usage instance inherit from library
43 public boolean isInherit
;
45 /// The pcd type of this token for module.
47 public Token
.PCD_TYPE modulePcdType
;
49 /// The name of the module who contains this PCD.
51 public String moduleName
;
53 /// The name of the package whose module contains this PCD.
55 public String packageName
;
57 /// The component type for this usage instance.
59 public int componentType
;
61 /// The default value defined in MSA has high prior than defined in SPD.
63 public Object defaultValueInMSA
;
65 /// The default value defined in SPD.
67 public Object defaultValueInSPD
;
71 public String helpTextInMSA
;
75 public String helpTextInSPD
;
77 /// Autogen string for header file.
79 public String hAutogenStr
;
81 * Auotgen string for C code file.
83 public String cAutogenStr
;
88 @param parentToken Member variable.
89 @param usage Member variable.
90 @param pcdType Member variable.
91 @param componentType Member variable.
92 @param defaultValueInMSA Member variable.
93 @param defaultValueInSPD Member variable.
94 @param helpTextInMSA Member variable.
95 @param helpTextInSPD Member variable.
96 @param moduleName Member variable.
97 @param packageName Member variable.
98 @param isInherit Member variable.
100 public UsageInstance(
102 Token
.PCD_USAGE usage
,
103 Token
.PCD_TYPE pcdType
,
105 Object defaultValueInMSA
,
106 Object defaultValueInSPD
,
107 String helpTextInMSA
,
108 String helpTextInSPD
,
114 this.parentToken
= parentToken
;
116 this.modulePcdType
= pcdType
;
117 this.componentType
= componentType
;
118 this.defaultValueInMSA
= defaultValueInMSA
;
119 this.defaultValueInSPD
= defaultValueInSPD
;
120 this.helpTextInMSA
= helpTextInMSA
;
121 this.helpTextInSPD
= helpTextInSPD
;
122 this.moduleName
= moduleName
;
123 this.packageName
= packageName
;
124 this.isInherit
= isInherit
;
128 Generate autogen string for header file and C code file.
130 @throws EntityException Fail to generate.
132 public void generateAutoGen() throws EntityException
{
139 value
= this.parentToken
.datum
;
142 // If this pcd token's PCD_TYPE is DYNAMIC_EX, use itself token space name
143 // otherwices use assgined token space name from tool automatically.
145 if(parentToken
.pcdType
== Token
.PCD_TYPE
.DYNAMIC_EX
) {
146 tokenNumber
= parentToken
.tokenNumber
;
148 tokenNumber
= parentToken
.assignedtokenNumber
;
151 hAutogenStr
+= String
.format("#define _PCD_TOKEN_%s 0x%016x\r\n",
152 parentToken
.cName
, tokenNumber
);
154 switch(modulePcdType
) {
157 // BUGBUG: The judegement of module PCD type and platform PCD type should not be
158 // done here, but in wizard tools, But here is just following something
159 // PcdEmulation driver.
161 if(parentToken
.pcdType
.ordinal() > Token
.PCD_TYPE
.FEATURE_FLAG
.ordinal()) {
162 throw new EntityException(
164 "%s:Platform PCD Type %d is not compatible with Module PCD Type %d\r\n",
166 parentToken
.pcdType
.name(),
172 if(CommonDefinition
.isLibraryComponent(componentType
)) {
173 hAutogenStr
+= String
.format(
174 "extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
177 hAutogenStr
+= String
.format(
178 "#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
179 parentToken
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
184 hAutogenStr
+= String
.format(
185 "#define _PCD_VALUE_%s %s\r\n",
189 hAutogenStr
+= String
.format(
190 "extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
193 cAutogenStr
+= String
.format(
194 "GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
198 hAutogenStr
+= String
.format(
199 "#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",
200 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
208 // BUGBUG: The judegement of module PCD type and platform PCD type should not be
209 // done here, but in wizard tools, But here is just following something
210 // PcdEmulation driver.
212 if(parentToken
.pcdType
.ordinal() > Token
.PCD_TYPE
.FIXED_AT_BUILD
.ordinal()) {
213 throw new EntityException(
215 "%s:Platform PCD Type %d is not compatible with Module PCD Type %d\r\n",
217 parentToken
.pcdType
.name(),
223 if(CommonDefinition
.isLibraryComponent(componentType
)) {
224 hAutogenStr
+= String
.format(
225 "extern const %s _gPcd_FixedAtBuild_%s;\r\n",
226 Token
.getAutogendatumTypeString(parentToken
.datumType
),
229 hAutogenStr
+= String
.format(
230 "#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
231 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
236 hAutogenStr
+= String
.format(
237 "#define _PCD_VALUE_%s %s\r\n",
241 hAutogenStr
+= String
.format(
242 "extern const %s _gPcd_FixedAtBuild_%s;\r\n",
243 Token
.getAutogendatumTypeString(parentToken
.datumType
),
246 cAutogenStr
+= String
.format(
247 "GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
248 Token
.getAutogendatumTypeString(parentToken
.datumType
),
252 hAutogenStr
+= String
.format(
253 "#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",
254 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
260 case PATCHABLE_IN_MODULE
:
262 // BUGBUG: The judegement of module PCD type and platform PCD type should not be
263 // done here, but in wizard tools, But here is just following something
264 // PcdEmulation driver.
266 if(parentToken
.pcdType
.ordinal() > Token
.PCD_TYPE
.PATCHABLE_IN_MODULE
.ordinal()) {
267 throw new EntityException(
269 "%s:Platform PCD Type %d is not compatible with Module PCD Type %d\r\n",
271 parentToken
.pcdType
.name(),
277 if(CommonDefinition
.isLibraryComponent(componentType
)) {
278 hAutogenStr
+= String
.format(
279 "extern %s _gPcd_BinaryPatch_%s;\r\n",
280 Token
.getAutogendatumTypeString(parentToken
.datumType
),
283 hAutogenStr
+= String
.format(
284 "#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
285 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
290 hAutogenStr
+= String
.format(
291 "#define _PCD_VALUE_%s %s\r\n",
295 hAutogenStr
+= String
.format(
296 "extern %s _gPcd_BinaryPatch_%s;\r\n",
297 Token
.getAutogendatumTypeString(parentToken
.datumType
),
300 cAutogenStr
+= String
.format(
301 "GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",
302 Token
.getAutogendatumTypeString(parentToken
.datumType
),
306 hAutogenStr
+= String
.format(
307 "#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
308 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
317 // BUGBUG: The judegement of module PCD type and platform PCD type should not be
318 // done here, but in wizard tools, But here is just following something
319 // PcdEmulation driver.
321 if(parentToken
.pcdType
.ordinal() > Token
.PCD_TYPE
.DYNAMIC
.ordinal()) {
322 throw new EntityException(
324 "%s:Platform PCD Type %d is not compatible with Module PCD Type %d\r\n",
326 parentToken
.pcdType
.name(),
332 switch(parentToken
.pcdType
) {
334 if(CommonDefinition
.isLibraryComponent(componentType
)) {
335 hAutogenStr
+= String
.format(
336 "extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
339 hAutogenStr
+= String
.format(
340 "#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
341 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
346 hAutogenStr
+= String
.format(
347 "#define _PCD_VALUE_%s %s\r\n",
351 hAutogenStr
+= String
.format(
352 "extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
355 cAutogenStr
+= String
.format(
356 "const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
360 hAutogenStr
+= String
.format(
361 "#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",
362 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
369 if(CommonDefinition
.isLibraryComponent(componentType
)) {
370 hAutogenStr
+= String
.format(
371 "extern const %s _gPcd_FixedAtBuild_%s;\r\n",
372 Token
.getAutogendatumTypeString(parentToken
.datumType
),
375 hAutogenStr
+= String
.format(
376 "#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
377 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
383 hAutogenStr
+= String
.format(
384 "#define _PCD_VALUE_%s %s\r\n",
388 hAutogenStr
+= String
.format(
389 "extern const %s _gPcd_FixedAtBuild_%s\r\n",
390 Token
.getAutogendatumTypeString(parentToken
.datumType
),
393 cAutogenStr
+= String
.format(
394 "const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
395 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
399 hAutogenStr
+= String
.format(
400 "#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",
401 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
407 case PATCHABLE_IN_MODULE
:
408 hAutogenStr
+= String
.format(
409 "#define _PCD_VALUE_%s %s\r\n",
413 hAutogenStr
+= String
.format(
414 "extern %s _gPcd_BinaryPatch_%s;\r\n",
415 Token
.getAutogendatumTypeString(parentToken
.datumType
),
419 cAutogenStr
+= String
.format(
420 "%s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;",
421 Token
.getAutogendatumTypeString(parentToken
.datumType
),
425 hAutogenStr
+= String
.format(
426 "#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
427 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
433 hAutogenStr
+= String
.format(
434 "#define _PCD_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",
435 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
437 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
444 "The PCD_TYPE setted by platform is unknown"
454 Get the autogen string for header file.
456 @return The string of header file.
458 public String
getHAutogenStr() {
463 Get the autogen string for C code file.
465 @return The string of C Code file.
467 public String
getCAutogenStr() {