]> 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 if (isBuildUsedLibrary) {
229 hAutogenStr += String.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
230 parentToken.cName);
231 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
232 parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType),
233 parentToken.cName,
234 parentToken.cName);
235 } else {
236 hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n",
237 parentToken.cName,
238 printDatum);
239 hAutogenStr += String.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
240 parentToken.cName);
241 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
242 parentToken.cName,
243 parentToken.cName);
244 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",
245 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
246 parentToken.cName,
247 parentToken.cName);
248 }
249 break;
250 case FIXED_AT_BUILD:
251 if (isBuildUsedLibrary) {
252 hAutogenStr += String.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",
253 Token.getAutogendatumTypeString(parentToken.datumType),
254 parentToken.cName);
255 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
256 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
257 parentToken.cName,
258 parentToken.cName);
259 } else {
260 hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n",
261 parentToken.cName,
262 printDatum);
263 if (isByteArray) {
264 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = _PCD_VALUE_%s;\r\n",
265 parentToken.cName,
266 parentToken.cName);
267 hAutogenStr += String.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n",
268 parentToken.cName);
269 hAutogenStr += String.format("#define _PCD_MODE_%s_%s &_gPcd_FixedAtBuild_%s\r\n",
270 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
271 parentToken.cName,
272 parentToken.cName);
273 } else {
274 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
275 Token.getAutogendatumTypeString(parentToken.datumType),
276 parentToken.cName,
277 parentToken.cName);
278 hAutogenStr += String.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",
279 Token.getAutogendatumTypeString(parentToken.datumType),
280 parentToken.cName);
281 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",
282 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
283 parentToken.cName,
284 parentToken.cName);
285 }
286 }
287 break;
288 case PATCHABLE_IN_MODULE:
289 if (isBuildUsedLibrary) {
290 hAutogenStr += String.format("extern %s _gPcd_BinaryPatch_%s;\r\n",
291 Token.getAutogendatumTypeString(parentToken.datumType),
292 parentToken.cName);
293 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
294 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
295 parentToken.cName,
296 parentToken.cName);
297 } else {
298 hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n",
299 parentToken.cName,
300 printDatum);
301 if (isByteArray) {
302 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[] = _PCD_VALUE_%s;\r\n",
303 parentToken.cName,
304 parentToken.cName);
305 hAutogenStr += String.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n",
306 parentToken.cName);
307 hAutogenStr += String.format("#define _PCD_MODE_%s_%s &_gPcd_BinaryPatch_%s\r\n",
308 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
309 parentToken.cName,
310 parentToken.cName);
311 } else {
312 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",
313 Token.getAutogendatumTypeString(parentToken.datumType),
314 parentToken.cName,
315 parentToken.cName);
316 hAutogenStr += String.format("extern %s _gPcd_BinaryPatch_%s;\r\n",
317 Token.getAutogendatumTypeString(parentToken.datumType),
318 parentToken.cName);
319 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
320 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
321 parentToken.cName,
322 parentToken.cName);
323 }
324 }
325
326 break;
327 case DYNAMIC:
328 hAutogenStr += String.format("#define _PCD_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",
329 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
330 parentToken.cName,
331 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),
332 parentToken.cName);
333 break;
334 case DYNAMIC_EX:
335 guidStringCName = "_gPcd_TokenSpaceGuid_" +
336 parentToken.tokenSpaceName.toString().replaceAll("-", "_");
337
338 hAutogenStr += String.format("#define _PCD_MODE_%s_%s LibPcdGetEx%s(&%s, _PCD_TOKEN_%s)\r\n",
339 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
340 parentToken.cName,
341 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),
342 guidStringCName,
343 parentToken.cName);
344
345 break;
346 }
347 }
348
349 /**
350 Get the autogen string for header file.
351
352 @return The string of header file.
353 **/
354 public String getHAutogenStr() {
355 return hAutogenStr;
356 }
357
358 /**
359 Get the autogen string for C code file.
360
361 @return The string of C Code file.
362 **/
363 public String getCAutogenStr() {
364 return cAutogenStr;
365 }
366 }
367