[PATCH] D41979: [bcanalyzer] Recognize more stream types

Brian Gesiak via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 12 09:22:00 PST 2018


modocache updated this revision to Diff 129642.
modocache added a comment.

Add tests directly to the LLVM test suite. Thanks, @davide!


https://reviews.llvm.org/D41979

Files:
  test/Bitcode/stream-types.c
  test/Bitcode/stream-types.c.ast
  test/Bitcode/stream-types.c.dia
  tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp


Index: tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
===================================================================
--- tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
+++ tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp
@@ -75,7 +75,9 @@
 /// CurStreamTypeType - A type for CurStreamType
 enum CurStreamTypeType {
   UnknownBitstream,
-  LLVMIRBitstream
+  LLVMIRBitstream,
+  ClangSerializedASTBitstream,
+  ClangSerializedDiagnosticsBitstream,
 };
 
 }
@@ -791,17 +793,29 @@
   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;
+  if (Signature[0] == 'C' && Signature[1] == 'P') {
+    Signature[2] = Stream.Read(8);
+    Signature[3] = Stream.Read(8);
+    if (Signature[2] == 'C' && Signature[3] == 'H')
+      CurStreamType = 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')
+      CurStreamType = 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)
+      CurStreamType = LLVMIRBitstream;
+  }
 
   return false;
 }
@@ -870,8 +884,18 @@
   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";
Index: test/Bitcode/stream-types.c
===================================================================
--- /dev/null
+++ test/Bitcode/stream-types.c
@@ -0,0 +1,18 @@
+// Tests that llvm-bcanalyzer recognizes the correct "stream type" for various
+// common bitstream formats.
+
+
+// stream-types.c.ast was generated by running:
+//   clang -emit-ast stream-types.c -o stream-types.c.ast
+//
+// RUN: llvm-bcanalyzer -dump %s.ast | FileCheck %s -check-prefix=CHECK-AST
+// CHECK-AST: Stream type: Clang Serialized AST
+
+
+// stream-types.c.dia was generated by running:
+//    clang stream-types.c \
+//      -serialize-diagnostics stream-types.c.dia \
+//      -fsyntax-only
+//
+// RUN: llvm-bcanalyzer -dump %s.dia | FileCheck %s -check-prefix=CHECK-DIAG
+// CHECK-DIAG: Stream type: Clang Serialized Diagnostics


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41979.129642.patch
Type: text/x-patch
Size: 3293 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180112/c68a660a/attachment.bin>


More information about the llvm-commits mailing list