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