]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/GenBuild/org/tianocore/build/global/Spd.java
Initial import.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / global / Spd.java
CommitLineData
878ddf1f 1/** @file\r
2 Spd class.\r
3\r
4 This class is to generate a global table for the content of spd file.\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.global;\r
17import java.util.HashMap;\r
18import java.util.List;\r
19import java.util.Map;\r
20\r
21import org.tianocore.PackageSurfaceAreaDocument;\r
22import org.tianocore.GuidDeclarationsDocument.GuidDeclarations;\r
23import org.tianocore.IncludeHeaderDocument.IncludeHeader;\r
24import org.tianocore.LibraryClassDeclarationDocument.LibraryClassDeclaration;\r
25import org.tianocore.LibraryClassDeclarationsDocument.LibraryClassDeclarations;\r
26import org.tianocore.PackageHeadersDocument.PackageHeaders;\r
27import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea;\r
28import org.tianocore.PpiDeclarationsDocument.PpiDeclarations;\r
29import org.tianocore.ProtocolDeclarationsDocument.ProtocolDeclarations;\r
30\r
31/**\r
32 \r
33 This class is to generate a global table for the content of spd file.\r
34 \r
35**/\r
36public class Spd {\r
37 ///\r
38 /// Map of module name and package it belongs to.\r
39 /// Key : Module BaseName\r
40 /// Value: Relative Path to Package\r
41 ///\r
42 Map<String, String[]> msaInfo = new HashMap<String, String[]>();\r
43\r
44 ///\r
45 /// Map of module info. \r
46 /// Key : moduletype\r
47 /// Value: moduletype related include file\r
48 ///\r
49 Map<String, String> moduleInfo = new HashMap<String, String>();\r
50\r
51 ///\r
52 /// Map of PPI info.\r
53 /// Key : PPI name\r
54 /// value: String[] a. PPI C_NAME; b. PPI GUID;\r
55 ///\r
56 Map<String, String[]> ppiInfo = new HashMap<String, String[]>();\r
57\r
58 ///\r
59 /// Map of Protocol info.\r
60 /// Key : Protocol name\r
61 /// value: String[] a. Protocol C_NAME; b. Protocol GUID;\r
62 ///\r
63 Map<String, String[]> protocolInfo = new HashMap<String, String[]>();\r
64\r
65 ///\r
66 /// Map of Guid info.\r
67 /// Key : Guid name\r
68 /// value: String[] a. Guid C_NAME; b. Guid's GUID;\r
69 ///\r
70 Map<String, String[]> guidInfo = new HashMap<String, String[]>();\r
71\r
72\r
73 ///\r
74 /// Map of library class and its exposed header file.\r
75 /// Key : library class name\r
76 /// value : library class corresponding header file\r
77 ///\r
78 Map<String, String> libClassHeaderList = new HashMap<String, String>();\r
79\r
80 ///\r
81 /// Package path.\r
82 ///\r
83 String packagePath = null;\r
84\r
85 /**\r
86 Constructor function\r
87 \r
88 This function mainly initialize some member variables. \r
89 \r
90 @param spdDoc Handle of spd document.\r
91 @param spdPath Path of spd file.\r
92 **/\r
93 Spd (PackageSurfaceAreaDocument spdDoc, String spdPath) {\r
94\r
95 PackageSurfaceArea spd = spdDoc.getPackageSurfaceArea();\r
96 this.packagePath = spdPath;\r
97\r
98 GuidDeclarations spdGuidInfo = spd.getGuidDeclarations();\r
99 genGuidInfoList(spdGuidInfo);\r
100\r
101 PpiDeclarations spdPpiInfo = spd.getPpiDeclarations();\r
102 genPpiInfoList(spdPpiInfo);\r
103\r
104 ProtocolDeclarations spdProtocolInfo = spd.getProtocolDeclarations();\r
105 genProtocolInfoList(spdProtocolInfo);\r
106\r
107 LibraryClassDeclarations spdLibClassDeclare = spd\r
108 .getLibraryClassDeclarations();\r
109 genLibClassDeclare(spdLibClassDeclare);\r
110\r
111 PackageHeaders spdPackageHeaderInfo = spd.getPackageHeaders();\r
112 genModuleInfoList(spdPackageHeaderInfo);\r
113\r
114 }\r
115\r
116 /**\r
117 genModuleInfoList\r
118 \r
119 This function is to generate Module info map.\r
120 \r
121 @param packageHeader The information of packageHeader which descripted\r
122 in spd file. \r
123 **/\r
124 public void genModuleInfoList(PackageHeaders packageHeader) {\r
125\r
126 if (packageHeader != null) {\r
127 List<IncludeHeader> headerList = packageHeader.getIncludeHeaderList();\r
128 for (int i = 0; i < headerList.size(); i++) {\r
129 try {\r
130 this.moduleInfo\r
131 .put(headerList.get(i).getModuleType()\r
132 .toString(), headerList.get(i)\r
133 .getStringValue());\r
134 } catch (Exception e) {\r
135 System.out\r
136 .print("can't find ModuleHeaders ModuleType & includeHeader!\n");\r
137 }\r
138 }\r
139 }\r
140 }\r
141\r
142 /**\r
143 genPpiInfoList\r
144 \r
145 This function is to generate Ppi info map.\r
146 \r
147 @param ppiInfo The information of PpiDeclarations which descripted\r
148 in spd file. \r
149 **/\r
150 public void genPpiInfoList(PpiDeclarations ppiInfo) {\r
151 String[] cNameGuid = new String[2];\r
152\r
153 if (ppiInfo != null) {\r
154 List<PpiDeclarations.Entry> ppiEntryList = ppiInfo.getEntryList();\r
155 for (int i = 0; i < ppiEntryList.size(); i++) {\r
156 try {\r
157 cNameGuid[0] = ppiEntryList.get(i).getCName();\r
158 cNameGuid[1] = formatGuidName(ppiEntryList.get(i)\r
159 .getGuid().getStringValue());\r
160 this.ppiInfo.put(ppiEntryList.get(i).getName(), new String[] {\r
161 cNameGuid[0], cNameGuid[1] });\r
162 } catch (Exception e) {\r
163 System.out\r
164 .print("can't find GuidDeclarations C_Name & Guid!\n");\r
165 }\r
166 }\r
167 }\r
168 }\r
169\r
170 /**\r
171 genProtocolInfoList \r
172 \r
173 This function is to generate Protocol info map.\r
174 \r
175 @param proInfo The information of ProtocolDeclarations which \r
176 descripted in spd file.\r
177 **/\r
178 public void genProtocolInfoList(ProtocolDeclarations proInfo) {\r
179 String[] cNameGuid = new String[2];\r
180 if (proInfo != null) {\r
181 List<ProtocolDeclarations.Entry> protocolEntryList = proInfo.getEntryList();\r
182 for (int i = 0; i < protocolEntryList.size(); i++) {\r
183 try {\r
184 cNameGuid[0] = protocolEntryList.get(i).getCName();\r
185 cNameGuid[1] = formatGuidName(protocolEntryList.get(i)\r
186 .getGuid().getStringValue());\r
187\r
188 String temp = new String(protocolEntryList.get(i).getName());\r
189 this.protocolInfo.put(temp, new String[] { cNameGuid[0],\r
190 cNameGuid[1] });\r
191 } catch (Exception e) {\r
192 System.out\r
193 .print("can't find ProtocolDeclarations C_Name & Guid!\n");\r
194 }\r
195 }\r
196 }\r
197 }\r
198\r
199 /**\r
200 genGuidInfoList\r
201 \r
202 This function is to generate GUID inf map.\r
203 \r
204 @param guidInfo The information of GuidDeclarations which descripted\r
205 in spd file.\r
206 \r
207 **/\r
208 public void genGuidInfoList(GuidDeclarations guidInfo) {\r
209 String[] cNameGuid = new String[2];\r
210 if (guidInfo != null) {\r
211 \r
212 List<GuidDeclarations.Entry> guidEntryList = guidInfo.getEntryList();\r
213 for (int i = 0; i < guidEntryList.size(); i++) {\r
214 cNameGuid[0] = guidEntryList.get(i).getCName();\r
215 cNameGuid[1] = formatGuidName(guidEntryList.get(i)\r
216 .getGuid().getStringValue());\r
217 this.guidInfo.put(guidEntryList.get(i).getName(), new String[] {\r
218 cNameGuid[0], cNameGuid[1] });\r
219 }\r
220 }\r
221 }\r
222\r
223 /**\r
224 genLibClassDeclare\r
225 \r
226 This function is to generate the libClassHeader list.\r
227 \r
228 @param libClassDeclares The information of LibraryClassDeclarations which\r
229 descripted in spd file.\r
230 **/\r
231 public void genLibClassDeclare(LibraryClassDeclarations libClassDeclares) {\r
232 if (libClassDeclares != null && libClassDeclares.getLibraryClassDeclarationList() != null) {\r
233 if (libClassDeclares.getLibraryClassDeclarationList().size() > 0) {\r
234 List<LibraryClassDeclaration> libDeclareList = libClassDeclares.getLibraryClassDeclarationList();\r
235 for (int i = 0; i < libDeclareList.size(); i++) {\r
236 libClassHeaderList.put(libDeclareList.get(i).getLibraryClass()\r
237 .getStringValue(), libDeclareList.get(i)\r
238 .getIncludeHeader().getStringValue());\r
239 }\r
240 }\r
241 }\r
242 }\r
243\r
244 /**\r
245 getPpiGuid\r
246 \r
247 This function is to get ppi GUID according ppi name.\r
248 \r
249 @param ppiStr Name of ppi.\r
250 @return PPi's GUID.\r
251 **/\r
252 public String getPpiGuid(String ppiStr) {\r
253 if (ppiInfo.get(ppiStr) != null) {\r
254 return ppiInfo.get(ppiStr)[1];\r
255 } else {\r
256 return null;\r
257 }\r
258\r
259 }\r
260\r
261 /**\r
262 getPpiCnameGuidArray\r
263 \r
264 This function is to get the ppi CName and it's GUID according to ppi name.\r
265 \r
266 @param ppiName Name of ppi.\r
267 @return Ppi CName and it's GUID.\r
268 **/\r
269 public String[] getPpiCnameGuidArray(String ppiName) {\r
270 return this.ppiInfo.get(ppiName);\r
271 }\r
272\r
273 /**\r
274 getProtocolGuid\r
275 \r
276 This function is to get the protocol GUID according to protocol's name.\r
277 \r
278 @param protocolStr Name of protocol.\r
279 @return Protocol's GUID.\r
280 **/\r
281 public String getProtocolGuid(String protocolStr) {\r
282 if (protocolInfo.get(protocolStr) != null) {\r
283 return this.protocolInfo.get(protocolStr)[0];\r
284 } else {\r
285 return null;\r
286 }\r
287 }\r
288\r
289 /**\r
290 getProtocolNameGuidArray\r
291 \r
292 This function is to get the protocol's CName ant it's GUID according to\r
293 protocol's namej.\r
294 \r
295 @param protocolName Name of protocl.\r
296 @return Protocol's CName and it's GUID.\r
297 **/\r
298 public String[] getProtocolNameGuidArray(String protocolName) {\r
299 return this.protocolInfo.get(protocolName);\r
300 }\r
301\r
302 /**\r
303 getGUIDGuid\r
304 \r
305 This function is to get the GUID according to GUID's name\r
306 \r
307 @param guidStr Name of GUID\r
308 @return GUID.\r
309 **/\r
310 public String getGUIDGuid(String guidStr) {\r
311 if (guidInfo.get(guidStr) != null) {\r
312 return guidInfo.get(guidStr)[1];\r
313 } else {\r
314 return null;\r
315 }\r
316\r
317 }\r
318\r
319 /**\r
320 getGuidNameArray\r
321 \r
322 This function is to get the GUID's CName and it's GUID according to \r
323 GUID's name\r
324 \r
325 @param guidName Name of GUID\r
326 @return CName and GUID.\r
327 **/\r
328 public String[] getGuidNameArray(String guidName) {\r
329 return this.guidInfo.get(guidName);\r
330 }\r
331\r
332 /**\r
333 getLibClassInclude \r
334 \r
335 This function is to get the library exposed header file name according \r
336 library class name.\r
337 \r
338 @param libName Name of library class \r
339 @return Name of header file\r
340 **/\r
341 String getLibClassIncluder(String libName) {\r
342 return libClassHeaderList.get(libName);\r
343 }\r
344\r
345 /**\r
346 getModuleTypeIncluder\r
347 \r
348 This function is to get the header file name from module info map \r
349 according to module type.\r
350 \r
351 @param moduleType Module type.\r
352 @return Name of header file.\r
353 **/\r
354 String getModuleTypeIncluder(String moduleType) {\r
355 return moduleInfo.get(moduleType);\r
356 }\r
357\r
358 /**\r
359 formateGuidName\r
360 \r
361 This function is to formate GUID to ANSI c form.\r
362 \r
363 @param guidNameCon String of GUID.\r
364 @return Formated GUID.\r
365 **/\r
366 public static String formatGuidName (String guidNameConv) {\r
367 String[] strList;\r
368 String guid = "";\r
369 int index = 0;\r
370 if (guidNameConv\r
371 .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
372 strList = guidNameConv.split("-");\r
373 guid = "0x" + strList[0] + ", ";\r
374 guid = guid + "0x" + strList[1] + ", ";\r
375 guid = guid + "0x" + strList[2] + ", ";\r
376 guid = guid + "{";\r
377 guid = guid + "0x" + strList[3].substring(0, 2) + ", ";\r
378 guid = guid + "0x" + strList[3].substring(2, 4);\r
379\r
380 while (index < strList[4].length()) {\r
381 guid = guid + ", ";\r
382 guid = guid + "0x" + strList[4].substring(index, index + 2);\r
383 index = index + 2;\r
384 }\r
385 guid = guid + "}";\r
386 return guid;\r
387 } else if (guidNameConv\r
388 .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
389 strList = guidNameConv.split(",");\r
390 \r
391 //\r
392 // chang Microsoft specific form to ANSI c form\r
393 //\r
394 for (int i = 0; i < 3; i++){\r
395 guid = guid + strList[i] + ",";\r
396 }\r
397 guid = guid + "{";\r
398 \r
399 for (int i = 3; i < strList.length; i++){\r
400 if (i == strList.length - 1){\r
401 guid = guid + strList[i];\r
402 } else {\r
403 guid = guid + strList[i] + ",";\r
404 }\r
405 }\r
406 guid = guid + "}"; \r
407 return guid;\r
408 } else {\r
409 System.out.println("Check GUID Value, it don't conform to the schema!!!");\r
410 return "0";\r
411\r
412 }\r
413 }\r
414}\r