OLD | NEW |
1 //===- NaClBitcodeReader.h ------------------------------------*- C++ -*-===// | 1 //===- NaClBitcodeReader.h ------------------------------------*- C++ -*-===// |
2 // Internal NaClBitcodeReader implementation | 2 // Internal NaClBitcodeReader implementation |
3 // | 3 // |
4 // The LLVM Compiler Infrastructure | 4 // The LLVM Compiler Infrastructure |
5 // | 5 // |
6 // This file is distributed under the University of Illinois Open Source | 6 // This file is distributed under the University of Illinois Open Source |
7 // License. See LICENSE.TXT for details. | 7 // License. See LICENSE.TXT for details. |
8 // | 8 // |
9 //===----------------------------------------------------------------------===// | 9 //===----------------------------------------------------------------------===// |
10 // | 10 // |
11 // This header defines the NaClBitcodeReader class. | 11 // This header defines the NaClBitcodeReader class. |
12 // | 12 // |
13 //===----------------------------------------------------------------------===// | 13 //===----------------------------------------------------------------------===// |
14 | 14 |
15 #ifndef NACL_BITCODE_READER_H | 15 #ifndef NACL_BITCODE_READER_H |
16 #define NACL_BITCODE_READER_H | 16 #define NACL_BITCODE_READER_H |
17 | 17 |
18 #include "llvm/ADT/DenseMap.h" | 18 #include "llvm/ADT/DenseMap.h" |
| 19 #include "llvm/Analysis/NaCl/PNaClABIProps.h" |
19 #include "llvm/Analysis/NaCl/PNaClAllowedIntrinsics.h" | 20 #include "llvm/Analysis/NaCl/PNaClAllowedIntrinsics.h" |
20 #include "llvm/Bitcode/NaCl/NaClBitcodeHeader.h" | 21 #include "llvm/Bitcode/NaCl/NaClBitcodeHeader.h" |
21 #include "llvm/Bitcode/NaCl/NaClBitstreamReader.h" | 22 #include "llvm/Bitcode/NaCl/NaClBitstreamReader.h" |
22 #include "llvm/Bitcode/NaCl/NaClLLVMBitCodes.h" | 23 #include "llvm/Bitcode/NaCl/NaClLLVMBitCodes.h" |
23 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" | 24 #include "llvm/Bitcode/NaCl/NaClReaderWriter.h" |
24 #include "llvm/IR/DerivedTypes.h" | 25 #include "llvm/IR/DerivedTypes.h" |
25 #include "llvm/IR/GVMaterializer.h" | 26 #include "llvm/IR/GVMaterializer.h" |
26 #include "llvm/IR/Instruction.h" | 27 #include "llvm/IR/Instruction.h" |
27 #include "llvm/IR/OperandTraits.h" | 28 #include "llvm/IR/OperandTraits.h" |
28 #include "llvm/IR/Type.h" | 29 #include "llvm/IR/Type.h" |
29 #include "llvm/IR/ValueHandle.h" | 30 #include "llvm/IR/ValueHandle.h" |
| 31 #include "llvm/Support/raw_ostream.h" |
30 #include <vector> | 32 #include <vector> |
31 | 33 |
32 namespace llvm { | 34 namespace llvm { |
33 class MemoryBuffer; | 35 class MemoryBuffer; |
34 class LLVMContext; | 36 class LLVMContext; |
35 class CastInst; | 37 class CastInst; |
36 | 38 |
37 // Models a Cast. Used to cache casts created in a basic block by the | 39 // Models a Cast. Used to cache casts created in a basic block by the |
38 // PNaCl bitcode reader. | 40 // PNaCl bitcode reader. |
39 struct NaClBitcodeReaderCast { | 41 struct NaClBitcodeReaderCast { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 return std::error_code(E, BitcodeErrorCategory()); | 243 return std::error_code(E, BitcodeErrorCategory()); |
242 } | 244 } |
243 | 245 |
244 /// Generates the corresponding verbose Message, then generates error. | 246 /// Generates the corresponding verbose Message, then generates error. |
245 std::error_code Error(ErrorType E, const std::string &Message) const; | 247 std::error_code Error(ErrorType E, const std::string &Message) const; |
246 | 248 |
247 /// @brief Main interface to parsing a bitcode buffer. | 249 /// @brief Main interface to parsing a bitcode buffer. |
248 /// @returns true if an error occurred. | 250 /// @returns true if an error occurred. |
249 std::error_code ParseBitcodeInto(Module *M); | 251 std::error_code ParseBitcodeInto(Module *M); |
250 | 252 |
| 253 /// Convert alignment exponent (i.e. power of two (or zero)) to the |
| 254 /// corresponding alignment to use. If alignment is too large, it generates |
| 255 /// an error message and returns corresponding error code. |
| 256 std::error_code getAlignmentValue(uint64_t Exponent, unsigned &Alignment); |
| 257 |
251 private: | 258 private: |
252 // Returns false if Header is acceptable. | 259 // Returns false if Header is acceptable. |
253 bool AcceptHeader() const { | 260 bool AcceptHeader() const { |
254 return !(Header.IsSupported() || | 261 return !(Header.IsSupported() || |
255 (!AcceptSupportedBitcodeOnly && Header.IsReadable())); | 262 (!AcceptSupportedBitcodeOnly && Header.IsReadable())); |
256 } | 263 } |
257 uint32_t GetPNaClVersion() const { | 264 uint32_t GetPNaClVersion() const { |
258 return Header.GetPNaClVersion(); | 265 return Header.GetPNaClVersion(); |
259 } | 266 } |
260 Type *getTypeByID(unsigned ID); | 267 Type *getTypeByID(unsigned ID); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 /// getValueSigned -- Like getValue, but decodes signed VBRs. | 300 /// getValueSigned -- Like getValue, but decodes signed VBRs. |
294 Value *getValueSigned(const SmallVector<uint64_t, 64> &Record, unsigned Slot, | 301 Value *getValueSigned(const SmallVector<uint64_t, 64> &Record, unsigned Slot, |
295 unsigned InstNum) { | 302 unsigned InstNum) { |
296 if (Slot == Record.size()) return 0; | 303 if (Slot == Record.size()) return 0; |
297 // ValNo is encoded relative to the InstNum. | 304 // ValNo is encoded relative to the InstNum. |
298 unsigned ValNo = InstNum - | 305 unsigned ValNo = InstNum - |
299 (unsigned) NaClDecodeSignRotatedValue(Record[Slot]); | 306 (unsigned) NaClDecodeSignRotatedValue(Record[Slot]); |
300 return getFnValueByID(ValNo); | 307 return getFnValueByID(ValNo); |
301 } | 308 } |
302 | 309 |
| 310 /// Convert alignment exponent (i.e. power of two (or zero)) to the |
| 311 /// corresponding load/store alignment to use. If alignment is not |
| 312 /// allowed for the load/store, it generates an error message and |
| 313 /// returns the corresponding error code. |
| 314 std::error_code getLoadStoreAlignmentValue( |
| 315 uint64_t Exponent, const DataLayout *DL, Type *MemType, |
| 316 const char *InstName, unsigned &Alignment) { |
| 317 std::error_code EC = getAlignmentValue(Exponent, Alignment); |
| 318 if (EC) |
| 319 return EC; |
| 320 if (!PNaClABIProps::isAllowedAlignment(DL, Alignment, MemType)) { |
| 321 std::string Buffer; |
| 322 raw_string_ostream StrBuf(Buffer); |
| 323 StrBuf << "Invalid alignment for " << InstName << " of type " |
| 324 << *MemType << ": " << Alignment; |
| 325 return Error(InvalidValue, StrBuf.str()); |
| 326 } |
| 327 // Successful! |
| 328 return EC; |
| 329 } |
| 330 |
303 /// \brief Create an (elided) cast instruction for basic block | 331 /// \brief Create an (elided) cast instruction for basic block |
304 /// BBIndex. Op is the type of cast. V is the value to cast. CT | 332 /// BBIndex. Op is the type of cast. V is the value to cast. CT |
305 /// is the type to convert V to. DeferInsertion defines whether the | 333 /// is the type to convert V to. DeferInsertion defines whether the |
306 /// generated conversion should also be installed into basic block | 334 /// generated conversion should also be installed into basic block |
307 /// BBIndex. Note: For PHI nodes, we don't insert when created | 335 /// BBIndex. Note: For PHI nodes, we don't insert when created |
308 /// (i.e. DeferInsertion=true), since they must be inserted at the end | 336 /// (i.e. DeferInsertion=true), since they must be inserted at the end |
309 /// of the corresponding incoming basic block. | 337 /// of the corresponding incoming basic block. |
310 CastInst *CreateCast(unsigned BBIndex, Instruction::CastOps Op, | 338 CastInst *CreateCast(unsigned BBIndex, Instruction::CastOps Op, |
311 Type *CT, Value *V, bool DeferInsertion = false); | 339 Type *CT, Value *V, bool DeferInsertion = false); |
312 | 340 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 std::error_code InitStreamFromBuffer(); | 372 std::error_code InitStreamFromBuffer(); |
345 std::error_code InitLazyStream(); | 373 std::error_code InitLazyStream(); |
346 std::error_code FindFunctionInStream( | 374 std::error_code FindFunctionInStream( |
347 Function *F, | 375 Function *F, |
348 DenseMap<Function*, uint64_t>::iterator DeferredFunctionInfoIterator); | 376 DenseMap<Function*, uint64_t>::iterator DeferredFunctionInfoIterator); |
349 }; | 377 }; |
350 | 378 |
351 } // End llvm namespace | 379 } // End llvm namespace |
352 | 380 |
353 #endif | 381 #endif |
OLD | NEW |