[tint][ir] Add 'const' accessors
const methods that return a pointer can only return a const pointee
object.
This will be used by consumers of the IR that will not mutate the IR,
such as printers, validators, disassemblers, serializers, etc.
Change-Id: I5e881126c21f95a0848ad65c317cc8cdc70d1ae9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/161010
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/src/tint/lang/core/ir/function.h b/src/tint/lang/core/ir/function.h
index 33639bb..92699a3 100644
--- a/src/tint/lang/core/ir/function.h
+++ b/src/tint/lang/core/ir/function.h
@@ -88,7 +88,7 @@
void SetStage(PipelineStage stage) { pipeline_stage_ = stage; }
/// @returns the function pipeline stage
- PipelineStage Stage() { return pipeline_stage_; }
+ PipelineStage Stage() const { return pipeline_stage_; }
/// Sets the workgroup size
/// @param x the x size
@@ -100,10 +100,10 @@
void ClearWorkgroupSize() { workgroup_size_ = {}; }
/// @returns the workgroup size information
- std::optional<std::array<uint32_t, 3>> WorkgroupSize() { return workgroup_size_; }
+ std::optional<std::array<uint32_t, 3>> WorkgroupSize() const { return workgroup_size_; }
/// @returns the return type for the function
- const core::type::Type* ReturnType() { return return_.type; }
+ const core::type::Type* ReturnType() const { return return_.type; }
/// Sets the return attributes
/// @param builtin the builtin to set
@@ -112,7 +112,7 @@
return_.builtin = builtin;
}
/// @returns the return builtin attribute
- std::optional<enum ReturnBuiltin> ReturnBuiltin() { return return_.builtin; }
+ std::optional<enum ReturnBuiltin> ReturnBuiltin() const { return return_.builtin; }
/// Clears the return builtin attribute.
void ClearReturnBuiltin() { return_.builtin = {}; }
@@ -123,7 +123,7 @@
return_.location = {loc, interp};
}
/// @returns the return location
- std::optional<Location> ReturnLocation() { return return_.location; }
+ std::optional<Location> ReturnLocation() const { return return_.location; }
/// Clears the return location attribute.
void ClearReturnLocation() { return_.location = {}; }
@@ -131,7 +131,7 @@
/// @param val the invariant value to set
void SetReturnInvariant(bool val) { return_.invariant = val; }
/// @returns the return invariant value
- bool ReturnInvariant() { return return_.invariant; }
+ bool ReturnInvariant() const { return return_.invariant; }
/// Sets the function parameters
/// @param params the function parameters
@@ -144,15 +144,22 @@
/// @returns the function parameters
const VectorRef<FunctionParam*> Params() { return params_; }
+ /// @returns the function parameters
+ VectorRef<const FunctionParam*> Params() const { return params_; }
+
/// Sets the root block for the function
/// @param target the root block
void SetBlock(Block* target) {
TINT_ASSERT(target != nullptr);
block_ = target;
}
+
/// @returns the function root block
ir::Block* Block() { return block_; }
+ /// @returns the function root block
+ const ir::Block* Block() const { return block_; }
+
/// Destroys the function and all of its instructions.
void Destroy() override;