diff options
author | Derek Schuff <dschuff@chromium.org> | 2013-10-23 08:35:49 -0700 |
---|---|---|
committer | Derek Schuff <dschuff@chromium.org> | 2013-10-23 08:35:49 -0700 |
commit | 99a581677ff9a785f77e9d9d171b87d61f2da25e (patch) | |
tree | 68028c90a26c775aee1bd2834a4d3ec2953f140e /include | |
parent | 7287c45c13dc887cebe3db6abfa2f1080186bb97 (diff) |
Remove obsolete bitcode wrapper code
We are using our own bitcode reader now, and no longer need this.
R=jvoung@chromium.org, kschimpf@google.com
BUG=cleanup
Review URL: https://codereview.chromium.org/32943005
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Wrap/BCHeaderField.h | 106 | ||||
-rw-r--r-- | include/llvm/Wrap/bitcode_wrapperer.h | 192 | ||||
-rw-r--r-- | include/llvm/Wrap/file_wrapper_input.h | 48 | ||||
-rw-r--r-- | include/llvm/Wrap/file_wrapper_output.h | 34 | ||||
-rw-r--r-- | include/llvm/Wrap/wrapper_input.h | 38 | ||||
-rw-r--r-- | include/llvm/Wrap/wrapper_output.h | 34 |
6 files changed, 0 insertions, 452 deletions
diff --git a/include/llvm/Wrap/BCHeaderField.h b/include/llvm/Wrap/BCHeaderField.h deleted file mode 100644 index 40a3714c9f..0000000000 --- a/include/llvm/Wrap/BCHeaderField.h +++ /dev/null @@ -1,106 +0,0 @@ -/* Copyright 2012 The Native Client Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can - * be found in the LICENSE file. - */ - -#ifndef LLVM_WRAP_BCHEADERFIELD_H -#define LLVM_WRAP_BCHEADERFIELD_H -#include <limits> -#include <stdint.h> -#include <stdio.h> -#include <string.h> - -// Class representing a variable-size metadata field in the bitcode header. -// Also contains the list of known Tag IDs. -// Contains a pointer to the data but does not own the data, so it can be -// copied with the trivial copy constructor/assignment operator. - -// The serialized format has 2 fixed subfields (ID and length) and the -// variable-length data subfield -class BCHeaderField { - public: - typedef enum { - kInvalid = 0, - kBitcodeHash = 1, - kAndroidCompilerVersion = 0x4001, - kAndroidOptimizationLevel = 0x4002 - } Tag; - typedef uint16_t FixedSubfield; - - BCHeaderField(Tag ID, size_t len, uint8_t* data) : - ID_(ID), len_(len), data_(data) {} - size_t GetTotalSize() { - // Round up to 4 byte alignment - return (kTagLenSize + len_ + 3) & ~3; - } - - bool Write(uint8_t* buf, size_t buf_len) { - size_t fields_len = kTagLenSize + len_; - size_t pad_len = (4 - (fields_len & 3)) & 3; - // Ensure buffer is large enough and that length can be represented - // in 16 bits - if (buf_len < fields_len + pad_len || - len_ > std::numeric_limits<FixedSubfield>::max()) return false; - - WriteFixedSubfield(static_cast<FixedSubfield>(ID_), buf); - WriteFixedSubfield(static_cast<FixedSubfield>(len_), - buf + sizeof(FixedSubfield)); - memcpy(buf + kTagLenSize, data_, len_); - // Pad out to 4 byte alignment - if (pad_len) { - memset(buf + fields_len, 0, pad_len); - } - return true; - } - - bool Read(const uint8_t* buf, size_t buf_len) { - if (buf_len < kTagLenSize) return false; - FixedSubfield field; - ReadFixedSubfield(&field, buf); - ID_ = static_cast<Tag>(field); - ReadFixedSubfield(&field, buf + sizeof(FixedSubfield)); - len_ = static_cast<size_t>(field); - if (buf_len < kTagLenSize + len_) return false; - memcpy(data_, buf + kTagLenSize, len_); - return true; - } - - void Print() { - fprintf(stderr, "Field ID: %d, data length %d, total length %d\n", - ID_, static_cast<int>(len_), static_cast<int>(GetTotalSize())); - fprintf(stderr, "Data: "); - for (size_t i = 0; i < len_; i++) fprintf(stderr, "%02x", data_[i]); - fprintf(stderr, "\n"); - } - - // Get the data size from a serialized field to allow allocation - static size_t GetDataSizeFromSerialized(const uint8_t* buf) { - FixedSubfield len; - ReadFixedSubfield(&len, buf + sizeof(FixedSubfield)); - return len; - } - - Tag getID() const { - return ID_; - } - - size_t getLen() const { - return len_; - } - - private: - // Combined size of the fixed subfields - const static size_t kTagLenSize = 2 * sizeof(FixedSubfield); - static void WriteFixedSubfield(FixedSubfield value, uint8_t* buf) { - buf[0] = value & 0xFF; - buf[1] = (value >> 8) & 0xFF; - } - static void ReadFixedSubfield(FixedSubfield* value, const uint8_t* buf) { - *value = buf[0] | buf[1] << 8; - } - Tag ID_; - size_t len_; - uint8_t *data_; -}; - -#endif diff --git a/include/llvm/Wrap/bitcode_wrapperer.h b/include/llvm/Wrap/bitcode_wrapperer.h deleted file mode 100644 index 89f2a4cbcc..0000000000 --- a/include/llvm/Wrap/bitcode_wrapperer.h +++ /dev/null @@ -1,192 +0,0 @@ -/* Copyright 2012 The Native Client Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can - * be found in the LICENSE file. - */ - -// Define utility class to wrap/unwrap bitcode files. Does wrapping/unwrapping -// in such a way that the wrappered bitcode file is still a bitcode file. - -#ifndef LLVM_WRAP_BITCODE_WRAPPERER_H__ -#define LLVM_WRAP_BITCODE_WRAPPERER_H__ - -#include <stdint.h> -#include <stddef.h> -#include <vector> - -#include "llvm/Support/support_macros.h" -#include "llvm/Wrap/BCHeaderField.h" -#include "llvm/Wrap/wrapper_input.h" -#include "llvm/Wrap/wrapper_output.h" - -// The bitcode wrapper header is the following 7 fixed 4-byte fields: -// 1) 0B17C0DE - The magic number expected by llvm for wrapped bitcodes -// 2) Version # 0 - The current version of wrapped bitcode files -// 3) (raw) bitcode offset -// 4) (raw) bitcode size -// 5) Android header version -// 6) Android target API -// 7) PNaCl Bitcode version -// plus 0 or more variable-length fields (consisting of ID, length, data) - -// Initial buffer size. It is expanded if needed to hold large variable-size -// fields. -static const size_t kBitcodeWrappererBufferSize = 1024; - -// Support class for outputting a wrapped bitcode file from a raw bitcode -// file (and optionally additional header fields), or for outputting a raw -// bitcode file from a wrapped one. -class BitcodeWrapperer { - public: - // Create a bitcode wrapperer using the following - // input and output files. - BitcodeWrapperer(WrapperInput* infile, WrapperOutput* outfile); - - // Returns true if the input file begins with a bitcode - // wrapper magic number. As a side effect, _wrapper_ fields are set. - bool IsInputBitcodeWrapper(); - - // Returns true if the input file begins with a bitcode - // file magic number. - bool IsInputBitcodeFile(); - - // Add a variable-length field to the header. The caller is responsible - // for freeing the data pointed to by the BCHeaderField. - void AddHeaderField(BCHeaderField* field); - - // Generate a wrapped bitcode file from the input bitcode file - // and the current header data. Return true on success. - bool GenerateWrappedBitcodeFile(); - - // Unwrap the wrapped bitcode file, to the corresponding - // outfile. Return true on success. - bool GenerateRawBitcodeFile(); - - // Print current wrapper header fields to stderr for debugging. - void PrintWrapperHeader(); - - ~BitcodeWrapperer(); - - private: - DISALLOW_CLASS_COPY_AND_ASSIGN(BitcodeWrapperer); - - // Refills the buffer with more bytes. Does this in a way - // such that it is maximally filled. - void FillBuffer(); - - // Returns the number of bytes in infile. - off_t GetInFileSize() { - if (infile_ != NULL) { - return infile_->Size(); - } else { - return 0; - } - } - - // Returns the offset of bitcode (i.e. the size of the wrapper header) - // if the output file were to be written now. - size_t BitcodeOffset(); - - // Returns true if we can read a word. If necessary, fills the buffer - // with enough characters so that there are at least a 32-bit value - // in the buffer. Returns false if there isn't a 32-bit value - // to read from the input file. - bool CanReadWord(); - - // Read a (32-bit) word from the input. Return true - // if able to read the word. - bool ReadWord(uint32_t& word); - - // Write a (32-bit) word to the output. Return true if successful - bool WriteWord(uint32_t word); - - // Write all variable-sized header fields to the output. Return true - // if successful. - bool WriteVariableFields(); - - // Parse the bitcode wrapper header in the infile, if any. Return true - // if successful. - bool ParseWrapperHeader(); - - // Returns the i-th character in front of the cursor in the buffer. - uint8_t BufferLookahead(int i) { return buffer_[cursor_ + i]; } - - // Returns how many unread bytes are in the buffer. - size_t GetBufferUnreadBytes() { return buffer_size_ - cursor_; } - - - // Backs up the read cursor to the beginning of the input buffer. - void ResetCursor() { - cursor_ = 0; - } - - // Generates the header sequence for the wrapped bitcode being - // generated. - bool WriteBitcodeWrapperHeader(); - - // Copies size bytes of infile to outfile, using the buffer. - bool BufferCopyInToOut(uint32_t size); - - // Discards the old infile and replaces it with the given file. - void ReplaceInFile(WrapperInput* new_infile); - - // Discards the old outfile and replaces it with the given file. - void ReplaceOutFile(WrapperOutput* new_outfile); - - // Moves to the given position in the input file. Returns false - // if unsuccessful. - bool Seek(uint32_t pos); - - // Clear the buffer of all contents. - void ClearBuffer(); - - // The input file being processed. Can be either - // a bitcode file, a wrappered bitcode file, or a secondary - // file to be wrapped. - WrapperInput* infile_; - - // The output file being generated. Can be either - // a bitcode file, a wrappered bitcode file, or a secondary - // unwrapped file. - WrapperOutput* outfile_; - - // A buffer of bytes read from the input file. - std::vector<uint8_t> buffer_; - - // The number of bytes that were read from the input file - // into the buffer. - size_t buffer_size_; - - // The index to the current read point within the buffer. - size_t cursor_; - - // True when eof of input is reached. - bool infile_at_eof_; - - // The 32-bit value defining the offset of the raw bitcode in the input file. - uint32_t infile_bc_offset_; - - // The 32-bit value defining the generated offset of the wrapped bitcode. - // This value changes as new fields are added with AddHeaderField - uint32_t wrapper_bc_offset_; - - // The 32-bit value defining the size of the raw wrapped bitcode. - uint32_t wrapper_bc_size_; - - // Android header version and target API - uint32_t android_header_version_; - uint32_t android_target_api_; - - // PNaCl bitcode version - uint32_t pnacl_bc_version_; - - // Vector of variable header fields - std::vector<BCHeaderField> header_fields_; - // If any bufferdata from header fields is owned, it is stored here and - // freed on destruction. - std::vector<uint8_t*> variable_field_data_; - - // True if there was an error condition (e.g. the file is not bitcode) - bool error_; -}; - -#endif // LLVM_WRAP_BITCODE_WRAPPERER_H__ diff --git a/include/llvm/Wrap/file_wrapper_input.h b/include/llvm/Wrap/file_wrapper_input.h deleted file mode 100644 index 9f3de004c4..0000000000 --- a/include/llvm/Wrap/file_wrapper_input.h +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright 2012 The Native Client Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can - * be found in the LICENSE file. - */ - -// Defines utility allowing files for bitcode input wrapping. - -#ifndef FILE_WRAPPER_INPUT_H__ -#define FILE_WRAPPER_INPUT_H__ - -#include "llvm/Support/support_macros.h" -#include "llvm/Wrap/wrapper_input.h" - -#include <stdio.h> -#include <string> - -// Define a class to wrap named files. -class FileWrapperInput : public WrapperInput { - public: - FileWrapperInput(const std::string& name); - ~FileWrapperInput(); - // Tries to read the requested number of bytes into the buffer. Returns the - // actual number of bytes read. - virtual size_t Read(uint8_t* buffer, size_t wanted); - // Returns true if at end of file. Note: May return false - // until Read is called, and returns 0. - virtual bool AtEof(); - // Returns the size of the file (in bytes). - virtual off_t Size(); - // Moves to the given offset within the file. Returns - // false if unable to move to that position. - virtual bool Seek(uint32_t pos); - private: - // The name of the file. - std::string _name; - // True once eof has been encountered. - bool _at_eof; - // True if size has been computed. - bool _size_found; - // The size of the file. - off_t _size; - // The corresponding (opened) file. - FILE* _file; - private: - DISALLOW_CLASS_COPY_AND_ASSIGN(FileWrapperInput); -}; - -#endif // FILE_WRAPPER_INPUT_H__ diff --git a/include/llvm/Wrap/file_wrapper_output.h b/include/llvm/Wrap/file_wrapper_output.h deleted file mode 100644 index 714bd36a75..0000000000 --- a/include/llvm/Wrap/file_wrapper_output.h +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright 2012 The Native Client Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can - * be found in the LICENSE file. - */ - -// Defines utility allowing files for bitcode output wrapping. - -#ifndef FILE_WRAPPER_OUTPUT_H__ -#define FILE_WRAPPER_OUTPUT_H__ - -#include "llvm/Support/support_macros.h" -#include "llvm/Wrap/wrapper_output.h" -#include <stdio.h> -#include <string> - -// Define a class to wrap named files. */ -class FileWrapperOutput : public WrapperOutput { - public: - FileWrapperOutput(const std::string& name); - ~FileWrapperOutput(); - // Writes a single byte, returning false if unable to write. - virtual bool Write(uint8_t byte); - // Writes the specified number of bytes in the buffer to - // output. Returns false if unable to write. - virtual bool Write(const uint8_t* buffer, size_t buffer_size); - private: - // The name of the file - std::string _name; - // The corresponding (opened) file. - FILE* _file; - private: - DISALLOW_CLASS_COPY_AND_ASSIGN(FileWrapperOutput); -}; -#endif // FILE_WRAPPER_OUTPUT_H__ diff --git a/include/llvm/Wrap/wrapper_input.h b/include/llvm/Wrap/wrapper_input.h deleted file mode 100644 index cde918083a..0000000000 --- a/include/llvm/Wrap/wrapper_input.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright 2012 The Native Client Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can - * be found in the LICENSE file. - */ - -// Define a generic interface to a file/memory region that contains -// a bitcode file, a wrapped bitcode file, or a data file to wrap. - -#ifndef LLVM_WRAP_WRAPPER_INPUT_H__ -#define LLVM_WRAP_WRAPPER_INPUT_H__ - -#include <stdint.h> -#include <sys/types.h> - -#include "llvm/Support/support_macros.h" - -// The following is a generic interface to a file/memory region that contains -// a bitcode file, a wrapped bitcode file, or data file to wrap. -class WrapperInput { - public: - WrapperInput() {} - virtual ~WrapperInput() {} - // Tries to read the requested number of bytes into the buffer. Returns the - // actual number of bytes read. - virtual size_t Read(uint8_t* buffer, size_t wanted) = 0; - // Returns true if at end of input. Note: May return false until - // Read is called, and returns 0. - virtual bool AtEof() = 0; - // Returns the size of the input (in bytes). - virtual off_t Size() = 0; - // Moves to the given offset within the input region. Returns false - // if unable to move to that position. - virtual bool Seek(uint32_t pos) = 0; - private: - DISALLOW_CLASS_COPY_AND_ASSIGN(WrapperInput); -}; - -#endif // LLVM_WRAP_WRAPPER_INPUT_H__ diff --git a/include/llvm/Wrap/wrapper_output.h b/include/llvm/Wrap/wrapper_output.h deleted file mode 100644 index 7045705991..0000000000 --- a/include/llvm/Wrap/wrapper_output.h +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright 2012 The Native Client Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can - * be found in the LICENSE file. - */ - -// Defines a generic interface to a file/memory region that -// contains a generated wrapped bitcode file, bitcode file, -// or data file. - -#ifndef LLVM_WRAP_WRAPPER_OUTPUT_H__ -#define LLVM_WRAP_WRAPPER_OUTPUT_H__ - -#include <stdint.h> -#include <stddef.h> - -#include "llvm/Support/support_macros.h" - -// The following is a generic interface to a file/memory region -// that contains a generated bitcode file, wrapped bitcode file, -// or a data file. -class WrapperOutput { - public: - WrapperOutput() {} - virtual ~WrapperOutput() {} - // Writes a single byte, returning false if unable to write. - virtual bool Write(uint8_t byte) = 0; - // Writes the specified number of bytes in the buffer to - // output. Returns false if unable to write. - virtual bool Write(const uint8_t* buffer, size_t buffer_size); - private: - DISALLOW_CLASS_COPY_AND_ASSIGN(WrapperOutput); -}; - -#endif // LLVM_WRAP_WRAPPER_OUTPUT_H__ |