]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/pcd/entity/UsageInstance.java
In before, FixedPcdGetxx macro was defined as global variable, it is wrong. It should...
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / pcd / entity / UsageInstance.java
1 /** @file
2 UsageInstance class.
3
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.
7
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
13
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.
16
17 **/
18 package org.tianocore.build.pcd.entity;
19
20
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;
26
27 /**
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.
31 **/
32 public class UsageInstance {
33 ///
34 /// This parent that this usage instance belongs to.
35 ///
36 public Token parentToken;
37
38 ///
39 /// The name of the module who contains this PCD.
40 ///
41 public String moduleName;
42
43 ///
44 /// The GUID of the module who contains this PCD.
45 ///
46 public UUID moduleGUID;
47
48 ///
49 /// The name of the package whose module contains this PCD.
50 ///
51 public String packageName;
52
53 ///
54 /// The GUID of the package whose module contains this PCD.
55 ///
56 public UUID packageGUID;
57
58 ///
59 /// The PCD type defined for module
60 ///
61 public Token.PCD_TYPE modulePcdType;
62
63 ///
64 /// The arch string of module contains this PCD
65 ///
66 public String arch;
67
68 ///
69 /// The version of module contains this PCD
70 ///
71 public String version;
72
73 ///
74 /// The module type for this usage instance.
75 ///
76 public ModuleTypeDef.Enum moduleType;
77
78 ///
79 /// The value of the PCD in this usage instance.
80 ///
81 public String datum;
82
83 ///
84 /// The maxDatumSize could be different for same PCD in different module
85 /// But this case is allow for FeatureFlag, FixedAtBuild, PatchableInModule
86 /// type.
87 ///
88 public int maxDatumSize;
89
90 ///
91 /// Autogen string for header file.
92 ///
93 public String hAutogenStr;
94
95 ///
96 /// Auotgen string for C code file.
97 ///
98 public String cAutogenStr;
99
100 /**
101 Constructure function
102
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.
114 */
115 public UsageInstance (Token parentToken,
116 String moduleName,
117 UUID moduleGUID,
118 String packageName,
119 UUID packageGUID,
120 ModuleTypeDef.Enum moduleType,
121 Token.PCD_TYPE modulePcdType,
122 String arch,
123 String version,
124 String value,
125 int maxDatumSize) {
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;
133 this.arch = arch;
134 this.version = version;
135 this.datum = value;
136 this.maxDatumSize = maxDatumSize;
137 }
138
139 /**
140 Get the primary key for usage instance array for every token.
141
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
148
149 @return String primary key
150 */
151 public static String getPrimaryKey(String moduleName,
152 UUID moduleGUID,
153 String packageName,
154 UUID packageGUID,
155 String arch,
156 String version) {
157 //
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"));
166 }
167
168 /**
169 Get primary key string for this usage instance
170
171 @return String primary key string
172 **/
173 public String getPrimaryKey() {
174 return UsageInstance.getPrimaryKey(moduleName, moduleGUID, packageName, packageGUID, arch, version);
175 }
176
177 /**
178 Judget whether current module is PEI driver
179
180 @return boolean
181 */
182 public boolean isPeiPhaseComponent() {
183 if ((moduleType == ModuleTypeDef.PEI_CORE) ||
184 (moduleType == ModuleTypeDef.PEIM)) {
185 return true;
186 }
187 return false;
188 }
189
190 /**
191 Generate autogen string for header file and C code file.
192
193 @throws EntityException Fail to generate.
194
195 @param isBuildUsedLibrary whether the autogen is for library.
196 */
197 public void generateAutoGen(boolean isBuildUsedLibrary)
198 throws EntityException {
199 String guidStringCName = null;
200 boolean isByteArray = false;
201 String printDatum = null;
202
203 hAutogenStr = "";
204 cAutogenStr = "";
205
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);
209 } else {
210 hAutogenStr += String.format("#define _PCD_TOKEN_%s 0x%016x\r\n",
211 parentToken.cName, parentToken.tokenNumber);
212 }
213
214 if (!isBuildUsedLibrary && !parentToken.isDynamicPCD) {
215 if (datum.trim().charAt(0) == '{') {
216 isByteArray = true;
217 }
218 }
219
220 if (parentToken.datumType == Token.DATUM_TYPE.UINT64) {
221 printDatum = this.datum + "ULL";
222 } else {
223 printDatum = this.datum;
224 }
225
226 switch (modulePcdType) {
227 case FEATURE_FLAG:
228 hAutogenStr += String.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
229 parentToken.cName);
230 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
231 parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType),
232 parentToken.cName,
233 parentToken.cName);
234
235 if (!isBuildUsedLibrary) {
236 hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n",
237 parentToken.cName,
238 printDatum);
239 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
240 parentToken.cName,
241 parentToken.cName);
242 }
243 break;
244 case FIXED_AT_BUILD:
245 if (isByteArray) {
246 hAutogenStr += String.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n",
247 parentToken.cName);
248 hAutogenStr += String.format("#define _PCD_MODE_%s_%s &_gPcd_FixedAtBuild_%s\r\n",
249 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
250 parentToken.cName,
251 parentToken.cName);
252 } else {
253 hAutogenStr += String.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",
254 Token.getAutogendatumTypeString(parentToken.datumType),
255 parentToken.cName);
256 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
257 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
258 parentToken.cName,
259 parentToken.cName);
260 }
261
262 if (!isBuildUsedLibrary) {
263 hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n",
264 parentToken.cName,
265 printDatum);
266 if (isByteArray) {
267 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = _PCD_VALUE_%s;\r\n",
268 parentToken.cName,
269 parentToken.cName);
270 } else {
271 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
272 Token.getAutogendatumTypeString(parentToken.datumType),
273 parentToken.cName,
274 parentToken.cName);
275 }
276 }
277 break;
278 case PATCHABLE_IN_MODULE:
279 if (isByteArray) {
280 hAutogenStr += String.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n",
281 parentToken.cName);
282 hAutogenStr += String.format("#define _PCD_MODE_%s_%s &_gPcd_BinaryPatch_%s\r\n",
283 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
284 parentToken.cName,
285 parentToken.cName);
286 } else {
287 hAutogenStr += String.format("extern %s _gPcd_BinaryPatch_%s;\r\n",
288 Token.getAutogendatumTypeString(parentToken.datumType),
289 parentToken.cName);
290 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
291 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
292 parentToken.cName,
293 parentToken.cName);
294 }
295
296 if (!isBuildUsedLibrary) {
297 hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n",
298 parentToken.cName,
299 printDatum);
300 if (isByteArray) {
301 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[] = _PCD_VALUE_%s;\r\n",
302 parentToken.cName,
303 parentToken.cName);
304 } else {
305 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",
306 Token.getAutogendatumTypeString(parentToken.datumType),
307 parentToken.cName,
308 parentToken.cName);
309 }
310 }
311
312 break;
313 case DYNAMIC:
314 hAutogenStr += String.format("#define _PCD_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",
315 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
316 parentToken.cName,
317 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),
318 parentToken.cName);
319 break;
320 case DYNAMIC_EX:
321 guidStringCName = "_gPcd_TokenSpaceGuid_" +
322 parentToken.tokenSpaceName.toString().replaceAll("-", "_");
323
324 hAutogenStr += String.format("#define _PCD_MODE_%s_%s LibPcdGetEx%s(&%s, _PCD_TOKEN_%s)\r\n",
325 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
326 parentToken.cName,
327 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),
328 guidStringCName,
329 parentToken.cName);
330
331 break;
332 }
333 }
334
335 /**
336 Get the autogen string for header file.
337
338 @return The string of header file.
339 **/
340 public String getHAutogenStr() {
341 return hAutogenStr;
342 }
343
344 /**
345 Get the autogen string for C code file.
346
347 @return The string of C Code file.
348 **/
349 public String getCAutogenStr() {
350 return cAutogenStr;
351 }
352 }
353