OLD | NEW |
1 //===-- llvm/Bitcode/NaCl/NaClBitcodeHeader.h - ----------------*- C++ -*-===// | 1 //===-- llvm/Bitcode/NaCl/NaClBitcodeHeader.h - ----------------*- C++ -*-===// |
2 // NaCl Bitcode header reader. | 2 // NaCl Bitcode header reader. |
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 interfaces to read and write NaCl bitcode wire format | 11 // This header defines interfaces to read and write NaCl bitcode wire format |
12 // file headers. | 12 // file headers. |
13 // | 13 // |
14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
15 | 15 |
16 #ifndef LLVM_BITCODE_NACL_NACLBITCODEHEADER_H | 16 #ifndef LLVM_BITCODE_NACL_NACLBITCODEHEADER_H |
17 #define LLVM_BITCODE_NACL_NACLBITCODEHEADER_H | 17 #define LLVM_BITCODE_NACL_NACLBITCODEHEADER_H |
18 | 18 |
19 #include "llvm/ADT/StringRef.h" | 19 #include "llvm/ADT/StringRef.h" |
20 #include "llvm/Support/Compiler.h" | 20 #include "llvm/Support/Compiler.h" |
21 #include "llvm/Support/DataTypes.h" | 21 #include "llvm/Support/DataTypes.h" |
22 #include <string> | 22 #include <string> |
23 #include <vector> | 23 #include <vector> |
24 | 24 |
25 namespace llvm { | 25 namespace llvm { |
26 class StreamableMemoryObject; | 26 class MemoryObject; |
27 | 27 |
28 // Class representing a variable-size metadata field in the bitcode header. | 28 // Class representing a variable-size metadata field in the bitcode header. |
29 // Also contains the list of known (typed) Tag IDs. | 29 // Also contains the list of known (typed) Tag IDs. |
30 // | 30 // |
31 // The serialized format has 2 fixed subfields (ID:type and data length) and the | 31 // The serialized format has 2 fixed subfields (ID:type and data length) and the |
32 // variable-length data subfield | 32 // variable-length data subfield |
33 class NaClBitcodeHeaderField { | 33 class NaClBitcodeHeaderField { |
34 NaClBitcodeHeaderField(const NaClBitcodeHeaderField &) LLVM_DELETED_FUNCTION; | 34 NaClBitcodeHeaderField(const NaClBitcodeHeaderField &) LLVM_DELETED_FUNCTION; |
35 void operator=(const NaClBitcodeHeaderField &)LLVM_DELETED_FUNCTION; | 35 void operator=(const NaClBitcodeHeaderField &)LLVM_DELETED_FUNCTION; |
36 | 36 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 | 68 |
69 /// \brief Number of bytes used to represent header field. | 69 /// \brief Number of bytes used to represent header field. |
70 size_t GetTotalSize() const { | 70 size_t GetTotalSize() const { |
71 // Round up to 4 byte alignment | 71 // Round up to 4 byte alignment |
72 return (kTagLenSize + Len + (WordSize - 1)) & ~(WordSize - 1); | 72 return (kTagLenSize + Len + (WordSize - 1)) & ~(WordSize - 1); |
73 } | 73 } |
74 | 74 |
75 /// \brief Write field into Buf[BufLen]. | 75 /// \brief Write field into Buf[BufLen]. |
76 bool Write(uint8_t *Buf, size_t BufLen) const; | 76 bool Write(uint8_t *Buf, size_t BufLen) const; |
77 | 77 |
78 /// \brief Read field form Buf[BufLen]. | 78 /// \brief Read field from Buf[BufLen]. |
79 bool Read(const uint8_t *Buf, size_t BufLen); | 79 bool Read(const uint8_t *Buf, size_t BufLen); |
80 | 80 |
81 /// \brief Returns string describing field. | 81 /// \brief Returns string describing field. |
82 std::string Contents() const; | 82 std::string Contents() const; |
83 | 83 |
84 /// \brief Get the data size from a serialized field to allow allocation. | 84 /// \brief Get the data size from a serialized field to allow allocation. |
85 static size_t GetDataSizeFromSerialized(const uint8_t *Buf) { | 85 static size_t GetDataSizeFromSerialized(const uint8_t *Buf) { |
86 FixedSubfield Length; | 86 FixedSubfield Length; |
87 ReadFixedSubfield(&Length, Buf + sizeof(FixedSubfield)); | 87 ReadFixedSubfield(&Length, Buf + sizeof(FixedSubfield)); |
88 return Length; | 88 return Length; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 /// 4) NaClBitcodeHeaderField f1 - The first bitcode header field. | 170 /// 4) NaClBitcodeHeaderField f1 - The first bitcode header field. |
171 /// ... | 171 /// ... |
172 /// 2 + num_fields) NaClBitcodeHeaderField fn - The last bitcode header | 172 /// 2 + num_fields) NaClBitcodeHeaderField fn - The last bitcode header |
173 /// field. | 173 /// field. |
174 /// | 174 /// |
175 /// Returns false if able to read (all of) the bitcode header. | 175 /// Returns false if able to read (all of) the bitcode header. |
176 bool Read(const unsigned char *&BufPtr, const unsigned char *&BufEnd); | 176 bool Read(const unsigned char *&BufPtr, const unsigned char *&BufEnd); |
177 | 177 |
178 // \brief Read the PNaCl bitcode header, recording the fields found | 178 // \brief Read the PNaCl bitcode header, recording the fields found |
179 // in the header. Returns false if able to read (all of) the bitcode header. | 179 // in the header. Returns false if able to read (all of) the bitcode header. |
180 bool Read(StreamableMemoryObject *Bytes); | 180 bool Read(MemoryObject *Bytes); |
181 | 181 |
182 // \brief Returns the number of bytes read to consume the header. | 182 // \brief Returns the number of bytes read to consume the header. |
183 size_t getHeaderSize() { return HeaderSize; } | 183 size_t getHeaderSize() { return HeaderSize; } |
184 | 184 |
185 /// \brief Returns string describing why the header describes | 185 /// \brief Returns string describing why the header describes |
186 /// an unsupported PNaCl Bitcode file. | 186 /// an unsupported PNaCl Bitcode file. |
187 const std::string &Unsupported() const { return UnsupportedMessage; } | 187 const std::string &Unsupported() const { return UnsupportedMessage; } |
188 | 188 |
189 /// \brief Returns true if supported. That is, it can be run in the | 189 /// \brief Returns true if supported. That is, it can be run in the |
190 /// browser. | 190 /// browser. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 bool UnsupportedError(StringRef Message) { | 226 bool UnsupportedError(StringRef Message) { |
227 UnsupportedMessage = Message.str(); | 227 UnsupportedMessage = Message.str(); |
228 return true; | 228 return true; |
229 } | 229 } |
230 | 230 |
231 }; | 231 }; |
232 | 232 |
233 } // namespace llvm | 233 } // namespace llvm |
234 | 234 |
235 #endif | 235 #endif |
OLD | NEW |