Mercurial > hg > CbC > CbC_llvm
comparison include/llvm/Bitcode/BitstreamWriter.h @ 121:803732b1fca8
LLVM 5.0
author | kono |
---|---|
date | Fri, 27 Oct 2017 17:07:41 +0900 |
parents | 1172e4bd9c6f |
children |
comparison
equal
deleted
inserted
replaced
120:1172e4bd9c6f | 121:803732b1fca8 |
---|---|
41 /// BlockInfoCurBID - When emitting a BLOCKINFO_BLOCK, this is the currently | 41 /// BlockInfoCurBID - When emitting a BLOCKINFO_BLOCK, this is the currently |
42 /// selected BLOCK ID. | 42 /// selected BLOCK ID. |
43 unsigned BlockInfoCurBID; | 43 unsigned BlockInfoCurBID; |
44 | 44 |
45 /// CurAbbrevs - Abbrevs installed at in this block. | 45 /// CurAbbrevs - Abbrevs installed at in this block. |
46 std::vector<IntrusiveRefCntPtr<BitCodeAbbrev>> CurAbbrevs; | 46 std::vector<std::shared_ptr<BitCodeAbbrev>> CurAbbrevs; |
47 | 47 |
48 struct Block { | 48 struct Block { |
49 unsigned PrevCodeSize; | 49 unsigned PrevCodeSize; |
50 size_t StartSizeWord; | 50 size_t StartSizeWord; |
51 std::vector<IntrusiveRefCntPtr<BitCodeAbbrev>> PrevAbbrevs; | 51 std::vector<std::shared_ptr<BitCodeAbbrev>> PrevAbbrevs; |
52 Block(unsigned PCS, size_t SSW) : PrevCodeSize(PCS), StartSizeWord(SSW) {} | 52 Block(unsigned PCS, size_t SSW) : PrevCodeSize(PCS), StartSizeWord(SSW) {} |
53 }; | 53 }; |
54 | 54 |
55 /// BlockScope - This tracks the current blocks that we have entered. | 55 /// BlockScope - This tracks the current blocks that we have entered. |
56 std::vector<Block> BlockScope; | 56 std::vector<Block> BlockScope; |
57 | 57 |
58 /// BlockInfo - This contains information emitted to BLOCKINFO_BLOCK blocks. | 58 /// BlockInfo - This contains information emitted to BLOCKINFO_BLOCK blocks. |
59 /// These describe abbreviations that all blocks of the specified ID inherit. | 59 /// These describe abbreviations that all blocks of the specified ID inherit. |
60 struct BlockInfo { | 60 struct BlockInfo { |
61 unsigned BlockID; | 61 unsigned BlockID; |
62 std::vector<IntrusiveRefCntPtr<BitCodeAbbrev>> Abbrevs; | 62 std::vector<std::shared_ptr<BitCodeAbbrev>> Abbrevs; |
63 }; | 63 }; |
64 std::vector<BlockInfo> BlockInfoRecords; | 64 std::vector<BlockInfo> BlockInfoRecords; |
65 | 65 |
66 void WriteByte(unsigned char Value) { | 66 void WriteByte(unsigned char Value) { |
67 Out.push_back(Value); | 67 Out.push_back(Value); |
110 "Expected to be patching over 0-value placeholders"); | 110 "Expected to be patching over 0-value placeholders"); |
111 endian::writeAtBitAlignment<uint32_t, little, unaligned>( | 111 endian::writeAtBitAlignment<uint32_t, little, unaligned>( |
112 &Out[ByteNo], NewWord, BitNo & 7); | 112 &Out[ByteNo], NewWord, BitNo & 7); |
113 } | 113 } |
114 | 114 |
115 void BackpatchWord64(uint64_t BitNo, uint64_t Val) { | |
116 BackpatchWord(BitNo, (uint32_t)Val); | |
117 BackpatchWord(BitNo + 32, (uint32_t)(Val >> 32)); | |
118 } | |
119 | |
115 void Emit(uint32_t Val, unsigned NumBits) { | 120 void Emit(uint32_t Val, unsigned NumBits) { |
116 assert(NumBits && NumBits <= 32 && "Invalid value size!"); | 121 assert(NumBits && NumBits <= 32 && "Invalid value size!"); |
117 assert((Val & ~(~0U >> (32-NumBits))) == 0 && "High bits set!"); | 122 assert((Val & ~(~0U >> (32-NumBits))) == 0 && "High bits set!"); |
118 CurValue |= Val << CurBit; | 123 CurValue |= Val << CurBit; |
119 if (CurBit + NumBits < 32) { | 124 if (CurBit + NumBits < 32) { |
127 if (CurBit) | 132 if (CurBit) |
128 CurValue = Val >> (32-CurBit); | 133 CurValue = Val >> (32-CurBit); |
129 else | 134 else |
130 CurValue = 0; | 135 CurValue = 0; |
131 CurBit = (CurBit+NumBits) & 31; | 136 CurBit = (CurBit+NumBits) & 31; |
132 } | |
133 | |
134 void Emit64(uint64_t Val, unsigned NumBits) { | |
135 if (NumBits <= 32) | |
136 Emit((uint32_t)Val, NumBits); | |
137 else { | |
138 Emit((uint32_t)Val, 32); | |
139 Emit((uint32_t)(Val >> 32), NumBits-32); | |
140 } | |
141 } | 137 } |
142 | 138 |
143 void FlushToWord() { | 139 void FlushToWord() { |
144 if (CurBit) { | 140 if (CurBit) { |
145 WriteWord(CurValue); | 141 WriteWord(CurValue); |
471 // Abbrev Emission | 467 // Abbrev Emission |
472 //===--------------------------------------------------------------------===// | 468 //===--------------------------------------------------------------------===// |
473 | 469 |
474 private: | 470 private: |
475 // Emit the abbreviation as a DEFINE_ABBREV record. | 471 // Emit the abbreviation as a DEFINE_ABBREV record. |
476 void EncodeAbbrev(BitCodeAbbrev *Abbv) { | 472 void EncodeAbbrev(const BitCodeAbbrev &Abbv) { |
477 EmitCode(bitc::DEFINE_ABBREV); | 473 EmitCode(bitc::DEFINE_ABBREV); |
478 EmitVBR(Abbv->getNumOperandInfos(), 5); | 474 EmitVBR(Abbv.getNumOperandInfos(), 5); |
479 for (unsigned i = 0, e = static_cast<unsigned>(Abbv->getNumOperandInfos()); | 475 for (unsigned i = 0, e = static_cast<unsigned>(Abbv.getNumOperandInfos()); |
480 i != e; ++i) { | 476 i != e; ++i) { |
481 const BitCodeAbbrevOp &Op = Abbv->getOperandInfo(i); | 477 const BitCodeAbbrevOp &Op = Abbv.getOperandInfo(i); |
482 Emit(Op.isLiteral(), 1); | 478 Emit(Op.isLiteral(), 1); |
483 if (Op.isLiteral()) { | 479 if (Op.isLiteral()) { |
484 EmitVBR64(Op.getLiteralValue(), 8); | 480 EmitVBR64(Op.getLiteralValue(), 8); |
485 } else { | 481 } else { |
486 Emit(Op.getEncoding(), 3); | 482 Emit(Op.getEncoding(), 3); |
491 } | 487 } |
492 public: | 488 public: |
493 | 489 |
494 /// EmitAbbrev - This emits an abbreviation to the stream. Note that this | 490 /// EmitAbbrev - This emits an abbreviation to the stream. Note that this |
495 /// method takes ownership of the specified abbrev. | 491 /// method takes ownership of the specified abbrev. |
496 unsigned EmitAbbrev(BitCodeAbbrev *Abbv) { | 492 unsigned EmitAbbrev(std::shared_ptr<BitCodeAbbrev> Abbv) { |
497 // Emit the abbreviation as a record. | 493 // Emit the abbreviation as a record. |
498 EncodeAbbrev(Abbv); | 494 EncodeAbbrev(*Abbv); |
499 CurAbbrevs.push_back(Abbv); | 495 CurAbbrevs.push_back(std::move(Abbv)); |
500 return static_cast<unsigned>(CurAbbrevs.size())-1 + | 496 return static_cast<unsigned>(CurAbbrevs.size())-1 + |
501 bitc::FIRST_APPLICATION_ABBREV; | 497 bitc::FIRST_APPLICATION_ABBREV; |
502 } | 498 } |
503 | 499 |
504 //===--------------------------------------------------------------------===// | 500 //===--------------------------------------------------------------------===// |
507 | 503 |
508 /// EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK. | 504 /// EnterBlockInfoBlock - Start emitting the BLOCKINFO_BLOCK. |
509 void EnterBlockInfoBlock() { | 505 void EnterBlockInfoBlock() { |
510 EnterSubblock(bitc::BLOCKINFO_BLOCK_ID, 2); | 506 EnterSubblock(bitc::BLOCKINFO_BLOCK_ID, 2); |
511 BlockInfoCurBID = ~0U; | 507 BlockInfoCurBID = ~0U; |
508 BlockInfoRecords.clear(); | |
512 } | 509 } |
513 private: | 510 private: |
514 /// SwitchToBlockID - If we aren't already talking about the specified block | 511 /// SwitchToBlockID - If we aren't already talking about the specified block |
515 /// ID, emit a BLOCKINFO_CODE_SETBID record. | 512 /// ID, emit a BLOCKINFO_CODE_SETBID record. |
516 void SwitchToBlockID(unsigned BlockID) { | 513 void SwitchToBlockID(unsigned BlockID) { |
533 | 530 |
534 public: | 531 public: |
535 | 532 |
536 /// EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified | 533 /// EmitBlockInfoAbbrev - Emit a DEFINE_ABBREV record for the specified |
537 /// BlockID. | 534 /// BlockID. |
538 unsigned EmitBlockInfoAbbrev(unsigned BlockID, BitCodeAbbrev *Abbv) { | 535 unsigned EmitBlockInfoAbbrev(unsigned BlockID, std::shared_ptr<BitCodeAbbrev> Abbv) { |
539 SwitchToBlockID(BlockID); | 536 SwitchToBlockID(BlockID); |
540 EncodeAbbrev(Abbv); | 537 EncodeAbbrev(*Abbv); |
541 | 538 |
542 // Add the abbrev to the specified block record. | 539 // Add the abbrev to the specified block record. |
543 BlockInfo &Info = getOrCreateBlockInfo(BlockID); | 540 BlockInfo &Info = getOrCreateBlockInfo(BlockID); |
544 Info.Abbrevs.push_back(Abbv); | 541 Info.Abbrevs.push_back(std::move(Abbv)); |
545 | 542 |
546 return Info.Abbrevs.size()-1+bitc::FIRST_APPLICATION_ABBREV; | 543 return Info.Abbrevs.size()-1+bitc::FIRST_APPLICATION_ABBREV; |
547 } | 544 } |
548 }; | 545 }; |
549 | 546 |