1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
//===-- llvm/Bitcode/NaCl/NaClReaderWriter.h - ------------------*- C++ -*-===//
// NaCl Bitcode reader/writer.
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This header defines interfaces to read and write NaCl bitcode wire format
// files.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_BITCODE_NACL_NACLREADERWRITER_H
#define LLVM_BITCODE_NACL_NACLREADERWRITER_H
#include <string>
namespace llvm {
class MemoryBuffer;
class DataStreamer;
class LLVMContext;
class Module;
class raw_ostream;
/// \brief Defines the integer bit size used to model pointers in PNaCl.
static const unsigned PNaClIntPtrTypeBitSize = 32;
/// getNaClLazyBitcodeModule - Read the header of the specified bitcode buffer
/// and prepare for lazy deserialization of function bodies. If successful,
/// this takes ownership of 'buffer' and returns a non-null pointer. On
/// error, this returns null, *does not* take ownership of Buffer, and fills
/// in *ErrMsg with an error description if ErrMsg is non-null.
///
/// The AcceptSupportedOnly argument is used to decide which PNaCl versions
/// of the PNaCl bitcode to accept. There are three forms:
/// 1) Readable and supported.
/// 2) Readable and unsupported. Allows testing of code before becoming
/// supported, as well as running experiments on the bitcode format.
/// 3) Unreadable.
/// When AcceptSupportedOnly is true, only form 1 is allowed. When
/// AcceptSupportedOnly is false, forms 1 and 2 are allowed.
Module *getNaClLazyBitcodeModule(MemoryBuffer *Buffer,
LLVMContext &Context,
std::string *ErrMsg = 0,
bool AcceptSupportedOnly = true);
/// getNaClStreamedBitcodeModule - Read the header of the specified stream
/// and prepare for lazy deserialization and streaming of function bodies.
/// On error, this returns null, and fills in *ErrMsg with an error
/// description if ErrMsg is non-null.
///
/// See getNaClLazyBitcodeModule for an explanation of argument
/// AcceptSupportedOnly.
Module *getNaClStreamedBitcodeModule(const std::string &name,
DataStreamer *streamer,
LLVMContext &Context,
std::string *ErrMsg = 0,
bool AcceptSupportedOnly = true);
/// NaClParseBitcodeFile - Read the specified bitcode file,
/// returning the module. If an error occurs, this returns null and
/// fills in *ErrMsg if it is non-null. This method *never* takes
/// ownership of Buffer.
///
/// See getNaClLazyBitcodeModule for an explanation of argument
/// AcceptSupportedOnly.
Module *NaClParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext &Context,
std::string *ErrMsg = 0,
bool AcceptSupportedOnly = true);
/// NaClWriteBitcodeToFile - Write the specified module to the
/// specified raw output stream, using PNaCl wire format. For
/// streams where it matters, the given stream should be in "binary"
/// mode.
///
/// The AcceptSupportedOnly argument is used to decide which PNaCl versions
/// of the PNaCl bitcode to generate. There are two forms:
/// 1) Writable and supported.
/// 2) Writable and unsupported. Allows testing of code before becoming
/// supported, as well as running experiments on the bitcode format.
/// When AcceptSupportedOnly is true, only form 1 is allowed. When
/// AcceptSupportedOnly is false, forms 1 and 2 are allowed.
void NaClWriteBitcodeToFile(const Module *M, raw_ostream &Out,
bool AcceptSupportedOnly = true);
/// isNaClBitcode - Return true if the given bytes are the magic bytes for
/// PNaCl bitcode wire format.
///
inline bool isNaClBitcode(const unsigned char *BufPtr,
const unsigned char *BufEnd) {
return BufPtr+4 <= BufEnd &&
BufPtr[0] == 'P' &&
BufPtr[1] == 'E' &&
BufPtr[2] == 'X' &&
BufPtr[3] == 'E';
}
} // end llvm namespace
#endif
|