chromium/third_party/dawn/src/tint/lang/glsl/writer/ast_printer/ast_printer.cc

/// Copyright 2021 The Dawn & Tint Authors
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
//    list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
//    this list of conditions and the following disclaimer in the documentation
//    and/or other materials provided with the distribution.
//
// 3. Neither the name of the copyright holder nor the names of its
//    contributors may be used to endorse or promote products derived from
//    this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "src/tint/lang/glsl/writer/ast_printer/ast_printer.h"

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <limits>
#include <set>
#include <utility>
#include <vector>

#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/depth_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/glsl/writer/ast_raise/combine_samplers.h"
#include "src/tint/lang/glsl/writer/ast_raise/pad_structs.h"
#include "src/tint/lang/glsl/writer/ast_raise/texture_1d_to_2d.h"
#include "src/tint/lang/glsl/writer/ast_raise/texture_builtins_from_uniform.h"
#include "src/tint/lang/glsl/writer/common/option_helpers.h"
#include "src/tint/lang/glsl/writer/common/options.h"
#include "src/tint/lang/glsl/writer/common/printer_support.h"
#include "src/tint/lang/wgsl/ast/call_statement.h"
#include "src/tint/lang/wgsl/ast/id_attribute.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_block_attribute.h"
#include "src/tint/lang/wgsl/ast/transform/add_empty_entry_point.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/clamp_frag_depth.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/offset_first_index.h"
#include "src/tint/lang/wgsl/ast/transform/preserve_padding.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/renamer.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/single_entry_point.h"
#include "src/tint/lang/wgsl/ast/transform/std140.h"
#include "src/tint/lang/wgsl/ast/transform/unshadow.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/builtin_enum_expression.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/defer.h"
#include "src/tint/utils/macros/scoped_assignment.h"
#include "src/tint/utils/rtti/switch.h"
#include "src/tint/utils/text/string.h"
#include "src/tint/utils/text/string_stream.h"

usingnamespacetint::core::number_suffixes;  // NOLINT
usingnamespacetint::core::fluent_types;     // NOLINT

