mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-05 04:36:02 +00:00
[spirv-reader] Support function call returning void
Bug: tint:3, tint:99 Change-Id: I6fe6d06d79115e6b3b0adb800f21c4704795dc15 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25360 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
a0b73e8aca
commit
28d0f4b905
@ -34,6 +34,7 @@
|
|||||||
#include "src/ast/bool_literal.h"
|
#include "src/ast/bool_literal.h"
|
||||||
#include "src/ast/break_statement.h"
|
#include "src/ast/break_statement.h"
|
||||||
#include "src/ast/call_expression.h"
|
#include "src/ast/call_expression.h"
|
||||||
|
#include "src/ast/call_statement.h"
|
||||||
#include "src/ast/case_statement.h"
|
#include "src/ast/case_statement.h"
|
||||||
#include "src/ast/cast_expression.h"
|
#include "src/ast/cast_expression.h"
|
||||||
#include "src/ast/continue_statement.h"
|
#include "src/ast/continue_statement.h"
|
||||||
@ -3365,19 +3366,21 @@ bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
|
|||||||
for (uint32_t iarg = 1; iarg < inst.NumInOperands(); ++iarg) {
|
for (uint32_t iarg = 1; iarg < inst.NumInOperands(); ++iarg) {
|
||||||
params.emplace_back(MakeOperand(inst, iarg).expr);
|
params.emplace_back(MakeOperand(inst, iarg).expr);
|
||||||
}
|
}
|
||||||
TypedExpression expr{parser_impl_.ConvertType(inst.type_id()),
|
auto call_expr = std::make_unique<ast::CallExpression>(std::move(function),
|
||||||
std::make_unique<ast::CallExpression>(
|
std::move(params));
|
||||||
std::move(function), std::move(params))};
|
auto result_type = parser_impl_.ConvertType(inst.type_id());
|
||||||
|
if (!result_type) {
|
||||||
if (expr.type->IsVoid()) {
|
return Fail() << "internal error: no mapped type result of call: "
|
||||||
// TODO(dneto): Tint AST needs support for function call as a statement
|
|
||||||
// https://bugs.chromium.org/p/tint/issues/detail?id=45
|
|
||||||
return Fail() << "missing support for function call as a statement: can't "
|
|
||||||
"generate code for function call returning void: "
|
|
||||||
<< inst.PrettyPrint();
|
<< inst.PrettyPrint();
|
||||||
}
|
}
|
||||||
|
|
||||||
return EmitConstDefOrWriteToHoistedVar(inst, std::move(expr));
|
if (result_type->IsVoid()) {
|
||||||
|
return nullptr != AddStatement(std::make_unique<ast::CallStatement>(
|
||||||
|
std::move(call_expr)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return EmitConstDefOrWriteToHoistedVar(inst,
|
||||||
|
{result_type, std::move(call_expr)});
|
||||||
}
|
}
|
||||||
|
|
||||||
TypedExpression FunctionEmitter::MakeSimpleSelect(
|
TypedExpression FunctionEmitter::MakeSimpleSelect(
|
||||||
|
@ -46,13 +46,26 @@ TEST_F(SpvParserTest, EmitStatement_VoidCallNoParams) {
|
|||||||
OpReturn
|
OpReturn
|
||||||
OpFunctionEnd
|
OpFunctionEnd
|
||||||
)"));
|
)"));
|
||||||
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
ASSERT_TRUE(p->BuildAndParseInternalModule()) << p->error();
|
||||||
FunctionEmitter fe(p, *spirv_function(100));
|
const auto module_ast_str = p->module().to_str();
|
||||||
EXPECT_FALSE(fe.EmitBody());
|
EXPECT_THAT(module_ast_str, Eq(R"(Module{
|
||||||
EXPECT_THAT(
|
Function x_50 -> __void
|
||||||
p->error(),
|
()
|
||||||
Eq("missing support for function call as a statement: can't generate "
|
{
|
||||||
"code for function call returning void: %1 = OpFunctionCall %2 %50"));
|
Return{}
|
||||||
|
}
|
||||||
|
Function x_100 -> __void
|
||||||
|
()
|
||||||
|
{
|
||||||
|
Call{
|
||||||
|
Identifier{x_50}
|
||||||
|
(
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Return{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)")) << module_ast_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SpvParserTest, EmitStatement_ScalarCallNoParams) {
|
TEST_F(SpvParserTest, EmitStatement_ScalarCallNoParams) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user