Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 //===- NaClBitcodeHeader.cpp ----------------------------------------------===// | |
| 2 // PNaCl bitcode header reader. | |
| 3 // | |
| 4 // The LLVM Compiler Infrastructure | |
| 5 // | |
| 6 // This file is distributed under the University of Illinois Open Source | |
| 7 // License. See LICENSE.TXT for details. | |
| 8 // | |
| 9 //===----------------------------------------------------------------------===// | |
| 10 // | |
| 11 // Implementation of Bitcode abbrevations. | |
| 12 // | |
| 13 //===----------------------------------------------------------------------===// | |
| 14 | |
| 15 #include "llvm/Bitcode/NaCl/NaClBitCodes.h" | |
| 16 #include "llvm/Support/raw_ostream.h" | |
| 17 #include "llvm/Support/ErrorHandling.h" | |
| 18 | |
| 19 using namespace llvm; | |
| 20 | |
| 21 void NaClBitCodeAbbrevOp::Print(raw_ostream& Stream) const { | |
| 22 if (isLiteral()) { | |
| 23 Stream << getLiteralValue(); | |
| 24 } else if (isEncoding()) { | |
| 25 switch (getEncoding()) { | |
| 26 case Fixed: | |
| 27 Stream << "Fixed(" << getEncodingData() << ")"; | |
| 28 break; | |
| 29 case VBR: | |
| 30 Stream << "VBR(" << getEncodingData() << ")"; | |
| 31 break; | |
| 32 case Array: | |
| 33 Stream << "Array"; | |
| 34 break; | |
| 35 case Char6: | |
| 36 Stream << "Char6"; | |
| 37 break; | |
| 38 case Blob: | |
| 39 Stream << "Blob"; | |
| 40 break; | |
| 41 default: | |
| 42 llvm_unreachable("Unknown bitcode abbreviation operator"); | |
| 43 assert(false); | |
|
jvoung (off chromium)
2014/02/07 23:50:27
can remove the assert(false) then, here and below
Karl
2014/02/10 16:47:01
Done.
| |
| 44 Stream << "??"; // In case asserts are turned off. | |
| 45 break; | |
| 46 } | |
| 47 } else { | |
| 48 llvm_unreachable("Unknown bitcode abbreviation operator"); | |
| 49 assert(false); | |
| 50 Stream << "??"; // In case asserts are turned off. | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 static void PrintExpression(raw_ostream &Stream, | |
| 55 const NaClBitCodeAbbrev *Abbrev, | |
| 56 unsigned &Index) { | |
| 57 // Bail out early, in case we are incrementally building the | |
| 58 // expression and the argument is not available yet. | |
| 59 if (Index >= Abbrev->getNumOperandInfos()) return; | |
| 60 | |
| 61 const NaClBitCodeAbbrevOp &Op = Abbrev->getOperandInfo(Index); | |
| 62 Op.Print(Stream); | |
| 63 if (unsigned NumArgs = Op.NumArguments()) { | |
| 64 Stream << "("; | |
| 65 for (unsigned i = 0; i < NumArgs; ++i) { | |
| 66 ++Index; | |
| 67 if (i > 0) Stream << ","; | |
| 68 PrintExpression(Stream, Abbrev, Index); | |
| 69 } | |
| 70 Stream << ")"; | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 void NaClBitCodeAbbrev::Print(raw_ostream &Stream) const { | |
| 75 Stream << "["; | |
| 76 for (unsigned i = 0; i < getNumOperandInfos(); ++i) { | |
| 77 if (i > 0) Stream << ", "; | |
| 78 PrintExpression(Stream, this, i); | |
| 79 } | |
| 80 Stream << "]\n"; | |
| 81 } | |
| 82 | |
| 83 NaClBitCodeAbbrev *NaClBitCodeAbbrev::Simplify() const { | |
| 84 NaClBitCodeAbbrev *Abbrev = new NaClBitCodeAbbrev(); | |
| 85 for (unsigned i = 0; i < OperandList.size(); ++i) { | |
| 86 const NaClBitCodeAbbrevOp &Op = OperandList[i]; | |
| 87 // Simplify if possible. Currently, the only simplification known | |
| 88 // is to remove unnecessary operands appearing immediately before an | |
| 89 // array operator. That is, apply the simplification: | |
| 90 // Op Array(Op) -> Array(Op) | |
| 91 assert(!Op.isArrayOp() || i == OperandList.size()-2); | |
| 92 while (Op.isArrayOp() && !Abbrev->OperandList.empty() && | |
| 93 Abbrev->OperandList.back() == OperandList[i+1]) { | |
| 94 Abbrev->OperandList.pop_back(); | |
| 95 } | |
| 96 Abbrev->OperandList.push_back(Op); | |
| 97 } | |
| 98 return Abbrev; | |
| 99 } | |
| OLD | NEW |