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 #include "llvm/Support/ErrorOr.h" |
| 21 #include "llvm/Support/MemoryBuffer.h" |
21 | 22 |
22 #include <string> | 23 #include <string> |
23 | 24 |
24 namespace llvm { | 25 namespace llvm { |
25 class MemoryBuffer; | |
26 class LLVMContext; | 26 class LLVMContext; |
27 class Module; | 27 class Module; |
28 class raw_ostream; | |
29 class NaClBitcodeHeader; | 28 class NaClBitcodeHeader; |
30 class NaClBitstreamWriter; | 29 class NaClBitstreamWriter; |
31 class StreamingMemoryObject; | 30 class StreamingMemoryObject; |
| 31 class raw_ostream; |
32 | 32 |
33 /// 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 |
34 /// 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 |
35 /// 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 |
36 /// it is run on a pexe. | 36 /// it is run on a pexe. |
37 extern const char *PNaClDataLayout; | 37 extern const char *PNaClDataLayout; |
38 | 38 |
39 /// Allows (function) local symbol tables (unsupported) in PNaCl bitcode | 39 /// Allows (function) local symbol tables (unsupported) in PNaCl bitcode |
40 /// files. | 40 /// files. |
41 extern cl::opt<bool> PNaClAllowLocalSymbolTables; | 41 extern cl::opt<bool> PNaClAllowLocalSymbolTables; |
42 | 42 |
43 /// \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. |
44 static const unsigned PNaClIntPtrTypeBitSize = 32; | 44 static const unsigned PNaClIntPtrTypeBitSize = 32; |
45 | 45 |
46 /// getNaClLazyBitcodeModule - Read the header of the specified bitcode buffer | 46 /// Read the header of the specified bitcode buffer and prepare for lazy |
47 /// and prepare for lazy deserialization of function bodies. If successful, | 47 /// deserialization of function bodies. If successful, this takes ownership |
48 /// takes ownership of 'buffer' and returns a non-null pointer. On | 48 /// of 'Buffer' (extending its lifetime). On error, this returns an error cod
e |
49 /// error, this returns an error code and *does not* take ownership of Buffer. | 49 /// and deletes Buffer. |
50 /// | 50 /// |
51 /// When Verbose is non-null, more descriptive error messages are also | 51 /// When Verbose is non-null, more descriptive error messages are also |
52 /// written to Verbose. | 52 /// written to Verbose. |
53 /// | 53 /// |
54 /// The AcceptSupportedOnly argument is used to decide which PNaCl versions | 54 /// The AcceptSupportedOnly argument is used to decide which PNaCl versions |
55 /// of the PNaCl bitcode to accept. There are three forms: | 55 /// of the PNaCl bitcode to accept. There are three forms: |
56 /// 1) Readable and supported. | 56 /// 1) Readable and supported. |
57 /// 2) Readable and unsupported. Allows testing of code before becoming | 57 /// 2) Readable and unsupported. Allows testing of code before becoming |
58 /// supported, as well as running experiments on the bitcode format. | 58 /// supported, as well as running experiments on the bitcode format. |
59 /// 3) Unreadable. | 59 /// 3) Unreadable. |
60 /// When AcceptSupportedOnly is true, only form 1 is allowed. When | 60 /// When AcceptSupportedOnly is true, only form 1 is allowed. When |
61 /// AcceptSupportedOnly is false, forms 1 and 2 are allowed. | 61 /// AcceptSupportedOnly is false, forms 1 and 2 are allowed. |
62 ErrorOr<Module *> getNaClLazyBitcodeModule(MemoryBuffer *Buffer, | 62 ErrorOr<Module *> getNaClLazyBitcodeModule( |
63 LLVMContext &Context, | 63 std::unique_ptr<MemoryBuffer> &&Buffer, LLVMContext &Context, |
64 raw_ostream *Verbose = nullptr, | 64 raw_ostream *Verbose = nullptr, bool AcceptSupportedOnly = true); |
65 bool AcceptSupportedOnly = true); | |
66 | 65 |
67 /// getNaClStreamedBitcodeModule - Read the header of the specified stream | 66 /// Read the header of the specified stream and prepare for lazy |
68 /// and prepare for lazy deserialization and streaming of function bodies. | 67 /// deserialization and streaming of function bodies. On error, |
69 /// On error, this returns null, and fills in *ErrMsg with an error | 68 /// this returns null, and fills in *ErrMsg with an error description |
70 /// description if ErrMsg is non-null. | 69 /// if ErrMsg is non-null. |
71 /// | 70 /// |
72 /// See getNaClLazyBitcodeModule for an explanation of arguments | 71 /// See getNaClLazyBitcodeModule for an explanation of arguments |
73 /// Verbose, AcceptSupportedOnly. | 72 /// Verbose, AcceptSupportedOnly. |
74 /// TODO(kschimpf): Refactor this and getStreamedBitcodeModule to use | 73 /// TODO(kschimpf): Refactor this and getStreamedBitcodeModule to use |
75 /// ErrorOr<Module *> API so that all methods have the same interface. | 74 /// ErrorOr<Module *> API so that all methods have the same interface. |
76 Module *getNaClStreamedBitcodeModule(const std::string &name, | 75 Module *getNaClStreamedBitcodeModule(const std::string &name, |
77 StreamingMemoryObject *streamer, | 76 StreamingMemoryObject *streamer, |
78 LLVMContext &Context, | 77 LLVMContext &Context, |
79 raw_ostream *Verbose = nullptr, | 78 raw_ostream *Verbose = nullptr, |
80 std::string *ErrMsg = nullptr, | 79 std::string *ErrMsg = nullptr, |
81 bool AcceptSupportedOnly = true); | 80 bool AcceptSupportedOnly = true); |
82 | 81 |
83 /// NaClParseBitcodeFile - Read the specified bitcode file, | 82 /// Read the bitcode file from a buffer, returning the module. |
84 /// returning the module. This method *never* takes ownership of Buffer. | |
85 /// | 83 /// |
86 /// See getNaClLazyBitcodeModule for an explanation of arguments | 84 /// See getNaClLazyBitcodeModule for an explanation of arguments |
87 /// Verbose, AcceptSupportedOnly. | 85 /// Verbose, AcceptSupportedOnly. |
88 ErrorOr<Module *> NaClParseBitcodeFile(MemoryBuffer *Buffer, | 86 ErrorOr<Module *> NaClParseBitcodeFile(MemoryBufferRef Buffer, |
89 LLVMContext &Context, | 87 LLVMContext &Context, |
90 raw_ostream *Verbose = nullptr, | 88 raw_ostream *Verbose = nullptr, |
91 bool AcceptSupportedOnly = true); | 89 bool AcceptSupportedOnly = true); |
92 | 90 |
93 /// NaClWriteBitcodeToFile - Write the specified module to the | 91 /// Write the specified module to the specified raw output stream, using |
94 /// specified raw output stream, using PNaCl wire format. For | 92 /// PNaCl wire format. For streams where it matters, the given stream |
95 /// streams where it matters, the given stream should be in "binary" | 93 /// should be in "binary" mode. |
96 /// mode. | |
97 /// | 94 /// |
98 /// The AcceptSupportedOnly argument is used to decide which PNaCl versions | 95 /// The AcceptSupportedOnly argument is used to decide which PNaCl versions |
99 /// of the PNaCl bitcode to generate. There are two forms: | 96 /// of the PNaCl bitcode to generate. There are two forms: |
100 /// 1) Writable and supported. | 97 /// 1) Writable and supported. |
101 /// 2) Writable and unsupported. Allows testing of code before becoming | 98 /// 2) Writable and unsupported. Allows testing of code before becoming |
102 /// supported, as well as running experiments on the bitcode format. | 99 /// supported, as well as running experiments on the bitcode format. |
103 /// When AcceptSupportedOnly is true, only form 1 is allowed. When | 100 /// When AcceptSupportedOnly is true, only form 1 is allowed. When |
104 /// AcceptSupportedOnly is false, forms 1 and 2 are allowed. | 101 /// AcceptSupportedOnly is false, forms 1 and 2 are allowed. |
105 void NaClWriteBitcodeToFile(const Module *M, raw_ostream &Out, | 102 void NaClWriteBitcodeToFile(const Module *M, raw_ostream &Out, |
106 bool AcceptSupportedOnly = true); | 103 bool AcceptSupportedOnly = true); |
(...skipping 22 matching lines...) Expand all Loading... |
129 | 126 |
130 /// NaClObjDump - Read PNaCl bitcode file from input, and print a | 127 /// NaClObjDump - Read PNaCl bitcode file from input, and print a |
131 /// textual representation of its contents. NoRecords and NoAssembly | 128 /// textual representation of its contents. NoRecords and NoAssembly |
132 /// define what should not be included in the dump. Note: The caller | 129 /// define what should not be included in the dump. Note: The caller |
133 /// retains ownership of the Input memory buffer. | 130 /// retains ownership of the Input memory buffer. |
134 bool NaClObjDump(MemoryBuffer *Input, raw_ostream &output, | 131 bool NaClObjDump(MemoryBuffer *Input, raw_ostream &output, |
135 bool NoRecords, bool NoAssembly); | 132 bool NoRecords, bool NoAssembly); |
136 | 133 |
137 } // end llvm namespace | 134 } // end llvm namespace |
138 #endif | 135 #endif |
OLD | NEW |