[lld] Add -emit-yaml option. This outputs yaml instead of a binary.

llvm-svn: 171710
This commit is contained in:
Michael J. Spencer 2013-01-07 08:00:25 +00:00
parent 1ac382f0c5
commit 956b03618c
5 changed files with 45 additions and 5 deletions

View File

@ -111,7 +111,8 @@ struct LinkerOptions {
, _outputPath(std::move(other._outputPath))
, _entrySymbol(std::move(other._entrySymbol))
, _relocatable(other._relocatable)
, _outputCommands(other._outputCommands) {}
, _outputCommands(other._outputCommands)
, _outputYAML(other._outputYAML) {}
std::vector<LinkerInput> _input;
std::string _target;
@ -120,6 +121,7 @@ struct LinkerOptions {
unsigned _relocatable : 1;
/// \brief -###
unsigned _outputCommands : 1;
unsigned _outputYAML : 1;
private:
LinkerOptions(const LinkerOptions&) LLVM_DELETED_FUNCTION;

View File

@ -8,3 +8,5 @@ def entry : Joined<["-"], "entry=">;
def relocatable : Flag<["-"], "relocatable">;
def OCTOTHORPE_OCTOTHORPE_OCTOTHORPE : Flag<["-"], "###">;
def emit_yaml : Flag<["-"], "emit-yaml">;

View File

@ -136,6 +136,9 @@ public:
newArgs->AddFlagArg(A, _core.getOption(
core::OPT_OCTOTHORPE_OCTOTHORPE_OCTOTHORPE));
if (llvm::opt::Arg *A = _inputArgs->getLastArg(ld::OPT_emit_yaml))
newArgs->AddFlagArg(A, _core.getOption(core::OPT_emit_yaml));
// Copy input args.
for (llvm::opt::arg_iterator it = _inputArgs->filtered_begin(ld::OPT_INPUT),
ie = _inputArgs->filtered_end();
@ -197,6 +200,7 @@ LinkerOptions lld::generateOptions(const llvm::opt::ArgList &args) {
ret._entrySymbol = args.getLastArgValue(core::OPT_entry);
ret._relocatable = args.hasArg(core::OPT_relocatable);
ret._outputCommands = args.hasArg(core::OPT_OCTOTHORPE_OCTOTHORPE_OCTOTHORPE);
ret._outputYAML = args.hasArg(core::OPT_emit_yaml);
return std::move(ret);
}

View File

@ -13,3 +13,5 @@ def relocatable : Flag<["--"], "relocatable">;
def relocatable_r : Flag<["-"], "r">, Alias<relocatable>;
def OCTOTHORPE_OCTOTHORPE_OCTOTHORPE : Flag<["-"], "###">;
def emit_yaml : Flag<["-"], "emit-yaml">;

View File

@ -19,8 +19,12 @@
#include "lld/ReaderWriter/ReaderELF.h"
#include "lld/ReaderWriter/ReaderYAML.h"
#include "lld/ReaderWriter/WriterELF.h"
#include "lld/ReaderWriter/WriterYAML.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Support/raw_ostream.h"
#include <set>
using namespace lld;
@ -30,6 +34,7 @@ public:
_readerELF.reset(createReaderELF(_roe, _roa));
_readerYAML.reset(createReaderYAML(_roy));
_writer.reset(createWriterELF(_woe));
_writerYAML.reset(createWriterYAML(_woy));
}
virtual ErrorOr<lld::Reader&> getReader(const LinkerInput &input) {
@ -47,7 +52,7 @@ public:
}
virtual ErrorOr<lld::Writer&> getWriter() {
return *_writer;
return _options._outputYAML ? *_writerYAML : *_writer;
}
private:
@ -72,8 +77,20 @@ private:
}
} _woe;
struct WYOpts : lld::WriterOptionsYAML {
virtual StringRef kindToString(Reference::Kind k) const {
std::string str;
llvm::raw_string_ostream rso(str);
rso << (unsigned)k;
rso.flush();
return *_strings.insert(str).first;
}
mutable std::set<std::string> _strings;
} _woy;
std::unique_ptr<lld::Reader> _readerELF, _readerYAML;
std::unique_ptr<lld::Writer> _writer;
std::unique_ptr<lld::Writer> _writer, _writerYAML;
};
class X86_64LinuxTarget final : public Target {
@ -83,6 +100,7 @@ public:
_readerELF.reset(createReaderELF(_roe, _roa));
_readerYAML.reset(createReaderYAML(_roy));
_writer.reset(createWriterELF(_woe));
_writerYAML.reset(createWriterYAML(_woy));
}
virtual ErrorOr<lld::Reader&> getReader(const LinkerInput &input) {
@ -100,7 +118,7 @@ public:
}
virtual ErrorOr<lld::Writer&> getWriter() {
return *_writer;
return _options._outputYAML ? *_writerYAML : *_writer;
}
private:
@ -125,8 +143,20 @@ private:
}
} _woe;
struct WYOpts : lld::WriterOptionsYAML {
virtual StringRef kindToString(Reference::Kind k) const {
std::string str;
llvm::raw_string_ostream rso(str);
rso << (unsigned)k;
rso.flush();
return *_strings.insert(str).first;
}
mutable std::set<std::string> _strings;
} _woy;
std::unique_ptr<lld::Reader> _readerELF, _readerYAML;
std::unique_ptr<lld::Writer> _writer;
std::unique_ptr<lld::Writer> _writer, _writerYAML;
};
std::unique_ptr<Target> Target::create(const LinkerOptions &lo) {