#include "src/tint/lang/hlsl/writer/ast_printer/ast_printer.h"
#include <cmath>
#include <functional>
#include <iomanip>
#include <utility>
#include <vector>
#include "src/tint/api/common/binding_point.h"
#include "src/tint/lang/core/constant/splat.h"
#include "src/tint/lang/core/constant/value.h"
#include "src/tint/lang/core/fluent_types.h"
#include "src/tint/lang/core/type/array.h"
#include "src/tint/lang/core/type/atomic.h"
#include "src/tint/lang/core/type/depth_multisampled_texture.h"
#include "src/tint/lang/core/type/multisampled_texture.h"
#include "src/tint/lang/core/type/sampled_texture.h"
#include "src/tint/lang/core/type/storage_texture.h"
#include "src/tint/lang/core/type/texture_dimension.h"
#include "src/tint/lang/hlsl/writer/ast_raise/calculate_array_length.h"
#include "src/tint/lang/hlsl/writer/ast_raise/decompose_memory_access.h"
#include "src/tint/lang/hlsl/writer/ast_raise/localize_struct_array_assignment.h"
#include "src/tint/lang/hlsl/writer/ast_raise/num_workgroups_from_uniform.h"
#include "src/tint/lang/hlsl/writer/ast_raise/pixel_local.h"
#include "src/tint/lang/hlsl/writer/ast_raise/truncate_interstage_variables.h"
#include "src/tint/lang/hlsl/writer/common/option_helpers.h"
#include "src/tint/lang/wgsl/ast/call_statement.h"
#include "src/tint/lang/wgsl/ast/internal_attribute.h"
#include "src/tint/lang/wgsl/ast/interpolate_attribute.h"
#include "src/tint/lang/wgsl/ast/transform/add_empty_entry_point.h"
#include "src/tint/lang/wgsl/ast/transform/array_length_from_uniform.h"
#include "src/tint/lang/wgsl/ast/transform/binding_remapper.h"
#include "src/tint/lang/wgsl/ast/transform/builtin_polyfill.h"
#include "src/tint/lang/wgsl/ast/transform/canonicalize_entry_point_io.h"
#include "src/tint/lang/wgsl/ast/transform/demote_to_helper.h"
#include "src/tint/lang/wgsl/ast/transform/direct_variable_access.h"
#include "src/tint/lang/wgsl/ast/transform/disable_uniformity_analysis.h"
#include "src/tint/lang/wgsl/ast/transform/expand_compound_assignment.h"
#include "src/tint/lang/wgsl/ast/transform/fold_constants.h"
#include "src/tint/lang/wgsl/ast/transform/manager.h"
#include "src/tint/lang/wgsl/ast/transform/multiplanar_external_texture.h"
#include "src/tint/lang/wgsl/ast/transform/promote_initializers_to_let.h"
#include "src/tint/lang/wgsl/ast/transform/promote_side_effects_to_decl.h"
#include "src/tint/lang/wgsl/ast/transform/remove_continue_in_switch.h"
#include "src/tint/lang/wgsl/ast/transform/remove_phonies.h"
#include "src/tint/lang/wgsl/ast/transform/robustness.h"
#include "src/tint/lang/wgsl/ast/transform/simplify_pointers.h"
#include "src/tint/lang/wgsl/ast/transform/unshadow.h"
#include "src/tint/lang/wgsl/ast/transform/vectorize_scalar_matrix_initializers.h"
#include "src/tint/lang/wgsl/ast/transform/zero_init_workgroup_memory.h"
#include "src/tint/lang/wgsl/ast/variable_decl_statement.h"
#include "src/tint/lang/wgsl/helpers/append_vector.h"
#include "src/tint/lang/wgsl/helpers/check_supported_extensions.h"
#include "src/tint/lang/wgsl/sem/block_statement.h"
#include "src/tint/lang/wgsl/sem/call.h"
#include "src/tint/lang/wgsl/sem/function.h"
#include "src/tint/lang/wgsl/sem/member_accessor_expression.h"
#include "src/tint/lang/wgsl/sem/module.h"
#include "src/tint/lang/wgsl/sem/statement.h"
#include "src/tint/lang/wgsl/sem/struct.h"
#include "src/tint/lang/wgsl/sem/switch_statement.h"
#include "src/tint/lang/wgsl/sem/value_constructor.h"
#include "src/tint/lang/wgsl/sem/value_conversion.h"
#include "src/tint/lang/wgsl/sem/variable.h"
#include "src/tint/utils/containers/map.h"
#include "src/tint/utils/ice/ice.h"
#include "src/tint/utils/macros/compiler.h"
#include "src/tint/utils/macros/defer.h"
#include "src/tint/utils/macros/scoped_assignment.h"
#include "src/tint/utils/rtti/switch.h"
#include "src/tint/utils/strconv/float_to_string.h"
#include "src/tint/utils/text/string.h"
#include "src/tint/utils/text/string_stream.h"
usingnamespacetint::core::number_suffixes;
usingnamespacetint::core::fluent_types;
namespace tint::hlsl::writer {
namespace {
const char kTempNamePrefix[] = …;
const char* ImageFormatToRWtextureType(core::TexelFormat image_format) { … }
void PrintF32(StringStream& out, float value) { … }
void PrintF16(StringStream& out, float value) { … }
struct RegisterAndSpace { … };
StringStream& operator<<(StringStream& s, const RegisterAndSpace& rs) { … }
}
SanitizedResult::SanitizedResult() = default;
SanitizedResult::~SanitizedResult() = default;
SanitizedResult::SanitizedResult(SanitizedResult&&) = default;
SanitizedResult Sanitize(const Program& in, const Options& options) { … }
ASTPrinter::ASTPrinter(const Program& program) : … { … }
ASTPrinter::~ASTPrinter() = default;
bool ASTPrinter::Generate() { … }
bool ASTPrinter::EmitDynamicVectorAssignment(const ast::AssignmentStatement* stmt,
const core::type::Vector* vec) { … }
bool ASTPrinter::EmitDynamicMatrixVectorAssignment(const ast::AssignmentStatement* stmt,
const core::type::Matrix* mat) { … }
bool ASTPrinter::EmitDynamicMatrixScalarAssignment(const ast::AssignmentStatement* stmt,
const core::type::Matrix* mat) { … }
bool ASTPrinter::EmitIndexAccessor(StringStream& out, const ast::IndexAccessorExpression* expr) { … }
bool ASTPrinter::EmitBitcastCall(StringStream& out, const ast::CallExpression* call) { … }
bool ASTPrinter::EmitAssign(const ast::AssignmentStatement* stmt) { … }
bool ASTPrinter::EmitBinary(StringStream& out, const ast::BinaryExpression* expr) { … }
bool ASTPrinter::EmitStatements(VectorRef<const ast::Statement*> stmts) { … }
bool ASTPrinter::EmitStatementsWithIndent(VectorRef<const ast::Statement*> stmts) { … }
bool ASTPrinter::EmitBlock(const ast::BlockStatement* stmt) { … }
bool ASTPrinter::EmitBreak(const ast::BreakStatement*) { … }
bool ASTPrinter::EmitBreakIf(const ast::BreakIfStatement* b) { … }
bool ASTPrinter::EmitCall(StringStream& out, const ast::CallExpression* expr) { … }
bool ASTPrinter::EmitFunctionCall(StringStream& out,
const sem::Call* call,
const sem::Function* func) { … }
bool ASTPrinter::EmitBuiltinCall(StringStream& out,
const sem::Call* call,
const sem::BuiltinFn* builtin) { … }
bool ASTPrinter::EmitValueConversion(StringStream& out,
const sem::Call* call,
const sem::ValueConversion* conv) { … }
bool ASTPrinter::EmitValueConstructor(StringStream& out,
const sem::Call* call,
const sem::ValueConstructor* ctor) { … }
bool ASTPrinter::EmitUniformBufferAccess(StringStream& out,
const ast::CallExpression* expr,
const DecomposeMemoryAccess::Intrinsic* intrinsic) { … }
bool ASTPrinter::EmitStorageBufferAccess(StringStream& out,
const ast::CallExpression* expr,
const DecomposeMemoryAccess::Intrinsic* intrinsic) { … }
bool ASTPrinter::EmitStorageAtomicIntrinsic(const ast::Function* func,
const DecomposeMemoryAccess::Intrinsic* intrinsic) { … }
bool ASTPrinter::EmitWorkgroupAtomicCall(StringStream& out,
const ast::CallExpression* expr,
const sem::BuiltinFn* builtin) { … }
bool ASTPrinter::EmitSelectCall(StringStream& out, const ast::CallExpression* expr) { … }
bool ASTPrinter::EmitModfCall(StringStream& out,
const ast::CallExpression* expr,
const sem::BuiltinFn* builtin) { … }
bool ASTPrinter::EmitFrexpCall(StringStream& out,
const ast::CallExpression* expr,
const sem::BuiltinFn* builtin) { … }
bool ASTPrinter::EmitDegreesCall(StringStream& out,
const ast::CallExpression* expr,
const sem::BuiltinFn* builtin) { … }
bool ASTPrinter::EmitRadiansCall(StringStream& out,
const ast::CallExpression* expr,
const sem::BuiltinFn* builtin) { … }
bool ASTPrinter::EmitSignCall(StringStream& out, const sem::Call* call, const sem::BuiltinFn*) { … }
bool ASTPrinter::EmitQuantizeToF16Call(StringStream& out,
const ast::CallExpression* expr,
const sem::BuiltinFn* builtin) { … }
bool ASTPrinter::EmitTruncCall(StringStream& out,
const ast::CallExpression* expr,
const sem::BuiltinFn* builtin) { … }
bool ASTPrinter::EmitDataPackingCall(StringStream& out,
const ast::CallExpression* expr,
const sem::BuiltinFn* builtin) { … }
bool ASTPrinter::EmitDataUnpackingCall(StringStream& out,
const ast::CallExpression* expr,
const sem::BuiltinFn* builtin) { … }
bool ASTPrinter::EmitPacked4x8IntegerDotProductBuiltinCall(StringStream& out,
const ast::CallExpression* expr,
const sem::BuiltinFn* builtin) { … }
bool ASTPrinter::EmitBarrierCall(StringStream& out, const sem::BuiltinFn* builtin) { … }
bool ASTPrinter::EmitTextureOrStorageBufferCallArgExpression(StringStream& out,
const ast::Expression* expr) { … }
bool ASTPrinter::EmitTextureCall(StringStream& out,
const sem::Call* call,
const sem::BuiltinFn* builtin) { … }
bool ASTPrinter::EmitSubgroupShuffleBuiltinCall(StringStream& out,
const ast::CallExpression* expr,
const sem::BuiltinFn* builtin) { … }
std::string ASTPrinter::generate_builtin_name(const sem::BuiltinFn* builtin) { … }
bool ASTPrinter::EmitCase(const ast::SwitchStatement* s, size_t case_idx) { … }
bool ASTPrinter::EmitContinue(const ast::ContinueStatement*) { … }
bool ASTPrinter::EmitDiscard(const ast::DiscardStatement*) { … }
bool ASTPrinter::EmitExpression(StringStream& out, const ast::Expression* expr) { … }
bool ASTPrinter::EmitIdentifier(StringStream& out, const ast::IdentifierExpression* expr) { … }
bool ASTPrinter::EmitIf(const ast::IfStatement* stmt) { … }
bool ASTPrinter::EmitFunction(const ast::Function* func) { … }
bool ASTPrinter::EmitFunctionBodyWithDiscard(const ast::Function* func) { … }
bool ASTPrinter::EmitGlobalVariable(const ast::Variable* global) { … }
bool ASTPrinter::EmitUniformVariable(const ast::Var* var, const sem::Variable* sem) { … }
bool ASTPrinter::EmitStorageVariable(const ast::Var* var, const sem::Variable* sem) { … }
bool ASTPrinter::EmitHandleVariable(const ast::Var* var, const sem::Variable* sem) { … }
bool ASTPrinter::EmitPrivateVariable(const sem::Variable* var) { … }
bool ASTPrinter::EmitWorkgroupVariable(const sem::Variable* var) { … }
std::string ASTPrinter::builtin_to_attribute(core::BuiltinValue builtin) const { … }
std::string ASTPrinter::interpolation_to_modifiers(core::InterpolationType type,
core::InterpolationSampling sampling) const { … }
bool ASTPrinter::EmitEntryPointFunction(const ast::Function* func) { … }
bool ASTPrinter::EmitConstant(StringStream& out,
const core::constant::Value* constant,
bool is_variable_initializer) { … }
bool ASTPrinter::EmitLiteral(StringStream& out, const ast::LiteralExpression* lit) { … }
bool ASTPrinter::EmitValue(StringStream& out, const core::type::Type* type, int value) { … }
bool ASTPrinter::EmitZeroValue(StringStream& out, const core::type::Type* type) { … }
bool ASTPrinter::EmitLoop(const ast::LoopStatement* stmt) { … }
bool ASTPrinter::EmitForLoop(const ast::ForLoopStatement* stmt) { … }
bool ASTPrinter::EmitWhile(const ast::WhileStatement* stmt) { … }
bool ASTPrinter::EmitMemberAccessor(StringStream& out, const ast::MemberAccessorExpression* expr) { … }
bool ASTPrinter::EmitReturn(const ast::ReturnStatement* stmt) { … }
bool ASTPrinter::EmitStatement(const ast::Statement* stmt) { … }
bool ASTPrinter::EmitDefaultOnlySwitch(const ast::SwitchStatement* stmt) { … }
bool ASTPrinter::EmitSwitch(const ast::SwitchStatement* stmt) { … }
bool ASTPrinter::EmitType(StringStream& out,
const core::type::Type* type,
core::AddressSpace address_space,
core::Access access,
const std::string& name,
bool* name_printed ) { … }
bool ASTPrinter::EmitTypeAndName(StringStream& out,
const core::type::Type* type,
core::AddressSpace address_space,
core::Access access,
const std::string& name) { … }
bool ASTPrinter::EmitStructType(TextBuffer* b,
const core::type::Struct* str,
VectorRef<const ast::StructMember*> ast_struct_members) { … }
bool ASTPrinter::EmitUnaryOp(StringStream& out, const ast::UnaryOpExpression* expr) { … }
bool ASTPrinter::EmitVar(const ast::Var* var) { … }
bool ASTPrinter::EmitLet(const ast::Let* let) { … }
template <typename F>
bool ASTPrinter::CallBuiltinHelper(StringStream& out,
const ast::CallExpression* call,
const sem::BuiltinFn* builtin,
F&& build) { … }
std::string ASTPrinter::StructName(const core::type::Struct* s) { … }
std::string ASTPrinter::UniqueIdentifier(const std::string& prefix ) { … }
}