blob: a9ac78bce4869863c57ec4adaa7435a10136389f [file] [log] [blame]
Michael J. Spencer1ffd9de2012-08-02 19:16:56 +00001//===- 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 Silva3b76e402013-06-05 19:56:47 +000017#include "yaml2obj.h"
18#include "llvm/ADT/OwningPtr.h"
Michael J. Spencer1ffd9de2012-08-02 19:16:56 +000019#include "llvm/Support/CommandLine.h"
Michael J. Spencer1ffd9de2012-08-02 19:16:56 +000020#include "llvm/Support/ManagedStatic.h"
21#include "llvm/Support/MemoryBuffer.h"
22#include "llvm/Support/PrettyStackTrace.h"
Michael J. Spencer1ffd9de2012-08-02 19:16:56 +000023#include "llvm/Support/Signals.h"
Chandler Carruth91d19d82012-12-04 10:37:14 +000024#include "llvm/Support/raw_ostream.h"
25#include "llvm/Support/system_error.h"
Michael J. Spencer1ffd9de2012-08-02 19:16:56 +000026
27using namespace llvm;
28
29static cl::opt<std::string>
30 Input(cl::Positional, cl::desc("<input>"), cl::init("-"));
31
Sean Silva741cebb2013-06-05 18:51:34 +000032// 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.
40enum YAMLObjectFormat {
41 YOF_COFF
42};
43
44cl::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 Silva741cebb2013-06-05 18:51:34 +000051
52int 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. Spencer1ffd9de2012-08-02 19:16:56 +000067}