]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/GenBuild/org/tianocore/build/pcd/entity/UsageInstance.java
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@250 6f19259b...
[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 org.tianocore.build.pcd.exception.EntityException;
22 import org.tianocore.build.pcd.action.ActionMessage;
23
24 import org.tianocore.build.autogen.CommonDefinition;
25
26 /**
27 This class indicate an usage instance for a PCD token. This instance maybe a module
28 or platform setting. When a module produce or cosume a PCD token, then this module
29 is an usage instance for this PCD token.
30 **/
31 public class UsageInstance {
32 ///
33 /// This parent that this usage instance belongs to.
34 ///
35 public Token parentToken;
36 ///
37 /// The usage of this token for platform or module.
38 ///
39 public Token.PCD_USAGE usage;
40 ///
41 /// Whether this usage instance inherit from library
42 ///
43 public boolean isInherit;
44 ///
45 /// The pcd type of this token for module.
46 ///
47 public Token.PCD_TYPE modulePcdType;
48 ///
49 /// The name of the module who contains this PCD.
50 ///
51 public String moduleName;
52 ///
53 /// The name of the package whose module contains this PCD.
54 ///
55 public String packageName;
56 ///
57 /// The component type for this usage instance.
58 ///
59 public int componentType;
60 ///
61 /// The default value defined in MSA has high prior than defined in SPD.
62 ///
63 public Object defaultValueInMSA;
64 ///
65 /// The default value defined in SPD.
66 ///
67 public Object defaultValueInSPD;
68 ///
69 /// Help text in MSA
70 ///
71 public String helpTextInMSA;
72 ///
73 /// Help text in SPD
74 ///
75 public String helpTextInSPD;
76 ///
77 /// Autogen string for header file.
78 ///
79 public String hAutogenStr;
80 /**
81 * Auotgen string for C code file.
82 */
83 public String cAutogenStr;
84
85 /**
86 Constructure function
87
88 @param parentToken Member variable.
89 @param usage Member variable.
90 @param pcdType Member variable.
91 @param componentType Member variable.
92 @param defaultValueInMSA Member variable.
93 @param defaultValueInSPD Member variable.
94 @param helpTextInMSA Member variable.
95 @param helpTextInSPD Member variable.
96 @param moduleName Member variable.
97 @param packageName Member variable.
98 @param isInherit Member variable.
99 **/
100 public UsageInstance(
101 Token parentToken,
102 Token.PCD_USAGE usage,
103 Token.PCD_TYPE pcdType,
104 int componentType,
105 Object defaultValueInMSA,
106 Object defaultValueInSPD,
107 String helpTextInMSA,
108 String helpTextInSPD,
109 String moduleName,
110 String packageName,
111 boolean isInherit
112 )
113 {
114 this.parentToken = parentToken;
115 this.usage = usage;
116 this.modulePcdType = pcdType;
117 this.componentType = componentType;
118 this.defaultValueInMSA = defaultValueInMSA;
119 this.defaultValueInSPD = defaultValueInSPD;
120 this.helpTextInMSA = helpTextInMSA;
121 this.helpTextInSPD = helpTextInSPD;
122 this.moduleName = moduleName;
123 this.packageName = packageName;
124 this.isInherit = isInherit;
125 }
126
127 /**
128 Generate autogen string for header file and C code file.
129
130 @throws EntityException Fail to generate.
131 **/
132 public void generateAutoGen() throws EntityException {
133 Object value = null;
134 int tokenNumber = 0;
135
136 hAutogenStr = "";
137 cAutogenStr = "";
138
139 value = this.parentToken.datum;
140
141 //
142 // If this pcd token's PCD_TYPE is DYNAMIC_EX, use itself token space name
143 // otherwices use assgined token space name from tool automatically.
144 //
145 if(parentToken.pcdType == Token.PCD_TYPE.DYNAMIC_EX) {
146 tokenNumber = parentToken.tokenNumber;
147 } else {
148 tokenNumber = parentToken.assignedtokenNumber;
149 }
150
151 hAutogenStr += String.format("#define _PCD_TOKEN_%s 0x%016x\r\n",
152 parentToken.cName, tokenNumber);
153
154 switch(modulePcdType) {
155 case FEATURE_FLAG:
156 //
157 // BUGBUG: The judegement of module PCD type and platform PCD type should not be
158 // done here, but in wizard tools, But here is just following something
159 // PcdEmulation driver.
160 //
161 if(parentToken.pcdType.ordinal() > Token.PCD_TYPE.FEATURE_FLAG.ordinal()) {
162 throw new EntityException(
163 String.format(
164 "%s:Platform PCD Type %d is not compatible with Module PCD Type %d\r\n",
165 parentToken.cName,
166 parentToken.pcdType.name(),
167 modulePcdType.name()
168 )
169 );
170 }
171
172 if(CommonDefinition.isLibraryComponent(componentType)) {
173 hAutogenStr += String.format(
174 "extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
175 parentToken.cName
176 );
177 hAutogenStr += String.format(
178 "#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
179 parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType),
180 parentToken.cName,
181 parentToken.cName
182 );
183 } else {
184 hAutogenStr += String.format(
185 "#define _PCD_VALUE_%s %s\r\n",
186 parentToken.cName,
187 value.toString()
188 );
189 hAutogenStr += String.format(
190 "extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
191 parentToken.cName
192 );
193 cAutogenStr += String.format(
194 "GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
195 parentToken.cName,
196 parentToken.cName
197 );
198 hAutogenStr += String.format(
199 "#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",
200 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
201 parentToken.cName,
202 parentToken.cName
203 );
204 }
205 break;
206 case FIXED_AT_BUILD:
207 //
208 // BUGBUG: The judegement of module PCD type and platform PCD type should not be
209 // done here, but in wizard tools, But here is just following something
210 // PcdEmulation driver.
211 //
212 if(parentToken.pcdType.ordinal() > Token.PCD_TYPE.FIXED_AT_BUILD.ordinal()) {
213 throw new EntityException(
214 String.format(
215 "%s:Platform PCD Type %d is not compatible with Module PCD Type %d\r\n",
216 parentToken.cName,
217 parentToken.pcdType.name(),
218 modulePcdType.name()
219 )
220 );
221 }
222
223 if(CommonDefinition.isLibraryComponent(componentType)) {
224 hAutogenStr += String.format(
225 "extern const %s _gPcd_FixedAtBuild_%s;\r\n",
226 Token.getAutogendatumTypeString(parentToken.datumType),
227 parentToken.cName
228 );
229 hAutogenStr += String.format(
230 "#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
231 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
232 parentToken.cName,
233 parentToken.cName
234 );
235 } else {
236 hAutogenStr += String.format(
237 "#define _PCD_VALUE_%s %s\r\n",
238 parentToken.cName,
239 value.toString()
240 );
241 hAutogenStr += String.format(
242 "extern const %s _gPcd_FixedAtBuild_%s;\r\n",
243 Token.getAutogendatumTypeString(parentToken.datumType),
244 parentToken.cName
245 );
246 cAutogenStr += String.format(
247 "GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
248 Token.getAutogendatumTypeString(parentToken.datumType),
249 parentToken.cName,
250 parentToken.cName
251 );
252 hAutogenStr += String.format(
253 "#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",
254 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
255 parentToken.cName,
256 parentToken.cName
257 );
258 }
259 break;
260 case PATCHABLE_IN_MODULE:
261 //
262 // BUGBUG: The judegement of module PCD type and platform PCD type should not be
263 // done here, but in wizard tools, But here is just following something
264 // PcdEmulation driver.
265 //
266 if(parentToken.pcdType.ordinal() > Token.PCD_TYPE.PATCHABLE_IN_MODULE.ordinal()) {
267 throw new EntityException(
268 String.format(
269 "%s:Platform PCD Type %d is not compatible with Module PCD Type %d\r\n",
270 parentToken.cName,
271 parentToken.pcdType.name(),
272 modulePcdType.name()
273 )
274 );
275 }
276
277 if(CommonDefinition.isLibraryComponent(componentType)) {
278 hAutogenStr += String.format(
279 "extern %s _gPcd_BinaryPatch_%s;\r\n",
280 Token.getAutogendatumTypeString(parentToken.datumType),
281 parentToken.cName
282 );
283 hAutogenStr += String.format(
284 "#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
285 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
286 parentToken.cName,
287 parentToken.cName
288 );
289 } else {
290 hAutogenStr += String.format(
291 "#define _PCD_VALUE_%s %s\r\n",
292 parentToken.cName,
293 value
294 );
295 hAutogenStr += String.format(
296 "extern %s _gPcd_BinaryPatch_%s;\r\n",
297 Token.getAutogendatumTypeString(parentToken.datumType),
298 parentToken.cName
299 );
300 cAutogenStr += String.format(
301 "GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",
302 Token.getAutogendatumTypeString(parentToken.datumType),
303 parentToken.cName,
304 parentToken.cName
305 );
306 hAutogenStr += String.format(
307 "#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
308 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
309 parentToken.cName,
310 parentToken.cName
311 );
312 }
313
314 break;
315 case DYNAMIC:
316 //
317 // BUGBUG: The judegement of module PCD type and platform PCD type should not be
318 // done here, but in wizard tools, But here is just following something
319 // PcdEmulation driver.
320 //
321 if(parentToken.pcdType.ordinal() > Token.PCD_TYPE.DYNAMIC.ordinal()) {
322 throw new EntityException(
323 String.format(
324 "%s:Platform PCD Type %d is not compatible with Module PCD Type %d\r\n",
325 parentToken.cName,
326 parentToken.pcdType.name(),
327 modulePcdType.name()
328 )
329 );
330 }
331
332 switch(parentToken.pcdType) {
333 case FEATURE_FLAG:
334 if(CommonDefinition.isLibraryComponent(componentType)) {
335 hAutogenStr += String.format(
336 "extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
337 parentToken.cName
338 );
339 hAutogenStr += String.format(
340 "#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
341 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
342 parentToken.cName,
343 parentToken.cName
344 );
345 } else {
346 hAutogenStr += String.format(
347 "#define _PCD_VALUE_%s %s\r\n",
348 parentToken.cName,
349 value
350 );
351 hAutogenStr += String.format(
352 "extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n",
353 parentToken.cName
354 );
355 cAutogenStr += String.format(
356 "const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
357 parentToken.cName,
358 parentToken.cName
359 );
360 hAutogenStr += String.format(
361 "#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",
362 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
363 parentToken.cName,
364 parentToken.cName
365 );
366 }
367 break;
368 case FIXED_AT_BUILD:
369 if(CommonDefinition.isLibraryComponent(componentType)) {
370 hAutogenStr += String.format(
371 "extern const %s _gPcd_FixedAtBuild_%s;\r\n",
372 Token.getAutogendatumTypeString(parentToken.datumType),
373 parentToken.cName
374 );
375 hAutogenStr += String.format(
376 "#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",
377 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
378 parentToken.cName,
379 parentToken.cName
380 );
381
382 } else {
383 hAutogenStr += String.format(
384 "#define _PCD_VALUE_%s %s\r\n",
385 parentToken.cName,
386 value
387 );
388 hAutogenStr += String.format(
389 "extern const %s _gPcd_FixedAtBuild_%s\r\n",
390 Token.getAutogendatumTypeString(parentToken.datumType),
391 parentToken.cName
392 );
393 cAutogenStr += String.format(
394 "const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",
395 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
396 parentToken.cName,
397 parentToken.cName
398 );
399 hAutogenStr += String.format(
400 "#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",
401 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
402 parentToken.cName,
403 parentToken.cName
404 );
405 }
406 break;
407 case PATCHABLE_IN_MODULE:
408 hAutogenStr += String.format(
409 "#define _PCD_VALUE_%s %s\r\n",
410 parentToken.cName,
411 value
412 );
413 hAutogenStr += String.format(
414 "extern %s _gPcd_BinaryPatch_%s;\r\n",
415 Token.getAutogendatumTypeString(parentToken.datumType),
416 parentToken.cName,
417 parentToken.cName
418 );
419 cAutogenStr += String.format(
420 "%s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;",
421 Token.getAutogendatumTypeString(parentToken.datumType),
422 parentToken.cName,
423 parentToken.cName
424 );
425 hAutogenStr += String.format(
426 "#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",
427 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
428 parentToken.cName,
429 parentToken.cName
430 );
431 break;
432 case DYNAMIC:
433 hAutogenStr += "\r\n";
434 hAutogenStr += String.format(
435 "#define _PCD_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",
436 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),
437 parentToken.cName,
438 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),
439 parentToken.cName
440 );
441 break;
442 default:
443 ActionMessage.log(
444 this,
445 "The PCD_TYPE setted by platform is unknown"
446 );
447 }
448 break;
449 case DYNAMIC_EX:
450 break;
451 }
452 }
453
454 /**
455 Get the autogen string for header file.
456
457 @return The string of header file.
458 **/
459 public String getHAutogenStr() {
460 return hAutogenStr;
461 }
462
463 /**
464 Get the autogen string for C code file.
465
466 @return The string of C Code file.
467 **/
468 public String getCAutogenStr() {
469 return cAutogenStr;
470 }
471 }
472