diff options
author | Simon Atanasyan <simon@atanasyan.com> | 2014-05-31 04:51:07 +0000 |
---|---|---|
committer | Simon Atanasyan <simon@atanasyan.com> | 2014-05-31 04:51:07 +0000 |
commit | df96c562a5f9a53287689b426896080c72a85785 (patch) | |
tree | c8b2c763c1d335383d894874edfe13e27f2b34f0 /tools/yaml2obj | |
parent | 44c63540158fe25f33a14e2b4758fb4a88890fd9 (diff) | |
download | llvm-df96c562a5f9a53287689b426896080c72a85785.tar.gz llvm-df96c562a5f9a53287689b426896080c72a85785.tar.bz2 llvm-df96c562a5f9a53287689b426896080c72a85785.tar.xz |
[yaml2obj] Add new command line option `-docnum`.
Input YAML file might contain multiple object file definitions.
New option `-docnum` allows to specify an ordinal number (starting from 1)
of definition used for an object file generation.
Patch reviewed by Sean Silva.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209967 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/yaml2obj')
-rw-r--r-- | tools/yaml2obj/yaml2coff.cpp | 3 | ||||
-rw-r--r-- | tools/yaml2obj/yaml2elf.cpp | 3 | ||||
-rw-r--r-- | tools/yaml2obj/yaml2obj.cpp | 33 | ||||
-rw-r--r-- | tools/yaml2obj/yaml2obj.h | 10 |
4 files changed, 37 insertions, 12 deletions
diff --git a/tools/yaml2obj/yaml2coff.cpp b/tools/yaml2obj/yaml2coff.cpp index a0ede246bd..c772db9a8e 100644 --- a/tools/yaml2obj/yaml2coff.cpp +++ b/tools/yaml2obj/yaml2coff.cpp @@ -327,8 +327,7 @@ bool writeCOFF(COFFParser &CP, raw_ostream &OS) { return true; } -int yaml2coff(llvm::raw_ostream &Out, llvm::MemoryBuffer *Buf) { - yaml::Input YIn(Buf->getBuffer()); +int yaml2coff(yaml::Input &YIn, raw_ostream &Out) { COFFYAML::Object Doc; YIn >> Doc; if (YIn.error()) { diff --git a/tools/yaml2obj/yaml2elf.cpp b/tools/yaml2obj/yaml2elf.cpp index bb52cda7c1..11a56469b0 100644 --- a/tools/yaml2obj/yaml2elf.cpp +++ b/tools/yaml2obj/yaml2elf.cpp @@ -467,8 +467,7 @@ static bool isLittleEndian(const ELFYAML::Object &Doc) { return Doc.Header.Data == ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB); } -int yaml2elf(llvm::raw_ostream &Out, llvm::MemoryBuffer *Buf) { - yaml::Input YIn(Buf->getBuffer()); +int yaml2elf(yaml::Input &YIn, raw_ostream &Out) { ELFYAML::Object Doc; YIn >> Doc; if (YIn.error()) { diff --git a/tools/yaml2obj/yaml2obj.cpp b/tools/yaml2obj/yaml2obj.cpp index 2493b48699..eef9c841f3 100644 --- a/tools/yaml2obj/yaml2obj.cpp +++ b/tools/yaml2obj/yaml2obj.cpp @@ -15,6 +15,7 @@ //===----------------------------------------------------------------------===// #include "yaml2obj.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/ManagedStatic.h" @@ -24,6 +25,7 @@ #include "llvm/Support/raw_ostream.h" #include "llvm/Support/system_error.h" #include "llvm/Support/ToolOutputFile.h" +#include "llvm/Support/YAMLTraits.h" using namespace llvm; @@ -51,9 +53,27 @@ cl::opt<YAMLObjectFormat> Format( clEnumValN(YOF_ELF, "elf", "ELF object file format"), clEnumValEnd)); +cl::opt<unsigned> +DocNum("docnum", cl::init(1), + cl::desc("Read specified document from input (default = 1)")); + static cl::opt<std::string> OutputFilename("o", cl::desc("Output filename"), cl::value_desc("filename")); +typedef int (*ConvertFuncPtr)(yaml::Input & YIn, raw_ostream &Out); + +int convertYAML(yaml::Input & YIn, raw_ostream &Out, ConvertFuncPtr Convert) { + unsigned CurDocNum = 0; + do { + if (++CurDocNum == DocNum) + return Convert(YIn, Out); + } while (YIn.nextDocument()); + + errs() << "yaml2obj: Cannot find the " << DocNum + << llvm::getOrdinalSuffix(DocNum) << " document\n"; + return 1; +} + int main(int argc, char **argv) { cl::ParseCommandLineOptions(argc, argv); sys::PrintStackTraceOnErrorSignal(); @@ -75,14 +95,19 @@ int main(int argc, char **argv) { if (MemoryBuffer::getFileOrSTDIN(Input, Buf)) return 1; - int Res = 1; + ConvertFuncPtr Convert = nullptr; if (Format == YOF_COFF) - Res = yaml2coff(Out->os(), Buf.get()); + Convert = yaml2coff; else if (Format == YOF_ELF) - Res = yaml2elf(Out->os(), Buf.get()); - else + Convert = yaml2elf; + else { errs() << "Not yet implemented\n"; + return 1; + } + + yaml::Input YIn(Buf->getBuffer()); + int Res = convertYAML(YIn, Out->os(), Convert); if (Res == 0) Out->keep(); diff --git a/tools/yaml2obj/yaml2obj.h b/tools/yaml2obj/yaml2obj.h index 095435c549..086f6413aa 100644 --- a/tools/yaml2obj/yaml2obj.h +++ b/tools/yaml2obj/yaml2obj.h @@ -13,10 +13,12 @@ #define LLVM_TOOLS_YAML2OBJ_H namespace llvm { - class raw_ostream; - class MemoryBuffer; +class raw_ostream; +namespace yaml { +class Input; } -int yaml2coff(llvm::raw_ostream &Out, llvm::MemoryBuffer *Buf); -int yaml2elf(llvm::raw_ostream &Out, llvm::MemoryBuffer *Buf); +} +int yaml2coff(llvm::yaml::Input &YIn, llvm::raw_ostream &Out); +int yaml2elf(llvm::yaml::Input &YIn, llvm::raw_ostream &Out); #endif |