Browse Source

Dump HLSLBufferDecl info in ASTDumper::dumpDecl.

Xiang Li 8 years ago
parent
commit
06d3407ed4

+ 1 - 1
tools/clang/include/clang/AST/Decl.h

@@ -3857,7 +3857,7 @@ public:
   virtual SourceRange getSourceRange() const LLVM_READONLY{
   virtual SourceRange getSourceRange() const LLVM_READONLY{
     return SourceRange(getLocStart(), RBraceLoc);
     return SourceRange(getLocStart(), RBraceLoc);
   }
   }
-
+  const char *getDeclKindName() const;
   SourceLocation getLocStart() const LLVM_READONLY{ return KwLoc; }
   SourceLocation getLocStart() const LLVM_READONLY{ return KwLoc; }
   SourceLocation getRBraceLoc() const { return RBraceLoc; }
   SourceLocation getRBraceLoc() const { return RBraceLoc; }
   void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }
   void setRBraceLoc(SourceLocation L) { RBraceLoc = L; }

+ 7 - 0
tools/clang/lib/AST/ASTDumper.cpp

@@ -1068,6 +1068,13 @@ void ASTDumper::dumpDecl(const Decl *D) {
     dumpPointer(D);
     dumpPointer(D);
     if (D->getLexicalDeclContext() != D->getDeclContext())
     if (D->getLexicalDeclContext() != D->getDeclContext())
       OS << " parent " << cast<Decl>(D->getDeclContext());
       OS << " parent " << cast<Decl>(D->getDeclContext());
+    // HLSL Change Begin - dump HLSLBufferDecl
+    if (const HLSLBufferDecl *bufDecl =
+            dyn_cast_or_null<HLSLBufferDecl>(D->getDeclContext())) {
+      OS << " parent " << bufDecl->getDeclKindName();
+      dumpPointer(bufDecl);
+    }
+    // HLSL Change End
     dumpPreviousDecl(OS, D);
     dumpPreviousDecl(OS, D);
     dumpSourceRange(D->getSourceRange());
     dumpSourceRange(D->getSourceRange());
     OS << ' ';
     OS << ' ';

+ 7 - 0
tools/clang/lib/Sema/SemaHLSL.cpp

@@ -10409,6 +10409,13 @@ HLSLBufferDecl::Create(ASTContext &C, DeclContext *lexicalParent, bool cbuffer,
   return result;
   return result;
 }
 }
 
 
+const char *HLSLBufferDecl::getDeclKindName() const {
+  static const char *HLSLBufferNames[] = {"tbuffer", "cbuffer", "TextureBuffer",
+                                          "ConstantBuffer"};
+  unsigned index = isCBuffer() | (isConstantBufferView()) << 1;
+  return HLSLBufferNames[index];
+}
+
 void Sema::TransferUnusualAttributes(Declarator &D, NamedDecl *NewDecl) {
 void Sema::TransferUnusualAttributes(Declarator &D, NamedDecl *NewDecl) {
   assert(NewDecl != nullptr);
   assert(NewDecl != nullptr);
 
 

+ 28 - 0
tools/clang/test/HLSL/ctbuf.hlsl

@@ -0,0 +1,28 @@
+// RUN: %dxc -T lib_6_1 -ast-dump %s | FileCheck %s
+
+struct S {
+  float4 f;
+};
+
+// CHECK: ConstantBuffer
+// CHECK: <line:9:16, col:19> col:19 myCBuffer 'const S'
+ConstantBuffer<S> myCBuffer;
+// CHECK: TextureBuffer
+// CHECK: <line:12:15, col:18> col:18 myTBffer 'const S'
+TextureBuffer<S> myTBffer;
+
+// CHECK: cbuffer
+// CHECK: <line:18:3, col:5> col:5 c0 'const S'
+
+cbuffer A {
+  S c0;
+};
+
+// CHECK: tbuffer
+// CHECK: <line:24:3, col:5> col:5 t0 'const S'
+tbuffer B {
+  S t0;
+};
+float main() : A {
+  return 1.0;
+}

+ 5 - 0
tools/clang/unittests/HLSL/CompilerTest.cpp

@@ -410,6 +410,7 @@ public:
   TEST_METHOD(CompileHlsl2016ThenOK)
   TEST_METHOD(CompileHlsl2016ThenOK)
   TEST_METHOD(CompileHlsl2017ThenOK)
   TEST_METHOD(CompileHlsl2017ThenOK)
   TEST_METHOD(CompileHlsl2018ThenFail)
   TEST_METHOD(CompileHlsl2018ThenFail)
+  TEST_METHOD(CompileCBufferTBufferASTDump)
 
 
   TEST_METHOD(DiaLoadBadBitcodeThenFail)
   TEST_METHOD(DiaLoadBadBitcodeThenFail)
   TEST_METHOD(DiaLoadDebugThenOK)
   TEST_METHOD(DiaLoadDebugThenOK)
@@ -2729,6 +2730,10 @@ TEST_F(CompilerTest, CompileHlsl2018ThenFail) {
   CheckOperationResultMsgs(pResult, &pErrorMsg, 1, false, false);
   CheckOperationResultMsgs(pResult, &pErrorMsg, 1, false, false);
 }
 }
 
 
+TEST_F(CompilerTest, CompileCBufferTBufferASTDump) {
+  CodeGenTestCheck(L"ctbuf.hlsl");
+}
+
 TEST_F(CompilerTest, DiaLoadBadBitcodeThenFail) {
 TEST_F(CompilerTest, DiaLoadBadBitcodeThenFail) {
   CComPtr<IDxcBlob> pBadBitcode;
   CComPtr<IDxcBlob> pBadBitcode;
   CComPtr<IDiaDataSource> pDiaSource;
   CComPtr<IDiaDataSource> pDiaSource;

+ 6 - 2
tools/clang/unittests/HLSL/FileCheckerTest.cpp

@@ -232,8 +232,12 @@ static string trim(string value) {
       IFT(pResult->GetStatus(&resultStatus));
       IFT(pResult->GetStatus(&resultStatus));
       if (SUCCEEDED(resultStatus)) {
       if (SUCCEEDED(resultStatus)) {
         IFT(pResult->GetResult(&pCompiledBlob));
         IFT(pResult->GetResult(&pCompiledBlob));
-        IFT(pCompiler->Disassemble(pCompiledBlob, &pDisassembly));
-        StdOut = BlobToUtf8(pDisassembly);
+        if (!opts.AstDump) {
+          IFT(pCompiler->Disassemble(pCompiledBlob, &pDisassembly));
+          StdOut = BlobToUtf8(pDisassembly);
+        } else {
+          StdOut = BlobToUtf8(pCompiledBlob);
+        }
         CComPtr<IDxcBlobEncoding> pStdErr;
         CComPtr<IDxcBlobEncoding> pStdErr;
         IFT(pResult->GetErrorBuffer(&pStdErr));
         IFT(pResult->GetErrorBuffer(&pStdErr));
         StdErr = BlobToUtf8(pStdErr);
         StdErr = BlobToUtf8(pStdErr);