[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 <dsinclair@google.com>
diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index 22dc974..6cb34f0 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc
@@ -163,6 +163,18 @@ return success(); } +std::unique_ptr<ast::Expression> 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 7a4dd95..6a00f30 100644 --- a/src/reader/spirv/function.h +++ b/src/reader/spirv/function.h
@@ -66,6 +66,11 @@ /// @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<ast::Expression> MakeExpression(uint32_t id); + private: /// @returns the store type for the OpVariable instruction, or /// null on failure.