diff options
Diffstat (limited to 'llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp')
| -rw-r--r-- | llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp | 64 |
1 files changed, 45 insertions, 19 deletions
diff --git a/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp index 1252ed5df8a..5b10b091ade 100644 --- a/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp +++ b/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp @@ -75,7 +75,9 @@ namespace { /// CurStreamTypeType - A type for CurStreamType enum CurStreamTypeType { UnknownBitstream, - LLVMIRBitstream + LLVMIRBitstream, + ClangSerializedASTBitstream, + ClangSerializedDiagnosticsBitstream, }; } @@ -746,6 +748,35 @@ static void PrintSize(uint64_t Bits) { (double)Bits/8, (unsigned long)(Bits/32)); } +static CurStreamTypeType ReadSignature(BitstreamCursor &Stream) { + char Signature[6]; + Signature[0] = Stream.Read(8); + Signature[1] = Stream.Read(8); + + // Autodetect the file contents, if it is one we know. + if (Signature[0] == 'C' && Signature[1] == 'P') { + Signature[2] = Stream.Read(8); + Signature[3] = Stream.Read(8); + if (Signature[2] == 'C' && Signature[3] == 'H') + return ClangSerializedASTBitstream; + } else if (Signature[0] == 'D' && Signature[1] == 'I') { + Signature[2] = Stream.Read(8); + Signature[3] = Stream.Read(8); + if (Signature[2] == 'A' && Signature[3] == 'G') + return ClangSerializedDiagnosticsBitstream; + } else { + Signature[2] = Stream.Read(4); + Signature[3] = Stream.Read(4); + Signature[4] = Stream.Read(4); + Signature[5] = Stream.Read(4); + if (Signature[0] == 'B' && Signature[1] == 'C' && + Signature[2] == 0x0 && Signature[3] == 0xC && + Signature[4] == 0xE && Signature[5] == 0xD) + return LLVMIRBitstream; + } + return UnknownBitstream; +} + static bool openBitcodeFile(StringRef Path, std::unique_ptr<MemoryBuffer> &MemBuf, BitstreamCursor &Stream, @@ -789,22 +820,7 @@ static bool openBitcodeFile(StringRef Path, } Stream = BitstreamCursor(ArrayRef<uint8_t>(BufPtr, EndBufPtr)); - - // Read the stream signature. - char Signature[6]; - Signature[0] = Stream.Read(8); - Signature[1] = Stream.Read(8); - Signature[2] = Stream.Read(4); - Signature[3] = Stream.Read(4); - Signature[4] = Stream.Read(4); - Signature[5] = Stream.Read(4); - - // Autodetect the file contents, if it is one we know. - CurStreamType = UnknownBitstream; - if (Signature[0] == 'B' && Signature[1] == 'C' && - Signature[2] == 0x0 && Signature[3] == 0xC && - Signature[4] == 0xE && Signature[5] == 0xD) - CurStreamType = LLVMIRBitstream; + CurStreamType = ReadSignature(Stream); return false; } @@ -873,8 +889,18 @@ static int AnalyzeBitcode() { outs() << "\n"; outs() << " Stream type: "; switch (CurStreamType) { - case UnknownBitstream: outs() << "unknown\n"; break; - case LLVMIRBitstream: outs() << "LLVM IR\n"; break; + case UnknownBitstream: + outs() << "unknown\n"; + break; + case LLVMIRBitstream: + outs() << "LLVM IR\n"; + break; + case ClangSerializedASTBitstream: + outs() << "Clang Serialized AST\n"; + break; + case ClangSerializedDiagnosticsBitstream: + outs() << "Clang Serialized Diagnostics\n"; + break; } outs() << " # Toplevel Blocks: " << NumTopBlocks << "\n"; outs() << "\n"; |

