summaryrefslogtreecommitdiff
path: root/tools/llvm2cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-05-06 05:21:42 +0000
committerChris Lattner <sabre@nondot.org>2007-05-06 05:21:42 +0000
commitb958ba3761e12f99b89ad4feb33be95137f526c0 (patch)
tree4b2e7f59925851077490238d86cce86eac1534bd /tools/llvm2cpp
parent2cb1ad92d1b2d6e77200995685ccabf39673f1b6 (diff)
downloadllvm-b958ba3761e12f99b89ad4feb33be95137f526c0.tar.gz
llvm-b958ba3761e12f99b89ad4feb33be95137f526c0.tar.bz2
llvm-b958ba3761e12f99b89ad4feb33be95137f526c0.tar.xz
bitcodify, remove eh cruft
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36844 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm2cpp')
-rw-r--r--tools/llvm2cpp/Makefile3
-rw-r--r--tools/llvm2cpp/llvm2cpp.cpp22
2 files changed, 19 insertions, 6 deletions
diff --git a/tools/llvm2cpp/Makefile b/tools/llvm2cpp/Makefile
index f9c8aec24c..89ffc97e80 100644
--- a/tools/llvm2cpp/Makefile
+++ b/tools/llvm2cpp/Makefile
@@ -8,8 +8,7 @@
##===----------------------------------------------------------------------===##
LEVEL = ../..
TOOLNAME = llvm2cpp
-LINK_COMPONENTS = bcreader
-REQUIRES_EH := 1
+LINK_COMPONENTS = bcreader bitreader
include $(LEVEL)/Makefile.common
diff --git a/tools/llvm2cpp/llvm2cpp.cpp b/tools/llvm2cpp/llvm2cpp.cpp
index fe9504e567..3424482fda 100644
--- a/tools/llvm2cpp/llvm2cpp.cpp
+++ b/tools/llvm2cpp/llvm2cpp.cpp
@@ -17,19 +17,22 @@
//===------------------------------------------------------------------------===
#include "llvm/Module.h"
+#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Bytecode/Reader.h"
#include "llvm/Analysis/Verifier.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SystemUtils.h"
#include "llvm/System/Signals.h"
#include "CppWriter.h"
#include <fstream>
#include <iostream>
#include <memory>
-
using namespace llvm;
+cl::opt<bool> Bitcode("bitcode");
+
static cl::opt<std::string>
InputFilename(cl::Positional, cl::desc("<input LLVM bytecode file>"),
cl::init("-"));
@@ -49,9 +52,20 @@ int main(int argc, char **argv) {
int exitCode = 0;
std::ostream *Out = 0;
std::string ErrorMessage;
- std::auto_ptr<Module> M(ParseBytecodeFile(InputFilename,
- Compressor::decompressToNewBuffer,
- &ErrorMessage));
+
+ std::auto_ptr<Module> M;
+ if (Bitcode) {
+ std::auto_ptr<MemoryBuffer> Buffer(
+ MemoryBuffer::getFileOrSTDIN(&InputFilename[0], InputFilename.size()));
+ if (Buffer.get())
+ M.reset(ParseBitcodeFile(Buffer.get(), &ErrorMessage));
+ else
+ ErrorMessage = "Error reading file '" + InputFilename + "'";
+ } else {
+ M.reset(ParseBytecodeFile(InputFilename,
+ Compressor::decompressToNewBuffer,
+ &ErrorMessage));
+ }
if (M.get() == 0) {
std::cerr << argv[0] << ": ";
if (ErrorMessage.size())