Michael J. Spencer | 1ffd9de | 2012-08-02 19:16:56 +0000 | [diff] [blame] | 1 | //===- yaml2obj - Convert YAML to a binary object file --------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This program takes a YAML description of an object file and outputs the |
| 11 | // binary equivalent. |
| 12 | // |
| 13 | // This is used for writing tests that require binary files. |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
Sean Silva | 3b76e40 | 2013-06-05 19:56:47 +0000 | [diff] [blame^] | 17 | #include "yaml2obj.h" |
| 18 | #include "llvm/ADT/OwningPtr.h" |
Michael J. Spencer | 1ffd9de | 2012-08-02 19:16:56 +0000 | [diff] [blame] | 19 | #include "llvm/Support/CommandLine.h" |
Michael J. Spencer | 1ffd9de | 2012-08-02 19:16:56 +0000 | [diff] [blame] | 20 | #include "llvm/Support/ManagedStatic.h" |
| 21 | #include "llvm/Support/MemoryBuffer.h" |
| 22 | #include "llvm/Support/PrettyStackTrace.h" |
Michael J. Spencer | 1ffd9de | 2012-08-02 19:16:56 +0000 | [diff] [blame] | 23 | #include "llvm/Support/Signals.h" |
Chandler Carruth | 91d19d8 | 2012-12-04 10:37:14 +0000 | [diff] [blame] | 24 | #include "llvm/Support/raw_ostream.h" |
| 25 | #include "llvm/Support/system_error.h" |
Michael J. Spencer | 1ffd9de | 2012-08-02 19:16:56 +0000 | [diff] [blame] | 26 | |
| 27 | using namespace llvm; |
| 28 | |
| 29 | static cl::opt<std::string> |
| 30 | Input(cl::Positional, cl::desc("<input>"), cl::init("-")); |
| 31 | |
Sean Silva | 741cebb | 2013-06-05 18:51:34 +0000 | [diff] [blame] | 32 | // TODO: The "right" way to tell what kind of object file a given YAML file |
| 33 | // corresponds to is to look at YAML "tags" (e.g. `!Foo`). Then, different |
| 34 | // tags (`!ELF`, `!COFF`, etc.) would be used to discriminate between them. |
| 35 | // Interpreting the tags is needed eventually for when writing test cases, |
| 36 | // so that we can e.g. have `!Archive` contain a sequence of `!ELF`, and |
| 37 | // just Do The Right Thing. However, interpreting these tags and acting on |
| 38 | // them appropriately requires some work in the YAML parser and the YAMLIO |
| 39 | // library. |
| 40 | enum YAMLObjectFormat { |
| 41 | YOF_COFF |
| 42 | }; |
| 43 | |
| 44 | cl::opt<YAMLObjectFormat> Format( |
| 45 | "format", |
| 46 | cl::desc("Interpret input as this type of object file"), |
| 47 | cl::values( |
| 48 | clEnumValN(YOF_COFF, "coff", "COFF object file format"), |
| 49 | clEnumValEnd)); |
| 50 | |
Sean Silva | 741cebb | 2013-06-05 18:51:34 +0000 | [diff] [blame] | 51 | |
| 52 | int main(int argc, char **argv) { |
| 53 | cl::ParseCommandLineOptions(argc, argv); |
| 54 | sys::PrintStackTraceOnErrorSignal(); |
| 55 | PrettyStackTraceProgram X(argc, argv); |
| 56 | llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. |
| 57 | |
| 58 | OwningPtr<MemoryBuffer> Buf; |
| 59 | if (MemoryBuffer::getFileOrSTDIN(Input, Buf)) |
| 60 | return 1; |
| 61 | if (Format == YOF_COFF) { |
| 62 | return yaml2coff(outs(), Buf.get()); |
| 63 | } else { |
| 64 | errs() << "Not yet implemented\n"; |
| 65 | return 1; |
| 66 | } |
Michael J. Spencer | 1ffd9de | 2012-08-02 19:16:56 +0000 | [diff] [blame] | 67 | } |