start wiring up support for asm parsing.
[oota-llvm.git] / tools / llvm-mc / llvm-mc.cpp
1 //===-- llvm-mc.cpp - Machine Code Hacking Driver -------------------------===//
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 utility is a simple driver that allows command line hacking on machine
11 // code.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/Support/CommandLine.h"
16 #include "llvm/Support/ManagedStatic.h"
17 #include "llvm/Support/MemoryBuffer.h"
18 #include "llvm/Support/PrettyStackTrace.h"
19 #include "llvm/Support/SourceMgr.h"
20 #include "llvm/Support/raw_ostream.h"
21 #include "llvm/System/Signals.h"
22 using namespace llvm;
23
24 static cl::opt<std::string>
25 InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-"));
26
27 static cl::opt<std::string>
28 OutputFilename("o", cl::desc("Output filename"),
29                cl::value_desc("filename"));
30
31 static cl::list<std::string>
32 IncludeDirs("I", cl::desc("Directory of include files"),
33             cl::value_desc("directory"), cl::Prefix);
34
35 enum ActionType {
36   AC_Assemble
37 };
38
39 static cl::opt<ActionType>
40 Action(cl::desc("Action to perform:"),
41        cl::values(clEnumValN(AC_Assemble, "assemble",
42                              "Assemble a .s file (default)"),
43                   clEnumValEnd));
44
45 static int AssembleInput(const char *ProgName) {
46   std::string ErrorMessage;
47   MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename,
48                                                       &ErrorMessage);
49   if (Buffer == 0) {
50     errs() << ProgName << ": ";
51     if (ErrorMessage.size())
52       errs() << ErrorMessage << "\n";
53     else
54       errs() << "input file didn't read correctly.\n";
55     return 1;
56   }
57
58   SourceMgr SrcMgr;
59   
60   // Tell SrcMgr about this buffer, which is what TGParser will pick up.
61   SrcMgr.AddNewSourceBuffer(Buffer, SMLoc());
62   
63   // Record the location of the include directories so that the lexer can find
64   // it later.
65   SrcMgr.setIncludeDirs(IncludeDirs);
66   
67   //TGParser Parser(SrcMgr);
68   //return Parser.ParseFile();
69   
70   
71   return 1;
72 }
73
74
75 int main(int argc, char **argv) {
76   // Print a stack trace if we signal out.
77   sys::PrintStackTraceOnErrorSignal();
78   PrettyStackTraceProgram X(argc, argv);
79   llvm_shutdown_obj Y;  // Call llvm_shutdown() on exit.
80   cl::ParseCommandLineOptions(argc, argv, "llvm machine code playground\n");
81
82   switch (Action) {
83   default:
84   case AC_Assemble:
85     return AssembleInput(argv[0]);
86   }
87   
88   return 0;
89 }
90