]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Java/Source/PcdTools/org/tianocore/pcd/entity/CommonDefinition.java
Restructuring for better separation of Tool packages.
[mirror_edk2.git] / Tools / Java / Source / PcdTools / org / tianocore / pcd / entity / CommonDefinition.java
CommitLineData
d14ebb43 1/** @file\r
2 CommonDefinition class.\r
3\r
4 This class is to define some common marcos and funcions, which used by AutoGen.\r
bc262841 5\r
d14ebb43 6 Copyright (c) 2006, Intel Corporation\r
7 All rights reserved. This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
bc262841 11\r
d14ebb43 12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15 **/\r
16package org.tianocore.pcd.entity;\r
17\r
d14ebb43 18import java.util.Iterator;\r
19import java.util.LinkedHashSet;\r
20import java.util.Set;\r
21\r
22/**\r
23 CommonDefinition\r
bc262841 24\r
d14ebb43 25 This class is to define some common marcos, which used by AutoGen.\r
bc262841 26\r
d14ebb43 27**/\r
28public class CommonDefinition {\r
29 public final static String spdSuffix = ".spd";\r
30 public final static String mbdSuffix = ".mbd";\r
31 public final static String msaSuffix = ".msa";\r
32 public final static String LibraryStr = "LIBRARY";\r
33 public final static String autoGenHbegin = "extern int __make_me_compile_correctly;\r\n";\r
34 public final static String include = "#include";\r
35 public final static String autoGenCLine1 = "\r\n";\r
bc262841 36\r
d14ebb43 37 public final static String autoGenCLine2 = "const UINT8 _gDebugPropertyMask "\r
38 + "= DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED"\r
39 + " | DEBUG_PROPERTY_DEBUG_PRINT_ENABLED"\r
40 + " | DEBUG_PROPERTY_DEBUG_CODE_ENABLED;\r\n";\r
41\r
42 public final static String autoGenCLine3 = "const UINTN _gModuleDefaultErrorLevel"\r
43 + " = EFI_D_ERROR | EFI_D_LOAD;\r\n";\r
bc262841 44\r
d14ebb43 45 public final static String autoGenHLine1 = "#define EFI_SPECIFICATION_VERSION 0x00020000\r\n";\r
46 public final static String autoGenHVersionDefault = "#define EFI_SPECIFICATION_VERSION 0x00000000\r\n";\r
47 public final static String autoGenHLine2 = "#define EDK_RELEASE_VERSION 0x00090000\r\n";\r
48 public final static String autoGenHReleaseDefault = "#define EDK_RELEASE_VERSION 0x00000000\r\n";\r
49\r
50 public final static String includeAutogenH = "#include <AutoGen.h>\r\n" ;\r
51 public final static String marcDefineStr = "#define ";\r
52\r
53 public final static String gEfi = "gEfi";\r
54 public final static String protocolGuid = "ProtocolGuid";\r
55 public final static String ppiGuid = "PpiGuid";\r
56 public final static String guidGuid = "Guid";\r
57\r
58 public final static String tianoR8FlashMapH = "TianoR8FlashMap.h";\r
59 public final static String flashMapH = "FlashMap.h";\r
bc262841 60\r
d14ebb43 61 //\r
62 // AutoGen.h and AutoGen.c file's header\r
63 //\r
bc262841 64 public final static String autogenHNotation =\r
d14ebb43 65 "/**\r\n" +\r
66 " DO NOT EDIT\r\n" +\r
67 " FILE auto-generated by GenBuild tasks\r\n" +\r
68 " Module name:\r\n" +\r
69 " AutoGen.h\r\n" +\r
70 " Abstract:" +\r
71 " Auto-generated AutoGen.h for building module or library.\r\n" +\r
72 "**/\r\n\r\n";\r
bc262841 73\r
74 public final static String autogenCNotation =\r
d14ebb43 75 "/**\r\n" +\r
76 " DO NOT EDIT\r\n" +\r
77 " FILE auto-generated by GenBuild tasks\r\n" +\r
78 " Module name:\r\n" +\r
79 " AutoGen.c\r\n" +\r
80 " Abstract:" +\r
81 " Auto-generated AutoGen.c for building module or library.\r\n" +\r
82 "**/\r\n\r\n";\r
bc262841 83\r
d14ebb43 84 //\r
85 // module type\r
86 //\r
87 public final static int ModuleTypeBase = 0;\r
88 public final static int ModuleTypeSec = 1;\r
89 public final static int ModuleTypePeiCore = 2;\r
90 public final static int ModuleTypePeim = 3;\r
91 public final static int ModuleTypeDxeCore = 4;\r
92 public final static int ModuleTypeDxeDriver = 5;\r
93 public final static int ModuleTypeDxeRuntimeDriver = 6;\r
94 public final static int ModuleTypeDxeSmmDriver = 7;\r
95 public final static int ModuleTypeDxeSalDriver = 8;\r
96 public final static int ModuleTypeUefiDriver = 9;\r
97 public final static int ModuleTypeUefiApplication = 10;\r
98 public final static int ModuleTypeUnknown = 11;\r
bc262841 99\r
100\r
d14ebb43 101 //\r
102 // component type\r
bc262841 103 //\r
d14ebb43 104 public final static int ComponentTypeNull = 0;\r
105 public final static int ComponentTypeApriori = 1;\r
106 public final static int ComponentTypeSec = 2;\r
107 public final static int ComponentTypeLibrary = 3;\r
108 public final static int ComponentTypeFvImageFile = 4;\r
109 public final static int ComponentTypeBsDriver = 5;\r
110 public final static int ComponentTypeRtDriver = 6;\r
111 public final static int ComponentTypeSalRtDriver =7;\r
112 public final static int ComponentTypePe32Peim = 8;\r
113 public final static int ComponentTypePicPeim =9;\r
114 public final static int ComponentTypeCombinedPeimDriver =10;\r
115 public final static int ComponentTypePeiCore = 11;\r
116 public final static int ComponentTypeDxeCore = 12;\r
117 public final static int ComponentTypeApplication = 13;\r
118 public final static int ComponentTypeBsDriverEfi = 14;\r
119 public final static int ComponentTypeShellApp = 15;\r
120 public final static int ComponentTypeBinary =16;\r
121 public final static int ComponentTypeLogo = 17;\r
122 public final static int ComponentTypeCustomBuild = 18;\r
123 public final static int ComponentTypeUnknown = 19;\r
124\r
bc262841 125\r
d14ebb43 126 //\r
127 // Usaged style\r
128 //\r
129 public final static String AlwaysConsumed = "ALWAYS_CONSUMED";\r
130 public final static String AlwaysProduced = "ALWAYS_PRODUCED";\r
bc262841 131\r
d14ebb43 132\r
133 public static class MyEnum {\r
134 String moduleTypeStr;\r
135 int type;\r
136\r
137 MyEnum (String str, int type) {\r
138 this.type = type;\r
139 this.moduleTypeStr = str;\r
140 }\r
141\r
142 int ForInt(String str) {\r
143 if (str.equals(this.moduleTypeStr)) {\r
144 return this.type;\r
145 } else\r
146 return -1;\r
147 }\r
148 }\r
bc262841 149\r
d14ebb43 150 //\r
151 // Module type\r
152 //\r
153 public static final MyEnum[] moduleEnum = new MyEnum[] {\r
154 new MyEnum("BASE", ModuleTypeBase),\r
155 new MyEnum("SEC", ModuleTypeSec),\r
156 new MyEnum("PEI_CORE", ModuleTypePeiCore),\r
157 new MyEnum("PEIM", ModuleTypePeim),\r
158 new MyEnum("DXE_CORE", ModuleTypeDxeCore),\r
159 new MyEnum("DXE_DRIVER", ModuleTypeDxeDriver),\r
160 new MyEnum("DXE_RUNTIME_DRIVER", ModuleTypeDxeRuntimeDriver),\r
161 new MyEnum("DXE_SAL_DRIVER", ModuleTypeDxeSalDriver),\r
162 new MyEnum("DXE_SMM_DRIVER", ModuleTypeDxeSmmDriver),\r
163 new MyEnum("UEFI_DRIVER", ModuleTypeUefiDriver),\r
164 new MyEnum("UEFI_APPLICATION", ModuleTypeUefiApplication) };\r
bc262841 165\r
d14ebb43 166 //\r
167 // Component type\r
168 //\r
169 public static final MyEnum[] componentEnum = new MyEnum[]{\r
170 new MyEnum("APRIORI", ComponentTypeApriori),\r
171 new MyEnum("SEC", ComponentTypeSec),\r
172 new MyEnum("LIBRARY", ComponentTypeLibrary),\r
173 new MyEnum("FV_IMAGE_FILE", ComponentTypeFvImageFile),\r
174 new MyEnum("BS_DRIVER", ComponentTypeBsDriver),\r
175 new MyEnum("RT_DRIVER", ComponentTypeRtDriver),\r
176 new MyEnum("SAL_RT_DRIVER", ComponentTypeSalRtDriver),\r
177 new MyEnum("PE32_PEIM", ComponentTypePe32Peim),\r
178 new MyEnum("PIC_PEIM", ComponentTypePicPeim),\r
179 new MyEnum("COMBINED_PEIM_DRIVER", ComponentTypeCombinedPeimDriver),\r
180 new MyEnum("PEI_CORE", ComponentTypePeiCore),\r
181 new MyEnum("DXE_CORE", ComponentTypeDxeCore),\r
182 new MyEnum("APPLICATION", ComponentTypeApplication),\r
183 new MyEnum("BS_DRIVER_EFI", ComponentTypeBsDriverEfi),\r
184 new MyEnum("SHELLAPP", ComponentTypeShellApp),\r
185 new MyEnum("BINARY", ComponentTypeBinary),\r
186 new MyEnum("LOGO", ComponentTypeLogo),\r
187 new MyEnum("CUSTOM_BUILD", ComponentTypeCustomBuild)\r
188 };\r
bc262841 189\r
d14ebb43 190 /**\r
191 getModuleType\r
bc262841 192\r
d14ebb43 193 This function get the module type value according module type string.\r
bc262841 194\r
d14ebb43 195 @param moduleTypeStr String of modlue type.\r
bc262841 196 @return\r
d14ebb43 197 **/\r
198 static public int getModuleType(String moduleTypeStr) {\r
199 int returnValue = -1;\r
200 for (int i = 0; i < CommonDefinition.moduleEnum.length; i++) {\r
201 returnValue = CommonDefinition.moduleEnum[i].ForInt(moduleTypeStr);\r
202 if (returnValue != -1) {\r
203 return returnValue;\r
204 }\r
205 }\r
206 return CommonDefinition.ModuleTypeUnknown;\r
207 }\r
208\r
209 /**\r
210 getComponentType\r
bc262841 211\r
212 This function get the component type value according commponet type\r
d14ebb43 213 string.\r
bc262841 214\r
d14ebb43 215 @param componentTypeStr String of component type.\r
216 @return\r
217 **/\r
218 static public int getComponentType (String componentTypeStr){\r
219 int returnValue = -1;\r
220 for (int i = 0; i < CommonDefinition.componentEnum.length; i++) {\r
221 returnValue = CommonDefinition.componentEnum[i].ForInt(componentTypeStr);\r
222 if (returnValue != -1) {\r
223 return returnValue;\r
224 }\r
225 }\r
226 return CommonDefinition.ComponentTypeUnknown;\r
227 }\r
228\r
229 /**\r
230 getComponentTypeString\r
bc262841 231\r
d14ebb43 232 This function get the commponet type string according component type value.\r
bc262841 233\r
d14ebb43 234 @param componentType Integer value of component type.\r
235 @return\r
236 **/\r
237 static public String getComponentTypeString (int componentType) {\r
bc262841 238 if ((componentType > CommonDefinition.ComponentTypeUnknown) ||\r
d14ebb43 239 (componentType < CommonDefinition.ComponentTypeNull)) {\r
240 return null;\r
241 }\r
f28c0830 242 for (int index = 0; index < CommonDefinition.componentEnum.length; index++) {\r
d14ebb43 243 if (componentType == CommonDefinition.componentEnum[index].type) {\r
244 return CommonDefinition.componentEnum[index].moduleTypeStr;\r
245 }\r
246 }\r
247 return null;\r
248 }\r
249\r
250 /**\r
bc262841 251 isLibraryComponent\r
252\r
d14ebb43 253 This function is to check does componet is library according to commponet\r
254 type value.\r
bc262841 255\r
d14ebb43 256 @param componentType Integer value of component type.\r
257 @return\r
258 **/\r
259 static public boolean isLibraryComponent (int componentType) {\r
260 if (ComponentTypeLibrary == componentType) {\r
261 return true;\r
262 }\r
263 return false;\r
264 }\r
bc262841 265\r
d14ebb43 266 /**\r
267 * formateGuidName\r
bc262841 268 *\r
d14ebb43 269 * This function is to formate GUID to ANSI c form.\r
bc262841 270 *\r
d14ebb43 271 * @param guidNameCon\r
272 * String of GUID.\r
273 * @return Formated GUID.\r
274 */\r
275 public static String formatGuidName(String guidNameConv) {\r
276 String[] strList;\r
277 String guid = "";\r
278 int index = 0;\r
279 if (guidNameConv\r
280 .matches("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}")) {\r
281 strList = guidNameConv.split("-");\r
282 guid = "0x" + strList[0] + ", ";\r
283 guid = guid + "0x" + strList[1] + ", ";\r
284 guid = guid + "0x" + strList[2] + ", ";\r
285 guid = guid + "{";\r
286 guid = guid + "0x" + strList[3].substring(0, 2) + ", ";\r
287 guid = guid + "0x" + strList[3].substring(2, 4);\r
288\r
289 while (index < strList[4].length()) {\r
290 guid = guid + ", ";\r
291 guid = guid + "0x" + strList[4].substring(index, index + 2);\r
292 index = index + 2;\r
293 }\r
294 guid = guid + "}";\r
295 return guid;\r
296 } else if (guidNameConv\r
297 .matches("0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},( )*0x[a-fA-F0-9]{1,4}(,( )*\\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\\})?")) {\r
298 strList = guidNameConv.split(",");\r
299\r
300 //\r
301 // chang Microsoft specific form to ANSI c form\r
302 //\r
303 for (int i = 0; i < 3; i++) {\r
304 guid = guid + strList[i] + ",";\r
305 }\r
306 guid = guid + "{";\r
307\r
308 for (int i = 3; i < strList.length; i++) {\r
309 if (i == strList.length - 1) {\r
310 guid = guid + strList[i];\r
311 } else {\r
312 guid = guid + strList[i] + ",";\r
313 }\r
314 }\r
315 guid = guid + "}";\r
316 return guid;\r
317 } else {\r
318 System.out\r
d653c17a 319 .println("Check GUID Value, it doesn't conform to the registry format specified by the schema!!!");\r
d14ebb43 320 return "0";\r
321\r
322 }\r
323 }\r
bc262841 324\r
d14ebb43 325 /**\r
326 * Remove deuplicat string in list\r
bc262841 327 *\r
d14ebb43 328 * This function is to duplicat string in list\r
bc262841 329 *\r
d14ebb43 330 * @param String[]\r
331 * String list.\r
332 * @return String[] String list which remove the duplicate string.\r
333 */\r
334 public static String[] remDupString (String[] orgList){\r
335 Set<String> strList = new LinkedHashSet<String>();\r
336 String[] desList ;\r
337 if (orgList == null){\r
338 return new String[0];\r
339 }\r
340 for (int i = 0; i < orgList.length; i++){\r
341 strList.add(orgList[i]);\r
342 }\r
343 desList = new String[strList.size()];\r
344 Iterator item = strList.iterator();\r
345 int index = 0;\r
346 while (item.hasNext()){\r
347 desList[index] = (String)item.next();\r
348 index++;\r
349 }\r
350 return desList;\r
351 }\r
bc262841 352\r
d653c17a 353}\r