| OLD | NEW |
| 1 //===---- IRReader.cpp - Reader for LLVM IR files -------------------------===// | 1 //===---- IRReader.cpp - Reader for LLVM IR files -------------------------===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 | 9 |
| 10 #include "llvm/IRReader/IRReader.h" | 10 #include "llvm/IRReader/IRReader.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 return nullptr; | 95 return nullptr; |
| 96 } | 96 } |
| 97 | 97 |
| 98 return ParseIR(FileOrErr.get().get(), Err, Context); | 98 return ParseIR(FileOrErr.get().get(), Err, Context); |
| 99 } | 99 } |
| 100 | 100 |
| 101 // @LOCALMOD-BEGIN | 101 // @LOCALMOD-BEGIN |
| 102 Module *llvm::NaClParseIR(MemoryBuffer *Buffer, | 102 Module *llvm::NaClParseIR(MemoryBuffer *Buffer, |
| 103 NaClFileFormat Format, | 103 NaClFileFormat Format, |
| 104 SMDiagnostic &Err, | 104 SMDiagnostic &Err, |
| 105 raw_ostream *Verbose, |
| 105 LLVMContext &Context) { | 106 LLVMContext &Context) { |
| 106 NamedRegionTimer T(TimeIRParsingName, TimeIRParsingGroupName, | 107 NamedRegionTimer T(TimeIRParsingName, TimeIRParsingGroupName, |
| 107 TimePassesIsEnabled); | 108 TimePassesIsEnabled); |
| 108 if ((Format == PNaClFormat) && | 109 if ((Format == PNaClFormat) && |
| 109 isNaClBitcode((const unsigned char *)Buffer->getBufferStart(), | 110 isNaClBitcode((const unsigned char *)Buffer->getBufferStart(), |
| 110 (const unsigned char *)Buffer->getBufferEnd())) { | 111 (const unsigned char *)Buffer->getBufferEnd())) { |
| 111 std::string ErrMsg; | 112 ErrorOr<Module *> ModuleOrErr = |
| 112 Module *M = NaClParseBitcodeFile(Buffer, Context, &ErrMsg); | 113 NaClParseBitcodeFile(Buffer, Context, Verbose); |
| 113 if (M == 0) | 114 if (std::error_code EC = ModuleOrErr.getError()) |
| 114 Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error, | 115 Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error, |
| 115 ErrMsg); | 116 EC.message()); |
| 116 // ParseBitcodeFile does not take ownership of the Buffer. | 117 // ParseBitcodeFile does not take ownership of the Buffer. |
| 117 return M; | 118 return ModuleOrErr.get(); |
| 118 } else if (Format == LLVMFormat) { | 119 } else if (Format == LLVMFormat) { |
| 119 if (isBitcode((const unsigned char *)Buffer->getBufferStart(), | 120 if (isBitcode((const unsigned char *)Buffer->getBufferStart(), |
| 120 (const unsigned char *)Buffer->getBufferEnd())) { | 121 (const unsigned char *)Buffer->getBufferEnd())) { |
| 121 ErrorOr<Module *> MOrErr = parseBitcodeFile(Buffer, Context); | 122 ErrorOr<Module *> MOrErr = parseBitcodeFile(Buffer, Context); |
| 122 if (std::error_code EC = MOrErr.getError()) | 123 if (std::error_code EC = MOrErr.getError()) |
| 123 Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error, | 124 Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error, |
| 124 EC.message()); | 125 EC.message()); |
| 125 // ParseBitcodeFile does not take ownership of the Buffer. | 126 // ParseBitcodeFile does not take ownership of the Buffer. |
| 126 return MOrErr.get(); | 127 return MOrErr.get(); |
| 127 } | 128 } |
| 128 | 129 |
| 129 return ParseAssembly(Buffer, 0, Err, Context); | 130 return ParseAssembly(Buffer, 0, Err, Context); |
| 130 } else { | 131 } else { |
| 131 Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error, | 132 Err = SMDiagnostic(Buffer->getBufferIdentifier(), SourceMgr::DK_Error, |
| 132 "Did not specify correct format for file"); | 133 "Did not specify correct format for file"); |
| 133 return 0; | 134 return 0; |
| 134 } | 135 } |
| 135 } | 136 } |
| 136 | 137 |
| 137 Module *llvm::NaClParseIRFile(const std::string &Filename, | 138 Module *llvm::NaClParseIRFile(const std::string &Filename, |
| 138 NaClFileFormat Format, | 139 NaClFileFormat Format, |
| 139 SMDiagnostic &Err, | 140 SMDiagnostic &Err, |
| 141 raw_ostream *Verbose, |
| 140 LLVMContext &Context) { | 142 LLVMContext &Context) { |
| 141 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrOrFile = | 143 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrOrFile = |
| 142 MemoryBuffer::getFileOrSTDIN(Filename); | 144 MemoryBuffer::getFileOrSTDIN(Filename); |
| 143 if (std::error_code EC = ErrOrFile.getError()) { | 145 if (std::error_code EC = ErrOrFile.getError()) { |
| 144 Err = SMDiagnostic(Filename, SourceMgr::DK_Error, | 146 Err = SMDiagnostic(Filename, SourceMgr::DK_Error, |
| 145 "Could not open input file: " + EC.message()); | 147 "Could not open input file: " + EC.message()); |
| 146 return nullptr; | 148 return nullptr; |
| 147 } | 149 } |
| 148 | 150 |
| 149 return NaClParseIR(ErrOrFile.get().release(), Format, Err, Context); | 151 return NaClParseIR(ErrOrFile.get().release(), Format, Err, Verbose, |
| 152 Context); |
| 150 } | 153 } |
| 151 | 154 |
| 152 // @LOCALMOD-END | 155 // @LOCALMOD-END |
| 153 | 156 |
| 154 //===----------------------------------------------------------------------===// | 157 //===----------------------------------------------------------------------===// |
| 155 // C API. | 158 // C API. |
| 156 //===----------------------------------------------------------------------===// | 159 //===----------------------------------------------------------------------===// |
| 157 | 160 |
| 158 LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef, | 161 LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef, |
| 159 LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM, | 162 LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 171 Diag.print(nullptr, os, false); | 174 Diag.print(nullptr, os, false); |
| 172 os.flush(); | 175 os.flush(); |
| 173 | 176 |
| 174 *OutMessage = strdup(buf.c_str()); | 177 *OutMessage = strdup(buf.c_str()); |
| 175 } | 178 } |
| 176 return 1; | 179 return 1; |
| 177 } | 180 } |
| 178 | 181 |
| 179 return 0; | 182 return 0; |
| 180 } | 183 } |
| OLD | NEW |