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