]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/pcd/entity/UsageInstance.java
Fix a bug when generate default value for byte array for FIXED_AT_BUILD, PATCHABLE_IN...
[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
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 /// The module type of usage instance.
35 ///
36 public enum MODULE_TYPE {SEC, PEI_CORE, PEIM, DXE_CORE, DXE_DRIVERS, OTHER_COMPONENTS}
37
38 ///
39 /// This parent that this usage instance belongs to.
40 ///
41 public Token parentToken;
42
43 ///
44 /// The name of the module who contains this PCD.
45 ///
46 public String moduleName;
47
48 ///
49 /// The GUID of the module who contains this PCD.
50 ///
51 public UUID moduleGUID;
52
53 ///
54 /// The name of the package whose module contains this PCD.
55 ///
56 public String packageName;
57
58 ///
59 /// The GUID of the package whose module contains this PCD.
60 ///
61 public UUID packageGUID;
62
63 ///
64 /// The PCD type defined for module
65 ///
66 public Token.PCD_TYPE modulePcdType;
67
68 ///
69 /// The arch string of module contains this PCD
70 ///
71 public String arch;
72
73 ///
74 /// The version of module contains this PCD
75 ///
76 public String version;
77
78 ///
79 /// The module type for this usage instance.
80 ///
81 public MODULE_TYPE moduleType;
82
83 ///
84 /// The value of the PCD in this usage instance.
85 ///
86 public String datum;
87
88 ///
89 /// The maxDatumSize could be different for same PCD in different module
90 /// But this case is allow for FeatureFlag, FixedAtBuild, PatchableInModule
91 /// type.
92 ///
93 public int maxDatumSize;
94
95 ///
96 /// Autogen string for header file.
97 ///
98 public String hAutogenStr;
99
100 ///
101 /// Auotgen string for C code file.
102 ///
103 public String cAutogenStr;
104
105 /**
106 Constructure function
107
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.
119 */
120 public UsageInstance (Token parentToken,
121 String moduleName,
122 UUID moduleGUID,
123 String packageName,
124 UUID packageGUID,
125 MODULE_TYPE moduleType,
126 Token.PCD_TYPE modulePcdType,
127 String arch,
128 String version,
129 String value,
130 int maxDatumSize) {
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;
138 this.arch = arch;
139 this.version = version;
140 this.datum = value;
141 this.maxDatumSize = maxDatumSize;
142 }
143
144 /**
145 Get the primary key for usage instance array for every token.
146
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
153
154 @return String primary key
155 */
156 public static String getPrimaryKey(String moduleName,
157 UUID moduleGUID,
158 String packageName,
159 UUID packageGUID,
160 String arch,
161 String version) {
162 //
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"));
171 }
172
173 /**
174 Get primary key string for this usage instance
175
176 @return String primary key string
177 **/
178 public String getPrimaryKey() {
179 return UsageInstance.getPrimaryKey(moduleName, moduleGUID, packageName, packageGUID, arch, version);
180 }
181
182 /**
183 Judget whether current module is PEI driver
184
185 @return boolean
186 */
187 public boolean isPeiPhaseComponent() {
188 if ((moduleType == MODULE_TYPE.PEI_CORE) ||
189 (moduleType == MODULE_TYPE.PEIM)) {
190 return true;
191 }
192 return false;
193 }
194
195 /**
196 Generate autogen string for header file and C code file.
197
198 @throws EntityException Fail to generate.
199
200 @param isBuildUsedLibrary whether the autogen is for library.
201 */
202 public void generateAutoGen(boolean isBuildUsedLibrary)
203 throws EntityException {
204 String guidStringArray[] = null;
205 String guidString = null;
206 boolean isByteArray = false;
207
208 hAutogenStr = "";
209 cAutogenStr = "";
210
211 if (this.modulePcdType == Token.PCD_TYPE.DYNAMIC_EX) {
212 hAutogenStr += String.format("#define _PCD_LOCAL_TOKEN_%s 0x%016x\r\n",
213 parentToken.cName, parentToken.tokenNumber);
214 hAutogenStr += String.format("#define _PCD_TOKEN_%s 0x%016x\r\n",
215 parentToken.cName, parentToken.dynamicExTokenNumber);
216 } else {
217 hAutogenStr += String.format("#define _PCD_TOKEN_%s 0x%016x\r\n",
218 parentToken.cName, parentToken.tokenNumber);
219 }
220
221 if (!isBuildUsedLibrary && !parentToken.isDynamicPCD) {
222 if (datum.trim().charAt(0) == '{') {
223 isByteArray = true;
224 }
225 }
226
227 switch (modulePcdType) {
228 case FEATURE_FLAG:
229 if (isBuildUsedLibrary) {
230 hAutogenStr += String.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
231 parentToken.cName);
232 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
233 parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType),
234 parentToken.cName,
235 parentToken.cName);
236 } else {
237 hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n",
238 parentToken.cName,
239 datum.toString());
240 hAutogenStr += String.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
241 parentToken.cName);
242 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
243 parentToken.cName,
244 parentToken.cName);
245 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",
246 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
247 parentToken.cName,
248 parentToken.cName);
249 }
250 break;
251 case FIXED_AT_BUILD:
252 if (isBuildUsedLibrary) {
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 } else {
261 hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n",
262 parentToken.cName,
263 datum.toString());
264 if (isByteArray) {
265 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = _PCD_VALUE_%s;\r\n",
266 parentToken.cName,
267 parentToken.cName);
268 hAutogenStr += String.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n",
269 parentToken.cName);
270 hAutogenStr += String.format("#define _PCD_MODE_%s_%s &_gPcd_FixedAtBuild_%s\r\n",
271 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
272 parentToken.cName,
273 parentToken.cName);
274 } else {
275 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
276 Token.getAutogendatumTypeString(parentToken.datumType),
277 parentToken.cName,
278 parentToken.cName);
279 hAutogenStr += String.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",
280 Token.getAutogendatumTypeString(parentToken.datumType),
281 parentToken.cName);
282 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",
283 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
284 parentToken.cName,
285 parentToken.cName);
286 }
287 }
288 break;
289 case PATCHABLE_IN_MODULE:
290 if (isBuildUsedLibrary) {
291 hAutogenStr += String.format("extern %s _gPcd_BinaryPatch_%s;\r\n",
292 Token.getAutogendatumTypeString(parentToken.datumType),
293 parentToken.cName);
294 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
295 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
296 parentToken.cName,
297 parentToken.cName);
298 } else {
299 hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n",
300 parentToken.cName,
301 datum.toString());
302 if (isByteArray) {
303 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[] = _PCD_VALUE_%s;\r\n",
304 parentToken.cName,
305 parentToken.cName);
306 hAutogenStr += String.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n",
307 parentToken.cName);
308 hAutogenStr += String.format("#define _PCD_MODE_%s_%s &_gPcd_BinaryPatch_%s\r\n",
309 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
310 parentToken.cName,
311 parentToken.cName);
312 } else {
313 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",
314 Token.getAutogendatumTypeString(parentToken.datumType),
315 parentToken.cName,
316 parentToken.cName);
317 hAutogenStr += String.format("extern %s _gPcd_BinaryPatch_%s;\r\n",
318 Token.getAutogendatumTypeString(parentToken.datumType),
319 parentToken.cName);
320 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
321 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
322 parentToken.cName,
323 parentToken.cName);
324 }
325 }
326
327 break;
328 case DYNAMIC:
329 hAutogenStr += String.format("#define _PCD_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",
330 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
331 parentToken.cName,
332 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),
333 parentToken.cName);
334 break;
335 case DYNAMIC_EX:
336 guidStringArray = parentToken.tokenSpaceName.toString().split("-");
337 guidString = String.format("{ 0x%s, 0x%s, 0x%s, {0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s}}",
338 guidStringArray[0],
339 guidStringArray[1],
340 guidStringArray[2],
341 (guidStringArray[3].substring(0, 2)),
342 (guidStringArray[3].substring(2, 4)),
343 (guidStringArray[4].substring(0, 2)),
344 (guidStringArray[4].substring(2, 4)),
345 (guidStringArray[4].substring(4, 6)),
346 (guidStringArray[4].substring(6, 8)),
347 (guidStringArray[4].substring(8, 10)),
348 (guidStringArray[4].substring(10, 12)));
349
350 hAutogenStr += String.format("extern EFI_GUID _gPcd_DynamicEx_TokenSpaceGuid_%s;\r\n",
351 parentToken.cName);
352 hAutogenStr += String.format("#define _PCD_MODE_%s_%s LibPcdGet%s(_PCD_LOCAL_TOKEN_%s)\r\n",
353 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
354 parentToken.cName,
355 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),
356 parentToken.cName,
357 parentToken.cName);
358
359 if (!isBuildUsedLibrary) {
360 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED EFI_GUID _gPcd_DynamicEx_TokenSpaceGuid_%s = %s;\r\n",
361 parentToken.cName,
362 guidString);
363 }
364 break;
365 }
366 }
367
368 /**
369 Get the autogen string for header file.
370
371 @return The string of header file.
372 **/
373 public String getHAutogenStr() {
374 return hAutogenStr;
375 }
376
377 /**
378 Get the autogen string for C code file.
379
380 @return The string of C Code file.
381 **/
382 public String getCAutogenStr() {
383 return cAutogenStr;
384 }
385 }
386