]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/pcd/entity/UsageInstance.java
3bebc45829afbcdb91e11c76abcd6b03d3fb8e74
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 if (isBuildUsedLibrary
) {
229 hAutogenStr
+= String
.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
231 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
232 parentToken
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
236 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
239 hAutogenStr
+= String
.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
241 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
244 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",
245 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
251 if (isBuildUsedLibrary
) {
252 hAutogenStr
+= String
.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",
253 Token
.getAutogendatumTypeString(parentToken
.datumType
),
255 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
256 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
260 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
264 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = _PCD_VALUE_%s;\r\n",
267 hAutogenStr
+= String
.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n",
269 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s &_gPcd_FixedAtBuild_%s\r\n",
270 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
274 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
275 Token
.getAutogendatumTypeString(parentToken
.datumType
),
278 hAutogenStr
+= String
.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",
279 Token
.getAutogendatumTypeString(parentToken
.datumType
),
281 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",
282 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
288 case PATCHABLE_IN_MODULE
:
289 if (isBuildUsedLibrary
) {
290 hAutogenStr
+= String
.format("extern %s _gPcd_BinaryPatch_%s;\r\n",
291 Token
.getAutogendatumTypeString(parentToken
.datumType
),
293 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
294 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
298 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
302 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[] = _PCD_VALUE_%s;\r\n",
305 hAutogenStr
+= String
.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n",
307 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s &_gPcd_BinaryPatch_%s\r\n",
308 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
312 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",
313 Token
.getAutogendatumTypeString(parentToken
.datumType
),
316 hAutogenStr
+= String
.format("extern %s _gPcd_BinaryPatch_%s;\r\n",
317 Token
.getAutogendatumTypeString(parentToken
.datumType
),
319 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
320 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
328 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",
329 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
331 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
335 guidStringCName
= "_gPcd_TokenSpaceGuid_" +
336 parentToken
.tokenSpaceName
.toString().replaceAll("-", "_");
338 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s LibPcdGetEx%s(&%s, _PCD_TOKEN_%s)\r\n",
339 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
341 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
350 Get the autogen string for header file.
352 @return The string of header file.
354 public String
getHAutogenStr() {
359 Get the autogen string for C code file.
361 @return The string of C Code file.
363 public String
getCAutogenStr() {