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