add bitcode reading support. Remove EH cruft.

llvm-svn: 36839
This commit is contained in:
Chris Lattner 2007-05-06 04:55:19 +00:00
parent d29a084c58
commit 22509133cd
2 changed files with 141 additions and 132 deletions

View File

@ -9,14 +9,13 @@
LEVEL = ../..
TOOLNAME = llc
REQUIRES_EH := 1
# Include this here so we can get the configuration of the targets
# that have been configured for construction. We have to do this
# early so we can set up LINK_COMPONENTS before including Makefile.rules
include $(LEVEL)/Makefile.config
LINK_COMPONENTS := $(TARGETS_TO_BUILD) bcreader
LINK_COMPONENTS := $(TARGETS_TO_BUILD) bcreader bitreader
include $(LLVM_SRC_ROOT)/Makefile.rules

View File

@ -13,6 +13,7 @@
//
//===----------------------------------------------------------------------===//
#include "llvm/Bitcode/ReaderWriter.h"
#include "llvm/Bytecode/Reader.h"
#include "llvm/CodeGen/FileWriters.h"
#include "llvm/CodeGen/LinkAllCodegenComponents.h"
@ -27,6 +28,7 @@
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Compressor.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/PluginLoader.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Analysis/Verifier.h"
@ -36,9 +38,11 @@
#include <fstream>
#include <iostream>
#include <memory>
using namespace llvm;
cl::opt<bool> Bitcode("bitcode");
// General options for llc. Other pass-specific options are specified
// within the corresponding llc passes, and target-specific options
// and back-end code generation options are specified with the target machine.
@ -172,18 +176,30 @@ static std::ostream *GetOutputStream(const char *ProgName) {
//
int main(int argc, char **argv) {
llvm_shutdown_obj X; // Call llvm_shutdown() on exit.
try {
cl::ParseCommandLineOptions(argc, argv, " llvm system compiler\n");
sys::PrintStackTraceOnErrorSignal();
// Load the module to be compiled...
std::string errmsg;
std::auto_ptr<Module> M(ParseBytecodeFile(InputFilename,
std::string ErrorMessage;
std::auto_ptr<Module> M;
if (Bitcode) {
MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(&InputFilename[0],
InputFilename.size());
if (Buffer == 0)
ErrorMessage = "Error reading file '" + InputFilename + "'";
else
M.reset(ParseBitcodeFile(Buffer, &ErrorMessage));
delete Buffer;
} else {
M.reset(ParseBytecodeFile(InputFilename,
Compressor::decompressToNewBuffer,
&errmsg));
&ErrorMessage));
}
if (M.get() == 0) {
std::cerr << argv[0] << ": bytecode didn't read correctly.\n";
std::cerr << "Reason: " << errmsg << "\n";
std::cerr << "Reason: " << ErrorMessage << "\n";
return 1;
}
Module &mod = *M.get();
@ -299,10 +315,4 @@ int main(int argc, char **argv) {
if (Out != &std::cout) delete Out;
return 0;
} catch (const std::string& msg) {
std::cerr << argv[0] << ": " << msg << "\n";
} catch (...) {
std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n";
}
return 1;
}