Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(675)

Side by Side Diff: include/llvm/Bitcode/NaCl/NaClBitstreamWriter.h

Issue 1156103003: Initial implementation of a record-level bitcode fuzzer. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@fuzz
Patch Set: Fix nits. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 //===- NaClBitstreamWriter.h - NaCl bitstream writer ------------*- C++ -*-===// 1 //===- NaClBitstreamWriter.h - NaCl bitstream writer ------------*- C++ -*-===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This header defines the BitstreamWriter class. This class can be used to 10 // This header defines the BitstreamWriter class. This class can be used to
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 424 }
425 } 425 }
426 assert(RecordIdx == Vals.size() && "Not all record operands emitted!"); 426 assert(RecordIdx == Vals.size() && "Not all record operands emitted!");
427 } 427 }
428 428
429 public: 429 public:
430 430
431 /// Returns a pointer to the abbreviation currently associated with 431 /// Returns a pointer to the abbreviation currently associated with
432 /// the abbreviation index. Returns nullptr if no such abbreviation. 432 /// the abbreviation index. Returns nullptr if no such abbreviation.
433 const NaClBitCodeAbbrev *getAbbreviation(unsigned Index) const { 433 const NaClBitCodeAbbrev *getAbbreviation(unsigned Index) const {
434 if (Index < naclbitc::FIRST_APPLICATION_ABBREV) 434 if (Index < naclbitc::FIRST_APPLICATION_ABBREV
435 return nullptr; 435 || BlockScope.empty()
436 if (Index >= BlockScope.back().AbbreviationIndexLimit) 436 || Index >= BlockScope.back().AbbreviationIndexLimit)
437 return nullptr; 437 return nullptr;
438 unsigned AbbrevNo = Index - naclbitc::FIRST_APPLICATION_ABBREV; 438 unsigned AbbrevNo = Index - naclbitc::FIRST_APPLICATION_ABBREV;
439 if (AbbrevNo >= CurAbbrevs.size()) 439 if (AbbrevNo >= CurAbbrevs.size())
440 return nullptr; 440 return nullptr;
441 return CurAbbrevs[AbbrevNo]; 441 return CurAbbrevs[AbbrevNo];
442 } 442 }
443 443
444 /// EmitRecord - Emit the specified record to the stream, using an abbrev if 444 /// EmitRecord - Emit the specified record to the stream, using an abbrev if
445 /// we have one to compress the output. 445 /// we have one to compress the output.
446 template<typename uintty> 446 template<typename uintty>
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 } 487 }
488 } 488 }
489 flushToByteIfAligned(); 489 flushToByteIfAligned();
490 } 490 }
491 public: 491 public:
492 492
493 /// EmitAbbrev - This emits an abbreviation to the stream. Note that this 493 /// EmitAbbrev - This emits an abbreviation to the stream. Note that this
494 /// method takes ownership of the specified abbrev. 494 /// method takes ownership of the specified abbrev.
495 unsigned EmitAbbrev(NaClBitCodeAbbrev *Abbv) { 495 unsigned EmitAbbrev(NaClBitCodeAbbrev *Abbv) {
496 assert(Abbv->isValid() && "Can't emit invalid abbreviation!"); 496 assert(Abbv->isValid() && "Can't emit invalid abbreviation!");
497 assert(!BlockScope.empty() && "Can't emit abbreviations outside of blocks");
497 // Emit the abbreviation as a record. 498 // Emit the abbreviation as a record.
498 EncodeAbbrev(Abbv); 499 EncodeAbbrev(Abbv);
499 CurAbbrevs.push_back(Abbv); 500 CurAbbrevs.push_back(Abbv);
500 return static_cast<unsigned>(CurAbbrevs.size())-1 + 501 return static_cast<unsigned>(CurAbbrevs.size())-1 +
501 naclbitc::FIRST_APPLICATION_ABBREV; 502 naclbitc::FIRST_APPLICATION_ABBREV;
502 } 503 }
503 504
504 //===--------------------------------------------------------------------===// 505 //===--------------------------------------------------------------------===//
505 // BlockInfo Block Emission 506 // BlockInfo Block Emission
506 //===--------------------------------------------------------------------===// 507 //===--------------------------------------------------------------------===//
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 Info.Abbrevs.push_back(Abbv); 545 Info.Abbrevs.push_back(Abbv);
545 546
546 return Info.Abbrevs.size()-1+naclbitc::FIRST_APPLICATION_ABBREV; 547 return Info.Abbrevs.size()-1+naclbitc::FIRST_APPLICATION_ABBREV;
547 } 548 }
548 }; 549 };
549 550
550 551
551 } // End llvm namespace 552 } // End llvm namespace
552 553
553 #endif 554 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698