]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/pcd/entity/UsageInstance.java
2769d497f70d75e0e9831b64857fa38e3d571210
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
;
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 /// The module type of usage instance.
36 public enum MODULE_TYPE
{SEC
, PEI_CORE
, PEIM
, DXE_CORE
, DXE_DRIVERS
, OTHER_COMPONENTS
}
39 /// This parent that this usage instance belongs to.
41 public Token parentToken
;
44 /// The name of the module who contains this PCD.
46 public String moduleName
;
49 /// The GUID of the module who contains this PCD.
51 public UUID moduleGUID
;
54 /// The name of the package whose module contains this PCD.
56 public String packageName
;
59 /// The GUID of the package whose module contains this PCD.
61 public UUID packageGUID
;
64 /// The PCD type defined for module
66 public Token
.PCD_TYPE modulePcdType
;
69 /// The arch string of module contains this PCD
74 /// The version of module contains this PCD
76 public String version
;
79 /// The module type for this usage instance.
81 public MODULE_TYPE moduleType
;
84 /// The value of the PCD in this usage instance.
89 /// The maxDatumSize could be different for same PCD in different module
90 /// But this case is allow for FeatureFlag, FixedAtBuild, PatchableInModule
93 public int maxDatumSize
;
96 /// Autogen string for header file.
98 public String hAutogenStr
;
101 /// Auotgen string for C code file.
103 public String cAutogenStr
;
106 Constructure function
108 @param parentToken Member variable.
109 @param moduleName Member variable.
110 @param moduleGUID Member variable.
111 @param packageName Member variable.
112 @param packageGUID Member variable.
113 @param moduleType Member variable.
114 @param modulePcdType Member variable.
115 @param arch Member variable.
116 @param version Member variable.
117 @param value Member variable.
118 @param maxDatumSize Member variable.
120 public UsageInstance (Token parentToken
,
125 MODULE_TYPE moduleType
,
126 Token
.PCD_TYPE modulePcdType
,
131 this.parentToken
= parentToken
;
132 this.moduleName
= moduleName
;
133 this.moduleGUID
= moduleGUID
;
134 this.packageName
= packageName
;
135 this.packageGUID
= packageGUID
;
136 this.moduleType
= moduleType
;
137 this.modulePcdType
= modulePcdType
;
139 this.version
= version
;
141 this.maxDatumSize
= maxDatumSize
;
145 Get the primary key for usage instance array for every token.
147 @param moduleName the name of module
148 @param moduleGUID the GUID name of module
149 @param packageName the name of package who contains this module
150 @param packageGUID the GUID name of package
151 @param arch the archtecture string
152 @param version the version of this module
154 @return String primary key
156 public static String
getPrimaryKey(String moduleName
,
163 // Because currently transition schema not require write moduleGuid, package Name, Packge GUID in
164 // <ModuleSA> section, So currently no expect all paramter must be valid.
165 return(moduleName
+ "_" +
166 ((moduleGUID
!= null) ? moduleGUID
.toString() : "NullModuleGuid") + "_" +
167 ((packageName
!= null) ? packageName
: "NullPackageName") + "_" +
168 ((packageGUID
!= null) ? packageGUID
.toString() : "NullPackageGuid") + "_" +
169 ((arch
!= null) ? arch
: "NullArch") + "_" +
170 ((version
!= null) ? version
: "NullVersion"));
174 Get primary key string for this usage instance
176 @return String primary key string
178 public String
getPrimaryKey() {
179 return UsageInstance
.getPrimaryKey(moduleName
, moduleGUID
, packageName
, packageGUID
, arch
, version
);
183 Judget whether current module is PEI driver
187 public boolean isPeiPhaseComponent() {
188 if ((moduleType
== MODULE_TYPE
.PEI_CORE
) ||
189 (moduleType
== MODULE_TYPE
.PEIM
)) {
196 Generate autogen string for header file and C code file.
198 @throws EntityException Fail to generate.
200 @param isBuildUsedLibrary whether the autogen is for library.
202 public void generateAutoGen(boolean isBuildUsedLibrary
)
203 throws EntityException
{
204 String guidStringCName
= null;
205 boolean isByteArray
= false;
206 String printDatum
= null;
211 if (this.modulePcdType
== Token
.PCD_TYPE
.DYNAMIC_EX
) {
212 hAutogenStr
+= String
.format("#define _PCD_TOKEN_%s 0x%016x\r\n",
213 parentToken
.cName
, parentToken
.dynamicExTokenNumber
);
215 hAutogenStr
+= String
.format("#define _PCD_TOKEN_%s 0x%016x\r\n",
216 parentToken
.cName
, parentToken
.tokenNumber
);
219 if (!isBuildUsedLibrary
&& !parentToken
.isDynamicPCD
) {
220 if (datum
.trim().charAt(0) == '{') {
225 if (parentToken
.datumType
== Token
.DATUM_TYPE
.UINT64
) {
226 printDatum
= this.datum
+ "ULL";
228 printDatum
= this.datum
;
231 switch (modulePcdType
) {
233 if (isBuildUsedLibrary
) {
234 hAutogenStr
+= String
.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
236 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
237 parentToken
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
241 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
244 hAutogenStr
+= String
.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
246 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
249 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",
250 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
256 if (isBuildUsedLibrary
) {
257 hAutogenStr
+= String
.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",
258 Token
.getAutogendatumTypeString(parentToken
.datumType
),
260 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
261 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
265 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
269 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = _PCD_VALUE_%s;\r\n",
272 hAutogenStr
+= String
.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n",
274 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s &_gPcd_FixedAtBuild_%s\r\n",
275 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
279 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
280 Token
.getAutogendatumTypeString(parentToken
.datumType
),
283 hAutogenStr
+= String
.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",
284 Token
.getAutogendatumTypeString(parentToken
.datumType
),
286 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",
287 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
293 case PATCHABLE_IN_MODULE
:
294 if (isBuildUsedLibrary
) {
295 hAutogenStr
+= String
.format("extern %s _gPcd_BinaryPatch_%s;\r\n",
296 Token
.getAutogendatumTypeString(parentToken
.datumType
),
298 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
299 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
303 hAutogenStr
+= String
.format("#define _PCD_VALUE_%s %s\r\n",
307 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[] = _PCD_VALUE_%s;\r\n",
310 hAutogenStr
+= String
.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n",
312 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s &_gPcd_BinaryPatch_%s\r\n",
313 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
317 cAutogenStr
+= String
.format("GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",
318 Token
.getAutogendatumTypeString(parentToken
.datumType
),
321 hAutogenStr
+= String
.format("extern %s _gPcd_BinaryPatch_%s;\r\n",
322 Token
.getAutogendatumTypeString(parentToken
.datumType
),
324 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
325 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
333 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",
334 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
336 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
340 guidStringCName
= "_gPcd_TokenSpaceGuid_" +
341 parentToken
.tokenSpaceName
.toString().replaceAll("-", "_");
343 hAutogenStr
+= String
.format("#define _PCD_MODE_%s_%s LibPcdGetEx%s(&%s, _PCD_TOKEN_%s)\r\n",
344 Token
.GetAutogenDefinedatumTypeString(parentToken
.datumType
),
346 Token
.getAutogenLibrarydatumTypeString(parentToken
.datumType
),
355 Get the autogen string for header file.
357 @return The string of header file.
359 public String
getHAutogenStr() {
364 Get the autogen string for C code file.
366 @return The string of C Code file.
368 public String
getCAutogenStr() {