Index: include/llvm/Bitcode/NaCl/NaClBitcodeMungeUtils.h |
diff --git a/include/llvm/Bitcode/NaCl/NaClBitcodeMungeUtils.h b/include/llvm/Bitcode/NaCl/NaClBitcodeMungeUtils.h |
index 6f8a05a8f29aa93f8dec5e1c796b8b8f2c8f148d..21dfb95e575bef2697c497a7df643b4a9f17f39d 100644 |
--- a/include/llvm/Bitcode/NaCl/NaClBitcodeMungeUtils.h |
+++ b/include/llvm/Bitcode/NaCl/NaClBitcodeMungeUtils.h |
@@ -81,6 +81,7 @@ |
namespace llvm { |
+class MemoryBuffer; // Buffer to read bitcode from |
class NaClBitcodeAbbrevRecord; // bitcode record. |
class NaClMungedBitcodeIter; // iterator over edited bitcode records. |
@@ -99,6 +100,10 @@ void readNaClBitcodeRecordList(NaClBitcodeRecordList &RecordList, |
size_t RecordsSize, |
uint64_t RecordTerminator); |
+/// \brief Read in the list of records from bitcode in a memory buffer. |
+void readNaClBitcodeRecordList(NaClBitcodeRecordList &RecordList, |
+ std::unique_ptr<MemoryBuffer> InputBuffer); |
+ |
/// \brief An edited (i.e. munged) list of bitcode records. Edits are |
/// always relative to the initial list of records. |
class NaClMungedBitcode { |
@@ -111,6 +116,9 @@ public: |
/// \brief Iterator over edited records. |
typedef NaClMungedBitcodeIter iterator; |
+ /// \brief Read in initial list of records from bitcode in a memory buffer. |
+ explicit NaClMungedBitcode(std::unique_ptr<MemoryBuffer> InputBuffer); |
+ |
/// \brief Initialize the list of records to be edited. |
explicit NaClMungedBitcode(std::unique_ptr<NaClBitcodeRecordList> BaseRecords) |
: BaseRecords(std::move(BaseRecords)) {} |
@@ -160,6 +168,47 @@ public: |
/// \brief Print out the resulting edited list of records. |
void print(raw_ostream &Out) const; |
+ /// Defines set of possible write flags. |
+ struct WriteFlags { |
+ /// True if error recovery should be applied. |
+ bool TryToRecover = false; |
+ /// True if bad abbreviation indices should be saved, rather |
+ /// than trying to error recover. |
jvoung (off chromium)
2015/05/06 22:08:09
What does the Save case do after saving? Abort?
S
Karl
2015/05/07 20:09:18
Updated comment to clarify.
|
+ bool SaveBadAbbrevIndices = false; |
+ }; |
+ |
+ /// Defines how writing performed. |
jvoung (off chromium)
2015/05/06 22:08:09
"Defines how writing *is* performed"?
Karl
2015/05/07 20:09:18
Changed to: Defines the results associated with wr
|
+ struct WriteResults { |
+ /// True if errors occurred during writing. |
+ bool HasErrors = false; |
+ /// True if repairs (via error recovery) were applied. |
+ bool HasRepairs = false; |
+ /// True if saved bad abbreviation indices. |
+ bool SavedBadAbbrevIndices = false; |
+ }; |
+ |
+ /// \brief Write out the edited list of bitcode records using |
+ /// the given buffer. |
+ /// |
+ /// \param Buffer The buffer to write into. |
+ /// \param AddHeader Add header block when true. |
+ /// \param Flags Write flags to use. |
+ /// |
+ /// \return Returns the results of the write. |
+ WriteResults writeMaybeRepair( |
+ SmallVectorImpl<char> &Buffer, bool AddHeader, |
+ const WriteFlags &Flags) const; |
+ |
+ bool write(SmallVectorImpl<char> &Buffer, bool AddHeader, |
+ const WriteFlags &Flags) const { |
+ return !writeMaybeRepair(Buffer, AddHeader, Flags).HasErrors; |
+ } |
+ |
+ bool write(SmallVectorImpl<char> &Buffer, bool AddHeader) const { |
+ WriteFlags Flags; |
+ return write(Buffer, AddHeader, Flags); |
+ } |
+ |
/// \brief The types of editing actions that can be applied. |
enum EditAction { |
AddBefore, // Insert new record before base record at index. |
@@ -190,6 +239,11 @@ public: |
/// set of base records. |
void removeEdits(); |
+ /// Returns the unedited list of bitcode records. |
+ const NaClBitcodeRecordList &getBaseRecords() const { |
+ return *BaseRecords; |
+ } |
+ |
private: |
typedef std::list<NaClBitcodeAbbrevRecord *> RecordListType; |
typedef std::map<size_t, RecordListType *> InsertionsMapType; |
@@ -241,7 +295,7 @@ public: |
/// \param Code The selector code of the record. |
/// \param Values The values associated with the selector code. |
NaClBitcodeAbbrevRecord(unsigned Abbrev, unsigned Code, |
- NaClRecordVector &Values) |
+ const NaClRecordVector &Values) |
: NaClBitcodeRecordData(Code, Values), Abbrev(Abbrev) {} |
/// \brief Creates a copy of the given abbreviated bitcode record. |