mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-09 21:47:47 +00:00
Merge remote-tracking branch 'tint/main' into HEAD
Integrates Tint repo into Dawn KIs: - Building docs for Tint is turned off, because it fails due to lack of annotations in Dawn source files. - Dawn CQ needs to be updated to run Tint specific tests - Significant post-merge cleanup needed R=bclayton,cwallez BUG=dawn:1339 Change-Id: I6c9714a0030934edd6c51f3cac4684dcd59d1ea3
This commit is contained in:
@@ -163,7 +163,7 @@ source_set("sources") {
|
||||
"${dawn_root}/src/dawn/common",
|
||||
"${dawn_spirv_tools_dir}:spvtools_opt",
|
||||
"${dawn_spirv_tools_dir}:spvtools_val",
|
||||
"${dawn_tint_dir}/src/tint:libtint",
|
||||
"${dawn_root}/src/tint:libtint",
|
||||
]
|
||||
defines = []
|
||||
libs = []
|
||||
|
||||
799
src/tint/BUILD.gn
Normal file
799
src/tint/BUILD.gn
Normal file
@@ -0,0 +1,799 @@
|
||||
# Copyright 2021 The Tint Authors
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build_overrides/build.gni")
|
||||
import("../../tint_overrides_with_defaults.gni")
|
||||
|
||||
###############################################################################
|
||||
# Common - Configs, etc. shared across targets
|
||||
###############################################################################
|
||||
|
||||
config("tint_common_config") {
|
||||
include_dirs = [
|
||||
"${target_gen_dir}",
|
||||
"${tint_root_dir}/",
|
||||
"${tint_spirv_headers_dir}/include",
|
||||
"${tint_spirv_tools_dir}/",
|
||||
"${tint_spirv_tools_dir}/include",
|
||||
]
|
||||
}
|
||||
|
||||
config("tint_public_config") {
|
||||
defines = []
|
||||
if (tint_build_spv_reader) {
|
||||
defines += [ "TINT_BUILD_SPV_READER=1" ]
|
||||
} else {
|
||||
defines += [ "TINT_BUILD_SPV_READER=0" ]
|
||||
}
|
||||
|
||||
if (tint_build_spv_writer) {
|
||||
defines += [ "TINT_BUILD_SPV_WRITER=1" ]
|
||||
} else {
|
||||
defines += [ "TINT_BUILD_SPV_WRITER=0" ]
|
||||
}
|
||||
|
||||
if (tint_build_wgsl_reader) {
|
||||
defines += [ "TINT_BUILD_WGSL_READER=1" ]
|
||||
} else {
|
||||
defines += [ "TINT_BUILD_WGSL_READER=0" ]
|
||||
}
|
||||
|
||||
if (tint_build_wgsl_writer) {
|
||||
defines += [ "TINT_BUILD_WGSL_WRITER=1" ]
|
||||
} else {
|
||||
defines += [ "TINT_BUILD_WGSL_WRITER=0" ]
|
||||
}
|
||||
|
||||
if (tint_build_msl_writer) {
|
||||
defines += [ "TINT_BUILD_MSL_WRITER=1" ]
|
||||
} else {
|
||||
defines += [ "TINT_BUILD_MSL_WRITER=0" ]
|
||||
}
|
||||
|
||||
if (tint_build_hlsl_writer) {
|
||||
defines += [ "TINT_BUILD_HLSL_WRITER=1" ]
|
||||
} else {
|
||||
defines += [ "TINT_BUILD_HLSL_WRITER=0" ]
|
||||
}
|
||||
|
||||
if (tint_build_glsl_writer) {
|
||||
defines += [ "TINT_BUILD_GLSL_WRITER=1" ]
|
||||
} else {
|
||||
defines += [ "TINT_BUILD_GLSL_WRITER=0" ]
|
||||
}
|
||||
|
||||
include_dirs = [
|
||||
"${tint_root_dir}/",
|
||||
"${tint_root_dir}/include/",
|
||||
"${tint_spirv_headers_dir}/include",
|
||||
]
|
||||
}
|
||||
|
||||
config("tint_config") {
|
||||
include_dirs = []
|
||||
if (tint_build_spv_reader || tint_build_spv_writer) {
|
||||
include_dirs += [ "${tint_spirv_tools_dir}/include/" ]
|
||||
}
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Helper library for IO operations
|
||||
# Only to be used by tests and sample executable
|
||||
###############################################################################
|
||||
source_set("tint_utils_io") {
|
||||
sources = [
|
||||
"utils/io/command.h",
|
||||
"utils/io/tmpfile.h",
|
||||
]
|
||||
|
||||
if (is_linux || is_mac) {
|
||||
sources += [ "utils/io/command_posix.cc" ]
|
||||
sources += [ "utils/io/tmpfile_posix.cc" ]
|
||||
} else if (is_win) {
|
||||
sources += [ "utils/io/command_windows.cc" ]
|
||||
sources += [ "utils/io/tmpfile_windows.cc" ]
|
||||
} else {
|
||||
sources += [ "utils/io/command_other.cc" ]
|
||||
sources += [ "utils/io/tmpfile_other.cc" ]
|
||||
}
|
||||
|
||||
public_deps = [ ":libtint_core_all_src" ]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Helper library for validating generated shaders
|
||||
# As this depends on tint_utils_io, this is only to be used by tests and sample
|
||||
# executable
|
||||
###############################################################################
|
||||
source_set("tint_val") {
|
||||
sources = [
|
||||
"val/hlsl.cc",
|
||||
"val/msl.cc",
|
||||
"val/val.h",
|
||||
]
|
||||
public_deps = [ ":tint_utils_io" ]
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
# Library - Tint core and optional modules of libtint
|
||||
###############################################################################
|
||||
# libtint source sets are divided into a non-optional core in :libtint_core_src
|
||||
# and optional :libtint_*_src subsets, because ninja does not like having
|
||||
# multiple source files with the same name, like function.cc, in the same
|
||||
# source set
|
||||
# target.
|
||||
#
|
||||
# Targets that want to use tint as a library should depend on ":libtint" and
|
||||
# use the build flags to control what is included, instead of trying to specify
|
||||
# the subsets that they want.
|
||||
|
||||
template("libtint_source_set") {
|
||||
source_set(target_name) {
|
||||
forward_variables_from(invoker, "*", [ "configs" ])
|
||||
|
||||
if (!defined(invoker.deps)) {
|
||||
deps = []
|
||||
}
|
||||
deps += [
|
||||
"${tint_spirv_headers_dir}:spv_headers",
|
||||
"${tint_spirv_tools_dir}:spvtools_core_enums_unified1",
|
||||
"${tint_spirv_tools_dir}:spvtools_core_tables_unified1",
|
||||
"${tint_spirv_tools_dir}:spvtools_headers",
|
||||
"${tint_spirv_tools_dir}:spvtools_language_header_cldebuginfo100",
|
||||
"${tint_spirv_tools_dir}:spvtools_language_header_debuginfo",
|
||||
"${tint_spirv_tools_dir}:spvtools_language_header_vkdebuginfo100",
|
||||
]
|
||||
|
||||
if (defined(invoker.configs)) {
|
||||
configs += invoker.configs
|
||||
}
|
||||
configs += [ ":tint_common_config" ]
|
||||
if (build_with_chromium) {
|
||||
configs -= [ "//build/config/compiler:chromium_code" ]
|
||||
configs += [ "//build/config/compiler:no_chromium_code" ]
|
||||
}
|
||||
|
||||
if (!defined(invoker.public_configs)) {
|
||||
public_configs = []
|
||||
}
|
||||
public_configs += [ ":tint_public_config" ]
|
||||
}
|
||||
}
|
||||
|
||||
libtint_source_set("libtint_core_all_src") {
|
||||
sources = [
|
||||
"ast/access.cc",
|
||||
"ast/access.h",
|
||||
"ast/alias.cc",
|
||||
"ast/alias.h",
|
||||
"ast/array.cc",
|
||||
"ast/array.h",
|
||||
"ast/assignment_statement.cc",
|
||||
"ast/assignment_statement.h",
|
||||
"ast/ast_type.cc", # TODO(bclayton) - rename to type.cc
|
||||
"ast/atomic.cc",
|
||||
"ast/atomic.h",
|
||||
"ast/attribute.cc",
|
||||
"ast/attribute.h",
|
||||
"ast/binary_expression.cc",
|
||||
"ast/binary_expression.h",
|
||||
"ast/binding_attribute.cc",
|
||||
"ast/binding_attribute.h",
|
||||
"ast/bitcast_expression.cc",
|
||||
"ast/bitcast_expression.h",
|
||||
"ast/block_statement.cc",
|
||||
"ast/block_statement.h",
|
||||
"ast/bool.cc",
|
||||
"ast/bool.h",
|
||||
"ast/bool_literal_expression.cc",
|
||||
"ast/bool_literal_expression.h",
|
||||
"ast/break_statement.cc",
|
||||
"ast/break_statement.h",
|
||||
"ast/builtin.cc",
|
||||
"ast/builtin.h",
|
||||
"ast/builtin_attribute.cc",
|
||||
"ast/builtin_attribute.h",
|
||||
"ast/call_expression.cc",
|
||||
"ast/call_expression.h",
|
||||
"ast/call_statement.cc",
|
||||
"ast/call_statement.h",
|
||||
"ast/case_statement.cc",
|
||||
"ast/case_statement.h",
|
||||
"ast/compound_assignment_statement.cc",
|
||||
"ast/compound_assignment_statement.h",
|
||||
"ast/continue_statement.cc",
|
||||
"ast/continue_statement.h",
|
||||
"ast/depth_multisampled_texture.cc",
|
||||
"ast/depth_multisampled_texture.h",
|
||||
"ast/depth_texture.cc",
|
||||
"ast/depth_texture.h",
|
||||
"ast/disable_validation_attribute.cc",
|
||||
"ast/disable_validation_attribute.h",
|
||||
"ast/discard_statement.cc",
|
||||
"ast/discard_statement.h",
|
||||
"ast/else_statement.cc",
|
||||
"ast/else_statement.h",
|
||||
"ast/expression.cc",
|
||||
"ast/expression.h",
|
||||
"ast/external_texture.cc",
|
||||
"ast/external_texture.h",
|
||||
"ast/f32.cc",
|
||||
"ast/f32.h",
|
||||
"ast/fallthrough_statement.cc",
|
||||
"ast/fallthrough_statement.h",
|
||||
"ast/float_literal_expression.cc",
|
||||
"ast/float_literal_expression.h",
|
||||
"ast/for_loop_statement.cc",
|
||||
"ast/for_loop_statement.h",
|
||||
"ast/function.cc",
|
||||
"ast/function.h",
|
||||
"ast/group_attribute.cc",
|
||||
"ast/group_attribute.h",
|
||||
"ast/i32.cc",
|
||||
"ast/i32.h",
|
||||
"ast/id_attribute.cc",
|
||||
"ast/id_attribute.h",
|
||||
"ast/identifier_expression.cc",
|
||||
"ast/identifier_expression.h",
|
||||
"ast/if_statement.cc",
|
||||
"ast/if_statement.h",
|
||||
"ast/index_accessor_expression.cc",
|
||||
"ast/index_accessor_expression.h",
|
||||
"ast/int_literal_expression.cc",
|
||||
"ast/int_literal_expression.h",
|
||||
"ast/internal_attribute.cc",
|
||||
"ast/internal_attribute.h",
|
||||
"ast/interpolate_attribute.cc",
|
||||
"ast/interpolate_attribute.h",
|
||||
"ast/invariant_attribute.cc",
|
||||
"ast/invariant_attribute.h",
|
||||
"ast/literal_expression.cc",
|
||||
"ast/literal_expression.h",
|
||||
"ast/location_attribute.cc",
|
||||
"ast/location_attribute.h",
|
||||
"ast/loop_statement.cc",
|
||||
"ast/loop_statement.h",
|
||||
"ast/matrix.cc",
|
||||
"ast/matrix.h",
|
||||
"ast/member_accessor_expression.cc",
|
||||
"ast/member_accessor_expression.h",
|
||||
"ast/module.cc",
|
||||
"ast/module.h",
|
||||
"ast/multisampled_texture.cc",
|
||||
"ast/multisampled_texture.h",
|
||||
"ast/node.cc",
|
||||
"ast/node.h",
|
||||
"ast/phony_expression.cc",
|
||||
"ast/phony_expression.h",
|
||||
"ast/pipeline_stage.cc",
|
||||
"ast/pipeline_stage.h",
|
||||
"ast/pointer.cc",
|
||||
"ast/pointer.h",
|
||||
"ast/return_statement.cc",
|
||||
"ast/return_statement.h",
|
||||
"ast/sampled_texture.cc",
|
||||
"ast/sampled_texture.h",
|
||||
"ast/sampler.cc",
|
||||
"ast/sampler.h",
|
||||
"ast/sint_literal_expression.cc",
|
||||
"ast/sint_literal_expression.h",
|
||||
"ast/stage_attribute.cc",
|
||||
"ast/stage_attribute.h",
|
||||
"ast/statement.cc",
|
||||
"ast/statement.h",
|
||||
"ast/storage_class.cc",
|
||||
"ast/storage_class.h",
|
||||
"ast/storage_texture.cc",
|
||||
"ast/storage_texture.h",
|
||||
"ast/stride_attribute.cc",
|
||||
"ast/stride_attribute.h",
|
||||
"ast/struct.cc",
|
||||
"ast/struct.h",
|
||||
"ast/struct_member.cc",
|
||||
"ast/struct_member.h",
|
||||
"ast/struct_member_align_attribute.cc",
|
||||
"ast/struct_member_align_attribute.h",
|
||||
"ast/struct_member_offset_attribute.cc",
|
||||
"ast/struct_member_offset_attribute.h",
|
||||
"ast/struct_member_size_attribute.cc",
|
||||
"ast/struct_member_size_attribute.h",
|
||||
"ast/switch_statement.cc",
|
||||
"ast/switch_statement.h",
|
||||
"ast/texture.cc",
|
||||
"ast/texture.h",
|
||||
"ast/traverse_expressions.h",
|
||||
"ast/type.h",
|
||||
"ast/type_decl.cc",
|
||||
"ast/type_decl.h",
|
||||
"ast/type_name.cc",
|
||||
"ast/type_name.h",
|
||||
"ast/u32.cc",
|
||||
"ast/u32.h",
|
||||
"ast/uint_literal_expression.cc",
|
||||
"ast/uint_literal_expression.h",
|
||||
"ast/unary_op.cc",
|
||||
"ast/unary_op.h",
|
||||
"ast/unary_op_expression.cc",
|
||||
"ast/unary_op_expression.h",
|
||||
"ast/variable.cc",
|
||||
"ast/variable.h",
|
||||
"ast/variable_decl_statement.cc",
|
||||
"ast/variable_decl_statement.h",
|
||||
"ast/vector.cc",
|
||||
"ast/vector.h",
|
||||
"ast/void.cc",
|
||||
"ast/void.h",
|
||||
"ast/workgroup_attribute.cc",
|
||||
"ast/workgroup_attribute.h",
|
||||
"builtin_table.cc",
|
||||
"builtin_table.h",
|
||||
"builtin_table.inl",
|
||||
"castable.cc",
|
||||
"castable.h",
|
||||
"clone_context.cc",
|
||||
"clone_context.h",
|
||||
"debug.cc",
|
||||
"debug.h",
|
||||
"demangler.cc",
|
||||
"demangler.h",
|
||||
"diagnostic/diagnostic.cc",
|
||||
"diagnostic/diagnostic.h",
|
||||
"diagnostic/formatter.cc",
|
||||
"diagnostic/formatter.h",
|
||||
"diagnostic/printer.cc",
|
||||
"diagnostic/printer.h",
|
||||
"inspector/entry_point.cc",
|
||||
"inspector/entry_point.h",
|
||||
"inspector/inspector.cc",
|
||||
"inspector/inspector.h",
|
||||
"inspector/resource_binding.cc",
|
||||
"inspector/resource_binding.h",
|
||||
"inspector/scalar.cc",
|
||||
"inspector/scalar.h",
|
||||
"program.cc",
|
||||
"program.h",
|
||||
"program_builder.cc",
|
||||
"program_builder.h",
|
||||
"program_id.cc",
|
||||
"program_id.h",
|
||||
"reader/reader.cc",
|
||||
"reader/reader.h",
|
||||
"resolver/dependency_graph.cc",
|
||||
"resolver/dependency_graph.h",
|
||||
"resolver/resolver.cc",
|
||||
"resolver/resolver.h",
|
||||
"resolver/resolver_constants.cc",
|
||||
"resolver/resolver_validation.cc",
|
||||
"scope_stack.h",
|
||||
"sem/array.h",
|
||||
"sem/atomic_type.h",
|
||||
"sem/behavior.h",
|
||||
"sem/binding_point.h",
|
||||
"sem/bool_type.h",
|
||||
"sem/builtin.h",
|
||||
"sem/builtin_type.h",
|
||||
"sem/call.h",
|
||||
"sem/call_target.h",
|
||||
"sem/constant.h",
|
||||
"sem/depth_multisampled_texture_type.h",
|
||||
"sem/depth_texture_type.h",
|
||||
"sem/expression.h",
|
||||
"sem/external_texture_type.h",
|
||||
"sem/f32_type.h",
|
||||
"sem/for_loop_statement.h",
|
||||
"sem/i32_type.h",
|
||||
"sem/if_statement.h",
|
||||
"sem/info.h",
|
||||
"sem/loop_statement.h",
|
||||
"sem/matrix_type.h",
|
||||
"sem/module.h",
|
||||
"sem/multisampled_texture_type.h",
|
||||
"sem/node.h",
|
||||
"sem/parameter_usage.h",
|
||||
"sem/pipeline_stage_set.h",
|
||||
"sem/pointer_type.h",
|
||||
"sem/reference_type.h",
|
||||
"sem/sampled_texture_type.h",
|
||||
"sem/sampler_texture_pair.h",
|
||||
"sem/sampler_type.h",
|
||||
"sem/storage_texture_type.h",
|
||||
"sem/switch_statement.h",
|
||||
"sem/texture_type.h",
|
||||
"sem/type.h",
|
||||
"sem/type_constructor.h",
|
||||
"sem/type_conversion.h",
|
||||
"sem/type_manager.h",
|
||||
"sem/type_mappings.h",
|
||||
"sem/u32_type.h",
|
||||
"sem/vector_type.h",
|
||||
"sem/void_type.h",
|
||||
"source.cc",
|
||||
"source.h",
|
||||
"symbol.cc",
|
||||
"symbol.h",
|
||||
"symbol_table.cc",
|
||||
"symbol_table.h",
|
||||
"text/unicode.cc",
|
||||
"text/unicode.h",
|
||||
"traits.h",
|
||||
"transform/add_empty_entry_point.cc",
|
||||
"transform/add_empty_entry_point.h",
|
||||
"transform/add_spirv_block_attribute.cc",
|
||||
"transform/add_spirv_block_attribute.h",
|
||||
"transform/array_length_from_uniform.cc",
|
||||
"transform/array_length_from_uniform.h",
|
||||
"transform/binding_remapper.cc",
|
||||
"transform/binding_remapper.h",
|
||||
"transform/builtin_polyfill.cc",
|
||||
"transform/builtin_polyfill.h",
|
||||
"transform/calculate_array_length.cc",
|
||||
"transform/calculate_array_length.h",
|
||||
"transform/canonicalize_entry_point_io.cc",
|
||||
"transform/canonicalize_entry_point_io.h",
|
||||
"transform/combine_samplers.cc",
|
||||
"transform/combine_samplers.h",
|
||||
"transform/decompose_memory_access.cc",
|
||||
"transform/decompose_memory_access.h",
|
||||
"transform/decompose_strided_array.cc",
|
||||
"transform/decompose_strided_array.h",
|
||||
"transform/decompose_strided_matrix.cc",
|
||||
"transform/decompose_strided_matrix.h",
|
||||
"transform/first_index_offset.cc",
|
||||
"transform/first_index_offset.h",
|
||||
"transform/fold_constants.cc",
|
||||
"transform/fold_constants.h",
|
||||
"transform/fold_trivial_single_use_lets.cc",
|
||||
"transform/fold_trivial_single_use_lets.h",
|
||||
"transform/for_loop_to_loop.cc",
|
||||
"transform/for_loop_to_loop.h",
|
||||
"transform/expand_compound_assignment.cc",
|
||||
"transform/expand_compound_assignment.h",
|
||||
"transform/localize_struct_array_assignment.cc",
|
||||
"transform/localize_struct_array_assignment.h",
|
||||
"transform/loop_to_for_loop.cc",
|
||||
"transform/loop_to_for_loop.h",
|
||||
"transform/manager.cc",
|
||||
"transform/manager.h",
|
||||
"transform/module_scope_var_to_entry_point_param.cc",
|
||||
"transform/module_scope_var_to_entry_point_param.h",
|
||||
"transform/multiplanar_external_texture.cc",
|
||||
"transform/multiplanar_external_texture.h",
|
||||
"transform/num_workgroups_from_uniform.cc",
|
||||
"transform/num_workgroups_from_uniform.h",
|
||||
"transform/promote_initializers_to_const_var.cc",
|
||||
"transform/promote_initializers_to_const_var.h",
|
||||
"transform/promote_side_effects_to_decl.cc",
|
||||
"transform/promote_side_effects_to_decl.h",
|
||||
"transform/remove_continue_in_switch.cc",
|
||||
"transform/remove_continue_in_switch.h",
|
||||
"transform/remove_phonies.cc",
|
||||
"transform/remove_phonies.h",
|
||||
"transform/remove_unreachable_statements.cc",
|
||||
"transform/remove_unreachable_statements.h",
|
||||
"transform/renamer.cc",
|
||||
"transform/renamer.h",
|
||||
"transform/robustness.cc",
|
||||
"transform/robustness.h",
|
||||
"transform/simplify_pointers.cc",
|
||||
"transform/simplify_pointers.h",
|
||||
"transform/single_entry_point.cc",
|
||||
"transform/single_entry_point.h",
|
||||
"transform/transform.cc",
|
||||
"transform/transform.h",
|
||||
"transform/unshadow.cc",
|
||||
"transform/unshadow.h",
|
||||
"transform/unwind_discard_functions.cc",
|
||||
"transform/unwind_discard_functions.h",
|
||||
"transform/utils/get_insertion_point.cc",
|
||||
"transform/utils/get_insertion_point.h",
|
||||
"transform/utils/hoist_to_decl_before.cc",
|
||||
"transform/utils/hoist_to_decl_before.h",
|
||||
"transform/var_for_dynamic_index.cc",
|
||||
"transform/var_for_dynamic_index.h",
|
||||
"transform/vectorize_scalar_matrix_constructors.cc",
|
||||
"transform/vectorize_scalar_matrix_constructors.h",
|
||||
"transform/vertex_pulling.cc",
|
||||
"transform/vertex_pulling.h",
|
||||
"transform/wrap_arrays_in_structs.cc",
|
||||
"transform/wrap_arrays_in_structs.h",
|
||||
"transform/zero_init_workgroup_memory.cc",
|
||||
"transform/zero_init_workgroup_memory.h",
|
||||
"utils/block_allocator.h",
|
||||
"utils/crc32.h",
|
||||
"utils/debugger.cc",
|
||||
"utils/debugger.h",
|
||||
"utils/enum_set.h",
|
||||
"utils/hash.h",
|
||||
"utils/map.h",
|
||||
"utils/math.h",
|
||||
"utils/scoped_assignment.h",
|
||||
"utils/string.h",
|
||||
"utils/unique_allocator.h",
|
||||
"utils/unique_vector.h",
|
||||
"writer/append_vector.cc",
|
||||
"writer/append_vector.h",
|
||||
"writer/array_length_from_uniform_options.cc",
|
||||
"writer/array_length_from_uniform_options.h",
|
||||
"writer/float_to_string.cc",
|
||||
"writer/float_to_string.h",
|
||||
"writer/generate_external_texture_bindings.cc",
|
||||
"writer/generate_external_texture_bindings.h",
|
||||
"writer/text.cc",
|
||||
"writer/text.h",
|
||||
"writer/text_generator.cc",
|
||||
"writer/text_generator.h",
|
||||
"writer/writer.cc",
|
||||
"writer/writer.h",
|
||||
]
|
||||
|
||||
if (is_linux) {
|
||||
sources += [ "diagnostic/printer_linux.cc" ]
|
||||
} else if (is_win) {
|
||||
sources += [ "diagnostic/printer_windows.cc" ]
|
||||
} else {
|
||||
sources += [ "diagnostic/printer_other.cc" ]
|
||||
}
|
||||
}
|
||||
|
||||
libtint_source_set("libtint_sem_src") {
|
||||
sources = [
|
||||
"sem/array.cc",
|
||||
"sem/array.h",
|
||||
"sem/atomic_type.cc",
|
||||
"sem/atomic_type.h",
|
||||
"sem/behavior.cc",
|
||||
"sem/behavior.h",
|
||||
"sem/binding_point.h",
|
||||
"sem/block_statement.cc",
|
||||
"sem/bool_type.cc",
|
||||
"sem/bool_type.h",
|
||||
"sem/builtin.cc",
|
||||
"sem/builtin.h",
|
||||
"sem/builtin_type.cc",
|
||||
"sem/builtin_type.h",
|
||||
"sem/call.cc",
|
||||
"sem/call.h",
|
||||
"sem/call_target.cc",
|
||||
"sem/call_target.h",
|
||||
"sem/constant.cc",
|
||||
"sem/constant.h",
|
||||
"sem/depth_multisampled_texture_type.cc",
|
||||
"sem/depth_multisampled_texture_type.h",
|
||||
"sem/depth_texture_type.cc",
|
||||
"sem/depth_texture_type.h",
|
||||
"sem/expression.cc",
|
||||
"sem/expression.h",
|
||||
"sem/external_texture_type.cc",
|
||||
"sem/external_texture_type.h",
|
||||
"sem/f32_type.cc",
|
||||
"sem/f32_type.h",
|
||||
"sem/for_loop_statement.cc",
|
||||
"sem/for_loop_statement.h",
|
||||
"sem/function.cc",
|
||||
"sem/i32_type.cc",
|
||||
"sem/i32_type.h",
|
||||
"sem/if_statement.cc",
|
||||
"sem/if_statement.h",
|
||||
"sem/info.cc",
|
||||
"sem/info.h",
|
||||
"sem/loop_statement.cc",
|
||||
"sem/loop_statement.h",
|
||||
"sem/matrix_type.cc",
|
||||
"sem/matrix_type.h",
|
||||
"sem/member_accessor_expression.cc",
|
||||
"sem/module.cc",
|
||||
"sem/module.h",
|
||||
"sem/multisampled_texture_type.cc",
|
||||
"sem/multisampled_texture_type.h",
|
||||
"sem/node.cc",
|
||||
"sem/node.h",
|
||||
"sem/parameter_usage.cc",
|
||||
"sem/parameter_usage.h",
|
||||
"sem/pipeline_stage_set.h",
|
||||
"sem/pointer_type.cc",
|
||||
"sem/pointer_type.h",
|
||||
"sem/reference_type.cc",
|
||||
"sem/reference_type.h",
|
||||
"sem/sampled_texture_type.cc",
|
||||
"sem/sampled_texture_type.h",
|
||||
"sem/sampler_type.cc",
|
||||
"sem/sampler_type.h",
|
||||
"sem/statement.cc",
|
||||
"sem/storage_texture_type.cc",
|
||||
"sem/storage_texture_type.h",
|
||||
"sem/struct.cc",
|
||||
"sem/switch_statement.cc",
|
||||
"sem/switch_statement.h",
|
||||
"sem/texture_type.cc",
|
||||
"sem/texture_type.h",
|
||||
"sem/type.cc",
|
||||
"sem/type.h",
|
||||
"sem/type_constructor.cc",
|
||||
"sem/type_constructor.h",
|
||||
"sem/type_conversion.cc",
|
||||
"sem/type_conversion.h",
|
||||
"sem/type_manager.cc",
|
||||
"sem/type_manager.h",
|
||||
"sem/type_mappings.h",
|
||||
"sem/u32_type.cc",
|
||||
"sem/u32_type.h",
|
||||
"sem/variable.cc",
|
||||
"sem/vector_type.cc",
|
||||
"sem/vector_type.h",
|
||||
"sem/void_type.cc",
|
||||
"sem/void_type.h",
|
||||
]
|
||||
|
||||
public_deps = [ ":libtint_core_all_src" ]
|
||||
}
|
||||
|
||||
libtint_source_set("libtint_core_src") {
|
||||
public_deps = [
|
||||
":libtint_core_all_src",
|
||||
":libtint_sem_src",
|
||||
]
|
||||
}
|
||||
|
||||
libtint_source_set("libtint_spv_reader_src") {
|
||||
sources = [
|
||||
"reader/spirv/construct.cc",
|
||||
"reader/spirv/construct.h",
|
||||
"reader/spirv/entry_point_info.cc",
|
||||
"reader/spirv/entry_point_info.h",
|
||||
"reader/spirv/enum_converter.cc",
|
||||
"reader/spirv/enum_converter.h",
|
||||
"reader/spirv/fail_stream.h",
|
||||
"reader/spirv/function.cc",
|
||||
"reader/spirv/function.h",
|
||||
"reader/spirv/namer.cc",
|
||||
"reader/spirv/namer.h",
|
||||
"reader/spirv/parser.cc",
|
||||
"reader/spirv/parser.h",
|
||||
"reader/spirv/parser_impl.cc",
|
||||
"reader/spirv/parser_impl.h",
|
||||
"reader/spirv/parser_type.cc",
|
||||
"reader/spirv/parser_type.h",
|
||||
"reader/spirv/usage.cc",
|
||||
"reader/spirv/usage.h",
|
||||
]
|
||||
|
||||
public_deps = [
|
||||
":libtint_core_src",
|
||||
"${tint_spirv_tools_dir}/:spvtools_opt",
|
||||
]
|
||||
|
||||
public_configs = [ "${tint_spirv_tools_dir}/:spvtools_internal_config" ]
|
||||
}
|
||||
|
||||
libtint_source_set("libtint_spv_writer_src") {
|
||||
sources = [
|
||||
"writer/spirv/binary_writer.cc",
|
||||
"writer/spirv/binary_writer.h",
|
||||
"writer/spirv/builder.cc",
|
||||
"writer/spirv/builder.h",
|
||||
"writer/spirv/function.cc",
|
||||
"writer/spirv/function.h",
|
||||
"writer/spirv/generator.cc",
|
||||
"writer/spirv/generator.h",
|
||||
"writer/spirv/instruction.cc",
|
||||
"writer/spirv/instruction.h",
|
||||
"writer/spirv/operand.cc",
|
||||
"writer/spirv/operand.h",
|
||||
"writer/spirv/scalar_constant.h",
|
||||
]
|
||||
|
||||
public_deps = [ ":libtint_core_src" ]
|
||||
}
|
||||
|
||||
libtint_source_set("libtint_wgsl_reader_src") {
|
||||
sources = [
|
||||
"reader/wgsl/lexer.cc",
|
||||
"reader/wgsl/lexer.h",
|
||||
"reader/wgsl/parser.cc",
|
||||
"reader/wgsl/parser.h",
|
||||
"reader/wgsl/parser_impl.cc",
|
||||
"reader/wgsl/parser_impl.h",
|
||||
"reader/wgsl/parser_impl_detail.h",
|
||||
"reader/wgsl/token.cc",
|
||||
"reader/wgsl/token.h",
|
||||
]
|
||||
|
||||
public_deps = [ ":libtint_core_src" ]
|
||||
}
|
||||
|
||||
libtint_source_set("libtint_wgsl_writer_src") {
|
||||
sources = [
|
||||
"writer/wgsl/generator.cc",
|
||||
"writer/wgsl/generator.h",
|
||||
"writer/wgsl/generator_impl.cc",
|
||||
"writer/wgsl/generator_impl.h",
|
||||
]
|
||||
|
||||
public_deps = [ ":libtint_core_src" ]
|
||||
}
|
||||
|
||||
libtint_source_set("libtint_msl_writer_src") {
|
||||
sources = [
|
||||
"writer/msl/generator.cc",
|
||||
"writer/msl/generator.h",
|
||||
"writer/msl/generator_impl.cc",
|
||||
"writer/msl/generator_impl.h",
|
||||
]
|
||||
|
||||
public_deps = [ ":libtint_core_src" ]
|
||||
}
|
||||
|
||||
libtint_source_set("libtint_hlsl_writer_src") {
|
||||
sources = [
|
||||
"writer/hlsl/generator.cc",
|
||||
"writer/hlsl/generator.h",
|
||||
"writer/hlsl/generator_impl.cc",
|
||||
"writer/hlsl/generator_impl.h",
|
||||
]
|
||||
|
||||
public_deps = [ ":libtint_core_src" ]
|
||||
}
|
||||
|
||||
libtint_source_set("libtint_glsl_writer_src") {
|
||||
sources = [
|
||||
"transform/glsl.cc",
|
||||
"transform/glsl.h",
|
||||
"writer/glsl/generator.cc",
|
||||
"writer/glsl/generator.h",
|
||||
"writer/glsl/generator_impl.cc",
|
||||
"writer/glsl/generator_impl.h",
|
||||
]
|
||||
|
||||
public_deps = [ ":libtint_core_src" ]
|
||||
}
|
||||
|
||||
source_set("libtint") {
|
||||
public_deps = [ ":libtint_core_src" ]
|
||||
|
||||
if (tint_build_spv_reader) {
|
||||
public_deps += [ ":libtint_spv_reader_src" ]
|
||||
}
|
||||
|
||||
if (tint_build_spv_writer) {
|
||||
public_deps += [ ":libtint_spv_writer_src" ]
|
||||
}
|
||||
|
||||
if (tint_build_wgsl_reader) {
|
||||
public_deps += [ ":libtint_wgsl_reader_src" ]
|
||||
}
|
||||
|
||||
if (tint_build_wgsl_writer) {
|
||||
public_deps += [ ":libtint_wgsl_writer_src" ]
|
||||
}
|
||||
|
||||
if (tint_build_msl_writer) {
|
||||
public_deps += [ ":libtint_msl_writer_src" ]
|
||||
}
|
||||
|
||||
if (tint_build_hlsl_writer) {
|
||||
public_deps += [ ":libtint_hlsl_writer_src" ]
|
||||
}
|
||||
|
||||
if (tint_build_glsl_writer) {
|
||||
public_deps += [ ":libtint_glsl_writer_src" ]
|
||||
}
|
||||
|
||||
configs += [ ":tint_common_config" ]
|
||||
public_configs = [ ":tint_public_config" ]
|
||||
|
||||
if (build_with_chromium) {
|
||||
configs -= [ "//build/config/compiler:chromium_code" ]
|
||||
configs += [ "//build/config/compiler:no_chromium_code" ]
|
||||
}
|
||||
}
|
||||
1239
src/tint/CMakeLists.txt
Normal file
1239
src/tint/CMakeLists.txt
Normal file
File diff suppressed because it is too large
Load Diff
43
src/tint/ast/access.cc
Normal file
43
src/tint/ast/access.cc
Normal file
@@ -0,0 +1,43 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/access.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, Access access) {
|
||||
switch (access) {
|
||||
case ast::Access::kUndefined: {
|
||||
out << "undefined";
|
||||
break;
|
||||
}
|
||||
case ast::Access::kRead: {
|
||||
out << "read";
|
||||
break;
|
||||
}
|
||||
case ast::Access::kReadWrite: {
|
||||
out << "read_write";
|
||||
break;
|
||||
}
|
||||
case ast::Access::kWrite: {
|
||||
out << "write";
|
||||
break;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
46
src/tint/ast/access.h
Normal file
46
src/tint/ast/access.h
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_ACCESS_H_
|
||||
#define SRC_TINT_AST_ACCESS_H_
|
||||
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// The access control settings
|
||||
enum Access {
|
||||
/// Not declared in the source
|
||||
kUndefined = 0,
|
||||
/// Read only
|
||||
kRead,
|
||||
/// Write only
|
||||
kWrite,
|
||||
/// Read write
|
||||
kReadWrite,
|
||||
// Last valid access mode
|
||||
kLastValid = kReadWrite,
|
||||
};
|
||||
|
||||
/// @param out the std::ostream to write to
|
||||
/// @param access the Access
|
||||
/// @return the std::ostream so calls can be chained
|
||||
std::ostream& operator<<(std::ostream& out, Access access);
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_ACCESS_H_
|
||||
45
src/tint/ast/alias.cc
Normal file
45
src/tint/ast/alias.cc
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/alias.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::Alias);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
Alias::Alias(ProgramID pid,
|
||||
const Source& src,
|
||||
const Symbol& n,
|
||||
const Type* subtype)
|
||||
: Base(pid, src, n), type(subtype) {
|
||||
TINT_ASSERT(AST, type);
|
||||
}
|
||||
|
||||
Alias::Alias(Alias&&) = default;
|
||||
|
||||
Alias::~Alias() = default;
|
||||
|
||||
const Alias* Alias::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
auto sym = ctx->Clone(name);
|
||||
auto* ty = ctx->Clone(type);
|
||||
return ctx->dst->create<Alias>(src, sym, ty);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
54
src/tint/ast/alias.h
Normal file
54
src/tint/ast/alias.h
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_ALIAS_H_
|
||||
#define SRC_TINT_AST_ALIAS_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/ast/type_decl.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// A type alias type. Holds a name and pointer to another type.
|
||||
class Alias final : public Castable<Alias, TypeDecl> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
/// @param name the symbol for the alias
|
||||
/// @param subtype the alias'd type
|
||||
Alias(ProgramID pid,
|
||||
const Source& src,
|
||||
const Symbol& name,
|
||||
const Type* subtype);
|
||||
/// Move constructor
|
||||
Alias(Alias&&);
|
||||
/// Destructor
|
||||
~Alias() override;
|
||||
|
||||
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned type
|
||||
const Alias* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// the alias type
|
||||
const Type* const type;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_ALIAS_H_
|
||||
45
src/tint/ast/alias_test.cc
Normal file
45
src/tint/ast/alias_test.cc
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/alias.h"
|
||||
#include "src/tint/ast/access.h"
|
||||
#include "src/tint/ast/array.h"
|
||||
#include "src/tint/ast/bool.h"
|
||||
#include "src/tint/ast/f32.h"
|
||||
#include "src/tint/ast/i32.h"
|
||||
#include "src/tint/ast/matrix.h"
|
||||
#include "src/tint/ast/pointer.h"
|
||||
#include "src/tint/ast/sampler.h"
|
||||
#include "src/tint/ast/struct.h"
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
#include "src/tint/ast/texture.h"
|
||||
#include "src/tint/ast/u32.h"
|
||||
#include "src/tint/ast/vector.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using AstAliasTest = TestHelper;
|
||||
|
||||
TEST_F(AstAliasTest, Create) {
|
||||
auto* u32 = create<U32>();
|
||||
auto* a = Alias("a_type", u32);
|
||||
EXPECT_EQ(a->name, Symbol(1, ID()));
|
||||
EXPECT_EQ(a->type, u32);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
78
src/tint/ast/array.cc
Normal file
78
src/tint/ast/array.cc
Normal file
@@ -0,0 +1,78 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/array.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::Array);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
namespace {
|
||||
// Returns the string representation of an array size expression.
|
||||
std::string SizeExprToString(const Expression* size,
|
||||
const SymbolTable& symbols) {
|
||||
if (auto* ident = size->As<IdentifierExpression>()) {
|
||||
return symbols.NameFor(ident->symbol);
|
||||
}
|
||||
if (auto* literal = size->As<IntLiteralExpression>()) {
|
||||
return std::to_string(literal->ValueAsU32());
|
||||
}
|
||||
// This will never be exposed to the user as the Resolver will reject this
|
||||
// expression for array size.
|
||||
return "<invalid>";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
Array::Array(ProgramID pid,
|
||||
const Source& src,
|
||||
const Type* subtype,
|
||||
const Expression* cnt,
|
||||
AttributeList attrs)
|
||||
: Base(pid, src), type(subtype), count(cnt), attributes(attrs) {}
|
||||
|
||||
Array::Array(Array&&) = default;
|
||||
|
||||
Array::~Array() = default;
|
||||
|
||||
std::string Array::FriendlyName(const SymbolTable& symbols) const {
|
||||
std::ostringstream out;
|
||||
for (auto* attr : attributes) {
|
||||
if (auto* stride = attr->As<ast::StrideAttribute>()) {
|
||||
out << "@stride(" << stride->stride << ") ";
|
||||
}
|
||||
}
|
||||
out << "array<" << type->FriendlyName(symbols);
|
||||
if (!IsRuntimeArray()) {
|
||||
out << ", " << SizeExprToString(count, symbols);
|
||||
}
|
||||
out << ">";
|
||||
return out.str();
|
||||
}
|
||||
|
||||
const Array* Array::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
auto* ty = ctx->Clone(type);
|
||||
auto* cnt = ctx->Clone(count);
|
||||
auto attrs = ctx->Clone(attributes);
|
||||
return ctx->dst->create<Array>(src, ty, cnt, attrs);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
75
src/tint/ast/array.h
Normal file
75
src/tint/ast/array.h
Normal file
@@ -0,0 +1,75 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_ARRAY_H_
|
||||
#define SRC_TINT_AST_ARRAY_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/ast/attribute.h"
|
||||
#include "src/tint/ast/type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
// Forward declarations.
|
||||
class Expression;
|
||||
|
||||
/// An array type. If size is zero then it is a runtime array.
|
||||
class Array final : public Castable<Array, Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
/// @param subtype the type of the array elements
|
||||
/// @param count the number of elements in the array. nullptr represents a
|
||||
/// runtime-sized array.
|
||||
/// @param attributes the array attributes
|
||||
Array(ProgramID pid,
|
||||
const Source& src,
|
||||
const Type* subtype,
|
||||
const Expression* count,
|
||||
AttributeList attributes);
|
||||
/// Move constructor
|
||||
Array(Array&&);
|
||||
~Array() override;
|
||||
|
||||
/// @returns true if this is a runtime array.
|
||||
/// i.e. the size is determined at runtime
|
||||
bool IsRuntimeArray() const { return count == nullptr; }
|
||||
|
||||
/// @param symbols the program's symbol table
|
||||
/// @returns the name for this type that closely resembles how it would be
|
||||
/// declared in WGSL.
|
||||
std::string FriendlyName(const SymbolTable& symbols) const override;
|
||||
|
||||
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned type
|
||||
const Array* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// the array element type
|
||||
const Type* const type;
|
||||
|
||||
/// the array size in elements, or nullptr for a runtime array
|
||||
const Expression* const count;
|
||||
|
||||
/// the array attributes
|
||||
const AttributeList attributes;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_ARRAY_H_
|
||||
71
src/tint/ast/array_test.cc
Normal file
71
src/tint/ast/array_test.cc
Normal file
@@ -0,0 +1,71 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/array.h"
|
||||
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using AstArrayTest = TestHelper;
|
||||
|
||||
TEST_F(AstArrayTest, CreateSizedArray) {
|
||||
auto* u32 = create<U32>();
|
||||
auto* count = Expr(3);
|
||||
auto* arr = create<Array>(u32, count, AttributeList{});
|
||||
EXPECT_EQ(arr->type, u32);
|
||||
EXPECT_EQ(arr->count, count);
|
||||
EXPECT_TRUE(arr->Is<Array>());
|
||||
EXPECT_FALSE(arr->IsRuntimeArray());
|
||||
}
|
||||
|
||||
TEST_F(AstArrayTest, CreateRuntimeArray) {
|
||||
auto* u32 = create<U32>();
|
||||
auto* arr = create<Array>(u32, nullptr, AttributeList{});
|
||||
EXPECT_EQ(arr->type, u32);
|
||||
EXPECT_EQ(arr->count, nullptr);
|
||||
EXPECT_TRUE(arr->Is<Array>());
|
||||
EXPECT_TRUE(arr->IsRuntimeArray());
|
||||
}
|
||||
|
||||
TEST_F(AstArrayTest, FriendlyName_RuntimeSized) {
|
||||
auto* i32 = create<I32>();
|
||||
auto* arr = create<Array>(i32, nullptr, AttributeList{});
|
||||
EXPECT_EQ(arr->FriendlyName(Symbols()), "array<i32>");
|
||||
}
|
||||
|
||||
TEST_F(AstArrayTest, FriendlyName_LiteralSized) {
|
||||
auto* i32 = create<I32>();
|
||||
auto* arr = create<Array>(i32, Expr(5), AttributeList{});
|
||||
EXPECT_EQ(arr->FriendlyName(Symbols()), "array<i32, 5>");
|
||||
}
|
||||
|
||||
TEST_F(AstArrayTest, FriendlyName_ConstantSized) {
|
||||
auto* i32 = create<I32>();
|
||||
auto* arr = create<Array>(i32, Expr("size"), AttributeList{});
|
||||
EXPECT_EQ(arr->FriendlyName(Symbols()), "array<i32, size>");
|
||||
}
|
||||
|
||||
TEST_F(AstArrayTest, FriendlyName_WithStride) {
|
||||
auto* i32 = create<I32>();
|
||||
auto* arr =
|
||||
create<Array>(i32, Expr(5), AttributeList{create<StrideAttribute>(32)});
|
||||
EXPECT_EQ(arr->FriendlyName(Symbols()), "@stride(32) array<i32, 5>");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
48
src/tint/ast/assignment_statement.cc
Normal file
48
src/tint/ast/assignment_statement.cc
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/assignment_statement.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::AssignmentStatement);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
AssignmentStatement::AssignmentStatement(ProgramID pid,
|
||||
const Source& src,
|
||||
const Expression* l,
|
||||
const Expression* r)
|
||||
: Base(pid, src), lhs(l), rhs(r) {
|
||||
TINT_ASSERT(AST, lhs);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs, program_id);
|
||||
TINT_ASSERT(AST, rhs);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, rhs, program_id);
|
||||
}
|
||||
|
||||
AssignmentStatement::AssignmentStatement(AssignmentStatement&&) = default;
|
||||
|
||||
AssignmentStatement::~AssignmentStatement() = default;
|
||||
|
||||
const AssignmentStatement* AssignmentStatement::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
auto* l = ctx->Clone(lhs);
|
||||
auto* r = ctx->Clone(rhs);
|
||||
return ctx->dst->create<AssignmentStatement>(src, l, r);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
57
src/tint/ast/assignment_statement.h
Normal file
57
src/tint/ast/assignment_statement.h
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_ASSIGNMENT_STATEMENT_H_
|
||||
#define SRC_TINT_AST_ASSIGNMENT_STATEMENT_H_
|
||||
|
||||
#include "src/tint/ast/expression.h"
|
||||
#include "src/tint/ast/statement.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// An assignment statement
|
||||
class AssignmentStatement final
|
||||
: public Castable<AssignmentStatement, Statement> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param program_id the identifier of the program that owns this node
|
||||
/// @param source the assignment statement source
|
||||
/// @param lhs the left side of the expression
|
||||
/// @param rhs the right side of the expression
|
||||
AssignmentStatement(ProgramID program_id,
|
||||
const Source& source,
|
||||
const Expression* lhs,
|
||||
const Expression* rhs);
|
||||
/// Move constructor
|
||||
AssignmentStatement(AssignmentStatement&&);
|
||||
~AssignmentStatement() override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const AssignmentStatement* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// left side expression
|
||||
const Expression* const lhs;
|
||||
|
||||
/// right side expression
|
||||
const Expression* const rhs;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_ASSIGNMENT_STATEMENT_H_
|
||||
94
src/tint/ast/assignment_statement_test.cc
Normal file
94
src/tint/ast/assignment_statement_test.cc
Normal file
@@ -0,0 +1,94 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/assignment_statement.h"
|
||||
|
||||
#include "gtest/gtest-spi.h"
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using AssignmentStatementTest = TestHelper;
|
||||
|
||||
TEST_F(AssignmentStatementTest, Creation) {
|
||||
auto* lhs = Expr("lhs");
|
||||
auto* rhs = Expr("rhs");
|
||||
|
||||
auto* stmt = create<AssignmentStatement>(lhs, rhs);
|
||||
EXPECT_EQ(stmt->lhs, lhs);
|
||||
EXPECT_EQ(stmt->rhs, rhs);
|
||||
}
|
||||
|
||||
TEST_F(AssignmentStatementTest, CreationWithSource) {
|
||||
auto* lhs = Expr("lhs");
|
||||
auto* rhs = Expr("rhs");
|
||||
|
||||
auto* stmt =
|
||||
create<AssignmentStatement>(Source{Source::Location{20, 2}}, lhs, rhs);
|
||||
auto src = stmt->source;
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
}
|
||||
|
||||
TEST_F(AssignmentStatementTest, IsAssign) {
|
||||
auto* lhs = Expr("lhs");
|
||||
auto* rhs = Expr("rhs");
|
||||
|
||||
auto* stmt = create<AssignmentStatement>(lhs, rhs);
|
||||
EXPECT_TRUE(stmt->Is<AssignmentStatement>());
|
||||
}
|
||||
|
||||
TEST_F(AssignmentStatementTest, Assert_Null_LHS) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<AssignmentStatement>(nullptr, b.Expr(1));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(AssignmentStatementTest, Assert_Null_RHS) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<AssignmentStatement>(b.Expr(1), nullptr);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(AssignmentStatementTest, Assert_DifferentProgramID_LHS) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<AssignmentStatement>(b2.Expr("lhs"), b1.Expr("rhs"));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(AssignmentStatementTest, Assert_DifferentProgramID_RHS) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<AssignmentStatement>(b1.Expr("lhs"), b2.Expr("rhs"));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
41
src/tint/ast/ast_type.cc
Normal file
41
src/tint/ast/ast_type.cc
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/type.h"
|
||||
|
||||
#include "src/tint/ast/alias.h"
|
||||
#include "src/tint/ast/bool.h"
|
||||
#include "src/tint/ast/f32.h"
|
||||
#include "src/tint/ast/i32.h"
|
||||
#include "src/tint/ast/matrix.h"
|
||||
#include "src/tint/ast/pointer.h"
|
||||
#include "src/tint/ast/sampler.h"
|
||||
#include "src/tint/ast/texture.h"
|
||||
#include "src/tint/ast/u32.h"
|
||||
#include "src/tint/ast/vector.h"
|
||||
#include "src/tint/symbol_table.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::Type);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
Type::Type(ProgramID pid, const Source& src) : Base(pid, src) {}
|
||||
|
||||
Type::Type(Type&&) = default;
|
||||
|
||||
Type::~Type() = default;
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
45
src/tint/ast/atomic.cc
Normal file
45
src/tint/ast/atomic.cc
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright 2021 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/atomic.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::Atomic);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
Atomic::Atomic(ProgramID pid, const Source& src, const Type* const subtype)
|
||||
: Base(pid, src), type(subtype) {}
|
||||
|
||||
std::string Atomic::FriendlyName(const SymbolTable& symbols) const {
|
||||
std::ostringstream out;
|
||||
out << "atomic<" << type->FriendlyName(symbols) << ">";
|
||||
return out.str();
|
||||
}
|
||||
|
||||
Atomic::Atomic(Atomic&&) = default;
|
||||
|
||||
Atomic::~Atomic() = default;
|
||||
|
||||
const Atomic* Atomic::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
auto* ty = ctx->Clone(type);
|
||||
return ctx->dst->create<Atomic>(src, ty);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
54
src/tint/ast/atomic.h
Normal file
54
src/tint/ast/atomic.h
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright 2021 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_ATOMIC_H_
|
||||
#define SRC_TINT_AST_ATOMIC_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/ast/type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// An atomic type.
|
||||
class Atomic final : public Castable<Atomic, Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
/// @param subtype the pointee type
|
||||
Atomic(ProgramID pid, const Source& src, const Type* const subtype);
|
||||
/// Move constructor
|
||||
Atomic(Atomic&&);
|
||||
~Atomic() override;
|
||||
|
||||
/// @param symbols the program's symbol table
|
||||
/// @returns the name for this type that closely resembles how it would be
|
||||
/// declared in WGSL.
|
||||
std::string FriendlyName(const SymbolTable& symbols) const override;
|
||||
|
||||
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned type
|
||||
const Atomic* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// the pointee type
|
||||
const Type* const type;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_ATOMIC_H_
|
||||
40
src/tint/ast/atomic_test.cc
Normal file
40
src/tint/ast/atomic_test.cc
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright 2021 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/atomic.h"
|
||||
|
||||
#include "src/tint/ast/i32.h"
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using AstAtomicTest = TestHelper;
|
||||
|
||||
TEST_F(AstAtomicTest, Creation) {
|
||||
auto* i32 = create<I32>();
|
||||
auto* p = create<Atomic>(i32);
|
||||
EXPECT_EQ(p->type, i32);
|
||||
}
|
||||
|
||||
TEST_F(AstAtomicTest, FriendlyName) {
|
||||
auto* i32 = create<I32>();
|
||||
auto* p = create<Atomic>(i32);
|
||||
EXPECT_EQ(p->FriendlyName(Symbols()), "atomic<i32>");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
25
src/tint/ast/attribute.cc
Normal file
25
src/tint/ast/attribute.cc
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/attribute.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::Attribute);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
Attribute::~Attribute() = default;
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
71
src/tint/ast/attribute.h
Normal file
71
src/tint/ast/attribute.h
Normal file
@@ -0,0 +1,71 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_ATTRIBUTE_H_
|
||||
#define SRC_TINT_AST_ATTRIBUTE_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "src/tint/ast/node.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// The base class for all attributes
|
||||
class Attribute : public Castable<Attribute, Node> {
|
||||
public:
|
||||
~Attribute() override;
|
||||
|
||||
/// @returns the WGSL name for the attribute
|
||||
virtual std::string Name() const = 0;
|
||||
|
||||
protected:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
Attribute(ProgramID pid, const Source& src) : Base(pid, src) {}
|
||||
};
|
||||
|
||||
/// A list of attributes
|
||||
using AttributeList = std::vector<const Attribute*>;
|
||||
|
||||
/// @param attributes the list of attributes to search
|
||||
/// @returns true if `attributes` includes a attribute of type `T`
|
||||
template <typename T>
|
||||
bool HasAttribute(const AttributeList& attributes) {
|
||||
for (auto* attr : attributes) {
|
||||
if (attr->Is<T>()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// @param attributes the list of attributes to search
|
||||
/// @returns a pointer to `T` from `attributes` if found, otherwise nullptr.
|
||||
template <typename T>
|
||||
const T* GetAttribute(const AttributeList& attributes) {
|
||||
for (auto* attr : attributes) {
|
||||
if (attr->Is<T>()) {
|
||||
return attr->As<T>();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_ATTRIBUTE_H_
|
||||
50
src/tint/ast/binary_expression.cc
Normal file
50
src/tint/ast/binary_expression.cc
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/binary_expression.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::BinaryExpression);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
BinaryExpression::BinaryExpression(ProgramID pid,
|
||||
const Source& src,
|
||||
BinaryOp o,
|
||||
const Expression* l,
|
||||
const Expression* r)
|
||||
: Base(pid, src), op(o), lhs(l), rhs(r) {
|
||||
TINT_ASSERT(AST, lhs);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs, program_id);
|
||||
TINT_ASSERT(AST, rhs);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, rhs, program_id);
|
||||
TINT_ASSERT(AST, op != BinaryOp::kNone);
|
||||
}
|
||||
|
||||
BinaryExpression::BinaryExpression(BinaryExpression&&) = default;
|
||||
|
||||
BinaryExpression::~BinaryExpression() = default;
|
||||
|
||||
const BinaryExpression* BinaryExpression::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
auto* l = ctx->Clone(lhs);
|
||||
auto* r = ctx->Clone(rhs);
|
||||
return ctx->dst->create<BinaryExpression>(src, op, l, r);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
264
src/tint/ast/binary_expression.h
Normal file
264
src/tint/ast/binary_expression.h
Normal file
@@ -0,0 +1,264 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_BINARY_EXPRESSION_H_
|
||||
#define SRC_TINT_AST_BINARY_EXPRESSION_H_
|
||||
|
||||
#include "src/tint/ast/expression.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// The operator type
|
||||
enum class BinaryOp {
|
||||
kNone = 0,
|
||||
kAnd, // &
|
||||
kOr, // |
|
||||
kXor,
|
||||
kLogicalAnd, // &&
|
||||
kLogicalOr, // ||
|
||||
kEqual,
|
||||
kNotEqual,
|
||||
kLessThan,
|
||||
kGreaterThan,
|
||||
kLessThanEqual,
|
||||
kGreaterThanEqual,
|
||||
kShiftLeft,
|
||||
kShiftRight,
|
||||
kAdd,
|
||||
kSubtract,
|
||||
kMultiply,
|
||||
kDivide,
|
||||
kModulo,
|
||||
};
|
||||
|
||||
/// An binary expression
|
||||
class BinaryExpression final : public Castable<BinaryExpression, Expression> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param program_id the identifier of the program that owns this node
|
||||
/// @param source the binary expression source
|
||||
/// @param op the operation type
|
||||
/// @param lhs the left side of the expression
|
||||
/// @param rhs the right side of the expression
|
||||
BinaryExpression(ProgramID program_id,
|
||||
const Source& source,
|
||||
BinaryOp op,
|
||||
const Expression* lhs,
|
||||
const Expression* rhs);
|
||||
/// Move constructor
|
||||
BinaryExpression(BinaryExpression&&);
|
||||
~BinaryExpression() override;
|
||||
|
||||
/// @returns true if the op is and
|
||||
bool IsAnd() const { return op == BinaryOp::kAnd; }
|
||||
/// @returns true if the op is or
|
||||
bool IsOr() const { return op == BinaryOp::kOr; }
|
||||
/// @returns true if the op is xor
|
||||
bool IsXor() const { return op == BinaryOp::kXor; }
|
||||
/// @returns true if the op is logical and
|
||||
bool IsLogicalAnd() const { return op == BinaryOp::kLogicalAnd; }
|
||||
/// @returns true if the op is logical or
|
||||
bool IsLogicalOr() const { return op == BinaryOp::kLogicalOr; }
|
||||
/// @returns true if the op is equal
|
||||
bool IsEqual() const { return op == BinaryOp::kEqual; }
|
||||
/// @returns true if the op is not equal
|
||||
bool IsNotEqual() const { return op == BinaryOp::kNotEqual; }
|
||||
/// @returns true if the op is less than
|
||||
bool IsLessThan() const { return op == BinaryOp::kLessThan; }
|
||||
/// @returns true if the op is greater than
|
||||
bool IsGreaterThan() const { return op == BinaryOp::kGreaterThan; }
|
||||
/// @returns true if the op is less than equal
|
||||
bool IsLessThanEqual() const { return op == BinaryOp::kLessThanEqual; }
|
||||
/// @returns true if the op is greater than equal
|
||||
bool IsGreaterThanEqual() const { return op == BinaryOp::kGreaterThanEqual; }
|
||||
/// @returns true if the op is shift left
|
||||
bool IsShiftLeft() const { return op == BinaryOp::kShiftLeft; }
|
||||
/// @returns true if the op is shift right
|
||||
bool IsShiftRight() const { return op == BinaryOp::kShiftRight; }
|
||||
/// @returns true if the op is add
|
||||
bool IsAdd() const { return op == BinaryOp::kAdd; }
|
||||
/// @returns true if the op is subtract
|
||||
bool IsSubtract() const { return op == BinaryOp::kSubtract; }
|
||||
/// @returns true if the op is multiply
|
||||
bool IsMultiply() const { return op == BinaryOp::kMultiply; }
|
||||
/// @returns true if the op is divide
|
||||
bool IsDivide() const { return op == BinaryOp::kDivide; }
|
||||
/// @returns true if the op is modulo
|
||||
bool IsModulo() const { return op == BinaryOp::kModulo; }
|
||||
/// @returns true if the op is an arithmetic operation
|
||||
bool IsArithmetic() const;
|
||||
/// @returns true if the op is a comparison operation
|
||||
bool IsComparison() const;
|
||||
/// @returns true if the op is a bitwise operation
|
||||
bool IsBitwise() const;
|
||||
/// @returns true if the op is a bit shift operation
|
||||
bool IsBitshift() const;
|
||||
/// @returns true if the op is a logical expression
|
||||
bool IsLogical() const;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const BinaryExpression* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// the binary op type
|
||||
const BinaryOp op;
|
||||
/// the left side expression
|
||||
const Expression* const lhs;
|
||||
/// the right side expression
|
||||
const Expression* const rhs;
|
||||
};
|
||||
|
||||
/// @param op the operator
|
||||
/// @returns true if the op is an arithmetic operation
|
||||
inline bool IsArithmetic(BinaryOp op) {
|
||||
switch (op) {
|
||||
case ast::BinaryOp::kAdd:
|
||||
case ast::BinaryOp::kSubtract:
|
||||
case ast::BinaryOp::kMultiply:
|
||||
case ast::BinaryOp::kDivide:
|
||||
case ast::BinaryOp::kModulo:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// @param op the operator
|
||||
/// @returns true if the op is a comparison operation
|
||||
inline bool IsComparison(BinaryOp op) {
|
||||
switch (op) {
|
||||
case ast::BinaryOp::kEqual:
|
||||
case ast::BinaryOp::kNotEqual:
|
||||
case ast::BinaryOp::kLessThan:
|
||||
case ast::BinaryOp::kLessThanEqual:
|
||||
case ast::BinaryOp::kGreaterThan:
|
||||
case ast::BinaryOp::kGreaterThanEqual:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// @param op the operator
|
||||
/// @returns true if the op is a bitwise operation
|
||||
inline bool IsBitwise(BinaryOp op) {
|
||||
switch (op) {
|
||||
case ast::BinaryOp::kAnd:
|
||||
case ast::BinaryOp::kOr:
|
||||
case ast::BinaryOp::kXor:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// @param op the operator
|
||||
/// @returns true if the op is a bit shift operation
|
||||
inline bool IsBitshift(BinaryOp op) {
|
||||
switch (op) {
|
||||
case ast::BinaryOp::kShiftLeft:
|
||||
case ast::BinaryOp::kShiftRight:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool BinaryExpression::IsLogical() const {
|
||||
switch (op) {
|
||||
case ast::BinaryOp::kLogicalAnd:
|
||||
case ast::BinaryOp::kLogicalOr:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool BinaryExpression::IsArithmetic() const {
|
||||
return ast::IsArithmetic(op);
|
||||
}
|
||||
|
||||
inline bool BinaryExpression::IsComparison() const {
|
||||
return ast::IsComparison(op);
|
||||
}
|
||||
|
||||
inline bool BinaryExpression::IsBitwise() const {
|
||||
return ast::IsBitwise(op);
|
||||
}
|
||||
|
||||
inline bool BinaryExpression::IsBitshift() const {
|
||||
return ast::IsBitshift(op);
|
||||
}
|
||||
|
||||
/// @returns the human readable name of the given BinaryOp
|
||||
/// @param op the BinaryOp
|
||||
constexpr const char* FriendlyName(BinaryOp op) {
|
||||
switch (op) {
|
||||
case BinaryOp::kNone:
|
||||
return "none";
|
||||
case BinaryOp::kAnd:
|
||||
return "and";
|
||||
case BinaryOp::kOr:
|
||||
return "or";
|
||||
case BinaryOp::kXor:
|
||||
return "xor";
|
||||
case BinaryOp::kLogicalAnd:
|
||||
return "logical_and";
|
||||
case BinaryOp::kLogicalOr:
|
||||
return "logical_or";
|
||||
case BinaryOp::kEqual:
|
||||
return "equal";
|
||||
case BinaryOp::kNotEqual:
|
||||
return "not_equal";
|
||||
case BinaryOp::kLessThan:
|
||||
return "less_than";
|
||||
case BinaryOp::kGreaterThan:
|
||||
return "greater_than";
|
||||
case BinaryOp::kLessThanEqual:
|
||||
return "less_than_equal";
|
||||
case BinaryOp::kGreaterThanEqual:
|
||||
return "greater_than_equal";
|
||||
case BinaryOp::kShiftLeft:
|
||||
return "shift_left";
|
||||
case BinaryOp::kShiftRight:
|
||||
return "shift_right";
|
||||
case BinaryOp::kAdd:
|
||||
return "add";
|
||||
case BinaryOp::kSubtract:
|
||||
return "subtract";
|
||||
case BinaryOp::kMultiply:
|
||||
return "multiply";
|
||||
case BinaryOp::kDivide:
|
||||
return "divide";
|
||||
case BinaryOp::kModulo:
|
||||
return "modulo";
|
||||
}
|
||||
return "INVALID";
|
||||
}
|
||||
|
||||
/// @param out the std::ostream to write to
|
||||
/// @param op the BinaryOp
|
||||
/// @return the std::ostream so calls can be chained
|
||||
inline std::ostream& operator<<(std::ostream& out, BinaryOp op) {
|
||||
out << FriendlyName(op);
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_BINARY_EXPRESSION_H_
|
||||
95
src/tint/ast/binary_expression_test.cc
Normal file
95
src/tint/ast/binary_expression_test.cc
Normal file
@@ -0,0 +1,95 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "gtest/gtest-spi.h"
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using BinaryExpressionTest = TestHelper;
|
||||
|
||||
TEST_F(BinaryExpressionTest, Creation) {
|
||||
auto* lhs = Expr("lhs");
|
||||
auto* rhs = Expr("rhs");
|
||||
|
||||
auto* r = create<BinaryExpression>(BinaryOp::kEqual, lhs, rhs);
|
||||
EXPECT_EQ(r->lhs, lhs);
|
||||
EXPECT_EQ(r->rhs, rhs);
|
||||
EXPECT_EQ(r->op, BinaryOp::kEqual);
|
||||
}
|
||||
|
||||
TEST_F(BinaryExpressionTest, Creation_WithSource) {
|
||||
auto* lhs = Expr("lhs");
|
||||
auto* rhs = Expr("rhs");
|
||||
|
||||
auto* r = create<BinaryExpression>(Source{Source::Location{20, 2}},
|
||||
BinaryOp::kEqual, lhs, rhs);
|
||||
auto src = r->source;
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
}
|
||||
|
||||
TEST_F(BinaryExpressionTest, IsBinary) {
|
||||
auto* lhs = Expr("lhs");
|
||||
auto* rhs = Expr("rhs");
|
||||
|
||||
auto* r = create<BinaryExpression>(BinaryOp::kEqual, lhs, rhs);
|
||||
EXPECT_TRUE(r->Is<BinaryExpression>());
|
||||
}
|
||||
|
||||
TEST_F(BinaryExpressionTest, Assert_Null_LHS) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<BinaryExpression>(BinaryOp::kEqual, nullptr, b.Expr("rhs"));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(BinaryExpressionTest, Assert_Null_RHS) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<BinaryExpression>(BinaryOp::kEqual, b.Expr("lhs"), nullptr);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(BinaryExpressionTest, Assert_DifferentProgramID_LHS) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<BinaryExpression>(BinaryOp::kEqual, b2.Expr("lhs"),
|
||||
b1.Expr("rhs"));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(BinaryExpressionTest, Assert_DifferentProgramID_RHS) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<BinaryExpression>(BinaryOp::kEqual, b1.Expr("lhs"),
|
||||
b2.Expr("rhs"));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
44
src/tint/ast/binding_attribute.cc
Normal file
44
src/tint/ast/binding_attribute.cc
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/binding_attribute.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::BindingAttribute);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
BindingAttribute::BindingAttribute(ProgramID pid,
|
||||
const Source& src,
|
||||
uint32_t val)
|
||||
: Base(pid, src), value(val) {}
|
||||
|
||||
BindingAttribute::~BindingAttribute() = default;
|
||||
|
||||
std::string BindingAttribute::Name() const {
|
||||
return "binding";
|
||||
}
|
||||
|
||||
const BindingAttribute* BindingAttribute::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
return ctx->dst->create<BindingAttribute>(src, value);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
51
src/tint/ast/binding_attribute.h
Normal file
51
src/tint/ast/binding_attribute.h
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_BINDING_ATTRIBUTE_H_
|
||||
#define SRC_TINT_AST_BINDING_ATTRIBUTE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/ast/attribute.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// A binding attribute
|
||||
class BindingAttribute final : public Castable<BindingAttribute, Attribute> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
/// @param value the binding value
|
||||
BindingAttribute(ProgramID pid, const Source& src, uint32_t value);
|
||||
~BindingAttribute() override;
|
||||
|
||||
/// @returns the WGSL name for the attribute
|
||||
std::string Name() const override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const BindingAttribute* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// the binding value
|
||||
const uint32_t value;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_BINDING_ATTRIBUTE_H_
|
||||
30
src/tint/ast/binding_attribute_test.cc
Normal file
30
src/tint/ast/binding_attribute_test.cc
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using BindingAttributeTest = TestHelper;
|
||||
|
||||
TEST_F(BindingAttributeTest, Creation) {
|
||||
auto* d = create<BindingAttribute>(2);
|
||||
EXPECT_EQ(2u, d->value);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
46
src/tint/ast/bitcast_expression.cc
Normal file
46
src/tint/ast/bitcast_expression.cc
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/bitcast_expression.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::BitcastExpression);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
BitcastExpression::BitcastExpression(ProgramID pid,
|
||||
const Source& src,
|
||||
const Type* t,
|
||||
const Expression* e)
|
||||
: Base(pid, src), type(t), expr(e) {
|
||||
TINT_ASSERT(AST, type);
|
||||
TINT_ASSERT(AST, expr);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, expr, program_id);
|
||||
}
|
||||
|
||||
BitcastExpression::BitcastExpression(BitcastExpression&&) = default;
|
||||
BitcastExpression::~BitcastExpression() = default;
|
||||
|
||||
const BitcastExpression* BitcastExpression::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
auto* t = ctx->Clone(type);
|
||||
auto* e = ctx->Clone(expr);
|
||||
return ctx->dst->create<BitcastExpression>(src, t, e);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
57
src/tint/ast/bitcast_expression.h
Normal file
57
src/tint/ast/bitcast_expression.h
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_BITCAST_EXPRESSION_H_
|
||||
#define SRC_TINT_AST_BITCAST_EXPRESSION_H_
|
||||
|
||||
#include "src/tint/ast/expression.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
// Forward declaration
|
||||
class Type;
|
||||
|
||||
/// A bitcast expression
|
||||
class BitcastExpression final : public Castable<BitcastExpression, Expression> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param program_id the identifier of the program that owns this node
|
||||
/// @param source the bitcast expression source
|
||||
/// @param type the type
|
||||
/// @param expr the expr
|
||||
BitcastExpression(ProgramID program_id,
|
||||
const Source& source,
|
||||
const Type* type,
|
||||
const Expression* expr);
|
||||
/// Move constructor
|
||||
BitcastExpression(BitcastExpression&&);
|
||||
~BitcastExpression() override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const BitcastExpression* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// the target cast type
|
||||
const Type* const type;
|
||||
/// the expression
|
||||
const Expression* const expr;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_BITCAST_EXPRESSION_H_
|
||||
81
src/tint/ast/bitcast_expression_test.cc
Normal file
81
src/tint/ast/bitcast_expression_test.cc
Normal file
@@ -0,0 +1,81 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/bitcast_expression.h"
|
||||
|
||||
#include "gtest/gtest-spi.h"
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using BitcastExpressionTest = TestHelper;
|
||||
|
||||
TEST_F(BitcastExpressionTest, Create) {
|
||||
auto* expr = Expr("expr");
|
||||
|
||||
auto* exp = create<BitcastExpression>(ty.f32(), expr);
|
||||
EXPECT_TRUE(exp->type->Is<ast::F32>());
|
||||
ASSERT_EQ(exp->expr, expr);
|
||||
}
|
||||
|
||||
TEST_F(BitcastExpressionTest, CreateWithSource) {
|
||||
auto* expr = Expr("expr");
|
||||
|
||||
auto* exp = create<BitcastExpression>(Source{Source::Location{20, 2}},
|
||||
ty.f32(), expr);
|
||||
auto src = exp->source;
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
}
|
||||
|
||||
TEST_F(BitcastExpressionTest, IsBitcast) {
|
||||
auto* expr = Expr("expr");
|
||||
|
||||
auto* exp = create<BitcastExpression>(ty.f32(), expr);
|
||||
EXPECT_TRUE(exp->Is<BitcastExpression>());
|
||||
}
|
||||
|
||||
TEST_F(BitcastExpressionTest, Assert_Null_Type) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<BitcastExpression>(nullptr, b.Expr("idx"));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(BitcastExpressionTest, Assert_Null_Expr) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<BitcastExpression>(b.ty.f32(), nullptr);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(BitcastExpressionTest, Assert_DifferentProgramID_Expr) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<BitcastExpression>(b1.ty.f32(), b2.Expr("idx"));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
46
src/tint/ast/block_statement.cc
Normal file
46
src/tint/ast/block_statement.cc
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/block_statement.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::BlockStatement);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
BlockStatement::BlockStatement(ProgramID pid,
|
||||
const Source& src,
|
||||
const StatementList& stmts)
|
||||
: Base(pid, src), statements(std::move(stmts)) {
|
||||
for (auto* stmt : statements) {
|
||||
TINT_ASSERT(AST, stmt);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, stmt, program_id);
|
||||
}
|
||||
}
|
||||
|
||||
BlockStatement::BlockStatement(BlockStatement&&) = default;
|
||||
|
||||
BlockStatement::~BlockStatement() = default;
|
||||
|
||||
const BlockStatement* BlockStatement::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
auto stmts = ctx->Clone(statements);
|
||||
return ctx->dst->create<BlockStatement>(src, stmts);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
60
src/tint/ast/block_statement.h
Normal file
60
src/tint/ast/block_statement.h
Normal file
@@ -0,0 +1,60 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_BLOCK_STATEMENT_H_
|
||||
#define SRC_TINT_AST_BLOCK_STATEMENT_H_
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "src/tint/ast/statement.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// A block statement
|
||||
class BlockStatement final : public Castable<BlockStatement, Statement> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param program_id the identifier of the program that owns this node
|
||||
/// @param source the block statement source
|
||||
/// @param statements the statements
|
||||
BlockStatement(ProgramID program_id,
|
||||
const Source& source,
|
||||
const StatementList& statements);
|
||||
/// Move constructor
|
||||
BlockStatement(BlockStatement&&);
|
||||
~BlockStatement() override;
|
||||
|
||||
/// @returns true if the block has no statements
|
||||
bool Empty() const { return statements.empty(); }
|
||||
|
||||
/// @returns the last statement in the block or nullptr if block empty
|
||||
const Statement* Last() const {
|
||||
return statements.empty() ? nullptr : statements.back();
|
||||
}
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const BlockStatement* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// the statement list
|
||||
const StatementList statements;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_BLOCK_STATEMENT_H_
|
||||
71
src/tint/ast/block_statement_test.cc
Normal file
71
src/tint/ast/block_statement_test.cc
Normal file
@@ -0,0 +1,71 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "gtest/gtest-spi.h"
|
||||
#include "src/tint/ast/discard_statement.h"
|
||||
#include "src/tint/ast/if_statement.h"
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using BlockStatementTest = TestHelper;
|
||||
|
||||
TEST_F(BlockStatementTest, Creation) {
|
||||
auto* d = create<DiscardStatement>();
|
||||
auto* ptr = d;
|
||||
|
||||
auto* b = create<BlockStatement>(StatementList{d});
|
||||
|
||||
ASSERT_EQ(b->statements.size(), 1u);
|
||||
EXPECT_EQ(b->statements[0], ptr);
|
||||
}
|
||||
|
||||
TEST_F(BlockStatementTest, Creation_WithSource) {
|
||||
auto* b = create<BlockStatement>(Source{Source::Location{20, 2}},
|
||||
ast::StatementList{});
|
||||
auto src = b->source;
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
}
|
||||
|
||||
TEST_F(BlockStatementTest, IsBlock) {
|
||||
auto* b = create<BlockStatement>(ast::StatementList{});
|
||||
EXPECT_TRUE(b->Is<BlockStatement>());
|
||||
}
|
||||
|
||||
TEST_F(BlockStatementTest, Assert_Null_Statement) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<BlockStatement>(ast::StatementList{nullptr});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(BlockStatementTest, Assert_DifferentProgramID_Statement) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<BlockStatement>(
|
||||
ast::StatementList{b2.create<DiscardStatement>()});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
40
src/tint/ast/bool.cc
Normal file
40
src/tint/ast/bool.cc
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/bool.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::Bool);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
Bool::Bool(ProgramID pid, const Source& src) : Base(pid, src) {}
|
||||
|
||||
Bool::Bool(Bool&&) = default;
|
||||
|
||||
Bool::~Bool() = default;
|
||||
|
||||
std::string Bool::FriendlyName(const SymbolTable&) const {
|
||||
return "bool";
|
||||
}
|
||||
|
||||
const Bool* Bool::Clone(CloneContext* ctx) const {
|
||||
auto src = ctx->Clone(source);
|
||||
return ctx->dst->create<Bool>(src);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
56
src/tint/ast/bool.h
Normal file
56
src/tint/ast/bool.h
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_BOOL_H_
|
||||
#define SRC_TINT_AST_BOOL_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/ast/type.h"
|
||||
|
||||
// X11 likes to #define Bool leading to confusing error messages.
|
||||
// If its defined, undefine it.
|
||||
#ifdef Bool
|
||||
#undef Bool
|
||||
#endif
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// A boolean type
|
||||
class Bool final : public Castable<Bool, Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
Bool(ProgramID pid, const Source& src);
|
||||
/// Move constructor
|
||||
Bool(Bool&&);
|
||||
~Bool() override;
|
||||
|
||||
/// @param symbols the program's symbol table
|
||||
/// @returns the name for this type that closely resembles how it would be
|
||||
/// declared in WGSL.
|
||||
std::string FriendlyName(const SymbolTable& symbols) const override;
|
||||
|
||||
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned type
|
||||
const Bool* Clone(CloneContext* ctx) const override;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_BOOL_H_
|
||||
39
src/tint/ast/bool_literal_expression.cc
Normal file
39
src/tint/ast/bool_literal_expression.cc
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/bool_literal_expression.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::BoolLiteralExpression);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
BoolLiteralExpression::BoolLiteralExpression(ProgramID pid,
|
||||
const Source& src,
|
||||
bool val)
|
||||
: Base(pid, src), value(val) {}
|
||||
|
||||
BoolLiteralExpression::~BoolLiteralExpression() = default;
|
||||
|
||||
const BoolLiteralExpression* BoolLiteralExpression::Clone(
|
||||
CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
return ctx->dst->create<BoolLiteralExpression>(src, value);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
49
src/tint/ast/bool_literal_expression.h
Normal file
49
src/tint/ast/bool_literal_expression.h
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_BOOL_LITERAL_EXPRESSION_H_
|
||||
#define SRC_TINT_AST_BOOL_LITERAL_EXPRESSION_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/ast/literal_expression.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// A boolean literal
|
||||
class BoolLiteralExpression final
|
||||
: public Castable<BoolLiteralExpression, LiteralExpression> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
/// @param value the bool literals value
|
||||
BoolLiteralExpression(ProgramID pid, const Source& src, bool value);
|
||||
~BoolLiteralExpression() override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const BoolLiteralExpression* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// The boolean literal value
|
||||
const bool value;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_BOOL_LITERAL_EXPRESSION_H_
|
||||
37
src/tint/ast/bool_literal_expression_test.cc
Normal file
37
src/tint/ast/bool_literal_expression_test.cc
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using BoolLiteralExpressionTest = TestHelper;
|
||||
|
||||
TEST_F(BoolLiteralExpressionTest, True) {
|
||||
auto* b = create<BoolLiteralExpression>(true);
|
||||
ASSERT_TRUE(b->Is<BoolLiteralExpression>());
|
||||
ASSERT_TRUE(b->value);
|
||||
}
|
||||
|
||||
TEST_F(BoolLiteralExpressionTest, False) {
|
||||
auto* b = create<BoolLiteralExpression>(false);
|
||||
ASSERT_TRUE(b->Is<BoolLiteralExpression>());
|
||||
ASSERT_FALSE(b->value);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
32
src/tint/ast/bool_test.cc
Normal file
32
src/tint/ast/bool_test.cc
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/bool.h"
|
||||
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using AstBoolTest = TestHelper;
|
||||
|
||||
TEST_F(AstBoolTest, FriendlyName) {
|
||||
auto* b = create<Bool>();
|
||||
EXPECT_EQ(b->FriendlyName(Symbols()), "bool");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
38
src/tint/ast/break_statement.cc
Normal file
38
src/tint/ast/break_statement.cc
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/break_statement.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::BreakStatement);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
BreakStatement::BreakStatement(ProgramID pid, const Source& src)
|
||||
: Base(pid, src) {}
|
||||
|
||||
BreakStatement::BreakStatement(BreakStatement&&) = default;
|
||||
|
||||
BreakStatement::~BreakStatement() = default;
|
||||
|
||||
const BreakStatement* BreakStatement::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
return ctx->dst->create<BreakStatement>(src);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
44
src/tint/ast/break_statement.h
Normal file
44
src/tint/ast/break_statement.h
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_BREAK_STATEMENT_H_
|
||||
#define SRC_TINT_AST_BREAK_STATEMENT_H_
|
||||
|
||||
#include "src/tint/ast/statement.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// An break statement
|
||||
class BreakStatement final : public Castable<BreakStatement, Statement> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
BreakStatement(ProgramID pid, const Source& src);
|
||||
/// Move constructor
|
||||
BreakStatement(BreakStatement&&);
|
||||
~BreakStatement() override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const BreakStatement* Clone(CloneContext* ctx) const override;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_BREAK_STATEMENT_H_
|
||||
39
src/tint/ast/break_statement_test.cc
Normal file
39
src/tint/ast/break_statement_test.cc
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/break_statement.h"
|
||||
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using BreakStatementTest = TestHelper;
|
||||
|
||||
TEST_F(BreakStatementTest, Creation_WithSource) {
|
||||
auto* stmt = create<BreakStatement>(Source{Source::Location{20, 2}});
|
||||
auto src = stmt->source;
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
}
|
||||
|
||||
TEST_F(BreakStatementTest, IsBreak) {
|
||||
auto* stmt = create<BreakStatement>();
|
||||
EXPECT_TRUE(stmt->Is<BreakStatement>());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
82
src/tint/ast/builtin.cc
Normal file
82
src/tint/ast/builtin.cc
Normal file
@@ -0,0 +1,82 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/builtin.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, Builtin builtin) {
|
||||
switch (builtin) {
|
||||
case Builtin::kNone: {
|
||||
out << "none";
|
||||
break;
|
||||
}
|
||||
case Builtin::kPosition: {
|
||||
out << "position";
|
||||
break;
|
||||
}
|
||||
case Builtin::kVertexIndex: {
|
||||
out << "vertex_index";
|
||||
break;
|
||||
}
|
||||
case Builtin::kInstanceIndex: {
|
||||
out << "instance_index";
|
||||
break;
|
||||
}
|
||||
case Builtin::kFrontFacing: {
|
||||
out << "front_facing";
|
||||
break;
|
||||
}
|
||||
case Builtin::kFragDepth: {
|
||||
out << "frag_depth";
|
||||
break;
|
||||
}
|
||||
case Builtin::kLocalInvocationId: {
|
||||
out << "local_invocation_id";
|
||||
break;
|
||||
}
|
||||
case Builtin::kLocalInvocationIndex: {
|
||||
out << "local_invocation_index";
|
||||
break;
|
||||
}
|
||||
case Builtin::kGlobalInvocationId: {
|
||||
out << "global_invocation_id";
|
||||
break;
|
||||
}
|
||||
case Builtin::kWorkgroupId: {
|
||||
out << "workgroup_id";
|
||||
break;
|
||||
}
|
||||
case Builtin::kNumWorkgroups: {
|
||||
out << "num_workgroups";
|
||||
break;
|
||||
}
|
||||
case Builtin::kSampleIndex: {
|
||||
out << "sample_index";
|
||||
break;
|
||||
}
|
||||
case Builtin::kSampleMask: {
|
||||
out << "sample_mask";
|
||||
break;
|
||||
}
|
||||
case Builtin::kPointSize: {
|
||||
out << "pointsize";
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
52
src/tint/ast/builtin.h
Normal file
52
src/tint/ast/builtin.h
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_BUILTIN_H_
|
||||
#define SRC_TINT_AST_BUILTIN_H_
|
||||
|
||||
#include <ostream>
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// The builtin identifiers
|
||||
enum class Builtin {
|
||||
kNone = -1,
|
||||
kPosition,
|
||||
kVertexIndex,
|
||||
kInstanceIndex,
|
||||
kFrontFacing,
|
||||
kFragDepth,
|
||||
kLocalInvocationId,
|
||||
kLocalInvocationIndex,
|
||||
kGlobalInvocationId,
|
||||
kWorkgroupId,
|
||||
kNumWorkgroups,
|
||||
kSampleIndex,
|
||||
kSampleMask,
|
||||
|
||||
// Below are not currently WGSL builtins, but are included in this enum as
|
||||
// they are used by certain backends.
|
||||
kPointSize,
|
||||
};
|
||||
|
||||
/// @param out the std::ostream to write to
|
||||
/// @param builtin the Builtin
|
||||
/// @return the std::ostream so calls can be chained
|
||||
std::ostream& operator<<(std::ostream& out, Builtin builtin);
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_BUILTIN_H_
|
||||
42
src/tint/ast/builtin_attribute.cc
Normal file
42
src/tint/ast/builtin_attribute.cc
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/builtin_attribute.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::BuiltinAttribute);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
BuiltinAttribute::BuiltinAttribute(ProgramID pid, const Source& src, Builtin b)
|
||||
: Base(pid, src), builtin(b) {}
|
||||
|
||||
BuiltinAttribute::~BuiltinAttribute() = default;
|
||||
|
||||
std::string BuiltinAttribute::Name() const {
|
||||
return "builtin";
|
||||
}
|
||||
|
||||
const BuiltinAttribute* BuiltinAttribute::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
return ctx->dst->create<BuiltinAttribute>(src, builtin);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
52
src/tint/ast/builtin_attribute.h
Normal file
52
src/tint/ast/builtin_attribute.h
Normal file
@@ -0,0 +1,52 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_BUILTIN_ATTRIBUTE_H_
|
||||
#define SRC_TINT_AST_BUILTIN_ATTRIBUTE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/ast/attribute.h"
|
||||
#include "src/tint/ast/builtin.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// A builtin attribute
|
||||
class BuiltinAttribute final : public Castable<BuiltinAttribute, Attribute> {
|
||||
public:
|
||||
/// constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
/// @param builtin the builtin value
|
||||
BuiltinAttribute(ProgramID pid, const Source& src, Builtin builtin);
|
||||
~BuiltinAttribute() override;
|
||||
|
||||
/// @returns the WGSL name for the attribute
|
||||
std::string Name() const override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const BuiltinAttribute* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// The builtin value
|
||||
const Builtin builtin;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_BUILTIN_ATTRIBUTE_H_
|
||||
30
src/tint/ast/builtin_attribute_test.cc
Normal file
30
src/tint/ast/builtin_attribute_test.cc
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied->
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using BuiltinAttributeTest = TestHelper;
|
||||
|
||||
TEST_F(BuiltinAttributeTest, Creation) {
|
||||
auto* d = create<BuiltinAttribute>(Builtin::kFragDepth);
|
||||
EXPECT_EQ(Builtin::kFragDepth, d->builtin);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
2286
src/tint/ast/builtin_texture_helper_test.cc
Normal file
2286
src/tint/ast/builtin_texture_helper_test.cc
Normal file
File diff suppressed because it is too large
Load Diff
269
src/tint/ast/builtin_texture_helper_test.h
Normal file
269
src/tint/ast/builtin_texture_helper_test.h
Normal file
@@ -0,0 +1,269 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_BUILTIN_TEXTURE_HELPER_TEST_H_
|
||||
#define SRC_TINT_AST_BUILTIN_TEXTURE_HELPER_TEST_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "src/tint/ast/access.h"
|
||||
#include "src/tint/program_builder.h"
|
||||
#include "src/tint/sem/storage_texture_type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace builtin {
|
||||
namespace test {
|
||||
|
||||
enum class TextureKind {
|
||||
kRegular,
|
||||
kDepth,
|
||||
kDepthMultisampled,
|
||||
kMultisampled,
|
||||
kStorage
|
||||
};
|
||||
enum class TextureDataType { kF32, kU32, kI32 };
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const TextureKind& kind);
|
||||
std::ostream& operator<<(std::ostream& out, const TextureDataType& ty);
|
||||
|
||||
/// Non-exhaustive list of valid texture overloads
|
||||
enum class ValidTextureOverload {
|
||||
kDimensions1d,
|
||||
kDimensions2d,
|
||||
kDimensions2dLevel,
|
||||
kDimensions2dArray,
|
||||
kDimensions2dArrayLevel,
|
||||
kDimensions3d,
|
||||
kDimensions3dLevel,
|
||||
kDimensionsCube,
|
||||
kDimensionsCubeLevel,
|
||||
kDimensionsCubeArray,
|
||||
kDimensionsCubeArrayLevel,
|
||||
kDimensionsMultisampled2d,
|
||||
kDimensionsDepth2d,
|
||||
kDimensionsDepth2dLevel,
|
||||
kDimensionsDepth2dArray,
|
||||
kDimensionsDepth2dArrayLevel,
|
||||
kDimensionsDepthCube,
|
||||
kDimensionsDepthCubeLevel,
|
||||
kDimensionsDepthCubeArray,
|
||||
kDimensionsDepthCubeArrayLevel,
|
||||
kDimensionsDepthMultisampled2d,
|
||||
kDimensionsStorageWO1d,
|
||||
kDimensionsStorageWO2d,
|
||||
kDimensionsStorageWO2dArray,
|
||||
kDimensionsStorageWO3d,
|
||||
kGather2dF32,
|
||||
kGather2dOffsetF32,
|
||||
kGather2dArrayF32,
|
||||
kGather2dArrayOffsetF32,
|
||||
kGatherCubeF32,
|
||||
kGatherCubeArrayF32,
|
||||
kGatherDepth2dF32,
|
||||
kGatherDepth2dOffsetF32,
|
||||
kGatherDepth2dArrayF32,
|
||||
kGatherDepth2dArrayOffsetF32,
|
||||
kGatherDepthCubeF32,
|
||||
kGatherDepthCubeArrayF32,
|
||||
kGatherCompareDepth2dF32,
|
||||
kGatherCompareDepth2dOffsetF32,
|
||||
kGatherCompareDepth2dArrayF32,
|
||||
kGatherCompareDepth2dArrayOffsetF32,
|
||||
kGatherCompareDepthCubeF32,
|
||||
kGatherCompareDepthCubeArrayF32,
|
||||
kNumLayers2dArray,
|
||||
kNumLayersCubeArray,
|
||||
kNumLayersDepth2dArray,
|
||||
kNumLayersDepthCubeArray,
|
||||
kNumLayersStorageWO2dArray,
|
||||
kNumLevels2d,
|
||||
kNumLevels2dArray,
|
||||
kNumLevels3d,
|
||||
kNumLevelsCube,
|
||||
kNumLevelsCubeArray,
|
||||
kNumLevelsDepth2d,
|
||||
kNumLevelsDepth2dArray,
|
||||
kNumLevelsDepthCube,
|
||||
kNumLevelsDepthCubeArray,
|
||||
kNumSamplesMultisampled2d,
|
||||
kNumSamplesDepthMultisampled2d,
|
||||
kSample1dF32,
|
||||
kSample2dF32,
|
||||
kSample2dOffsetF32,
|
||||
kSample2dArrayF32,
|
||||
kSample2dArrayOffsetF32,
|
||||
kSample3dF32,
|
||||
kSample3dOffsetF32,
|
||||
kSampleCubeF32,
|
||||
kSampleCubeArrayF32,
|
||||
kSampleDepth2dF32,
|
||||
kSampleDepth2dOffsetF32,
|
||||
kSampleDepth2dArrayF32,
|
||||
kSampleDepth2dArrayOffsetF32,
|
||||
kSampleDepthCubeF32,
|
||||
kSampleDepthCubeArrayF32,
|
||||
kSampleBias2dF32,
|
||||
kSampleBias2dOffsetF32,
|
||||
kSampleBias2dArrayF32,
|
||||
kSampleBias2dArrayOffsetF32,
|
||||
kSampleBias3dF32,
|
||||
kSampleBias3dOffsetF32,
|
||||
kSampleBiasCubeF32,
|
||||
kSampleBiasCubeArrayF32,
|
||||
kSampleLevel2dF32,
|
||||
kSampleLevel2dOffsetF32,
|
||||
kSampleLevel2dArrayF32,
|
||||
kSampleLevel2dArrayOffsetF32,
|
||||
kSampleLevel3dF32,
|
||||
kSampleLevel3dOffsetF32,
|
||||
kSampleLevelCubeF32,
|
||||
kSampleLevelCubeArrayF32,
|
||||
kSampleLevelDepth2dF32,
|
||||
kSampleLevelDepth2dOffsetF32,
|
||||
kSampleLevelDepth2dArrayF32,
|
||||
kSampleLevelDepth2dArrayOffsetF32,
|
||||
kSampleLevelDepthCubeF32,
|
||||
kSampleLevelDepthCubeArrayF32,
|
||||
kSampleGrad2dF32,
|
||||
kSampleGrad2dOffsetF32,
|
||||
kSampleGrad2dArrayF32,
|
||||
kSampleGrad2dArrayOffsetF32,
|
||||
kSampleGrad3dF32,
|
||||
kSampleGrad3dOffsetF32,
|
||||
kSampleGradCubeF32,
|
||||
kSampleGradCubeArrayF32,
|
||||
kSampleCompareDepth2dF32,
|
||||
kSampleCompareDepth2dOffsetF32,
|
||||
kSampleCompareDepth2dArrayF32,
|
||||
kSampleCompareDepth2dArrayOffsetF32,
|
||||
kSampleCompareDepthCubeF32,
|
||||
kSampleCompareDepthCubeArrayF32,
|
||||
kSampleCompareLevelDepth2dF32,
|
||||
kSampleCompareLevelDepth2dOffsetF32,
|
||||
kSampleCompareLevelDepth2dArrayF32,
|
||||
kSampleCompareLevelDepth2dArrayOffsetF32,
|
||||
kSampleCompareLevelDepthCubeF32,
|
||||
kSampleCompareLevelDepthCubeArrayF32,
|
||||
kLoad1dLevelF32,
|
||||
kLoad1dLevelU32,
|
||||
kLoad1dLevelI32,
|
||||
kLoad2dLevelF32,
|
||||
kLoad2dLevelU32,
|
||||
kLoad2dLevelI32,
|
||||
kLoad2dArrayLevelF32,
|
||||
kLoad2dArrayLevelU32,
|
||||
kLoad2dArrayLevelI32,
|
||||
kLoad3dLevelF32,
|
||||
kLoad3dLevelU32,
|
||||
kLoad3dLevelI32,
|
||||
kLoadMultisampled2dF32,
|
||||
kLoadMultisampled2dU32,
|
||||
kLoadMultisampled2dI32,
|
||||
kLoadDepth2dLevelF32,
|
||||
kLoadDepth2dArrayLevelF32,
|
||||
kLoadDepthMultisampled2dF32,
|
||||
kStoreWO1dRgba32float, // Not permutated for all texel formats
|
||||
kStoreWO2dRgba32float, // Not permutated for all texel formats
|
||||
kStoreWO2dArrayRgba32float, // Not permutated for all texel formats
|
||||
kStoreWO3dRgba32float, // Not permutated for all texel formats
|
||||
};
|
||||
|
||||
/// @param texture_overload the ValidTextureOverload
|
||||
/// @returns true if the ValidTextureOverload builtin returns no value.
|
||||
bool ReturnsVoid(ValidTextureOverload texture_overload);
|
||||
|
||||
/// Describes a texture builtin overload
|
||||
struct TextureOverloadCase {
|
||||
/// Constructor for textureSample...() functions
|
||||
TextureOverloadCase(ValidTextureOverload,
|
||||
const char*,
|
||||
TextureKind,
|
||||
ast::SamplerKind,
|
||||
ast::TextureDimension,
|
||||
TextureDataType,
|
||||
const char*,
|
||||
std::function<ExpressionList(ProgramBuilder*)>);
|
||||
/// Constructor for textureLoad() functions with non-storage textures
|
||||
TextureOverloadCase(ValidTextureOverload,
|
||||
const char*,
|
||||
TextureKind,
|
||||
ast::TextureDimension,
|
||||
TextureDataType,
|
||||
const char*,
|
||||
std::function<ExpressionList(ProgramBuilder*)>);
|
||||
/// Constructor for textureLoad() with storage textures
|
||||
TextureOverloadCase(ValidTextureOverload,
|
||||
const char*,
|
||||
Access,
|
||||
ast::TexelFormat,
|
||||
ast::TextureDimension,
|
||||
TextureDataType,
|
||||
const char*,
|
||||
std::function<ExpressionList(ProgramBuilder*)>);
|
||||
/// Copy constructor
|
||||
TextureOverloadCase(const TextureOverloadCase&);
|
||||
/// Destructor
|
||||
~TextureOverloadCase();
|
||||
|
||||
/// @return a vector containing a large number (non-exhaustive) of valid
|
||||
/// texture overloads.
|
||||
static std::vector<TextureOverloadCase> ValidCases();
|
||||
|
||||
/// @param builder the AST builder used for the test
|
||||
/// @returns the vector component type of the texture function return value
|
||||
const ast::Type* BuildResultVectorComponentType(
|
||||
ProgramBuilder* builder) const;
|
||||
/// @param builder the AST builder used for the test
|
||||
/// @returns a variable holding the test texture, automatically registered as
|
||||
/// a global variable.
|
||||
const ast::Variable* BuildTextureVariable(ProgramBuilder* builder) const;
|
||||
/// @param builder the AST builder used for the test
|
||||
/// @returns a Variable holding the test sampler, automatically registered as
|
||||
/// a global variable.
|
||||
const ast::Variable* BuildSamplerVariable(ProgramBuilder* builder) const;
|
||||
|
||||
/// The enumerator for this overload
|
||||
const ValidTextureOverload overload;
|
||||
/// A human readable description of the overload
|
||||
const char* const description;
|
||||
/// The texture kind for the texture parameter
|
||||
const TextureKind texture_kind;
|
||||
/// The sampler kind for the sampler parameter
|
||||
/// Used only when texture_kind is not kStorage
|
||||
ast::SamplerKind const sampler_kind = ast::SamplerKind::kSampler;
|
||||
/// The access control for the storage texture
|
||||
/// Used only when texture_kind is kStorage
|
||||
Access const access = Access::kReadWrite;
|
||||
/// The image format for the storage texture
|
||||
/// Used only when texture_kind is kStorage
|
||||
ast::TexelFormat const texel_format = ast::TexelFormat::kNone;
|
||||
/// The dimensions of the texture parameter
|
||||
ast::TextureDimension const texture_dimension;
|
||||
/// The data type of the texture parameter
|
||||
const TextureDataType texture_data_type;
|
||||
/// Name of the function. e.g. `textureSample`, `textureSampleGrad`, etc
|
||||
const char* const function;
|
||||
/// A function that builds the AST arguments for the overload
|
||||
std::function<ExpressionList(ProgramBuilder*)> const args;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const TextureOverloadCase& data);
|
||||
|
||||
} // namespace test
|
||||
} // namespace builtin
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_BUILTIN_TEXTURE_HELPER_TEST_H_
|
||||
78
src/tint/ast/call_expression.cc
Normal file
78
src/tint/ast/call_expression.cc
Normal file
@@ -0,0 +1,78 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/call_expression.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::CallExpression);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
namespace {
|
||||
CallExpression::Target ToTarget(const IdentifierExpression* name) {
|
||||
CallExpression::Target target;
|
||||
target.name = name;
|
||||
return target;
|
||||
}
|
||||
CallExpression::Target ToTarget(const Type* type) {
|
||||
CallExpression::Target target;
|
||||
target.type = type;
|
||||
return target;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
CallExpression::CallExpression(ProgramID pid,
|
||||
const Source& src,
|
||||
const IdentifierExpression* name,
|
||||
ExpressionList a)
|
||||
: Base(pid, src), target(ToTarget(name)), args(a) {
|
||||
TINT_ASSERT(AST, name);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, name, program_id);
|
||||
for (auto* arg : args) {
|
||||
TINT_ASSERT(AST, arg);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, arg, program_id);
|
||||
}
|
||||
}
|
||||
|
||||
CallExpression::CallExpression(ProgramID pid,
|
||||
const Source& src,
|
||||
const Type* type,
|
||||
ExpressionList a)
|
||||
: Base(pid, src), target(ToTarget(type)), args(a) {
|
||||
TINT_ASSERT(AST, type);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, type, program_id);
|
||||
for (auto* arg : args) {
|
||||
TINT_ASSERT(AST, arg);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, arg, program_id);
|
||||
}
|
||||
}
|
||||
|
||||
CallExpression::CallExpression(CallExpression&&) = default;
|
||||
|
||||
CallExpression::~CallExpression() = default;
|
||||
|
||||
const CallExpression* CallExpression::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
auto p = ctx->Clone(args);
|
||||
return target.name
|
||||
? ctx->dst->create<CallExpression>(src, ctx->Clone(target.name), p)
|
||||
: ctx->dst->create<CallExpression>(src, ctx->Clone(target.type),
|
||||
p);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
84
src/tint/ast/call_expression.h
Normal file
84
src/tint/ast/call_expression.h
Normal file
@@ -0,0 +1,84 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_CALL_EXPRESSION_H_
|
||||
#define SRC_TINT_AST_CALL_EXPRESSION_H_
|
||||
|
||||
#include "src/tint/ast/expression.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
// Forward declarations.
|
||||
class Type;
|
||||
class IdentifierExpression;
|
||||
|
||||
/// A call expression - represents either a:
|
||||
/// * sem::Function
|
||||
/// * sem::Builtin
|
||||
/// * sem::TypeConstructor
|
||||
/// * sem::TypeConversion
|
||||
class CallExpression final : public Castable<CallExpression, Expression> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param program_id the identifier of the program that owns this node
|
||||
/// @param source the call expression source
|
||||
/// @param name the function or type name
|
||||
/// @param args the arguments
|
||||
CallExpression(ProgramID program_id,
|
||||
const Source& source,
|
||||
const IdentifierExpression* name,
|
||||
ExpressionList args);
|
||||
|
||||
/// Constructor
|
||||
/// @param program_id the identifier of the program that owns this node
|
||||
/// @param source the call expression source
|
||||
/// @param type the type
|
||||
/// @param args the arguments
|
||||
CallExpression(ProgramID program_id,
|
||||
const Source& source,
|
||||
const Type* type,
|
||||
ExpressionList args);
|
||||
|
||||
/// Move constructor
|
||||
CallExpression(CallExpression&&);
|
||||
~CallExpression() override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const CallExpression* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// Target is either an identifier, or a Type.
|
||||
/// One of these must be nullptr and the other a non-nullptr.
|
||||
struct Target {
|
||||
/// name is a function or builtin to call, or type name to construct or
|
||||
/// cast-to
|
||||
const IdentifierExpression* name = nullptr;
|
||||
/// type to construct or cast-to
|
||||
const Type* type = nullptr;
|
||||
};
|
||||
|
||||
/// The target function
|
||||
const Target target;
|
||||
|
||||
/// The arguments
|
||||
const ExpressionList args;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_CALL_EXPRESSION_H_
|
||||
149
src/tint/ast/call_expression_test.cc
Normal file
149
src/tint/ast/call_expression_test.cc
Normal file
@@ -0,0 +1,149 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "gtest/gtest-spi.h"
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using CallExpressionTest = TestHelper;
|
||||
|
||||
TEST_F(CallExpressionTest, CreationIdentifier) {
|
||||
auto* func = Expr("func");
|
||||
ExpressionList params;
|
||||
params.push_back(Expr("param1"));
|
||||
params.push_back(Expr("param2"));
|
||||
|
||||
auto* stmt = create<CallExpression>(func, params);
|
||||
EXPECT_EQ(stmt->target.name, func);
|
||||
EXPECT_EQ(stmt->target.type, nullptr);
|
||||
|
||||
const auto& vec = stmt->args;
|
||||
ASSERT_EQ(vec.size(), 2u);
|
||||
EXPECT_EQ(vec[0], params[0]);
|
||||
EXPECT_EQ(vec[1], params[1]);
|
||||
}
|
||||
|
||||
TEST_F(CallExpressionTest, CreationIdentifier_WithSource) {
|
||||
auto* func = Expr("func");
|
||||
auto* stmt = create<CallExpression>(Source{{20, 2}}, func, ExpressionList{});
|
||||
EXPECT_EQ(stmt->target.name, func);
|
||||
EXPECT_EQ(stmt->target.type, nullptr);
|
||||
|
||||
auto src = stmt->source;
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
}
|
||||
|
||||
TEST_F(CallExpressionTest, CreationType) {
|
||||
auto* type = ty.f32();
|
||||
ExpressionList params;
|
||||
params.push_back(Expr("param1"));
|
||||
params.push_back(Expr("param2"));
|
||||
|
||||
auto* stmt = create<CallExpression>(type, params);
|
||||
EXPECT_EQ(stmt->target.name, nullptr);
|
||||
EXPECT_EQ(stmt->target.type, type);
|
||||
|
||||
const auto& vec = stmt->args;
|
||||
ASSERT_EQ(vec.size(), 2u);
|
||||
EXPECT_EQ(vec[0], params[0]);
|
||||
EXPECT_EQ(vec[1], params[1]);
|
||||
}
|
||||
|
||||
TEST_F(CallExpressionTest, CreationType_WithSource) {
|
||||
auto* type = ty.f32();
|
||||
auto* stmt = create<CallExpression>(Source{{20, 2}}, type, ExpressionList{});
|
||||
EXPECT_EQ(stmt->target.name, nullptr);
|
||||
EXPECT_EQ(stmt->target.type, type);
|
||||
|
||||
auto src = stmt->source;
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
}
|
||||
|
||||
TEST_F(CallExpressionTest, IsCall) {
|
||||
auto* func = Expr("func");
|
||||
auto* stmt = create<CallExpression>(func, ExpressionList{});
|
||||
EXPECT_TRUE(stmt->Is<CallExpression>());
|
||||
}
|
||||
|
||||
TEST_F(CallExpressionTest, Assert_Null_Identifier) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<CallExpression>(static_cast<IdentifierExpression*>(nullptr),
|
||||
ExpressionList{});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(CallExpressionTest, Assert_Null_Type) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<CallExpression>(static_cast<Type*>(nullptr), ExpressionList{});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(CallExpressionTest, Assert_Null_Param) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
ExpressionList params;
|
||||
params.push_back(b.Expr("param1"));
|
||||
params.push_back(nullptr);
|
||||
params.push_back(b.Expr("param2"));
|
||||
b.create<CallExpression>(b.Expr("func"), params);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(CallExpressionTest, Assert_DifferentProgramID_Identifier) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<CallExpression>(b2.Expr("func"), ExpressionList{});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(CallExpressionTest, Assert_DifferentProgramID_Type) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<CallExpression>(b2.ty.f32(), ExpressionList{});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(CallExpressionTest, Assert_DifferentProgramID_Param) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<CallExpression>(b1.Expr("func"),
|
||||
ExpressionList{b2.Expr("param1")});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
44
src/tint/ast/call_statement.cc
Normal file
44
src/tint/ast/call_statement.cc
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/call_statement.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::CallStatement);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
CallStatement::CallStatement(ProgramID pid,
|
||||
const Source& src,
|
||||
const CallExpression* call)
|
||||
: Base(pid, src), expr(call) {
|
||||
TINT_ASSERT(AST, expr);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, expr, program_id);
|
||||
}
|
||||
|
||||
CallStatement::CallStatement(CallStatement&&) = default;
|
||||
|
||||
CallStatement::~CallStatement() = default;
|
||||
|
||||
const CallStatement* CallStatement::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
auto* call = ctx->Clone(expr);
|
||||
return ctx->dst->create<CallStatement>(src, call);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
49
src/tint/ast/call_statement.h
Normal file
49
src/tint/ast/call_statement.h
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_CALL_STATEMENT_H_
|
||||
#define SRC_TINT_AST_CALL_STATEMENT_H_
|
||||
|
||||
#include "src/tint/ast/call_expression.h"
|
||||
#include "src/tint/ast/statement.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// A call expression
|
||||
class CallStatement final : public Castable<CallStatement, Statement> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node for the statement
|
||||
/// @param call the function
|
||||
CallStatement(ProgramID pid, const Source& src, const CallExpression* call);
|
||||
/// Move constructor
|
||||
CallStatement(CallStatement&&);
|
||||
~CallStatement() override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const CallStatement* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// The call expression
|
||||
const CallExpression* const expr;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_CALL_STATEMENT_H_
|
||||
60
src/tint/ast/call_statement_test.cc
Normal file
60
src/tint/ast/call_statement_test.cc
Normal file
@@ -0,0 +1,60 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/call_statement.h"
|
||||
|
||||
#include "gtest/gtest-spi.h"
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using CallStatementTest = TestHelper;
|
||||
|
||||
TEST_F(CallStatementTest, Creation) {
|
||||
auto* expr = create<CallExpression>(Expr("func"), ExpressionList{});
|
||||
|
||||
auto* c = create<CallStatement>(expr);
|
||||
EXPECT_EQ(c->expr, expr);
|
||||
}
|
||||
|
||||
TEST_F(CallStatementTest, IsCall) {
|
||||
auto* c = create<CallStatement>(Call("f"));
|
||||
EXPECT_TRUE(c->Is<CallStatement>());
|
||||
}
|
||||
|
||||
TEST_F(CallStatementTest, Assert_Null_Call) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<CallStatement>(nullptr);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(CallStatementTest, Assert_DifferentProgramID_Call) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<CallStatement>(
|
||||
b2.create<CallExpression>(b2.Expr("func"), ExpressionList{}));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
50
src/tint/ast/case_statement.cc
Normal file
50
src/tint/ast/case_statement.cc
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/case_statement.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::CaseStatement);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
CaseStatement::CaseStatement(ProgramID pid,
|
||||
const Source& src,
|
||||
CaseSelectorList s,
|
||||
const BlockStatement* b)
|
||||
: Base(pid, src), selectors(s), body(b) {
|
||||
TINT_ASSERT(AST, body);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
|
||||
for (auto* selector : selectors) {
|
||||
TINT_ASSERT(AST, selector);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, selector, program_id);
|
||||
}
|
||||
}
|
||||
|
||||
CaseStatement::CaseStatement(CaseStatement&&) = default;
|
||||
|
||||
CaseStatement::~CaseStatement() = default;
|
||||
|
||||
const CaseStatement* CaseStatement::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
auto sel = ctx->Clone(selectors);
|
||||
auto* b = ctx->Clone(body);
|
||||
return ctx->dst->create<CaseStatement>(src, sel, b);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
67
src/tint/ast/case_statement.h
Normal file
67
src/tint/ast/case_statement.h
Normal file
@@ -0,0 +1,67 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_CASE_STATEMENT_H_
|
||||
#define SRC_TINT_AST_CASE_STATEMENT_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "src/tint/ast/block_statement.h"
|
||||
#include "src/tint/ast/int_literal_expression.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// A list of case literals
|
||||
using CaseSelectorList = std::vector<const IntLiteralExpression*>;
|
||||
|
||||
/// A case statement
|
||||
class CaseStatement final : public Castable<CaseStatement, Statement> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
/// @param selectors the case selectors
|
||||
/// @param body the case body
|
||||
CaseStatement(ProgramID pid,
|
||||
const Source& src,
|
||||
CaseSelectorList selectors,
|
||||
const BlockStatement* body);
|
||||
/// Move constructor
|
||||
CaseStatement(CaseStatement&&);
|
||||
~CaseStatement() override;
|
||||
|
||||
/// @returns true if this is a default statement
|
||||
bool IsDefault() const { return selectors.empty(); }
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const CaseStatement* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// The case selectors, empty if none set
|
||||
const CaseSelectorList selectors;
|
||||
|
||||
/// The case body
|
||||
const BlockStatement* const body;
|
||||
};
|
||||
|
||||
/// A list of case statements
|
||||
using CaseStatementList = std::vector<const CaseStatement*>;
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_CASE_STATEMENT_H_
|
||||
137
src/tint/ast/case_statement_test.cc
Normal file
137
src/tint/ast/case_statement_test.cc
Normal file
@@ -0,0 +1,137 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/case_statement.h"
|
||||
|
||||
#include "gtest/gtest-spi.h"
|
||||
#include "src/tint/ast/discard_statement.h"
|
||||
#include "src/tint/ast/if_statement.h"
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using CaseStatementTest = TestHelper;
|
||||
|
||||
TEST_F(CaseStatementTest, Creation_i32) {
|
||||
CaseSelectorList b;
|
||||
auto* selector = create<SintLiteralExpression>(2);
|
||||
b.push_back(selector);
|
||||
|
||||
auto* discard = create<DiscardStatement>();
|
||||
auto* body = create<BlockStatement>(StatementList{discard});
|
||||
|
||||
auto* c = create<CaseStatement>(b, body);
|
||||
ASSERT_EQ(c->selectors.size(), 1u);
|
||||
EXPECT_EQ(c->selectors[0], selector);
|
||||
ASSERT_EQ(c->body->statements.size(), 1u);
|
||||
EXPECT_EQ(c->body->statements[0], discard);
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, Creation_u32) {
|
||||
CaseSelectorList b;
|
||||
auto* selector = create<UintLiteralExpression>(2u);
|
||||
b.push_back(selector);
|
||||
|
||||
auto* discard = create<DiscardStatement>();
|
||||
auto* body = create<BlockStatement>(StatementList{discard});
|
||||
|
||||
auto* c = create<CaseStatement>(b, body);
|
||||
ASSERT_EQ(c->selectors.size(), 1u);
|
||||
EXPECT_EQ(c->selectors[0], selector);
|
||||
ASSERT_EQ(c->body->statements.size(), 1u);
|
||||
EXPECT_EQ(c->body->statements[0], discard);
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, Creation_WithSource) {
|
||||
CaseSelectorList b;
|
||||
b.push_back(create<SintLiteralExpression>(2));
|
||||
|
||||
auto* body = create<BlockStatement>(StatementList{
|
||||
create<DiscardStatement>(),
|
||||
});
|
||||
auto* c = create<CaseStatement>(Source{Source::Location{20, 2}}, b, body);
|
||||
auto src = c->source;
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, IsDefault_WithoutSelectors) {
|
||||
auto* body = create<BlockStatement>(StatementList{
|
||||
create<DiscardStatement>(),
|
||||
});
|
||||
auto* c = create<CaseStatement>(CaseSelectorList{}, body);
|
||||
EXPECT_TRUE(c->IsDefault());
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, IsDefault_WithSelectors) {
|
||||
CaseSelectorList b;
|
||||
b.push_back(create<SintLiteralExpression>(2));
|
||||
|
||||
auto* c = create<CaseStatement>(b, create<BlockStatement>(StatementList{}));
|
||||
EXPECT_FALSE(c->IsDefault());
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, IsCase) {
|
||||
auto* c = create<CaseStatement>(CaseSelectorList{},
|
||||
create<BlockStatement>(StatementList{}));
|
||||
EXPECT_TRUE(c->Is<CaseStatement>());
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, Assert_Null_Body) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<CaseStatement>(CaseSelectorList{}, nullptr);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, Assert_Null_Selector) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<CaseStatement>(CaseSelectorList{nullptr},
|
||||
b.create<BlockStatement>(StatementList{}));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, Assert_DifferentProgramID_Call) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<CaseStatement>(CaseSelectorList{},
|
||||
b2.create<BlockStatement>(StatementList{}));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(CaseStatementTest, Assert_DifferentProgramID_Selector) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<CaseStatement>(
|
||||
CaseSelectorList{b2.create<SintLiteralExpression>(2)},
|
||||
b1.create<BlockStatement>(StatementList{}));
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
51
src/tint/ast/compound_assignment_statement.cc
Normal file
51
src/tint/ast/compound_assignment_statement.cc
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright 2022 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/compound_assignment_statement.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::CompoundAssignmentStatement);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
CompoundAssignmentStatement::CompoundAssignmentStatement(ProgramID pid,
|
||||
const Source& src,
|
||||
const Expression* l,
|
||||
const Expression* r,
|
||||
BinaryOp o)
|
||||
: Base(pid, src), lhs(l), rhs(r), op(o) {
|
||||
TINT_ASSERT(AST, lhs);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, lhs, program_id);
|
||||
TINT_ASSERT(AST, rhs);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, rhs, program_id);
|
||||
}
|
||||
|
||||
CompoundAssignmentStatement::CompoundAssignmentStatement(
|
||||
CompoundAssignmentStatement&&) = default;
|
||||
|
||||
CompoundAssignmentStatement::~CompoundAssignmentStatement() = default;
|
||||
|
||||
const CompoundAssignmentStatement* CompoundAssignmentStatement::Clone(
|
||||
CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
auto* l = ctx->Clone(lhs);
|
||||
auto* r = ctx->Clone(rhs);
|
||||
return ctx->dst->create<CompoundAssignmentStatement>(src, l, r, op);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
63
src/tint/ast/compound_assignment_statement.h
Normal file
63
src/tint/ast/compound_assignment_statement.h
Normal file
@@ -0,0 +1,63 @@
|
||||
// Copyright 2022 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_COMPOUND_ASSIGNMENT_STATEMENT_H_
|
||||
#define SRC_TINT_AST_COMPOUND_ASSIGNMENT_STATEMENT_H_
|
||||
|
||||
#include "src/tint/ast/binary_expression.h"
|
||||
#include "src/tint/ast/expression.h"
|
||||
#include "src/tint/ast/statement.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// A compound assignment statement
|
||||
class CompoundAssignmentStatement final
|
||||
: public Castable<CompoundAssignmentStatement, Statement> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param program_id the identifier of the program that owns this node
|
||||
/// @param source the compound assignment statement source
|
||||
/// @param lhs the left side of the expression
|
||||
/// @param rhs the right side of the expression
|
||||
/// @param op the binary operator
|
||||
CompoundAssignmentStatement(ProgramID program_id,
|
||||
const Source& source,
|
||||
const Expression* lhs,
|
||||
const Expression* rhs,
|
||||
BinaryOp op);
|
||||
/// Move constructor
|
||||
CompoundAssignmentStatement(CompoundAssignmentStatement&&);
|
||||
~CompoundAssignmentStatement() override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const CompoundAssignmentStatement* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// left side expression
|
||||
const Expression* const lhs;
|
||||
|
||||
/// right side expression
|
||||
const Expression* const rhs;
|
||||
|
||||
/// the binary operator
|
||||
const BinaryOp op;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_COMPOUND_ASSIGNMENT_STATEMENT_H_
|
||||
102
src/tint/ast/compound_assignment_statement_test.cc
Normal file
102
src/tint/ast/compound_assignment_statement_test.cc
Normal file
@@ -0,0 +1,102 @@
|
||||
// Copyright 2022 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/compound_assignment_statement.h"
|
||||
|
||||
#include "gtest/gtest-spi.h"
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using CompoundAssignmentStatementTest = TestHelper;
|
||||
|
||||
TEST_F(CompoundAssignmentStatementTest, Creation) {
|
||||
auto* lhs = Expr("lhs");
|
||||
auto* rhs = Expr("rhs");
|
||||
auto op = BinaryOp::kAdd;
|
||||
|
||||
auto* stmt = create<CompoundAssignmentStatement>(lhs, rhs, op);
|
||||
EXPECT_EQ(stmt->lhs, lhs);
|
||||
EXPECT_EQ(stmt->rhs, rhs);
|
||||
EXPECT_EQ(stmt->op, op);
|
||||
}
|
||||
|
||||
TEST_F(CompoundAssignmentStatementTest, CreationWithSource) {
|
||||
auto* lhs = Expr("lhs");
|
||||
auto* rhs = Expr("rhs");
|
||||
auto op = BinaryOp::kMultiply;
|
||||
|
||||
auto* stmt = create<CompoundAssignmentStatement>(
|
||||
Source{Source::Location{20, 2}}, lhs, rhs, op);
|
||||
auto src = stmt->source;
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
}
|
||||
|
||||
TEST_F(CompoundAssignmentStatementTest, IsCompoundAssign) {
|
||||
auto* lhs = Expr("lhs");
|
||||
auto* rhs = Expr("rhs");
|
||||
auto op = BinaryOp::kSubtract;
|
||||
|
||||
auto* stmt = create<CompoundAssignmentStatement>(lhs, rhs, op);
|
||||
EXPECT_TRUE(stmt->Is<CompoundAssignmentStatement>());
|
||||
}
|
||||
|
||||
TEST_F(CompoundAssignmentStatementTest, Assert_Null_LHS) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<CompoundAssignmentStatement>(nullptr, b.Expr(1),
|
||||
BinaryOp::kAdd);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(CompoundAssignmentStatementTest, Assert_Null_RHS) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<CompoundAssignmentStatement>(b.Expr(1), nullptr,
|
||||
BinaryOp::kAdd);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(CompoundAssignmentStatementTest, Assert_DifferentProgramID_LHS) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<CompoundAssignmentStatement>(b2.Expr("lhs"), b1.Expr("rhs"),
|
||||
BinaryOp::kAdd);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(CompoundAssignmentStatementTest, Assert_DifferentProgramID_RHS) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<CompoundAssignmentStatement>(b1.Expr("lhs"), b2.Expr("rhs"),
|
||||
BinaryOp::kAdd);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
38
src/tint/ast/continue_statement.cc
Normal file
38
src/tint/ast/continue_statement.cc
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/continue_statement.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::ContinueStatement);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
ContinueStatement::ContinueStatement(ProgramID pid, const Source& src)
|
||||
: Base(pid, src) {}
|
||||
|
||||
ContinueStatement::ContinueStatement(ContinueStatement&&) = default;
|
||||
|
||||
ContinueStatement::~ContinueStatement() = default;
|
||||
|
||||
const ContinueStatement* ContinueStatement::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
return ctx->dst->create<ContinueStatement>(src);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
44
src/tint/ast/continue_statement.h
Normal file
44
src/tint/ast/continue_statement.h
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_CONTINUE_STATEMENT_H_
|
||||
#define SRC_TINT_AST_CONTINUE_STATEMENT_H_
|
||||
|
||||
#include "src/tint/ast/statement.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// An continue statement
|
||||
class ContinueStatement final : public Castable<ContinueStatement, Statement> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
ContinueStatement(ProgramID pid, const Source& src);
|
||||
/// Move constructor
|
||||
ContinueStatement(ContinueStatement&&);
|
||||
~ContinueStatement() override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const ContinueStatement* Clone(CloneContext* ctx) const override;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_CONTINUE_STATEMENT_H_
|
||||
39
src/tint/ast/continue_statement_test.cc
Normal file
39
src/tint/ast/continue_statement_test.cc
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/continue_statement.h"
|
||||
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using ContinueStatementTest = TestHelper;
|
||||
|
||||
TEST_F(ContinueStatementTest, Creation_WithSource) {
|
||||
auto* stmt = create<ContinueStatement>(Source{Source::Location{20, 2}});
|
||||
auto src = stmt->source;
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
}
|
||||
|
||||
TEST_F(ContinueStatementTest, IsContinue) {
|
||||
auto* stmt = create<ContinueStatement>();
|
||||
EXPECT_TRUE(stmt->Is<ContinueStatement>());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
56
src/tint/ast/depth_multisampled_texture.cc
Normal file
56
src/tint/ast/depth_multisampled_texture.cc
Normal file
@@ -0,0 +1,56 @@
|
||||
// Copyright 2021 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/depth_multisampled_texture.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::DepthMultisampledTexture);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
bool IsValidDepthDimension(TextureDimension dim) {
|
||||
return dim == TextureDimension::k2d;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
DepthMultisampledTexture::DepthMultisampledTexture(ProgramID pid,
|
||||
const Source& src,
|
||||
TextureDimension d)
|
||||
: Base(pid, src, d) {
|
||||
TINT_ASSERT(AST, IsValidDepthDimension(dim));
|
||||
}
|
||||
|
||||
DepthMultisampledTexture::DepthMultisampledTexture(DepthMultisampledTexture&&) =
|
||||
default;
|
||||
|
||||
DepthMultisampledTexture::~DepthMultisampledTexture() = default;
|
||||
|
||||
std::string DepthMultisampledTexture::FriendlyName(const SymbolTable&) const {
|
||||
std::ostringstream out;
|
||||
out << "texture_depth_multisampled_" << dim;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
const DepthMultisampledTexture* DepthMultisampledTexture::Clone(
|
||||
CloneContext* ctx) const {
|
||||
auto src = ctx->Clone(source);
|
||||
return ctx->dst->create<DepthMultisampledTexture>(src, dim);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
54
src/tint/ast/depth_multisampled_texture.h
Normal file
54
src/tint/ast/depth_multisampled_texture.h
Normal file
@@ -0,0 +1,54 @@
|
||||
// Copyright 2021 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_DEPTH_MULTISAMPLED_TEXTURE_H_
|
||||
#define SRC_TINT_AST_DEPTH_MULTISAMPLED_TEXTURE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/ast/texture.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// A multisampled depth texture type.
|
||||
class DepthMultisampledTexture final
|
||||
: public Castable<DepthMultisampledTexture, Texture> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
/// @param dim the dimensionality of the texture
|
||||
DepthMultisampledTexture(ProgramID pid,
|
||||
const Source& src,
|
||||
TextureDimension dim);
|
||||
/// Move constructor
|
||||
DepthMultisampledTexture(DepthMultisampledTexture&&);
|
||||
~DepthMultisampledTexture() override;
|
||||
|
||||
/// @param symbols the program's symbol table
|
||||
/// @returns the name for this type that closely resembles how it would be
|
||||
/// declared in WGSL.
|
||||
std::string FriendlyName(const SymbolTable& symbols) const override;
|
||||
|
||||
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned type
|
||||
const DepthMultisampledTexture* Clone(CloneContext* ctx) const override;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_DEPTH_MULTISAMPLED_TEXTURE_H_
|
||||
37
src/tint/ast/depth_multisampled_texture_test.cc
Normal file
37
src/tint/ast/depth_multisampled_texture_test.cc
Normal file
@@ -0,0 +1,37 @@
|
||||
// Copyright 2021 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/depth_multisampled_texture.h"
|
||||
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using AstDepthMultisampledTextureTest = TestHelper;
|
||||
|
||||
TEST_F(AstDepthMultisampledTextureTest, Dim) {
|
||||
auto* d = create<DepthMultisampledTexture>(TextureDimension::k2d);
|
||||
EXPECT_EQ(d->dim, TextureDimension::k2d);
|
||||
}
|
||||
|
||||
TEST_F(AstDepthMultisampledTextureTest, FriendlyName) {
|
||||
auto* d = create<DepthMultisampledTexture>(TextureDimension::k2d);
|
||||
EXPECT_EQ(d->FriendlyName(Symbols()), "texture_depth_multisampled_2d");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
53
src/tint/ast/depth_texture.cc
Normal file
53
src/tint/ast/depth_texture.cc
Normal file
@@ -0,0 +1,53 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/depth_texture.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::DepthTexture);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
bool IsValidDepthDimension(TextureDimension dim) {
|
||||
return dim == TextureDimension::k2d || dim == TextureDimension::k2dArray ||
|
||||
dim == TextureDimension::kCube || dim == TextureDimension::kCubeArray;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
DepthTexture::DepthTexture(ProgramID pid, const Source& src, TextureDimension d)
|
||||
: Base(pid, src, d) {
|
||||
TINT_ASSERT(AST, IsValidDepthDimension(dim));
|
||||
}
|
||||
|
||||
DepthTexture::DepthTexture(DepthTexture&&) = default;
|
||||
|
||||
DepthTexture::~DepthTexture() = default;
|
||||
|
||||
std::string DepthTexture::FriendlyName(const SymbolTable&) const {
|
||||
std::ostringstream out;
|
||||
out << "texture_depth_" << dim;
|
||||
return out.str();
|
||||
}
|
||||
|
||||
const DepthTexture* DepthTexture::Clone(CloneContext* ctx) const {
|
||||
auto src = ctx->Clone(source);
|
||||
return ctx->dst->create<DepthTexture>(src, dim);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
51
src/tint/ast/depth_texture.h
Normal file
51
src/tint/ast/depth_texture.h
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_DEPTH_TEXTURE_H_
|
||||
#define SRC_TINT_AST_DEPTH_TEXTURE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/ast/texture.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// A depth texture type.
|
||||
class DepthTexture final : public Castable<DepthTexture, Texture> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
/// @param dim the dimensionality of the texture
|
||||
DepthTexture(ProgramID pid, const Source& src, TextureDimension dim);
|
||||
/// Move constructor
|
||||
DepthTexture(DepthTexture&&);
|
||||
~DepthTexture() override;
|
||||
|
||||
/// @param symbols the program's symbol table
|
||||
/// @returns the name for this type that closely resembles how it would be
|
||||
/// declared in WGSL.
|
||||
std::string FriendlyName(const SymbolTable& symbols) const override;
|
||||
|
||||
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned type
|
||||
const DepthTexture* Clone(CloneContext* ctx) const override;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_DEPTH_TEXTURE_H_
|
||||
44
src/tint/ast/depth_texture_test.cc
Normal file
44
src/tint/ast/depth_texture_test.cc
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/depth_texture.h"
|
||||
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using AstDepthTextureTest = TestHelper;
|
||||
|
||||
TEST_F(AstDepthTextureTest, IsTexture) {
|
||||
Texture* ty = create<DepthTexture>(TextureDimension::kCube);
|
||||
EXPECT_TRUE(ty->Is<DepthTexture>());
|
||||
EXPECT_FALSE(ty->Is<SampledTexture>());
|
||||
EXPECT_FALSE(ty->Is<StorageTexture>());
|
||||
}
|
||||
|
||||
TEST_F(AstDepthTextureTest, Dim) {
|
||||
auto* d = create<DepthTexture>(TextureDimension::kCube);
|
||||
EXPECT_EQ(d->dim, TextureDimension::kCube);
|
||||
}
|
||||
|
||||
TEST_F(AstDepthTextureTest, FriendlyName) {
|
||||
auto* d = create<DepthTexture>(TextureDimension::kCube);
|
||||
EXPECT_EQ(d->FriendlyName(Symbols()), "texture_depth_cube");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
57
src/tint/ast/disable_validation_attribute.cc
Normal file
57
src/tint/ast/disable_validation_attribute.cc
Normal file
@@ -0,0 +1,57 @@
|
||||
// Copyright 2021 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/disable_validation_attribute.h"
|
||||
#include "src/tint/clone_context.h"
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::DisableValidationAttribute);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
DisableValidationAttribute::DisableValidationAttribute(ProgramID pid,
|
||||
DisabledValidation val)
|
||||
: Base(pid), validation(val) {}
|
||||
|
||||
DisableValidationAttribute::~DisableValidationAttribute() = default;
|
||||
|
||||
std::string DisableValidationAttribute::InternalName() const {
|
||||
switch (validation) {
|
||||
case DisabledValidation::kFunctionHasNoBody:
|
||||
return "disable_validation__function_has_no_body";
|
||||
case DisabledValidation::kBindingPointCollision:
|
||||
return "disable_validation__binding_point_collision";
|
||||
case DisabledValidation::kIgnoreStorageClass:
|
||||
return "disable_validation__ignore_storage_class";
|
||||
case DisabledValidation::kEntryPointParameter:
|
||||
return "disable_validation__entry_point_parameter";
|
||||
case DisabledValidation::kIgnoreConstructibleFunctionParameter:
|
||||
return "disable_validation__ignore_constructible_function_parameter";
|
||||
case DisabledValidation::kIgnoreStrideAttribute:
|
||||
return "disable_validation__ignore_stride";
|
||||
case DisabledValidation::kIgnoreInvalidPointerArgument:
|
||||
return "disable_validation__ignore_invalid_pointer_argument";
|
||||
}
|
||||
return "<invalid>";
|
||||
}
|
||||
|
||||
const DisableValidationAttribute* DisableValidationAttribute::Clone(
|
||||
CloneContext* ctx) const {
|
||||
return ctx->dst->ASTNodes().Create<DisableValidationAttribute>(ctx->dst->ID(),
|
||||
validation);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
83
src/tint/ast/disable_validation_attribute.h
Normal file
83
src/tint/ast/disable_validation_attribute.h
Normal file
@@ -0,0 +1,83 @@
|
||||
// Copyright 2021 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_DISABLE_VALIDATION_ATTRIBUTE_H_
|
||||
#define SRC_TINT_AST_DISABLE_VALIDATION_ATTRIBUTE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/ast/internal_attribute.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// Enumerator of validation features that can be disabled with a
|
||||
/// DisableValidationAttribute attribute.
|
||||
enum class DisabledValidation {
|
||||
/// When applied to a function, the validator will not complain there is no
|
||||
/// body to a function.
|
||||
kFunctionHasNoBody,
|
||||
/// When applied to a module-scoped variable, the validator will not complain
|
||||
/// if two resource variables have the same binding points.
|
||||
kBindingPointCollision,
|
||||
/// When applied to a variable, the validator will not complain about the
|
||||
/// declared storage class.
|
||||
kIgnoreStorageClass,
|
||||
/// When applied to an entry-point function parameter, the validator will not
|
||||
/// check for entry IO attributes.
|
||||
kEntryPointParameter,
|
||||
/// When applied to a function parameter, the validator will not
|
||||
/// check if parameter type is constructible
|
||||
kIgnoreConstructibleFunctionParameter,
|
||||
/// When applied to a member attribute, a stride attribute may be applied to
|
||||
/// non-array types.
|
||||
kIgnoreStrideAttribute,
|
||||
/// When applied to a pointer function parameter, the validator will not
|
||||
/// require a function call argument passed for that parameter to have a
|
||||
/// certain form.
|
||||
kIgnoreInvalidPointerArgument,
|
||||
};
|
||||
|
||||
/// An internal attribute used to tell the validator to ignore specific
|
||||
/// violations. Typically generated by transforms that need to produce ASTs that
|
||||
/// would otherwise cause validation errors.
|
||||
class DisableValidationAttribute final
|
||||
: public Castable<DisableValidationAttribute, InternalAttribute> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param program_id the identifier of the program that owns this node
|
||||
/// @param validation the validation to disable
|
||||
explicit DisableValidationAttribute(ProgramID program_id,
|
||||
DisabledValidation validation);
|
||||
|
||||
/// Destructor
|
||||
~DisableValidationAttribute() override;
|
||||
|
||||
/// @return a short description of the internal attribute which will be
|
||||
/// displayed in WGSL as `@internal(<name>)` (but is not parsable).
|
||||
std::string InternalName() const override;
|
||||
|
||||
/// Performs a deep clone of this object using the CloneContext `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned object
|
||||
const DisableValidationAttribute* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// The validation that this attribute disables
|
||||
const DisabledValidation validation;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_DISABLE_VALIDATION_ATTRIBUTE_H_
|
||||
38
src/tint/ast/discard_statement.cc
Normal file
38
src/tint/ast/discard_statement.cc
Normal file
@@ -0,0 +1,38 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/discard_statement.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::DiscardStatement);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
DiscardStatement::DiscardStatement(ProgramID pid, const Source& src)
|
||||
: Base(pid, src) {}
|
||||
|
||||
DiscardStatement::DiscardStatement(DiscardStatement&&) = default;
|
||||
|
||||
DiscardStatement::~DiscardStatement() = default;
|
||||
|
||||
const DiscardStatement* DiscardStatement::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
return ctx->dst->create<DiscardStatement>(src);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
44
src/tint/ast/discard_statement.h
Normal file
44
src/tint/ast/discard_statement.h
Normal file
@@ -0,0 +1,44 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_DISCARD_STATEMENT_H_
|
||||
#define SRC_TINT_AST_DISCARD_STATEMENT_H_
|
||||
|
||||
#include "src/tint/ast/statement.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// A discard statement
|
||||
class DiscardStatement final : public Castable<DiscardStatement, Statement> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
DiscardStatement(ProgramID pid, const Source& src);
|
||||
/// Move constructor
|
||||
DiscardStatement(DiscardStatement&&);
|
||||
~DiscardStatement() override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const DiscardStatement* Clone(CloneContext* ctx) const override;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_DISCARD_STATEMENT_H_
|
||||
49
src/tint/ast/discard_statement_test.cc
Normal file
49
src/tint/ast/discard_statement_test.cc
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/discard_statement.h"
|
||||
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using DiscardStatementTest = TestHelper;
|
||||
|
||||
TEST_F(DiscardStatementTest, Creation) {
|
||||
auto* stmt = create<DiscardStatement>();
|
||||
EXPECT_EQ(stmt->source.range.begin.line, 0u);
|
||||
EXPECT_EQ(stmt->source.range.begin.column, 0u);
|
||||
EXPECT_EQ(stmt->source.range.end.line, 0u);
|
||||
EXPECT_EQ(stmt->source.range.end.column, 0u);
|
||||
}
|
||||
|
||||
TEST_F(DiscardStatementTest, Creation_WithSource) {
|
||||
auto* stmt = create<DiscardStatement>(
|
||||
Source{Source::Range{Source::Location{20, 2}, Source::Location{20, 5}}});
|
||||
EXPECT_EQ(stmt->source.range.begin.line, 20u);
|
||||
EXPECT_EQ(stmt->source.range.begin.column, 2u);
|
||||
EXPECT_EQ(stmt->source.range.end.line, 20u);
|
||||
EXPECT_EQ(stmt->source.range.end.column, 5u);
|
||||
}
|
||||
|
||||
TEST_F(DiscardStatementTest, IsDiscard) {
|
||||
auto* stmt = create<DiscardStatement>();
|
||||
EXPECT_TRUE(stmt->Is<DiscardStatement>());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
47
src/tint/ast/else_statement.cc
Normal file
47
src/tint/ast/else_statement.cc
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/else_statement.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::ElseStatement);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
ElseStatement::ElseStatement(ProgramID pid,
|
||||
const Source& src,
|
||||
const Expression* cond,
|
||||
const BlockStatement* b)
|
||||
: Base(pid, src), condition(cond), body(b) {
|
||||
TINT_ASSERT(AST, body);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition, program_id);
|
||||
}
|
||||
|
||||
ElseStatement::ElseStatement(ElseStatement&&) = default;
|
||||
|
||||
ElseStatement::~ElseStatement() = default;
|
||||
|
||||
const ElseStatement* ElseStatement::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
auto* cond = ctx->Clone(condition);
|
||||
auto* b = ctx->Clone(body);
|
||||
return ctx->dst->create<ElseStatement>(src, cond, b);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
61
src/tint/ast/else_statement.h
Normal file
61
src/tint/ast/else_statement.h
Normal file
@@ -0,0 +1,61 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_ELSE_STATEMENT_H_
|
||||
#define SRC_TINT_AST_ELSE_STATEMENT_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "src/tint/ast/block_statement.h"
|
||||
#include "src/tint/ast/expression.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// An else statement
|
||||
class ElseStatement final : public Castable<ElseStatement, Statement> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
/// @param condition the else condition
|
||||
/// @param body the else body
|
||||
ElseStatement(ProgramID pid,
|
||||
const Source& src,
|
||||
const Expression* condition,
|
||||
const BlockStatement* body);
|
||||
/// Move constructor
|
||||
ElseStatement(ElseStatement&&);
|
||||
~ElseStatement() override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const ElseStatement* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// The else condition or nullptr if none set
|
||||
const Expression* const condition;
|
||||
|
||||
/// The else body
|
||||
const BlockStatement* const body;
|
||||
};
|
||||
|
||||
/// A list of else statements
|
||||
using ElseStatementList = std::vector<const ElseStatement*>;
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_ELSE_STATEMENT_H_
|
||||
94
src/tint/ast/else_statement_test.cc
Normal file
94
src/tint/ast/else_statement_test.cc
Normal file
@@ -0,0 +1,94 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "gtest/gtest-spi.h"
|
||||
#include "src/tint/ast/discard_statement.h"
|
||||
#include "src/tint/ast/if_statement.h"
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using ElseStatementTest = TestHelper;
|
||||
|
||||
TEST_F(ElseStatementTest, Creation) {
|
||||
auto* cond = Expr(true);
|
||||
auto* body = create<BlockStatement>(StatementList{
|
||||
create<DiscardStatement>(),
|
||||
});
|
||||
auto* discard = body->statements[0];
|
||||
|
||||
auto* e = create<ElseStatement>(cond, body);
|
||||
EXPECT_EQ(e->condition, cond);
|
||||
ASSERT_EQ(e->body->statements.size(), 1u);
|
||||
EXPECT_EQ(e->body->statements[0], discard);
|
||||
}
|
||||
|
||||
TEST_F(ElseStatementTest, Creation_WithSource) {
|
||||
auto* e = create<ElseStatement>(Source{Source::Location{20, 2}}, Expr(true),
|
||||
Block());
|
||||
auto src = e->source;
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
}
|
||||
|
||||
TEST_F(ElseStatementTest, IsElse) {
|
||||
auto* e = create<ElseStatement>(nullptr, Block());
|
||||
EXPECT_TRUE(e->Is<ElseStatement>());
|
||||
}
|
||||
|
||||
TEST_F(ElseStatementTest, HasCondition) {
|
||||
auto* cond = Expr(true);
|
||||
auto* e = create<ElseStatement>(cond, Block());
|
||||
EXPECT_TRUE(e->condition);
|
||||
}
|
||||
|
||||
TEST_F(ElseStatementTest, HasContition_NullCondition) {
|
||||
auto* e = create<ElseStatement>(nullptr, Block());
|
||||
EXPECT_FALSE(e->condition);
|
||||
}
|
||||
|
||||
TEST_F(ElseStatementTest, Assert_Null_Body) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.create<ElseStatement>(b.Expr(true), nullptr);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(ElseStatementTest, Assert_DifferentProgramID_Condition) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<ElseStatement>(b2.Expr(true), b1.Block());
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(ElseStatementTest, Assert_DifferentProgramID_Body) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.create<ElseStatement>(b1.Expr(true), b2.Block());
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
32
src/tint/ast/expression.cc
Normal file
32
src/tint/ast/expression.cc
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/expression.h"
|
||||
|
||||
#include "src/tint/sem/expression.h"
|
||||
#include "src/tint/sem/info.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::Expression);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
Expression::Expression(ProgramID pid, const Source& src) : Base(pid, src) {}
|
||||
|
||||
Expression::Expression(Expression&&) = default;
|
||||
|
||||
Expression::~Expression() = default;
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
47
src/tint/ast/expression.h
Normal file
47
src/tint/ast/expression.h
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_EXPRESSION_H_
|
||||
#define SRC_TINT_AST_EXPRESSION_H_
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "src/tint/ast/node.h"
|
||||
#include "src/tint/sem/type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// Base expression class
|
||||
class Expression : public Castable<Expression, Node> {
|
||||
public:
|
||||
~Expression() override;
|
||||
|
||||
protected:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
Expression(ProgramID pid, const Source& src);
|
||||
/// Move constructor
|
||||
Expression(Expression&&);
|
||||
};
|
||||
|
||||
/// A list of expressions
|
||||
using ExpressionList = std::vector<const Expression*>;
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_EXPRESSION_H_
|
||||
41
src/tint/ast/external_texture.cc
Normal file
41
src/tint/ast/external_texture.cc
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright 2021 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/external_texture.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::ExternalTexture);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
// ExternalTexture::ExternalTexture() : Base(ast::TextureDimension::k2d) {}
|
||||
ExternalTexture::ExternalTexture(ProgramID pid, const Source& src)
|
||||
: Base(pid, src, ast::TextureDimension::k2d) {}
|
||||
|
||||
ExternalTexture::ExternalTexture(ExternalTexture&&) = default;
|
||||
|
||||
ExternalTexture::~ExternalTexture() = default;
|
||||
|
||||
std::string ExternalTexture::FriendlyName(const SymbolTable&) const {
|
||||
return "texture_external";
|
||||
}
|
||||
|
||||
const ExternalTexture* ExternalTexture::Clone(CloneContext* ctx) const {
|
||||
return ctx->dst->create<ExternalTexture>();
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
51
src/tint/ast/external_texture.h
Normal file
51
src/tint/ast/external_texture.h
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright 2021 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_EXTERNAL_TEXTURE_H_
|
||||
#define SRC_TINT_AST_EXTERNAL_TEXTURE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/ast/texture.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// An external texture type
|
||||
class ExternalTexture final : public Castable<ExternalTexture, Texture> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
ExternalTexture(ProgramID pid, const Source& src);
|
||||
|
||||
/// Move constructor
|
||||
ExternalTexture(ExternalTexture&&);
|
||||
~ExternalTexture() override;
|
||||
|
||||
/// @param symbols the program's symbol table
|
||||
/// @returns the name for this type that closely resembles how it would be
|
||||
/// declared in WGSL.
|
||||
std::string FriendlyName(const SymbolTable& symbols) const override;
|
||||
|
||||
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned type
|
||||
const ExternalTexture* Clone(CloneContext* ctx) const override;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_EXTERNAL_TEXTURE_H_
|
||||
46
src/tint/ast/external_texture_test.cc
Normal file
46
src/tint/ast/external_texture_test.cc
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright 2021 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/external_texture.h"
|
||||
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using AstExternalTextureTest = TestHelper;
|
||||
|
||||
TEST_F(AstExternalTextureTest, IsTexture) {
|
||||
Texture* ty = create<ExternalTexture>();
|
||||
EXPECT_FALSE(ty->Is<DepthTexture>());
|
||||
EXPECT_TRUE(ty->Is<ExternalTexture>());
|
||||
EXPECT_FALSE(ty->Is<MultisampledTexture>());
|
||||
EXPECT_FALSE(ty->Is<SampledTexture>());
|
||||
EXPECT_FALSE(ty->Is<StorageTexture>());
|
||||
}
|
||||
|
||||
TEST_F(AstExternalTextureTest, Dim) {
|
||||
auto* ty = create<ExternalTexture>();
|
||||
EXPECT_EQ(ty->dim, ast::TextureDimension::k2d);
|
||||
}
|
||||
|
||||
TEST_F(AstExternalTextureTest, FriendlyName) {
|
||||
auto* ty = create<ExternalTexture>();
|
||||
EXPECT_EQ(ty->FriendlyName(Symbols()), "texture_external");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
40
src/tint/ast/f32.cc
Normal file
40
src/tint/ast/f32.cc
Normal file
@@ -0,0 +1,40 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/f32.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::F32);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
F32::F32(ProgramID pid, const Source& src) : Base(pid, src) {}
|
||||
|
||||
F32::F32(F32&&) = default;
|
||||
|
||||
F32::~F32() = default;
|
||||
|
||||
std::string F32::FriendlyName(const SymbolTable&) const {
|
||||
return "f32";
|
||||
}
|
||||
|
||||
const F32* F32::Clone(CloneContext* ctx) const {
|
||||
auto src = ctx->Clone(source);
|
||||
return ctx->dst->create<F32>(src);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
50
src/tint/ast/f32.h
Normal file
50
src/tint/ast/f32.h
Normal file
@@ -0,0 +1,50 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_F32_H_
|
||||
#define SRC_TINT_AST_F32_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/ast/type.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// A float 32 type
|
||||
class F32 final : public Castable<F32, Type> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
F32(ProgramID pid, const Source& src);
|
||||
/// Move constructor
|
||||
F32(F32&&);
|
||||
~F32() override;
|
||||
|
||||
/// @param symbols the program's symbol table
|
||||
/// @returns the name for this type that closely resembles how it would be
|
||||
/// declared in WGSL.
|
||||
std::string FriendlyName(const SymbolTable& symbols) const override;
|
||||
|
||||
/// Clones this type and all transitive types using the `CloneContext` `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned type
|
||||
const F32* Clone(CloneContext* ctx) const override;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_F32_H_
|
||||
32
src/tint/ast/f32_test.cc
Normal file
32
src/tint/ast/f32_test.cc
Normal file
@@ -0,0 +1,32 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/f32.h"
|
||||
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using AstF32Test = TestHelper;
|
||||
|
||||
TEST_F(AstF32Test, FriendlyName) {
|
||||
auto* f = create<F32>();
|
||||
EXPECT_EQ(f->FriendlyName(Symbols()), "f32");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
39
src/tint/ast/fallthrough_statement.cc
Normal file
39
src/tint/ast/fallthrough_statement.cc
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/fallthrough_statement.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::FallthroughStatement);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
FallthroughStatement::FallthroughStatement(ProgramID pid, const Source& src)
|
||||
: Base(pid, src) {}
|
||||
|
||||
FallthroughStatement::FallthroughStatement(FallthroughStatement&&) = default;
|
||||
|
||||
FallthroughStatement::~FallthroughStatement() = default;
|
||||
|
||||
const FallthroughStatement* FallthroughStatement::Clone(
|
||||
CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
return ctx->dst->create<FallthroughStatement>(src);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
45
src/tint/ast/fallthrough_statement.h
Normal file
45
src/tint/ast/fallthrough_statement.h
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_FALLTHROUGH_STATEMENT_H_
|
||||
#define SRC_TINT_AST_FALLTHROUGH_STATEMENT_H_
|
||||
|
||||
#include "src/tint/ast/statement.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// An fallthrough statement
|
||||
class FallthroughStatement final
|
||||
: public Castable<FallthroughStatement, Statement> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
FallthroughStatement(ProgramID pid, const Source& src);
|
||||
/// Move constructor
|
||||
FallthroughStatement(FallthroughStatement&&);
|
||||
~FallthroughStatement() override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const FallthroughStatement* Clone(CloneContext* ctx) const override;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_FALLTHROUGH_STATEMENT_H_
|
||||
47
src/tint/ast/fallthrough_statement_test.cc
Normal file
47
src/tint/ast/fallthrough_statement_test.cc
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/fallthrough_statement.h"
|
||||
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using FallthroughStatementTest = TestHelper;
|
||||
|
||||
TEST_F(FallthroughStatementTest, Creation) {
|
||||
auto* stmt = create<FallthroughStatement>();
|
||||
EXPECT_EQ(stmt->source.range.begin.line, 0u);
|
||||
EXPECT_EQ(stmt->source.range.begin.column, 0u);
|
||||
EXPECT_EQ(stmt->source.range.end.line, 0u);
|
||||
EXPECT_EQ(stmt->source.range.end.column, 0u);
|
||||
}
|
||||
|
||||
TEST_F(FallthroughStatementTest, Creation_WithSource) {
|
||||
auto* stmt = create<FallthroughStatement>(Source{Source::Location{20, 2}});
|
||||
auto src = stmt->source;
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
}
|
||||
|
||||
TEST_F(FallthroughStatementTest, IsFallthrough) {
|
||||
auto* stmt = create<FallthroughStatement>();
|
||||
EXPECT_TRUE(stmt->Is<FallthroughStatement>());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
41
src/tint/ast/float_literal_expression.cc
Normal file
41
src/tint/ast/float_literal_expression.cc
Normal file
@@ -0,0 +1,41 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/float_literal_expression.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::FloatLiteralExpression);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
FloatLiteralExpression::FloatLiteralExpression(ProgramID pid,
|
||||
const Source& src,
|
||||
float val)
|
||||
: Base(pid, src), value(val) {}
|
||||
|
||||
FloatLiteralExpression::~FloatLiteralExpression() = default;
|
||||
|
||||
const FloatLiteralExpression* FloatLiteralExpression::Clone(
|
||||
CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
return ctx->dst->create<FloatLiteralExpression>(src, value);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
49
src/tint/ast/float_literal_expression.h
Normal file
49
src/tint/ast/float_literal_expression.h
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_FLOAT_LITERAL_EXPRESSION_H_
|
||||
#define SRC_TINT_AST_FLOAT_LITERAL_EXPRESSION_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/ast/literal_expression.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// A float literal
|
||||
class FloatLiteralExpression final
|
||||
: public Castable<FloatLiteralExpression, LiteralExpression> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
/// @param value the float literals value
|
||||
FloatLiteralExpression(ProgramID pid, const Source& src, float value);
|
||||
~FloatLiteralExpression() override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const FloatLiteralExpression* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// The float literal value
|
||||
const float value;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_FLOAT_LITERAL_EXPRESSION_H_
|
||||
31
src/tint/ast/float_literal_expression_test.cc
Normal file
31
src/tint/ast/float_literal_expression_test.cc
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using FloatLiteralExpressionTest = TestHelper;
|
||||
|
||||
TEST_F(FloatLiteralExpressionTest, Value) {
|
||||
auto* f = create<FloatLiteralExpression>(47.2f);
|
||||
ASSERT_TRUE(f->Is<FloatLiteralExpression>());
|
||||
EXPECT_EQ(f->value, 47.2f);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
59
src/tint/ast/for_loop_statement.cc
Normal file
59
src/tint/ast/for_loop_statement.cc
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright 2021 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/for_loop_statement.h"
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::ForLoopStatement);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
ForLoopStatement::ForLoopStatement(ProgramID pid,
|
||||
const Source& src,
|
||||
const Statement* init,
|
||||
const Expression* cond,
|
||||
const Statement* cont,
|
||||
const BlockStatement* b)
|
||||
: Base(pid, src),
|
||||
initializer(init),
|
||||
condition(cond),
|
||||
continuing(cont),
|
||||
body(b) {
|
||||
TINT_ASSERT(AST, body);
|
||||
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, initializer, program_id);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, condition, program_id);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, continuing, program_id);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
|
||||
}
|
||||
|
||||
ForLoopStatement::ForLoopStatement(ForLoopStatement&&) = default;
|
||||
|
||||
ForLoopStatement::~ForLoopStatement() = default;
|
||||
|
||||
const ForLoopStatement* ForLoopStatement::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
|
||||
auto* init = ctx->Clone(initializer);
|
||||
auto* cond = ctx->Clone(condition);
|
||||
auto* cont = ctx->Clone(continuing);
|
||||
auto* b = ctx->Clone(body);
|
||||
return ctx->dst->create<ForLoopStatement>(src, init, cond, cont, b);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
67
src/tint/ast/for_loop_statement.h
Normal file
67
src/tint/ast/for_loop_statement.h
Normal file
@@ -0,0 +1,67 @@
|
||||
// Copyright 2021 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_FOR_LOOP_STATEMENT_H_
|
||||
#define SRC_TINT_AST_FOR_LOOP_STATEMENT_H_
|
||||
|
||||
#include "src/tint/ast/block_statement.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
class Expression;
|
||||
|
||||
/// A for loop statement
|
||||
class ForLoopStatement final : public Castable<ForLoopStatement, Statement> {
|
||||
public:
|
||||
/// Constructor
|
||||
/// @param program_id the identifier of the program that owns this node
|
||||
/// @param source the for loop statement source
|
||||
/// @param initializer the optional loop initializer statement
|
||||
/// @param condition the optional loop condition expression
|
||||
/// @param continuing the optional continuing statement
|
||||
/// @param body the loop body
|
||||
ForLoopStatement(ProgramID program_id,
|
||||
Source const& source,
|
||||
const Statement* initializer,
|
||||
const Expression* condition,
|
||||
const Statement* continuing,
|
||||
const BlockStatement* body);
|
||||
/// Move constructor
|
||||
ForLoopStatement(ForLoopStatement&&);
|
||||
~ForLoopStatement() override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const ForLoopStatement* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// The initializer statement
|
||||
const Statement* const initializer;
|
||||
|
||||
/// The condition expression
|
||||
const Expression* const condition;
|
||||
|
||||
/// The continuing statement
|
||||
const Statement* const continuing;
|
||||
|
||||
/// The loop body block
|
||||
const BlockStatement* const body;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_FOR_LOOP_STATEMENT_H_
|
||||
104
src/tint/ast/for_loop_statement_test.cc
Normal file
104
src/tint/ast/for_loop_statement_test.cc
Normal file
@@ -0,0 +1,104 @@
|
||||
// Copyright 2021 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "gtest/gtest-spi.h"
|
||||
#include "src/tint/ast/binary_expression.h"
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using ForLoopStatementTest = TestHelper;
|
||||
|
||||
TEST_F(ForLoopStatementTest, Creation) {
|
||||
auto* init = Decl(Var("i", ty.u32()));
|
||||
auto* cond =
|
||||
create<BinaryExpression>(BinaryOp::kLessThan, Expr("i"), Expr(5u));
|
||||
auto* cont = Assign("i", Add("i", 1));
|
||||
auto* body = Block(Return());
|
||||
auto* l = For(init, cond, cont, body);
|
||||
|
||||
EXPECT_EQ(l->initializer, init);
|
||||
EXPECT_EQ(l->condition, cond);
|
||||
EXPECT_EQ(l->continuing, cont);
|
||||
EXPECT_EQ(l->body, body);
|
||||
}
|
||||
|
||||
TEST_F(ForLoopStatementTest, Creation_WithSource) {
|
||||
auto* body = Block(Return());
|
||||
auto* l = For(Source{{20u, 2u}}, nullptr, nullptr, nullptr, body);
|
||||
auto src = l->source;
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
}
|
||||
|
||||
TEST_F(ForLoopStatementTest, Creation_Null_InitCondCont) {
|
||||
auto* body = Block(Return());
|
||||
auto* l = For(nullptr, nullptr, nullptr, body);
|
||||
EXPECT_EQ(l->body, body);
|
||||
}
|
||||
|
||||
TEST_F(ForLoopStatementTest, Assert_Null_Body) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.For(nullptr, nullptr, nullptr, nullptr);
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(ForLoopStatementTest, Assert_DifferentProgramID_Initializer) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.For(b2.Block(), nullptr, nullptr, b1.Block());
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(ForLoopStatementTest, Assert_DifferentProgramID_Condition) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.For(nullptr, b2.Expr(true), nullptr, b1.Block());
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(ForLoopStatementTest, Assert_DifferentProgramID_Continuing) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.For(nullptr, nullptr, b2.Block(), b1.Block());
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(ForLoopStatementTest, Assert_DifferentProgramID_Body) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.For(nullptr, nullptr, nullptr, b2.Block());
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
108
src/tint/ast/function.cc
Normal file
108
src/tint/ast/function.cc
Normal file
@@ -0,0 +1,108 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/function.h"
|
||||
|
||||
#include "src/tint/ast/stage_attribute.h"
|
||||
#include "src/tint/ast/workgroup_attribute.h"
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::Function);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
Function::Function(ProgramID pid,
|
||||
const Source& src,
|
||||
Symbol sym,
|
||||
VariableList parameters,
|
||||
const Type* return_ty,
|
||||
const BlockStatement* b,
|
||||
AttributeList attrs,
|
||||
AttributeList return_type_attrs)
|
||||
: Base(pid, src),
|
||||
symbol(sym),
|
||||
params(std::move(parameters)),
|
||||
return_type(return_ty),
|
||||
body(b),
|
||||
attributes(std::move(attrs)),
|
||||
return_type_attributes(std::move(return_type_attrs)) {
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, symbol, program_id);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, body, program_id);
|
||||
for (auto* param : params) {
|
||||
TINT_ASSERT(AST, param && param->is_const);
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, param, program_id);
|
||||
}
|
||||
TINT_ASSERT(AST, symbol.IsValid());
|
||||
TINT_ASSERT(AST, return_type);
|
||||
for (auto* attr : attributes) {
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, attr, program_id);
|
||||
}
|
||||
for (auto* attr : return_type_attributes) {
|
||||
TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, attr, program_id);
|
||||
}
|
||||
}
|
||||
|
||||
Function::Function(Function&&) = default;
|
||||
|
||||
Function::~Function() = default;
|
||||
|
||||
PipelineStage Function::PipelineStage() const {
|
||||
if (auto* stage = GetAttribute<StageAttribute>(attributes)) {
|
||||
return stage->stage;
|
||||
}
|
||||
return PipelineStage::kNone;
|
||||
}
|
||||
|
||||
const Function* Function::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
auto sym = ctx->Clone(symbol);
|
||||
auto p = ctx->Clone(params);
|
||||
auto* ret = ctx->Clone(return_type);
|
||||
auto* b = ctx->Clone(body);
|
||||
auto attrs = ctx->Clone(attributes);
|
||||
auto ret_attrs = ctx->Clone(return_type_attributes);
|
||||
return ctx->dst->create<Function>(src, sym, p, ret, b, attrs, ret_attrs);
|
||||
}
|
||||
|
||||
const Function* FunctionList::Find(Symbol sym) const {
|
||||
for (auto* func : *this) {
|
||||
if (func->symbol == sym) {
|
||||
return func;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const Function* FunctionList::Find(Symbol sym, PipelineStage stage) const {
|
||||
for (auto* func : *this) {
|
||||
if (func->symbol == sym && func->PipelineStage() == stage) {
|
||||
return func;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool FunctionList::HasStage(ast::PipelineStage stage) const {
|
||||
for (auto* func : *this) {
|
||||
if (func->PipelineStage() == stage) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
118
src/tint/ast/function.h
Normal file
118
src/tint/ast/function.h
Normal file
@@ -0,0 +1,118 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_FUNCTION_H_
|
||||
#define SRC_TINT_AST_FUNCTION_H_
|
||||
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "src/tint/ast/attribute.h"
|
||||
#include "src/tint/ast/binding_attribute.h"
|
||||
#include "src/tint/ast/block_statement.h"
|
||||
#include "src/tint/ast/builtin_attribute.h"
|
||||
#include "src/tint/ast/group_attribute.h"
|
||||
#include "src/tint/ast/location_attribute.h"
|
||||
#include "src/tint/ast/pipeline_stage.h"
|
||||
#include "src/tint/ast/variable.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// A Function statement.
|
||||
class Function final : public Castable<Function, Node> {
|
||||
public:
|
||||
/// Create a function
|
||||
/// @param program_id the identifier of the program that owns this node
|
||||
/// @param source the variable source
|
||||
/// @param symbol the function symbol
|
||||
/// @param params the function parameters
|
||||
/// @param return_type the return type
|
||||
/// @param body the function body
|
||||
/// @param attributes the function attributes
|
||||
/// @param return_type_attributes the return type attributes
|
||||
Function(ProgramID program_id,
|
||||
const Source& source,
|
||||
Symbol symbol,
|
||||
VariableList params,
|
||||
const Type* return_type,
|
||||
const BlockStatement* body,
|
||||
AttributeList attributes,
|
||||
AttributeList return_type_attributes);
|
||||
/// Move constructor
|
||||
Function(Function&&);
|
||||
|
||||
~Function() override;
|
||||
|
||||
/// @returns the functions pipeline stage or None if not set
|
||||
ast::PipelineStage PipelineStage() const;
|
||||
|
||||
/// @returns true if this function is an entry point
|
||||
bool IsEntryPoint() const { return PipelineStage() != PipelineStage::kNone; }
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const Function* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// The function symbol
|
||||
const Symbol symbol;
|
||||
|
||||
/// The function params
|
||||
const VariableList params;
|
||||
|
||||
/// The function return type
|
||||
const Type* const return_type;
|
||||
|
||||
/// The function body
|
||||
const BlockStatement* const body;
|
||||
|
||||
/// The attributes attached to this function
|
||||
const AttributeList attributes;
|
||||
|
||||
/// The attributes attached to the function return type.
|
||||
const AttributeList return_type_attributes;
|
||||
};
|
||||
|
||||
/// A list of functions
|
||||
class FunctionList : public std::vector<const Function*> {
|
||||
public:
|
||||
/// Appends f to the end of the list
|
||||
/// @param f the function to append to this list
|
||||
void Add(const Function* f) { this->emplace_back(f); }
|
||||
|
||||
/// Returns the function with the given name
|
||||
/// @param sym the function symbol to search for
|
||||
/// @returns the associated function or nullptr if none exists
|
||||
const Function* Find(Symbol sym) const;
|
||||
|
||||
/// Returns the function with the given name
|
||||
/// @param sym the function symbol to search for
|
||||
/// @param stage the pipeline stage
|
||||
/// @returns the associated function or nullptr if none exists
|
||||
const Function* Find(Symbol sym, PipelineStage stage) const;
|
||||
|
||||
/// @param stage the pipeline stage
|
||||
/// @returns true if the Builder contains an entrypoint function with
|
||||
/// the given stage
|
||||
bool HasStage(PipelineStage stage) const;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_FUNCTION_H_
|
||||
196
src/tint/ast/function_test.cc
Normal file
196
src/tint/ast/function_test.cc
Normal file
@@ -0,0 +1,196 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "gtest/gtest-spi.h"
|
||||
#include "src/tint/ast/discard_statement.h"
|
||||
#include "src/tint/ast/stage_attribute.h"
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
#include "src/tint/ast/workgroup_attribute.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using FunctionTest = TestHelper;
|
||||
|
||||
TEST_F(FunctionTest, Creation) {
|
||||
VariableList params;
|
||||
params.push_back(Param("var", ty.i32()));
|
||||
auto* var = params[0];
|
||||
|
||||
auto* f = Func("func", params, ty.void_(), StatementList{}, AttributeList{});
|
||||
EXPECT_EQ(f->symbol, Symbols().Get("func"));
|
||||
ASSERT_EQ(f->params.size(), 1u);
|
||||
EXPECT_TRUE(f->return_type->Is<ast::Void>());
|
||||
EXPECT_EQ(f->params[0], var);
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, Creation_WithSource) {
|
||||
VariableList params;
|
||||
params.push_back(Param("var", ty.i32()));
|
||||
|
||||
auto* f = Func(Source{Source::Location{20, 2}}, "func", params, ty.void_(),
|
||||
StatementList{}, AttributeList{});
|
||||
auto src = f->source;
|
||||
EXPECT_EQ(src.range.begin.line, 20u);
|
||||
EXPECT_EQ(src.range.begin.column, 2u);
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, Assert_InvalidName) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.Func("", VariableList{}, b.ty.void_(), StatementList{},
|
||||
AttributeList{});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, Assert_Null_ReturnType) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
b.Func("f", VariableList{}, nullptr, StatementList{}, AttributeList{});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, Assert_Null_Param) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
VariableList params;
|
||||
params.push_back(b.Param("var", b.ty.i32()));
|
||||
params.push_back(nullptr);
|
||||
|
||||
b.Func("f", params, b.ty.void_(), StatementList{}, AttributeList{});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, Assert_DifferentProgramID_Symbol) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.Func(b2.Sym("func"), VariableList{}, b1.ty.void_(), StatementList{});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, Assert_DifferentProgramID_Param) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.Func("func", VariableList{b2.Param("var", b2.ty.i32())},
|
||||
b1.ty.void_(), StatementList{});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, Assert_DifferentProgramID_Attr) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.Func("func", VariableList{}, b1.ty.void_(), StatementList{},
|
||||
AttributeList{
|
||||
b2.WorkgroupSize(2, 4, 6),
|
||||
});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, Assert_DifferentProgramID_ReturnAttr) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b1;
|
||||
ProgramBuilder b2;
|
||||
b1.Func("func", VariableList{}, b1.ty.void_(), StatementList{},
|
||||
AttributeList{},
|
||||
AttributeList{
|
||||
b2.WorkgroupSize(2, 4, 6),
|
||||
});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
TEST_F(FunctionTest, Assert_NonConstParam) {
|
||||
EXPECT_FATAL_FAILURE(
|
||||
{
|
||||
ProgramBuilder b;
|
||||
VariableList params;
|
||||
params.push_back(b.Var("var", b.ty.i32(), ast::StorageClass::kNone));
|
||||
|
||||
b.Func("f", params, b.ty.void_(), StatementList{}, AttributeList{});
|
||||
},
|
||||
"internal compiler error");
|
||||
}
|
||||
|
||||
using FunctionListTest = TestHelper;
|
||||
|
||||
TEST_F(FunctionListTest, FindSymbol) {
|
||||
auto* func = Func("main", VariableList{}, ty.f32(), StatementList{},
|
||||
ast::AttributeList{});
|
||||
FunctionList list;
|
||||
list.Add(func);
|
||||
EXPECT_EQ(func, list.Find(Symbols().Register("main")));
|
||||
}
|
||||
|
||||
TEST_F(FunctionListTest, FindSymbolMissing) {
|
||||
FunctionList list;
|
||||
EXPECT_EQ(nullptr, list.Find(Symbols().Register("Missing")));
|
||||
}
|
||||
|
||||
TEST_F(FunctionListTest, FindSymbolStage) {
|
||||
auto* fs = Func("main", VariableList{}, ty.f32(), StatementList{},
|
||||
ast::AttributeList{
|
||||
Stage(PipelineStage::kFragment),
|
||||
});
|
||||
auto* vs = Func("main", VariableList{}, ty.f32(), StatementList{},
|
||||
ast::AttributeList{
|
||||
Stage(PipelineStage::kVertex),
|
||||
});
|
||||
FunctionList list;
|
||||
list.Add(fs);
|
||||
list.Add(vs);
|
||||
EXPECT_EQ(fs,
|
||||
list.Find(Symbols().Register("main"), PipelineStage::kFragment));
|
||||
EXPECT_EQ(vs, list.Find(Symbols().Register("main"), PipelineStage::kVertex));
|
||||
}
|
||||
|
||||
TEST_F(FunctionListTest, FindSymbolStageMissing) {
|
||||
FunctionList list;
|
||||
list.Add(Func("main", VariableList{}, ty.f32(), StatementList{},
|
||||
ast::AttributeList{
|
||||
Stage(PipelineStage::kFragment),
|
||||
}));
|
||||
EXPECT_EQ(nullptr,
|
||||
list.Find(Symbols().Register("main"), PipelineStage::kVertex));
|
||||
}
|
||||
|
||||
TEST_F(FunctionListTest, HasStage) {
|
||||
FunctionList list;
|
||||
list.Add(Func("main", VariableList{}, ty.f32(), StatementList{},
|
||||
ast::AttributeList{
|
||||
Stage(PipelineStage::kFragment),
|
||||
}));
|
||||
EXPECT_TRUE(list.HasStage(PipelineStage::kFragment));
|
||||
EXPECT_FALSE(list.HasStage(PipelineStage::kVertex));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
42
src/tint/ast/group_attribute.cc
Normal file
42
src/tint/ast/group_attribute.cc
Normal file
@@ -0,0 +1,42 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/group_attribute.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/program_builder.h"
|
||||
|
||||
TINT_INSTANTIATE_TYPEINFO(tint::ast::GroupAttribute);
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
GroupAttribute::GroupAttribute(ProgramID pid, const Source& src, uint32_t val)
|
||||
: Base(pid, src), value(val) {}
|
||||
|
||||
GroupAttribute::~GroupAttribute() = default;
|
||||
|
||||
std::string GroupAttribute::Name() const {
|
||||
return "group";
|
||||
}
|
||||
|
||||
const GroupAttribute* GroupAttribute::Clone(CloneContext* ctx) const {
|
||||
// Clone arguments outside of create() call to have deterministic ordering
|
||||
auto src = ctx->Clone(source);
|
||||
return ctx->dst->create<GroupAttribute>(src, value);
|
||||
}
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
51
src/tint/ast/group_attribute.h
Normal file
51
src/tint/ast/group_attribute.h
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef SRC_TINT_AST_GROUP_ATTRIBUTE_H_
|
||||
#define SRC_TINT_AST_GROUP_ATTRIBUTE_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/tint/ast/attribute.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
|
||||
/// A group attribute
|
||||
class GroupAttribute final : public Castable<GroupAttribute, Attribute> {
|
||||
public:
|
||||
/// constructor
|
||||
/// @param pid the identifier of the program that owns this node
|
||||
/// @param src the source of this node
|
||||
/// @param value the group value
|
||||
GroupAttribute(ProgramID pid, const Source& src, uint32_t value);
|
||||
~GroupAttribute() override;
|
||||
|
||||
/// @returns the WGSL name for the attribute
|
||||
std::string Name() const override;
|
||||
|
||||
/// Clones this node and all transitive child nodes using the `CloneContext`
|
||||
/// `ctx`.
|
||||
/// @param ctx the clone context
|
||||
/// @return the newly cloned node
|
||||
const GroupAttribute* Clone(CloneContext* ctx) const override;
|
||||
|
||||
/// The group value
|
||||
const uint32_t value;
|
||||
};
|
||||
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
|
||||
#endif // SRC_TINT_AST_GROUP_ATTRIBUTE_H_
|
||||
30
src/tint/ast/group_attribute_test.cc
Normal file
30
src/tint/ast/group_attribute_test.cc
Normal file
@@ -0,0 +1,30 @@
|
||||
// Copyright 2020 The Tint Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "src/tint/ast/test_helper.h"
|
||||
|
||||
namespace tint {
|
||||
namespace ast {
|
||||
namespace {
|
||||
|
||||
using GroupAttributeTest = TestHelper;
|
||||
|
||||
TEST_F(GroupAttributeTest, Creation) {
|
||||
auto* d = create<GroupAttribute>(2);
|
||||
EXPECT_EQ(2u, d->value);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace ast
|
||||
} // namespace tint
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user