llvm.org GIT mirror llvm / c32a226
Use ParseIRFile to auto-detect LLVM Assembly automatically. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@113765 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 9 years ago
1 changed file(s) with 7 addition(s) and 26 deletion(s). Raw diff Collapse all Expand all
1616 #include "llvm/LLVMContext.h"
1717 #include "llvm/Module.h"
1818 #include "llvm/Type.h"
19 #include "llvm/Assembly/Parser.h"
20 #include "llvm/Bitcode/ReaderWriter.h"
2119 #include "llvm/ADT/DenseMap.h"
2220 #include "llvm/ADT/SmallVector.h"
2321 #include "llvm/ADT/StringRef.h"
2422 #include "llvm/Support/CommandLine.h"
2523 #include "llvm/Support/ErrorHandling.h"
24 #include "llvm/Support/IRReader.h"
2625 #include "llvm/Support/MemoryBuffer.h"
2726 #include "llvm/Support/raw_ostream.h"
2827 #include "llvm/Support/SourceMgr.h"
3332
3433 using namespace llvm;
3534
36 /// Reads a module from a file. If the filename ends in .ll, it is
37 /// interpreted as an assembly file; otherwise, it is interpreted as
38 /// bitcode. On error, messages are written to stderr and null is
39 /// returned.
35 /// Reads a module from a file. On error, messages are written to stderr
36 /// and null is returned.
4037 static Module *ReadModule(LLVMContext &Context, StringRef Name) {
41 // LLVM assembly path.
42 if (Name.endswith(".ll")) {
43 SMDiagnostic Diag;
44 Module *M = ParseAssemblyFile(Name, Diag, Context);
45 if (M) return M;
46
38 SMDiagnostic Diag;
39 Module *M = ParseIRFile(Name, Diag, Context);
40 if (!M)
4741 Diag.Print("llvmdiff", errs());
48 return 0;
49 }
50
51 // Bitcode path.
52 MemoryBuffer *Buffer = MemoryBuffer::getFile(Name);
53
54 // ParseBitcodeFile takes ownership of the buffer if it succeeds.
55 std::string Error;
56 Module *M = ParseBitcodeFile(Buffer, Context, &Error);
57 if (M) return M;
58
59 errs() << "error parsing " << Name << ": " << Error;
60 delete Buffer;
61 return 0;
42 return M;
6243 }
6344
6445 namespace {