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

Unified Diff: include/llvm/Bitcode/NaCl/NaClReaderWriter.h

Issue 939073008: Rebased PNaCl localmods in LLVM to 223109 (Closed)
Patch Set: undo localmod 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/llvm/Bitcode/NaCl/NaClReaderWriter.h
diff --git a/include/llvm/Bitcode/NaCl/NaClReaderWriter.h b/include/llvm/Bitcode/NaCl/NaClReaderWriter.h
new file mode 100644
index 0000000000000000000000000000000000000000..eb3a23f3cc1d61c348442c4f1283006607286b4e
--- /dev/null
+++ b/include/llvm/Bitcode/NaCl/NaClReaderWriter.h
@@ -0,0 +1,135 @@
+//===-- 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 "llvm/Support/CommandLine.h"
+#include "llvm/Support/ErrorOr.h"
+#include "llvm/Support/MemoryBuffer.h"
+
+#include <string>
+
+namespace llvm {
+ class LLVMContext;
+ class Module;
+ class NaClBitcodeHeader;
+ class NaClBitstreamWriter;
+ class StreamingMemoryObject;
+ class raw_ostream;
+
+ /// Defines the data layout used for PNaCl bitcode files. We set the
+ /// data layout of the module in the bitcode readers rather than in
+ /// pnacl-llc so that 'opt' will also use the correct data layout if
+ /// it is run on a pexe.
+ extern const char *PNaClDataLayout;
+
+ /// Allows (function) local symbol tables (unsupported) in PNaCl bitcode
+ /// files.
+ extern cl::opt<bool> PNaClAllowLocalSymbolTables;
+
+ /// \brief Defines the integer bit size used to model pointers in PNaCl.
+ static const unsigned PNaClIntPtrTypeBitSize = 32;
+
+ /// Read the header of the specified bitcode buffer and prepare for lazy
+ /// deserialization of function bodies. If successful, this takes ownership
+ /// of 'Buffer' (extending its lifetime). On error, this returns an error code
+ /// and deletes Buffer.
+ ///
+ /// When Verbose is non-null, more descriptive error messages are also
+ /// written to Verbose.
+ ///
+ /// 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.
+ ErrorOr<Module *> getNaClLazyBitcodeModule(
+ std::unique_ptr<MemoryBuffer> &&Buffer, LLVMContext &Context,
+ raw_ostream *Verbose = nullptr, bool AcceptSupportedOnly = true);
+
+ /// 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 arguments
+ /// Verbose, AcceptSupportedOnly.
+ /// TODO(kschimpf): Refactor this and getStreamedBitcodeModule to use
+ /// ErrorOr<Module *> API so that all methods have the same interface.
+ Module *getNaClStreamedBitcodeModule(const std::string &name,
+ StreamingMemoryObject *streamer,
+ LLVMContext &Context,
+ raw_ostream *Verbose = nullptr,
+ std::string *ErrMsg = nullptr,
+ bool AcceptSupportedOnly = true);
+
+ /// Read the bitcode file from a buffer, returning the module.
+ ///
+ /// See getNaClLazyBitcodeModule for an explanation of arguments
+ /// Verbose, AcceptSupportedOnly.
+ ErrorOr<Module *> NaClParseBitcodeFile(MemoryBufferRef Buffer,
+ LLVMContext &Context,
+ raw_ostream *Verbose = nullptr,
+ bool AcceptSupportedOnly = true);
+
+ /// 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';
+ }
+
+ /// NaClWriteHeader - Generate a default header (using the version
+ /// number defined by kPNaClVersion) and write to the corresponding
+ /// bitcode stream.
+ void NaClWriteHeader(NaClBitstreamWriter &Stream, bool AcceptSupportedOnly);
+
+ // NaClWriteHeader - Write the contents of the bitcode header to the
+ // corresponding bitcode stream.
+ void NaClWriteHeader(const NaClBitcodeHeader &Header,
+ NaClBitstreamWriter &Stream);
+
+ /// NaClObjDump - Read PNaCl bitcode file from input, and print a
+ /// textual representation of its contents. NoRecords and NoAssembly
+ /// define what should not be included in the dump. Note: The caller
+ /// retains ownership of the Input memory buffer.
+ bool NaClObjDump(MemoryBuffer *Input, raw_ostream &output,
+ bool NoRecords, bool NoAssembly);
+
+} // end llvm namespace
+#endif
« 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