]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/GenBuild/org/tianocore/build/autogen/CommonDefinition.java
1. Fix one bug on EBC for GetPowerOfTwo64.c
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / autogen / CommonDefinition.java
CommitLineData
878ddf1f 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
5 \r
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
11 \r
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.build.autogen;\r
17\r
136adffc 18import java.util.HashSet;\r
19import java.util.Iterator;\r
20import java.util.Set;\r
21\r
878ddf1f 22/**\r
23 CommonDefinition\r
24 \r
25 This class is to define some common marcos, which used by AutoGen.\r
26 \r
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
36 \r
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
44 \r
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
a29c47e0 51 public final static String marcDefineStr = "#define ";\r
878ddf1f 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 //\r
59 // AutoGen.h and AutoGen.c file's header\r
60 //\r
61 public final static String autogenHNotation = \r
62 "/**\r\n" +\r
63 " DO NOT EDIT\r\n" +\r
64 " FILE auto-generated by GenBuild tasks\r\n" +\r
65 " Module name:\r\n" +\r
66 " AutoGen.h\r\n" +\r
67 " Abstract:" +\r
68 " Auto-generated AutoGen.h for building module or library.\r\n" +\r
69 "**/\r\n\r\n";\r
70 \r
71 public final static String autogenCNotation = \r
72 "/**\r\n" +\r
73 " DO NOT EDIT\r\n" +\r
74 " FILE auto-generated by GenBuild tasks\r\n" +\r
75 " Module name:\r\n" +\r
76 " AutoGen.c\r\n" +\r
77 " Abstract:" +\r
78 " Auto-generated AutoGen.c for building module or library.\r\n" +\r
79 "**/\r\n\r\n";\r
80 \r
81 //\r
82 // module type\r
83 //\r
84 public final static int ModuleTypeBase = 0;\r
85 public final static int ModuleTypeSec = 1;\r
86 public final static int ModuleTypePeiCore = 2;\r
87 public final static int ModuleTypePeim = 3;\r
88 public final static int ModuleTypeDxeCore = 4;\r
89 public final static int ModuleTypeDxeDriver = 5;\r
90 public final static int ModuleTypeDxeRuntimeDriver = 6;\r
91 public final static int ModuleTypeDxeSmmDriver = 7;\r
92 public final static int ModuleTypeDxeSalDriver = 8;\r
93 public final static int ModuleTypeUefiDriver = 9;\r
94 public final static int ModuleTypeUefiApplication = 10;\r
95 public final static int ModuleTypeUnknown = 11;\r
96 \r
97 \r
98 //\r
99 // component type\r
100 // \r
101 public final static int ComponentTypeNull = 0;\r
102 public final static int ComponentTypeApriori = 1;\r
103 public final static int ComponentTypeSec = 2;\r
104 public final static int ComponentTypeLibrary = 3;\r
105 public final static int ComponentTypeFvImageFile = 4;\r
106 public final static int ComponentTypeBsDriver = 5;\r
107 public final static int ComponentTypeRtDriver = 6;\r
108 public final static int ComponentTypeSalRtDriver =7;\r
109 public final static int ComponentTypePe32Peim = 8;\r
110 public final static int ComponentTypePicPeim =9;\r
111 public final static int ComponentTypeCombinedPeimDriver =10;\r
112 public final static int ComponentTypePeiCore = 11;\r
113 public final static int ComponentTypeDxeCore = 12;\r
114 public final static int ComponentTypeApplication = 13;\r
115 public final static int ComponentTypeBsDriverEfi = 14;\r
116 public final static int ComponentTypeShellApp = 15;\r
117 public final static int ComponentTypeBinary =16;\r
118 public final static int ComponentTypeLogo = 17;\r
119 public final static int ComponentTypeCustomBuild = 18;\r
120 public final static int ComponentTypeUnknown = 19;\r
121\r
122 \r
123 //\r
124 // Usaged style\r
125 //\r
126 public final static String AlwaysConsumed = "ALWAYS_CONSUMED";\r
127 public final static String AlwaysProduced = "ALWAYS_PRODUCED";\r
128 \r
129\r
130 public static class MyEnum {\r
131 String moduleTypeStr;\r
132 int type;\r
133\r
134 MyEnum (String str, int type) {\r
135 this.type = type;\r
136 this.moduleTypeStr = str;\r
137 }\r
138\r
139 int ForInt(String str) {\r
140 if (str.equals(this.moduleTypeStr)) {\r
141 return this.type;\r
142 } else\r
143 return -1;\r
144 }\r
145 }\r
146 \r
147 //\r
148 // Module type\r
149 //\r
150 public static final MyEnum[] moduleEnum = new MyEnum[] {\r
151 new MyEnum("BASE", ModuleTypeBase),\r
152 new MyEnum("SEC", ModuleTypeSec),\r
153 new MyEnum("PEI_CORE", ModuleTypePeiCore),\r
154 new MyEnum("PEIM", ModuleTypePeim),\r
155 new MyEnum("DXE_CORE", ModuleTypeDxeCore),\r
136adffc 156 new MyEnum("DXE_DRIVER", ModuleTypeDxeDriver),\r
878ddf1f 157 new MyEnum("DXE_RUNTIME_DRIVER", ModuleTypeDxeRuntimeDriver),\r
0b8c16e4 158 new MyEnum("DXE_SAL_DRIVER", ModuleTypeDxeSalDriver),\r
a29c47e0 159 new MyEnum("DXE_SMM_DRIVER", ModuleTypeDxeSmmDriver),\r
878ddf1f 160 new MyEnum("UEFI_DRIVER", ModuleTypeUefiDriver),\r
161 new MyEnum("UEFI_APPLICATION", ModuleTypeUefiApplication) };\r
162 \r
163 //\r
164 // Component type\r
165 //\r
166 public static final MyEnum[] componentEnum = new MyEnum[]{\r
167 new MyEnum("APRIORI", ComponentTypeApriori),\r
168 new MyEnum("SEC", ComponentTypeSec),\r
169 new MyEnum("LIBRARY", ComponentTypeLibrary),\r
170 new MyEnum("FV_IMAGE_FILE", ComponentTypeFvImageFile),\r
171 new MyEnum("BS_DRIVER", ComponentTypeBsDriver),\r
172 new MyEnum("RT_DRIVER", ComponentTypeRtDriver),\r
173 new MyEnum("SAL_RT_DRIVER", ComponentTypeSalRtDriver),\r
174 new MyEnum("PE32_PEIM", ComponentTypePe32Peim),\r
175 new MyEnum("PIC_PEIM", ComponentTypePicPeim),\r
176 new MyEnum("COMBINED_PEIM_DRIVER", ComponentTypeCombinedPeimDriver),\r
177 new MyEnum("PEI_CORE", ComponentTypePeiCore),\r
178 new MyEnum("DXE_CORE", ComponentTypeDxeCore),\r
179 new MyEnum("APPLICATION", ComponentTypeApplication),\r
180 new MyEnum("BS_DRIVER_EFI", ComponentTypeBsDriverEfi),\r
181 new MyEnum("SHELLAPP", ComponentTypeShellApp),\r
182 new MyEnum("BINARY", ComponentTypeBinary),\r
183 new MyEnum("LOGO", ComponentTypeLogo),\r
184 new MyEnum("CUSTOM_BUILD", ComponentTypeCustomBuild)\r
185 };\r
186 \r
187 /**\r
188 getModuleType\r
189 \r
190 This function get the module type value according module type string.\r
191 \r
192 @param moduleTypeStr String of modlue type.\r
193 @return \r
194 **/\r
195 static public int getModuleType(String moduleTypeStr) {\r
196 int returnValue = -1;\r
197 for (int i = 0; i < CommonDefinition.moduleEnum.length; i++) {\r
198 returnValue = CommonDefinition.moduleEnum[i].ForInt(moduleTypeStr);\r
199 if (returnValue != -1) {\r
200 return returnValue;\r
201 }\r
202 }\r
203 return CommonDefinition.ModuleTypeUnknown;\r
204 }\r
205\r
206 /**\r
207 getComponentType\r
208 \r
209 This function get the component type value according commponet type \r
210 string.\r
211 \r
212 @param componentTypeStr String of component type.\r
213 @return\r
214 **/\r
215 static public int getComponentType (String componentTypeStr){\r
216 int returnValue = -1;\r
217 for (int i = 0; i < CommonDefinition.componentEnum.length; i++) {\r
218 returnValue = CommonDefinition.componentEnum[i].ForInt(componentTypeStr);\r
219 if (returnValue != -1) {\r
220 return returnValue;\r
221 }\r
222 }\r
223 return CommonDefinition.ComponentTypeUnknown;\r
224 }\r
225\r
226 /**\r
227 getComponentTypeString\r
228 \r
229 This function get the commponet type string according component type value.\r
230 \r
231 @param componentType Integer value of component type.\r
232 @return\r
233 **/\r
234 static public String getComponentTypeString (int componentType) {\r
235 if ((componentType > CommonDefinition.ComponentTypeUnknown) || \r
236 (componentType < CommonDefinition.ComponentTypeNull)) {\r
237 return null;\r
238 }\r
239 for (int index = 0; index < CommonDefinition.componentEnum.length; index ++) {\r
240 if (componentType == CommonDefinition.componentEnum[index].type) {\r
241 return CommonDefinition.componentEnum[index].moduleTypeStr;\r
242 }\r
243 }\r
244 return null;\r
245 }\r
246\r
247 /**\r
248 isLibraryComponent \r
249 \r
250 This function is to check does componet is library according to commponet\r
251 type value.\r
252 \r
253 @param componentType Integer value of component type.\r
254 @return\r
255 **/\r
256 static public boolean isLibraryComponent (int componentType) {\r
257 if (ComponentTypeLibrary == componentType) {\r
258 return true;\r
259 }\r
260 return false;\r
261 }\r
a29c47e0 262 \r
263 /**\r
264 * formateGuidName\r
265 * \r
266 * This function is to formate GUID to ANSI c form.\r
267 * \r
268 * @param guidNameCon\r
269 * String of GUID.\r
270 * @return Formated GUID.\r
271 */\r
272 public static String formatGuidName(String guidNameConv) {\r
273 String[] strList;\r
274 String guid = "";\r
275 int index = 0;\r
276 if (guidNameConv\r
277 .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
278 strList = guidNameConv.split("-");\r
279 guid = "0x" + strList[0] + ", ";\r
280 guid = guid + "0x" + strList[1] + ", ";\r
281 guid = guid + "0x" + strList[2] + ", ";\r
282 guid = guid + "{";\r
283 guid = guid + "0x" + strList[3].substring(0, 2) + ", ";\r
284 guid = guid + "0x" + strList[3].substring(2, 4);\r
99d2c3c4 285\r
a29c47e0 286 while (index < strList[4].length()) {\r
287 guid = guid + ", ";\r
288 guid = guid + "0x" + strList[4].substring(index, index + 2);\r
289 index = index + 2;\r
290 }\r
291 guid = guid + "}";\r
292 return guid;\r
293 } else if (guidNameConv\r
294 .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
295 strList = guidNameConv.split(",");\r
99d2c3c4 296\r
a29c47e0 297 //\r
298 // chang Microsoft specific form to ANSI c form\r
299 //\r
300 for (int i = 0; i < 3; i++) {\r
301 guid = guid + strList[i] + ",";\r
302 }\r
303 guid = guid + "{";\r
99d2c3c4 304\r
a29c47e0 305 for (int i = 3; i < strList.length; i++) {\r
306 if (i == strList.length - 1) {\r
307 guid = guid + strList[i];\r
308 } else {\r
309 guid = guid + strList[i] + ",";\r
310 }\r
311 }\r
312 guid = guid + "}";\r
313 return guid;\r
314 } else {\r
315 System.out\r
316 .println("Check GUID Value, it don't conform to the schema!!!");\r
317 return "0";\r
318\r
319 }\r
320 }\r
321 \r
136adffc 322 /**\r
323 * Remove deuplicat string in list\r
324 * \r
325 * This function is to duplicat string in list\r
326 * \r
327 * @param String[]\r
328 * String list.\r
329 * @return String[] String list which remove the duplicate string.\r
330 */\r
331 public static String[] remDupString (String[] orgList){\r
332 Set<String> strList = new HashSet<String>();\r
333 String[] desList ;\r
334 if (orgList == null){\r
335 return new String[0];\r
336 }\r
337 for (int i = 0; i < orgList.length; i++){\r
338 strList.add(orgList[i]);\r
339 }\r
340 desList = new String[strList.size()];\r
341 Iterator item = strList.iterator();\r
342 int index = 0;\r
343 while (item.hasNext()){\r
344 desList[index] = (String)item.next();\r
345 index++;\r
346 }\r
347 return desList;\r
348 }\r
349 \r
a29c47e0 350}