forked from OSchip/llvm-project
Convert the YAMLReader to use LLVM/Support/YAMLParser.
llvm-svn: 155847
This commit is contained in:
parent
63d320064d
commit
d0d5ec4a38
|
@ -14,6 +14,7 @@
|
|||
|
||||
#include "llvm/Support/system_error.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace llvm {
|
||||
|
@ -33,14 +34,15 @@ namespace yaml {
|
|||
/// the specified vector<File*>.
|
||||
error_code parseObjectTextFileOrSTDIN( StringRef path
|
||||
, Platform&
|
||||
, std::vector<const File *>&);
|
||||
, std::vector<
|
||||
std::unique_ptr<const File>>&);
|
||||
|
||||
|
||||
/// parseObjectText - Parse the specified YAML formatted MemoryBuffer
|
||||
/// into lld::File object(s) and append each to the specified vector<File*>.
|
||||
error_code parseObjectText( llvm::MemoryBuffer *mb
|
||||
, Platform&
|
||||
, std::vector<const File *>&);
|
||||
, std::vector<std::unique_ptr<const File>>&);
|
||||
|
||||
} // namespace yaml
|
||||
} // namespace lld
|
||||
|
|
|
@ -73,9 +73,9 @@ static const FileKindMapping fileKindMappings[] = {
|
|||
{ nullptr, File::kindObject }
|
||||
};
|
||||
|
||||
File::Kind KeyValues::fileKind(const char* str) {
|
||||
File::Kind KeyValues::fileKind(StringRef str) {
|
||||
for (const FileKindMapping* p = fileKindMappings; p->string != nullptr; ++p) {
|
||||
if ( strcmp(p->string, str) == 0 )
|
||||
if (str == p->string)
|
||||
return p->value;
|
||||
}
|
||||
llvm::report_fatal_error("bad file kind value");
|
||||
|
@ -103,10 +103,10 @@ static const DefinitionMapping defMappings[] = {
|
|||
{ nullptr, Atom::definitionRegular }
|
||||
};
|
||||
|
||||
Atom::Definition KeyValues::definition(const char* s)
|
||||
Atom::Definition KeyValues::definition(StringRef s)
|
||||
{
|
||||
for (const DefinitionMapping* p = defMappings; p->string != nullptr; ++p) {
|
||||
if ( strcmp(p->string, s) == 0 )
|
||||
if (s == p->string)
|
||||
return p->value;
|
||||
}
|
||||
llvm::report_fatal_error("bad definition value");
|
||||
|
@ -136,10 +136,10 @@ static const ScopeMapping scopeMappings[] = {
|
|||
{ nullptr, DefinedAtom::scopeGlobal }
|
||||
};
|
||||
|
||||
DefinedAtom::Scope KeyValues::scope(const char* s)
|
||||
DefinedAtom::Scope KeyValues::scope(StringRef s)
|
||||
{
|
||||
for (const ScopeMapping* p = scopeMappings; p->string != nullptr; ++p) {
|
||||
if ( strcmp(p->string, s) == 0 )
|
||||
if (s == p->string)
|
||||
return p->value;
|
||||
}
|
||||
llvm::report_fatal_error("bad scope value");
|
||||
|
@ -197,10 +197,10 @@ static const ContentTypeMapping typeMappings[] = {
|
|||
{ nullptr, DefinedAtom::typeUnknown }
|
||||
};
|
||||
|
||||
DefinedAtom::ContentType KeyValues::contentType(const char* s)
|
||||
DefinedAtom::ContentType KeyValues::contentType(StringRef s)
|
||||
{
|
||||
for (const ContentTypeMapping* p = typeMappings; p->string != nullptr; ++p) {
|
||||
if ( strcmp(p->string, s) == 0 )
|
||||
if (s == p->string)
|
||||
return p->value;
|
||||
}
|
||||
llvm::report_fatal_error("bad content type value");
|
||||
|
@ -232,11 +232,11 @@ static const DeadStripMapping deadStripMappings[] = {
|
|||
{ nullptr, DefinedAtom::deadStripNormal }
|
||||
};
|
||||
|
||||
DefinedAtom::DeadStripKind KeyValues::deadStripKind(const char* s)
|
||||
DefinedAtom::DeadStripKind KeyValues::deadStripKind(StringRef s)
|
||||
{
|
||||
for (const DeadStripMapping* p = deadStripMappings; p->string != nullptr; ++p)
|
||||
{
|
||||
if ( strcmp(p->string, s) == 0 )
|
||||
if (s == p->string)
|
||||
return p->value;
|
||||
}
|
||||
llvm::report_fatal_error("bad dead strip value");
|
||||
|
@ -267,10 +267,10 @@ static const InterposableMapping interMappings[] = {
|
|||
{ nullptr, DefinedAtom::interposeNo }
|
||||
};
|
||||
|
||||
DefinedAtom::Interposable KeyValues::interposable(const char* s)
|
||||
DefinedAtom::Interposable KeyValues::interposable(StringRef s)
|
||||
{
|
||||
for (const InterposableMapping* p = interMappings; p->string != nullptr; ++p){
|
||||
if ( strcmp(p->string, s) == 0 )
|
||||
if (s == p->string)
|
||||
return p->value;
|
||||
}
|
||||
llvm::report_fatal_error("bad interposable value");
|
||||
|
@ -302,10 +302,10 @@ static const MergeMapping mergeMappings[] = {
|
|||
{ nullptr, DefinedAtom::mergeNo }
|
||||
};
|
||||
|
||||
DefinedAtom::Merge KeyValues::merge(const char* s)
|
||||
DefinedAtom::Merge KeyValues::merge(StringRef s)
|
||||
{
|
||||
for (const MergeMapping* p = mergeMappings; p->string != nullptr; ++p) {
|
||||
if ( strcmp(p->string, s) == 0 )
|
||||
if (s == p->string)
|
||||
return p->value;
|
||||
}
|
||||
llvm::report_fatal_error("bad merge value");
|
||||
|
@ -336,10 +336,10 @@ static const SectionChoiceMapping sectMappings[] = {
|
|||
{ nullptr, DefinedAtom::sectionBasedOnContent }
|
||||
};
|
||||
|
||||
DefinedAtom::SectionChoice KeyValues::sectionChoice(const char* s)
|
||||
DefinedAtom::SectionChoice KeyValues::sectionChoice(StringRef s)
|
||||
{
|
||||
for (const SectionChoiceMapping* p = sectMappings; p->string != nullptr; ++p){
|
||||
if ( strcmp(p->string, s) == 0 )
|
||||
if (s == p->string)
|
||||
return p->value;
|
||||
}
|
||||
llvm::report_fatal_error("bad dead strip value");
|
||||
|
@ -373,10 +373,10 @@ static const PermissionsMapping permMappings[] = {
|
|||
{ nullptr, DefinedAtom::perm___ }
|
||||
};
|
||||
|
||||
DefinedAtom::ContentPermissions KeyValues::permissions(const char* s)
|
||||
DefinedAtom::ContentPermissions KeyValues::permissions(StringRef s)
|
||||
{
|
||||
for (const PermissionsMapping* p = permMappings; p->string != nullptr; ++p) {
|
||||
if ( strcmp(p->string, s) == 0 )
|
||||
if (s == p->string)
|
||||
return p->value;
|
||||
}
|
||||
llvm::report_fatal_error("bad permissions value");
|
||||
|
@ -390,37 +390,10 @@ const char* KeyValues::permissions(DefinedAtom::ContentPermissions s) {
|
|||
llvm::report_fatal_error("bad permissions value");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool KeyValues::isThumb(const char* s)
|
||||
{
|
||||
if ( strcmp(s, "true") == 0 )
|
||||
return true;
|
||||
else if ( strcmp(s, "false") == 0 )
|
||||
return false;
|
||||
llvm::report_fatal_error("bad is-thumb value");
|
||||
}
|
||||
|
||||
const char* KeyValues::isThumb(bool b) {
|
||||
return b ? "true" : "false";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool KeyValues::isAlias(const char* s)
|
||||
{
|
||||
if ( strcmp(s, "true") == 0 )
|
||||
return true;
|
||||
else if ( strcmp(s, "false") == 0 )
|
||||
return false;
|
||||
llvm::report_fatal_error("bad is-alias value");
|
||||
}
|
||||
|
||||
const char* KeyValues::isAlias(bool b) {
|
||||
return b ? "true" : "false";
|
||||
}
|
||||
|
@ -441,10 +414,10 @@ static const CanBeNullMapping cbnMappings[] = {
|
|||
};
|
||||
|
||||
|
||||
UndefinedAtom::CanBeNull KeyValues::canBeNull(const char* s)
|
||||
UndefinedAtom::CanBeNull KeyValues::canBeNull(StringRef s)
|
||||
{
|
||||
for (const CanBeNullMapping* p = cbnMappings; p->string != nullptr; ++p) {
|
||||
if ( strcmp(p->string, s) == 0 )
|
||||
if (s == p->string)
|
||||
return p->value;
|
||||
}
|
||||
llvm::report_fatal_error("bad can-be-null value");
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
#include "lld/Core/UndefinedAtom.h"
|
||||
#include "lld/Core/File.h"
|
||||
|
||||
|
||||
namespace lld {
|
||||
namespace yaml {
|
||||
|
||||
|
@ -34,62 +33,60 @@ public:
|
|||
|
||||
static const char* const fileKindKeyword;
|
||||
static const File::Kind fileKindDefault;
|
||||
static File::Kind fileKind(const char*);
|
||||
static File::Kind fileKind(StringRef);
|
||||
static const char* fileKind(File::Kind);
|
||||
|
||||
static const char* const definitionKeyword;
|
||||
static const Atom::Definition definitionDefault;
|
||||
static Atom::Definition definition(const char*);
|
||||
static Atom::Definition definition(StringRef);
|
||||
static const char* definition(Atom::Definition);
|
||||
|
||||
static const char* const scopeKeyword;
|
||||
static const DefinedAtom::Scope scopeDefault;
|
||||
static DefinedAtom::Scope scope(const char*);
|
||||
static DefinedAtom::Scope scope(StringRef);
|
||||
static const char* scope(DefinedAtom::Scope);
|
||||
|
||||
static const char* const contentTypeKeyword;
|
||||
static const DefinedAtom::ContentType contentTypeDefault;
|
||||
static DefinedAtom::ContentType contentType(const char*);
|
||||
static DefinedAtom::ContentType contentType(StringRef);
|
||||
static const char* contentType(DefinedAtom::ContentType);
|
||||
|
||||
static const char* const deadStripKindKeyword;
|
||||
static const DefinedAtom::DeadStripKind deadStripKindDefault;
|
||||
static DefinedAtom::DeadStripKind deadStripKind(const char*);
|
||||
static DefinedAtom::DeadStripKind deadStripKind(StringRef);
|
||||
static const char* deadStripKind(DefinedAtom::DeadStripKind);
|
||||
|
||||
static const char* const sectionChoiceKeyword;
|
||||
static const DefinedAtom::SectionChoice sectionChoiceDefault;
|
||||
static DefinedAtom::SectionChoice sectionChoice(const char*);
|
||||
static DefinedAtom::SectionChoice sectionChoice(StringRef);
|
||||
static const char* sectionChoice(DefinedAtom::SectionChoice);
|
||||
|
||||
static const char* const interposableKeyword;
|
||||
static const DefinedAtom::Interposable interposableDefault;
|
||||
static DefinedAtom::Interposable interposable(const char*);
|
||||
static DefinedAtom::Interposable interposable(StringRef);
|
||||
static const char* interposable(DefinedAtom::Interposable);
|
||||
|
||||
static const char* const mergeKeyword;
|
||||
static const DefinedAtom::Merge mergeDefault;
|
||||
static DefinedAtom::Merge merge(const char*);
|
||||
static DefinedAtom::Merge merge(StringRef);
|
||||
static const char* merge(DefinedAtom::Merge);
|
||||
|
||||
static const char* const permissionsKeyword;
|
||||
static const DefinedAtom::ContentPermissions permissionsDefault;
|
||||
static DefinedAtom::ContentPermissions permissions(const char*);
|
||||
static DefinedAtom::ContentPermissions permissions(StringRef);
|
||||
static const char* permissions(DefinedAtom::ContentPermissions);
|
||||
|
||||
static const char* const isThumbKeyword;
|
||||
static const bool isThumbDefault;
|
||||
static bool isThumb(const char*);
|
||||
static const char* isThumb(bool);
|
||||
|
||||
static const char* const isAliasKeyword;
|
||||
static const bool isAliasDefault;
|
||||
static bool isAlias(const char*);
|
||||
static const char* isAlias(bool);
|
||||
|
||||
static const char* const canBeNullKeyword;
|
||||
static const UndefinedAtom::CanBeNull canBeNullDefault;
|
||||
static UndefinedAtom::CanBeNull canBeNull(const char*);
|
||||
static UndefinedAtom::CanBeNull canBeNull(StringRef);
|
||||
static const char* canBeNull(UndefinedAtom::CanBeNull);
|
||||
|
||||
|
||||
|
@ -104,4 +101,3 @@ public:
|
|||
} // namespace lld
|
||||
|
||||
#endif // LLD_CORE_YAML_KEY_VALUES_H_
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -9,34 +9,29 @@
|
|||
atoms:
|
||||
- name: foo
|
||||
type: code
|
||||
|
||||
|
||||
- name: bar
|
||||
definition: undefined
|
||||
|
||||
---
|
||||
name: bar.o
|
||||
atoms:
|
||||
- name: bar
|
||||
scope: global
|
||||
type: code
|
||||
|
||||
- name: bar2
|
||||
type: code
|
||||
|
||||
---
|
||||
name: baz.o
|
||||
atoms:
|
||||
- name: baz
|
||||
scope: global
|
||||
type: code
|
||||
|
||||
- name: baz2
|
||||
type: code
|
||||
---
|
||||
kind: archive
|
||||
members:
|
||||
- name: bar.o
|
||||
- name: baz.o
|
||||
archive:
|
||||
- name: bar.o
|
||||
atoms:
|
||||
- name: bar
|
||||
scope: global
|
||||
type: code
|
||||
|
||||
- name: bar2
|
||||
type: code
|
||||
|
||||
- name: baz.o
|
||||
atoms:
|
||||
- name: baz
|
||||
scope: global
|
||||
type: code
|
||||
|
||||
- name: baz2
|
||||
type: code
|
||||
...
|
||||
|
||||
# CHECK: name: foo
|
||||
|
|
|
@ -8,60 +8,52 @@
|
|||
atoms:
|
||||
- name: foo
|
||||
type: code
|
||||
|
||||
|
||||
- name: bar1
|
||||
definition: undefined
|
||||
|
||||
---
|
||||
name: bar1.o
|
||||
atoms:
|
||||
- name: bar1
|
||||
scope: global
|
||||
type: code
|
||||
|
||||
- name: bar1b
|
||||
type: code
|
||||
|
||||
- name: baz1
|
||||
definition: undefined
|
||||
archive:
|
||||
- name: bar1.o
|
||||
- atoms:
|
||||
- name: bar1
|
||||
scope: global
|
||||
type: code
|
||||
|
||||
- name: bar1b
|
||||
type: code
|
||||
|
||||
- name: baz1
|
||||
definition: undefined
|
||||
|
||||
- name: bar2.o
|
||||
- atoms:
|
||||
- name: bar2
|
||||
scope: global
|
||||
type: code
|
||||
|
||||
- name: bar2b
|
||||
type: code
|
||||
|
||||
---
|
||||
name: bar2.o
|
||||
atoms:
|
||||
- name: bar2
|
||||
scope: global
|
||||
type: code
|
||||
|
||||
- name: bar2b
|
||||
type: code
|
||||
|
||||
---
|
||||
name: baz1.o
|
||||
atoms:
|
||||
- name: baz1
|
||||
scope: global
|
||||
type: code
|
||||
|
||||
- name: baz1b
|
||||
type: code
|
||||
---
|
||||
name: baz2.o
|
||||
atoms:
|
||||
- name: baz2
|
||||
scope: global
|
||||
type: code
|
||||
|
||||
- name: baz2b
|
||||
type: code
|
||||
---
|
||||
kind: archive
|
||||
members:
|
||||
- name: bar1.o
|
||||
- name: bar2.o
|
||||
---
|
||||
kind: archive
|
||||
members:
|
||||
- name: baz1.o
|
||||
- name: baz2.o
|
||||
archive:
|
||||
- name: baz1.o
|
||||
- atoms:
|
||||
- name: baz1
|
||||
scope: global
|
||||
type: code
|
||||
|
||||
- name: baz1b
|
||||
type: code
|
||||
|
||||
- name: baz2.o
|
||||
- atoms:
|
||||
- name: baz2
|
||||
scope: global
|
||||
type: code
|
||||
|
||||
- name: baz2b
|
||||
type: code
|
||||
...
|
||||
|
||||
# CHECK: name: foo
|
||||
|
|
|
@ -11,26 +11,22 @@
|
|||
atoms:
|
||||
- name: foo
|
||||
type: code
|
||||
|
||||
|
||||
- name: bar
|
||||
scope: global
|
||||
content: zero-fill
|
||||
merge: asTentative
|
||||
|
||||
---
|
||||
name: bar.o
|
||||
atoms:
|
||||
- name: bar
|
||||
scope: global
|
||||
type: data
|
||||
|
||||
- name: bar2
|
||||
type: data
|
||||
|
||||
---
|
||||
kind: archive
|
||||
members:
|
||||
- name: bar.o
|
||||
archive:
|
||||
- name: bar.o
|
||||
- atoms:
|
||||
- name: bar
|
||||
scope: global
|
||||
type: data
|
||||
|
||||
- name: bar2
|
||||
type: data
|
||||
...
|
||||
|
||||
# CHK1: name: foo
|
||||
|
|
|
@ -422,7 +422,7 @@ int main(int argc, char *argv[]) {
|
|||
llvm::cl::ParseCommandLineOptions(argc, argv);
|
||||
|
||||
// create platform for testing
|
||||
Platform* platform = NULL;
|
||||
Platform* platform = nullptr;
|
||||
switch ( platformSelected ) {
|
||||
case platformTesting:
|
||||
platform = new TestingPlatform();
|
||||
|
@ -433,7 +433,7 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
// read input YAML doc into object file(s)
|
||||
std::vector<const File *> files;
|
||||
std::vector<std::unique_ptr<const File>> files;
|
||||
if (error(yaml::parseObjectTextFileOrSTDIN(cmdLineInputFilePath,
|
||||
*platform, files))) {
|
||||
return 1;
|
||||
|
@ -444,7 +444,7 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
// create object to mange input files
|
||||
InputFiles inputFiles;
|
||||
for (const File *file : files) {
|
||||
for (const auto &file : files) {
|
||||
inputFiles.appendFile(*file);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue