FlashMap can not work correctly in unix GCC because the windows path char "\" exist...
[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
eece174a 22\r
03b1a72d 23import org.tianocore.ModuleTypeDef;\r
136adffc 24import org.tianocore.build.autogen.CommonDefinition;\r
eece174a 25import org.tianocore.build.id.ModuleIdentification;\r
8840ad58 26import org.tianocore.build.pcd.exception.EntityException;\r
878ddf1f 27\r
28/**\r
29 This class indicate an usage instance for a PCD token. This instance maybe a module\r
30 or platform setting. When a module produce or cosume a PCD token, then this module\r
31 is an usage instance for this PCD token.\r
32**/\r
33public class UsageInstance {\r
38ee8d9e 34 ///\r
35 /// This parent that this usage instance belongs to.\r
36 ///\r
eece174a 37 public Token parentToken;\r
38ee8d9e 38\r
39 ///\r
eece174a 40 /// ModuleIdentification for Usage Instance\r
38ee8d9e 41 /// \r
eece174a 42 public ModuleIdentification moduleId;\r
38ee8d9e 43\r
44 ///\r
eece174a 45 /// Arch also is a key for a UsageInstance\r
38ee8d9e 46 /// \r
eece174a 47 public String arch;\r
38ee8d9e 48\r
49 ///\r
50 /// The PCD type defined for module \r
51 /// \r
eece174a 52 public Token.PCD_TYPE modulePcdType;\r
38ee8d9e 53\r
54 ///\r
55 /// The value of the PCD in this usage instance. \r
56 /// \r
eece174a 57 public String datum;\r
38ee8d9e 58\r
59 ///\r
60 /// The maxDatumSize could be different for same PCD in different module\r
61 /// But this case is allow for FeatureFlag, FixedAtBuild, PatchableInModule\r
62 /// type.\r
63 /// \r
eece174a 64 public int maxDatumSize;\r
38ee8d9e 65\r
66 ///\r
67 /// Autogen string for header file.\r
68 ///\r
eece174a 69 public String hAutogenStr;\r
38ee8d9e 70\r
71 ///\r
72 /// Auotgen string for C code file.\r
73 /// \r
eece174a 74 public String cAutogenStr;\r
38ee8d9e 75\r
76 /**\r
eece174a 77 Constructure function for UsageInstance\r
38ee8d9e 78 \r
eece174a 79 @param parentToken The token instance for this usgaInstance\r
80 @param id The identification for usage instance\r
81 @param modulePcdType The PCD type for this usage instance\r
82 @param value The value of this PCD in this usage instance\r
83 @param maxDatumSize The max datum size of this PCD in this usage\r
84 instance.\r
85 **/\r
86 public UsageInstance(Token parentToken,\r
87 ModuleIdentification moduleId,\r
88 Token.PCD_TYPE modulePcdType,\r
89 String arch,\r
90 String value,\r
91 int maxDatumSize) {\r
38ee8d9e 92 this.parentToken = parentToken;\r
eece174a 93 this.moduleId = moduleId;\r
38ee8d9e 94 this.modulePcdType = modulePcdType;\r
95 this.arch = arch;\r
38ee8d9e 96 this.datum = value;\r
97 this.maxDatumSize = maxDatumSize;\r
98 }\r
99\r
100 /**\r
101 Get the primary key for usage instance array for every token.\r
102 \r
eece174a 103 @param moduleId The module Identification for generating primary key\r
104 @param arch Arch string\r
38ee8d9e 105 \r
eece174a 106 @retval String The primary key for this usage instance\r
107 **/\r
108 public static String getPrimaryKey(ModuleIdentification moduleId,\r
109 String arch) {\r
110 String moduleName = moduleId.getName();\r
111 String moduleGuid = moduleId.getGuid();\r
112 String packageName = moduleId.getPackage().getName();\r
113 String packageGuid = moduleId.getPackage().getGuid();\r
114 String version = moduleId.getVersion();\r
115\r
38ee8d9e 116 //\r
117 // Because currently transition schema not require write moduleGuid, package Name, Packge GUID in\r
118 // <ModuleSA> section, So currently no expect all paramter must be valid.\r
eece174a 119 // BUGBUG: Because currently we can not get version from MSA, So ignore verison.\r
120 // \r
121 return(moduleName + "_" +\r
122 ((moduleGuid != null) ? moduleGuid.toLowerCase() : "NullModuleGuid") + "_" +\r
123 ((packageName != null) ? packageName : "NullPackageName") + "_" +\r
124 ((packageGuid != null) ? packageGuid.toLowerCase() : "NullPackageGuid") + "_" +\r
125 ((arch != null) ? arch : "NullArch") + "_" +\r
126 "NullVersion");\r
38ee8d9e 127 }\r
128\r
129 /**\r
130 Get primary key string for this usage instance\r
131 \r
132 @return String primary key string\r
133 **/\r
134 public String getPrimaryKey() {\r
eece174a 135 return UsageInstance.getPrimaryKey(moduleId, arch);\r
38ee8d9e 136 }\r
137\r
138 /**\r
139 Judget whether current module is PEI driver\r
140 \r
eece174a 141 @return boolean whether current module is PEI driver\r
142 **/\r
38ee8d9e 143 public boolean isPeiPhaseComponent() {\r
eece174a 144 int moduleType = CommonDefinition.getModuleType(moduleId.getModuleType());\r
145\r
136adffc 146 if ((moduleType == CommonDefinition.ModuleTypePeiCore) ||\r
147 (moduleType == CommonDefinition.ModuleTypePeim)) {\r
38ee8d9e 148 return true;\r
149 }\r
150 return false;\r
151 }\r
152\r
153 /**\r
eece174a 154 Judge whether current module is DXE driver.\r
38ee8d9e 155 \r
eece174a 156 @return boolean whether current module is DXE driver\r
157 **/\r
158 public boolean isDxePhaseComponent() {\r
159 int moduleType = CommonDefinition.getModuleType(moduleId.getModuleType());\r
160\r
161 if ((moduleType == CommonDefinition.ModuleTypeDxeDriver) ||\r
162 (moduleType == CommonDefinition.ModuleTypeDxeRuntimeDriver) ||\r
163 (moduleType == CommonDefinition.ModuleTypeDxeSalDriver) ||\r
164 (moduleType == CommonDefinition.ModuleTypeDxeSmmDriver) ||\r
165 (moduleType == CommonDefinition.ModuleTypeUefiDriver) ||\r
166 (moduleType == CommonDefinition.ModuleTypeUefiApplication)\r
167 ) {\r
168 return true;\r
169 }\r
170 return false;\r
171 }\r
172\r
173 /**\r
174 Generate autogen string for header file and C code file.\r
38ee8d9e 175 \r
176 @param isBuildUsedLibrary whether the autogen is for library.\r
eece174a 177 **/\r
178 public void generateAutoGen(boolean isBuildUsedLibrary) {\r
51da9e80 179 String guidStringCName = null;\r
180 boolean isByteArray = false;\r
181 String printDatum = null;\r
182 String tokenNumberString = null;\r
38ee8d9e 183\r
184 hAutogenStr = "";\r
185 cAutogenStr = "";\r
186\r
187 if (this.modulePcdType == Token.PCD_TYPE.DYNAMIC_EX) {\r
eece174a 188 //\r
189 // For DYNAMIC_EX type PCD, use original token number in SPD or FPD to generate autogen\r
190 // \r
51da9e80 191 tokenNumberString = Long.toString(parentToken.dynamicExTokenNumber, 16);\r
38ee8d9e 192 } else {\r
eece174a 193 //\r
194 // For Others type PCD, use autogenerated token number to generate autogen\r
195 // \r
51da9e80 196 tokenNumberString = Long.toString(parentToken.tokenNumber, 16);\r
38ee8d9e 197 }\r
198\r
eece174a 199 hAutogenStr += String.format("#define _PCD_TOKEN_%s 0x%s\r\n", parentToken.cName, tokenNumberString);\r
200\r
201 //\r
202 // Judge the value of this PCD is byte array type\r
203 // \r
2435723a 204 if (!isBuildUsedLibrary && !parentToken.isDynamicPCD) {\r
205 if (datum.trim().charAt(0) == '{') {\r
206 isByteArray = true;\r
207 }\r
208 }\r
209\r
eece174a 210 //\r
211 // "ULL" should be added to value's tail for UINT64 value\r
212 // \r
1cf9cdcc 213 if (parentToken.datumType == Token.DATUM_TYPE.UINT64) {\r
214 printDatum = this.datum + "ULL";\r
215 } else {\r
216 printDatum = this.datum;\r
217 }\r
218\r
38ee8d9e 219 switch (modulePcdType) {\r
220 case FEATURE_FLAG:\r
16d3e132 221 hAutogenStr += String.format("extern const BOOLEAN _gPcd_FixedAtBuild_%s;\r\n", \r
222 parentToken.cName);\r
57a38e69 223 hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n",\r
16d3e132 224 parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
225 parentToken.cName,\r
226 parentToken.cName);\r
57a38e69 227 hAutogenStr += String.format("//#define _PCD_SET_MODE_%s_%s ASSERT(FALSE) If is not allowed to set value for a FEATURE_FLAG PCD\r\n",\r
228 parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
229 parentToken.cName);\r
16d3e132 230\r
231 if (!isBuildUsedLibrary) {\r
38ee8d9e 232 hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r
233 parentToken.cName, \r
1cf9cdcc 234 printDatum);\r
38ee8d9e 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
38ee8d9e 238 }\r
239 break;\r
240 case FIXED_AT_BUILD:\r
16d3e132 241 if (isByteArray) {\r
242 hAutogenStr += String.format("extern const UINT8 _gPcd_FixedAtBuild_%s[];\r\n",\r
243 parentToken.cName);\r
57a38e69 244 hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_FixedAtBuild_%s\r\n", \r
16d3e132 245 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
246 parentToken.cName,\r
247 parentToken.cName);\r
248 } else {\r
38ee8d9e 249 hAutogenStr += String.format("extern const %s _gPcd_FixedAtBuild_%s;\r\n",\r
250 Token.getAutogendatumTypeString(parentToken.datumType),\r
251 parentToken.cName);\r
57a38e69 252 hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_FixedAtBuild_%s\r\n", \r
38ee8d9e 253 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
254 parentToken.cName,\r
255 parentToken.cName);\r
16d3e132 256 }\r
257\r
57a38e69 258 hAutogenStr += String.format("//#define _PCD_SET_MODE_%s_%s ASSERT(FALSE) // It is not allowed to set value for a FIXED_AT_BUILD PCD\r\n",\r
259 parentToken.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
260 parentToken.cName);\r
16d3e132 261 if (!isBuildUsedLibrary) {\r
38ee8d9e 262 hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r
263 parentToken.cName, \r
1cf9cdcc 264 printDatum);\r
2435723a 265 if (isByteArray) {\r
266 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const UINT8 _gPcd_FixedAtBuild_%s[] = _PCD_VALUE_%s;\r\n",\r
267 parentToken.cName,\r
268 parentToken.cName);\r
2435723a 269 } else {\r
270 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED const %s _gPcd_FixedAtBuild_%s = _PCD_VALUE_%s;\r\n",\r
271 Token.getAutogendatumTypeString(parentToken.datumType),\r
272 parentToken.cName,\r
273 parentToken.cName);\r
2435723a 274 }\r
38ee8d9e 275 }\r
276 break;\r
277 case PATCHABLE_IN_MODULE:\r
16d3e132 278 if (isByteArray) {\r
279 hAutogenStr += String.format("extern UINT8 _gPcd_BinaryPatch_%s[];\r\n",\r
280 parentToken.cName);\r
57a38e69 281 hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s (VOID*)_gPcd_BinaryPatch_%s\r\n",\r
16d3e132 282 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
283 parentToken.cName,\r
284 parentToken.cName); \r
285 } else {\r
38ee8d9e 286 hAutogenStr += String.format("extern %s _gPcd_BinaryPatch_%s;\r\n",\r
287 Token.getAutogendatumTypeString(parentToken.datumType),\r
288 parentToken.cName);\r
57a38e69 289 hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s _gPcd_BinaryPatch_%s\r\n",\r
38ee8d9e 290 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
291 parentToken.cName,\r
16d3e132 292 parentToken.cName); \r
293 }\r
294\r
57a38e69 295 //\r
296 // Generate _PCD_SET_MODE_xx macro for using set BinaryPatch value via PcdSet macro\r
297 // \r
298 if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {\r
299 hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) CopyMem (_gPcd_BinaryPatch_%s, (Buffer), (SizeOfBuffer))\r\n",\r
300 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
301 parentToken.cName,\r
302 parentToken.cName);\r
303 } else {\r
304 hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(Value) (_gPcd_BinaryPatch_%s = (Value))\r\n",\r
305 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
306 parentToken.cName,\r
307 parentToken.cName);\r
308 }\r
309 \r
16d3e132 310 if (!isBuildUsedLibrary) {\r
38ee8d9e 311 hAutogenStr += String.format("#define _PCD_VALUE_%s %s\r\n", \r
312 parentToken.cName, \r
1cf9cdcc 313 printDatum);\r
2435723a 314 if (isByteArray) {\r
315 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED UINT8 _gPcd_BinaryPatch_%s[] = _PCD_VALUE_%s;\r\n",\r
316 parentToken.cName,\r
317 parentToken.cName);\r
2435723a 318 } else {\r
319 cAutogenStr += String.format("GLOBAL_REMOVE_IF_UNREFERENCED %s _gPcd_BinaryPatch_%s = _PCD_VALUE_%s;\r\n",\r
320 Token.getAutogendatumTypeString(parentToken.datumType),\r
321 parentToken.cName,\r
322 parentToken.cName);\r
2435723a 323 }\r
38ee8d9e 324 }\r
325\r
326 break;\r
327 case DYNAMIC:\r
57a38e69 328 hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s LibPcdGet%s(_PCD_TOKEN_%s)\r\n",\r
38ee8d9e 329 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
330 parentToken.cName,\r
331 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
332 parentToken.cName);\r
57a38e69 333 if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {\r
334 hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSet%s(_PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",\r
335 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
336 parentToken.cName,\r
337 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
338 parentToken.cName);\r
339 } else {\r
340 hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSet%s(_PCD_TOKEN_%s, (Value))\r\n",\r
341 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
342 parentToken.cName,\r
343 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
344 parentToken.cName);\r
345 }\r
38ee8d9e 346 break;\r
347 case DYNAMIC_EX:\r
11e7b0f6 348 guidStringCName = "_gPcd_TokenSpaceGuid_" +\r
349 parentToken.tokenSpaceName.toString().replaceAll("-", "_");\r
57a38e69 350\r
351 hAutogenStr += String.format("#define _PCD_GET_MODE_%s_%s LibPcdGetEx%s(&%s, _PCD_TOKEN_%s)\r\n",\r
38ee8d9e 352 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
353 parentToken.cName,\r
354 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
a49b34c0 355 guidStringCName,\r
38ee8d9e 356 parentToken.cName);\r
357\r
57a38e69 358 if (parentToken.datumType == Token.DATUM_TYPE.POINTER) {\r
359 hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(SizeOfBuffer, Buffer) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (SizeOfBuffer), (Buffer))\r\n",\r
360 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
361 parentToken.cName,\r
362 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
363 guidStringCName,\r
364 parentToken.cName);\r
365 } else {\r
366 hAutogenStr += String.format("#define _PCD_SET_MODE_%s_%s(Value) LibPcdSetEx%s(&%s, _PCD_TOKEN_%s, (Value))\r\n",\r
367 Token.GetAutogenDefinedatumTypeString(parentToken.datumType),\r
368 parentToken.cName,\r
369 Token.getAutogenLibrarydatumTypeString(parentToken.datumType),\r
370 guidStringCName,\r
371 parentToken.cName);\r
372\r
373 }\r
38ee8d9e 374 break;\r
375 }\r
376 }\r
377\r
378 /**\r
379 Get the autogen string for header file.\r
380 \r
381 @return The string of header file.\r
382 **/\r
383 public String getHAutogenStr() {\r
384 return hAutogenStr;\r
385 }\r
878ddf1f 386\r
38ee8d9e 387 /**\r
388 Get the autogen string for C code file.\r
389 \r
390 @return The string of C Code file.\r
391 **/\r
392 public String getCAutogenStr() {\r
393 return cAutogenStr;\r
878ddf1f 394 }\r
878ddf1f 395}\r
396\r