OLD | NEW |
---|---|
1 //===-- llvm/Bitcode/NaCl/NaClReaderWriter.h - ------------------*- C++ -*-===// | 1 //===-- llvm/Bitcode/NaCl/NaClReaderWriter.h - ------------------*- C++ -*-===// |
2 // NaCl Bitcode reader/writer. | 2 // NaCl Bitcode reader/writer. |
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 // files. | 12 // files. |
13 // | 13 // |
14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
15 | 15 |
16 #ifndef LLVM_BITCODE_NACL_NACLREADERWRITER_H | 16 #ifndef LLVM_BITCODE_NACL_NACLREADERWRITER_H |
17 #define LLVM_BITCODE_NACL_NACLREADERWRITER_H | 17 #define LLVM_BITCODE_NACL_NACLREADERWRITER_H |
18 | 18 |
19 #include "llvm/Support/CommandLine.h" | 19 #include "llvm/Support/CommandLine.h" |
20 #include "llvm/Support/ErrorOr.h" | |
20 | 21 |
21 #include <string> | 22 #include <string> |
22 | 23 |
23 namespace llvm { | 24 namespace llvm { |
24 class MemoryBuffer; | 25 class MemoryBuffer; |
25 class LLVMContext; | 26 class LLVMContext; |
26 class Module; | 27 class Module; |
27 class raw_ostream; | 28 class raw_ostream; |
28 class NaClBitcodeHeader; | 29 class NaClBitcodeHeader; |
29 class NaClBitstreamWriter; | 30 class NaClBitstreamWriter; |
30 class StreamingMemoryObject; | 31 class StreamingMemoryObject; |
31 | 32 |
32 /// Defines the data layout used for PNaCl bitcode files. We set the | 33 /// Defines the data layout used for PNaCl bitcode files. We set the |
33 /// data layout of the module in the bitcode readers rather than in | 34 /// data layout of the module in the bitcode readers rather than in |
34 /// pnacl-llc so that 'opt' will also use the correct data layout if | 35 /// pnacl-llc so that 'opt' will also use the correct data layout if |
35 /// it is run on a pexe. | 36 /// it is run on a pexe. |
36 extern const char *PNaClDataLayout; | 37 extern const char *PNaClDataLayout; |
37 | 38 |
38 /// Allows (function) local symbol tables (unsupported) in PNaCl bitcode | 39 /// Allows (function) local symbol tables (unsupported) in PNaCl bitcode |
39 /// files. | 40 /// files. |
40 extern cl::opt<bool> PNaClAllowLocalSymbolTables; | 41 extern cl::opt<bool> PNaClAllowLocalSymbolTables; |
41 | 42 |
42 /// \brief Defines the integer bit size used to model pointers in PNaCl. | 43 /// \brief Defines the integer bit size used to model pointers in PNaCl. |
43 static const unsigned PNaClIntPtrTypeBitSize = 32; | 44 static const unsigned PNaClIntPtrTypeBitSize = 32; |
44 | 45 |
45 /// getNaClLazyBitcodeModule - Read the header of the specified bitcode buffer | 46 /// getNaClLazyBitcodeModule - Read the header of the specified bitcode buffer |
46 /// and prepare for lazy deserialization of function bodies. If successful, | 47 /// and prepare for lazy deserialization of function bodies. If successful, |
47 /// this takes ownership of 'buffer' and returns a non-null pointer. On | 48 /// this takes ownership of 'buffer' and returns a non-null pointer. On |
48 /// error, this returns null, *does not* take ownership of Buffer, and fills | 49 /// error, this returns an error code and *does not* take ownership of Buffer. |
49 /// in *ErrMsg with an error description if ErrMsg is non-null. | 50 /// |
51 /// When VerboseErrors is true, more descriptive error messages are also | |
52 /// written to errs(). | |
50 /// | 53 /// |
51 /// The AcceptSupportedOnly argument is used to decide which PNaCl versions | 54 /// The AcceptSupportedOnly argument is used to decide which PNaCl versions |
52 /// of the PNaCl bitcode to accept. There are three forms: | 55 /// of the PNaCl bitcode to accept. There are three forms: |
53 /// 1) Readable and supported. | 56 /// 1) Readable and supported. |
54 /// 2) Readable and unsupported. Allows testing of code before becoming | 57 /// 2) Readable and unsupported. Allows testing of code before becoming |
55 /// supported, as well as running experiments on the bitcode format. | 58 /// supported, as well as running experiments on the bitcode format. |
56 /// 3) Unreadable. | 59 /// 3) Unreadable. |
57 /// When AcceptSupportedOnly is true, only form 1 is allowed. When | 60 /// When AcceptSupportedOnly is true, only form 1 is allowed. When |
58 /// AcceptSupportedOnly is false, forms 1 and 2 are allowed. | 61 /// AcceptSupportedOnly is false, forms 1 and 2 are allowed. |
59 Module *getNaClLazyBitcodeModule(MemoryBuffer *Buffer, | 62 ErrorOr<Module *> getNaClLazyBitcodeModule(MemoryBuffer *Buffer, |
60 LLVMContext &Context, | 63 LLVMContext &Context, |
61 std::string *ErrMsg = 0, | 64 bool VerboseErrors = false, |
62 bool AcceptSupportedOnly = true); | 65 bool AcceptSupportedOnly = true); |
63 | 66 |
64 /// getNaClStreamedBitcodeModule - Read the header of the specified stream | 67 /// getNaClStreamedBitcodeModule - Read the header of the specified stream |
65 /// and prepare for lazy deserialization and streaming of function bodies. | 68 /// and prepare for lazy deserialization and streaming of function bodies. |
66 /// On error, this returns null, and fills in *ErrMsg with an error | 69 /// On error, this returns null, and fills in *ErrMsg with an error |
67 /// description if ErrMsg is non-null. | 70 /// description if ErrMsg is non-null. |
68 /// | 71 /// |
69 /// See getNaClLazyBitcodeModule for an explanation of argument | 72 /// See getNaClLazyBitcodeModule for an explanation of arguments |
70 /// AcceptSupportedOnly. | 73 /// VerboseErrors, AcceptSupportedOnly. |
71 Module *getNaClStreamedBitcodeModule(const std::string &name, | 74 Module *getNaClStreamedBitcodeModule(const std::string &name, |
jvoung (off chromium)
2014/12/01 23:23:49
Interesting... Didn't realize that upstream this i
Karl
2014/12/03 18:32:09
I noticed it too. However, since it wasn't changed
| |
72 StreamingMemoryObject *streamer, | 75 StreamingMemoryObject *streamer, |
73 LLVMContext &Context, | 76 LLVMContext &Context, |
77 bool VerboseErrors = false, | |
74 std::string *ErrMsg = 0, | 78 std::string *ErrMsg = 0, |
jvoung (off chromium)
2014/12/01 23:23:49
nullptr
Karl
2014/12/03 18:32:09
Done.
| |
75 bool AcceptSupportedOnly = true); | 79 bool AcceptSupportedOnly = true); |
76 | 80 |
77 /// NaClParseBitcodeFile - Read the specified bitcode file, | 81 /// NaClParseBitcodeFile - Read the specified bitcode file, |
78 /// returning the module. If an error occurs, this returns null and | 82 /// returning the module. If an error_code if error occurs. This |
JF
2014/12/02 00:49:03
This line doesn't make sense.
Karl
2014/12/03 18:32:09
Cleaned this up.
| |
79 /// fills in *ErrMsg if it is non-null. This method *never* takes | 83 /// method *never* takes ownership of Buffer. |
80 /// ownership of Buffer. | |
81 /// | 84 /// |
82 /// See getNaClLazyBitcodeModule for an explanation of argument | 85 /// See getNaClLazyBitcodeModule for an explanation of arguments |
83 /// AcceptSupportedOnly. | 86 /// VerboseErrors, AcceptSupportedOnly. |
84 Module *NaClParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext &Context, | 87 ErrorOr<Module *> NaClParseBitcodeFile(MemoryBuffer *Buffer, |
85 std::string *ErrMsg = 0, | 88 LLVMContext &Context, |
86 bool AcceptSupportedOnly = true); | 89 bool VerboseErrors = false, |
90 bool AcceptSupportedOnly = true); | |
87 | 91 |
88 /// NaClWriteBitcodeToFile - Write the specified module to the | 92 /// NaClWriteBitcodeToFile - Write the specified module to the |
89 /// specified raw output stream, using PNaCl wire format. For | 93 /// specified raw output stream, using PNaCl wire format. For |
90 /// streams where it matters, the given stream should be in "binary" | 94 /// streams where it matters, the given stream should be in "binary" |
91 /// mode. | 95 /// mode. |
92 /// | 96 /// |
93 /// The AcceptSupportedOnly argument is used to decide which PNaCl versions | 97 /// See getNaClLazyBitcodeModule for an explanation of arguments |
94 /// of the PNaCl bitcode to generate. There are two forms: | 98 /// VerboseErrors, AcceptSupportedOnly. |
JF
2014/12/02 00:49:03
This method doesn't have a VerboseErrors argument.
Karl
2014/12/03 18:32:09
Good point. Incorrectly changed comment to write r
| |
95 /// 1) Writable and supported. | |
96 /// 2) Writable and unsupported. Allows testing of code before becoming | |
97 /// supported, as well as running experiments on the bitcode format. | |
98 /// When AcceptSupportedOnly is true, only form 1 is allowed. When | |
99 /// AcceptSupportedOnly is false, forms 1 and 2 are allowed. | |
100 void NaClWriteBitcodeToFile(const Module *M, raw_ostream &Out, | 99 void NaClWriteBitcodeToFile(const Module *M, raw_ostream &Out, |
101 bool AcceptSupportedOnly = true); | 100 bool AcceptSupportedOnly = true); |
102 | 101 |
103 /// isNaClBitcode - Return true if the given bytes are the magic bytes for | 102 /// isNaClBitcode - Return true if the given bytes are the magic bytes for |
104 /// PNaCl bitcode wire format. | 103 /// PNaCl bitcode wire format. |
105 /// | 104 /// |
106 inline bool isNaClBitcode(const unsigned char *BufPtr, | 105 inline bool isNaClBitcode(const unsigned char *BufPtr, |
107 const unsigned char *BufEnd) { | 106 const unsigned char *BufEnd) { |
108 return BufPtr+4 <= BufEnd && | 107 return BufPtr+4 <= BufEnd && |
109 BufPtr[0] == 'P' && | 108 BufPtr[0] == 'P' && |
(...skipping 14 matching lines...) Expand all Loading... | |
124 | 123 |
125 /// NaClObjDump - Read PNaCl bitcode file from input, and print a | 124 /// NaClObjDump - Read PNaCl bitcode file from input, and print a |
126 /// textual representation of its contents. NoRecords and NoAssembly | 125 /// textual representation of its contents. NoRecords and NoAssembly |
127 /// define what should not be included in the dump. Note: The caller | 126 /// define what should not be included in the dump. Note: The caller |
128 /// retains ownership of the Input memory buffer. | 127 /// retains ownership of the Input memory buffer. |
129 bool NaClObjDump(MemoryBuffer *Input, raw_ostream &output, | 128 bool NaClObjDump(MemoryBuffer *Input, raw_ostream &output, |
130 bool NoRecords, bool NoAssembly); | 129 bool NoRecords, bool NoAssembly); |
131 | 130 |
132 } // end llvm namespace | 131 } // end llvm namespace |
133 #endif | 132 #endif |
OLD | NEW |