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/Support/Compiler.h" | 20 #include "llvm/Support/Compiler.h" |
20 #include "llvm/Support/DataTypes.h" | 21 #include "llvm/Support/DataTypes.h" |
21 #include <string> | 22 #include <string> |
22 #include <vector> | 23 #include <vector> |
23 | 24 |
24 namespace llvm { | 25 namespace llvm { |
25 class StreamableMemoryObject; | 26 class StreamableMemoryObject; |
26 | 27 |
27 // Class representing a variable-size metadata field in the bitcode header. | 28 // Class representing a variable-size metadata field in the bitcode header. |
28 // Also contains the list of known (typed) Tag IDs. | 29 // Also contains the list of known (typed) Tag IDs. |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 // Defines the PNaCl version defined by the header file. | 142 // Defines the PNaCl version defined by the header file. |
142 uint32_t PNaClVersion; | 143 uint32_t PNaClVersion; |
143 | 144 |
144 public: | 145 public: |
145 static const int WordSize = NaClBitcodeHeaderField::WordSize; | 146 static const int WordSize = NaClBitcodeHeaderField::WordSize; |
146 | 147 |
147 NaClBitcodeHeader(); | 148 NaClBitcodeHeader(); |
148 ~NaClBitcodeHeader(); | 149 ~NaClBitcodeHeader(); |
149 | 150 |
150 /// \brief Installs the fields of the header, defining if the header | 151 /// \brief Installs the fields of the header, defining if the header |
151 /// is readable and supported. | 152 /// is readable and supported. Sets UnsupportedMessage on failure. |
152 void InstallFields(); | 153 void InstallFields(); |
153 | 154 |
154 /// \brief Adds a field to the list of fields in a header. Takes ownership | 155 /// \brief Adds a field to the list of fields in a header. Takes ownership |
155 /// of fields added. | 156 /// of fields added. |
156 void push_back(NaClBitcodeHeaderField *Field) { | 157 void push_back(NaClBitcodeHeaderField *Field) { |
157 Fields.push_back(Field); | 158 Fields.push_back(Field); |
158 } | 159 } |
159 | 160 |
160 /// \brief Read the PNaCl bitcode header, The format of the header is: | 161 /// \brief Read the PNaCl bitcode header, The format of the header is: |
161 /// | 162 /// |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 /// (0 if no such field). | 203 /// (0 if no such field). |
203 NaClBitcodeHeaderField *GetField(size_t index) const; | 204 NaClBitcodeHeaderField *GetField(size_t index) const; |
204 | 205 |
205 /// \brief Returns the PNaClVersion, as defined by the header. | 206 /// \brief Returns the PNaClVersion, as defined by the header. |
206 uint32_t GetPNaClVersion() const { return PNaClVersion; } | 207 uint32_t GetPNaClVersion() const { return PNaClVersion; } |
207 | 208 |
208 private: | 209 private: |
209 // Reads and verifies the first 8 bytes of the header, consisting | 210 // Reads and verifies the first 8 bytes of the header, consisting |
210 // of the magic number 'PEXE', and the value defining the number | 211 // of the magic number 'PEXE', and the value defining the number |
211 // of fields and number of bytes used to hold fields. | 212 // of fields and number of bytes used to hold fields. |
212 // Returns false if successful. | 213 // Returns false if successful, sets UnsupportedMessage otherwise. |
213 bool ReadPrefix(const unsigned char *BufPtr, const unsigned char *BufEnd, | 214 bool ReadPrefix(const unsigned char *BufPtr, const unsigned char *BufEnd, |
214 unsigned &NumFields, unsigned &NumBytes); | 215 unsigned &NumFields, unsigned &NumBytes); |
215 | 216 |
216 // Reads and verifies the fields in the header. | 217 // Reads and verifies the fields in the header. |
217 // Returns false if successful. | 218 // Returns false if successful, sets UnsupportedMessage otherwise. |
218 bool ReadFields(const unsigned char *BufPtr, const unsigned char *BufEnd, | 219 bool ReadFields(const unsigned char *BufPtr, const unsigned char *BufEnd, |
219 unsigned NumFields, unsigned NumBytes); | 220 unsigned NumFields, unsigned NumBytes); |
220 | 221 |
| 222 // Sets the Unsupported error message and returns true. |
| 223 bool UnsupportedError(StringRef Message) { |
| 224 UnsupportedMessage = Message.str(); |
| 225 return true; |
| 226 } |
| 227 |
221 }; | 228 }; |
222 | 229 |
223 } // namespace llvm | 230 } // namespace llvm |
224 | 231 |
225 #endif | 232 #endif |
OLD | NEW |