llvm-project/clang/lib/AST/HLSLResource.cpp
Helena Kotas 39b6a4d84a
[HLSL] Add globals for resources embedded in structs (#184281)
For each resource or resource array member of a struct declared at global scope or inside a `cbuffer`, create an implicit global variable of the same resource type. The variable name will be derived from the struct instance name and the member name and will be associated with the struct declaration using a new attribute `HLSLAssociatedResourceDeclAttr`.

Closes #182988
2026-03-18 17:40:13 -07:00

46 lines
1.3 KiB
C++

//===--- HLSLResource.cpp - Helper routines for HLSL resources -----------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file provides shared routines to help analyze HLSL resources and
// their bindings during Sema and CodeGen.
//
//===----------------------------------------------------------------------===//
#include "clang/AST/HLSLResource.h"
#include "clang/AST/Decl.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/Type.h"
using namespace clang;
namespace clang {
namespace hlsl {
void EmbeddedResourceNameBuilder::pushBaseName(llvm::StringRef N) {
pushName(N, FieldDelim);
Name.append(BaseClassDelim);
}
void EmbeddedResourceNameBuilder::pushName(llvm::StringRef N,
llvm::StringRef Delim) {
Offsets.push_back(Name.size());
if (!Name.empty() && !Name.ends_with(BaseClassDelim))
Name.append(Delim);
Name.append(N);
}
void EmbeddedResourceNameBuilder::pushArrayIndex(uint64_t Index) {
llvm::raw_svector_ostream OS(Name);
Offsets.push_back(Name.size());
OS << ArrayIndexDelim;
OS << Index;
}
} // namespace hlsl
} // namespace clang