2020-03-02 20:47:43 +00:00
|
|
|
// 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/type_determiner.h"
|
|
|
|
|
2020-04-07 12:57:42 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2020-04-20 15:46:18 +00:00
|
|
|
#include "spirv/unified1/GLSL.std.450.h"
|
2020-04-07 12:57:42 +00:00
|
|
|
#include "src/ast/array_accessor_expression.h"
|
2020-04-07 12:57:52 +00:00
|
|
|
#include "src/ast/as_expression.h"
|
2020-04-07 12:47:23 +00:00
|
|
|
#include "src/ast/assignment_statement.h"
|
2020-04-07 19:27:41 +00:00
|
|
|
#include "src/ast/binary_expression.h"
|
2020-04-07 12:54:10 +00:00
|
|
|
#include "src/ast/break_statement.h"
|
2020-04-07 16:41:10 +00:00
|
|
|
#include "src/ast/call_expression.h"
|
2020-04-07 12:54:20 +00:00
|
|
|
#include "src/ast/case_statement.h"
|
2020-04-07 16:41:23 +00:00
|
|
|
#include "src/ast/cast_expression.h"
|
2020-04-07 12:54:29 +00:00
|
|
|
#include "src/ast/continue_statement.h"
|
2020-04-07 12:54:37 +00:00
|
|
|
#include "src/ast/else_statement.h"
|
2020-04-07 12:57:27 +00:00
|
|
|
#include "src/ast/identifier_expression.h"
|
2020-04-07 12:55:25 +00:00
|
|
|
#include "src/ast/if_statement.h"
|
2020-06-04 17:05:35 +00:00
|
|
|
#include "src/ast/intrinsic.h"
|
2020-04-07 12:55:51 +00:00
|
|
|
#include "src/ast/loop_statement.h"
|
2020-04-07 16:41:33 +00:00
|
|
|
#include "src/ast/member_accessor_expression.h"
|
2020-04-07 12:56:24 +00:00
|
|
|
#include "src/ast/return_statement.h"
|
2020-04-07 12:46:30 +00:00
|
|
|
#include "src/ast/scalar_constructor_expression.h"
|
2020-04-07 12:56:45 +00:00
|
|
|
#include "src/ast/switch_statement.h"
|
2020-04-07 12:57:42 +00:00
|
|
|
#include "src/ast/type/array_type.h"
|
2020-04-07 19:26:39 +00:00
|
|
|
#include "src/ast/type/bool_type.h"
|
2020-04-07 19:27:00 +00:00
|
|
|
#include "src/ast/type/f32_type.h"
|
2020-04-07 12:57:42 +00:00
|
|
|
#include "src/ast/type/matrix_type.h"
|
2020-04-23 22:26:52 +00:00
|
|
|
#include "src/ast/type/pointer_type.h"
|
2020-04-07 16:41:33 +00:00
|
|
|
#include "src/ast/type/struct_type.h"
|
2020-04-07 12:57:42 +00:00
|
|
|
#include "src/ast/type/vector_type.h"
|
2020-04-07 12:46:30 +00:00
|
|
|
#include "src/ast/type_constructor_expression.h"
|
2020-04-07 19:27:21 +00:00
|
|
|
#include "src/ast/unary_op_expression.h"
|
2020-04-07 12:57:12 +00:00
|
|
|
#include "src/ast/variable_decl_statement.h"
|
2020-04-07 12:46:30 +00:00
|
|
|
|
2020-03-02 20:47:43 +00:00
|
|
|
namespace tint {
|
|
|
|
|
2020-04-20 14:20:01 +00:00
|
|
|
TypeDeterminer::TypeDeterminer(Context* ctx, ast::Module* mod)
|
|
|
|
: ctx_(*ctx), mod_(mod) {}
|
2020-03-02 20:47:43 +00:00
|
|
|
|
|
|
|
TypeDeterminer::~TypeDeterminer() = default;
|
|
|
|
|
2020-04-08 19:58:35 +00:00
|
|
|
void TypeDeterminer::set_error(const Source& src, const std::string& msg) {
|
|
|
|
error_ = "";
|
|
|
|
if (src.line > 0) {
|
|
|
|
error_ +=
|
|
|
|
std::to_string(src.line) + ":" + std::to_string(src.column) + ": ";
|
|
|
|
}
|
|
|
|
error_ += msg;
|
|
|
|
}
|
|
|
|
|
2020-04-20 14:20:01 +00:00
|
|
|
bool TypeDeterminer::Determine() {
|
|
|
|
for (const auto& var : mod_->global_variables()) {
|
2020-04-06 21:07:41 +00:00
|
|
|
variable_stack_.set_global(var->name(), var.get());
|
|
|
|
}
|
|
|
|
|
2020-04-20 14:20:01 +00:00
|
|
|
for (const auto& func : mod_->functions()) {
|
2020-04-06 21:07:41 +00:00
|
|
|
name_to_function_[func->name()] = func.get();
|
|
|
|
}
|
|
|
|
|
2020-04-20 14:20:01 +00:00
|
|
|
if (!DetermineFunctions(mod_->functions())) {
|
2020-04-06 21:07:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TypeDeterminer::DetermineFunctions(const ast::FunctionList& funcs) {
|
|
|
|
for (const auto& func : funcs) {
|
|
|
|
if (!DetermineFunction(func.get())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TypeDeterminer::DetermineFunction(ast::Function* func) {
|
|
|
|
variable_stack_.push_scope();
|
2020-04-08 19:58:20 +00:00
|
|
|
if (!DetermineStatements(func->body())) {
|
2020-04-06 21:07:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
variable_stack_.pop_scope();
|
|
|
|
|
2020-03-02 20:47:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-08 19:58:20 +00:00
|
|
|
bool TypeDeterminer::DetermineStatements(const ast::StatementList& stmts) {
|
2020-04-06 21:07:41 +00:00
|
|
|
for (const auto& stmt : stmts) {
|
2020-04-08 19:58:20 +00:00
|
|
|
if (!DetermineVariableStorageClass(stmt.get())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-06 21:07:41 +00:00
|
|
|
if (!DetermineResultType(stmt.get())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-08 19:58:20 +00:00
|
|
|
bool TypeDeterminer::DetermineVariableStorageClass(ast::Statement* stmt) {
|
|
|
|
if (!stmt->IsVariableDecl()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-09 18:52:06 +00:00
|
|
|
auto* var = stmt->AsVariableDecl()->variable();
|
2020-04-08 19:58:20 +00:00
|
|
|
// Nothing to do for const
|
|
|
|
if (var->is_const()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (var->storage_class() == ast::StorageClass::kFunction) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (var->storage_class() != ast::StorageClass::kNone) {
|
2020-04-21 13:05:42 +00:00
|
|
|
set_error(stmt->source(),
|
|
|
|
"function variable has a non-function storage class");
|
2020-04-08 19:58:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var->set_storage_class(ast::StorageClass::kFunction);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-07 12:47:23 +00:00
|
|
|
bool TypeDeterminer::DetermineResultType(ast::Statement* stmt) {
|
|
|
|
if (stmt->IsAssign()) {
|
2020-04-09 18:52:06 +00:00
|
|
|
auto* a = stmt->AsAssign();
|
2020-04-07 12:47:23 +00:00
|
|
|
return DetermineResultType(a->lhs()) && DetermineResultType(a->rhs());
|
|
|
|
}
|
2020-04-07 12:54:10 +00:00
|
|
|
if (stmt->IsBreak()) {
|
2020-06-03 16:11:28 +00:00
|
|
|
return true;
|
2020-04-07 12:54:10 +00:00
|
|
|
}
|
2020-04-07 12:54:20 +00:00
|
|
|
if (stmt->IsCase()) {
|
2020-04-09 18:52:06 +00:00
|
|
|
auto* c = stmt->AsCase();
|
2020-04-08 19:58:20 +00:00
|
|
|
return DetermineStatements(c->body());
|
2020-04-07 12:54:20 +00:00
|
|
|
}
|
2020-04-07 12:54:29 +00:00
|
|
|
if (stmt->IsContinue()) {
|
2020-06-03 16:11:28 +00:00
|
|
|
return true;
|
2020-04-07 12:54:29 +00:00
|
|
|
}
|
2020-04-07 12:54:37 +00:00
|
|
|
if (stmt->IsElse()) {
|
2020-04-09 18:52:06 +00:00
|
|
|
auto* e = stmt->AsElse();
|
2020-04-07 12:54:37 +00:00
|
|
|
return DetermineResultType(e->condition()) &&
|
2020-04-08 19:58:20 +00:00
|
|
|
DetermineStatements(e->body());
|
2020-04-07 12:54:37 +00:00
|
|
|
}
|
2020-04-07 12:54:59 +00:00
|
|
|
if (stmt->IsFallthrough()) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-04-07 12:55:25 +00:00
|
|
|
if (stmt->IsIf()) {
|
2020-04-09 18:52:06 +00:00
|
|
|
auto* i = stmt->AsIf();
|
2020-04-07 12:55:25 +00:00
|
|
|
if (!DetermineResultType(i->condition()) ||
|
2020-04-08 19:58:20 +00:00
|
|
|
!DetermineStatements(i->body())) {
|
2020-04-07 12:55:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto& else_stmt : i->else_statements()) {
|
|
|
|
if (!DetermineResultType(else_stmt.get())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2020-04-07 12:54:59 +00:00
|
|
|
if (stmt->IsKill()) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-04-07 12:55:51 +00:00
|
|
|
if (stmt->IsLoop()) {
|
2020-04-09 18:52:06 +00:00
|
|
|
auto* l = stmt->AsLoop();
|
2020-04-08 19:58:20 +00:00
|
|
|
return DetermineStatements(l->body()) &&
|
|
|
|
DetermineStatements(l->continuing());
|
2020-04-07 12:55:51 +00:00
|
|
|
}
|
2020-04-07 12:56:24 +00:00
|
|
|
if (stmt->IsReturn()) {
|
2020-04-09 18:52:06 +00:00
|
|
|
auto* r = stmt->AsReturn();
|
2020-04-07 12:56:24 +00:00
|
|
|
return DetermineResultType(r->value());
|
|
|
|
}
|
2020-04-07 12:56:45 +00:00
|
|
|
if (stmt->IsSwitch()) {
|
2020-04-09 18:52:06 +00:00
|
|
|
auto* s = stmt->AsSwitch();
|
2020-04-07 12:56:45 +00:00
|
|
|
if (!DetermineResultType(s->condition())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
for (const auto& case_stmt : s->body()) {
|
|
|
|
if (!DetermineResultType(case_stmt.get())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2020-04-07 12:54:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
2020-04-07 12:57:12 +00:00
|
|
|
if (stmt->IsVariableDecl()) {
|
2020-04-09 18:52:06 +00:00
|
|
|
auto* v = stmt->AsVariableDecl();
|
2020-04-07 12:57:12 +00:00
|
|
|
variable_stack_.set(v->variable()->name(), v->variable());
|
|
|
|
return DetermineResultType(v->variable()->constructor());
|
|
|
|
}
|
2020-04-07 12:47:23 +00:00
|
|
|
|
2020-04-08 19:58:35 +00:00
|
|
|
set_error(stmt->source(), "unknown statement type for type determination");
|
2020-04-06 21:07:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-20 15:46:18 +00:00
|
|
|
bool TypeDeterminer::DetermineResultType(const ast::ExpressionList& list) {
|
|
|
|
for (const auto& expr : list) {
|
|
|
|
if (!DetermineResultType(expr.get())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-06 21:07:41 +00:00
|
|
|
bool TypeDeterminer::DetermineResultType(ast::Expression* expr) {
|
|
|
|
// This is blindly called above, so in some cases the expression won't exist.
|
|
|
|
if (!expr) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-07 12:57:42 +00:00
|
|
|
if (expr->IsArrayAccessor()) {
|
|
|
|
return DetermineArrayAccessor(expr->AsArrayAccessor());
|
|
|
|
}
|
2020-04-07 12:57:52 +00:00
|
|
|
if (expr->IsAs()) {
|
|
|
|
return DetermineAs(expr->AsAs());
|
|
|
|
}
|
2020-04-07 19:27:41 +00:00
|
|
|
if (expr->IsBinary()) {
|
|
|
|
return DetermineBinary(expr->AsBinary());
|
|
|
|
}
|
2020-04-07 16:41:10 +00:00
|
|
|
if (expr->IsCall()) {
|
|
|
|
return DetermineCall(expr->AsCall());
|
|
|
|
}
|
2020-04-07 16:41:23 +00:00
|
|
|
if (expr->IsCast()) {
|
|
|
|
return DetermineCast(expr->AsCast());
|
|
|
|
}
|
2020-04-07 12:46:30 +00:00
|
|
|
if (expr->IsConstructor()) {
|
|
|
|
return DetermineConstructor(expr->AsConstructor());
|
|
|
|
}
|
2020-04-07 12:57:27 +00:00
|
|
|
if (expr->IsIdentifier()) {
|
|
|
|
return DetermineIdentifier(expr->AsIdentifier());
|
|
|
|
}
|
2020-04-07 16:41:33 +00:00
|
|
|
if (expr->IsMemberAccessor()) {
|
|
|
|
return DetermineMemberAccessor(expr->AsMemberAccessor());
|
|
|
|
}
|
2020-04-07 19:27:11 +00:00
|
|
|
if (expr->IsUnaryOp()) {
|
|
|
|
return DetermineUnaryOp(expr->AsUnaryOp());
|
|
|
|
}
|
2020-04-07 12:46:30 +00:00
|
|
|
|
2020-04-08 19:58:35 +00:00
|
|
|
set_error(expr->source(), "unknown expression for type determination");
|
2020-04-06 21:07:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-07 12:57:42 +00:00
|
|
|
bool TypeDeterminer::DetermineArrayAccessor(
|
|
|
|
ast::ArrayAccessorExpression* expr) {
|
|
|
|
if (!DetermineResultType(expr->array())) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-01 16:17:03 +00:00
|
|
|
if (!DetermineResultType(expr->idx_expr())) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-04-23 22:26:52 +00:00
|
|
|
|
|
|
|
auto* res = expr->array()->result_type();
|
|
|
|
auto* parent_type = res->UnwrapPtrIfNeeded();
|
|
|
|
ast::type::Type* ret = nullptr;
|
2020-04-07 12:57:42 +00:00
|
|
|
if (parent_type->IsArray()) {
|
2020-04-23 22:26:52 +00:00
|
|
|
ret = parent_type->AsArray()->type();
|
2020-04-07 12:57:42 +00:00
|
|
|
} else if (parent_type->IsVector()) {
|
2020-04-23 22:26:52 +00:00
|
|
|
ret = parent_type->AsVector()->type();
|
2020-04-07 12:57:42 +00:00
|
|
|
} else if (parent_type->IsMatrix()) {
|
2020-04-09 18:52:06 +00:00
|
|
|
auto* m = parent_type->AsMatrix();
|
2020-04-23 22:26:52 +00:00
|
|
|
ret = ctx_.type_mgr().Get(
|
|
|
|
std::make_unique<ast::type::VectorType>(m->type(), m->rows()));
|
2020-04-07 12:57:42 +00:00
|
|
|
} else {
|
2020-04-08 19:58:35 +00:00
|
|
|
set_error(expr->source(), "invalid parent type in array accessor");
|
2020-04-07 12:57:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
2020-04-23 22:26:52 +00:00
|
|
|
|
|
|
|
// If we're extracting from a pointer, we return a pointer.
|
|
|
|
if (res->IsPointer()) {
|
|
|
|
ret = ctx_.type_mgr().Get(std::make_unique<ast::type::PointerType>(
|
|
|
|
ret, res->AsPointer()->storage_class()));
|
|
|
|
}
|
|
|
|
expr->set_result_type(ret);
|
|
|
|
|
2020-04-07 12:57:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-07 12:57:52 +00:00
|
|
|
bool TypeDeterminer::DetermineAs(ast::AsExpression* expr) {
|
|
|
|
expr->set_result_type(expr->type());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-07 16:41:10 +00:00
|
|
|
bool TypeDeterminer::DetermineCall(ast::CallExpression* expr) {
|
2020-04-20 15:46:18 +00:00
|
|
|
if (!DetermineResultType(expr->params())) {
|
|
|
|
return false;
|
2020-04-20 14:18:54 +00:00
|
|
|
}
|
|
|
|
|
2020-04-20 15:46:18 +00:00
|
|
|
// The expression has to be an identifier as you can't store function pointers
|
|
|
|
// but, if it isn't we'll just use the normal result determination to be on
|
|
|
|
// the safe side.
|
|
|
|
if (expr->func()->IsIdentifier()) {
|
|
|
|
auto* ident = expr->func()->AsIdentifier();
|
|
|
|
|
2020-06-04 17:05:35 +00:00
|
|
|
if (ast::intrinsic::IsIntrinsic(ident->name())) {
|
2020-06-01 13:43:22 +00:00
|
|
|
if (!DetermineIntrinsic(ident->name(), expr))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} else if (ident->has_path()) {
|
2020-04-20 15:46:18 +00:00
|
|
|
auto* imp = mod_->FindImportByName(ident->path());
|
|
|
|
if (imp == nullptr) {
|
2020-04-21 13:05:42 +00:00
|
|
|
set_error(expr->source(), "Unable to find import for " + ident->name());
|
2020-04-20 15:46:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t ext_id = 0;
|
2020-04-21 13:05:42 +00:00
|
|
|
auto* result_type = GetImportData(expr->source(), imp->path(),
|
|
|
|
ident->name(), expr->params(), &ext_id);
|
2020-04-20 15:46:18 +00:00
|
|
|
if (result_type == nullptr) {
|
2020-04-24 00:40:12 +00:00
|
|
|
if (error_.empty()) {
|
|
|
|
set_error(expr->source(),
|
|
|
|
"Unable to determine result type for GLSL expression " +
|
|
|
|
ident->name());
|
|
|
|
}
|
2020-04-20 15:46:18 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
imp->AddMethodId(ident->name(), ext_id);
|
|
|
|
expr->func()->set_result_type(result_type);
|
|
|
|
} else {
|
|
|
|
// An identifier with a single name is a function call, not an import
|
|
|
|
// lookup which we can handle with the regular identifier lookup.
|
|
|
|
if (!DetermineResultType(ident)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!DetermineResultType(expr->func())) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-04-07 16:41:10 +00:00
|
|
|
}
|
|
|
|
expr->set_result_type(expr->func()->result_type());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-01 13:43:22 +00:00
|
|
|
bool TypeDeterminer::DetermineIntrinsic(const std::string& name,
|
|
|
|
ast::CallExpression* expr) {
|
2020-06-04 17:05:35 +00:00
|
|
|
if (ast::intrinsic::IsDerivative(name)) {
|
2020-06-01 13:43:22 +00:00
|
|
|
if (expr->params().size() != 1) {
|
|
|
|
set_error(expr->source(), "incorrect number of parameters for " + name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The result type must be the same as the type of the parameter.
|
|
|
|
auto& param = expr->params()[0];
|
|
|
|
if (!DetermineResultType(param.get())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
expr->func()->set_result_type(param->result_type()->UnwrapPtrIfNeeded());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (name == "any" || name == "all") {
|
|
|
|
expr->func()->set_result_type(
|
|
|
|
ctx_.type_mgr().Get(std::make_unique<ast::type::BoolType>()));
|
|
|
|
return true;
|
|
|
|
}
|
2020-06-04 17:05:35 +00:00
|
|
|
if (ast::intrinsic::IsFloatClassificationIntrinsic(name)) {
|
2020-06-01 13:43:22 +00:00
|
|
|
if (expr->params().size() != 1) {
|
|
|
|
set_error(expr->source(), "incorrect number of parameters for " + name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* bool_type =
|
|
|
|
ctx_.type_mgr().Get(std::make_unique<ast::type::BoolType>());
|
|
|
|
|
|
|
|
auto* param_type = expr->params()[0]->result_type()->UnwrapPtrIfNeeded();
|
|
|
|
if (param_type->IsVector()) {
|
|
|
|
expr->func()->set_result_type(
|
|
|
|
ctx_.type_mgr().Get(std::make_unique<ast::type::VectorType>(
|
|
|
|
bool_type, param_type->AsVector()->size())));
|
|
|
|
} else {
|
|
|
|
expr->func()->set_result_type(bool_type);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (name == "dot") {
|
|
|
|
expr->func()->set_result_type(
|
|
|
|
ctx_.type_mgr().Get(std::make_unique<ast::type::F32Type>()));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (name == "outer_product") {
|
|
|
|
if (expr->params().size() != 2) {
|
|
|
|
set_error(expr->source(),
|
|
|
|
"incorrect number of parameters for outer_product");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* param0_type = expr->params()[0]->result_type()->UnwrapPtrIfNeeded();
|
|
|
|
auto* param1_type = expr->params()[1]->result_type()->UnwrapPtrIfNeeded();
|
|
|
|
if (!param0_type->IsVector() || !param1_type->IsVector()) {
|
|
|
|
set_error(expr->source(), "invalid parameter type for outer_product");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
expr->func()->set_result_type(
|
|
|
|
ctx_.type_mgr().Get(std::make_unique<ast::type::MatrixType>(
|
|
|
|
ctx_.type_mgr().Get(std::make_unique<ast::type::F32Type>()),
|
|
|
|
param0_type->AsVector()->size(), param1_type->AsVector()->size())));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-07 16:41:23 +00:00
|
|
|
bool TypeDeterminer::DetermineCast(ast::CastExpression* expr) {
|
2020-05-01 19:05:55 +00:00
|
|
|
if (!DetermineResultType(expr->expr())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-07 16:41:23 +00:00
|
|
|
expr->set_result_type(expr->type());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-07 12:46:30 +00:00
|
|
|
bool TypeDeterminer::DetermineConstructor(ast::ConstructorExpression* expr) {
|
|
|
|
if (expr->IsTypeConstructor()) {
|
2020-04-24 00:41:12 +00:00
|
|
|
auto* ty = expr->AsTypeConstructor();
|
|
|
|
for (const auto& value : ty->values()) {
|
|
|
|
if (!DetermineResultType(value.get())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
expr->set_result_type(ty->type());
|
2020-04-07 12:46:30 +00:00
|
|
|
} else {
|
|
|
|
expr->set_result_type(expr->AsScalarConstructor()->literal()->type());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-07 12:57:27 +00:00
|
|
|
bool TypeDeterminer::DetermineIdentifier(ast::IdentifierExpression* expr) {
|
2020-04-20 14:21:00 +00:00
|
|
|
if (expr->has_path()) {
|
2020-04-20 15:46:18 +00:00
|
|
|
set_error(expr->source(),
|
|
|
|
"determine identifier should not be called with imports");
|
2020-04-07 12:57:27 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-20 14:21:00 +00:00
|
|
|
auto name = expr->name();
|
2020-04-07 12:57:27 +00:00
|
|
|
ast::Variable* var;
|
|
|
|
if (variable_stack_.get(name, &var)) {
|
2020-04-23 22:26:52 +00:00
|
|
|
// A constant is the type, but a variable is always a pointer so synthesize
|
|
|
|
// the pointer around the variable type.
|
|
|
|
if (var->is_const()) {
|
|
|
|
expr->set_result_type(var->type());
|
|
|
|
} else {
|
|
|
|
expr->set_result_type(
|
|
|
|
ctx_.type_mgr().Get(std::make_unique<ast::type::PointerType>(
|
|
|
|
var->type(), var->storage_class())));
|
|
|
|
}
|
2020-04-07 12:57:27 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto iter = name_to_function_.find(name);
|
|
|
|
if (iter != name_to_function_.end()) {
|
|
|
|
expr->set_result_type(iter->second->return_type());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-07 16:41:33 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TypeDeterminer::DetermineMemberAccessor(
|
|
|
|
ast::MemberAccessorExpression* expr) {
|
|
|
|
if (!DetermineResultType(expr->structure())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-23 22:26:52 +00:00
|
|
|
auto* res = expr->structure()->result_type();
|
|
|
|
auto* data_type = res->UnwrapPtrIfNeeded();
|
2020-04-24 00:40:45 +00:00
|
|
|
|
|
|
|
while (data_type->IsAlias()) {
|
|
|
|
data_type = data_type->AsAlias()->type();
|
|
|
|
}
|
|
|
|
|
2020-04-23 22:26:52 +00:00
|
|
|
ast::type::Type* ret = nullptr;
|
2020-04-07 16:41:33 +00:00
|
|
|
if (data_type->IsStruct()) {
|
2020-04-09 18:52:06 +00:00
|
|
|
auto* strct = data_type->AsStruct()->impl();
|
2020-04-20 14:21:00 +00:00
|
|
|
auto name = expr->member()->name();
|
2020-04-07 16:41:33 +00:00
|
|
|
|
|
|
|
for (const auto& member : strct->members()) {
|
2020-04-23 22:26:52 +00:00
|
|
|
if (member->name() == name) {
|
|
|
|
ret = member->type();
|
|
|
|
break;
|
2020-04-07 16:41:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-23 22:26:52 +00:00
|
|
|
if (ret == nullptr) {
|
|
|
|
set_error(expr->source(), "struct member " + name + " not found");
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-01 16:17:03 +00:00
|
|
|
|
|
|
|
// If we're extracting from a pointer, we return a pointer.
|
|
|
|
if (res->IsPointer()) {
|
|
|
|
ret = ctx_.type_mgr().Get(std::make_unique<ast::type::PointerType>(
|
|
|
|
ret, res->AsPointer()->storage_class()));
|
|
|
|
}
|
2020-04-23 22:26:52 +00:00
|
|
|
} else if (data_type->IsVector()) {
|
2020-04-09 18:52:06 +00:00
|
|
|
auto* vec = data_type->AsVector();
|
2020-04-07 16:41:33 +00:00
|
|
|
|
2020-04-21 13:05:34 +00:00
|
|
|
auto size = expr->member()->name().size();
|
|
|
|
if (size == 1) {
|
|
|
|
// A single element swizzle is just the type of the vector.
|
2020-04-23 22:26:52 +00:00
|
|
|
ret = vec->type();
|
2020-05-01 16:17:03 +00:00
|
|
|
// If we're extracting from a pointer, we return a pointer.
|
|
|
|
if (res->IsPointer()) {
|
|
|
|
ret = ctx_.type_mgr().Get(std::make_unique<ast::type::PointerType>(
|
|
|
|
ret, res->AsPointer()->storage_class()));
|
|
|
|
}
|
2020-04-21 13:05:34 +00:00
|
|
|
} else {
|
|
|
|
// The vector will have a number of components equal to the length of the
|
|
|
|
// swizzle. This assumes the validator will check that the swizzle
|
|
|
|
// is correct.
|
2020-04-23 22:26:52 +00:00
|
|
|
ret = ctx_.type_mgr().Get(
|
|
|
|
std::make_unique<ast::type::VectorType>(vec->type(), size));
|
2020-04-21 13:05:34 +00:00
|
|
|
}
|
2020-04-23 22:26:52 +00:00
|
|
|
} else {
|
|
|
|
set_error(expr->source(),
|
|
|
|
"invalid type " + data_type->type_name() + " in member accessor");
|
|
|
|
return false;
|
2020-04-07 16:41:33 +00:00
|
|
|
}
|
|
|
|
|
2020-04-23 22:26:52 +00:00
|
|
|
expr->set_result_type(ret);
|
|
|
|
|
|
|
|
return true;
|
2020-04-07 12:57:27 +00:00
|
|
|
}
|
|
|
|
|
2020-04-07 19:27:41 +00:00
|
|
|
bool TypeDeterminer::DetermineBinary(ast::BinaryExpression* expr) {
|
2020-04-07 19:26:39 +00:00
|
|
|
if (!DetermineResultType(expr->lhs()) || !DetermineResultType(expr->rhs())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Result type matches first parameter type
|
|
|
|
if (expr->IsAnd() || expr->IsOr() || expr->IsXor() || expr->IsShiftLeft() ||
|
2020-06-03 16:11:44 +00:00
|
|
|
expr->IsShiftRight() || expr->IsAdd() || expr->IsSubtract() ||
|
|
|
|
expr->IsDivide() || expr->IsModulo()) {
|
2020-04-23 22:26:52 +00:00
|
|
|
expr->set_result_type(expr->lhs()->result_type()->UnwrapPtrIfNeeded());
|
2020-04-07 19:26:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Result type is a scalar or vector of boolean type
|
|
|
|
if (expr->IsLogicalAnd() || expr->IsLogicalOr() || expr->IsEqual() ||
|
|
|
|
expr->IsNotEqual() || expr->IsLessThan() || expr->IsGreaterThan() ||
|
|
|
|
expr->IsLessThanEqual() || expr->IsGreaterThanEqual()) {
|
2020-04-09 18:52:06 +00:00
|
|
|
auto* bool_type =
|
2020-04-07 19:26:39 +00:00
|
|
|
ctx_.type_mgr().Get(std::make_unique<ast::type::BoolType>());
|
2020-04-23 22:26:52 +00:00
|
|
|
auto* param_type = expr->lhs()->result_type()->UnwrapPtrIfNeeded();
|
2020-04-07 19:26:39 +00:00
|
|
|
if (param_type->IsVector()) {
|
|
|
|
expr->set_result_type(
|
|
|
|
ctx_.type_mgr().Get(std::make_unique<ast::type::VectorType>(
|
|
|
|
bool_type, param_type->AsVector()->size())));
|
|
|
|
} else {
|
|
|
|
expr->set_result_type(bool_type);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (expr->IsMultiply()) {
|
2020-04-23 22:26:52 +00:00
|
|
|
auto* lhs_type = expr->lhs()->result_type()->UnwrapPtrIfNeeded();
|
|
|
|
auto* rhs_type = expr->rhs()->result_type()->UnwrapPtrIfNeeded();
|
2020-04-07 19:26:39 +00:00
|
|
|
|
|
|
|
// Note, the ordering here matters. The later checks depend on the prior
|
|
|
|
// checks having been done.
|
|
|
|
if (lhs_type->IsMatrix() && rhs_type->IsMatrix()) {
|
|
|
|
expr->set_result_type(
|
|
|
|
ctx_.type_mgr().Get(std::make_unique<ast::type::MatrixType>(
|
|
|
|
lhs_type->AsMatrix()->type(), lhs_type->AsMatrix()->rows(),
|
|
|
|
rhs_type->AsMatrix()->columns())));
|
|
|
|
|
|
|
|
} else if (lhs_type->IsMatrix() && rhs_type->IsVector()) {
|
2020-04-09 18:52:06 +00:00
|
|
|
auto* mat = lhs_type->AsMatrix();
|
2020-04-07 19:27:21 +00:00
|
|
|
expr->set_result_type(ctx_.type_mgr().Get(
|
|
|
|
std::make_unique<ast::type::VectorType>(mat->type(), mat->rows())));
|
2020-04-07 19:26:39 +00:00
|
|
|
} else if (lhs_type->IsVector() && rhs_type->IsMatrix()) {
|
2020-04-09 18:52:06 +00:00
|
|
|
auto* mat = rhs_type->AsMatrix();
|
2020-04-07 19:26:39 +00:00
|
|
|
expr->set_result_type(
|
|
|
|
ctx_.type_mgr().Get(std::make_unique<ast::type::VectorType>(
|
|
|
|
mat->type(), mat->columns())));
|
|
|
|
} else if (lhs_type->IsMatrix()) {
|
|
|
|
// matrix * scalar
|
|
|
|
expr->set_result_type(lhs_type);
|
|
|
|
} else if (rhs_type->IsMatrix()) {
|
|
|
|
// scalar * matrix
|
|
|
|
expr->set_result_type(rhs_type);
|
|
|
|
} else if (lhs_type->IsVector() && rhs_type->IsVector()) {
|
|
|
|
expr->set_result_type(lhs_type);
|
|
|
|
} else if (lhs_type->IsVector()) {
|
|
|
|
// Vector * scalar
|
|
|
|
expr->set_result_type(lhs_type);
|
|
|
|
} else if (rhs_type->IsVector()) {
|
|
|
|
// Scalar * vector
|
|
|
|
expr->set_result_type(rhs_type);
|
|
|
|
} else {
|
|
|
|
// Scalar * Scalar
|
|
|
|
expr->set_result_type(lhs_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-21 13:05:42 +00:00
|
|
|
set_error(expr->source(), "Unknown binary expression");
|
2020-04-07 19:26:39 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-04-07 19:27:11 +00:00
|
|
|
bool TypeDeterminer::DetermineUnaryOp(ast::UnaryOpExpression* expr) {
|
2020-04-07 19:27:21 +00:00
|
|
|
// Result type matches the parameter type.
|
|
|
|
if (!DetermineResultType(expr->expr())) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-04-23 22:26:52 +00:00
|
|
|
expr->set_result_type(expr->expr()->result_type()->UnwrapPtrIfNeeded());
|
2020-04-07 19:27:21 +00:00
|
|
|
return true;
|
2020-04-07 19:27:11 +00:00
|
|
|
}
|
|
|
|
|
2020-06-08 18:49:31 +00:00
|
|
|
// Most of these are floating-point general except the below which are only
|
|
|
|
// FP16 and FP32. We only have FP32 at this point so the below works, if we
|
|
|
|
// get FP64 support or otherwise we'll need to differentiate.
|
|
|
|
// * radians
|
|
|
|
// * degrees
|
|
|
|
// * sin, cos, tan
|
|
|
|
// * asin, acos, atan
|
|
|
|
// * sinh, cosh, tanh
|
|
|
|
// * asinh, acosh, atanh
|
|
|
|
// * exp, exp2
|
|
|
|
// * log, log2
|
|
|
|
enum class GlslDataType { kFloatScalarOrVector, kIntScalarOrVector };
|
|
|
|
struct GlslData {
|
|
|
|
const char* name;
|
|
|
|
uint8_t param_count;
|
|
|
|
uint32_t op_id;
|
|
|
|
GlslDataType type;
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr const GlslData kGlslData[] = {
|
|
|
|
{"acos", 1, GLSLstd450Acos, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"acosh", 1, GLSLstd450Acosh, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"asin", 1, GLSLstd450Asin, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"asinh", 1, GLSLstd450Asinh, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"atan", 1, GLSLstd450Atan, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"atan2", 2, GLSLstd450Atan2, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"atanh", 1, GLSLstd450Atanh, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"ceil", 1, GLSLstd450Ceil, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"cos", 1, GLSLstd450Cos, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"cosh", 1, GLSLstd450Cosh, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"degrees", 1, GLSLstd450Degrees, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"distance", 2, GLSLstd450Distance, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"exp", 1, GLSLstd450Exp, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"exp2", 1, GLSLstd450Exp2, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"fabs", 1, GLSLstd450FAbs, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"faceforward", 3, GLSLstd450FaceForward,
|
|
|
|
GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"fclamp", 3, GLSLstd450FClamp, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"floor", 1, GLSLstd450Floor, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"fma", 3, GLSLstd450Fma, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"fmax", 2, GLSLstd450FMax, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"fmin", 2, GLSLstd450FMin, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"fmix", 3, GLSLstd450FMix, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"fract", 1, GLSLstd450Fract, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"fsign", 1, GLSLstd450FSign, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"inversesqrt", 1, GLSLstd450InverseSqrt,
|
|
|
|
GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"length", 1, GLSLstd450Length, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"log", 1, GLSLstd450Log, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"log2", 1, GLSLstd450Log2, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"nclamp", 3, GLSLstd450NClamp, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"nmax", 2, GLSLstd450NMax, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"nmin", 2, GLSLstd450NMin, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"normalize", 1, GLSLstd450Normalize, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"pow", 2, GLSLstd450Pow, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"radians", 1, GLSLstd450Radians, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"reflect", 2, GLSLstd450Reflect, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"round", 1, GLSLstd450Round, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"roundeven", 1, GLSLstd450RoundEven, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"sin", 1, GLSLstd450Sin, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"sinh", 1, GLSLstd450Sinh, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"smoothstep", 3, GLSLstd450SmoothStep, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"sqrt", 1, GLSLstd450Sqrt, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"step", 2, GLSLstd450Step, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"tan", 1, GLSLstd450Tan, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"tanh", 1, GLSLstd450Tanh, GlslDataType::kFloatScalarOrVector},
|
|
|
|
{"trunc", 1, GLSLstd450Trunc, GlslDataType::kFloatScalarOrVector},
|
|
|
|
};
|
|
|
|
constexpr const uint32_t kGlslDataCount = sizeof(kGlslData) / sizeof(GlslData);
|
|
|
|
|
2020-04-20 15:46:18 +00:00
|
|
|
ast::type::Type* TypeDeterminer::GetImportData(
|
2020-04-21 13:05:42 +00:00
|
|
|
const Source& source,
|
2020-04-20 15:46:18 +00:00
|
|
|
const std::string& path,
|
|
|
|
const std::string& name,
|
|
|
|
const ast::ExpressionList& params,
|
|
|
|
uint32_t* id) {
|
|
|
|
if (path != "GLSL.std.450") {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-06-08 18:49:31 +00:00
|
|
|
const GlslData* data = nullptr;
|
|
|
|
for (uint32_t i = 0; i < kGlslDataCount; ++i) {
|
|
|
|
if (name == kGlslData[i].name) {
|
|
|
|
data = &kGlslData[i];
|
|
|
|
break;
|
2020-04-20 21:09:14 +00:00
|
|
|
}
|
2020-06-08 18:49:31 +00:00
|
|
|
}
|
|
|
|
if (data == nullptr) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-04-20 21:09:14 +00:00
|
|
|
|
2020-06-08 18:49:31 +00:00
|
|
|
if (params.size() != data->param_count) {
|
|
|
|
set_error(source, "incorrect number of parameters for " + name +
|
|
|
|
". Expected " + std::to_string(data->param_count) +
|
|
|
|
" got " + std::to_string(params.size()));
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-04-24 00:40:12 +00:00
|
|
|
|
2020-06-08 18:49:31 +00:00
|
|
|
std::vector<ast::type::Type*> result_types;
|
|
|
|
for (uint32_t i = 0; i < data->param_count; ++i) {
|
|
|
|
result_types.push_back(params[i]->result_type()->UnwrapPtrIfNeeded());
|
2020-04-21 12:55:06 +00:00
|
|
|
|
2020-06-08 18:49:31 +00:00
|
|
|
switch (data->type) {
|
|
|
|
case GlslDataType::kFloatScalarOrVector:
|
|
|
|
if (!result_types.back()->is_float_scalar_or_vector()) {
|
|
|
|
set_error(source, "incorrect type for " + name + ". " +
|
|
|
|
"Requires float scalar or float vector values");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-04-21 12:55:06 +00:00
|
|
|
|
2020-06-08 18:49:31 +00:00
|
|
|
break;
|
|
|
|
case GlslDataType::kIntScalarOrVector:
|
|
|
|
break;
|
2020-04-22 00:23:57 +00:00
|
|
|
}
|
2020-06-08 18:49:31 +00:00
|
|
|
}
|
2020-04-24 00:40:12 +00:00
|
|
|
|
2020-06-08 18:49:31 +00:00
|
|
|
// Verify all the parameter types match
|
|
|
|
for (size_t i = 1; i < data->param_count; ++i) {
|
|
|
|
if (result_types[0] != result_types[i]) {
|
2020-04-22 00:23:57 +00:00
|
|
|
error_ = "mismatched parameter types for " + name;
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-06-08 18:49:31 +00:00
|
|
|
}
|
2020-04-22 00:23:57 +00:00
|
|
|
|
2020-06-08 18:49:31 +00:00
|
|
|
*id = data->op_id;
|
2020-04-22 00:23:57 +00:00
|
|
|
|
2020-06-08 18:49:31 +00:00
|
|
|
// Handle functions which aways return the type, even if a vector is provided.
|
|
|
|
if (name == "length" || name == "distance") {
|
|
|
|
return result_types[0]->is_float_scalar()
|
|
|
|
? result_types[0]
|
|
|
|
: result_types[0]->AsVector()->type();
|
2020-04-20 15:46:18 +00:00
|
|
|
}
|
2020-06-08 18:49:31 +00:00
|
|
|
return result_types[0];
|
2020-04-20 15:46:18 +00:00
|
|
|
}
|
|
|
|
|
2020-03-02 20:47:43 +00:00
|
|
|
} // namespace tint
|