namespace tint::glsl::writer {
namespace {

const char kTempNamePrefix[] =;

bool last_is_break(const ast::BlockStatement* stmts) {}

bool IsRelational(tint::core::BinaryOp op) {}

bool RequiresOESSampleVariables(tint::core::BuiltinValue builtin) {}

}  // namespace

SanitizedResult::SanitizedResult() = default;
SanitizedResult::~SanitizedResult() = default;
SanitizedResult::SanitizedResult(SanitizedResult&&) = default;

SanitizedResult Sanitize(const Program& in,
                         const Options& options,
                         const std::string& entry_point) {}

ASTPrinter::ASTPrinter(const Program& program, const Version& version)
    :{}

ASTPrinter::~ASTPrinter() = default;

bool ASTPrinter::Generate() {}

void ASTPrinter::RecordExtension(const ast::Enable* enable) {}

void ASTPrinter::EmitIndexAccessor(StringStream& out, const ast::IndexAccessorExpression* expr) {}

void ASTPrinter::EmitBitcastCall(StringStream& out, const ast::CallExpression* call) {}

void ASTPrinter::EmitAssign(const ast::AssignmentStatement* stmt) {}

void ASTPrinter::EmitVectorRelational(StringStream& out, const ast::BinaryExpression* expr) {}

void ASTPrinter::EmitBitwiseBoolOp(StringStream& out, const ast::BinaryExpression* expr) {}

void ASTPrinter::EmitFloatModulo(StringStream& out, const ast::BinaryExpression* expr) {}

void ASTPrinter::EmitBinary(StringStream& out, const ast::BinaryExpression* expr) {}

void ASTPrinter::EmitStatements(VectorRef<const ast::Statement*> stmts) {}

void ASTPrinter::EmitStatementsWithIndent(VectorRef<const ast::Statement*> stmts) {}

void ASTPrinter::EmitBlock(const ast::BlockStatement* stmt) {}

void ASTPrinter::EmitBreak(const ast::BreakStatement*) {}

void ASTPrinter::EmitBreakIf(const ast::BreakIfStatement* b) {}

void ASTPrinter::EmitCall(StringStream& out, const ast::CallExpression* expr) {}

void ASTPrinter::EmitFunctionCall(StringStream& out,
                                  const sem::Call* call,
                                  const sem::Function* fn) {}

void ASTPrinter::EmitBuiltinCall(StringStream& out,
                                 const sem::Call* call,
                                 const sem::BuiltinFn* builtin) {}

void ASTPrinter::EmitValueConversion(StringStream& out,
                                     const sem::Call* call,
                                     const sem::ValueConversion* conv) {}

void ASTPrinter::EmitValueConstructor(StringStream& out,
                                      const sem::Call* call,
                                      const sem::ValueConstructor* ctor) {}

void ASTPrinter::EmitWorkgroupAtomicCall(StringStream& out,
                                         const ast::CallExpression* expr,
                                         const sem::BuiltinFn* builtin) {}

void ASTPrinter::EmitArrayLength(StringStream& out, const ast::CallExpression* expr) {}

void ASTPrinter::EmitExtractBits(StringStream& out, const ast::CallExpression* expr) {}

void ASTPrinter::EmitInsertBits(StringStream& out, const ast::CallExpression* expr) {}

void ASTPrinter::EmitEmulatedFMA(StringStream& out, const ast::CallExpression* expr) {}

void ASTPrinter::EmitCountOneBitsCall(StringStream& out, const ast::CallExpression* expr) {}

void ASTPrinter::EmitSelectCall(StringStream& out,
                                const ast::CallExpression* expr,
                                const sem::BuiltinFn* builtin) {}

void ASTPrinter::EmitDotCall(StringStream& out,
                             const ast::CallExpression* expr,
                             const sem::BuiltinFn* builtin) {}

void ASTPrinter::EmitModfCall(StringStream& out,
                              const ast::CallExpression* expr,
                              const sem::BuiltinFn* builtin) {}

void ASTPrinter::EmitFrexpCall(StringStream& out,
                               const ast::CallExpression* expr,
                               const sem::BuiltinFn* builtin) {}

void ASTPrinter::EmitDegreesCall(StringStream& out,
                                 const ast::CallExpression* expr,
                                 const sem::BuiltinFn* builtin) {}

void ASTPrinter::EmitRadiansCall(StringStream& out,
                                 const ast::CallExpression* expr,
                                 const sem::BuiltinFn* builtin) {}

void ASTPrinter::EmitQuantizeToF16Call(StringStream& out,
                                       const ast::CallExpression* expr,
                                       const sem::BuiltinFn* builtin) {}

void ASTPrinter::EmitBarrierCall(StringStream& out, const sem::BuiltinFn* builtin) {}

const ast::Expression* ASTPrinter::CreateF32Zero(const sem::Statement* stmt) {}

void ASTPrinter::EmitTextureCall(StringStream& out,
                                 const sem::Call* call,
                                 const sem::BuiltinFn* builtin) {}

std::string ASTPrinter::generate_builtin_name(const sem::BuiltinFn* builtin) {}

void ASTPrinter::EmitCase(const ast::CaseStatement* stmt) {}

void ASTPrinter::EmitContinue(const ast::ContinueStatement*) {}

void ASTPrinter::EmitDiscard(const ast::DiscardStatement*) {}

void ASTPrinter::EmitExpression(StringStream& out, const ast::Expression* expr) {}

void ASTPrinter::EmitIdentifier(StringStream& out, const ast::IdentifierExpression* expr) {}

void ASTPrinter::EmitIf(const ast::IfStatement* stmt) {}

void ASTPrinter::EmitFunction(const ast::Function* func) {}

void ASTPrinter::EmitGlobalVariable(const ast::Variable* global) {}

void ASTPrinter::EmitUniformVariable(const ast::Var* var, const sem::GlobalVariable* sem) {}

void ASTPrinter::EmitStorageVariable(const ast::Var* var, const sem::GlobalVariable* sem) {}

void ASTPrinter::EmitHandleVariable(const ast::Var* var, const sem::GlobalVariable* sem) {}

void ASTPrinter::EmitPrivateVariable(const sem::Variable* var) {}

void ASTPrinter::EmitWorkgroupVariable(const sem::Variable* var) {}

void ASTPrinter::EmitIOVariable(const sem::GlobalVariable* var) {}

void ASTPrinter::EmitPushConstant(const sem::GlobalVariable* var) {}

void ASTPrinter::EmitInterpolationQualifiers(StringStream& out,
                                             VectorRef<const ast::Attribute*> attributes) {}

void ASTPrinter::EmitAttributes(StringStream& out, const sem::GlobalVariable* var) {}

void ASTPrinter::EmitEntryPointFunction(const ast::Function* func) {}

void ASTPrinter::EmitConstant(StringStream& out, const core::constant::Value* constant) {}

void ASTPrinter::EmitLiteral(StringStream& out, const ast::LiteralExpression* lit) {}

void ASTPrinter::EmitZeroValue(StringStream& out, const core::type::Type* type) {}

void ASTPrinter::EmitLoop(const ast::LoopStatement* stmt) {}

void ASTPrinter::EmitForLoop(const ast::ForLoopStatement* stmt) {}

void ASTPrinter::EmitWhile(const ast::WhileStatement* stmt) {}

void ASTPrinter::EmitMemberAccessor(StringStream& out, const ast::MemberAccessorExpression* expr) {}

void ASTPrinter::EmitReturn(const ast::ReturnStatement* stmt) {}

void ASTPrinter::EmitStatement(const ast::Statement* stmt) {}

void ASTPrinter::EmitSwitch(const ast::SwitchStatement* stmt) {}

void ASTPrinter::EmitType(StringStream& out,
                          const core::type::Type* type,
                          core::AddressSpace address_space,
                          core::Access access,
                          const std::string& name,
                          bool* name_printed /* = nullptr */) {}

void ASTPrinter::EmitTypeAndName(StringStream& out,
                                 const core::type::Type* type,
                                 core::AddressSpace address_space,
                                 core::Access access,
                                 const std::string& name) {}

void ASTPrinter::EmitStructType(TextBuffer* b, const core::type::Struct* str) {}

void ASTPrinter::EmitStructMembers(TextBuffer* b, const core::type::Struct* str) {}

void ASTPrinter::EmitUnaryOp(StringStream& out, const ast::UnaryOpExpression* expr) {}

void ASTPrinter::EmitVar(const ast::Var* var) {}

void ASTPrinter::EmitLet(const ast::Let* let) {}

void ASTPrinter::EmitProgramConstVariable(const ast::Variable* var) {}

template <typename F>
void ASTPrinter::CallBuiltinHelper(StringStream& out,
                                   const ast::CallExpression* call,
                                   const sem::BuiltinFn* builtin,
                                   F&& build) {}

core::type::Type* ASTPrinter::BoolTypeToUint(const core::type::Type* type) {}

std::string ASTPrinter::StructName(const core::type::Struct* s) {}

std::string ASTPrinter::UniqueIdentifier(const std::string& prefix /* = "" */) {}

}  // namespace tint::glsl::writer