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