diff options
Diffstat (limited to 'tools/yaml2obj')
-rw-r--r-- | tools/yaml2obj/Android.mk | 2 | ||||
-rw-r--r-- | tools/yaml2obj/yaml2coff.cpp | 3 | ||||
-rw-r--r-- | tools/yaml2obj/yaml2elf.cpp | 6 | ||||
-rw-r--r-- | tools/yaml2obj/yaml2obj.cpp | 42 | ||||
-rw-r--r-- | tools/yaml2obj/yaml2obj.h | 10 |
5 files changed, 46 insertions, 17 deletions
diff --git a/tools/yaml2obj/Android.mk b/tools/yaml2obj/Android.mk index d69075a..3242c31 100644 --- a/tools/yaml2obj/Android.mk +++ b/tools/yaml2obj/Android.mk @@ -14,6 +14,8 @@ yaml2obj_SRC_FILES := \ yaml2obj_STATIC_LIBRARIES := \ libLLVMObject \ + libLLVMMC \ + libLLVMMCParser \ libLLVMBitReader \ libLLVMCore \ libLLVMSupport \ diff --git a/tools/yaml2obj/yaml2coff.cpp b/tools/yaml2obj/yaml2coff.cpp index a0ede24..c772db9 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 bb52cda..6eeecae 100644 --- a/tools/yaml2obj/yaml2elf.cpp +++ b/tools/yaml2obj/yaml2elf.cpp @@ -14,9 +14,9 @@ #include "yaml2obj.h" #include "llvm/ADT/ArrayRef.h" +#include "llvm/MC/StringTableBuilder.h" #include "llvm/Object/ELFObjectFile.h" #include "llvm/Object/ELFYAML.h" -#include "llvm/Object/StringTableBuilder.h" #include "llvm/Support/ELF.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/YAMLTraits.h" @@ -304,6 +304,7 @@ void ELFState<ELFT>::addSymbols(const std::vector<ELFYAML::Symbol> &Symbols, Symbol.st_shndx = Index; } // else Symbol.st_shndex == SHN_UNDEF (== 0), since it was zero'd earlier. Symbol.st_value = Sym.Value; + Symbol.st_other = Sym.Visibility; Symbol.st_size = Sym.Size; Syms.push_back(Symbol); } @@ -467,8 +468,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 2493b48..945fad1 100644 --- a/tools/yaml2obj/yaml2obj.cpp +++ b/tools/yaml2obj/yaml2obj.cpp @@ -15,15 +15,17 @@ //===----------------------------------------------------------------------===// #include "yaml2obj.h" +#include "llvm/ADT/StringExtras.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/ManagedStatic.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Signals.h" -#include "llvm/Support/raw_ostream.h" -#include "llvm/Support/system_error.h" #include "llvm/Support/ToolOutputFile.h" +#include "llvm/Support/YAMLTraits.h" +#include "llvm/Support/raw_ostream.h" +#include <system_error> 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(); @@ -71,18 +91,24 @@ int main(int argc, char **argv) { return 1; } - std::unique_ptr<MemoryBuffer> Buf; - if (MemoryBuffer::getFileOrSTDIN(Input, Buf)) + ErrorOr<std::unique_ptr<MemoryBuffer>> Buf = + MemoryBuffer::getFileOrSTDIN(Input); + if (!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.get()->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 095435c..086f641 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 |