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