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
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
8840ad58 21import java.util.UUID;\r
03b1a72d 22import org.tianocore.ModuleTypeDef;\r
878ddf1f 23import org.tianocore.build.autogen.CommonDefinition;\r
8840ad58 24import org.tianocore.build.pcd.action.ActionMessage;\r
25import org.tianocore.build.pcd.exception.EntityException;\r
878ddf1f 26\r
27/**\r
28 This class indicate an usage instance for a PCD token. This instance maybe a module\r
29 or platform setting. When a module produce or cosume a PCD token, then this module\r
30 is an usage instance for this PCD token.\r
31**/\r
32public class UsageInstance {\r
38ee8d9e 33 ///\r
34 /// This parent that this usage instance belongs to.\r
35 ///\r
36 public Token parentToken;\r
37\r
38 ///\r
39 /// The name of the module who contains this PCD.\r
40 ///\r
41 public String moduleName;\r
42\r
43 ///\r
44 /// The GUID of the module who contains this PCD. \r
45 /// \r
46 public UUID moduleGUID;\r
47\r
48 ///\r
49 /// The name of the package whose module contains this PCD.\r
50 ///\r
51 public String packageName;\r
52\r
53 ///\r
54 /// The GUID of the package whose module contains this PCD.\r
55 /// \r
56 public UUID packageGUID;\r
57\r
58 ///\r
59 /// The PCD type defined for module \r
60 /// \r
61 public Token.PCD_TYPE modulePcdType;\r
62\r
63 ///\r
64 /// The arch string of module contains this PCD\r
65 ///\r
66 public String arch;\r
67\r
68 ///\r
69 /// The version of module contains this PCD\r
70 /// \r
71 public String version;\r
72\r
73 ///\r
74 /// The module type for this usage instance.\r
75 ///\r
03b1a72d 76 public ModuleTypeDef.Enum moduleType;\r
38ee8d9e 77\r
78 ///\r
79 /// The value of the PCD in this usage instance. \r
80 /// \r
81 public String datum;\r
82\r
83 ///\r
84 /// The maxDatumSize could be different for same PCD in different module\r
85 /// But this case is allow for FeatureFlag, FixedAtBuild, PatchableInModule\r
86 /// type.\r
87 /// \r
88 public int maxDatumSize;\r
89\r
90 ///\r
91 /// Autogen string for header file.\r
92 ///\r
93 public String hAutogenStr;\r
94\r
95 ///\r
96 /// Auotgen string for C code file.\r
97 /// \r
98 public String cAutogenStr;\r
99\r
100 /**\r
101 Constructure function\r
102 \r
103 @param parentToken Member variable.\r
104 @param moduleName Member variable.\r
105 @param moduleGUID Member variable.\r
106 @param packageName Member variable.\r
107 @param packageGUID Member variable.\r
108 @param moduleType Member variable.\r
109 @param modulePcdType Member variable.\r
110 @param arch Member variable.\r
111 @param version Member variable.\r
112 @param value Member variable.\r
113 @param maxDatumSize Member variable.\r
114 */\r
115 public UsageInstance (Token parentToken,\r
116 String moduleName,\r
117 UUID moduleGUID,\r
118 String packageName,\r
119 UUID packageGUID,\r
03b1a72d 120 ModuleTypeDef.Enum moduleType,\r
38ee8d9e 121 Token.PCD_TYPE modulePcdType,\r
122 String arch,\r
123 String version,\r
124 String value,\r
125 int maxDatumSize) {\r
126 this.parentToken = parentToken;\r
127 this.moduleName = moduleName;\r
128 this.moduleGUID = moduleGUID;\r
129 this.packageName = packageName;\r
130 this.packageGUID = packageGUID;\r
131 this.moduleType = moduleType;\r
132 this.modulePcdType = modulePcdType;\r
133 this.arch = arch;\r
134 this.version = version;\r
135 this.datum = value;\r
136 this.maxDatumSize = maxDatumSize;\r
137 }\r
138\r
139 /**\r
140 Get the primary key for usage instance array for every token.\r
141 \r
142 @param moduleName the name of module\r
143 @param moduleGUID the GUID name of module\r
144 @param packageName the name of package who contains this module\r
145 @param packageGUID the GUID name of package\r
146 @param arch the archtecture string\r
147 @param version the version of this module\r
148 \r
149 @return String primary key\r
150 */\r
151 public static String getPrimaryKey(String moduleName, \r
152 UUID moduleGUID, \r
153 String packageName, \r
154 UUID packageGUID,\r
155 String arch,\r
156 String version) {\r
157 //\r
158 // Because currently transition schema not require write moduleGuid, package Name, Packge GUID in\r
159 // <ModuleSA> section, So currently no expect all paramter must be valid.\r
160 return(moduleName + "_" +\r
161 ((moduleGUID != null) ? moduleGUID.toString() : "NullModuleGuid") + "_" +\r
162 ((packageName != null) ? packageName : "NullPackageName") + "_" +\r
163 ((packageGUID != null) ? packageGUID.toString() : "NullPackageGuid") + "_" +\r
164 ((arch != null) ? arch : "NullArch") + "_" +\r
165 ((version != null) ? version : "NullVersion"));\r
166 }\r
167\r
168 /**\r
169 Get primary key string for this usage instance\r
170 \r
171 @return String primary key string\r
172 **/\r
173 public String getPrimaryKey() {\r
174 return UsageInstance.getPrimaryKey(moduleName, moduleGUID, packageName, packageGUID, arch, version);\r
175 }\r
176\r
177 /**\r
178 Judget whether current module is PEI driver\r
179 \r
180 @return boolean\r
181 */\r
182 public boolean isPeiPhaseComponent() {\r
03b1a72d 183 if ((moduleType == ModuleTypeDef.PEI_CORE) ||\r
184 (moduleType == ModuleTypeDef.PEIM)) {\r
38ee8d9e 185 return true;\r
186 }\r
187 return false;\r
188 }\r
189\r
190 /**\r
191 Generate autogen string for header file and C code file.\r
192 \r
193 @throws EntityException Fail to generate.\r
194 \r
195 @param isBuildUsedLibrary whether the autogen is for library.\r
196 */\r
197 public void generateAutoGen(boolean isBuildUsedLibrary) \r
a49b34c0 198 throws EntityException {\r
11e7b0f6 199 String guidStringCName = null;\r
2435723a 200 boolean isByteArray = false;\r
1cf9cdcc 201 String printDatum = null;\r
38ee8d9e 202\r
203 hAutogenStr = "";\r
204 cAutogenStr = "";\r
205\r
206 if (this.modulePcdType == Token.PCD_TYPE.DYNAMIC_EX) {\r
38ee8d9e 207 hAutogenStr += String.format("#define _PCD_TOKEN_%s 0x%016x\r\n", \r
208 parentToken.cName, parentToken.dynamicExTokenNumber);\r
209 } else {\r
210 hAutogenStr += String.format("#define _PCD_TOKEN_%s 0x%016x\r\n", \r
211 parentToken.cName, parentToken.tokenNumber);\r
212 }\r
213\r
2435723a 214 if (!isBuildUsedLibrary && !parentToken.isDynamicPCD) {\r
215 if (datum.trim().charAt(0) == '{') {\r
216 isByteArray = true;\r
217 }\r
218 }\r
219\r
1cf9cdcc 220 if (parentToken.datumType == Token.DATUM_TYPE.UINT64) {\r
221 printDatum = this.datum + "ULL";\r
222 } else {\r
223 printDatum = this.datum;\r
224 }\r
225\r
38ee8d9e 226 switch (modulePcdType) {\r
227 case FEATURE_FLAG:\r
228 if (isBuildUsedLibrary) {\r
229 hAutogenStr += String.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n", \r
230 parentToken.cName);\r
231 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",\r
232 parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
233 parentToken.cName,\r
234 parentToken.cName);\r
235 } else {\r
236 hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r
237 parentToken.cName, \r
1cf9cdcc 238 printDatum);\r
38ee8d9e 239 hAutogenStr += String.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n", \r
240 parentToken.cName);\r
241 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const BOOLEAN _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",\r
242 parentToken.cName,\r
243 parentToken.cName);\r
244 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",\r
245 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
246 parentToken.cName,\r
247 parentToken.cName);\r
248 }\r
249 break;\r
250 case FIXED_AT_BUILD:\r
251 if (isBuildUsedLibrary) {\r
252 hAutogenStr += String.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",\r
253 Token.getAutogendatumTypeString(parentToken.datumType),\r
254 parentToken.cName);\r
255 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",\r
256 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
257 parentToken.cName,\r
258 parentToken.cName);\r
259 } else {\r
260 hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r
261 parentToken.cName, \r
1cf9cdcc 262 printDatum);\r
2435723a 263 if (isByteArray) {\r
264 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = _PCD_VALUE_%s;\r\n",\r
265 parentToken.cName,\r
266 parentToken.cName);\r
267 hAutogenStr += String.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n",\r
268 parentToken.cName);\r
269 hAutogenStr += String.format("#define _PCD_MODE_%s_%s &_gPcd_FixedAtBuild_%s\r\n",\r
270 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
271 parentToken.cName,\r
272 parentToken.cName);\r
273 } else {\r
274 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",\r
275 Token.getAutogendatumTypeString(parentToken.datumType),\r
276 parentToken.cName,\r
277 parentToken.cName);\r
278 hAutogenStr += String.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",\r
279 Token.getAutogendatumTypeString(parentToken.datumType),\r
280 parentToken.cName);\r
281 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _PCD_VALUE_%s\r\n",\r
282 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
283 parentToken.cName,\r
284 parentToken.cName);\r
285 }\r
38ee8d9e 286 }\r
287 break;\r
288 case PATCHABLE_IN_MODULE:\r
289 if (isBuildUsedLibrary) {\r
290 hAutogenStr += String.format("extern %s _gPcd_BinaryPatch_%s;\r\n",\r
291 Token.getAutogendatumTypeString(parentToken.datumType),\r
292 parentToken.cName);\r
293 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",\r
294 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
295 parentToken.cName,\r
296 parentToken.cName);\r
297 } else {\r
298 hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r
299 parentToken.cName, \r
1cf9cdcc 300 printDatum);\r
2435723a 301 if (isByteArray) {\r
302 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[] = _PCD_VALUE_%s;\r\n",\r
303 parentToken.cName,\r
304 parentToken.cName);\r
305 hAutogenStr += String.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n",\r
306 parentToken.cName);\r
307 hAutogenStr += String.format("#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 } else {\r
312 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",\r
313 Token.getAutogendatumTypeString(parentToken.datumType),\r
314 parentToken.cName,\r
315 parentToken.cName);\r
316 hAutogenStr += String.format("extern %s _gPcd_BinaryPatch_%s;\r\n",\r
317 Token.getAutogendatumTypeString(parentToken.datumType),\r
318 parentToken.cName);\r
319 hAutogenStr += String.format("#define _PCD_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",\r
320 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
321 parentToken.cName,\r
322 parentToken.cName); \r
323 }\r
38ee8d9e 324 }\r
325\r
326 break;\r
327 case DYNAMIC:\r
328 hAutogenStr += String.format("#define _PCD_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",\r
329 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
330 parentToken.cName,\r
331 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
332 parentToken.cName);\r
333 break;\r
334 case DYNAMIC_EX:\r
11e7b0f6 335 guidStringCName = "_gPcd_TokenSpaceGuid_" +\r
336 parentToken.tokenSpaceName.toString().replaceAll("-", "_");\r
38ee8d9e 337 \r
a49b34c0 338 hAutogenStr += String.format("#define _PCD_MODE_%s_%s LibPcdGetEx%s(&%s, _PCD_TOKEN_%s)\r\n",\r
38ee8d9e 339 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
340 parentToken.cName,\r
341 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
a49b34c0 342 guidStringCName,\r
38ee8d9e 343 parentToken.cName);\r
344\r
38ee8d9e 345 break;\r
346 }\r
347 }\r
348\r
349 /**\r
350 Get the autogen string for header file.\r
351 \r
352 @return The string of header file.\r
353 **/\r
354 public String getHAutogenStr() {\r
355 return hAutogenStr;\r
356 }\r
878ddf1f 357\r
38ee8d9e 358 /**\r
359 Get the autogen string for C code file.\r
360 \r
361 @return The string of C Code file.\r
362 **/\r
363 public String getCAutogenStr() {\r
364 return cAutogenStr;\r
878ddf1f 365 }\r
878ddf1f 366}\r
367\r