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

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

Issue 939073008: Rebased PNaCl localmods in LLVM to 223109 (Closed)
Patch Set: Created 5 years, 10 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
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 /// getNaClLazyBitcodeModule - Read the header of the specified bitcode buffer
47 /// and prepare for lazy deserialization of function bodies. If successful,
48 /// takes ownership of 'buffer' and returns a non-null pointer. On
49 /// error, this returns an error code and *does not* take ownership of 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(std::unique_ptr<MemoryBuffer> &&Buf fer,
63 LLVMContext &Context,
64 raw_ostream *Verbose = nullptr,
65 bool AcceptSupportedOnly = true);
66
67 /// getNaClStreamedBitcodeModule - Read the header of the specified stream
68 /// and prepare for lazy deserialization and streaming of function bodies.
69 /// On error, this returns null, and fills in *ErrMsg with an error
70 /// description if ErrMsg is non-null.
71 ///
72 /// See getNaClLazyBitcodeModule for an explanation of arguments
73 /// Verbose, AcceptSupportedOnly.
74 /// TODO(kschimpf): Refactor this and getStreamedBitcodeModule to use
75 /// ErrorOr<Module *> API so that all methods have the same interface.
76 Module *getNaClStreamedBitcodeModule(const std::string &name,
77 StreamingMemoryObject *streamer,
78 LLVMContext &Context,
79 raw_ostream *Verbose = nullptr,
80 std::string *ErrMsg = nullptr,
81 bool AcceptSupportedOnly = true);
82
83 /// NaClParseBitcodeFile - Read the specified bitcode file,
84 /// returning the module.
85 ///
86 /// See getNaClLazyBitcodeModule for an explanation of arguments
87 /// Verbose, AcceptSupportedOnly.
88 ErrorOr<Module *> NaClParseBitcodeFile(MemoryBufferRef Buffer,
89 LLVMContext &Context,
90 raw_ostream *Verbose = nullptr,
91 bool AcceptSupportedOnly = true);
92
93 /// NaClWriteBitcodeToFile - Write the specified module to the
94 /// specified raw output stream, using PNaCl wire format. For
95 /// streams where it matters, the given stream should be in "binary"
96 /// mode.
97 ///
98 /// The AcceptSupportedOnly argument is used to decide which PNaCl versions
99 /// of the PNaCl bitcode to generate. There are two forms:
100 /// 1) Writable and supported.
101 /// 2) Writable and unsupported. Allows testing of code before becoming
102 /// supported, as well as running experiments on the bitcode format.
103 /// When AcceptSupportedOnly is true, only form 1 is allowed. When
104 /// AcceptSupportedOnly is false, forms 1 and 2 are allowed.
105 void NaClWriteBitcodeToFile(const Module *M, raw_ostream &Out,
106 bool AcceptSupportedOnly = true);
107
108 /// isNaClBitcode - Return true if the given bytes are the magic bytes for
109 /// PNaCl bitcode wire format.
110 ///
111 inline bool isNaClBitcode(const unsigned char *BufPtr,
112 const unsigned char *BufEnd) {
113 return BufPtr+4 <= BufEnd &&
114 BufPtr[0] == 'P' &&
115 BufPtr[1] == 'E' &&
116 BufPtr[2] == 'X' &&
117 BufPtr[3] == 'E';
118 }
119
120 /// NaClWriteHeader - Generate a default header (using the version
121 /// number defined by kPNaClVersion) and write to the corresponding
122 /// bitcode stream.
123 void NaClWriteHeader(NaClBitstreamWriter &Stream, bool AcceptSupportedOnly);
124
125 // NaClWriteHeader - Write the contents of the bitcode header to the
126 // corresponding bitcode stream.
127 void NaClWriteHeader(const NaClBitcodeHeader &Header,
128 NaClBitstreamWriter &Stream);
129
130 /// NaClObjDump - Read PNaCl bitcode file from input, and print a
131 /// textual representation of its contents. NoRecords and NoAssembly
132 /// define what should not be included in the dump. Note: The caller
133 /// retains ownership of the Input memory buffer.
134 bool NaClObjDump(MemoryBuffer *Input, raw_ostream &output,
135 bool NoRecords, bool NoAssembly);
136
137 } // end llvm namespace
138 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698