blob: 74e419ccfca53f3abafbd0393d880e916b487166 [file] [log] [blame]
Chris Lattnerbb4688a2009-06-18 23:05:21 +00001//===-- llvm-mc.cpp - Machine Code Hacking Driver -------------------------===//
Chris Lattnerf9f065e2009-06-18 23:04:45 +00002//
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//
Chris Lattnerbb4688a2009-06-18 23:05:21 +000010// This utility is a simple driver that allows command line hacking on machine
11// code.
Chris Lattnerf9f065e2009-06-18 23:04:45 +000012//
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"
Chris Lattnerb23677e2009-06-21 05:22:37 +000019#include "llvm/Support/SourceMgr.h"
Chris Lattnerf9f065e2009-06-18 23:04:45 +000020#include "llvm/Support/raw_ostream.h"
21#include "llvm/System/Signals.h"
22using namespace llvm;
23
24static cl::opt<std::string>
25InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-"));
26
27static cl::opt<std::string>
28OutputFilename("o", cl::desc("Output filename"),
29 cl::value_desc("filename"));
30
Chris Lattnerb23677e2009-06-21 05:22:37 +000031static cl::list<std::string>
32IncludeDirs("I", cl::desc("Directory of include files"),
33 cl::value_desc("directory"), cl::Prefix);
Chris Lattnerf9f065e2009-06-18 23:04:45 +000034
Chris Lattnerb23677e2009-06-21 05:22:37 +000035enum ActionType {
36 AC_Assemble
37};
Chris Lattnerf9f065e2009-06-18 23:04:45 +000038
Chris Lattnerb23677e2009-06-21 05:22:37 +000039static cl::opt<ActionType>
40Action(cl::desc("Action to perform:"),
41 cl::values(clEnumValN(AC_Assemble, "assemble",
42 "Assemble a .s file (default)"),
43 clEnumValEnd));
44
45static int AssembleInput(const char *ProgName) {
Chris Lattnerf9f065e2009-06-18 23:04:45 +000046 std::string ErrorMessage;
Chris Lattnerb23677e2009-06-21 05:22:37 +000047 MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(InputFilename,
48 &ErrorMessage);
Chris Lattnerf9f065e2009-06-18 23:04:45 +000049 if (Buffer == 0) {
Chris Lattnerb23677e2009-06-21 05:22:37 +000050 errs() << ProgName << ": ";
Chris Lattnerf9f065e2009-06-18 23:04:45 +000051 if (ErrorMessage.size())
52 errs() << ErrorMessage << "\n";
53 else
54 errs() << "input file didn't read correctly.\n";
55 return 1;
56 }
Chris Lattnerb23677e2009-06-21 05:22:37 +000057
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();
Chris Lattnerf9f065e2009-06-18 23:04:45 +000069
70
Chris Lattnerb23677e2009-06-21 05:22:37 +000071 return 1;
72}
73
74
75int 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 }
Chris Lattnerf9f065e2009-06-18 23:04:45 +000087
88 return 0;
89}
90