diff options
author | Karl Schimpf <kschimpf@google.com> | 2013-07-22 13:36:16 -0700 |
---|---|---|
committer | Karl Schimpf <kschimpf@google.com> | 2013-07-22 13:36:16 -0700 |
commit | 0b41f88a8de25db50e1a57645a6e132954a6dcd2 (patch) | |
tree | 059d73d19b2f788ce145d90015dd53b091095f28 /include | |
parent | 208b40ed21d78767d9d1c3c855cbd2e3a3c02451 (diff) |
Enable ability to have multiple PNaCl wire format versions.
Modifies PNaCl bitcode reader/writer to accept PNaClVersion=1 as supported,
and all other versions are unsupported and unreadable. The PNaCl bitcode
reader/writer will generate appropriate messages (including what version
is unsupported if applicable).
Also allows command-line option --pnacl-version for setting the PNaClVersion
in the PNaCl bitcode writer.
Also fixes some problems on PNaCl bitcode headers, using common support to
determine when the read/written PNaCl bitcode file is valid.
BUG=None
R=jvoung@chromium.org
Review URL: https://codereview.chromium.org/19400002
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Bitcode/NaCl/NaClBitcodeHeader.h | 12 | ||||
-rw-r--r-- | include/llvm/Bitcode/NaCl/NaClReaderWriter.h | 26 |
2 files changed, 34 insertions, 4 deletions
diff --git a/include/llvm/Bitcode/NaCl/NaClBitcodeHeader.h b/include/llvm/Bitcode/NaCl/NaClBitcodeHeader.h index 8febf95564..4f5f83a17a 100644 --- a/include/llvm/Bitcode/NaCl/NaClBitcodeHeader.h +++ b/include/llvm/Bitcode/NaCl/NaClBitcodeHeader.h @@ -151,6 +151,12 @@ public: /// is readable and supported. void InstallFields(); + /// \brief Adds a field to the list of fields in a header. Takes ownership + /// of fields added. + void push_back(NaClBitcodeHeaderField *Field) { + Fields.push_back(Field); + } + /// \brief Read the PNaCl bitcode header, The format of the header is: /// /// 1) 'PEXE' - The four character sequence defining the magic number. @@ -172,9 +178,9 @@ public: // \brief Returns the number of bytes read to consume the header. size_t getHeaderSize() { return HeaderSize; } - /// \brief Returns C string describing why the header describes - /// an unsupported PNaCl Bitcode file. Returns 0 if supported. - const std::string Unsupported() const { return UnsupportedMessage; } + /// \brief Returns string describing why the header describes + /// an unsupported PNaCl Bitcode file. + const std::string &Unsupported() const { return UnsupportedMessage; } /// \brief Returns true if supported. That is, it can be run in the /// browser. diff --git a/include/llvm/Bitcode/NaCl/NaClReaderWriter.h b/include/llvm/Bitcode/NaCl/NaClReaderWriter.h index 53feb8ab86..1eb188a83e 100644 --- a/include/llvm/Bitcode/NaCl/NaClReaderWriter.h +++ b/include/llvm/Bitcode/NaCl/NaClReaderWriter.h @@ -30,6 +30,15 @@ namespace llvm { /// 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, @@ -39,6 +48,9 @@ namespace llvm { /// 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, @@ -49,6 +61,9 @@ namespace llvm { /// 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); @@ -57,7 +72,16 @@ namespace llvm { /// specified raw output stream, using PNaCl wire format. For /// streams where it matters, the given stream should be in "binary" /// mode. - void NaClWriteBitcodeToFile(const Module *M, raw_ostream &Out); + /// + /// 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. |