From d877e8b0840cd28c483477cdd9238d9f0649cebf Mon Sep 17 00:00:00 2001 From: David Neto Date: Wed, 8 Apr 2020 14:24:18 +0000 Subject: [PATCH] [spirv-reader] Start emitting expression Bug: tint:3 Change-Id: I2e2fe41c43abbcbbc941968c0115d703f6bff501 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18822 Reviewed-by: dan sinclair --- src/reader/spirv/function.cc | 12 ++++++++++++ src/reader/spirv/function.h | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index 22dc974160..6cb34f0373 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -163,6 +163,18 @@ bool FunctionEmitter::EmitFunctionVariables() { return success(); } +std::unique_ptr FunctionEmitter::MakeExpression(uint32_t id) { + if (failed()) { + return nullptr; + } + const auto* spirv_constant = constant_mgr_->FindDeclaredConstant(id); + if (spirv_constant) { + return parser_impl_.MakeConstantExpression(id); + } + Fail() << "unhandled expression for ID " << id; + return nullptr; +} + } // namespace spirv } // namespace reader } // namespace tint diff --git a/src/reader/spirv/function.h b/src/reader/spirv/function.h index 7a4dd95bea..6a00f30d06 100644 --- a/src/reader/spirv/function.h +++ b/src/reader/spirv/function.h @@ -66,6 +66,11 @@ class FunctionEmitter { /// @returns false if emission failed. bool EmitFunctionVariables(); + /// Makes an expression + /// @param id the SPIR-V ID of the value + /// @returns true if emission has not yet failed. + std::unique_ptr MakeExpression(uint32_t id); + private: /// @returns the store type for the OpVariable instruction, or /// null on failure.