llvm.org GIT mirror llvm / 8ec018c
Use yaml::IO in yaml2obj.cpp. The generic structs and specializations will be refactored when obj2yaml is changed to use yaml::IO. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@178593 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 7 years ago
1 changed file(s) with 350 addition(s) and 555 deletion(s). Raw diff Collapse all Expand all
2626 #include "llvm/Support/PrettyStackTrace.h"
2727 #include "llvm/Support/Signals.h"
2828 #include "llvm/Support/SourceMgr.h"
29 #include "llvm/Support/YAMLParser.h"
29 #include "llvm/Support/YAMLTraits.h"
3030 #include "llvm/Support/raw_ostream.h"
3131 #include "llvm/Support/system_error.h"
3232 #include
3535
3636 static cl::opt
3737 Input(cl::Positional, cl::desc(""), cl::init("-"));
38
39 namespace {
3840
3941 template
4042 typename llvm::enable_if_c::is_integer, bool>::type
110112 return true;
111113 }
112114
115 // The structure of the yaml files is not an exact 1:1 match to COFF. In order
116 // to use yaml::IO, we use these structures which are closer to the source.
117 namespace COFFYAML {
118 struct Relocation {
119 uint32_t VirtualAddress;
120 uint32_t SymbolTableIndex;
121 COFF::RelocationTypeX86 Type;
122 };
123
124 struct Section {
125 std::vector Characteristics;
126 StringRef SectionData;
127 std::vector Relocations;
128 StringRef Name;
129 };
130
131 struct Header {
132 COFF::MachineTypes Machine;
133 };
134
135 struct Symbol {
136 COFF::SymbolBaseType SimpleType;
137 uint8_t NumberOfAuxSymbols;
138 StringRef Name;
139 COFF::SymbolStorageClass StorageClass;
140 StringRef AuxillaryData;
141 COFF::SymbolComplexType ComplexType;
142 uint32_t Value;
143 uint16_t SectionNumber;
144 };
145
146 struct Object {
147 Header HeaderData;
148 std::vector
Sections;
149 std::vector Symbols;
150 };
151 }
152
113153 /// This parses a yaml stream that represents a COFF object file.
114154 /// See docs/yaml2obj for the yaml scheema.
115155 struct COFFParser {
116 COFFParser(yaml::Stream &Input) : YS(Input) {
156 COFFParser(COFFYAML::Object &Obj) : Obj(Obj) {
117157 std::memset(&Header, 0, sizeof(Header));
118158 // A COFF string table always starts with a 4 byte size field. Offsets into
119159 // it include this size, so allocate it now.
120160 StringTable.append(4, 0);
121161 }
122162
123 bool parseHeader(yaml::Node *HeaderN) {
124 yaml::MappingNode *MN = dyn_cast(HeaderN);
125 if (!MN) {
126 YS.printError(HeaderN, "header's value must be a mapping node");
127 return false;
128 }
129 for (yaml::MappingNode::iterator i = MN->begin(), e = MN->end();
130 i != e; ++i) {
131 yaml::ScalarNode *Key = dyn_cast(i->getKey());
132 if (!Key) {
133 YS.printError(i->getKey(), "Keys must be scalar values");
134 return false;
135 }
136 SmallString<32> Storage;
137 StringRef KeyValue = Key->getValue(Storage);
138 if (KeyValue == "Characteristics") {
139 if (!parseHeaderCharacteristics(i->getValue()))
140 return false;
163 bool parseSections() {
164 for (std::vector::iterator i = Obj.Sections.begin(),
165 e = Obj.Sections.end(); i != e; ++i) {
166 const COFFYAML::Section &YamlSection = *i;
167 Section Sec;
168 std::memset(&Sec.Header, 0, sizeof(Sec.Header));
169
170 // If the name is less than 8 bytes, store it in place, otherwise
171 // store it in the string table.
172 StringRef Name = YamlSection.Name;
173 std::fill_n(Sec.Header.Name, unsigned(COFF::NameSize), 0);
174 if (Name.size() <= COFF::NameSize) {
175 std::copy(Name.begin(), Name.end(), Sec.Header.Name);
141176 } else {
142 yaml::ScalarNode *Value = dyn_cast(i->getValue());
143 if (!Value) {
144 YS.printError(Value,
145 Twine(KeyValue) + " must be a scalar value");
177 // Add string to the string table and format the index for output.
178 unsigned Index = getStringIndex(Name);
179 std::string str = utostr(Index);
180 if (str.size() > 7) {
181 errs() << "String table got too large";
146182 return false;
147183 }
148 if (KeyValue == "Machine") {
149 uint16_t Machine = COFF::MT_Invalid;
150 if (!getAs(Value, Machine)) {
151 // It's not a raw number, try matching the string.
152 StringRef ValueValue = Value->getValue(Storage);
153 Machine = StringSwitch(ValueValue)
154 .Case( "IMAGE_FILE_MACHINE_UNKNOWN"
155 , COFF::IMAGE_FILE_MACHINE_UNKNOWN)
156 .Case( "IMAGE_FILE_MACHINE_AM33"
157 , COFF::IMAGE_FILE_MACHINE_AM33)
158 .Case( "IMAGE_FILE_MACHINE_AMD64"
159 , COFF::IMAGE_FILE_MACHINE_AMD64)
160 .Case( "IMAGE_FILE_MACHINE_ARM"
161 , COFF::IMAGE_FILE_MACHINE_ARM)
162 .Case( "IMAGE_FILE_MACHINE_ARMV7"
163 , COFF::IMAGE_FILE_MACHINE_ARMV7)
164 .Case( "IMAGE_FILE_MACHINE_EBC"
165 , COFF::IMAGE_FILE_MACHINE_EBC)
166 .Case( "IMAGE_FILE_MACHINE_I386"
167 , COFF::IMAGE_FILE_MACHINE_I386)
168 .Case( "IMAGE_FILE_MACHINE_IA64"
169 , COFF::IMAGE_FILE_MACHINE_IA64)
170 .Case( "IMAGE_FILE_MACHINE_M32R"
171 , COFF::IMAGE_FILE_MACHINE_M32R)
172 .Case( "IMAGE_FILE_MACHINE_MIPS16"
173 , COFF::IMAGE_FILE_MACHINE_MIPS16)
174 .Case( "IMAGE_FILE_MACHINE_MIPSFPU"
175 , COFF::IMAGE_FILE_MACHINE_MIPSFPU)
176 .Case( "IMAGE_FILE_MACHINE_MIPSFPU16"
177 , COFF::IMAGE_FILE_MACHINE_MIPSFPU16)
178 .Case( "IMAGE_FILE_MACHINE_POWERPC"
179 , COFF::IMAGE_FILE_MACHINE_POWERPC)
180 .Case( "IMAGE_FILE_MACHINE_POWERPCFP"
181 , COFF::IMAGE_FILE_MACHINE_POWERPCFP)
182 .Case( "IMAGE_FILE_MACHINE_R4000"
183 , COFF::IMAGE_FILE_MACHINE_R4000)
184 .Case( "IMAGE_FILE_MACHINE_SH3"
185 , COFF::IMAGE_FILE_MACHINE_SH3)
186 .Case( "IMAGE_FILE_MACHINE_SH3DSP"
187 , COFF::IMAGE_FILE_MACHINE_SH3DSP)
188 .Case( "IMAGE_FILE_MACHINE_SH4"
189 , COFF::IMAGE_FILE_MACHINE_SH4)
190 .Case( "IMAGE_FILE_MACHINE_SH5"
191 , COFF::IMAGE_FILE_MACHINE_SH5)
192 .Case( "IMAGE_FILE_MACHINE_THUMB"
193 , COFF::IMAGE_FILE_MACHINE_THUMB)
194 .Case( "IMAGE_FILE_MACHINE_WCEMIPSV2"
195 , COFF::IMAGE_FILE_MACHINE_WCEMIPSV2)
196 .Default(COFF::MT_Invalid);
197 if (Machine == COFF::MT_Invalid) {
198 YS.printError(Value, "Invalid value for Machine");
199 return false;
200 }
201 }
202 Header.Machine = Machine;
203 } else if (KeyValue == "NumberOfSections") {
204 if (!getAs(Value, Header.NumberOfSections)) {
205 YS.printError(Value, "Invalid value for NumberOfSections");
206 return false;
207 }
208 } else if (KeyValue == "TimeDateStamp") {
209 if (!getAs(Value, Header.TimeDateStamp)) {
210 YS.printError(Value, "Invalid value for TimeDateStamp");
211 return false;
212 }
213 } else if (KeyValue == "PointerToSymbolTable") {
214 if (!getAs(Value, Header.PointerToSymbolTable)) {
215 YS.printError(Value, "Invalid value for PointerToSymbolTable");
216 return false;
217 }
218 } else if (KeyValue == "NumberOfSymbols") {
219 if (!getAs(Value, Header.NumberOfSymbols)) {
220 YS.printError(Value, "Invalid value for NumberOfSymbols");
221 return false;
222 }
223 } else if (KeyValue == "SizeOfOptionalHeader") {
224 if (!getAs(Value, Header.SizeOfOptionalHeader)) {
225 YS.printError(Value, "Invalid value for SizeOfOptionalHeader");
226 return false;
227 }
228 } else {
229 YS.printError(Key, "Unrecognized key in header");
230 return false;
231 }
184 Sec.Header.Name[0] = '/';
185 std::copy(str.begin(), str.end(), Sec.Header.Name + 1);
232186 }
233 }
234 return true;
235 }
236
237 bool parseHeaderCharacteristics(yaml::Node *Characteristics) {
238 yaml::ScalarNode *Value = dyn_cast(Characteristics);
239 yaml::SequenceNode *SeqValue
240 = dyn_cast(Characteristics);
241 if (!Value && !SeqValue) {
242 YS.printError(Characteristics,
243 "Characteristics must either be a number or sequence");
244 return false;
245 }
246 if (Value) {
247 if (!getAs(Value, Header.Characteristics)) {
248 YS.printError(Value, "Invalid value for Characteristics");
187
188 for (std::vector::const_iterator i =
189 YamlSection.Characteristics.begin(),
190 e = YamlSection.Characteristics.end();
191 i != e; ++i) {
192 uint32_t Characteristic = *i;
193 Sec.Header.Characteristics |= Characteristic;
194 }
195
196 StringRef Data = YamlSection.SectionData;
197 if (!hexStringToByteArray(Data, Sec.Data)) {
198 errs() << "SectionData must be a collection of pairs of hex bytes";
249199 return false;
250 }
251 } else {
252 for (yaml::SequenceNode::iterator ci = SeqValue->begin(),
253 ce = SeqValue->end();
254 ci != ce; ++ci) {
255 yaml::ScalarNode *CharValue = dyn_cast(&*ci);
256 if (!CharValue) {
257 YS.printError(CharValue,
258 "Characteristics must be scalar values");
259 return false;
260 }
261 SmallString<32> Storage;
262 StringRef Char = CharValue->getValue(Storage);
263 uint16_t Characteristic = StringSwitch(Char)
264 .Case( "IMAGE_FILE_RELOCS_STRIPPED"
265 , COFF::IMAGE_FILE_RELOCS_STRIPPED)
266 .Case( "IMAGE_FILE_EXECUTABLE_IMAGE"
267 , COFF::IMAGE_FILE_EXECUTABLE_IMAGE)
268 .Case( "IMAGE_FILE_LINE_NUMS_STRIPPED"
269 , COFF::IMAGE_FILE_LINE_NUMS_STRIPPED)
270 .Case( "IMAGE_FILE_LOCAL_SYMS_STRIPPED"
271 , COFF::IMAGE_FILE_LOCAL_SYMS_STRIPPED)
272 .Case( "IMAGE_FILE_AGGRESSIVE_WS_TRIM"
273 , COFF::IMAGE_FILE_AGGRESSIVE_WS_TRIM)
274 .Case( "IMAGE_FILE_LARGE_ADDRESS_AWARE"
275 , COFF::IMAGE_FILE_LARGE_ADDRESS_AWARE)
276 .Case( "IMAGE_FILE_BYTES_REVERSED_LO"
277 , COFF::IMAGE_FILE_BYTES_REVERSED_LO)
278 .Case( "IMAGE_FILE_32BIT_MACHINE"
279 , COFF::IMAGE_FILE_32BIT_MACHINE)
280 .Case( "IMAGE_FILE_DEBUG_STRIPPED"
281 , COFF::IMAGE_FILE_DEBUG_STRIPPED)
282 .Case( "IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP"
283 , COFF::IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP)
284 .Case( "IMAGE_FILE_SYSTEM"
285 , COFF::IMAGE_FILE_SYSTEM)
286 .Case( "IMAGE_FILE_DLL"
287 , COFF::IMAGE_FILE_DLL)
288 .Case( "IMAGE_FILE_UP_SYSTEM_ONLY"
289 , COFF::IMAGE_FILE_UP_SYSTEM_ONLY)
290 .Default(COFF::C_Invalid);
291 if (Characteristic == COFF::C_Invalid) {
292 // TODO: Typo-correct.
293 YS.printError(CharValue,
294 "Invalid value for Characteristic");
295 return false;
296 }
297 Header.Characteristics |= Characteristic;
298 }
299 }
300 return true;
301 }
302
303 bool parseSections(yaml::Node *SectionsN) {
304 yaml::SequenceNode *SN = dyn_cast(SectionsN);
305 if (!SN) {
306 YS.printError(SectionsN, "Sections must be a sequence");
307 return false;
308 }
309 for (yaml::SequenceNode::iterator i = SN->begin(), e = SN->end();
310 i != e; ++i) {
311 Section Sec;
312 std::memset(&Sec.Header, 0, sizeof(Sec.Header));
313 yaml::MappingNode *SecMap = dyn_cast(&*i);
314 if (!SecMap) {
315 YS.printError(&*i, "Section entry must be a map");
316 return false;
317 }
318 for (yaml::MappingNode::iterator si = SecMap->begin(), se = SecMap->end();
319 si != se; ++si) {
320 yaml::ScalarNode *Key = dyn_cast(si->getKey());
321 if (!Key) {
322 YS.printError(si->getKey(), "Keys must be scalar values");
323 return false;
324 }
325 SmallString<32> Storage;
326 StringRef KeyValue = Key->getValue(Storage);
327
328 yaml::ScalarNode *Value = dyn_cast(si->getValue());
329 if (KeyValue == "Name") {
330 // If the name is less than 8 bytes, store it in place, otherwise
331 // store it in the string table.
332 StringRef Name = Value->getValue(Storage);
333 std::fill_n(Sec.Header.Name, unsigned(COFF::NameSize), 0);
334 if (Name.size() <= COFF::NameSize) {
335 std::copy(Name.begin(), Name.end(), Sec.Header.Name);
336 } else {
337 // Add string to the string table and format the index for output.
338 unsigned Index = getStringIndex(Name);
339 std::string str = utostr(Index);
340 if (str.size() > 7) {
341 YS.printError(Value, "String table got too large");
342 return false;
343 }
344 Sec.Header.Name[0] = '/';
345 std::copy(str.begin(), str.end(), Sec.Header.Name + 1);
346 }
347 } else if (KeyValue == "VirtualSize") {
348 if (!getAs(Value, Sec.Header.VirtualSize)) {
349 YS.printError(Value, "Invalid value for VirtualSize");
350 return false;
351 }
352 } else if (KeyValue == "VirtualAddress") {
353 if (!getAs(Value, Sec.Header.VirtualAddress)) {
354 YS.printError(Value, "Invalid value for VirtualAddress");
355 return false;
356 }
357 } else if (KeyValue == "SizeOfRawData") {
358 if (!getAs(Value, Sec.Header.SizeOfRawData)) {
359 YS.printError(Value, "Invalid value for SizeOfRawData");
360 return false;
361 }
362 } else if (KeyValue == "PointerToRawData") {
363 if (!getAs(Value, Sec.Header.PointerToRawData)) {
364 YS.printError(Value, "Invalid value for PointerToRawData");
365 return false;
366 }
367 } else if (KeyValue == "PointerToRelocations") {
368 if (!getAs(Value, Sec.Header.PointerToRelocations)) {
369 YS.printError(Value, "Invalid value for PointerToRelocations");
370 return false;
371 }
372 } else if (KeyValue == "PointerToLineNumbers") {
373 if (!getAs(Value, Sec.Header.PointerToLineNumbers)) {
374 YS.printError(Value, "Invalid value for PointerToLineNumbers");
375 return false;
376 }
377 } else if (KeyValue == "NumberOfRelocations") {
378 if (!getAs(Value, Sec.Header.NumberOfRelocations)) {
379 YS.printError(Value, "Invalid value for NumberOfRelocations");
380 return false;
381 }
382 } else if (KeyValue == "NumberOfLineNumbers") {
383 if (!getAs(Value, Sec.Header.NumberOfLineNumbers)) {
384 YS.printError(Value, "Invalid value for NumberOfLineNumbers");
385 return false;
386 }
387 } else if (KeyValue == "Characteristics") {
388 yaml::SequenceNode *SeqValue
389 = dyn_cast(si->getValue());
390 if (!Value && !SeqValue) {
391 YS.printError(si->getValue(),
392 "Characteristics must either be a number or sequence");
393 return false;
394 }
395 if (Value) {
396 if (!getAs(Value, Sec.Header.Characteristics)) {
397 YS.printError(Value, "Invalid value for Characteristics");
398 return false;
399 }
400 } else {
401 for (yaml::SequenceNode::iterator ci = SeqValue->begin(),
402 ce = SeqValue->end();
403 ci != ce; ++ci) {
404 yaml::ScalarNode *CharValue = dyn_cast(&*ci);
405 if (!CharValue) {
406 YS.printError(CharValue, "Invalid value for Characteristics");
407 return false;
408 }
409 StringRef Char = CharValue->getValue(Storage);
410 uint32_t Characteristic =
411 StringSwitch(Char)
412 .Case( "IMAGE_SCN_TYPE_NO_PAD"
413 , COFF::IMAGE_SCN_TYPE_NO_PAD)
414 .Case( "IMAGE_SCN_CNT_CODE"
415 , COFF::IMAGE_SCN_CNT_CODE)
416 .Case( "IMAGE_SCN_CNT_INITIALIZED_DATA"
417 , COFF::IMAGE_SCN_CNT_INITIALIZED_DATA)
418 .Case( "IMAGE_SCN_CNT_UNINITIALIZED_DATA"
419 , COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA)
420 .Case( "IMAGE_SCN_LNK_OTHER"
421 , COFF::IMAGE_SCN_LNK_OTHER)
422 .Case( "IMAGE_SCN_LNK_INFO"
423 , COFF::IMAGE_SCN_LNK_INFO)
424 .Case( "IMAGE_SCN_LNK_REMOVE"
425 , COFF::IMAGE_SCN_LNK_REMOVE)
426 .Case( "IMAGE_SCN_LNK_COMDAT"
427 , COFF::IMAGE_SCN_LNK_COMDAT)
428 .Case( "IMAGE_SCN_GPREL"
429 , COFF::IMAGE_SCN_GPREL)
430 .Case( "IMAGE_SCN_MEM_PURGEABLE"
431 , COFF::IMAGE_SCN_MEM_PURGEABLE)
432 .Case( "IMAGE_SCN_MEM_16BIT"
433 , COFF::IMAGE_SCN_MEM_16BIT)
434 .Case( "IMAGE_SCN_MEM_LOCKED"
435 , COFF::IMAGE_SCN_MEM_LOCKED)
436 .Case( "IMAGE_SCN_MEM_PRELOAD"
437 , COFF::IMAGE_SCN_MEM_PRELOAD)
438 .Case( "IMAGE_SCN_ALIGN_1BYTES"
439 , COFF::IMAGE_SCN_ALIGN_1BYTES)
440 .Case( "IMAGE_SCN_ALIGN_2BYTES"
441 , COFF::IMAGE_SCN_ALIGN_2BYTES)
442 .Case( "IMAGE_SCN_ALIGN_4BYTES"
443 , COFF::IMAGE_SCN_ALIGN_4BYTES)
444 .Case( "IMAGE_SCN_ALIGN_8BYTES"
445 , COFF::IMAGE_SCN_ALIGN_8BYTES)
446 .Case( "IMAGE_SCN_ALIGN_16BYTES"
447 , COFF::IMAGE_SCN_ALIGN_16BYTES)
448 .Case( "IMAGE_SCN_ALIGN_32BYTES"
449 , COFF::IMAGE_SCN_ALIGN_32BYTES)
450 .Case( "IMAGE_SCN_ALIGN_64BYTES"
451 , COFF::IMAGE_SCN_ALIGN_64BYTES)
452 .Case( "IMAGE_SCN_ALIGN_128BYTES"
453 , COFF::IMAGE_SCN_ALIGN_128BYTES)
454 .Case( "IMAGE_SCN_ALIGN_256BYTES"
455 , COFF::IMAGE_SCN_ALIGN_256BYTES)
456 .Case( "IMAGE_SCN_ALIGN_512BYTES"
457 , COFF::IMAGE_SCN_ALIGN_512BYTES)
458 .Case( "IMAGE_SCN_ALIGN_1024BYTES"
459 , COFF::IMAGE_SCN_ALIGN_1024BYTES)
460 .Case( "IMAGE_SCN_ALIGN_2048BYTES"
461 , COFF::IMAGE_SCN_ALIGN_2048BYTES)
462 .Case( "IMAGE_SCN_ALIGN_4096BYTES"
463 , COFF::IMAGE_SCN_ALIGN_4096BYTES)
464 .Case( "IMAGE_SCN_ALIGN_8192BYTES"
465 , COFF::IMAGE_SCN_ALIGN_8192BYTES)
466 .Case( "IMAGE_SCN_LNK_NRELOC_OVFL"
467 , COFF::IMAGE_SCN_LNK_NRELOC_OVFL)
468 .Case( "IMAGE_SCN_MEM_DISCARDABLE"
469 , COFF::IMAGE_SCN_MEM_DISCARDABLE)
470 .Case( "IMAGE_SCN_MEM_NOT_CACHED"
471 , COFF::IMAGE_SCN_MEM_NOT_CACHED)
472 .Case( "IMAGE_SCN_MEM_NOT_PAGED"
473 , COFF::IMAGE_SCN_MEM_NOT_PAGED)
474 .Case( "IMAGE_SCN_MEM_SHARED"
475 , COFF::IMAGE_SCN_MEM_SHARED)
476 .Case( "IMAGE_SCN_MEM_EXECUTE"
477 , COFF::IMAGE_SCN_MEM_EXECUTE)
478 .Case( "IMAGE_SCN_MEM_READ"
479 , COFF::IMAGE_SCN_MEM_READ)
480 .Case( "IMAGE_SCN_MEM_WRITE"
481 , COFF::IMAGE_SCN_MEM_WRITE)
482 .Default(COFF::SC_Invalid);
483 if (Characteristic == COFF::SC_Invalid) {
484 YS.printError(CharValue, "Invalid value for Characteristic");
485 return false;
486 }
487 Sec.Header.Characteristics |= Characteristic;
488 }
489 }
490 } else if (KeyValue == "SectionData") {
491 yaml::ScalarNode *Value = dyn_cast(si->getValue());
492 SmallString<32> Storage;
493 StringRef Data = Value->getValue(Storage);
494 if (!hexStringToByteArray(Data, Sec.Data)) {
495 YS.printError(Value, "SectionData must be a collection of pairs of"
496 "hex bytes");
497 return false;
498 }
499 } else
500 si->skip();
501200 }
502201 Sections.push_back(Sec);
503202 }
504203 return true;
505204 }
506205
507 bool parseSymbols(yaml::Node *SymbolsN) {
508 yaml::SequenceNode *SN = dyn_cast(SymbolsN);
509 if (!SN) {
510 YS.printError(SymbolsN, "Symbols must be a sequence");
511 return false;
512 }
513 for (yaml::SequenceNode::iterator i = SN->begin(), e = SN->end();
514 i != e; ++i) {
206 bool parseSymbols() {
207 for (std::vector::iterator i = Obj.Symbols.begin(),
208 e = Obj.Symbols.end(); i != e; ++i) {
209 COFFYAML::Symbol YamlSymbol = *i;
515210 Symbol Sym;
516211 std::memset(&Sym.Header, 0, sizeof(Sym.Header));
517 yaml::MappingNode *SymMap = dyn_cast(&*i);
518 if (!SymMap) {
519 YS.printError(&*i, "Symbol must be a map");
212
213 // If the name is less than 8 bytes, store it in place, otherwise
214 // store it in the string table.
215 StringRef Name = YamlSymbol.Name;
216 std::fill_n(Sym.Header.Name, unsigned(COFF::NameSize), 0);
217 if (Name.size() <= COFF::NameSize) {
218 std::copy(Name.begin(), Name.end(), Sym.Header.Name);
219 } else {
220 // Add string to the string table and format the index for output.
221 unsigned Index = getStringIndex(Name);
222 *reinterpret_cast(
223 Sym.Header.Name + 4) = Index;
224 }
225
226 Sym.Header.Value = YamlSymbol.Value;
227 Sym.Header.Type |= YamlSymbol.SimpleType;
228 Sym.Header.Type |= YamlSymbol.ComplexType << COFF::SCT_COMPLEX_TYPE_SHIFT;
229 Sym.Header.StorageClass = YamlSymbol.StorageClass;
230 Sym.Header.SectionNumber = YamlSymbol.SectionNumber;
231
232 StringRef Data = YamlSymbol.AuxillaryData;
233 if (!hexStringToByteArray(Data, Sym.AuxSymbols)) {
234 errs() << "AuxillaryData must be a collection of pairs of hex bytes";
520235 return false;
521 }
522 for (yaml::MappingNode::iterator si = SymMap->begin(), se = SymMap->end();
523 si != se; ++si) {
524 yaml::ScalarNode *Key = dyn_cast(si->getKey());
525 if (!Key) {
526 YS.printError(si->getKey(), "Keys must be scalar values");
527 return false;
528 }
529 SmallString<32> Storage;
530 StringRef KeyValue = Key->getValue(Storage);
531
532 yaml::ScalarNode *Value = dyn_cast(si->getValue());
533 if (!Value) {
534 YS.printError(si->getValue(), "Must be a scalar value");
535 return false;
536 }
537 if (KeyValue == "Name") {
538 // If the name is less than 8 bytes, store it in place, otherwise
539 // store it in the string table.
540 StringRef Name = Value->getValue(Storage);
541 std::fill_n(Sym.Header.Name, unsigned(COFF::NameSize), 0);
542 if (Name.size() <= COFF::NameSize) {
543 std::copy(Name.begin(), Name.end(), Sym.Header.Name);
544 } else {
545 // Add string to the string table and format the index for output.
546 unsigned Index = getStringIndex(Name);
547 *reinterpret_cast(
548 Sym.Header.Name + 4) = Index;
549 }
550 } else if (KeyValue == "Value") {
551 if (!getAs(Value, Sym.Header.Value)) {
552 YS.printError(Value, "Invalid value for Value");
553 return false;
554 }
555 } else if (KeyValue == "SimpleType") {
556 Sym.Header.Type |= StringSwitch(
557 Value->getValue(Storage))
558 .Case("IMAGE_SYM_TYPE_NULL", COFF::IMAGE_SYM_TYPE_NULL)
559 .Case("IMAGE_SYM_TYPE_VOID", COFF::IMAGE_SYM_TYPE_VOID)
560 .Case("IMAGE_SYM_TYPE_CHAR", COFF::IMAGE_SYM_TYPE_CHAR)
561 .Case("IMAGE_SYM_TYPE_SHORT", COFF::IMAGE_SYM_TYPE_SHORT)
562 .Case("IMAGE_SYM_TYPE_INT", COFF::IMAGE_SYM_TYPE_INT)
563 .Case("IMAGE_SYM_TYPE_LONG", COFF::IMAGE_SYM_TYPE_LONG)
564 .Case("IMAGE_SYM_TYPE_FLOAT", COFF::IMAGE_SYM_TYPE_FLOAT)
565 .Case("IMAGE_SYM_TYPE_DOUBLE", COFF::IMAGE_SYM_TYPE_DOUBLE)
566 .Case("IMAGE_SYM_TYPE_STRUCT", COFF::IMAGE_SYM_TYPE_STRUCT)
567 .Case("IMAGE_SYM_TYPE_UNION", COFF::IMAGE_SYM_TYPE_UNION)
568 .Case("IMAGE_SYM_TYPE_ENUM", COFF::IMAGE_SYM_TYPE_ENUM)
569 .Case("IMAGE_SYM_TYPE_MOE", COFF::IMAGE_SYM_TYPE_MOE)
570 .Case("IMAGE_SYM_TYPE_BYTE", COFF::IMAGE_SYM_TYPE_BYTE)
571 .Case("IMAGE_SYM_TYPE_WORD", COFF::IMAGE_SYM_TYPE_WORD)
572 .Case("IMAGE_SYM_TYPE_UINT", COFF::IMAGE_SYM_TYPE_UINT)
573 .Case("IMAGE_SYM_TYPE_DWORD", COFF::IMAGE_SYM_TYPE_DWORD)
574 .Default(COFF::IMAGE_SYM_TYPE_NULL);
575 } else if (KeyValue == "ComplexType") {
576 Sym.Header.Type |= StringSwitch(
577 Value->getValue(Storage))
578 .Case("IMAGE_SYM_DTYPE_NULL", COFF::IMAGE_SYM_DTYPE_NULL)
579 .Case("IMAGE_SYM_DTYPE_POINTER", COFF::IMAGE_SYM_DTYPE_POINTER)
580 .Case("IMAGE_SYM_DTYPE_FUNCTION", COFF::IMAGE_SYM_DTYPE_FUNCTION)
581 .Case("IMAGE_SYM_DTYPE_ARRAY", COFF::IMAGE_SYM_DTYPE_ARRAY)
582 .Default(COFF::IMAGE_SYM_DTYPE_NULL)
583 << COFF::SCT_COMPLEX_TYPE_SHIFT;
584 } else if (KeyValue == "StorageClass") {
585 Sym.Header.StorageClass = StringSwitch(
586 Value->getValue(Storage))
587 .Case( "IMAGE_SYM_CLASS_END_OF_FUNCTION"
588 , COFF::IMAGE_SYM_CLASS_END_OF_FUNCTION)
589 .Case( "IMAGE_SYM_CLASS_NULL"
590 , COFF::IMAGE_SYM_CLASS_NULL)
591 .Case( "IMAGE_SYM_CLASS_AUTOMATIC"
592 , COFF::IMAGE_SYM_CLASS_AUTOMATIC)
593 .Case( "IMAGE_SYM_CLASS_EXTERNAL"
594 , COFF::IMAGE_SYM_CLASS_EXTERNAL)
595 .Case( "IMAGE_SYM_CLASS_STATIC"
596 , COFF::IMAGE_SYM_CLASS_STATIC)
597 .Case( "IMAGE_SYM_CLASS_REGISTER"
598 , COFF::IMAGE_SYM_CLASS_REGISTER)
599 .Case( "IMAGE_SYM_CLASS_EXTERNAL_DEF"
600 , COFF::IMAGE_SYM_CLASS_EXTERNAL_DEF)
601 .Case( "IMAGE_SYM_CLASS_LABEL"
602 , COFF::IMAGE_SYM_CLASS_LABEL)
603 .Case( "IMAGE_SYM_CLASS_UNDEFINED_LABEL"
604 , COFF::IMAGE_SYM_CLASS_UNDEFINED_LABEL)
605 .Case( "IMAGE_SYM_CLASS_MEMBER_OF_STRUCT"
606 , COFF::IMAGE_SYM_CLASS_MEMBER_OF_STRUCT)
607 .Case( "IMAGE_SYM_CLASS_ARGUMENT"
608 , COFF::IMAGE_SYM_CLASS_ARGUMENT)
609 .Case( "IMAGE_SYM_CLASS_STRUCT_TAG"
610 , COFF::IMAGE_SYM_CLASS_STRUCT_TAG)
611 .Case( "IMAGE_SYM_CLASS_MEMBER_OF_UNION"
612 , COFF::IMAGE_SYM_CLASS_MEMBER_OF_UNION)
613 .Case( "IMAGE_SYM_CLASS_UNION_TAG"
614 , COFF::IMAGE_SYM_CLASS_UNION_TAG)
615 .Case( "IMAGE_SYM_CLASS_TYPE_DEFINITION"
616 , COFF::IMAGE_SYM_CLASS_TYPE_DEFINITION)
617 .Case( "IMAGE_SYM_CLASS_UNDEFINED_STATIC"
618 , COFF::IMAGE_SYM_CLASS_UNDEFINED_STATIC)
619 .Case( "IMAGE_SYM_CLASS_ENUM_TAG"
620 , COFF::IMAGE_SYM_CLASS_ENUM_TAG)
621 .Case( "IMAGE_SYM_CLASS_MEMBER_OF_ENUM"
622 , COFF::IMAGE_SYM_CLASS_MEMBER_OF_ENUM)
623 .Case( "IMAGE_SYM_CLASS_REGISTER_PARAM"
624 , COFF::IMAGE_SYM_CLASS_REGISTER_PARAM)
625 .Case( "IMAGE_SYM_CLASS_BIT_FIELD"
626 , COFF::IMAGE_SYM_CLASS_BIT_FIELD)
627 .Case( "IMAGE_SYM_CLASS_BLOCK"
628 , COFF::IMAGE_SYM_CLASS_BLOCK)
629 .Case( "IMAGE_SYM_CLASS_FUNCTION"
630 , COFF::IMAGE_SYM_CLASS_FUNCTION)
631 .Case( "IMAGE_SYM_CLASS_END_OF_STRUCT"
632 , COFF::IMAGE_SYM_CLASS_END_OF_STRUCT)
633 .Case( "IMAGE_SYM_CLASS_FILE"
634 , COFF::IMAGE_SYM_CLASS_FILE)
635 .Case( "IMAGE_SYM_CLASS_SECTION"
636 , COFF::IMAGE_SYM_CLASS_SECTION)
637 .Case( "IMAGE_SYM_CLASS_WEAK_EXTERNAL"
638 , COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL)
639 .Case( "IMAGE_SYM_CLASS_CLR_TOKEN"
640 , COFF::IMAGE_SYM_CLASS_CLR_TOKEN)
641 .Default(COFF::SSC_Invalid);
642 if (Sym.Header.StorageClass == COFF::SSC_Invalid) {
643 YS.printError(Value, "Invalid value for StorageClass");
644 return false;
645 }
646 } else if (KeyValue == "SectionNumber") {
647 if (!getAs(Value, Sym.Header.SectionNumber)) {
648 YS.printError(Value, "Invalid value for SectionNumber");
649 return false;
650 }
651 } else if (KeyValue == "AuxillaryData") {
652 StringRef Data = Value->getValue(Storage);
653 if (!hexStringToByteArray(Data, Sym.AuxSymbols)) {
654 YS.printError(Value, "AuxillaryData must be a collection of pairs"
655 "of hex bytes");
656 return false;
657 }
658 } else
659 si->skip();
660236 }
661237 Symbols.push_back(Sym);
662238 }
664240 }
665241
666242 bool parse() {
667 yaml::Document &D = *YS.begin();
668 yaml::MappingNode *Root = dyn_cast(D.getRoot());
669 if (!Root) {
670 YS.printError(D.getRoot(), "Root node must be a map");
243 Header.Machine = Obj.HeaderData.Machine;
244 if (!parseSections())
671245 return false;
672 }
673 for (yaml::MappingNode::iterator i = Root->begin(), e = Root->end();
674 i != e; ++i) {
675 yaml::ScalarNode *Key = dyn_cast(i->getKey());
676 if (!Key) {
677 YS.printError(i->getKey(), "Keys must be scalar values");
678 return false;
679 }
680 SmallString<32> Storage;
681 StringRef KeyValue = Key->getValue(Storage);
682 if (KeyValue == "header") {
683 if (!parseHeader(i->getValue()))
684 return false;
685 } else if (KeyValue == "sections") {
686 if (!parseSections(i->getValue()))
687 return false;
688 } else if (KeyValue == "symbols") {
689 if (!parseSymbols(i->getValue()))
690 return false;
691 }
692 }
693 return !YS.failed();
246 if (!parseSymbols())
247 return false;
248 return true;
694249 }
695250
696251 unsigned getStringIndex(StringRef Str) {
705260 return i->second;
706261 }
707262
708 yaml::Stream &YS;
263 COFFYAML::Object &Obj;
709264 COFF::header Header;
710265
711266 struct Section {
853408 OS.write(&CP.StringTable[0], CP.StringTable.size());
854409 }
855410
411 }
412
413 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Relocation)
414 LLVM_YAML_IS_SEQUENCE_VECTOR(COFF::SectionCharacteristics)
415 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Section)
416 LLVM_YAML_IS_SEQUENCE_VECTOR(COFFYAML::Symbol)
417
418 namespace llvm {
419 namespace yaml {
420 #define ECase(X) IO.enumCase(Value, #X, COFF::X);
421
422 template <>
423 struct ScalarEnumerationTraits {
424 static void enumeration(IO &IO, COFF::SymbolComplexType &Value) {
425 ECase(IMAGE_SYM_DTYPE_NULL);
426 ECase(IMAGE_SYM_DTYPE_POINTER);
427 ECase(IMAGE_SYM_DTYPE_FUNCTION);
428 ECase(IMAGE_SYM_DTYPE_ARRAY);
429 }
430 };
431
432 // FIXME: We cannot use ScalarBitSetTraits because of
433 // IMAGE_SYM_CLASS_END_OF_FUNCTION which is -1.
434 template <>
435 struct ScalarEnumerationTraits {
436 static void enumeration(IO &IO, COFF::SymbolStorageClass &Value) {
437 ECase(IMAGE_SYM_CLASS_END_OF_FUNCTION);
438 ECase(IMAGE_SYM_CLASS_NULL);
439 ECase(IMAGE_SYM_CLASS_AUTOMATIC);
440 ECase(IMAGE_SYM_CLASS_EXTERNAL);
441 ECase(IMAGE_SYM_CLASS_STATIC);
442 ECase(IMAGE_SYM_CLASS_REGISTER);
443 ECase(IMAGE_SYM_CLASS_EXTERNAL_DEF);
444 ECase(IMAGE_SYM_CLASS_LABEL);
445 ECase(IMAGE_SYM_CLASS_UNDEFINED_LABEL);
446 ECase(IMAGE_SYM_CLASS_MEMBER_OF_STRUCT);
447 ECase(IMAGE_SYM_CLASS_ARGUMENT);
448 ECase(IMAGE_SYM_CLASS_STRUCT_TAG);
449 ECase(IMAGE_SYM_CLASS_MEMBER_OF_UNION);
450 ECase(IMAGE_SYM_CLASS_UNION_TAG);
451 ECase(IMAGE_SYM_CLASS_TYPE_DEFINITION);
452 ECase(IMAGE_SYM_CLASS_UNDEFINED_STATIC);
453 ECase(IMAGE_SYM_CLASS_ENUM_TAG);
454 ECase(IMAGE_SYM_CLASS_MEMBER_OF_ENUM);
455 ECase(IMAGE_SYM_CLASS_REGISTER_PARAM);
456 ECase(IMAGE_SYM_CLASS_BIT_FIELD);
457 ECase(IMAGE_SYM_CLASS_BLOCK);
458 ECase(IMAGE_SYM_CLASS_FUNCTION);
459 ECase(IMAGE_SYM_CLASS_END_OF_STRUCT);
460 ECase(IMAGE_SYM_CLASS_FILE);
461 ECase(IMAGE_SYM_CLASS_SECTION);
462 ECase(IMAGE_SYM_CLASS_WEAK_EXTERNAL);
463 ECase(IMAGE_SYM_CLASS_CLR_TOKEN);
464 }
465 };
466
467 template <>
468 struct ScalarEnumerationTraits {
469 static void enumeration(IO &IO, COFF::SymbolBaseType &Value) {
470 ECase(IMAGE_SYM_TYPE_NULL);
471 ECase(IMAGE_SYM_TYPE_VOID);
472 ECase(IMAGE_SYM_TYPE_CHAR);
473 ECase(IMAGE_SYM_TYPE_SHORT);
474 ECase(IMAGE_SYM_TYPE_INT);
475 ECase(IMAGE_SYM_TYPE_LONG);
476 ECase(IMAGE_SYM_TYPE_FLOAT);
477 ECase(IMAGE_SYM_TYPE_DOUBLE);
478 ECase(IMAGE_SYM_TYPE_STRUCT);
479 ECase(IMAGE_SYM_TYPE_UNION);
480 ECase(IMAGE_SYM_TYPE_ENUM);
481 ECase(IMAGE_SYM_TYPE_MOE);
482 ECase(IMAGE_SYM_TYPE_BYTE);
483 ECase(IMAGE_SYM_TYPE_WORD);
484 ECase(IMAGE_SYM_TYPE_UINT);
485 ECase(IMAGE_SYM_TYPE_DWORD);
486 }
487 };
488
489 template <>
490 struct ScalarEnumerationTraits {
491 static void enumeration(IO &IO, COFF::MachineTypes &Value) {
492 ECase(IMAGE_FILE_MACHINE_UNKNOWN);
493 ECase(IMAGE_FILE_MACHINE_AM33);
494 ECase(IMAGE_FILE_MACHINE_AMD64);
495 ECase(IMAGE_FILE_MACHINE_ARM);
496 ECase(IMAGE_FILE_MACHINE_ARMV7);
497 ECase(IMAGE_FILE_MACHINE_EBC);
498 ECase(IMAGE_FILE_MACHINE_I386);
499 ECase(IMAGE_FILE_MACHINE_IA64);
500 ECase(IMAGE_FILE_MACHINE_M32R);
501 ECase(IMAGE_FILE_MACHINE_MIPS16);
502 ECase(IMAGE_FILE_MACHINE_MIPSFPU);
503 ECase(IMAGE_FILE_MACHINE_MIPSFPU16);
504 ECase(IMAGE_FILE_MACHINE_POWERPC);
505 ECase(IMAGE_FILE_MACHINE_POWERPCFP);
506 ECase(IMAGE_FILE_MACHINE_R4000);
507 ECase(IMAGE_FILE_MACHINE_SH3);
508 ECase(IMAGE_FILE_MACHINE_SH3DSP);
509 ECase(IMAGE_FILE_MACHINE_SH4);
510 ECase(IMAGE_FILE_MACHINE_SH5);
511 ECase(IMAGE_FILE_MACHINE_THUMB);
512 ECase(IMAGE_FILE_MACHINE_WCEMIPSV2);
513 }
514 };
515
516 template <>
517 struct ScalarEnumerationTraits {
518 static void enumeration(IO &IO, COFF::SectionCharacteristics &Value) {
519 ECase(IMAGE_SCN_TYPE_NO_PAD);
520 ECase(IMAGE_SCN_CNT_CODE);
521 ECase(IMAGE_SCN_CNT_INITIALIZED_DATA);
522 ECase(IMAGE_SCN_CNT_UNINITIALIZED_DATA);
523 ECase(IMAGE_SCN_LNK_OTHER);
524 ECase(IMAGE_SCN_LNK_INFO);
525 ECase(IMAGE_SCN_LNK_REMOVE);
526 ECase(IMAGE_SCN_LNK_COMDAT);
527 ECase(IMAGE_SCN_GPREL);
528 ECase(IMAGE_SCN_MEM_PURGEABLE);
529 ECase(IMAGE_SCN_MEM_16BIT);
530 ECase(IMAGE_SCN_MEM_LOCKED);
531 ECase(IMAGE_SCN_MEM_PRELOAD);
532 ECase(IMAGE_SCN_ALIGN_1BYTES);
533 ECase(IMAGE_SCN_ALIGN_2BYTES);
534 ECase(IMAGE_SCN_ALIGN_4BYTES);
535 ECase(IMAGE_SCN_ALIGN_8BYTES);
536 ECase(IMAGE_SCN_ALIGN_16BYTES);
537 ECase(IMAGE_SCN_ALIGN_32BYTES);
538 ECase(IMAGE_SCN_ALIGN_64BYTES);
539 ECase(IMAGE_SCN_ALIGN_128BYTES);
540 ECase(IMAGE_SCN_ALIGN_256BYTES);
541 ECase(IMAGE_SCN_ALIGN_512BYTES);
542 ECase(IMAGE_SCN_ALIGN_1024BYTES);
543 ECase(IMAGE_SCN_ALIGN_2048BYTES);
544 ECase(IMAGE_SCN_ALIGN_4096BYTES);
545 ECase(IMAGE_SCN_ALIGN_8192BYTES);
546 ECase(IMAGE_SCN_LNK_NRELOC_OVFL);
547 ECase(IMAGE_SCN_MEM_DISCARDABLE);
548 ECase(IMAGE_SCN_MEM_NOT_CACHED);
549 ECase(IMAGE_SCN_MEM_NOT_PAGED);
550 ECase(IMAGE_SCN_MEM_SHARED);
551 ECase(IMAGE_SCN_MEM_EXECUTE);
552 ECase(IMAGE_SCN_MEM_READ);
553 ECase(IMAGE_SCN_MEM_WRITE);
554 }
555 };
556
557 template <>
558 struct ScalarEnumerationTraits {
559 static void enumeration(IO &IO, COFF::RelocationTypeX86 &Value) {
560 ECase(IMAGE_REL_I386_ABSOLUTE);
561 ECase(IMAGE_REL_I386_DIR16);
562 ECase(IMAGE_REL_I386_REL16);
563 ECase(IMAGE_REL_I386_DIR32);
564 ECase(IMAGE_REL_I386_DIR32NB);
565 ECase(IMAGE_REL_I386_SEG12);
566 ECase(IMAGE_REL_I386_SECTION);
567 ECase(IMAGE_REL_I386_SECREL);
568 ECase(IMAGE_REL_I386_TOKEN);
569 ECase(IMAGE_REL_I386_SECREL7);
570 ECase(IMAGE_REL_I386_REL32);
571 ECase(IMAGE_REL_AMD64_ABSOLUTE);
572 ECase(IMAGE_REL_AMD64_ADDR64);
573 ECase(IMAGE_REL_AMD64_ADDR32);
574 ECase(IMAGE_REL_AMD64_ADDR32NB);
575 ECase(IMAGE_REL_AMD64_REL32);
576 ECase(IMAGE_REL_AMD64_REL32_1);
577 ECase(IMAGE_REL_AMD64_REL32_2);
578 ECase(IMAGE_REL_AMD64_REL32_3);
579 ECase(IMAGE_REL_AMD64_REL32_4);
580 ECase(IMAGE_REL_AMD64_REL32_5);
581 ECase(IMAGE_REL_AMD64_SECTION);
582 ECase(IMAGE_REL_AMD64_SECREL);
583 ECase(IMAGE_REL_AMD64_SECREL7);
584 ECase(IMAGE_REL_AMD64_TOKEN);
585 ECase(IMAGE_REL_AMD64_SREL32);
586 ECase(IMAGE_REL_AMD64_PAIR);
587 ECase(IMAGE_REL_AMD64_SSPAN32);
588 }
589 };
590
591 #undef ECase
592
593 template <>
594 struct MappingTraits {
595 static void mapping(IO &IO, COFFYAML::Symbol &S) {
596 IO.mapRequired("SimpleType", S.SimpleType);
597 IO.mapOptional("NumberOfAuxSymbols", S.NumberOfAuxSymbols);
598 IO.mapRequired("Name", S.Name);
599 IO.mapRequired("StorageClass", S.StorageClass);
600 IO.mapOptional("AuxillaryData", S.AuxillaryData); // FIXME: typo
601 IO.mapRequired("ComplexType", S.ComplexType);
602 IO.mapRequired("Value", S.Value);
603 IO.mapRequired("SectionNumber", S.SectionNumber);
604 }
605 };
606
607 template <>
608 struct MappingTraits {
609 static void mapping(IO &IO, COFFYAML::Header &H) {
610 IO.mapRequired("Machine", H.Machine);
611 }
612 };
613
614 template <>
615 struct MappingTraits {
616 static void mapping(IO &IO, COFFYAML::Relocation &Rel) {
617 IO.mapRequired("Type", Rel.Type);
618 IO.mapRequired("VirtualAddress", Rel.VirtualAddress);
619 IO.mapRequired("SymbolTableIndex", Rel.SymbolTableIndex);
620 }
621 };
622
623 template <>
624 struct MappingTraits {
625 static void mapping(IO &IO, COFFYAML::Section &Sec) {
626 IO.mapOptional("Relocations", Sec.Relocations);
627 IO.mapRequired("SectionData", Sec.SectionData);
628 IO.mapRequired("Characteristics", Sec.Characteristics);
629 IO.mapRequired("Name", Sec.Name);
630 }
631 };
632
633 template <>
634 struct MappingTraits {
635 static void mapping(IO &IO, COFFYAML::Object &Obj) {
636 IO.mapRequired("sections", Obj.Sections);
637 IO.mapRequired("header", Obj.HeaderData);
638 IO.mapRequired("symbols", Obj.Symbols);
639 }
640 };
641 } // end namespace yaml
642 } // end namespace llvm
643
856644 int main(int argc, char **argv) {
857645 cl::ParseCommandLineOptions(argc, argv);
858646 sys::PrintStackTraceOnErrorSignal();
863651 if (MemoryBuffer::getFileOrSTDIN(Input, Buf))
864652 return 1;
865653
866 SourceMgr SM;
867 yaml::Stream S(Buf->getBuffer(), SM);
868 COFFParser CP(S);
654 yaml::Input YIn(Buf->getBuffer());
655 COFFYAML::Object Doc;
656 YIn >> Doc;
657 if (YIn.error()) {
658 errs() << "yaml2obj: Failed to parse YAML file!\n";
659 return 1;
660 }
661
662 COFFParser CP(Doc);
869663 if (!CP.parse()) {
870664 errs() << "yaml2obj: Failed to parse YAML file!\n";
871665 return 1;
872666 }
667
873668 if (!layoutCOFF(CP)) {
874669 errs() << "yaml2obj: Failed to layout COFF file!\n";
875670 return 1;