Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: include/llvm/Bitcode/NaCl/NaClReaderWriter.h

Issue 939073008: Rebased PNaCl localmods in LLVM to 223109 (Closed)
Patch Set: undo localmod Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/llvm/Bitcode/NaCl/NaClObjDumpStream.h ('k') | include/llvm/Bitcode/ReaderWriter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 //===-- llvm/Bitcode/NaCl/NaClReaderWriter.h - ------------------*- C++ -*-===//
2 // NaCl Bitcode reader/writer.
3 //
4 // The LLVM Compiler Infrastructure
5 //
6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 //
11 // This header defines interfaces to read and write NaCl bitcode wire format
12 // files.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef LLVM_BITCODE_NACL_NACLREADERWRITER_H
17 #define LLVM_BITCODE_NACL_NACLREADERWRITER_H
18
19 #include "llvm/Support/CommandLine.h"
20 #include "llvm/Support/ErrorOr.h"
21 #include "llvm/Support/MemoryBuffer.h"
22
23 #include <string>
24
25 namespace llvm {
26 class LLVMContext;
27 class Module;
28 class NaClBitcodeHeader;
29 class NaClBitstreamWriter;
30 class StreamingMemoryObject;
31 class raw_ostream;
32
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
35 /// pnacl-llc so that 'opt' will also use the correct data layout if
36 /// it is run on a pexe.
37 extern const char *PNaClDataLayout;
38
39 /// Allows (function) local symbol tables (unsupported) in PNaCl bitcode
40 /// files.
41 extern cl::opt<bool> PNaClAllowLocalSymbolTables;
42
43 /// \brief Defines the integer bit size used to model pointers in PNaCl.
44 static const unsigned PNaClIntPtrTypeBitSize = 32;
45
46 /// Read the header of the specified bitcode buffer and prepare for lazy
47 /// deserialization of function bodies. If successful, this takes ownership
48 /// of 'Buffer' (extending its lifetime). On error, this returns an error cod e
49 /// and deletes Buffer.
50 ///
51 /// When Verbose is non-null, more descriptive error messages are also
52 /// written to Verbose.
53 ///
54 /// The AcceptSupportedOnly argument is used to decide which PNaCl versions
55 /// of the PNaCl bitcode to accept. There are three forms:
56 /// 1) Readable and supported.
57 /// 2) Readable and unsupported. Allows testing of code before becoming
58 /// supported, as well as running experiments on the bitcode format.
59 /// 3) Unreadable.
60 /// When AcceptSupportedOnly is true, only form 1 is allowed. When
61 /// AcceptSupportedOnly is false, forms 1 and 2 are allowed.
62 ErrorOr<Module *> getNaClLazyBitcodeModule(
63 std::unique_ptr<MemoryBuffer> &&Buffer, LLVMContext &Context,
64 raw_ostream *Verbose = nullptr, bool AcceptSupportedOnly = true);
65
66 /// Read the header of the specified stream and prepare for lazy
67 /// deserialization and streaming of function bodies. On error,
68 /// this returns null, and fills in *ErrMsg with an error description
69 /// if ErrMsg is non-null.
70 ///
71 /// See getNaClLazyBitcodeModule for an explanation of arguments
72 /// Verbose, AcceptSupportedOnly.
73 /// TODO(kschimpf): Refactor this and getStreamedBitcodeModule to use
74 /// ErrorOr<Module *> API so that all methods have the same interface.
75 Module *getNaClStreamedBitcodeModule(const std::string &name,
76 StreamingMemoryObject *streamer,
77 LLVMContext &Context,
78 raw_ostream *Verbose = nullptr,
79 std::string *ErrMsg = nullptr,
80 bool AcceptSupportedOnly = true);
81
82 /// Read the bitcode file from a buffer, returning the module.
83 ///
84 /// See getNaClLazyBitcodeModule for an explanation of arguments
85 /// Verbose, AcceptSupportedOnly.
86 ErrorOr<Module *> NaClParseBitcodeFile(MemoryBufferRef Buffer,
87 LLVMContext &Context,
88 raw_ostream *Verbose = nullptr,
89 bool AcceptSupportedOnly = true);
90
91 /// Write the specified module to the specified raw output stream, using
92 /// PNaCl wire format. For streams where it matters, the given stream
93 /// should be in "binary" mode.
94 ///
95 /// The AcceptSupportedOnly argument is used to decide which PNaCl versions
96 /// of the PNaCl bitcode to generate. There are two forms:
97 /// 1) Writable and supported.
98 /// 2) Writable and unsupported. Allows testing of code before becoming
99 /// supported, as well as running experiments on the bitcode format.
100 /// When AcceptSupportedOnly is true, only form 1 is allowed. When
101 /// AcceptSupportedOnly is false, forms 1 and 2 are allowed.
102 void NaClWriteBitcodeToFile(const Module *M, raw_ostream &Out,
103 bool AcceptSupportedOnly = true);
104
105 /// isNaClBitcode - Return true if the given bytes are the magic bytes for
106 /// PNaCl bitcode wire format.
107 ///
108 inline bool isNaClBitcode(const unsigned char *BufPtr,
109 const unsigned char *BufEnd) {
110 return BufPtr+4 <= BufEnd &&
111 BufPtr[0] == 'P' &&
112 BufPtr[1] == 'E' &&
113 BufPtr[2] == 'X' &&
114 BufPtr[3] == 'E';
115 }
116
117 /// NaClWriteHeader - Generate a default header (using the version
118 /// number defined by kPNaClVersion) and write to the corresponding
119 /// bitcode stream.
120 void NaClWriteHeader(NaClBitstreamWriter &Stream, bool AcceptSupportedOnly);
121
122 // NaClWriteHeader - Write the contents of the bitcode header to the
123 // corresponding bitcode stream.
124 void NaClWriteHeader(const NaClBitcodeHeader &Header,
125 NaClBitstreamWriter &Stream);
126
127 /// NaClObjDump - Read PNaCl bitcode file from input, and print a
128 /// textual representation of its contents. NoRecords and NoAssembly
129 /// define what should not be included in the dump. Note: The caller
130 /// retains ownership of the Input memory buffer.
131 bool NaClObjDump(MemoryBuffer *Input, raw_ostream &output,
132 bool NoRecords, bool NoAssembly);
133
134 } // end llvm namespace
135 #endif
OLDNEW
« no previous file with comments | « include/llvm/Bitcode/NaCl/NaClObjDumpStream.h ('k') | include/llvm/Bitcode/ReaderWriter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698