blob: 64192b0ee3f6c0f3cfad92027e710621d1693c20 [file] [log] [blame]
Michael J. Spencer773a8fb2011-12-18 08:27:59 +00001//===- Core/YamlReader.cpp - Reads YAML -----------------------------------===//
2//
3// The LLVM Linker
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Nick Kledzik49d6cc82012-02-15 00:38:09 +000010#include <string.h>
11
Nick Kledzik7735a7d2012-01-04 23:58:17 +000012#include "YamlKeyValues.h"
13
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000014#include "lld/Core/YamlReader.h"
15#include "lld/Core/Atom.h"
Nick Kledzik6bc04c62012-02-22 21:56:59 +000016#include "lld/Core/UndefinedAtom.h"
17#include "lld/Core/SharedLibraryAtom.h"
18#include "lld/Core/AbsoluteAtom.h"
Michael J. Spencer7aba8952012-01-31 21:47:13 +000019#include "lld/Core/Error.h"
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000020#include "lld/Core/File.h"
21#include "lld/Core/Reference.h"
22
Nick Kledzik1a6615d2012-03-08 00:18:30 +000023#include "lld/Platform/Platform.h"
24
Michael J. Spencere753cbc2012-03-09 05:27:43 +000025#include "llvm/ADT/APInt.h"
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000026#include "llvm/ADT/OwningPtr.h"
27#include "llvm/ADT/StringRef.h"
Nick Kledzikbfedfc12012-01-09 20:18:15 +000028#include "llvm/ADT/ArrayRef.h"
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000029#include "llvm/Support/DataTypes.h"
30#include "llvm/Support/ErrorHandling.h"
31#include "llvm/Support/MemoryBuffer.h"
32#include "llvm/Support/system_error.h"
33
34#include <vector>
35
Nick Kledzik7735a7d2012-01-04 23:58:17 +000036
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000037
38namespace lld {
39namespace yaml {
Nick Kledzik7735a7d2012-01-04 23:58:17 +000040
Nick Kledzik49d6cc82012-02-15 00:38:09 +000041namespace {
42
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000043class YAML {
44public:
45 struct Entry {
Nick Kledzikbfedfc12012-01-09 20:18:15 +000046 Entry(const char *k, const char *v, std::vector<uint8_t>* vs,
47 int d, bool bd, bool bs)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000048 : key(strdup(k))
Nick Kledzikbfedfc12012-01-09 20:18:15 +000049 , value(v ? strdup(v) : NULL)
50 , valueSequenceBytes(vs)
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000051 , depth(d)
52 , beginSequence(bs)
53 , beginDocument(bd) {}
54
Nick Kledzikbfedfc12012-01-09 20:18:15 +000055 const char * key;
56 const char * value;
57 std::vector<uint8_t>* valueSequenceBytes;
58 int depth;
59 bool beginSequence;
60 bool beginDocument;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000061 };
62
63 static void parse(llvm::MemoryBuffer *mb, std::vector<const Entry *>&);
64
65private:
66 enum State {
67 start,
68 inHeaderComment,
69 inTripleDash,
70 inTriplePeriod,
71 inDocument,
72 inKey,
73 inSpaceBeforeValue,
74 inValue,
75 inValueSequence,
76 inValueSequenceEnd
77 };
78};
79
80
81void YAML::parse(llvm::MemoryBuffer *mb, std::vector<const Entry *> &entries) {
82 State state = start;
83 char key[64];
84 char value[64];
85 char *p = NULL;
86 unsigned int lineNumber = 1;
87 int depth = 0;
88 bool nextKeyIsStartOfDocument = false;
89 bool nextKeyIsStartOfSequence = false;
Nick Kledzikbfedfc12012-01-09 20:18:15 +000090 std::vector<uint8_t>* sequenceBytes = NULL;
91 unsigned contentByte = 0;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +000092 for (const char *s = mb->getBufferStart(); s < mb->getBufferEnd(); ++s) {
93 char c = *s;
94 if (c == '\n')
95 ++lineNumber;
96 switch (state) {
97 case start:
98 if (c == '#')
99 state = inHeaderComment;
100 else if (c == '-') {
101 p = &key[0];
102 *p++ = c;
103 state = inTripleDash;
104 }
105 break;
106 case inHeaderComment:
107 if (c == '\n') {
108 state = start;
109 }
110 break;
111 case inTripleDash:
112 if (c == '-') {
113 *p++ = c;
114 } else if (c == '\n') {
115 *p = '\0';
116 if (strcmp(key, "---") != 0)
117 return;
118 depth = 0;
119 state = inDocument;
120 nextKeyIsStartOfDocument = true;
121 } else {
122 return;
123 }
124 break;
125 case inTriplePeriod:
126 if (c == '.') {
127 *p++ = c;
128 } else if (c == '\n') {
129 *p = '\0';
130 if (strcmp(key, "...") != 0)
131 return;
132 depth = 0;
133 state = inHeaderComment;
134 } else {
135 return;
136 }
137 break;
138 case inDocument:
139 if (isalnum(c)) {
140 state = inKey;
141 p = &key[0];
142 *p++ = c;
143 } else if (c == '-') {
144 if (depth == 0) {
145 p = &key[0];
146 *p++ = c;
147 state = inTripleDash;
148 } else {
149 nextKeyIsStartOfSequence = true;
150 ++depth;
151 }
152 } else if (c == ' ') {
153 ++depth;
154 } else if (c == '.') {
155 p = &key[0];
156 *p++ = c;
157 state = inTriplePeriod;
158 } else if (c == '\n') {
159 // ignore empty lines
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000160 depth = 0;
Nick Kledzik38eec3d2011-12-22 02:38:01 +0000161 } else if (c == '\t') {
162 llvm::report_fatal_error("TAB character found in yaml file");
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000163 } else {
164 return;
165 }
166 break;
167 case inKey:
168 if (isalnum(c) || (c == '-')) {
169 *p++ = c;
170 } else if (c == ':') {
171 *p = '\0';
172 state = inSpaceBeforeValue;
173 } else if (c == '\n') {
174 *p = '\0';
175 if (strcmp(key, "---") == 0)
176 state = inDocument;
177 else
178 return;
179 } else {
180 return;
181 }
182 break;
183 case inSpaceBeforeValue:
184 if (isalnum(c) || (c == '-') || (c == '_')) {
185 p = &value[0];
186 *p++ = c;
187 state = inValue;
188 } else if (c == '\n') {
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000189 entries.push_back(new Entry(key, "", NULL, depth,
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000190 nextKeyIsStartOfDocument,
191 nextKeyIsStartOfSequence));
192 nextKeyIsStartOfSequence = false;
193 nextKeyIsStartOfDocument = false;
194 state = inDocument;
195 depth = 0;
196 } else if (c == '[') {
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000197 contentByte = 0;
198 sequenceBytes = new std::vector<uint8_t>();
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000199 state = inValueSequence;
200 } else if (c == ' ') {
201 // eat space
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000202 } else if (c == '\t') {
203 llvm::report_fatal_error("TAB character found in yaml file");
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000204 } else {
205 return;
206 }
207 break;
208 case inValue:
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000209 if (c == '\n') {
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000210 *p = '\0';
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000211 entries.push_back(new Entry(key, value, NULL, depth,
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000212 nextKeyIsStartOfDocument,
213 nextKeyIsStartOfSequence));
214 nextKeyIsStartOfSequence = false;
215 nextKeyIsStartOfDocument = false;
216 state = inDocument;
217 depth = 0;
218 }
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000219 else {
220 *p++ = c;
221 }
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000222 break;
223 case inValueSequence:
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000224 if (c == ']') {
225 sequenceBytes->push_back(contentByte);
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000226 state = inValueSequenceEnd;
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000227 }
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000228 else if ( (c == ' ') || (c == '\n') ) {
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000229 // eat white space
230 }
231 else if (c == ',') {
232 sequenceBytes->push_back(contentByte);
233 }
234 else if ( isdigit(c) ) {
235 contentByte = (contentByte << 4) | (c-'0');
236 }
237 else if ( ('a' <= tolower(c)) && (tolower(c) <= 'f') ) {
238 contentByte = (contentByte << 4) | (tolower(c)-'a'+10);
239 }
240 else {
241 llvm::report_fatal_error("non-hex digit found in content [ ]");
242 }
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000243 break;
244 case inValueSequenceEnd:
245 if (c == '\n') {
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000246 entries.push_back(new Entry(key, NULL, sequenceBytes, depth,
247 nextKeyIsStartOfDocument,
248 nextKeyIsStartOfSequence));
249 nextKeyIsStartOfSequence = false;
250 nextKeyIsStartOfDocument = false;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000251 state = inDocument;
252 depth = 0;
253 }
254 break;
255 }
256 }
257}
258
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000259
260
261class YAMLReference : public Reference {
262public:
263 YAMLReference() : _target(NULL), _targetName(NULL),
264 _offsetInAtom(0), _addend(0), _kind(0) { }
265
266 virtual uint64_t offsetInAtom() const {
267 return _offsetInAtom;
268 }
269
270 virtual Kind kind() const {
271 return _kind;
272 }
273
274 virtual const Atom* target() const {
275 return _target;
276 }
277
278 virtual Addend addend() const {
279 return _addend;
280 }
281
282 virtual void setTarget(const Atom* newAtom) {
283 _target = newAtom;
284 }
285
286 const Atom* _target;
287 const char* _targetName;
288 uint64_t _offsetInAtom;
289 Addend _addend;
290 Kind _kind;
291};
292
293
294
295class YAMLDefinedAtom;
296
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000297class YAMLFile : public File {
298public:
299 YAMLFile()
300 : File("path")
301 , _lastRefIndex(0) {}
302
Nick Kledzik1a6615d2012-03-08 00:18:30 +0000303 virtual const atom_collection<DefinedAtom>& defined() const {
304 return _definedAtoms;
305 }
306 virtual const atom_collection<UndefinedAtom>& undefined() const {
307 return _undefinedAtoms;
308 }
309 virtual const atom_collection<SharedLibraryAtom>& sharedLibrary() const {
310 return _sharedLibraryAtoms;
311 }
312 virtual const atom_collection<AbsoluteAtom>& absolute() const {
313 return _absoluteAtoms;
314 }
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000315
Nick Kledzik1a6615d2012-03-08 00:18:30 +0000316 virtual void addAtom(const Atom&) {
317 assert(0 && "cannot add atoms to YAML files");
318 }
319
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000320 void bindTargetReferences();
321 void addDefinedAtom(YAMLDefinedAtom* atom, const char* refName);
322 void addUndefinedAtom(UndefinedAtom* atom);
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000323 void addSharedLibraryAtom(SharedLibraryAtom* atom);
324 void addAbsoluteAtom(AbsoluteAtom* atom);
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000325 Atom* findAtom(const char* name);
326
327 struct NameAtomPair {
328 NameAtomPair(const char* n, Atom* a) : name(n), atom(a) {}
329 const char* name;
330 Atom* atom;
331 };
332
Nick Kledzik1a6615d2012-03-08 00:18:30 +0000333 atom_collection_vector<DefinedAtom> _definedAtoms;
334 atom_collection_vector<UndefinedAtom> _undefinedAtoms;
335 atom_collection_vector<SharedLibraryAtom> _sharedLibraryAtoms;
336 atom_collection_vector<AbsoluteAtom> _absoluteAtoms;
337 std::vector<YAMLReference> _references;
338 std::vector<NameAtomPair> _nameToAtomMapping;
339 unsigned int _lastRefIndex;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000340};
341
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000342
343
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000344class YAMLDefinedAtom : public DefinedAtom {
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000345public:
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000346 YAMLDefinedAtom( uint32_t ord
347 , YAMLFile& file
348 , DefinedAtom::Scope scope
349 , DefinedAtom::ContentType type
350 , DefinedAtom::SectionChoice sectionChoice
351 , DefinedAtom::Interposable interpose
352 , DefinedAtom::Merge merge
353 , DefinedAtom::DeadStripKind deadStrip
354 , DefinedAtom::ContentPermissions perms
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000355 , bool isThumb
356 , bool isAlias
357 , DefinedAtom::Alignment alignment
358 , const char* name
359 , const char* sectionName
360 , uint64_t size
361 , std::vector<uint8_t>* content)
362 : _file(file)
363 , _name(name)
364 , _sectionName(sectionName)
365 , _size(size)
366 , _ord(ord)
367 , _content(content)
368 , _alignment(alignment)
369 , _scope(scope)
370 , _type(type)
371 , _sectionChoice(sectionChoice)
372 , _interpose(interpose)
373 , _merge(merge)
374 , _deadStrip(deadStrip)
375 , _permissions(perms)
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000376 , _isThumb(isThumb)
377 , _isAlias(isAlias)
378 , _refStartIndex(file._lastRefIndex)
379 , _refEndIndex(file._references.size()) {
380 file._lastRefIndex = _refEndIndex;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000381 }
382
Nick Kledzikf46669c2011-12-21 23:29:36 +0000383 virtual const class File& file() const {
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000384 return _file;
385 }
386
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000387 virtual llvm::StringRef name() const {
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000388 if ( _name == NULL )
389 return llvm::StringRef();
390 else
391 return _name;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000392 }
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000393
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000394 virtual uint64_t size() const {
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000395 return (_content ? _content->size() : _size);
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000396 }
397
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000398 virtual DefinedAtom::Scope scope() const {
399 return _scope;
400 }
401
402 virtual DefinedAtom::Interposable interposable() const {
403 return _interpose;
404 }
405
406 virtual DefinedAtom::Merge merge() const {
407 return _merge;
408 }
409
410 virtual DefinedAtom::ContentType contentType() const {
411 return _type;
412 }
413
414 virtual DefinedAtom::Alignment alignment() const {
415 return _alignment;
416 }
417
418 virtual DefinedAtom::SectionChoice sectionChoice() const {
419 return _sectionChoice;
420 }
421
422 virtual llvm::StringRef customSectionName() const {
423 return _sectionName;
424 }
425
426 virtual DefinedAtom::DeadStripKind deadStrip() const {
427 return _deadStrip;
428 }
429
430 virtual DefinedAtom::ContentPermissions permissions() const {
431 return _permissions;
432 }
433
434 virtual bool isThumb() const {
435 return _isThumb;
436 }
437
438 virtual bool isAlias() const {
439 return _isAlias;
440 }
441
442 llvm::ArrayRef<uint8_t> rawContent() const {
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000443 if ( _content != NULL )
444 return llvm::ArrayRef<uint8_t>(*_content);
445 else
446 return llvm::ArrayRef<uint8_t>();
447 }
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000448
449 virtual uint64_t ordinal() const {
450 return _ord;
451 }
452
Nick Kledzik1a6615d2012-03-08 00:18:30 +0000453 DefinedAtom::reference_iterator referencesBegin() const {
454 uintptr_t index = _refStartIndex;
455 const void* it = reinterpret_cast<const void*>(index);
456 return reference_iterator(*this, it);
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000457 }
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000458
Nick Kledzik1a6615d2012-03-08 00:18:30 +0000459 DefinedAtom::reference_iterator referencesEnd() const {
460 uintptr_t index = _refEndIndex;
461 const void* it = reinterpret_cast<const void*>(index);
462 return reference_iterator(*this, it);
463 }
464
465 const Reference* derefIterator(const void* it) const {
466 uintptr_t index = reinterpret_cast<uintptr_t>(it);
467 assert(index >= _refStartIndex);
468 assert(index < _refEndIndex);
469 assert(index < _file._references.size());
470 return &_file._references[index];
471 }
472
473 void incrementIterator(const void*& it) const {
474 uintptr_t index = reinterpret_cast<uintptr_t>(it);
475 ++index;
476 it = reinterpret_cast<const void*>(index);
477 }
478
479
480
481 void bindTargetReferences() const {
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000482 for (unsigned int i=_refStartIndex; i < _refEndIndex; ++i) {
483 const char* targetName = _file._references[i]._targetName;
484 Atom* targetAtom = _file.findAtom(targetName);
485 _file._references[i]._target = targetAtom;
486 }
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000487 }
488
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000489private:
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000490 YAMLFile& _file;
491 const char * _name;
492 const char * _sectionName;
493 unsigned long _size;
494 uint32_t _ord;
495 std::vector<uint8_t>* _content;
496 DefinedAtom::Alignment _alignment;
497 DefinedAtom::Scope _scope;
498 DefinedAtom::ContentType _type;
499 DefinedAtom::SectionChoice _sectionChoice;
500 DefinedAtom::Interposable _interpose;
501 DefinedAtom::Merge _merge;
502 DefinedAtom::DeadStripKind _deadStrip;
503 DefinedAtom::ContentPermissions _permissions;
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000504 bool _isThumb;
505 bool _isAlias;
506 unsigned int _refStartIndex;
507 unsigned int _refEndIndex;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000508};
509
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000510
Nick Kledzik23384e82012-02-07 02:59:54 +0000511class YAMLUndefinedAtom : public UndefinedAtom {
512public:
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000513 YAMLUndefinedAtom(YAMLFile& f, int32_t ord, const char* nm,
514 UndefinedAtom::CanBeNull cbn)
515 : _file(f), _name(nm), _ordinal(ord), _canBeNull(cbn) { }
Nick Kledzik23384e82012-02-07 02:59:54 +0000516
517 virtual const class File& file() const {
518 return _file;
519 }
520
521 virtual llvm::StringRef name() const {
522 return _name;
523 }
524
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000525 virtual CanBeNull canBeNull() const {
526 return _canBeNull;
Nick Kledzik23384e82012-02-07 02:59:54 +0000527 }
528
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000529
Nick Kledzik23384e82012-02-07 02:59:54 +0000530private:
531 YAMLFile& _file;
532 const char * _name;
533 uint32_t _ordinal;
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000534 UndefinedAtom::CanBeNull _canBeNull;
Nick Kledzik23384e82012-02-07 02:59:54 +0000535};
536
537
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000538
539class YAMLSharedLibraryAtom : public SharedLibraryAtom {
540public:
541 YAMLSharedLibraryAtom(YAMLFile& f, int32_t ord, const char* nm,
542 const char* ldnm, bool cbn)
543 : _file(f), _name(nm), _ordinal(ord),
544 _loadName(ldnm), _canBeNull(cbn) { }
545
546 virtual const class File& file() const {
547 return _file;
548 }
549
550 virtual llvm::StringRef name() const {
551 return _name;
552 }
553
554 virtual llvm::StringRef loadName() const {
555 return _loadName;
556 }
557
558 virtual bool canBeNullAtRuntime() const {
559 return _canBeNull;
560 }
561
562
563private:
564 YAMLFile& _file;
565 const char * _name;
566 uint32_t _ordinal;
567 const char * _loadName;
568 bool _canBeNull;
569};
570
571
572
573class YAMLAbsoluteAtom : public AbsoluteAtom {
574public:
575 YAMLAbsoluteAtom(YAMLFile& f, int32_t ord, const char* nm, uint64_t v)
576 : _file(f), _name(nm), _ordinal(ord), _value(v) { }
577
578 virtual const class File& file() const {
579 return _file;
580 }
581
582 virtual llvm::StringRef name() const {
583 return _name;
584 }
585
586 virtual uint64_t value() const {
587 return _value;
588 }
589
590private:
591 YAMLFile& _file;
592 const char * _name;
593 uint32_t _ordinal;
594 uint64_t _value;
595};
596
597
598
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000599void YAMLFile::bindTargetReferences() {
Nick Kledzik1a6615d2012-03-08 00:18:30 +0000600 for (defined_iterator it = definedAtomsBegin(); it != definedAtomsEnd(); ++it) {
601 const YAMLDefinedAtom* atom = reinterpret_cast<const YAMLDefinedAtom*>(*it);
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000602 atom->bindTargetReferences();
603 }
604}
605
606Atom* YAMLFile::findAtom(const char* name) {
607 for (std::vector<NameAtomPair>::const_iterator it = _nameToAtomMapping.begin();
608 it != _nameToAtomMapping.end(); ++it) {
609 if ( strcmp(name, it->name) == 0 )
610 return it->atom;
611 }
612 llvm::report_fatal_error("reference to atom that does not exist");
613}
614
615void YAMLFile::addDefinedAtom(YAMLDefinedAtom* atom, const char* refName) {
Nick Kledzik1a6615d2012-03-08 00:18:30 +0000616 _definedAtoms._atoms.push_back(atom);
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000617 assert(refName != NULL);
618 _nameToAtomMapping.push_back(NameAtomPair(refName, atom));
619}
620
621void YAMLFile::addUndefinedAtom(UndefinedAtom* atom) {
Nick Kledzik1a6615d2012-03-08 00:18:30 +0000622 _undefinedAtoms._atoms.push_back(atom);
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000623 _nameToAtomMapping.push_back(NameAtomPair(atom->name().data(), atom));
624}
625
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000626void YAMLFile::addSharedLibraryAtom(SharedLibraryAtom* atom) {
Nick Kledzik1a6615d2012-03-08 00:18:30 +0000627 _sharedLibraryAtoms._atoms.push_back(atom);
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000628 _nameToAtomMapping.push_back(NameAtomPair(atom->name().data(), atom));
629}
630
631void YAMLFile::addAbsoluteAtom(AbsoluteAtom* atom) {
Nick Kledzik1a6615d2012-03-08 00:18:30 +0000632 _absoluteAtoms._atoms.push_back(atom);
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000633 _nameToAtomMapping.push_back(NameAtomPair(atom->name().data(), atom));
634}
635
Nick Kledzik23384e82012-02-07 02:59:54 +0000636
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000637class YAMLAtomState {
638public:
Nick Kledzik1a6615d2012-03-08 00:18:30 +0000639 YAMLAtomState(Platform& platform);
640
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000641 void setName(const char *n);
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000642 void setRefName(const char *n);
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000643 void setAlign2(const char *n);
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000644
645 void setFixupKind(const char *n);
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000646 void setFixupTarget(const char *n);
647 void addFixup(YAMLFile *f);
648
Nick Kledzikf46669c2011-12-21 23:29:36 +0000649 void makeAtom(YAMLFile&);
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000650
Nick Kledzik1a6615d2012-03-08 00:18:30 +0000651 Platform& _platform;
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000652 const char * _name;
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000653 const char * _refName;
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000654 const char * _sectionName;
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000655 const char* _loadName;
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000656 unsigned long long _size;
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000657 uint64_t _value;
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000658 uint32_t _ordinal;
659 std::vector<uint8_t>* _content;
660 DefinedAtom::Alignment _alignment;
661 Atom::Definition _definition;
662 DefinedAtom::Scope _scope;
663 DefinedAtom::ContentType _type;
664 DefinedAtom::SectionChoice _sectionChoice;
665 DefinedAtom::Interposable _interpose;
666 DefinedAtom::Merge _merge;
667 DefinedAtom::DeadStripKind _deadStrip;
668 DefinedAtom::ContentPermissions _permissions;
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000669 bool _isThumb;
670 bool _isAlias;
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000671 UndefinedAtom::CanBeNull _canBeNull;
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000672 YAMLReference _ref;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000673};
674
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000675
Nick Kledzik1a6615d2012-03-08 00:18:30 +0000676YAMLAtomState::YAMLAtomState(Platform& platform)
677 : _platform(platform)
678 , _name(NULL)
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000679 , _refName(NULL)
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000680 , _sectionName(NULL)
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000681 , _loadName(NULL)
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000682 , _size(0)
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000683 , _value(0)
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000684 , _ordinal(0)
685 , _content(NULL)
686 , _alignment(0, 0)
687 , _definition(KeyValues::definitionDefault)
688 , _scope(KeyValues::scopeDefault)
689 , _type(KeyValues::contentTypeDefault)
690 , _sectionChoice(KeyValues::sectionChoiceDefault)
691 , _interpose(KeyValues::interposableDefault)
692 , _merge(KeyValues::mergeDefault)
693 , _deadStrip(KeyValues::deadStripKindDefault)
694 , _permissions(KeyValues::permissionsDefault)
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000695 , _isThumb(KeyValues::isThumbDefault)
696 , _isAlias(KeyValues::isAliasDefault)
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000697 , _canBeNull(KeyValues::canBeNullDefault)
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000698 {
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000699 }
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000700
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000701
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000702void YAMLAtomState::makeAtom(YAMLFile& f) {
703 if ( _definition == Atom::definitionRegular ) {
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000704 YAMLDefinedAtom *a = new YAMLDefinedAtom(_ordinal, f, _scope, _type,
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000705 _sectionChoice, _interpose, _merge, _deadStrip,
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000706 _permissions, _isThumb, _isAlias,
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000707 _alignment, _name, _sectionName, _size, _content);
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000708 f.addDefinedAtom(a, _refName ? _refName : _name);
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000709 ++_ordinal;
710 }
Nick Kledzik23384e82012-02-07 02:59:54 +0000711 else if ( _definition == Atom::definitionUndefined ) {
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000712 UndefinedAtom *a = new YAMLUndefinedAtom(f, _ordinal, _name, _canBeNull);
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000713 f.addUndefinedAtom(a);
Nick Kledzik23384e82012-02-07 02:59:54 +0000714 ++_ordinal;
715 }
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000716 else if ( _definition == Atom::definitionSharedLibrary ) {
717 bool nullable = (_canBeNull == UndefinedAtom::canBeNullAtRuntime);
718 SharedLibraryAtom *a = new YAMLSharedLibraryAtom(f, _ordinal, _name,
719 _loadName, nullable);
720 f.addSharedLibraryAtom(a);
721 ++_ordinal;
722 }
723 else if ( _definition == Atom::definitionAbsolute ) {
724 AbsoluteAtom *a = new YAMLAbsoluteAtom(f, _ordinal, _name, _value);
725 f.addAbsoluteAtom(a);
726 ++_ordinal;
727 }
728
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000729 // reset state for next atom
730 _name = NULL;
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000731 _refName = NULL;
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000732 _sectionName = NULL;
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000733 _loadName = NULL;
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000734 _size = 0;
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000735 _value = 0;
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000736 _ordinal = 0;
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000737 _content = NULL;
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000738 _alignment.powerOf2= 0;
739 _alignment.modulus = 0;
740 _definition = KeyValues::definitionDefault;
741 _scope = KeyValues::scopeDefault;
742 _type = KeyValues::contentTypeDefault;
743 _sectionChoice = KeyValues::sectionChoiceDefault;
744 _interpose = KeyValues::interposableDefault;
745 _merge = KeyValues::mergeDefault;
746 _deadStrip = KeyValues::deadStripKindDefault;
747 _permissions = KeyValues::permissionsDefault;
748 _isThumb = KeyValues::isThumbDefault;
749 _isAlias = KeyValues::isAliasDefault;
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000750 _canBeNull = KeyValues::canBeNullDefault;
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000751 _ref._target = NULL;
752 _ref._targetName = NULL;
753 _ref._addend = 0;
754 _ref._offsetInAtom = 0;
755 _ref._kind = 0;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000756}
757
758void YAMLAtomState::setName(const char *n) {
759 _name = n;
760}
761
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000762void YAMLAtomState::setRefName(const char *n) {
763 _refName = n;
764}
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000765
766void YAMLAtomState::setAlign2(const char *s) {
Michael J. Spencer166b0902012-03-12 18:13:36 +0000767 if (llvm::StringRef(s).getAsInteger(10, _alignment.powerOf2))
768 _alignment.powerOf2 = 1;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000769}
770
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000771void YAMLAtomState::setFixupKind(const char *s) {
Nick Kledzik1a6615d2012-03-08 00:18:30 +0000772 _ref._kind = _platform.kindFromString(llvm::StringRef(s));
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000773}
774
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000775void YAMLAtomState::setFixupTarget(const char *s) {
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000776 _ref._targetName = s;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000777}
778
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000779
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000780void YAMLAtomState::addFixup(YAMLFile *f) {
781 f->_references.push_back(_ref);
782 // clear for next ref
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000783 _ref._target = NULL;
784 _ref._targetName = NULL;
785 _ref._addend = 0;
786 _ref._offsetInAtom = 0;
787 _ref._kind = 0;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000788}
789
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000790
791} // anonymous namespace
792
793
794
795
796
797/// parseObjectText - Parse the specified YAML formatted MemoryBuffer
798/// into lld::File object(s) and append each to the specified vector<File*>.
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000799llvm::error_code parseObjectText( llvm::MemoryBuffer *mb
Nick Kledzik1a6615d2012-03-08 00:18:30 +0000800 , Platform& platform
801 , std::vector<const File *> &result) {
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000802 std::vector<const YAML::Entry *> entries;
803 YAML::parse(mb, entries);
804
805 YAMLFile *file = NULL;
Nick Kledzik1a6615d2012-03-08 00:18:30 +0000806 YAMLAtomState atomState(platform);
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000807 bool inAtoms = false;
808 bool inFixups = false;
809 int depthForAtoms = -1;
810 int depthForFixups = -1;
811 int lastDepth = -1;
812 bool haveAtom = false;
813 bool haveFixup = false;
814
815 for (std::vector<const YAML::Entry *>::iterator it = entries.begin();
816 it != entries.end(); ++it) {
817 const YAML::Entry *entry = *it;
818
819 if (entry->beginDocument) {
820 if (file != NULL) {
821 if (haveAtom) {
Nick Kledzikf46669c2011-12-21 23:29:36 +0000822 atomState.makeAtom(*file);
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000823 haveAtom = false;
824 }
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000825 file->bindTargetReferences();
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000826 result.push_back(file);
827 }
828 file = new YAMLFile();
829 inAtoms = false;
830 depthForAtoms = -1;
831 }
832 if (lastDepth > entry->depth) {
833 // end of fixup sequence
834 if (haveFixup) {
835 atomState.addFixup(file);
836 haveFixup = false;
837 }
838 }
839
840 if (inAtoms && (depthForAtoms == -1)) {
841 depthForAtoms = entry->depth;
842 }
843 if (inFixups && (depthForFixups == -1)) {
844 depthForFixups = entry->depth;
845 }
846 if (strcmp(entry->key, "atoms") == 0) {
847 inAtoms = true;
848 }
849 if (inAtoms) {
850 if (depthForAtoms == entry->depth) {
851 if (entry->beginSequence) {
852 if (haveAtom) {
Nick Kledzikf46669c2011-12-21 23:29:36 +0000853 atomState.makeAtom(*file);
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000854 haveAtom = false;
855 }
856 }
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000857 if (strcmp(entry->key, KeyValues::nameKeyword) == 0) {
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000858 atomState.setName(entry->value);
859 haveAtom = true;
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000860 }
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000861 else if (strcmp(entry->key, KeyValues::refNameKeyword) == 0) {
862 atomState.setRefName(entry->value);
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000863 haveAtom = true;
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000864 }
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000865 else if (strcmp(entry->key, KeyValues::definitionKeyword) == 0) {
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000866 atomState._definition = KeyValues::definition(entry->value);
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000867 haveAtom = true;
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000868 }
869 else if (strcmp(entry->key, KeyValues::scopeKeyword) == 0) {
870 atomState._scope = KeyValues::scope(entry->value);
871 haveAtom = true;
872 }
873 else if (strcmp(entry->key, KeyValues::contentTypeKeyword) == 0) {
874 atomState._type = KeyValues::contentType(entry->value);
875 haveAtom = true;
876 }
877 else if (strcmp(entry->key, KeyValues::deadStripKindKeyword) == 0) {
878 atomState._deadStrip = KeyValues::deadStripKind(entry->value);
879 haveAtom = true;
880 }
881 else if (strcmp(entry->key, KeyValues::sectionChoiceKeyword) == 0) {
882 atomState._sectionChoice = KeyValues::sectionChoice(entry->value);
883 haveAtom = true;
884 }
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000885 else if (strcmp(entry->key, KeyValues::mergeKeyword) == 0) {
886 atomState._merge = KeyValues::merge(entry->value);
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000887 haveAtom = true;
888 }
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000889 else if (strcmp(entry->key, KeyValues::interposableKeyword) == 0) {
890 atomState._interpose = KeyValues::interposable(entry->value);
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000891 haveAtom = true;
892 }
893 else if (strcmp(entry->key, KeyValues::isThumbKeyword) == 0) {
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000894 atomState._isThumb = KeyValues::isThumb(entry->value);
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000895 haveAtom = true;
896 }
897 else if (strcmp(entry->key, KeyValues::isAliasKeyword) == 0) {
Nick Kledzikf4fb2c52012-01-11 01:06:19 +0000898 atomState._isAlias = KeyValues::isAlias(entry->value);
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000899 haveAtom = true;
900 }
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000901 else if (strcmp(entry->key, KeyValues::canBeNullKeyword) == 0) {
902 atomState._canBeNull = KeyValues::canBeNull(entry->value);
903 if ( atomState._definition == Atom::definitionSharedLibrary ) {
904 if ( atomState._canBeNull == UndefinedAtom::canBeNullAtBuildtime )
905 return make_error_code(yaml_reader_error::illegal_value);
906 }
Nick Kledzik23384e82012-02-07 02:59:54 +0000907 haveAtom = true;
908 }
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000909 else if (strcmp(entry->key, KeyValues::sectionNameKeyword) == 0) {
910 atomState._sectionName = entry->value;
911 haveAtom = true;
912 }
913 else if (strcmp(entry->key, KeyValues::sizeKeyword) == 0) {
914 llvm::StringRef val = entry->value;
Michael J. Spencer166b0902012-03-12 18:13:36 +0000915 if (val.getAsInteger(0, atomState._size))
Michael J. Spencer7aba8952012-01-31 21:47:13 +0000916 return make_error_code(yaml_reader_error::illegal_value);
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000917 haveAtom = true;
918 }
919 else if (strcmp(entry->key, KeyValues::contentKeyword) == 0) {
Nick Kledzikbfedfc12012-01-09 20:18:15 +0000920 atomState._content = entry->valueSequenceBytes;
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000921 haveAtom = true;
922 }
923 else if (strcmp(entry->key, "align2") == 0) {
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000924 atomState.setAlign2(entry->value);
925 haveAtom = true;
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000926 }
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000927 else if (strcmp(entry->key, KeyValues::fixupsKeyword) == 0) {
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000928 inFixups = true;
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000929 }
930 else if (strcmp(entry->key, KeyValues::loadNameKeyword) == 0) {
931 atomState._loadName = entry->value;
932 haveAtom = true;
933 }
934 else if (strcmp(entry->key, KeyValues::valueKeyword) == 0) {
Michael J. Spencere753cbc2012-03-09 05:27:43 +0000935 llvm::APInt Val;
936 llvm::StringRef(entry->value).getAsInteger(0, Val);
937 atomState._value = Val.getZExtValue();
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000938 haveAtom = true;
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000939 }
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000940 else {
Michael J. Spencer7aba8952012-01-31 21:47:13 +0000941 return make_error_code(yaml_reader_error::unknown_keyword);
Nick Kledzik7735a7d2012-01-04 23:58:17 +0000942 }
943 }
944 else if (depthForFixups == entry->depth) {
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000945 if (entry->beginSequence) {
946 if (haveFixup) {
947 atomState.addFixup(file);
948 haveFixup = false;
949 }
950 }
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000951 if (strcmp(entry->key, KeyValues::fixupsKindKeyword) == 0) {
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000952 atomState.setFixupKind(entry->value);
953 haveFixup = true;
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000954 }
955 else if (strcmp(entry->key, KeyValues::fixupsOffsetKeyword) == 0) {
Michael J. Spencer166b0902012-03-12 18:13:36 +0000956 if (llvm::StringRef(entry->value).getAsInteger(0,
957 atomState._ref._offsetInAtom))
958 return make_error_code(yaml_reader_error::illegal_value);
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000959 haveFixup = true;
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000960 }
961 else if (strcmp(entry->key, KeyValues::fixupsTargetKeyword) == 0) {
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000962 atomState.setFixupTarget(entry->value);
963 haveFixup = true;
964 }
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000965 else if (strcmp(entry->key, KeyValues::fixupsAddendKeyword) == 0) {
Michael J. Spencere753cbc2012-03-09 05:27:43 +0000966 llvm::StringRef Addend(entry->value);
Michael J. Spencer166b0902012-03-12 18:13:36 +0000967 if (Addend.getAsInteger(0, atomState._ref._addend))
968 return make_error_code(yaml_reader_error::illegal_value);
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000969 haveFixup = true;
970 }
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000971 }
972 }
973 lastDepth = entry->depth;
974 }
975 if (haveAtom) {
Nick Kledzikf46669c2011-12-21 23:29:36 +0000976 atomState.makeAtom(*file);
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000977 }
Nick Kledzik6bc04c62012-02-22 21:56:59 +0000978 if ( file != NULL ) {
979 file->bindTargetReferences();
980 result.push_back(file);
981 }
Michael J. Spencer7aba8952012-01-31 21:47:13 +0000982 return make_error_code(yaml_reader_error::success);
Michael J. Spencer773a8fb2011-12-18 08:27:59 +0000983}
Nick Kledzik070e1a72011-12-20 00:07:11 +0000984
Nick Kledzik49d6cc82012-02-15 00:38:09 +0000985
Nick Kledzik070e1a72011-12-20 00:07:11 +0000986//
987// Fill in vector<File*> from path to input text file.
988//
989llvm::error_code parseObjectTextFileOrSTDIN(llvm::StringRef path
Nick Kledzik1a6615d2012-03-08 00:18:30 +0000990 , Platform& platform
991 , std::vector<const File*>& result) {
Nick Kledzik070e1a72011-12-20 00:07:11 +0000992 llvm::OwningPtr<llvm::MemoryBuffer> mb;
993 llvm::error_code ec = llvm::MemoryBuffer::getFileOrSTDIN(path, mb);
994 if ( ec )
995 return ec;
996
Nick Kledzik1a6615d2012-03-08 00:18:30 +0000997 return parseObjectText(mb.get(), platform, result);
Nick Kledzik070e1a72011-12-20 00:07:11 +0000998}
999
1000
Michael J. Spencer773a8fb2011-12-18 08:27:59 +00001001} // namespace yaml
1002} // namespace lld