1212#include " llvm/Support/ToolOutputFile.h"
1313#include " llvm/Config/llvm-config.h"
1414
15- #define LLVM_360_AND_NEWER \
16- (LLVM_VERSION_MAJOR > 3 || (LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6 ))
17-
18- #define LLVM_350_AND_NEWER \
19- (LLVM_VERSION_MAJOR > 3 || (LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5 ))
20-
21- #if LLVM_350_AND_NEWER
2215#include < system_error>
2316
24- #define ERROR_CODE std::error_code
25- #define UNIQUE_PTR std::unique_ptr
26- #else
27- #include " llvm/ADT/OwningPtr.h"
28- #include " llvm/Support/system_error.h"
29-
30- #define ERROR_CODE error_code
31- #define UNIQUE_PTR OwningPtr
32- #endif
33-
3417using namespace llvm ;
3518
3619static cl::opt<std::string>
@@ -50,30 +33,17 @@ int main(int argc, char **argv) {
5033 std::auto_ptr<Module> M;
5134
5235 {
53- #if LLVM_350_AND_NEWER
5436 ErrorOr<std::unique_ptr<MemoryBuffer>> BufferOrErr =
5537 MemoryBuffer::getFile (InputFilename);
5638 std::unique_ptr<MemoryBuffer> &BufferPtr = BufferOrErr.get ();
5739 if (std::error_code ec = BufferOrErr.getError ())
58- #else
59- UNIQUE_PTR<MemoryBuffer> BufferPtr;
60- if (ERROR_CODE ec = MemoryBuffer::getFileOrSTDIN (InputFilename, BufferPtr))
61- #endif
6240 ErrorMessage = ec.message ();
6341 else {
64- #if LLVM_VERSION_MAJOR > 3 || (LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR > 4)
65- # if LLVM_360_AND_NEWER
6642 ErrorOr<Module *> ModuleOrErr =
6743 parseBitcodeFile (BufferPtr.get ()->getMemBufferRef (), Context);
68- # else
69- ErrorOr<Module *> ModuleOrErr = parseBitcodeFile (BufferPtr.get (), Context);
70- # endif
71- if (ERROR_CODE ec = ModuleOrErr.getError ())
44+ if (std::error_code ec = ModuleOrErr.getError ())
7245 ErrorMessage = ec.message ();
7346 M.reset (ModuleOrErr.get ());
74- #else
75- M.reset (ParseBitcodeFile (BufferPtr.get (), Context, &ErrorMessage));
76- #endif
7747 }
7848 }
7949
@@ -103,30 +73,13 @@ int main(int argc, char **argv) {
10373 return 1 ;
10474 }
10575
106- #if LLVM_360_AND_NEWER
10776 std::error_code EC;
108- UNIQUE_PTR <tool_output_file> Out
77+ std::unique_ptr <tool_output_file> Out
10978 (new tool_output_file (OutputFilename, EC, sys::fs::F_None));
11079 if (EC) {
11180 errs () << EC.message () << ' \n ' ;
11281 exit (1 );
11382 }
114- #else
115- std::string ErrorInfo;
116- UNIQUE_PTR<tool_output_file> Out
117- (new tool_output_file (OutputFilename.c_str (), ErrorInfo,
118- #if (LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 4)
119- sys::fs::F_Binary));
120- #elif LLVM_VERSION_MAJOR > 3 || (LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5)
121- sys::fs::F_None));
122- #else
123- raw_fd_ostream::F_Binary));
124- #endif
125- if (!ErrorInfo.empty ()) {
126- errs () << ErrorInfo << ' \n ' ;
127- exit (1 );
128- }
129- #endif // LLVM_360_AND_NEWER
13083
13184 WriteBitcodeToFile (M.get (), Out->os ());
13285
0 commit comments