diff options
-rw-r--r-- | include/llvm/Bitcode/NaCl/NaClBitCodes.h | 189 | ||||
-rw-r--r-- | include/llvm/Bitcode/NaCl/NaClBitstreamReader.h | 28 | ||||
-rw-r--r-- | include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h | 62 | ||||
-rw-r--r-- | include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h | 6 | ||||
-rw-r--r-- | lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp | 4 | ||||
-rw-r--r-- | lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp | 96 | ||||
-rw-r--r-- | lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp | 266 |
7 files changed, 422 insertions, 229 deletions
diff --git a/include/llvm/Bitcode/NaCl/NaClBitCodes.h b/include/llvm/Bitcode/NaCl/NaClBitCodes.h new file mode 100644 index 0000000000..4c0f754f7b --- /dev/null +++ b/include/llvm/Bitcode/NaCl/NaClBitCodes.h @@ -0,0 +1,189 @@ +//===- NaClBitCodes.h - Enum values for the bitcode format ------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This header Bitcode enum values. +// +// The enum values defined in this file should be considered permanent. If +// new features are added, they should have values added at the end of the +// respective lists. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_BITCODE_NACL_NACLBITCODES_H +#define LLVM_BITCODE_NACL_NACLBITCODES_H + +#include "llvm/ADT/SmallVector.h" +#include "llvm/Support/DataTypes.h" +#include "llvm/Support/ErrorHandling.h" +#include <cassert> + +namespace llvm { +namespace naclbitc { + enum StandardWidths { + BlockIDWidth = 8, // We use VBR-8 for block IDs. + CodeLenWidth = 4, // Codelen are VBR-4. + BlockSizeWidth = 32 // BlockSize up to 2^32 32-bit words = 16GB per block. + }; + + // The standard abbrev namespace always has a way to exit a block, enter a + // nested block, define abbrevs, and define an unabbreviated record. + enum FixedAbbrevIDs { + END_BLOCK = 0, // Must be zero to guarantee termination for broken bitcode. + ENTER_SUBBLOCK = 1, + + /// DEFINE_ABBREV - Defines an abbrev for the current block. It consists + /// of a vbr5 for # operand infos. Each operand info is emitted with a + /// single bit to indicate if it is a literal encoding. If so, the value is + /// emitted with a vbr8. If not, the encoding is emitted as 3 bits followed + /// by the info value as a vbr5 if needed. + DEFINE_ABBREV = 2, + + // UNABBREV_RECORDs are emitted with a vbr6 for the record code, followed by + // a vbr6 for the # operands, followed by vbr6's for each operand. + UNABBREV_RECORD = 3, + + // This is not a code, this is a marker for the first abbrev assignment. + FIRST_APPLICATION_ABBREV = 4 + }; + + /// StandardBlockIDs - All bitcode files can optionally include a BLOCKINFO + /// block, which contains metadata about other blocks in the file. + enum StandardBlockIDs { + /// BLOCKINFO_BLOCK is used to define metadata about blocks, for example, + /// standard abbrevs that should be available to all blocks of a specified + /// ID. + BLOCKINFO_BLOCK_ID = 0, + + // Block IDs 1-7 are reserved for future expansion. + FIRST_APPLICATION_BLOCKID = 8 + }; + + /// BlockInfoCodes - The blockinfo block contains metadata about user-defined + /// blocks. + enum BlockInfoCodes { + // DEFINE_ABBREV has magic semantics here, applying to the current SETBID'd + // block, instead of the BlockInfo block. + + BLOCKINFO_CODE_SETBID = 1, // SETBID: [blockid#] + BLOCKINFO_CODE_BLOCKNAME = 2, // BLOCKNAME: [name] + BLOCKINFO_CODE_SETRECORDNAME = 3 // BLOCKINFO_CODE_SETRECORDNAME: + // [id, name] + }; + +} // End naclbitc namespace + +/// NaClBitCodeAbbrevOp - This describes one or more operands in an abbreviation. +/// This is actually a union of two different things: +/// 1. It could be a literal integer value ("the operand is always 17"). +/// 2. It could be an encoding specification ("this operand encoded like so"). +/// +class NaClBitCodeAbbrevOp { + uint64_t Val; // A literal value or data for an encoding. + bool IsLiteral : 1; // Indicate whether this is a literal value or not. + unsigned Enc : 3; // The encoding to use. +public: + enum Encoding { + Fixed = 1, // A fixed width field, Val specifies number of bits. + VBR = 2, // A VBR field where Val specifies the width of each chunk. + Array = 3, // A sequence of fields, next field species elt encoding. + Char6 = 4, // A 6-bit fixed field which maps to [a-zA-Z0-9._]. + Blob = 5 // 32-bit aligned array of 8-bit characters. + }; + + explicit NaClBitCodeAbbrevOp(uint64_t V) : Val(V), IsLiteral(true) {} + explicit NaClBitCodeAbbrevOp(Encoding E, uint64_t Data = 0) + : Val(Data), IsLiteral(false), Enc(E) {} + + bool isLiteral() const { return IsLiteral; } + bool isEncoding() const { return !IsLiteral; } + + // Accessors for literals. + uint64_t getLiteralValue() const { assert(isLiteral()); return Val; } + + // Accessors for encoding info. + Encoding getEncoding() const { assert(isEncoding()); return (Encoding)Enc; } + uint64_t getEncodingData() const { + assert(isEncoding() && hasEncodingData()); + return Val; + } + + bool hasEncodingData() const { return hasEncodingData(getEncoding()); } + static bool hasEncodingData(Encoding E) { + switch (E) { + case Fixed: + case VBR: + return true; + case Array: + case Char6: + case Blob: + return false; + } + llvm_unreachable("Invalid encoding"); + } + + /// isChar6 - Return true if this character is legal in the Char6 encoding. + static bool isChar6(char C) { + if (C >= 'a' && C <= 'z') return true; + if (C >= 'A' && C <= 'Z') return true; + if (C >= '0' && C <= '9') return true; + if (C == '.' || C == '_') return true; + return false; + } + static unsigned EncodeChar6(char C) { + if (C >= 'a' && C <= 'z') return C-'a'; + if (C >= 'A' && C <= 'Z') return C-'A'+26; + if (C >= '0' && C <= '9') return C-'0'+26+26; + if (C == '.') return 62; + if (C == '_') return 63; + llvm_unreachable("Not a value Char6 character!"); + } + + static char DecodeChar6(unsigned V) { + assert((V & ~63) == 0 && "Not a Char6 encoded character!"); + if (V < 26) return V+'a'; + if (V < 26+26) return V-26+'A'; + if (V < 26+26+10) return V-26-26+'0'; + if (V == 62) return '.'; + if (V == 63) return '_'; + llvm_unreachable("Not a value Char6 character!"); + } + +}; + +template <> struct isPodLike<NaClBitCodeAbbrevOp> { + static const bool value=true; +}; + +/// NaClBitCodeAbbrev - This class represents an abbreviation record. An +/// abbreviation allows a complex record that has redundancy to be stored in a +/// specialized format instead of the fully-general, fully-vbr, format. +class NaClBitCodeAbbrev { + SmallVector<NaClBitCodeAbbrevOp, 32> OperandList; + unsigned char RefCount; // Number of things using this. + ~NaClBitCodeAbbrev() {} +public: + NaClBitCodeAbbrev() : RefCount(1) {} + + void addRef() { ++RefCount; } + void dropRef() { if (--RefCount == 0) delete this; } + + unsigned getNumOperandInfos() const { + return static_cast<unsigned>(OperandList.size()); + } + const NaClBitCodeAbbrevOp &getOperandInfo(unsigned N) const { + return OperandList[N]; + } + + void Add(const NaClBitCodeAbbrevOp &OpInfo) { + OperandList.push_back(OpInfo); + } +}; +} // End llvm namespace + +#endif diff --git a/include/llvm/Bitcode/NaCl/NaClBitstreamReader.h b/include/llvm/Bitcode/NaCl/NaClBitstreamReader.h index 238ce5275a..58c0a5d7fa 100644 --- a/include/llvm/Bitcode/NaCl/NaClBitstreamReader.h +++ b/include/llvm/Bitcode/NaCl/NaClBitstreamReader.h @@ -39,7 +39,7 @@ public: /// These describe abbreviations that all blocks of the specified ID inherit. struct BlockInfo { unsigned BlockID; - std::vector<BitCodeAbbrev*> Abbrevs; + std::vector<NaClBitCodeAbbrev*> Abbrevs; std::string Name; std::vector<std::pair<unsigned, std::string> > RecordNames; @@ -189,11 +189,11 @@ class NaClBitstreamCursor { unsigned CurCodeSize; /// CurAbbrevs - Abbrevs installed at in this block. - std::vector<BitCodeAbbrev*> CurAbbrevs; + std::vector<NaClBitCodeAbbrev*> CurAbbrevs; struct Block { unsigned PrevCodeSize; - std::vector<BitCodeAbbrev*> PrevAbbrevs; + std::vector<NaClBitCodeAbbrev*> PrevAbbrevs; explicit Block(unsigned PCS) : PrevCodeSize(PCS) {} }; @@ -286,17 +286,17 @@ public: NaClBitstreamEntry advance(unsigned Flags = 0) { while (1) { unsigned Code = ReadCode(); - if (Code == bitc::END_BLOCK) { + if (Code == naclbitc::END_BLOCK) { // Pop the end of the block unless Flags tells us not to. if (!(Flags & AF_DontPopBlockAtEnd) && ReadBlockEnd()) return NaClBitstreamEntry::getError(); return NaClBitstreamEntry::getEndBlock(); } - if (Code == bitc::ENTER_SUBBLOCK) + if (Code == naclbitc::ENTER_SUBBLOCK) return NaClBitstreamEntry::getSubBlock(ReadSubBlockID()); - if (Code == bitc::DEFINE_ABBREV && + if (Code == naclbitc::DEFINE_ABBREV && !(Flags & AF_DontAutoprocessAbbrevs)) { // We read and accumulate abbrev's, the client can't do anything with // them anyway. @@ -469,7 +469,7 @@ public: /// ReadSubBlockID - Having read the ENTER_SUBBLOCK code, read the BlockID for /// the block. unsigned ReadSubBlockID() { - return ReadVBR(bitc::BlockIDWidth); + return ReadVBR(naclbitc::BlockIDWidth); } /// SkipBlock - Having read the ENTER_SUBBLOCK abbrevid and a BlockID, skip @@ -478,9 +478,9 @@ public: bool SkipBlock() { // Read and ignore the codelen value. Since we are skipping this block, we // don't care what code widths are used inside of it. - ReadVBR(bitc::CodeLenWidth); + ReadVBR(naclbitc::CodeLenWidth); SkipToFourByteBoundary(); - unsigned NumFourBytes = Read(bitc::BlockSizeWidth); + unsigned NumFourBytes = Read(naclbitc::BlockSizeWidth); // Check that the block wasn't partially defined, and that the offset isn't // bogus. @@ -526,17 +526,17 @@ private: //===--------------------------------------------------------------------===// private: - void readAbbreviatedLiteral(const BitCodeAbbrevOp &Op, + void readAbbreviatedLiteral(const NaClBitCodeAbbrevOp &Op, SmallVectorImpl<uint64_t> &Vals); - void readAbbreviatedField(const BitCodeAbbrevOp &Op, + void readAbbreviatedField(const NaClBitCodeAbbrevOp &Op, SmallVectorImpl<uint64_t> &Vals); - void skipAbbreviatedField(const BitCodeAbbrevOp &Op); + void skipAbbreviatedField(const NaClBitCodeAbbrevOp &Op); public: /// getAbbrev - Return the abbreviation for the specified AbbrevId. - const BitCodeAbbrev *getAbbrev(unsigned AbbrevID) { - unsigned AbbrevNo = AbbrevID-bitc::FIRST_APPLICATION_ABBREV; + const NaClBitCodeAbbrev *getAbbrev(unsigned AbbrevID) { + unsigned AbbrevNo = AbbrevID-naclbitc::FIRST_APPLICATION_ABBREV; assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!"); return CurAbbrevs[AbbrevNo]; } diff --git a/include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h b/include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h index 11443ebd87..26d9cb6b24 100644 --- a/include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h +++ b/include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h @@ -17,7 +17,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" -#include "llvm/Bitcode/BitCodes.h" +#include "llvm/Bitcode/NaCl/NaClBitCodes.h" #include <vector> namespace llvm { @@ -40,12 +40,12 @@ class NaClBitstreamWriter { unsigned BlockInfoCurBID; /// CurAbbrevs - Abbrevs installed at in this block. - std::vector<BitCodeAbbrev*> CurAbbrevs; + std::vector<NaClBitCodeAbbrev*> CurAbbrevs; struct Block { unsigned PrevCodeSize; unsigned StartSizeWord; - std::vector<BitCodeAbbrev*> PrevAbbrevs; + std::vector<NaClBitCodeAbbrev*> PrevAbbrevs; Block(unsigned PCS, unsigned SSW) : PrevCodeSize(PCS), StartSizeWord(SSW) {} }; @@ -56,7 +56,7 @@ class NaClBitstreamWriter { /// These describe abbreviations that all blocks of the specified ID inherit. struct BlockInfo { unsigned BlockID; - std::vector<BitCodeAbbrev*> Abbrevs; + std::vector<NaClBitCodeAbbrev*> Abbrevs; }; std::vector<BlockInfo> BlockInfoRecords; @@ -210,16 +210,16 @@ public: void EnterSubblock(unsigned BlockID, unsigned CodeLen) { // Block header: // [ENTER_SUBBLOCK, blockid, newcodelen, <align4bytes>, blocklen] - EmitCode(bitc::ENTER_SUBBLOCK); - EmitVBR(BlockID, bitc::BlockIDWidth); - EmitVBR(CodeLen, bitc::CodeLenWidth); + EmitCode(naclbitc::ENTER_SUBBLOCK); + EmitVBR(BlockID, naclbitc::BlockIDWidth); + EmitVBR(CodeLen, naclbitc::CodeLenWidth); FlushToWord(); unsigned BlockSizeWordIndex = GetWordIndex(); unsigned OldCodeSize = CurCodeSize; // Emit a placeholder, which will be replaced when the block is popped. - Emit(0, bitc::BlockSizeWidth); + Emit(0, naclbitc::BlockSizeWidth); CurCodeSize = CodeLen; @@ -251,7 +251,7 @@ public: // Block tail: // [END_BLOCK, <align4bytes>] - EmitCode(bitc::END_BLOCK); + EmitCode(naclbitc::END_BLOCK); FlushToWord(); // Compute the size of the block, in words, not counting the size field. @@ -275,7 +275,7 @@ private: /// EmitAbbreviatedLiteral - Emit a literal value according to its abbrev /// record. This is a no-op, since the abbrev specifies the literal to use. template<typename uintty> - void EmitAbbreviatedLiteral(const BitCodeAbbrevOp &Op, uintty V) { + void EmitAbbreviatedLiteral(const NaClBitCodeAbbrevOp &Op, uintty V) { assert(Op.isLiteral() && "Not a literal"); // If the abbrev specifies the literal value to use, don't emit // anything. @@ -286,22 +286,22 @@ private: /// EmitAbbreviatedField - Emit a single scalar field value with the specified /// encoding. template<typename uintty> - void EmitAbbreviatedField(const BitCodeAbbrevOp &Op, uintty V) { + void EmitAbbreviatedField(const NaClBitCodeAbbrevOp &Op, uintty V) { assert(!Op.isLiteral() && "Literals should use EmitAbbreviatedLiteral!"); // Encode the value as we are commanded. switch (Op.getEncoding()) { default: llvm_unreachable("Unknown encoding!"); - case BitCodeAbbrevOp::Fixed: + case NaClBitCodeAbbrevOp::Fixed: if (Op.getEncodingData()) Emit((unsigned)V, (unsigned)Op.getEncodingData()); break; - case BitCodeAbbrevOp::VBR: + case NaClBitCodeAbbrevOp::VBR: if (Op.getEncodingData()) EmitVBR64(V, (unsigned)Op.getEncodingData()); break; - case BitCodeAbbrevOp::Char6: - Emit(BitCodeAbbrevOp::EncodeChar6((char)V), 6); + case NaClBitCodeAbbrevOp::Char6: + Emit(NaClBitCodeAbbrevOp::EncodeChar6((char)V), 6); break; } } @@ -315,24 +315,24 @@ private: StringRef Blob) { const char *BlobData = Blob.data(); unsigned BlobLen = (unsigned) Blob.size(); - unsigned AbbrevNo = Abbrev-bitc::FIRST_APPLICATION_ABBREV; + unsigned AbbrevNo = Abbrev-naclbitc::FIRST_APPLICATION_ABBREV; assert(AbbrevNo < CurAbbrevs.size() && "Invalid abbrev #!"); - BitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo]; + NaClBitCodeAbbrev *Abbv = CurAbbrevs[AbbrevNo]; EmitCode(Abbrev); unsigned RecordIdx = 0; for (unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos()); i != e; ++i) { - const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); + const NaClBitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); if (Op.isLiteral()) { assert(RecordIdx < Vals.size() && "Invalid abbrev/record"); EmitAbbreviatedLiteral(Op, Vals[RecordIdx]); ++RecordIdx; - } else if (Op.getEncoding() == BitCodeAbbrevOp::Array) { + } else if (Op.getEncoding() == NaClBitCodeAbbrevOp::Array) { // Array case. assert(i+2 == e && "array op not second to last?"); - const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); + const NaClBitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); // If this record has blob data, emit it, otherwise we must have record // entries to encode this way. @@ -356,7 +356,7 @@ private: for (unsigned e = Vals.size(); RecordIdx != e; ++RecordIdx) EmitAbbreviatedField(EltEnc, Vals[RecordIdx]); } - } else if (Op.getEncoding() == BitCodeAbbrevOp::Blob) { + } else if (Op.getEncoding() == NaClBitCodeAbbrevOp::Blob) { // If this record has blob data, emit it, otherwise we must have record // entries to encode this way. @@ -410,7 +410,7 @@ public: if (!Abbrev) { // If we don't have an abbrev to use, emit this in its fully unabbreviated // form. - EmitCode(bitc::UNABBREV_RECORD); + EmitCode(naclbitc::UNABBREV_RECORD); EmitVBR(Code, 6); EmitVBR(static_cast<uint32_t>(Vals.size()), 6); for (unsigned i = 0, e = static_cast<unsigned>(Vals.size()); i != e; ++i) @@ -468,12 +468,12 @@ public: private: // Emit the abbreviation as a DEFINE_ABBREV record. - void EncodeAbbrev(BitCodeAbbrev *Abbv) { - EmitCode(bitc::DEFINE_ABBREV); + void EncodeAbbrev(NaClBitCodeAbbrev *Abbv) { + EmitCode(naclbitc::DEFINE_ABBREV); EmitVBR(Abbv->getNumOperandInfos(), 5); for (unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos()); i != e; ++i) { - const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); + const NaClBitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); Emit(Op.isLiteral(), 1); if (Op.isLiteral()) { EmitVBR64(Op.getLiteralValue(), 8); @@ -488,12 +488,12 @@ public: /// EmitAbbrev - This emits an abbreviation to the stream. Note that this /// method takes ownership of the specified abbrev. - unsigned EmitAbbrev(BitCodeAbbrev *Abbv) { + unsigned EmitAbbrev(NaClBitCodeAbbrev *Abbv) { // Emit the abbreviation as a record. EncodeAbbrev(Abbv); CurAbbrevs.push_back(Abbv); return static_cast<unsigned>(CurAbbrevs.size())-1 + - bitc::FIRST_APPLICATION_ABBREV; + naclbitc::FIRST_APPLICATION_ABBREV; } //===--------------------------------------------------------------------===// @@ -502,7 +502,7 @@ public: /// EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK. void EnterBlockInfoBlock(unsigned CodeWidth) { - EnterSubblock(bitc::BLOCKINFO_BLOCK_ID, CodeWidth); + EnterSubblock(naclbitc::BLOCKINFO_BLOCK_ID, CodeWidth); BlockInfoCurBID = ~0U; } private: @@ -512,7 +512,7 @@ private: if (BlockInfoCurBID == BlockID) return; SmallVector<unsigned, 2> V; V.push_back(BlockID); - EmitRecord(bitc::BLOCKINFO_CODE_SETBID, V); + EmitRecord(naclbitc::BLOCKINFO_CODE_SETBID, V); BlockInfoCurBID = BlockID; } @@ -530,7 +530,7 @@ public: /// EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified /// BlockID. - unsigned EmitBlockInfoAbbrev(unsigned BlockID, BitCodeAbbrev *Abbv) { + unsigned EmitBlockInfoAbbrev(unsigned BlockID, NaClBitCodeAbbrev *Abbv) { SwitchToBlockID(BlockID); EncodeAbbrev(Abbv); @@ -538,7 +538,7 @@ public: BlockInfo &Info = getOrCreateBlockInfo(BlockID); Info.Abbrevs.push_back(Abbv); - return Info.Abbrevs.size()-1+bitc::FIRST_APPLICATION_ABBREV; + return Info.Abbrevs.size()-1+naclbitc::FIRST_APPLICATION_ABBREV; } }; diff --git a/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h b/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h index a8ebe8b8f6..bf31c5bea3 100644 --- a/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h +++ b/include/llvm/Bitcode/NaCl/NaClLLVMBitCodes.h @@ -19,16 +19,14 @@ #ifndef LLVM_BITCODE_NACL_NACLLLVMBITCODES_H #define LLVM_BITCODE_NACL_NACLLLVMBITCODES_H -// TODO(kschimpf) Make a NaCl version of BitCodes.h, so that block id's -// and abbreviations can be modified. -#include "llvm/Bitcode/BitCodes.h" +#include "llvm/Bitcode/NaCl/NaClBitCodes.h" namespace llvm { namespace naclbitc { // The only top-level block type defined is for a module. enum NaClBlockIDs { // Blocks - MODULE_BLOCK_ID = bitc::FIRST_APPLICATION_BLOCKID, + MODULE_BLOCK_ID = FIRST_APPLICATION_BLOCKID, // Module sub-block id's. PARAMATTR_BLOCK_ID, diff --git a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp index 79b6ea6cca..5317e11a27 100644 --- a/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp +++ b/lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp @@ -1525,7 +1525,7 @@ bool NaClBitcodeReader::ParseModule(bool Resume) { if (Stream.SkipBlock()) return Error("Malformed block record"); break; - case bitc::BLOCKINFO_BLOCK_ID: + case naclbitc::BLOCKINFO_BLOCK_ID: if (Stream.ReadBlockInfoBlock()) return Error("Malformed BlockInfoBlock"); break; @@ -1825,7 +1825,7 @@ bool NaClBitcodeReader::ParseBitcodeInto(Module *M) { case NaClBitstreamEntry::SubBlock: switch (Entry.ID) { - case bitc::BLOCKINFO_BLOCK_ID: + case naclbitc::BLOCKINFO_BLOCK_ID: if (Stream.ReadBlockInfoBlock()) return Error("Malformed BlockInfoBlock"); break; diff --git a/lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp b/lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp index ab8f1a5c6d..677539071b 100644 --- a/lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp +++ b/lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp @@ -33,7 +33,7 @@ void NaClBitstreamCursor::operator=(const NaClBitstreamCursor &RHS) { // Copy block scope and bump ref counts. BlockScope = RHS.BlockScope; for (size_t S = 0, e = BlockScope.size(); S != e; ++S) { - std::vector<BitCodeAbbrev*> &Abbrevs = BlockScope[S].PrevAbbrevs; + std::vector<NaClBitCodeAbbrev*> &Abbrevs = BlockScope[S].PrevAbbrevs; for (size_t i = 0, e = Abbrevs.size(); i != e; ++i) Abbrevs[i]->addRef(); } @@ -47,7 +47,7 @@ void NaClBitstreamCursor::freeState() { // Free all the Abbrevs in the block scope. for (size_t S = 0, e = BlockScope.size(); S != e; ++S) { - std::vector<BitCodeAbbrev*> &Abbrevs = BlockScope[S].PrevAbbrevs; + std::vector<NaClBitCodeAbbrev*> &Abbrevs = BlockScope[S].PrevAbbrevs; for (size_t i = 0, e = Abbrevs.size(); i != e; ++i) Abbrevs[i]->dropRef(); } @@ -71,9 +71,9 @@ bool NaClBitstreamCursor::EnterSubBlock(unsigned BlockID, unsigned *NumWordsP) { } // Get the codesize of this block. - CurCodeSize = ReadVBR(bitc::CodeLenWidth); + CurCodeSize = ReadVBR(naclbitc::CodeLenWidth); SkipToFourByteBoundary(); - unsigned NumWords = Read(bitc::BlockSizeWidth); + unsigned NumWords = Read(naclbitc::BlockSizeWidth); if (NumWordsP) *NumWordsP = NumWords; // Validate that this block is sane. @@ -84,7 +84,7 @@ bool NaClBitstreamCursor::EnterSubBlock(unsigned BlockID, unsigned *NumWordsP) { } void NaClBitstreamCursor::readAbbreviatedLiteral( - const BitCodeAbbrevOp &Op, + const NaClBitCodeAbbrevOp &Op, SmallVectorImpl<uint64_t> &Vals) { assert(Op.isLiteral() && "Not a literal"); // If the abbrev specifies the literal value to use, use it. @@ -92,42 +92,42 @@ void NaClBitstreamCursor::readAbbreviatedLiteral( } void NaClBitstreamCursor::readAbbreviatedField( - const BitCodeAbbrevOp &Op, + const NaClBitCodeAbbrevOp &Op, SmallVectorImpl<uint64_t> &Vals) { assert(!Op.isLiteral() && "Use ReadAbbreviatedLiteral for literals!"); // Decode the value as we are commanded. switch (Op.getEncoding()) { - case BitCodeAbbrevOp::Array: - case BitCodeAbbrevOp::Blob: + case NaClBitCodeAbbrevOp::Array: + case NaClBitCodeAbbrevOp::Blob: assert(0 && "Should not reach here"); - case BitCodeAbbrevOp::Fixed: + case NaClBitCodeAbbrevOp::Fixed: Vals.push_back(Read((unsigned)Op.getEncodingData())); break; - case BitCodeAbbrevOp::VBR: + case NaClBitCodeAbbrevOp::VBR: Vals.push_back(ReadVBR64((unsigned)Op.getEncodingData())); break; - case BitCodeAbbrevOp::Char6: - Vals.push_back(BitCodeAbbrevOp::DecodeChar6(Read(6))); + case NaClBitCodeAbbrevOp::Char6: + Vals.push_back(NaClBitCodeAbbrevOp::DecodeChar6(Read(6))); break; } } -void NaClBitstreamCursor::skipAbbreviatedField(const BitCodeAbbrevOp &Op) { +void NaClBitstreamCursor::skipAbbreviatedField(const NaClBitCodeAbbrevOp &Op) { assert(!Op.isLiteral() && "Use ReadAbbreviatedLiteral for literals!"); // Decode the value as we are commanded. switch (Op.getEncoding()) { - case BitCodeAbbrevOp::Array: - case BitCodeAbbrevOp::Blob: + case NaClBitCodeAbbrevOp::Array: + case NaClBitCodeAbbrevOp::Blob: assert(0 && "Should not reach here"); - case BitCodeAbbrevOp::Fixed: + case NaClBitCodeAbbrevOp::Fixed: (void)Read((unsigned)Op.getEncodingData()); break; - case BitCodeAbbrevOp::VBR: + case NaClBitCodeAbbrevOp::VBR: (void)ReadVBR64((unsigned)Op.getEncodingData()); break; - case BitCodeAbbrevOp::Char6: + case NaClBitCodeAbbrevOp::Char6: (void)Read(6); break; } @@ -138,7 +138,7 @@ void NaClBitstreamCursor::skipAbbreviatedField(const BitCodeAbbrevOp &Op) { /// skipRecord - Read the current record and discard it. void NaClBitstreamCursor::skipRecord(unsigned AbbrevID) { // Skip unabbreviated records by reading past their entries. - if (AbbrevID == bitc::UNABBREV_RECORD) { + if (AbbrevID == naclbitc::UNABBREV_RECORD) { unsigned Code = ReadVBR(6); (void)Code; unsigned NumElts = ReadVBR(6); @@ -147,26 +147,26 @@ void NaClBitstreamCursor::skipRecord(unsigned AbbrevID) { return; } - const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID); + const NaClBitCodeAbbrev *Abbv = getAbbrev(AbbrevID); for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) { - const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); + const NaClBitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); if (Op.isLiteral()) continue; - if (Op.getEncoding() != BitCodeAbbrevOp::Array && - Op.getEncoding() != BitCodeAbbrevOp::Blob) { + if (Op.getEncoding() != NaClBitCodeAbbrevOp::Array && + Op.getEncoding() != NaClBitCodeAbbrevOp::Blob) { skipAbbreviatedField(Op); continue; } - if (Op.getEncoding() == BitCodeAbbrevOp::Array) { + if (Op.getEncoding() == NaClBitCodeAbbrevOp::Array) { // Array case. Read the number of elements as a vbr6. unsigned NumElts = ReadVBR(6); // Get the element encoding. assert(i+2 == e && "array op not second to last?"); - const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); + const NaClBitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); // Read all the elements. for (; NumElts; --NumElts) @@ -174,7 +174,7 @@ void NaClBitstreamCursor::skipRecord(unsigned AbbrevID) { continue; } - assert(Op.getEncoding() == BitCodeAbbrevOp::Blob); + assert(Op.getEncoding() == NaClBitCodeAbbrevOp::Blob); // Blob case. Read the number of bytes as a vbr6. unsigned NumElts = ReadVBR(6); SkipToFourByteBoundary(); // 32-bit alignment @@ -197,7 +197,7 @@ void NaClBitstreamCursor::skipRecord(unsigned AbbrevID) { unsigned NaClBitstreamCursor::readRecord(unsigned AbbrevID, SmallVectorImpl<uint64_t> &Vals, StringRef *Blob) { - if (AbbrevID == bitc::UNABBREV_RECORD) { + if (AbbrevID == naclbitc::UNABBREV_RECORD) { unsigned Code = ReadVBR(6); unsigned NumElts = ReadVBR(6); for (unsigned i = 0; i != NumElts; ++i) @@ -205,28 +205,28 @@ unsigned NaClBitstreamCursor::readRecord(unsigned AbbrevID, return Code; } - const BitCodeAbbrev *Abbv = getAbbrev(AbbrevID); + const NaClBitCodeAbbrev *Abbv = getAbbrev(AbbrevID); for (unsigned i = 0, e = Abbv->getNumOperandInfos(); i != e; ++i) { - const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); + const NaClBitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); if (Op.isLiteral()) { readAbbreviatedLiteral(Op, Vals); continue; } - if (Op.getEncoding() != BitCodeAbbrevOp::Array && - Op.getEncoding() != BitCodeAbbrevOp::Blob) { + if (Op.getEncoding() != NaClBitCodeAbbrevOp::Array && + Op.getEncoding() != NaClBitCodeAbbrevOp::Blob) { readAbbreviatedField(Op, Vals); continue; } - if (Op.getEncoding() == BitCodeAbbrevOp::Array) { + if (Op.getEncoding() == NaClBitCodeAbbrevOp::Array) { // Array case. Read the number of elements as a vbr6. unsigned NumElts = ReadVBR(6); // Get the element encoding. assert(i+2 == e && "array op not second to last?"); - const BitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); + const NaClBitCodeAbbrevOp &EltEnc = Abbv->getOperandInfo(++i); // Read all the elements. for (; NumElts; --NumElts) @@ -234,7 +234,7 @@ unsigned NaClBitstreamCursor::readRecord(unsigned AbbrevID, continue; } - assert(Op.getEncoding() == BitCodeAbbrevOp::Blob); + assert(Op.getEncoding() == NaClBitCodeAbbrevOp::Blob); // Blob case. Read the number of bytes as a vbr6. unsigned NumElts = ReadVBR(6); SkipToFourByteBoundary(); // 32-bit alignment @@ -274,31 +274,31 @@ unsigned NaClBitstreamCursor::readRecord(unsigned AbbrevID, void NaClBitstreamCursor::ReadAbbrevRecord() { - BitCodeAbbrev *Abbv = new BitCodeAbbrev(); + NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); unsigned NumOpInfo = ReadVBR(5); for (unsigned i = 0; i != NumOpInfo; ++i) { bool IsLiteral = Read(1) ? true : false; if (IsLiteral) { - Abbv->Add(BitCodeAbbrevOp(ReadVBR64(8))); + Abbv->Add(NaClBitCodeAbbrevOp(ReadVBR64(8))); continue; } - BitCodeAbbrevOp::Encoding E = (BitCodeAbbrevOp::Encoding)Read(3); - if (BitCodeAbbrevOp::hasEncodingData(E)) { + NaClBitCodeAbbrevOp::Encoding E = (NaClBitCodeAbbrevOp::Encoding)Read(3); + if (NaClBitCodeAbbrevOp::hasEncodingData(E)) { unsigned Data = ReadVBR64(5); // As a special case, handle fixed(0) (i.e., a fixed field with zero bits) // and vbr(0) as a literal zero. This is decoded the same way, and avoids // a slow path in Read() to have to handle reading zero bits. - if ((E == BitCodeAbbrevOp::Fixed || E == BitCodeAbbrevOp::VBR) && + if ((E == NaClBitCodeAbbrevOp::Fixed || E == NaClBitCodeAbbrevOp::VBR) && Data == 0) { - Abbv->Add(BitCodeAbbrevOp(0)); + Abbv->Add(NaClBitCodeAbbrevOp(0)); continue; } - Abbv->Add(BitCodeAbbrevOp(E, Data)); + Abbv->Add(NaClBitCodeAbbrevOp(E, Data)); } else - Abbv->Add(BitCodeAbbrevOp(E)); + Abbv->Add(NaClBitCodeAbbrevOp(E)); } CurAbbrevs.push_back(Abbv); } @@ -308,7 +308,7 @@ bool NaClBitstreamCursor::ReadBlockInfoBlock() { if (BitStream->hasBlockInfoRecords()) return SkipBlock(); - if (EnterSubBlock(bitc::BLOCKINFO_BLOCK_ID)) return true; + if (EnterSubBlock(naclbitc::BLOCKINFO_BLOCK_ID)) return true; SmallVector<uint64_t, 64> Record; NaClBitstreamReader::BlockInfo *CurBlockInfo = 0; @@ -329,13 +329,13 @@ bool NaClBitstreamCursor::ReadBlockInfoBlock() { } // Read abbrev records, associate them with CurBID. - if (Entry.ID == bitc::DEFINE_ABBREV) { + if (Entry.ID == naclbitc::DEFINE_ABBREV) { if (!CurBlockInfo) return true; ReadAbbrevRecord(); // ReadAbbrevRecord installs the abbrev in CurAbbrevs. Move it to the // appropriate BlockInfo. - BitCodeAbbrev *Abbv = CurAbbrevs.back(); + NaClBitCodeAbbrev *Abbv = CurAbbrevs.back(); CurAbbrevs.pop_back(); CurBlockInfo->Abbrevs.push_back(Abbv); continue; @@ -345,11 +345,11 @@ bool NaClBitstreamCursor::ReadBlockInfoBlock() { Record.clear(); switch (readRecord(Entry.ID, Record)) { default: break; // Default behavior, ignore unknown content. - case bitc::BLOCKINFO_CODE_SETBID: + case naclbitc::BLOCKINFO_CODE_SETBID: if (Record.size() < 1) return true; CurBlockInfo = &BitStream->getOrCreateBlockInfo((unsigned)Record[0]); break; - case bitc::BLOCKINFO_CODE_BLOCKNAME: { + case naclbitc::BLOCKINFO_CODE_BLOCKNAME: { if (!CurBlockInfo) return true; if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name. std::string Name; @@ -358,7 +358,7 @@ bool NaClBitstreamCursor::ReadBlockInfoBlock() { CurBlockInfo->Name = Name; break; } - case bitc::BLOCKINFO_CODE_SETRECORDNAME: { + case naclbitc::BLOCKINFO_CODE_SETRECORDNAME: { if (!CurBlockInfo) return true; if (BitStream->isIgnoringBlockInfoNames()) break; // Ignore name. std::string Name; diff --git a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp index edaaadf681..1d7d8dc23c 100644 --- a/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp +++ b/lib/Bitcode/NaCl/Writer/NaClBitcodeWriter.cpp @@ -36,19 +36,19 @@ using namespace llvm; /// be kept in sync with the reader, but need to be consistent within this file. enum { // VALUE_SYMTAB_BLOCK abbrev id's. - VST_ENTRY_8_ABBREV = bitc::FIRST_APPLICATION_ABBREV, + VST_ENTRY_8_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, VST_ENTRY_7_ABBREV, VST_ENTRY_6_ABBREV, VST_BBENTRY_6_ABBREV, // CONSTANTS_BLOCK abbrev id's. - CONSTANTS_SETTYPE_ABBREV = bitc::FIRST_APPLICATION_ABBREV, + CONSTANTS_SETTYPE_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, CONSTANTS_INTEGER_ABBREV, CONSTANTS_CE_CAST_Abbrev, CONSTANTS_NULL_Abbrev, // FUNCTION_BLOCK abbrev id's. - FUNCTION_INST_LOAD_ABBREV = bitc::FIRST_APPLICATION_ABBREV, + FUNCTION_INST_LOAD_ABBREV = naclbitc::FIRST_APPLICATION_ABBREV, FUNCTION_INST_BINOP_ABBREV, FUNCTION_INST_BINOP_FLAGS_ABBREV, FUNCTION_INST_CAST_ABBREV, @@ -141,12 +141,13 @@ static unsigned GetEncodedSynchScope(SynchronizationScope SynchScope) { } static void WriteStringRecord(unsigned Code, StringRef Str, - unsigned AbbrevToUse, NaClBitstreamWriter &Stream) { + unsigned AbbrevToUse, + NaClBitstreamWriter &Stream) { SmallVector<unsigned, 64> Vals; // Code: [strchar x N] for (unsigned i = 0, e = Str.size(); i != e; ++i) { - if (AbbrevToUse && !BitCodeAbbrevOp::isChar6(Str[i])) + if (AbbrevToUse && !NaClBitCodeAbbrevOp::isChar6(Str[i])) AbbrevToUse = 0; Vals.push_back(Str[i]); } @@ -228,57 +229,58 @@ static void WriteTypeTable(const NaClValueEnumerator &VE, NaClBitstreamWriter &Stream) { const NaClValueEnumerator::TypeList &TypeList = VE.getTypes(); - Stream.EnterSubblock(naclbitc::TYPE_BLOCK_ID_NEW, 4 /*count from # abbrevs */); + Stream.EnterSubblock(naclbitc::TYPE_BLOCK_ID_NEW, + 4 /*count from # abbrevs */); SmallVector<uint64_t, 64> TypeVals; uint64_t NumBits = Log2_32_Ceil(VE.getTypes().size()+1); // Abbrev for TYPE_CODE_POINTER. - BitCodeAbbrev *Abbv = new BitCodeAbbrev(); - Abbv->Add(BitCodeAbbrevOp(naclbitc::TYPE_CODE_POINTER)); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, NumBits)); - Abbv->Add(BitCodeAbbrevOp(0)); // Addrspace = 0 + NaClBitCodeAbbrev *Abbv = new NaClBitCodeAbbrev(); + Abbv->Add(NaClBitCodeAbbrevOp(naclbitc::TYPE_CODE_POINTER)); + Abbv->Add(NaClBitCodeAbbrevOp(NaClBitCodeAbbrevOp::Fixed, NumBits)); |