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/raw_ostream.h" 20 #include "llvm/System/Signals.h" 21 using namespace llvm; 22 23 static cl::opt<std::string> 24 InputFilename(cl::Positional, cl::desc("<input file>"), cl::init("-")); 25 26 static cl::opt<std::string> 27 OutputFilename("o", cl::desc("Output filename"), 28 cl::value_desc("filename")); 29 30 int main(int argc, char **argv) { 31 // Print a stack trace if we signal out. 32 sys::PrintStackTraceOnErrorSignal(); 33 PrettyStackTraceProgram X(argc, argv); 34 35 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit. 36 37 cl::ParseCommandLineOptions(argc, argv, "llvm machine code playground\n"); 38 39 std::string ErrorMessage; 40 41 MemoryBuffer *Buffer 42 = MemoryBuffer::getFileOrSTDIN(InputFilename, &ErrorMessage); 43 44 if (Buffer == 0) { 45 errs() << argv[0] << ": "; 46 if (ErrorMessage.size()) 47 errs() << ErrorMessage << "\n"; 48 else 49 errs() << "input file didn't read correctly.\n"; 50 return 1; 51 } 52 53 54 55 return 0; 56 } 57 58