diff --git a/src/tint/writer/glsl/generator.cc b/src/tint/writer/glsl/generator.cc index 32f14aa486..fa2e0e8613 100644 --- a/src/tint/writer/glsl/generator.cc +++ b/src/tint/writer/glsl/generator.cc @@ -45,7 +45,8 @@ Result Generate(const Program* program, const Options& options, const std::strin // Generate the GLSL code. auto impl = std::make_unique(&sanitized_result.program, options.version); - result.success = impl->Generate(); + impl->Generate(); + result.success = impl->Diagnostics().empty(); result.error = impl->Diagnostics().str(); result.glsl = impl->result(); diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc index 72eb737ba8..f2c59e499f 100644 --- a/src/tint/writer/glsl/generator_impl.cc +++ b/src/tint/writer/glsl/generator_impl.cc @@ -257,7 +257,7 @@ GeneratorImpl::GeneratorImpl(const Program* program, const Version& version) GeneratorImpl::~GeneratorImpl() = default; -bool GeneratorImpl::Generate() { +void GeneratorImpl::Generate() { { auto out = line(); out << "#version " << version_.major_version << version_.minor_version << "0"; @@ -276,7 +276,7 @@ bool GeneratorImpl::Generate() { continue; // These are not emitted. } - bool ok = Switch( + Switch( decl, // [&](const ast::Variable* global) { return EmitGlobalVariable(global); }, [&](const ast::Struct* str) { @@ -288,31 +288,24 @@ bool GeneratorImpl::Generate() { bool is_block = ast::HasAttribute( str->attributes); if (!has_rt_arr && !is_block) { - if (!EmitStructType(current_buffer_, sem)) { - return false; - } + EmitStructType(current_buffer_, sem); } - return true; }, [&](const ast::Function* func) { if (func->IsEntryPoint()) { - return EmitEntryPointFunction(func); + EmitEntryPointFunction(func); + } else { + EmitFunction(func); } - return EmitFunction(func); }, [&](const ast::Enable* enable) { // Record the required extension for generating extension directive later - return RecordExtension(enable); + RecordExtension(enable); }, [&](Default) { TINT_ICE(Writer, diagnostics_) << "unhandled module-scope declaration: " << decl->TypeInfo().name; - return false; }); - - if (TINT_UNLIKELY(!ok)) { - return false; - } } TextBuffer extensions; @@ -341,43 +334,32 @@ bool GeneratorImpl::Generate() { current_buffer_->Insert(helpers_, helpers_insertion_point, indent); helpers_insertion_point += helpers_.lines.size(); } - - return true; } -bool GeneratorImpl::RecordExtension(const ast::Enable* enable) { +void GeneratorImpl::RecordExtension(const ast::Enable* enable) { // Deal with extension node here, recording it within the generator for later emition. if (enable->HasExtension(builtin::Extension::kF16)) { requires_f16_extension_ = true; } - - return true; } -bool GeneratorImpl::EmitIndexAccessor(utils::StringStream& out, +void GeneratorImpl::EmitIndexAccessor(utils::StringStream& out, const ast::IndexAccessorExpression* expr) { - if (!EmitExpression(out, expr->object)) { - return false; - } + EmitExpression(out, expr->object); out << "["; - - if (!EmitExpression(out, expr->index)) { - return false; - } + EmitExpression(out, expr->index); out << "]"; - - return true; } -bool GeneratorImpl::EmitBitcast(utils::StringStream& out, const ast::BitcastExpression* expr) { +void GeneratorImpl::EmitBitcast(utils::StringStream& out, const ast::BitcastExpression* expr) { auto* src_type = TypeOf(expr->expr)->UnwrapRef(); auto* dst_type = TypeOf(expr)->UnwrapRef(); if (!dst_type->is_integer_scalar_or_vector() && !dst_type->is_float_scalar_or_vector()) { diagnostics_.add_error(diag::System::Writer, "Unable to do bitcast to type " + dst_type->FriendlyName()); - return false; + return; } if (src_type == dst_type) { @@ -396,32 +378,21 @@ bool GeneratorImpl::EmitBitcast(utils::StringStream& out, const ast::BitcastExpr dst_type->is_float_scalar_or_vector()) { out << "uintBitsToFloat"; } else { - if (!EmitType(out, dst_type, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, - "")) { - return false; - } + EmitType(out, dst_type, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); } ScopedParen sp(out); - if (!EmitExpression(out, expr->expr)) { - return false; - } - return true; + EmitExpression(out, expr->expr); } -bool GeneratorImpl::EmitAssign(const ast::AssignmentStatement* stmt) { +void GeneratorImpl::EmitAssign(const ast::AssignmentStatement* stmt) { auto out = line(); - if (!EmitExpression(out, stmt->lhs)) { - return false; - } + EmitExpression(out, stmt->lhs); out << " = "; - if (!EmitExpression(out, stmt->rhs)) { - return false; - } + EmitExpression(out, stmt->rhs); out << ";"; - return true; } -bool GeneratorImpl::EmitVectorRelational(utils::StringStream& out, +void GeneratorImpl::EmitVectorRelational(utils::StringStream& out, const ast::BinaryExpression* expr) { switch (expr->op) { case ast::BinaryOp::kEqual: @@ -446,37 +417,24 @@ bool GeneratorImpl::EmitVectorRelational(utils::StringStream& out, break; } ScopedParen sp(out); - if (!EmitExpression(out, expr->lhs)) { - return false; - } + EmitExpression(out, expr->lhs); out << ", "; - if (!EmitExpression(out, expr->rhs)) { - return false; - } - return true; + EmitExpression(out, expr->rhs); } -bool GeneratorImpl::EmitBitwiseBoolOp(utils::StringStream& out, const ast::BinaryExpression* expr) { +void GeneratorImpl::EmitBitwiseBoolOp(utils::StringStream& out, const ast::BinaryExpression* expr) { auto* bool_type = TypeOf(expr->lhs)->UnwrapRef(); auto* uint_type = BoolTypeToUint(bool_type); // Cast result to bool scalar or vector type. - if (!EmitType(out, bool_type, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, - "")) { - return false; - } + EmitType(out, bool_type, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); ScopedParen outerCastParen(out); // Cast LHS to uint scalar or vector type. - if (!EmitType(out, uint_type, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, - "")) { - return false; - } + EmitType(out, uint_type, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); { ScopedParen innerCastParen(out); // Emit LHS. - if (!EmitExpression(out, expr->lhs)) { - return false; - } + EmitExpression(out, expr->lhs); } // Emit operator. if (expr->op == ast::BinaryOp::kAnd) { @@ -485,98 +443,78 @@ bool GeneratorImpl::EmitBitwiseBoolOp(utils::StringStream& out, const ast::Binar out << " | "; } else { TINT_ICE(Writer, diagnostics_) << "unexpected binary op: " << FriendlyName(expr->op); - return false; + return; } + // Cast RHS to uint scalar or vector type. - if (!EmitType(out, uint_type, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, - "")) { - return false; - } + EmitType(out, uint_type, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); { ScopedParen innerCastParen(out); // Emit RHS. - if (!EmitExpression(out, expr->rhs)) { - return false; - } + EmitExpression(out, expr->rhs); } - return true; } -bool GeneratorImpl::EmitFloatModulo(utils::StringStream& out, const ast::BinaryExpression* expr) { +void GeneratorImpl::EmitFloatModulo(utils::StringStream& out, const ast::BinaryExpression* expr) { std::string fn; auto* ret_ty = TypeOf(expr)->UnwrapRef(); auto* lhs_ty = TypeOf(expr->lhs)->UnwrapRef(); auto* rhs_ty = TypeOf(expr->rhs)->UnwrapRef(); - fn = utils::GetOrCreate( - float_modulo_funcs_, BinaryOperandType{{lhs_ty, rhs_ty}}, [&]() -> std::string { - TextBuffer b; - TINT_DEFER(helpers_.Append(b)); + fn = utils::GetOrCreate(float_modulo_funcs_, BinaryOperandType{{lhs_ty, rhs_ty}}, + [&]() -> std::string { + TextBuffer b; + TINT_DEFER(helpers_.Append(b)); - auto fn_name = UniqueIdentifier("tint_float_modulo"); - std::vector parameter_names; - { - auto decl = line(&b); - if (!EmitTypeAndName(decl, ret_ty, builtin::AddressSpace::kUndefined, - builtin::Access::kUndefined, fn_name)) { - return ""; - } - { - ScopedParen sp(decl); - const auto* ty = TypeOf(expr->lhs)->UnwrapRef(); - if (!EmitTypeAndName(decl, ty, builtin::AddressSpace::kUndefined, - builtin::Access::kUndefined, "lhs")) { - return ""; - } - decl << ", "; - ty = TypeOf(expr->rhs)->UnwrapRef(); - if (!EmitTypeAndName(decl, ty, builtin::AddressSpace::kUndefined, - builtin::Access::kUndefined, "rhs")) { - return ""; - } - } - decl << " {"; - } - { - ScopedIndent si(&b); - line(&b) << "return (lhs - rhs * trunc(lhs / rhs));"; - } - line(&b) << "}"; - line(&b); - return fn_name; - }); - - if (fn.empty()) { - return false; - } + auto fn_name = UniqueIdentifier("tint_float_modulo"); + std::vector parameter_names; + { + auto decl = line(&b); + EmitTypeAndName(decl, ret_ty, builtin::AddressSpace::kUndefined, + builtin::Access::kUndefined, fn_name); + { + ScopedParen sp(decl); + const auto* ty = TypeOf(expr->lhs)->UnwrapRef(); + EmitTypeAndName(decl, ty, builtin::AddressSpace::kUndefined, + builtin::Access::kUndefined, "lhs"); + decl << ", "; + ty = TypeOf(expr->rhs)->UnwrapRef(); + EmitTypeAndName(decl, ty, builtin::AddressSpace::kUndefined, + builtin::Access::kUndefined, "rhs"); + } + decl << " {"; + } + { + ScopedIndent si(&b); + line(&b) << "return (lhs - rhs * trunc(lhs / rhs));"; + } + line(&b) << "}"; + line(&b); + return fn_name; + }); // Call the helper out << fn; { ScopedParen sp(out); - if (!EmitExpression(out, expr->lhs)) { - return false; - } + EmitExpression(out, expr->lhs); out << ", "; - if (!EmitExpression(out, expr->rhs)) { - return false; - } + EmitExpression(out, expr->rhs); } - return true; } -bool GeneratorImpl::EmitBinary(utils::StringStream& out, const ast::BinaryExpression* expr) { +void GeneratorImpl::EmitBinary(utils::StringStream& out, const ast::BinaryExpression* expr) { if (IsRelational(expr->op) && !TypeOf(expr->lhs)->UnwrapRef()->is_scalar()) { - return EmitVectorRelational(out, expr); + EmitVectorRelational(out, expr); + return; } + if (expr->op == ast::BinaryOp::kLogicalAnd || expr->op == ast::BinaryOp::kLogicalOr) { auto name = UniqueIdentifier(kTempNamePrefix); { auto pre = line(); pre << "bool " << name << " = "; - if (!EmitExpression(pre, expr->lhs)) { - return false; - } + EmitExpression(pre, expr->lhs); pre << ";"; } @@ -590,32 +528,31 @@ bool GeneratorImpl::EmitBinary(utils::StringStream& out, const ast::BinaryExpres ScopedIndent si(this); auto pre = line(); pre << name << " = "; - if (!EmitExpression(pre, expr->rhs)) { - return false; - } + EmitExpression(pre, expr->rhs); pre << ";"; } line() << "}"; out << "(" << name << ")"; - return true; + return; } + if ((expr->op == ast::BinaryOp::kAnd || expr->op == ast::BinaryOp::kOr) && TypeOf(expr->lhs)->UnwrapRef()->is_bool_scalar_or_vector()) { - return EmitBitwiseBoolOp(out, expr); + EmitBitwiseBoolOp(out, expr); + return; } if (expr->op == ast::BinaryOp::kModulo && (TypeOf(expr->lhs)->UnwrapRef()->is_float_scalar_or_vector() || TypeOf(expr->rhs)->UnwrapRef()->is_float_scalar_or_vector())) { - return EmitFloatModulo(out, expr); + EmitFloatModulo(out, expr); + return; } ScopedParen sp(out); - if (!EmitExpression(out, expr->lhs)) { - return false; - } + EmitExpression(out, expr->lhs); out << " "; switch (expr->op) { @@ -632,7 +569,7 @@ bool GeneratorImpl::EmitBinary(utils::StringStream& out, const ast::BinaryExpres case ast::BinaryOp::kLogicalOr: { // These are both handled above. TINT_UNREACHABLE(Writer, diagnostics_); - return false; + return; } case ast::BinaryOp::kEqual: out << "=="; @@ -656,10 +593,6 @@ bool GeneratorImpl::EmitBinary(utils::StringStream& out, const ast::BinaryExpres out << "<<"; break; case ast::BinaryOp::kShiftRight: - // TODO(dsinclair): MSL is based on C++14, and >> in C++14 has - // implementation-defined behaviour for negative LHS. We may have to - // generate extra code to implement WGSL-specified behaviour for negative - // LHS. out << R"(>>)"; break; @@ -680,71 +613,55 @@ bool GeneratorImpl::EmitBinary(utils::StringStream& out, const ast::BinaryExpres break; case ast::BinaryOp::kNone: diagnostics_.add_error(diag::System::Writer, "missing binary operation type"); - return false; + return; } out << " "; - - if (!EmitExpression(out, expr->rhs)) { - return false; - } - - return true; + EmitExpression(out, expr->rhs); } -bool GeneratorImpl::EmitStatements(utils::VectorRef stmts) { +void GeneratorImpl::EmitStatements(utils::VectorRef stmts) { for (auto* s : stmts) { - if (!EmitStatement(s)) { - return false; - } + EmitStatement(s); } - return true; } -bool GeneratorImpl::EmitStatementsWithIndent(utils::VectorRef stmts) { +void GeneratorImpl::EmitStatementsWithIndent(utils::VectorRef stmts) { ScopedIndent si(this); - return EmitStatements(stmts); + EmitStatements(stmts); } -bool GeneratorImpl::EmitBlock(const ast::BlockStatement* stmt) { +void GeneratorImpl::EmitBlock(const ast::BlockStatement* stmt) { line() << "{"; - if (!EmitStatementsWithIndent(stmt->statements)) { - return false; - } + EmitStatementsWithIndent(stmt->statements); line() << "}"; - return true; } -bool GeneratorImpl::EmitBreak(const ast::BreakStatement*) { +void GeneratorImpl::EmitBreak(const ast::BreakStatement*) { line() << "break;"; - return true; } -bool GeneratorImpl::EmitBreakIf(const ast::BreakIfStatement* b) { +void GeneratorImpl::EmitBreakIf(const ast::BreakIfStatement* b) { auto out = line(); out << "if ("; - if (!EmitExpression(out, b->condition)) { - return false; - } + EmitExpression(out, b->condition); out << ") { break; }"; - return true; } -bool GeneratorImpl::EmitCall(utils::StringStream& out, const ast::CallExpression* expr) { +void GeneratorImpl::EmitCall(utils::StringStream& out, const ast::CallExpression* expr) { auto* call = builder_.Sem().Get(expr); - return Switch( + Switch( call->Target(), // - [&](const sem::Function* fn) { return EmitFunctionCall(out, call, fn); }, - [&](const sem::Builtin* builtin) { return EmitBuiltinCall(out, call, builtin); }, - [&](const sem::ValueConversion* conv) { return EmitValueConversion(out, call, conv); }, - [&](const sem::ValueConstructor* ctor) { return EmitValueConstructor(out, call, ctor); }, + [&](const sem::Function* fn) { EmitFunctionCall(out, call, fn); }, + [&](const sem::Builtin* builtin) { EmitBuiltinCall(out, call, builtin); }, + [&](const sem::ValueConversion* conv) { EmitValueConversion(out, call, conv); }, + [&](const sem::ValueConstructor* ctor) { EmitValueConstructor(out, call, ctor); }, [&](Default) { TINT_ICE(Writer, diagnostics_) << "unhandled call target: " << call->Target()->TypeInfo().name; - return false; }); } -bool GeneratorImpl::EmitFunctionCall(utils::StringStream& out, +void GeneratorImpl::EmitFunctionCall(utils::StringStream& out, const sem::Call* call, const sem::Function* fn) { const auto& args = call->Arguments(); @@ -760,114 +677,84 @@ bool GeneratorImpl::EmitFunctionCall(utils::StringStream& out, } first = false; - if (!EmitExpression(out, arg->Declaration())) { - return false; - } + EmitExpression(out, arg->Declaration()); } - - return true; } -bool GeneratorImpl::EmitBuiltinCall(utils::StringStream& out, +void GeneratorImpl::EmitBuiltinCall(utils::StringStream& out, const sem::Call* call, const sem::Builtin* builtin) { auto* expr = call->Declaration(); if (builtin->IsTexture()) { - return EmitTextureCall(out, call, builtin); - } - if (builtin->Type() == builtin::Function::kCountOneBits) { - return EmitCountOneBitsCall(out, expr); - } - if (builtin->Type() == builtin::Function::kSelect) { - return EmitSelectCall(out, expr, builtin); - } - if (builtin->Type() == builtin::Function::kDot) { - return EmitDotCall(out, expr, builtin); - } - if (builtin->Type() == builtin::Function::kModf) { - return EmitModfCall(out, expr, builtin); - } - if (builtin->Type() == builtin::Function::kFrexp) { - return EmitFrexpCall(out, expr, builtin); - } - if (builtin->Type() == builtin::Function::kDegrees) { - return EmitDegreesCall(out, expr, builtin); - } - if (builtin->Type() == builtin::Function::kRadians) { - return EmitRadiansCall(out, expr, builtin); - } - if (builtin->Type() == builtin::Function::kQuantizeToF16) { - return EmitQuantizeToF16Call(out, expr, builtin); - } - if (builtin->Type() == builtin::Function::kArrayLength) { - return EmitArrayLength(out, expr); - } - if (builtin->Type() == builtin::Function::kExtractBits) { - return EmitExtractBits(out, expr); - } - if (builtin->Type() == builtin::Function::kInsertBits) { - return EmitInsertBits(out, expr); - } - if (builtin->Type() == builtin::Function::kFma && version_.IsES()) { - return EmitEmulatedFMA(out, expr); - } - if (builtin->Type() == builtin::Function::kAbs && - TypeOf(expr->args[0])->UnwrapRef()->is_unsigned_integer_scalar_or_vector()) { + EmitTextureCall(out, call, builtin); + } else if (builtin->Type() == builtin::Function::kCountOneBits) { + EmitCountOneBitsCall(out, expr); + } else if (builtin->Type() == builtin::Function::kSelect) { + EmitSelectCall(out, expr, builtin); + } else if (builtin->Type() == builtin::Function::kDot) { + EmitDotCall(out, expr, builtin); + } else if (builtin->Type() == builtin::Function::kModf) { + EmitModfCall(out, expr, builtin); + } else if (builtin->Type() == builtin::Function::kFrexp) { + EmitFrexpCall(out, expr, builtin); + } else if (builtin->Type() == builtin::Function::kDegrees) { + EmitDegreesCall(out, expr, builtin); + } else if (builtin->Type() == builtin::Function::kRadians) { + EmitRadiansCall(out, expr, builtin); + } else if (builtin->Type() == builtin::Function::kQuantizeToF16) { + EmitQuantizeToF16Call(out, expr, builtin); + } else if (builtin->Type() == builtin::Function::kArrayLength) { + EmitArrayLength(out, expr); + } else if (builtin->Type() == builtin::Function::kExtractBits) { + EmitExtractBits(out, expr); + } else if (builtin->Type() == builtin::Function::kInsertBits) { + EmitInsertBits(out, expr); + } else if (builtin->Type() == builtin::Function::kFma && version_.IsES()) { + EmitEmulatedFMA(out, expr); + } else if (builtin->Type() == builtin::Function::kAbs && + TypeOf(expr->args[0])->UnwrapRef()->is_unsigned_integer_scalar_or_vector()) { // GLSL does not support abs() on unsigned arguments. However, it's a no-op. - return EmitExpression(out, expr->args[0]); - } - if ((builtin->Type() == builtin::Function::kAny || - builtin->Type() == builtin::Function::kAll) && - TypeOf(expr->args[0])->UnwrapRef()->is_scalar()) { + EmitExpression(out, expr->args[0]); + } else if ((builtin->Type() == builtin::Function::kAny || + builtin->Type() == builtin::Function::kAll) && + TypeOf(expr->args[0])->UnwrapRef()->is_scalar()) { // GLSL does not support any() or all() on scalar arguments. It's a no-op. - return EmitExpression(out, expr->args[0]); - } - if (builtin->IsBarrier()) { - return EmitBarrierCall(out, builtin); - } - if (builtin->IsAtomic()) { - return EmitWorkgroupAtomicCall(out, expr, builtin); - } - auto name = generate_builtin_name(builtin); - if (name.empty()) { - return false; - } - - out << name; - ScopedParen sp(out); - - bool first = true; - for (auto* arg : call->Arguments()) { - if (!first) { - out << ", "; + EmitExpression(out, expr->args[0]); + } else if (builtin->IsBarrier()) { + EmitBarrierCall(out, builtin); + } else if (builtin->IsAtomic()) { + EmitWorkgroupAtomicCall(out, expr, builtin); + } else { + auto name = generate_builtin_name(builtin); + if (name.empty()) { + return; } - first = false; - if (!EmitExpression(out, arg->Declaration())) { - return false; + out << name; + ScopedParen sp(out); + + bool first = true; + for (auto* arg : call->Arguments()) { + if (!first) { + out << ", "; + } + first = false; + + EmitExpression(out, arg->Declaration()); } } - - return true; } -bool GeneratorImpl::EmitValueConversion(utils::StringStream& out, +void GeneratorImpl::EmitValueConversion(utils::StringStream& out, const sem::Call* call, const sem::ValueConversion* conv) { - if (!EmitType(out, conv->Target(), builtin::AddressSpace::kUndefined, - builtin::Access::kReadWrite, "")) { - return false; - } + EmitType(out, conv->Target(), builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, + ""); ScopedParen sp(out); - - if (!EmitExpression(out, call->Arguments()[0]->Declaration())) { - return false; - } - - return true; + EmitExpression(out, call->Arguments()[0]->Declaration()); } -bool GeneratorImpl::EmitValueConstructor(utils::StringStream& out, +void GeneratorImpl::EmitValueConstructor(utils::StringStream& out, const sem::Call* call, const sem::ValueConstructor* ctor) { auto* type = ctor->ReturnType(); @@ -875,12 +762,11 @@ bool GeneratorImpl::EmitValueConstructor(utils::StringStream& out, // If the value constructor is empty then we need to construct with the zero value for all // components. if (call->Arguments().IsEmpty()) { - return EmitZeroValue(out, type); + EmitZeroValue(out, type); + return; } - if (!EmitType(out, type, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, "")) { - return false; - } + EmitType(out, type, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); ScopedParen sp(out); bool first = true; @@ -890,15 +776,11 @@ bool GeneratorImpl::EmitValueConstructor(utils::StringStream& out, } first = false; - if (!EmitExpression(out, arg->Declaration())) { - return false; - } + EmitExpression(out, arg->Declaration()); } - - return true; } -bool GeneratorImpl::EmitWorkgroupAtomicCall(utils::StringStream& out, +void GeneratorImpl::EmitWorkgroupAtomicCall(utils::StringStream& out, const ast::CallExpression* expr, const sem::Builtin* builtin) { auto call = [&](const char* name) { @@ -910,12 +792,10 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(utils::StringStream& out, if (i > 0) { out << ", "; } - if (!EmitExpression(out, arg)) { - return false; - } + EmitExpression(out, arg); } } - return true; + return; }; switch (builtin->Type()) { @@ -925,20 +805,16 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(utils::StringStream& out, out << "atomicOr"; { ScopedParen sp(out); - if (!EmitExpression(out, expr->args[0])) { - return false; - } + EmitExpression(out, expr->args[0]); out << ", 0"; if (builtin->ReturnType()->Is()) { out << "u"; } } - return true; + return; } case builtin::Function::kAtomicCompareExchangeWeak: { - if (!EmitStructType(&helpers_, builtin->ReturnType()->As())) { - return false; - } + EmitStructType(&helpers_, builtin->ReturnType()->As()); auto* dest = expr->args[0]; auto* compare_value = expr->args[1]; @@ -948,10 +824,8 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(utils::StringStream& out, { auto pre = line(); - if (!EmitTypeAndName(pre, builtin->ReturnType(), builtin::AddressSpace::kUndefined, - builtin::Access::kUndefined, result)) { - return false; - } + EmitTypeAndName(pre, builtin->ReturnType(), builtin::AddressSpace::kUndefined, + builtin::Access::kUndefined, result); pre << ";"; } { @@ -959,174 +833,138 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(utils::StringStream& out, pre << result << ".old_value = atomicCompSwap"; { ScopedParen sp(pre); - if (!EmitExpression(pre, dest)) { - return false; - } + EmitExpression(pre, dest); pre << ", "; - if (!EmitExpression(pre, compare_value)) { - return false; - } + EmitExpression(pre, compare_value); pre << ", "; - if (!EmitExpression(pre, value)) { - return false; - } + EmitExpression(pre, value); } pre << ";"; } { auto pre = line(); pre << result << ".exchanged = " << result << ".old_value == "; - if (!EmitExpression(pre, compare_value)) { - return false; - } + EmitExpression(pre, compare_value); pre << ";"; } out << result; - return true; + return; } case builtin::Function::kAtomicAdd: case builtin::Function::kAtomicSub: - return call("atomicAdd"); + call("atomicAdd"); + return; case builtin::Function::kAtomicMax: - return call("atomicMax"); + call("atomicMax"); + return; case builtin::Function::kAtomicMin: - return call("atomicMin"); + call("atomicMin"); + return; case builtin::Function::kAtomicAnd: - return call("atomicAnd"); + call("atomicAnd"); + return; case builtin::Function::kAtomicOr: - return call("atomicOr"); + call("atomicOr"); + return; case builtin::Function::kAtomicXor: - return call("atomicXor"); + call("atomicXor"); + return; case builtin::Function::kAtomicExchange: case builtin::Function::kAtomicStore: // GLSL does not have an atomicStore, so we emulate it with // atomicExchange. - return call("atomicExchange"); + call("atomicExchange"); + return; default: break; } TINT_UNREACHABLE(Writer, diagnostics_) << "unsupported atomic builtin: " << builtin->Type(); - return false; } -bool GeneratorImpl::EmitArrayLength(utils::StringStream& out, const ast::CallExpression* expr) { +void GeneratorImpl::EmitArrayLength(utils::StringStream& out, const ast::CallExpression* expr) { out << "uint("; - if (!EmitExpression(out, expr->args[0])) { - return false; - } + EmitExpression(out, expr->args[0]); out << ".length())"; - return true; } -bool GeneratorImpl::EmitExtractBits(utils::StringStream& out, const ast::CallExpression* expr) { +void GeneratorImpl::EmitExtractBits(utils::StringStream& out, const ast::CallExpression* expr) { out << "bitfieldExtract("; - if (!EmitExpression(out, expr->args[0])) { - return false; - } + EmitExpression(out, expr->args[0]); out << ", int("; - if (!EmitExpression(out, expr->args[1])) { - return false; - } + EmitExpression(out, expr->args[1]); out << "), int("; - if (!EmitExpression(out, expr->args[2])) { - return false; - } + EmitExpression(out, expr->args[2]); out << "))"; - return true; } -bool GeneratorImpl::EmitInsertBits(utils::StringStream& out, const ast::CallExpression* expr) { +void GeneratorImpl::EmitInsertBits(utils::StringStream& out, const ast::CallExpression* expr) { out << "bitfieldInsert("; - if (!EmitExpression(out, expr->args[0])) { - return false; - } + EmitExpression(out, expr->args[0]); out << ", "; - if (!EmitExpression(out, expr->args[1])) { - return false; - } + EmitExpression(out, expr->args[1]); out << ", int("; - if (!EmitExpression(out, expr->args[2])) { - return false; - } + EmitExpression(out, expr->args[2]); out << "), int("; - if (!EmitExpression(out, expr->args[3])) { - return false; - } + EmitExpression(out, expr->args[3]); out << "))"; - return true; } -bool GeneratorImpl::EmitEmulatedFMA(utils::StringStream& out, const ast::CallExpression* expr) { +void GeneratorImpl::EmitEmulatedFMA(utils::StringStream& out, const ast::CallExpression* expr) { out << "(("; - if (!EmitExpression(out, expr->args[0])) { - return false; - } + EmitExpression(out, expr->args[0]); out << ") * ("; - if (!EmitExpression(out, expr->args[1])) { - return false; - } + EmitExpression(out, expr->args[1]); out << ") + ("; - if (!EmitExpression(out, expr->args[2])) { - return false; - } + EmitExpression(out, expr->args[2]); out << "))"; - return true; } -bool GeneratorImpl::EmitCountOneBitsCall(utils::StringStream& out, +void GeneratorImpl::EmitCountOneBitsCall(utils::StringStream& out, const ast::CallExpression* expr) { // GLSL's bitCount returns an integer type, so cast it to the appropriate // unsigned type. - if (!EmitType(out, TypeOf(expr)->UnwrapRef(), builtin::AddressSpace::kUndefined, - builtin::Access::kReadWrite, "")) { - return false; - } + EmitType(out, TypeOf(expr)->UnwrapRef(), builtin::AddressSpace::kUndefined, + builtin::Access::kReadWrite, ""); out << "(bitCount("; - - if (!EmitExpression(out, expr->args[0])) { - return false; - } + EmitExpression(out, expr->args[0]); out << "))"; - return true; } -bool GeneratorImpl::EmitSelectCall(utils::StringStream& out, +void GeneratorImpl::EmitSelectCall(utils::StringStream& out, const ast::CallExpression* expr, const sem::Builtin* builtin) { // GLSL does not support ternary expressions with a bool vector conditional, // so polyfill with a helper. if (auto* vec = builtin->Parameters()[2]->Type()->As()) { - return CallBuiltinHelper( - out, expr, builtin, [&](TextBuffer* b, const std::vector& params) { - auto l = line(b); - l << " return "; - if (!EmitType(l, builtin->ReturnType(), builtin::AddressSpace::kUndefined, - builtin::Access::kUndefined, "")) { - return false; - } - { - ScopedParen sp(l); - for (uint32_t i = 0; i < vec->Width(); i++) { - if (i > 0) { - l << ", "; - } - l << params[2] << "[" << i << "] ? " << params[1] << "[" << i - << "] : " << params[0] << "[" << i << "]"; - } - } - l << ";"; - return true; - }); + CallBuiltinHelper(out, expr, builtin, + [&](TextBuffer* b, const std::vector& params) { + auto l = line(b); + l << " return "; + EmitType(l, builtin->ReturnType(), builtin::AddressSpace::kUndefined, + builtin::Access::kUndefined, ""); + { + ScopedParen sp(l); + for (uint32_t i = 0; i < vec->Width(); i++) { + if (i > 0) { + l << ", "; + } + l << params[2] << "[" << i << "] ? " << params[1] << "[" << i + << "] : " << params[0] << "[" << i << "]"; + } + } + l << ";"; + }); + return; } auto* expr_false = expr->args[0]; @@ -1134,26 +972,15 @@ bool GeneratorImpl::EmitSelectCall(utils::StringStream& out, auto* expr_cond = expr->args[2]; ScopedParen paren(out); - if (!EmitExpression(out, expr_cond)) { - return false; - } + EmitExpression(out, expr_cond); out << " ? "; - - if (!EmitExpression(out, expr_true)) { - return false; - } - + EmitExpression(out, expr_true); out << " : "; - - if (!EmitExpression(out, expr_false)) { - return false; - } - - return true; + EmitExpression(out, expr_false); } -bool GeneratorImpl::EmitDotCall(utils::StringStream& out, +void GeneratorImpl::EmitDotCall(utils::StringStream& out, const ast::CallExpression* expr, const sem::Builtin* builtin) { auto* vec_ty = builtin->Parameters()[0]->Type()->As(); @@ -1170,28 +997,18 @@ bool GeneratorImpl::EmitDotCall(utils::StringStream& out, std::string v; { utils::StringStream s; - if (!EmitType(s, vec_ty->type(), builtin::AddressSpace::kUndefined, - builtin::Access::kRead, "")) { - return ""; - } + EmitType(s, vec_ty->type(), builtin::AddressSpace::kUndefined, + builtin::Access::kRead, ""); v = s.str(); } { // (u)int tint_int_dot([i|u]vecN a, [i|u]vecN b) { auto l = line(&b); - if (!EmitType(l, vec_ty->type(), builtin::AddressSpace::kUndefined, - builtin::Access::kRead, "")) { - return ""; - } + EmitType(l, vec_ty->type(), builtin::AddressSpace::kUndefined, + builtin::Access::kRead, ""); l << " " << fn_name << "("; - if (!EmitType(l, vec_ty, builtin::AddressSpace::kUndefined, builtin::Access::kRead, - "")) { - return ""; - } + EmitType(l, vec_ty, builtin::AddressSpace::kUndefined, builtin::Access::kRead, ""); l << " a, "; - if (!EmitType(l, vec_ty, builtin::AddressSpace::kUndefined, builtin::Access::kRead, - "")) { - return ""; - } + EmitType(l, vec_ty, builtin::AddressSpace::kUndefined, builtin::Access::kRead, ""); l << " b) {"; } { @@ -1208,135 +1025,114 @@ bool GeneratorImpl::EmitDotCall(utils::StringStream& out, line(&b) << "}"; return fn_name; }); - if (fn.empty()) { - return false; - } } out << fn; ScopedParen sp(out); - if (!EmitExpression(out, expr->args[0])) { - return false; - } + EmitExpression(out, expr->args[0]); out << ", "; - if (!EmitExpression(out, expr->args[1])) { - return false; - } - return true; + EmitExpression(out, expr->args[1]); } -bool GeneratorImpl::EmitModfCall(utils::StringStream& out, +void GeneratorImpl::EmitModfCall(utils::StringStream& out, const ast::CallExpression* expr, const sem::Builtin* builtin) { TINT_ASSERT(Writer, expr->args.Length() == 1); - return CallBuiltinHelper( - out, expr, builtin, [&](TextBuffer* b, const std::vector& params) { - // Emit the builtin return type unique to this overload. This does not - // exist in the AST, so it will not be generated in Generate(). - if (!EmitStructType(&helpers_, builtin->ReturnType()->As())) { - return false; - } + CallBuiltinHelper(out, expr, builtin, + [&](TextBuffer* b, const std::vector& params) { + // Emit the builtin return type unique to this overload. This does not + // exist in the AST, so it will not be generated in Generate(). + EmitStructType(&helpers_, builtin->ReturnType()->As()); - { - auto l = line(b); - if (!EmitType(l, builtin->ReturnType(), builtin::AddressSpace::kUndefined, - builtin::Access::kUndefined, "")) { - return false; - } - l << " result;"; - } - line(b) << "result.fract = modf(" << params[0] << ", result.whole);"; - line(b) << "return result;"; - return true; - }); + { + auto l = line(b); + EmitType(l, builtin->ReturnType(), builtin::AddressSpace::kUndefined, + builtin::Access::kUndefined, ""); + l << " result;"; + } + line(b) << "result.fract = modf(" << params[0] << ", result.whole);"; + line(b) << "return result;"; + }); } -bool GeneratorImpl::EmitFrexpCall(utils::StringStream& out, +void GeneratorImpl::EmitFrexpCall(utils::StringStream& out, const ast::CallExpression* expr, const sem::Builtin* builtin) { TINT_ASSERT(Writer, expr->args.Length() == 1); - return CallBuiltinHelper( - out, expr, builtin, [&](TextBuffer* b, const std::vector& params) { - // Emit the builtin return type unique to this overload. This does not - // exist in the AST, so it will not be generated in Generate(). - if (!EmitStructType(&helpers_, builtin->ReturnType()->As())) { - return false; - } + CallBuiltinHelper(out, expr, builtin, + [&](TextBuffer* b, const std::vector& params) { + // Emit the builtin return type unique to this overload. This does not + // exist in the AST, so it will not be generated in Generate(). + EmitStructType(&helpers_, builtin->ReturnType()->As()); - { - auto l = line(b); - if (!EmitType(l, builtin->ReturnType(), builtin::AddressSpace::kUndefined, - builtin::Access::kUndefined, "")) { - return false; - } - l << " result;"; - } - line(b) << "result.fract = frexp(" << params[0] << ", result.exp);"; - line(b) << "return result;"; - return true; - }); + { + auto l = line(b); + EmitType(l, builtin->ReturnType(), builtin::AddressSpace::kUndefined, + builtin::Access::kUndefined, ""); + l << " result;"; + } + line(b) << "result.fract = frexp(" << params[0] << ", result.exp);"; + line(b) << "return result;"; + }); } -bool GeneratorImpl::EmitDegreesCall(utils::StringStream& out, +void GeneratorImpl::EmitDegreesCall(utils::StringStream& out, const ast::CallExpression* expr, const sem::Builtin* builtin) { auto* return_elem_type = type::Type::DeepestElementOf(builtin->ReturnType()); const std::string suffix = Is(return_elem_type) ? "hf" : "f"; - return CallBuiltinHelper(out, expr, builtin, - [&](TextBuffer* b, const std::vector& params) { - line(b) << "return " << params[0] << " * " << std::setprecision(20) - << sem::kRadToDeg << suffix << ";"; - return true; - }); + CallBuiltinHelper(out, expr, builtin, + [&](TextBuffer* b, const std::vector& params) { + line(b) << "return " << params[0] << " * " << std::setprecision(20) + << sem::kRadToDeg << suffix << ";"; + }); } -bool GeneratorImpl::EmitRadiansCall(utils::StringStream& out, +void GeneratorImpl::EmitRadiansCall(utils::StringStream& out, const ast::CallExpression* expr, const sem::Builtin* builtin) { auto* return_elem_type = type::Type::DeepestElementOf(builtin->ReturnType()); const std::string suffix = Is(return_elem_type) ? "hf" : "f"; - return CallBuiltinHelper(out, expr, builtin, - [&](TextBuffer* b, const std::vector& params) { - line(b) << "return " << params[0] << " * " << std::setprecision(20) - << sem::kDegToRad << suffix << ";"; - return true; - }); + CallBuiltinHelper(out, expr, builtin, + [&](TextBuffer* b, const std::vector& params) { + line(b) << "return " << params[0] << " * " << std::setprecision(20) + << sem::kDegToRad << suffix << ";"; + }); } -bool GeneratorImpl::EmitQuantizeToF16Call(utils::StringStream& out, +void GeneratorImpl::EmitQuantizeToF16Call(utils::StringStream& out, const ast::CallExpression* expr, const sem::Builtin* builtin) { // Emulate by casting to f16 and back again. - return CallBuiltinHelper( + CallBuiltinHelper( out, expr, builtin, [&](TextBuffer* b, const std::vector& params) { const auto v = params[0]; if (auto* vec = builtin->ReturnType()->As()) { switch (vec->Width()) { case 2: { line(b) << "return unpackHalf2x16(packHalf2x16(" << v << "));"; - return true; + return; } case 3: { line(b) << "return vec3("; line(b) << " unpackHalf2x16(packHalf2x16(" << v << ".xy)),"; line(b) << " unpackHalf2x16(packHalf2x16(" << v << ".zz)).x);"; - return true; + return; } default: { line(b) << "return vec4("; line(b) << " unpackHalf2x16(packHalf2x16(" << v << ".xy)),"; line(b) << " unpackHalf2x16(packHalf2x16(" << v << ".zw)));"; - return true; + return; } } } line(b) << "return unpackHalf2x16(packHalf2x16(vec2(" << v << "))).x;"; - return true; }); } -bool GeneratorImpl::EmitBarrierCall(utils::StringStream& out, const sem::Builtin* builtin) { +void GeneratorImpl::EmitBarrierCall(utils::StringStream& out, const sem::Builtin* builtin) { // TODO(crbug.com/tint/661): Combine sequential barriers to a single // instruction. if (builtin->Type() == builtin::Function::kWorkgroupBarrier) { @@ -1346,9 +1142,7 @@ bool GeneratorImpl::EmitBarrierCall(utils::StringStream& out, const sem::Builtin } else { TINT_UNREACHABLE(Writer, diagnostics_) << "unexpected barrier builtin type " << builtin::str(builtin->Type()); - return false; } - return true; } const ast::Expression* GeneratorImpl::CreateF32Zero(const sem::Statement* stmt) { @@ -1361,7 +1155,7 @@ const ast::Expression* GeneratorImpl::CreateF32Zero(const sem::Statement* stmt) return zero; } -bool GeneratorImpl::EmitTextureCall(utils::StringStream& out, +void GeneratorImpl::EmitTextureCall(utils::StringStream& out, const sem::Call* call, const sem::Builtin* builtin) { using Usage = sem::ParameterUsage; @@ -1379,7 +1173,7 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out, auto* texture = arg(Usage::kTexture); if (TINT_UNLIKELY(!texture)) { TINT_ICE(Writer, diagnostics_) << "missing texture argument"; - return false; + return; } auto* texture_type = TypeOf(texture)->UnwrapRef()->As(); @@ -1407,11 +1201,13 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out, auto emit_expr_as_signed = [&](const ast::Expression* e) { auto* ty = TypeOf(e)->UnwrapRef(); if (!ty->is_unsigned_integer_scalar_or_vector()) { - return EmitExpression(out, e); + EmitExpression(out, e); + return; } emit_signed_int_type(ty); ScopedParen sp(out); - return EmitExpression(out, e); + EmitExpression(out, e); + return; }; switch (builtin->Type()) { @@ -1427,9 +1223,7 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out, } else { out << "textureSize("; } - if (!EmitExpression(out, texture)) { - return false; - } + EmitExpression(out, texture); // The LOD parameter is mandatory on textureSize() for non-multisampled // textures. @@ -1438,9 +1232,7 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out, !texture_type->Is()) { out << ", "; if (auto* level_arg = arg(Usage::kLevel)) { - if (!emit_expr_as_signed(level_arg)) { - return false; - } + emit_expr_as_signed(level_arg); } else { out << "0"; } @@ -1452,7 +1244,7 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out, texture_type->dim() == type::TextureDimension::kCubeArray) { out << ".xy"; } - return true; + return; } case builtin::Function::kTextureNumLayers: { // textureNumLayers() returns an unsigned scalar in WGSL. @@ -1468,9 +1260,8 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out, } // textureSize() on sampler2dArray returns the array size in the // final component, so return it - if (!EmitExpression(out, texture)) { - return false; - } + EmitExpression(out, texture); + // The LOD parameter is mandatory on textureSize() for non-multisampled // textures. if (!texture_type->Is() && @@ -1478,15 +1269,13 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out, !texture_type->Is()) { out << ", "; if (auto* level_arg = arg(Usage::kLevel)) { - if (!emit_expr_as_signed(level_arg)) { - return false; - } + emit_expr_as_signed(level_arg); } else { out << "0"; } } out << ").z"; - return true; + return; } case builtin::Function::kTextureNumLevels: { // textureNumLevels() returns an unsigned scalar in WGSL. @@ -1496,11 +1285,9 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out, ScopedParen sp(out); out << "textureQueryLevels("; - if (!EmitExpression(out, texture)) { - return false; - } + EmitExpression(out, texture); out << ")"; - return true; + return; } case builtin::Function::kTextureNumSamples: { // textureNumSamples() returns an unsigned scalar in WGSL. @@ -1510,11 +1297,9 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out, ScopedParen sp(out); out << "textureSamples("; - if (!EmitExpression(out, texture)) { - return false; - } + EmitExpression(out, texture); out << ")"; - return true; + return; } default: break; @@ -1561,7 +1346,7 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out, diagnostics_.add_error(diag::System::Writer, "Internal compiler error: Unhandled texture builtin '" + std::string(builtin->str()) + "'"); - return false; + return; } if (builtin->Signature().IndexOf(sem::ParameterUsage::kOffset) >= 0) { @@ -1569,17 +1354,13 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out, } out << "("; - - if (!EmitExpression(out, texture)) { - return false; - } - + EmitExpression(out, texture); out << ", "; auto* param_coords = arg(Usage::kCoords); if (TINT_UNLIKELY(!param_coords)) { TINT_ICE(Writer, diagnostics_) << "missing coords argument"; - return false; + return; } if (auto* array_index = arg(Usage::kArrayIndex)) { @@ -1604,9 +1385,7 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out, param_coords = AppendVector(&builder_, param_coords, depth_ref)->Declaration(); } - if (!emit_expr_as_signed(param_coords)) { - return false; - } + emit_expr_as_signed(param_coords); for (auto usage : {Usage::kLevel, Usage::kDdx, Usage::kDdy, Usage::kSampleIndex}) { if (auto* e = arg(usage)) { @@ -1615,21 +1394,17 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out, // WGSL's textureSampleLevel() "level" param is i32 for depth textures, // whereas GLSL's textureLod() "lod" param is always float, so cast it. out << "float("; - if (!EmitExpression(out, e)) { - return false; - } + EmitExpression(out, e); out << ")"; - } else if (!emit_expr_as_signed(e)) { - return false; + } else { + emit_expr_as_signed(e); } } } if (auto* e = arg(Usage::kValue)) { out << ", "; - if (!EmitExpression(out, e)) { - return false; - } + EmitExpression(out, e); } // GLSL's textureGather always requires a refZ parameter. @@ -1641,9 +1416,7 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out, if (is_depth && !append_depth_ref_to_coords) { if (auto* e = arg(Usage::kDepthRef)) { out << ", "; - if (!EmitExpression(out, e)) { - return false; - } + EmitExpression(out, e); } else if (builtin->Type() == builtin::Function::kTextureSample) { out << ", 0.0f"; } @@ -1652,16 +1425,14 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out, for (auto usage : {Usage::kOffset, Usage::kComponent, Usage::kBias}) { if (auto* e = arg(usage)) { out << ", "; - if (!emit_expr_as_signed(e)) { - return false; - } + emit_expr_as_signed(e); } } out << ")"; if (builtin->ReturnType()->Is()) { - return true; + return; } // If the builtin return type does not match the number of elements of the // GLSL builtin, we need to swizzle the expression to generate the correct @@ -1680,10 +1451,8 @@ bool GeneratorImpl::EmitTextureCall(utils::StringStream& out, TINT_ICE(Writer, diagnostics_) << "WGSL return width (" << wgsl_ret_width << ") is wider than GLSL return width (" << glsl_ret_width << ") for " << builtin->Type(); - return false; + return; } - - return true; } std::string GeneratorImpl::generate_builtin_name(const sem::Builtin* builtin) { @@ -1805,7 +1574,7 @@ std::string GeneratorImpl::generate_builtin_name(const sem::Builtin* builtin) { return ""; } -bool GeneratorImpl::EmitCase(const ast::CaseStatement* stmt) { +void GeneratorImpl::EmitCase(const ast::CaseStatement* stmt) { auto* sem = builder_.Sem().Get(stmt); for (auto* selector : sem->Selectors()) { auto out = line(); @@ -1814,9 +1583,7 @@ bool GeneratorImpl::EmitCase(const ast::CaseStatement* stmt) { out << "default"; } else { out << "case "; - if (!EmitConstant(out, selector->Value())) { - return false; - } + EmitConstant(out, selector->Value()); } out << ":"; if (selector == sem->Selectors().back()) { @@ -1826,114 +1593,92 @@ bool GeneratorImpl::EmitCase(const ast::CaseStatement* stmt) { { ScopedIndent si(this); - if (!EmitStatements(stmt->body->statements)) { - return false; - } + EmitStatements(stmt->body->statements); if (!last_is_break(stmt->body)) { line() << "break;"; } } line() << "}"; - - return true; } -bool GeneratorImpl::EmitContinue(const ast::ContinueStatement*) { - if (!emit_continuing_ || !emit_continuing_()) { - return false; +void GeneratorImpl::EmitContinue(const ast::ContinueStatement*) { + if (emit_continuing_) { + emit_continuing_(); } line() << "continue;"; - return true; } -bool GeneratorImpl::EmitDiscard(const ast::DiscardStatement*) { +void GeneratorImpl::EmitDiscard(const ast::DiscardStatement*) { // TODO(dsinclair): Verify this is correct when the discard semantics are // defined for WGSL (https://github.com/gpuweb/gpuweb/issues/361) line() << "discard;"; - return true; } -bool GeneratorImpl::EmitExpression(utils::StringStream& out, const ast::Expression* expr) { +void GeneratorImpl::EmitExpression(utils::StringStream& out, const ast::Expression* expr) { if (auto* sem = builder_.Sem().GetVal(expr)) { if (auto* constant = sem->ConstantValue()) { - return EmitConstant(out, constant); + EmitConstant(out, constant); + return; } } - return Switch( + Switch( expr, // - [&](const ast::IndexAccessorExpression* a) { return EmitIndexAccessor(out, a); }, - [&](const ast::BinaryExpression* b) { return EmitBinary(out, b); }, - [&](const ast::BitcastExpression* b) { return EmitBitcast(out, b); }, - [&](const ast::CallExpression* c) { return EmitCall(out, c); }, - [&](const ast::IdentifierExpression* i) { return EmitIdentifier(out, i); }, - [&](const ast::LiteralExpression* l) { return EmitLiteral(out, l); }, - [&](const ast::MemberAccessorExpression* m) { return EmitMemberAccessor(out, m); }, - [&](const ast::UnaryOpExpression* u) { return EmitUnaryOp(out, u); }, + [&](const ast::IndexAccessorExpression* a) { EmitIndexAccessor(out, a); }, + [&](const ast::BinaryExpression* b) { EmitBinary(out, b); }, + [&](const ast::BitcastExpression* b) { EmitBitcast(out, b); }, + [&](const ast::CallExpression* c) { EmitCall(out, c); }, + [&](const ast::IdentifierExpression* i) { EmitIdentifier(out, i); }, + [&](const ast::LiteralExpression* l) { EmitLiteral(out, l); }, + [&](const ast::MemberAccessorExpression* m) { EmitMemberAccessor(out, m); }, + [&](const ast::UnaryOpExpression* u) { EmitUnaryOp(out, u); }, [&](Default) { // diagnostics_.add_error(diag::System::Writer, "unknown expression type: " + std::string(expr->TypeInfo().name)); - return false; }); } -bool GeneratorImpl::EmitIdentifier(utils::StringStream& out, +void GeneratorImpl::EmitIdentifier(utils::StringStream& out, const ast::IdentifierExpression* expr) { out << expr->identifier->symbol.Name(); - return true; } -bool GeneratorImpl::EmitIf(const ast::IfStatement* stmt) { +void GeneratorImpl::EmitIf(const ast::IfStatement* stmt) { { auto out = line(); out << "if ("; - if (!EmitExpression(out, stmt->condition)) { - return false; - } + EmitExpression(out, stmt->condition); out << ") {"; } - - if (!EmitStatementsWithIndent(stmt->body->statements)) { - return false; - } + EmitStatementsWithIndent(stmt->body->statements); if (stmt->else_statement) { line() << "} else {"; if (auto* block = stmt->else_statement->As()) { - if (!EmitStatementsWithIndent(block->statements)) { - return false; - } + EmitStatementsWithIndent(block->statements); } else { - if (!EmitStatementsWithIndent(utils::Vector{stmt->else_statement})) { - return false; - } + EmitStatementsWithIndent(utils::Vector{stmt->else_statement}); } } line() << "}"; - - return true; } -bool GeneratorImpl::EmitFunction(const ast::Function* func) { +void GeneratorImpl::EmitFunction(const ast::Function* func) { auto* sem = builder_.Sem().Get(func); if (ast::HasAttribute(func->attributes)) { // An internal function. Do not emit. - return true; + return; } { auto out = line(); auto name = func->name->symbol.Name(); - if (!EmitType(out, sem->ReturnType(), builtin::AddressSpace::kUndefined, - builtin::Access::kReadWrite, "")) { - return false; - } - + EmitType(out, sem->ReturnType(), builtin::AddressSpace::kUndefined, + builtin::Access::kReadWrite, ""); out << " " << name << "("; bool first = true; - for (auto* v : sem->Parameters()) { if (!first) { out << ", "; @@ -1957,79 +1702,77 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) { // AddressSpace::kStorage or AddressSpace::kUniform. This is required to // correctly translate the parameter to a [RW]ByteAddressBuffer for // storage buffers and a uint4[N] for uniform buffers. - if (!EmitTypeAndName(out, type, v->AddressSpace(), v->Access(), - v->Declaration()->name->symbol.Name())) { - return false; - } + EmitTypeAndName(out, type, v->AddressSpace(), v->Access(), + v->Declaration()->name->symbol.Name()); } out << ") {"; } - if (!EmitStatementsWithIndent(func->body->statements)) { - return false; - } + EmitStatementsWithIndent(func->body->statements); line() << "}"; line(); - - return true; } -bool GeneratorImpl::EmitGlobalVariable(const ast::Variable* global) { - return Switch( +void GeneratorImpl::EmitGlobalVariable(const ast::Variable* global) { + Switch( global, // [&](const ast::Var* var) { auto* sem = builder_.Sem().Get(global); switch (sem->AddressSpace()) { case builtin::AddressSpace::kUniform: - return EmitUniformVariable(var, sem); + EmitUniformVariable(var, sem); + return; case builtin::AddressSpace::kStorage: - return EmitStorageVariable(var, sem); + EmitStorageVariable(var, sem); + return; case builtin::AddressSpace::kHandle: - return EmitHandleVariable(var, sem); + EmitHandleVariable(var, sem); + return; case builtin::AddressSpace::kPrivate: - return EmitPrivateVariable(sem); + EmitPrivateVariable(sem); + return; case builtin::AddressSpace::kWorkgroup: - return EmitWorkgroupVariable(sem); + EmitWorkgroupVariable(sem); + return; case builtin::AddressSpace::kIn: case builtin::AddressSpace::kOut: - return EmitIOVariable(sem); + EmitIOVariable(sem); + return; case builtin::AddressSpace::kPushConstant: diagnostics_.add_error( diag::System::Writer, "unhandled address space " + utils::ToString(sem->AddressSpace())); - return false; + return; default: { TINT_ICE(Writer, diagnostics_) << "unhandled address space " << sem->AddressSpace(); - return false; + break; } } }, - [&](const ast::Let* let) { return EmitProgramConstVariable(let); }, + [&](const ast::Let* let) { EmitProgramConstVariable(let); }, [&](const ast::Override*) { // Override is removed with SubstituteOverride diagnostics_.add_error(diag::System::Writer, "override-expressions should have been removed with the " "SubstituteOverride transform"); - return false; }, [&](const ast::Const*) { - return true; // Constants are embedded at their use + // Constants are embedded at their use }, [&](Default) { TINT_ICE(Writer, diagnostics_) << "unhandled global variable type " << global->TypeInfo().name; - return false; }); } -bool GeneratorImpl::EmitUniformVariable(const ast::Var* var, const sem::Variable* sem) { +void GeneratorImpl::EmitUniformVariable(const ast::Var* var, const sem::Variable* sem) { auto* type = sem->Type()->UnwrapRef(); auto* str = type->As(); if (TINT_UNLIKELY(!str)) { TINT_ICE(Writer, builder_.Diagnostics()) << "storage variable must be of struct type"; - return false; + return; } auto bp = *sem->As()->BindingPoint(); { @@ -2041,16 +1784,14 @@ bool GeneratorImpl::EmitUniformVariable(const ast::Var* var, const sem::Variable auto name = var->name->symbol.Name(); line() << "} " << name << ";"; line(); - - return true; } -bool GeneratorImpl::EmitStorageVariable(const ast::Var* var, const sem::Variable* sem) { +void GeneratorImpl::EmitStorageVariable(const ast::Var* var, const sem::Variable* sem) { auto* type = sem->Type()->UnwrapRef(); auto* str = type->As(); if (TINT_UNLIKELY(!str)) { TINT_ICE(Writer, builder_.Diagnostics()) << "storage variable must be of struct type"; - return false; + return; } auto bp = *sem->As()->BindingPoint(); line() << "layout(binding = " << bp.binding << ", std430) buffer " @@ -2059,19 +1800,18 @@ bool GeneratorImpl::EmitStorageVariable(const ast::Var* var, const sem::Variable auto name = var->name->symbol.Name(); line() << "} " << name << ";"; line(); - - return true; } -bool GeneratorImpl::EmitHandleVariable(const ast::Var* var, const sem::Variable* sem) { +void GeneratorImpl::EmitHandleVariable(const ast::Var* var, const sem::Variable* sem) { auto out = line(); auto name = var->name->symbol.Name(); auto* type = sem->Type()->UnwrapRef(); if (type->Is()) { // GLSL ignores Sampler variables. - return true; + return; } + if (auto* storage = type->As()) { out << "layout("; switch (storage->texel_format()) { @@ -2129,44 +1869,32 @@ bool GeneratorImpl::EmitHandleVariable(const ast::Var* var, const sem::Variable* break; case builtin::TexelFormat::kUndefined: TINT_ICE(Writer, diagnostics_) << "invalid texel format"; - return false; + return; } out << ") "; } - if (!EmitTypeAndName(out, type, sem->AddressSpace(), sem->Access(), name)) { - return false; - } - + EmitTypeAndName(out, type, sem->AddressSpace(), sem->Access(), name); out << ";"; - return true; } -bool GeneratorImpl::EmitPrivateVariable(const sem::Variable* var) { +void GeneratorImpl::EmitPrivateVariable(const sem::Variable* var) { auto* decl = var->Declaration(); auto out = line(); auto name = decl->name->symbol.Name(); auto* type = var->Type()->UnwrapRef(); - if (!EmitTypeAndName(out, type, var->AddressSpace(), var->Access(), name)) { - return false; - } + EmitTypeAndName(out, type, var->AddressSpace(), var->Access(), name); out << " = "; if (auto* initializer = decl->initializer) { - if (!EmitExpression(out, initializer)) { - return false; - } + EmitExpression(out, initializer); } else { - if (!EmitZeroValue(out, var->Type()->UnwrapRef())) { - return false; - } + EmitZeroValue(out, var->Type()->UnwrapRef()); } - out << ";"; - return true; } -bool GeneratorImpl::EmitWorkgroupVariable(const sem::Variable* var) { +void GeneratorImpl::EmitWorkgroupVariable(const sem::Variable* var) { auto* decl = var->Declaration(); auto out = line(); @@ -2174,22 +1902,17 @@ bool GeneratorImpl::EmitWorkgroupVariable(const sem::Variable* var) { auto name = decl->name->symbol.Name(); auto* type = var->Type()->UnwrapRef(); - if (!EmitTypeAndName(out, type, var->AddressSpace(), var->Access(), name)) { - return false; - } + EmitTypeAndName(out, type, var->AddressSpace(), var->Access(), name); if (auto* initializer = decl->initializer) { out << " = "; - if (!EmitExpression(out, initializer)) { - return false; - } + EmitExpression(out, initializer); } out << ";"; - return true; } -bool GeneratorImpl::EmitIOVariable(const sem::GlobalVariable* var) { +void GeneratorImpl::EmitIOVariable(const sem::GlobalVariable* var) { auto* decl = var->Declaration(); if (auto* attr = ast::GetAttribute(decl->attributes)) { @@ -2199,7 +1922,7 @@ bool GeneratorImpl::EmitIOVariable(const sem::GlobalVariable* var) { requires_oes_sample_variables_ = true; } // Do not emit builtin (gl_) variables. - return true; + return; } auto out = line(); @@ -2208,19 +1931,13 @@ bool GeneratorImpl::EmitIOVariable(const sem::GlobalVariable* var) { auto name = decl->name->symbol.Name(); auto* type = var->Type()->UnwrapRef(); - if (!EmitTypeAndName(out, type, var->AddressSpace(), var->Access(), name)) { - return false; - } + EmitTypeAndName(out, type, var->AddressSpace(), var->Access(), name); if (auto* initializer = decl->initializer) { out << " = "; - if (!EmitExpression(out, initializer)) { - return false; - } + EmitExpression(out, initializer); } - out << ";"; - return true; } void GeneratorImpl::EmitInterpolationQualifiers( @@ -2260,12 +1977,13 @@ void GeneratorImpl::EmitInterpolationQualifiers( } } -bool GeneratorImpl::EmitAttributes(utils::StringStream& out, +void GeneratorImpl::EmitAttributes(utils::StringStream& out, const sem::GlobalVariable* var, utils::VectorRef attributes) { if (attributes.IsEmpty()) { - return true; + return; } + bool first = true; for (auto* attr : attributes) { if (attr->As()) { @@ -2277,10 +1995,9 @@ bool GeneratorImpl::EmitAttributes(utils::StringStream& out, if (!first) { out << ") "; } - return true; } -bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) { +void GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) { auto* func_sem = builder_.Sem().Get(func); if (func->PipelineStage() == ast::PipelineStage::kFragment) { @@ -2303,7 +2020,7 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) { diag::System::Writer, "override-expressions should have been removed with the SubstituteOverride " "transform"); - return false; + return; } out << std::to_string(wgsize[i].value()); } @@ -2313,10 +2030,8 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) { // Emit original entry point signature { auto out = line(); - if (!EmitTypeAndName(out, func_sem->ReturnType(), builtin::AddressSpace::kUndefined, - builtin::Access::kUndefined, func->name->symbol.Name())) { - return false; - } + EmitTypeAndName(out, func_sem->ReturnType(), builtin::AddressSpace::kUndefined, + builtin::Access::kUndefined, func->name->symbol.Name()); out << "("; bool first = true; @@ -2336,10 +2051,8 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) { } first = false; - if (!EmitTypeAndName(out, type, sem->AddressSpace(), sem->Access(), - var->name->symbol.Name())) { - return false; - } + EmitTypeAndName(out, type, sem->AddressSpace(), sem->Access(), + var->name->symbol.Name()); } out << ") {"; @@ -2352,73 +2065,44 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) { line() << "gl_PointSize = 1.0;"; } - if (!EmitStatements(func->body->statements)) { - return false; - } + EmitStatements(func->body->statements); if (!Is(func->body->Last())) { ast::ReturnStatement ret(ProgramID{}, ast::NodeID{}, Source{}); - if (!EmitStatement(&ret)) { - return false; - } + EmitStatement(&ret); } } line() << "}"; - - return true; } -bool GeneratorImpl::EmitConstant(utils::StringStream& out, const constant::Value* constant) { - return Switch( +void GeneratorImpl::EmitConstant(utils::StringStream& out, const constant::Value* constant) { + Switch( constant->Type(), // - [&](const type::Bool*) { - out << (constant->ValueAs() ? "true" : "false"); - return true; - }, - [&](const type::F32*) { - PrintF32(out, constant->ValueAs()); - return true; - }, - [&](const type::F16*) { - PrintF16(out, constant->ValueAs()); - return true; - }, - [&](const type::I32*) { - PrintI32(out, constant->ValueAs()); - return true; - }, - [&](const type::U32*) { - out << constant->ValueAs() << "u"; - return true; - }, + [&](const type::Bool*) { out << (constant->ValueAs() ? "true" : "false"); }, + [&](const type::F32*) { PrintF32(out, constant->ValueAs()); }, + [&](const type::F16*) { PrintF16(out, constant->ValueAs()); }, + [&](const type::I32*) { PrintI32(out, constant->ValueAs()); }, + [&](const type::U32*) { out << constant->ValueAs() << "u"; }, [&](const type::Vector* v) { - if (!EmitType(out, v, builtin::AddressSpace::kUndefined, builtin::Access::kUndefined, - "")) { - return false; - } + EmitType(out, v, builtin::AddressSpace::kUndefined, builtin::Access::kUndefined, ""); ScopedParen sp(out); if (auto* splat = constant->As()) { - return EmitConstant(out, splat->el); + EmitConstant(out, splat->el); + return; } for (size_t i = 0; i < v->Width(); i++) { if (i > 0) { out << ", "; } - if (!EmitConstant(out, constant->Index(i))) { - return false; - } + EmitConstant(out, constant->Index(i)); } - return true; }, [&](const type::Matrix* m) { - if (!EmitType(out, m, builtin::AddressSpace::kUndefined, builtin::Access::kUndefined, - "")) { - return false; - } + EmitType(out, m, builtin::AddressSpace::kUndefined, builtin::Access::kUndefined, ""); ScopedParen sp(out); @@ -2426,17 +2110,11 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out, const constant::Value if (column_idx > 0) { out << ", "; } - if (!EmitConstant(out, constant->Index(column_idx))) { - return false; - } + EmitConstant(out, constant->Index(column_idx)); } - return true; }, [&](const type::Array* a) { - if (!EmitType(out, a, builtin::AddressSpace::kUndefined, builtin::Access::kUndefined, - "")) { - return false; - } + EmitType(out, a, builtin::AddressSpace::kUndefined, builtin::Access::kUndefined, ""); ScopedParen sp(out); @@ -2444,24 +2122,18 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out, const constant::Value if (!count) { diagnostics_.add_error(diag::System::Writer, type::Array::kErrExpectedConstantCount); - return false; + return; } for (size_t i = 0; i < count; i++) { if (i > 0) { out << ", "; } - if (!EmitConstant(out, constant->Index(i))) { - return false; - } + EmitConstant(out, constant->Index(i)); } - - return true; }, [&](const sem::Struct* s) { - if (!EmitStructType(&helpers_, s)) { - return false; - } + EmitStructType(&helpers_, s); out << StructName(s); @@ -2471,58 +2143,45 @@ bool GeneratorImpl::EmitConstant(utils::StringStream& out, const constant::Value if (i > 0) { out << ", "; } - if (!EmitConstant(out, constant->Index(i))) { - return false; - } + EmitConstant(out, constant->Index(i)); } - - return true; }, [&](Default) { diagnostics_.add_error( diag::System::Writer, "unhandled constant type: " + builder_.FriendlyName(constant->Type())); - return false; }); } -bool GeneratorImpl::EmitLiteral(utils::StringStream& out, const ast::LiteralExpression* lit) { - return Switch( - lit, - [&](const ast::BoolLiteralExpression* l) { - out << (l->value ? "true" : "false"); - return true; - }, +void GeneratorImpl::EmitLiteral(utils::StringStream& out, const ast::LiteralExpression* lit) { + Switch( + lit, // + [&](const ast::BoolLiteralExpression* l) { out << (l->value ? "true" : "false"); }, [&](const ast::FloatLiteralExpression* l) { if (l->suffix == ast::FloatLiteralExpression::Suffix::kH) { PrintF16(out, static_cast(l->value)); } else { PrintF32(out, static_cast(l->value)); } - return true; }, [&](const ast::IntLiteralExpression* i) { switch (i->suffix) { case ast::IntLiteralExpression::Suffix::kNone: case ast::IntLiteralExpression::Suffix::kI: { PrintI32(out, static_cast(i->value)); - return true; + return; } case ast::IntLiteralExpression::Suffix::kU: { out << i->value << "u"; - return true; + return; } } diagnostics_.add_error(diag::System::Writer, "unknown integer literal suffix type"); - return false; }, - [&](Default) { - diagnostics_.add_error(diag::System::Writer, "unknown literal type"); - return false; - }); + [&](Default) { diagnostics_.add_error(diag::System::Writer, "unknown literal type"); }); } -bool GeneratorImpl::EmitZeroValue(utils::StringStream& out, const type::Type* type) { +void GeneratorImpl::EmitZeroValue(utils::StringStream& out, const type::Type* type) { if (type->Is()) { out << "false"; } else if (type->Is()) { @@ -2534,38 +2193,25 @@ bool GeneratorImpl::EmitZeroValue(utils::StringStream& out, const type::Type* ty } else if (type->Is()) { out << "0u"; } else if (auto* vec = type->As()) { - if (!EmitType(out, type, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, - "")) { - return false; - } + EmitType(out, type, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); ScopedParen sp(out); for (uint32_t i = 0; i < vec->Width(); i++) { if (i != 0) { out << ", "; } - if (!EmitZeroValue(out, vec->type())) { - return false; - } + EmitZeroValue(out, vec->type()); } } else if (auto* mat = type->As()) { - if (!EmitType(out, type, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, - "")) { - return false; - } + EmitType(out, type, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); ScopedParen sp(out); for (uint32_t i = 0; i < (mat->rows() * mat->columns()); i++) { if (i != 0) { out << ", "; } - if (!EmitZeroValue(out, mat->type())) { - return false; - } + EmitZeroValue(out, mat->type()); } } else if (auto* str = type->As()) { - if (!EmitType(out, type, builtin::AddressSpace::kUndefined, builtin::Access::kUndefined, - "")) { - return false; - } + EmitType(out, type, builtin::AddressSpace::kUndefined, builtin::Access::kUndefined, ""); bool first = true; ScopedParen sp(out); for (auto* member : str->Members()) { @@ -2577,16 +2223,13 @@ bool GeneratorImpl::EmitZeroValue(utils::StringStream& out, const type::Type* ty EmitZeroValue(out, member->Type()); } } else if (auto* arr = type->As()) { - if (!EmitType(out, type, builtin::AddressSpace::kUndefined, builtin::Access::kUndefined, - "")) { - return false; - } + EmitType(out, type, builtin::AddressSpace::kUndefined, builtin::Access::kUndefined, ""); ScopedParen sp(out); auto count = arr->ConstantCount(); if (!count) { diagnostics_.add_error(diag::System::Writer, type::Array::kErrExpectedConstantCount); - return false; + return; } for (uint32_t i = 0; i < count; i++) { @@ -2598,38 +2241,27 @@ bool GeneratorImpl::EmitZeroValue(utils::StringStream& out, const type::Type* ty } else { diagnostics_.add_error(diag::System::Writer, "Invalid type for zero emission: " + type->FriendlyName()); - return false; } - return true; } -bool GeneratorImpl::EmitLoop(const ast::LoopStatement* stmt) { +void GeneratorImpl::EmitLoop(const ast::LoopStatement* stmt) { auto emit_continuing = [this, stmt]() { if (stmt->continuing && !stmt->continuing->Empty()) { - if (!EmitBlock(stmt->continuing)) { - return false; - } + EmitBlock(stmt->continuing); } - return true; }; TINT_SCOPED_ASSIGNMENT(emit_continuing_, emit_continuing); line() << "while (true) {"; { ScopedIndent si(this); - if (!EmitStatements(stmt->body->statements)) { - return false; - } - if (!emit_continuing_()) { - return false; - } + EmitStatements(stmt->body->statements); + emit_continuing_(); } line() << "}"; - - return true; } -bool GeneratorImpl::EmitForLoop(const ast::ForLoopStatement* stmt) { +void GeneratorImpl::EmitForLoop(const ast::ForLoopStatement* stmt) { // Nest a for loop with a new block. In HLSL the initializer scope is not // nested by the for-loop, so we may get variable redefinitions. line() << "{"; @@ -2642,26 +2274,20 @@ bool GeneratorImpl::EmitForLoop(const ast::ForLoopStatement* stmt) { TextBuffer init_buf; if (auto* init = stmt->initializer) { TINT_SCOPED_ASSIGNMENT(current_buffer_, &init_buf); - if (!EmitStatement(init)) { - return false; - } + EmitStatement(init); } TextBuffer cond_pre; utils::StringStream cond_buf; if (auto* cond = stmt->condition) { TINT_SCOPED_ASSIGNMENT(current_buffer_, &cond_pre); - if (!EmitExpression(cond_buf, cond)) { - return false; - } + EmitExpression(cond_buf, cond); } TextBuffer cont_buf; if (auto* cont = stmt->continuing) { TINT_SCOPED_ASSIGNMENT(current_buffer_, &cont_buf); - if (!EmitStatement(cont)) { - return false; - } + EmitStatement(cont); } // If the for-loop has a multi-statement conditional and / or continuing, then @@ -2678,10 +2304,7 @@ bool GeneratorImpl::EmitForLoop(const ast::ForLoopStatement* stmt) { } if (emit_as_loop) { - auto emit_continuing = [&]() { - current_buffer_->Append(cont_buf); - return true; - }; + auto emit_continuing = [&]() { current_buffer_->Append(cont_buf); }; TINT_SCOPED_ASSIGNMENT(emit_continuing_, emit_continuing); line() << "while (true) {"; @@ -2696,13 +2319,8 @@ bool GeneratorImpl::EmitForLoop(const ast::ForLoopStatement* stmt) { line() << "if (!(" << cond_buf.str() << ")) { break; }"; } - if (!EmitStatements(stmt->body->statements)) { - return false; - } - - if (!emit_continuing_()) { - return false; - } + EmitStatements(stmt->body->statements); + emit_continuing_(); } else { // For-loop can be generated. { @@ -2728,28 +2346,22 @@ bool GeneratorImpl::EmitForLoop(const ast::ForLoopStatement* stmt) { { auto emit_continuing = [] { return true; }; TINT_SCOPED_ASSIGNMENT(emit_continuing_, emit_continuing); - if (!EmitStatementsWithIndent(stmt->body->statements)) { - return false; - } + EmitStatementsWithIndent(stmt->body->statements); } line() << "}"; } - - return true; } -bool GeneratorImpl::EmitWhile(const ast::WhileStatement* stmt) { +void GeneratorImpl::EmitWhile(const ast::WhileStatement* stmt) { TextBuffer cond_pre; utils::StringStream cond_buf; { auto* cond = stmt->condition; TINT_SCOPED_ASSIGNMENT(current_buffer_, &cond_pre); - if (!EmitExpression(cond_buf, cond)) { - return false; - } + EmitExpression(cond_buf, cond); } - auto emit_continuing = [&]() { return true; }; + auto emit_continuing = [&]() {}; TINT_SCOPED_ASSIGNMENT(emit_continuing_, emit_continuing); // If the whilehas a multi-statement conditional, then we cannot emit this @@ -2766,9 +2378,7 @@ bool GeneratorImpl::EmitWhile(const ast::WhileStatement* stmt) { current_buffer_->Append(cond_pre); line() << "if (!(" << cond_buf.str() << ")) { break; }"; - if (!EmitStatements(stmt->body->statements)) { - return false; - } + EmitStatements(stmt->body->statements); } else { // While can be generated. { @@ -2780,128 +2390,105 @@ bool GeneratorImpl::EmitWhile(const ast::WhileStatement* stmt) { } out << " {"; } - if (!EmitStatementsWithIndent(stmt->body->statements)) { - return false; - } + EmitStatementsWithIndent(stmt->body->statements); line() << "}"; } - - return true; } -bool GeneratorImpl::EmitMemberAccessor(utils::StringStream& out, +void GeneratorImpl::EmitMemberAccessor(utils::StringStream& out, const ast::MemberAccessorExpression* expr) { - if (!EmitExpression(out, expr->object)) { - return false; - } + EmitExpression(out, expr->object); out << "."; auto* sem = builder_.Sem().Get(expr)->UnwrapLoad(); - return Switch( + Switch( sem, [&](const sem::Swizzle*) { // Swizzles output the name directly out << expr->member->symbol.Name(); - return true; }, [&](const sem::StructMemberAccess* member_access) { out << member_access->Member()->Name().Name(); - return true; }, [&](Default) { TINT_ICE(Writer, diagnostics_) << "unknown member access type: " << sem->TypeInfo().name; - return false; }); } -bool GeneratorImpl::EmitReturn(const ast::ReturnStatement* stmt) { +void GeneratorImpl::EmitReturn(const ast::ReturnStatement* stmt) { if (stmt->value) { auto out = line(); out << "return "; - if (!EmitExpression(out, stmt->value)) { - return false; - } + EmitExpression(out, stmt->value); out << ";"; } else { line() << "return;"; } - return true; } -bool GeneratorImpl::EmitStatement(const ast::Statement* stmt) { - return Switch( +void GeneratorImpl::EmitStatement(const ast::Statement* stmt) { + Switch( stmt, // - [&](const ast::AssignmentStatement* a) { return EmitAssign(a); }, - [&](const ast::BlockStatement* b) { return EmitBlock(b); }, - [&](const ast::BreakStatement* b) { return EmitBreak(b); }, - [&](const ast::BreakIfStatement* b) { return EmitBreakIf(b); }, + [&](const ast::AssignmentStatement* a) { EmitAssign(a); }, + [&](const ast::BlockStatement* b) { EmitBlock(b); }, + [&](const ast::BreakStatement* b) { EmitBreak(b); }, + [&](const ast::BreakIfStatement* b) { EmitBreakIf(b); }, [&](const ast::CallStatement* c) { auto out = line(); - if (!EmitCall(out, c->expr)) { - return false; - } + EmitCall(out, c->expr); out << ";"; - return true; }, - [&](const ast::ContinueStatement* c) { return EmitContinue(c); }, - [&](const ast::DiscardStatement* d) { return EmitDiscard(d); }, - [&](const ast::IfStatement* i) { return EmitIf(i); }, - [&](const ast::LoopStatement* l) { return EmitLoop(l); }, - [&](const ast::ForLoopStatement* l) { return EmitForLoop(l); }, - [&](const ast::WhileStatement* l) { return EmitWhile(l); }, - [&](const ast::ReturnStatement* r) { return EmitReturn(r); }, - [&](const ast::SwitchStatement* s) { return EmitSwitch(s); }, + [&](const ast::ContinueStatement* c) { EmitContinue(c); }, + [&](const ast::DiscardStatement* d) { EmitDiscard(d); }, + [&](const ast::IfStatement* i) { EmitIf(i); }, + [&](const ast::LoopStatement* l) { EmitLoop(l); }, + [&](const ast::ForLoopStatement* l) { EmitForLoop(l); }, + [&](const ast::WhileStatement* l) { EmitWhile(l); }, + [&](const ast::ReturnStatement* r) { EmitReturn(r); }, + [&](const ast::SwitchStatement* s) { EmitSwitch(s); }, [&](const ast::VariableDeclStatement* v) { - return Switch( + Switch( v->variable, // - [&](const ast::Var* var) { return EmitVar(var); }, - [&](const ast::Let* let) { return EmitLet(let); }, + [&](const ast::Var* var) { EmitVar(var); }, + [&](const ast::Let* let) { EmitLet(let); }, [&](const ast::Const*) { - return true; // Constants are embedded at their use + // Constants are embedded at their use }, [&](Default) { // TINT_ICE(Writer, diagnostics_) << "unknown variable type: " << v->variable->TypeInfo().name; - return false; }); }, [&](const ast::ConstAssert*) { - return true; // Not emitted + // Not emitted }, [&](Default) { diagnostics_.add_error(diag::System::Writer, "unknown statement type: " + std::string(stmt->TypeInfo().name)); - return false; }); } -bool GeneratorImpl::EmitSwitch(const ast::SwitchStatement* stmt) { +void GeneratorImpl::EmitSwitch(const ast::SwitchStatement* stmt) { { // switch(expr) { auto out = line(); out << "switch("; - if (!EmitExpression(out, stmt->condition)) { - return false; - } + EmitExpression(out, stmt->condition); out << ") {"; } { ScopedIndent si(this); for (auto* s : stmt->body) { - if (!EmitCase(s)) { - return false; - } + EmitCase(s); } } line() << "}"; - - return true; } -bool GeneratorImpl::EmitType(utils::StringStream& out, +void GeneratorImpl::EmitType(utils::StringStream& out, const type::Type* type, builtin::AddressSpace address_space, builtin::Access access, @@ -2939,16 +2526,14 @@ bool GeneratorImpl::EmitType(utils::StringStream& out, if (!count) { diagnostics_.add_error(diag::System::Writer, type::Array::kErrExpectedConstantCount); - return false; + return; } sizes.push_back(count.value()); } base_type = arr->ElemType(); } - if (!EmitType(out, base_type, address_space, access, "")) { - return false; - } + EmitType(out, base_type, address_space, access, ""); if (!name.empty()) { out << " " << name; if (name_printed) { @@ -2982,15 +2567,13 @@ bool GeneratorImpl::EmitType(utils::StringStream& out, } else if (TINT_UNLIKELY(type->Is())) { TINT_ICE(Writer, diagnostics_) << "Attempting to emit pointer type. These should have been " "removed with the SimplifyPointers transform"; - return false; } else if (type->Is()) { - return false; } else if (auto* str = type->As()) { out << StructName(str); } else if (auto* tex = type->As()) { if (TINT_UNLIKELY(tex->Is())) { TINT_ICE(Writer, diagnostics_) << "Multiplanar external texture transform was not run."; - return false; + return; } auto* storage = tex->As(); @@ -3014,7 +2597,7 @@ bool GeneratorImpl::EmitType(utils::StringStream& out, out << "u"; } else { TINT_ICE(Writer, diagnostics_) << "Unsupported texture type"; - return false; + return; } out << (storage ? "image" : "sampler"); @@ -3041,7 +2624,7 @@ bool GeneratorImpl::EmitType(utils::StringStream& out, default: TINT_UNREACHABLE(Writer, diagnostics_) << "unexpected TextureDimension " << tex->dim(); - return false; + return; } if (tex->Is()) { out << "Shadow"; @@ -3062,44 +2645,34 @@ bool GeneratorImpl::EmitType(utils::StringStream& out, out << "bvec" << width; } else { out << "vector<"; - if (!EmitType(out, vec->type(), address_space, access, "")) { - return false; - } + EmitType(out, vec->type(), address_space, access, ""); out << ", " << width << ">"; } } else if (auto* atomic = type->As()) { - if (!EmitType(out, atomic->Type(), address_space, access, name)) { - return false; - } + EmitType(out, atomic->Type(), address_space, access, name); } else if (type->Is()) { out << "void"; } else { diagnostics_.add_error(diag::System::Writer, "unknown type in EmitType"); - return false; } - - return true; } -bool GeneratorImpl::EmitTypeAndName(utils::StringStream& out, +void GeneratorImpl::EmitTypeAndName(utils::StringStream& out, const type::Type* type, builtin::AddressSpace address_space, builtin::Access access, const std::string& name) { bool printed_name = false; - if (!EmitType(out, type, address_space, access, name, &printed_name)) { - return false; - } + EmitType(out, type, address_space, access, name, &printed_name); if (!name.empty() && !printed_name) { out << " " << name; } - return true; } -bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) { +void GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) { auto it = emitted_structs_.emplace(str); if (!it.second) { - return true; + return; } auto address_space_uses = str->AddressSpaceUsage(); @@ -3107,33 +2680,27 @@ bool GeneratorImpl::EmitStructType(TextBuffer* b, const sem::Struct* str) { EmitStructMembers(b, str); line(b) << "};"; line(b); - - return true; } -bool GeneratorImpl::EmitStructMembers(TextBuffer* b, const sem::Struct* str) { +void GeneratorImpl::EmitStructMembers(TextBuffer* b, const sem::Struct* str) { ScopedIndent si(b); for (auto* mem : str->Members()) { auto name = mem->Name().Name(); - auto* ty = mem->Type(); auto out = line(b); - - if (!EmitTypeAndName(out, ty, builtin::AddressSpace::kUndefined, - builtin::Access::kReadWrite, name)) { - return false; - } + EmitTypeAndName(out, ty, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, + name); out << ";"; } - return true; } -bool GeneratorImpl::EmitUnaryOp(utils::StringStream& out, const ast::UnaryOpExpression* expr) { +void GeneratorImpl::EmitUnaryOp(utils::StringStream& out, const ast::UnaryOpExpression* expr) { switch (expr->op) { case ast::UnaryOp::kIndirection: case ast::UnaryOp::kAddressOf: - return EmitExpression(out, expr->expr); + EmitExpression(out, expr->expr); + return; case ast::UnaryOp::kComplement: out << "~"; break; @@ -3150,81 +2717,55 @@ bool GeneratorImpl::EmitUnaryOp(utils::StringStream& out, const ast::UnaryOpExpr } ScopedParen sp(out); - if (!EmitExpression(out, expr->expr)) { - return false; - } - - return true; + EmitExpression(out, expr->expr); } -bool GeneratorImpl::EmitVar(const ast::Var* var) { +void GeneratorImpl::EmitVar(const ast::Var* var) { auto* sem = builder_.Sem().Get(var); auto* type = sem->Type()->UnwrapRef(); auto out = line(); - if (!EmitTypeAndName(out, type, sem->AddressSpace(), sem->Access(), var->name->symbol.Name())) { - return false; - } + EmitTypeAndName(out, type, sem->AddressSpace(), sem->Access(), var->name->symbol.Name()); out << " = "; if (var->initializer) { - if (!EmitExpression(out, var->initializer)) { - return false; - } + EmitExpression(out, var->initializer); } else { - if (!EmitZeroValue(out, type)) { - return false; - } + EmitZeroValue(out, type); } out << ";"; - - return true; } -bool GeneratorImpl::EmitLet(const ast::Let* let) { +void GeneratorImpl::EmitLet(const ast::Let* let) { auto* sem = builder_.Sem().Get(let); auto* type = sem->Type()->UnwrapRef(); auto out = line(); // TODO(senorblanco): handle const - if (!EmitTypeAndName(out, type, builtin::AddressSpace::kUndefined, builtin::Access::kUndefined, - let->name->symbol.Name())) { - return false; - } + EmitTypeAndName(out, type, builtin::AddressSpace::kUndefined, builtin::Access::kUndefined, + let->name->symbol.Name()); out << " = "; - - if (!EmitExpression(out, let->initializer)) { - return false; - } - + EmitExpression(out, let->initializer); out << ";"; - - return true; } -bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) { +void GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) { auto* sem = builder_.Sem().Get(var); auto* type = sem->Type(); auto out = line(); out << "const "; - if (!EmitTypeAndName(out, type, builtin::AddressSpace::kUndefined, builtin::Access::kUndefined, - var->name->symbol.Name())) { - return false; - } + EmitTypeAndName(out, type, builtin::AddressSpace::kUndefined, builtin::Access::kUndefined, + var->name->symbol.Name()); out << " = "; - if (!EmitExpression(out, var->initializer)) { - return false; - } + EmitExpression(out, var->initializer); out << ";"; - - return true; } template -bool GeneratorImpl::CallBuiltinHelper(utils::StringStream& out, +void GeneratorImpl::CallBuiltinHelper(utils::StringStream& out, const ast::CallExpression* call, const sem::Builtin* builtin, F&& build) { @@ -3237,10 +2778,8 @@ bool GeneratorImpl::CallBuiltinHelper(utils::StringStream& out, std::vector parameter_names; { auto decl = line(&b); - if (!EmitTypeAndName(decl, builtin->ReturnType(), builtin::AddressSpace::kUndefined, - builtin::Access::kUndefined, fn_name)) { - return ""; - } + EmitTypeAndName(decl, builtin->ReturnType(), builtin::AddressSpace::kUndefined, + builtin::Access::kUndefined, fn_name); { ScopedParen sp(decl); for (auto* param : builtin->Parameters()) { @@ -3253,10 +2792,8 @@ bool GeneratorImpl::CallBuiltinHelper(utils::StringStream& out, decl << "inout "; ty = ptr->StoreType(); } - if (!EmitTypeAndName(decl, ty, builtin::AddressSpace::kUndefined, - builtin::Access::kUndefined, param_name)) { - return ""; - } + EmitTypeAndName(decl, ty, builtin::AddressSpace::kUndefined, + builtin::Access::kUndefined, param_name); parameter_names.emplace_back(std::move(param_name)); } } @@ -3264,19 +2801,13 @@ bool GeneratorImpl::CallBuiltinHelper(utils::StringStream& out, } { ScopedIndent si(&b); - if (!build(&b, parameter_names)) { - return ""; - } + build(&b, parameter_names); } line(&b) << "}"; line(&b); return fn_name; }); - if (fn.empty()) { - return false; - } - // Call the helper out << fn; { @@ -3287,12 +2818,9 @@ bool GeneratorImpl::CallBuiltinHelper(utils::StringStream& out, out << ", "; } first = false; - if (!EmitExpression(out, arg)) { - return false; - } + EmitExpression(out, arg); } } - return true; } type::Type* GeneratorImpl::BoolTypeToUint(const type::Type* type) { diff --git a/src/tint/writer/glsl/generator_impl.h b/src/tint/writer/glsl/generator_impl.h index 96042c1a1a..0698d4f64d 100644 --- a/src/tint/writer/glsl/generator_impl.h +++ b/src/tint/writer/glsl/generator_impl.h @@ -83,135 +83,111 @@ class GeneratorImpl : public TextGenerator { GeneratorImpl(const Program* program, const Version& version); ~GeneratorImpl(); - /// @returns true on successful generation; false otherwise - bool Generate(); + /// Generates the GLSL shader + void Generate(); /// Record an extension directive within the generator /// @param ext the extension to record - /// @returns true if the extension directive was recorded successfully - bool RecordExtension(const ast::Enable* ext); + void RecordExtension(const ast::Enable* ext); /// Handles an index accessor expression /// @param out the output of the expression stream /// @param expr the expression to emit - /// @returns true if the index accessor was emitted - bool EmitIndexAccessor(utils::StringStream& out, const ast::IndexAccessorExpression* expr); + void EmitIndexAccessor(utils::StringStream& out, const ast::IndexAccessorExpression* expr); /// Handles an assignment statement /// @param stmt the statement to emit - /// @returns true if the statement was emitted successfully - bool EmitAssign(const ast::AssignmentStatement* stmt); + void EmitAssign(const ast::AssignmentStatement* stmt); /// Handles emission of bitwise operators (&|) on bool scalars and vectors /// @param out the output of the expression stream /// @param expr the binary expression - /// @returns true if the expression was emitted, false otherwise - bool EmitBitwiseBoolOp(utils::StringStream& out, const ast::BinaryExpression* expr); + void EmitBitwiseBoolOp(utils::StringStream& out, const ast::BinaryExpression* expr); /// Handles generating a binary expression /// @param out the output of the expression stream /// @param expr the binary expression - /// @returns true if the expression was emitted, false otherwise - bool EmitFloatModulo(utils::StringStream& out, const ast::BinaryExpression* expr); + void EmitFloatModulo(utils::StringStream& out, const ast::BinaryExpression* expr); /// Handles generating the modulo operator on float vector operands /// @param out the output of the expression stream /// @param expr the binary expression - /// @returns true if the expression was emitted, false otherwise - bool EmitBinary(utils::StringStream& out, const ast::BinaryExpression* expr); + void EmitBinary(utils::StringStream& out, const ast::BinaryExpression* expr); /// Handles generating a bitcast expression /// @param out the output of the expression stream /// @param expr the expression - /// @returns true if the binary expression was emitted - bool EmitVectorRelational(utils::StringStream& out, const ast::BinaryExpression* expr); + void EmitVectorRelational(utils::StringStream& out, const ast::BinaryExpression* expr); /// Handles generating a vector relational expression /// @param out the output of the expression stream /// @param expr the expression - /// @returns true if the vector relational expression was emitted - bool EmitBitcast(utils::StringStream& out, const ast::BitcastExpression* expr); + void EmitBitcast(utils::StringStream& out, const ast::BitcastExpression* expr); /// Emits a list of statements /// @param stmts the statement list - /// @returns true if the statements were emitted successfully - bool EmitStatements(utils::VectorRef stmts); + void EmitStatements(utils::VectorRef stmts); /// Emits a list of statements with an indentation /// @param stmts the statement list - /// @returns true if the statements were emitted successfully - bool EmitStatementsWithIndent(utils::VectorRef stmts); + void EmitStatementsWithIndent(utils::VectorRef stmts); /// Handles a block statement /// @param stmt the statement to emit - /// @returns true if the statement was emitted successfully - bool EmitBlock(const ast::BlockStatement* stmt); + void EmitBlock(const ast::BlockStatement* stmt); /// Handles a break statement /// @param stmt the statement to emit - /// @returns true if the statement was emitted successfully - bool EmitBreak(const ast::BreakStatement* stmt); + void EmitBreak(const ast::BreakStatement* stmt); /// Handles a break-if statement /// @param stmt the statement to emit - /// @returns true if the statement was emitted successfully - bool EmitBreakIf(const ast::BreakIfStatement* stmt); + void EmitBreakIf(const ast::BreakIfStatement* stmt); /// Handles generating a call expression /// @param out the output of the expression stream /// @param expr the call expression - /// @returns true if the call expression is emitted - bool EmitCall(utils::StringStream& out, const ast::CallExpression* expr); + void EmitCall(utils::StringStream& out, const ast::CallExpression* expr); /// Handles generating a function call expression /// @param out the output of the expression stream /// @param call the call expression /// @param fn the function being called - /// @returns true if the expression is emitted - bool EmitFunctionCall(utils::StringStream& out, const sem::Call* call, const sem::Function* fn); + void EmitFunctionCall(utils::StringStream& out, const sem::Call* call, const sem::Function* fn); /// Handles generating a builtin call expression /// @param out the output of the expression stream /// @param call the call expression /// @param builtin the builtin being called - /// @returns true if the expression is emitted - bool EmitBuiltinCall(utils::StringStream& out, + void EmitBuiltinCall(utils::StringStream& out, const sem::Call* call, const sem::Builtin* builtin); /// Handles generating a value conversion expression /// @param out the output of the expression stream /// @param call the call expression /// @param conv the value conversion - /// @returns true if the expression is emitted - bool EmitValueConversion(utils::StringStream& out, + void EmitValueConversion(utils::StringStream& out, const sem::Call* call, const sem::ValueConversion* conv); /// Handles generating a value constructor expression /// @param out the output of the expression stream /// @param call the call expression /// @param ctor the value constructor - /// @returns true if the expression is emitted - bool EmitValueConstructor(utils::StringStream& out, + void EmitValueConstructor(utils::StringStream& out, const sem::Call* call, const sem::ValueConstructor* ctor); /// Handles generating a barrier builtin call /// @param out the output of the expression stream /// @param builtin the semantic information for the barrier builtin - /// @returns true if the call expression is emitted - bool EmitBarrierCall(utils::StringStream& out, const sem::Builtin* builtin); + void EmitBarrierCall(utils::StringStream& out, const sem::Builtin* builtin); /// Handles generating an atomic builtin call for a workgroup variable /// @param out the output of the expression stream /// @param expr the call expression /// @param builtin the semantic information for the atomic builtin - /// @returns true if the call expression is emitted - bool EmitWorkgroupAtomicCall(utils::StringStream& out, + void EmitWorkgroupAtomicCall(utils::StringStream& out, const ast::CallExpression* expr, const sem::Builtin* builtin); /// Handles generating an array.length() call /// @param out the output of the expression stream /// @param expr the call expression - /// @returns true if the array length expression is emitted - bool EmitArrayLength(utils::StringStream& out, const ast::CallExpression* expr); + void EmitArrayLength(utils::StringStream& out, const ast::CallExpression* expr); /// Handles generating a call to `bitfieldExtract` /// @param out the output of the expression stream /// @param expr the call expression - /// @returns true if the expression is emitted - bool EmitExtractBits(utils::StringStream& out, const ast::CallExpression* expr); + void EmitExtractBits(utils::StringStream& out, const ast::CallExpression* expr); /// Handles generating a call to `bitfieldInsert` /// @param out the output of the expression stream /// @param expr the call expression - /// @returns true if the expression is emitted - bool EmitInsertBits(utils::StringStream& out, const ast::CallExpression* expr); + void EmitInsertBits(utils::StringStream& out, const ast::CallExpression* expr); /// Emulates 'fma' on GLSL ES, where it is unsupported. /// @param out the output of the expression stream /// @param expr the fma() expression - /// @returns true if the expression is emitted - bool EmitEmulatedFMA(utils::StringStream& out, const ast::CallExpression* expr); + void EmitEmulatedFMA(utils::StringStream& out, const ast::CallExpression* expr); /// Create a float literal zero AST node, and associated semantic nodes. /// @param stmt the statement which will own the semantic expression node /// @returns an AST expression representing 0.0f @@ -222,130 +198,109 @@ class GeneratorImpl : public TextGenerator { /// @param out the output of the expression stream /// @param call the call expression /// @param builtin the semantic information for the texture builtin - /// @returns true if the call expression is emitted - bool EmitTextureCall(utils::StringStream& out, + void EmitTextureCall(utils::StringStream& out, const sem::Call* call, const sem::Builtin* builtin); /// Handles generating a call to the `select()` builtin /// @param out the output of the expression stream /// @param expr the call expression - /// @returns true if the call expression is emitted - bool EmitCountOneBitsCall(utils::StringStream& out, const ast::CallExpression* expr); + void EmitCountOneBitsCall(utils::StringStream& out, const ast::CallExpression* expr); /// Handles generating a call to the `countOneBits()` builtin /// @param out the output of the expression stream /// @param expr the call expression /// @param builtin the semantic information for the builtin - /// @returns true if the call expression is emitted - bool EmitSelectCall(utils::StringStream& out, + void EmitSelectCall(utils::StringStream& out, const ast::CallExpression* expr, const sem::Builtin* builtin); /// Handles generating a call to the `dot()` builtin /// @param out the output of the expression stream /// @param expr the call expression /// @param builtin the semantic information for the builtin - /// @returns true if the call expression is emitted - bool EmitDotCall(utils::StringStream& out, + void EmitDotCall(utils::StringStream& out, const ast::CallExpression* expr, const sem::Builtin* builtin); /// Handles generating a call to the `modf()` builtin /// @param out the output of the expression stream /// @param expr the call expression /// @param builtin the semantic information for the builtin - /// @returns true if the call expression is emitted - bool EmitModfCall(utils::StringStream& out, + void EmitModfCall(utils::StringStream& out, const ast::CallExpression* expr, const sem::Builtin* builtin); /// Handles generating a call to the `frexp()` builtin /// @param out the output of the expression stream /// @param expr the call expression /// @param builtin the semantic information for the builtin - /// @returns true if the call expression is emitted - bool EmitFrexpCall(utils::StringStream& out, + void EmitFrexpCall(utils::StringStream& out, const ast::CallExpression* expr, const sem::Builtin* builtin); /// Handles generating a call to the `degrees()` builtin /// @param out the output of the expression stream /// @param expr the call expression /// @param builtin the semantic information for the builtin - /// @returns true if the call expression is emitted - bool EmitDegreesCall(utils::StringStream& out, + void EmitDegreesCall(utils::StringStream& out, const ast::CallExpression* expr, const sem::Builtin* builtin); /// Handles generating a call to the `radians()` builtin /// @param out the output of the expression stream /// @param expr the call expression /// @param builtin the semantic information for the builtin - /// @returns true if the call expression is emitted - bool EmitRadiansCall(utils::StringStream& out, + void EmitRadiansCall(utils::StringStream& out, const ast::CallExpression* expr, const sem::Builtin* builtin); /// Handles generating a call to the `quantizeToF16()` intrinsic /// @param out the output of the expression stream /// @param expr the call expression /// @param builtin the semantic information for the builtin - /// @returns true if the call expression is emitted - bool EmitQuantizeToF16Call(utils::StringStream& out, + void EmitQuantizeToF16Call(utils::StringStream& out, const ast::CallExpression* expr, const sem::Builtin* builtin); /// Handles a case statement /// @param stmt the statement - /// @returns true if the statement was emitted successfully - bool EmitCase(const ast::CaseStatement* stmt); + void EmitCase(const ast::CaseStatement* stmt); /// Handles generating a discard statement /// @param stmt the discard statement - /// @returns true if the statement was successfully emitted - bool EmitDiscard(const ast::DiscardStatement* stmt); + void EmitDiscard(const ast::DiscardStatement* stmt); /// Handles a continue statement /// @param stmt the statement to emit - /// @returns true if the statement was emitted successfully - bool EmitContinue(const ast::ContinueStatement* stmt); + void EmitContinue(const ast::ContinueStatement* stmt); /// Handles generate an Expression /// @param out the output of the expression stream /// @param expr the expression - /// @returns true if the expression was emitted - bool EmitExpression(utils::StringStream& out, const ast::Expression* expr); + void EmitExpression(utils::StringStream& out, const ast::Expression* expr); /// Handles generating a function /// @param func the function to generate - /// @returns true if the function was emitted - bool EmitFunction(const ast::Function* func); + void EmitFunction(const ast::Function* func); /// Handles emitting a global variable /// @param global the global variable - /// @returns true on success - bool EmitGlobalVariable(const ast::Variable* global); + void EmitGlobalVariable(const ast::Variable* global); /// Handles emitting a global variable with the uniform address space /// @param var the AST node for the 'var' /// @param sem the semantic node for the 'var' - /// @returns true on success - bool EmitUniformVariable(const ast::Var* var, const sem::Variable* sem); + void EmitUniformVariable(const ast::Var* var, const sem::Variable* sem); /// Handles emitting a global variable with the storage address space /// @param var the AST node for the 'var' /// @param sem the semantic node for the 'var' - /// @returns true on success - bool EmitStorageVariable(const ast::Var* var, const sem::Variable* sem); + void EmitStorageVariable(const ast::Var* var, const sem::Variable* sem); /// Handles emitting a global variable with the handle address space /// @param var the AST node for the 'var' /// @param sem the semantic node for the 'var' - /// @returns true on success - bool EmitHandleVariable(const ast::Var* var, const sem::Variable* sem); + void EmitHandleVariable(const ast::Var* var, const sem::Variable* sem); /// Handles emitting a global variable with the private address space /// @param var the global variable - /// @returns true on success - bool EmitPrivateVariable(const sem::Variable* var); + void EmitPrivateVariable(const sem::Variable* var); /// Handles emitting a global variable with the workgroup address space /// @param var the global variable - /// @returns true on success - bool EmitWorkgroupVariable(const sem::Variable* var); + void EmitWorkgroupVariable(const sem::Variable* var); /// Handles emitting a global variable with the input or output address space /// @param var the global variable - /// @returns true on success - bool EmitIOVariable(const sem::GlobalVariable* var); + void EmitIOVariable(const sem::GlobalVariable* var); /// Handles emitting interpolation qualifiers /// @param out the output of the expression stream @@ -356,62 +311,49 @@ class GeneratorImpl : public TextGenerator { /// @param out the output of the expression stream /// @param var the global variable semantics /// @param attrs the attributes - /// @returns true if the attributes were emitted - bool EmitAttributes(utils::StringStream& out, + void EmitAttributes(utils::StringStream& out, const sem::GlobalVariable* var, utils::VectorRef attrs); /// Handles emitting the entry point function /// @param func the entry point - /// @returns true if the entry point function was emitted - bool EmitEntryPointFunction(const ast::Function* func); + void EmitEntryPointFunction(const ast::Function* func); /// Handles an if statement /// @param stmt the statement to emit - /// @returns true if the statement was successfully emitted - bool EmitIf(const ast::IfStatement* stmt); + void EmitIf(const ast::IfStatement* stmt); /// Handles a constant value /// @param out the output stream /// @param constant the constant value to emit - /// @returns true if the constant value was successfully emitted - bool EmitConstant(utils::StringStream& out, const constant::Value* constant); + void EmitConstant(utils::StringStream& out, const constant::Value* constant); /// Handles a literal /// @param out the output stream /// @param lit the literal to emit - /// @returns true if the literal was successfully emitted - bool EmitLiteral(utils::StringStream& out, const ast::LiteralExpression* lit); + void EmitLiteral(utils::StringStream& out, const ast::LiteralExpression* lit); /// Handles a loop statement /// @param stmt the statement to emit - /// @returns true if the statement was emitted - bool EmitLoop(const ast::LoopStatement* stmt); + void EmitLoop(const ast::LoopStatement* stmt); /// Handles a for loop statement /// @param stmt the statement to emit - /// @returns true if the statement was emitted - bool EmitForLoop(const ast::ForLoopStatement* stmt); + void EmitForLoop(const ast::ForLoopStatement* stmt); /// Handles a while statement /// @param stmt the statement to emit - /// @returns true if the statement was emitted - bool EmitWhile(const ast::WhileStatement* stmt); + void EmitWhile(const ast::WhileStatement* stmt); /// Handles generating an identifier expression /// @param out the output of the expression stream /// @param expr the identifier expression - /// @returns true if the identifier was emitted - bool EmitIdentifier(utils::StringStream& out, const ast::IdentifierExpression* expr); + void EmitIdentifier(utils::StringStream& out, const ast::IdentifierExpression* expr); /// Handles a member accessor expression /// @param out the output of the expression stream /// @param expr the member accessor expression - /// @returns true if the member accessor was emitted - bool EmitMemberAccessor(utils::StringStream& out, const ast::MemberAccessorExpression* expr); + void EmitMemberAccessor(utils::StringStream& out, const ast::MemberAccessorExpression* expr); /// Handles return statements /// @param stmt the statement to emit - /// @returns true if the statement was successfully emitted - bool EmitReturn(const ast::ReturnStatement* stmt); + void EmitReturn(const ast::ReturnStatement* stmt); /// Handles statement /// @param stmt the statement to emit - /// @returns true if the statement was emitted - bool EmitStatement(const ast::Statement* stmt); + void EmitStatement(const ast::Statement* stmt); /// Handles generating a switch statement /// @param stmt the statement to emit - /// @returns true if the statement was emitted - bool EmitSwitch(const ast::SwitchStatement* stmt); + void EmitSwitch(const ast::SwitchStatement* stmt); /// Handles generating type /// @param out the output stream /// @param type the type to generate @@ -420,8 +362,7 @@ class GeneratorImpl : public TextGenerator { /// @param name the name of the variable, used for array emission. /// @param name_printed (optional) if not nullptr and an array was printed /// then the boolean is set to true. - /// @returns true if the type is emitted - bool EmitType(utils::StringStream& out, + void EmitType(utils::StringStream& out, const type::Type* type, builtin::AddressSpace address_space, builtin::Access access, @@ -433,8 +374,7 @@ class GeneratorImpl : public TextGenerator { /// @param address_space the address space of the variable /// @param access the access control type of the variable /// @param name the name to emit - /// @returns true if the type is emitted - bool EmitTypeAndName(utils::StringStream& out, + void EmitTypeAndName(utils::StringStream& out, const type::Type* type, builtin::AddressSpace address_space, builtin::Access access, @@ -443,35 +383,28 @@ class GeneratorImpl : public TextGenerator { /// this function will simply return `true` without emitting anything. /// @param buffer the text buffer that the type declaration will be written to /// @param ty the struct to generate - /// @returns true if the struct is emitted - bool EmitStructType(TextBuffer* buffer, const sem::Struct* ty); + void EmitStructType(TextBuffer* buffer, const sem::Struct* ty); /// Handles generating the members of a structure /// @param buffer the text buffer that the struct members will be written to /// @param ty the struct to generate - /// @returns true if the struct members are emitted - bool EmitStructMembers(TextBuffer* buffer, const sem::Struct* ty); + void EmitStructMembers(TextBuffer* buffer, const sem::Struct* ty); /// Handles a unary op expression /// @param out the output of the expression stream /// @param expr the expression to emit - /// @returns true if the expression was emitted - bool EmitUnaryOp(utils::StringStream& out, const ast::UnaryOpExpression* expr); + void EmitUnaryOp(utils::StringStream& out, const ast::UnaryOpExpression* expr); /// Emits the zero value for the given type /// @param out the output stream /// @param type the type to emit the value for - /// @returns true if the zero value was successfully emitted. - bool EmitZeroValue(utils::StringStream& out, const type::Type* type); + void EmitZeroValue(utils::StringStream& out, const type::Type* type); /// Handles generating a 'var' declaration /// @param var the variable to generate - /// @returns true if the variable was emitted - bool EmitVar(const ast::Var* var); + void EmitVar(const ast::Var* var); /// Handles generating a function-scope 'let' declaration /// @param let the variable to generate - /// @returns true if the variable was emitted - bool EmitLet(const ast::Let* let); + void EmitLet(const ast::Let* let); /// Handles generating a module-scope 'let' declaration /// @param let the 'let' to emit - /// @returns true if the variable was emitted - bool EmitProgramConstVariable(const ast::Variable* let); + void EmitProgramConstVariable(const ast::Variable* let); /// Handles generating a builtin method name /// @param builtin the semantic info for the builtin /// @returns the name or "" if not valid @@ -510,9 +443,8 @@ class GeneratorImpl : public TextGenerator { /// Where: /// `buffer` is the body of the generated function /// `params` is the name of all the generated function parameters - /// @returns true if the call expression is emitted template - bool CallBuiltinHelper(utils::StringStream& out, + void CallBuiltinHelper(utils::StringStream& out, const ast::CallExpression* call, const sem::Builtin* builtin, F&& build); @@ -523,7 +455,7 @@ class GeneratorImpl : public TextGenerator { type::Type* BoolTypeToUint(const type::Type* type); TextBuffer helpers_; // Helper functions emitted at the top of the output - std::function emit_continuing_; + std::function emit_continuing_; std::unordered_map builtins_; std::unordered_map dynamic_vector_write_; std::unordered_map int_dot_funcs_; diff --git a/src/tint/writer/glsl/generator_impl_array_accessor_test.cc b/src/tint/writer/glsl/generator_impl_array_accessor_test.cc index 793902b19c..c194d647da 100644 --- a/src/tint/writer/glsl/generator_impl_array_accessor_test.cc +++ b/src/tint/writer/glsl/generator_impl_array_accessor_test.cc @@ -16,6 +16,8 @@ #include "src/tint/utils/string_stream.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::glsl { @@ -31,7 +33,8 @@ TEST_F(GlslGeneratorImplTest_Expression, IndexAccessor) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "ary[5]"); } diff --git a/src/tint/writer/glsl/generator_impl_assign_test.cc b/src/tint/writer/glsl/generator_impl_assign_test.cc index 63b8ce8c93..0adcac2d28 100644 --- a/src/tint/writer/glsl/generator_impl_assign_test.cc +++ b/src/tint/writer/glsl/generator_impl_assign_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::glsl { namespace { @@ -29,7 +31,8 @@ TEST_F(GlslGeneratorImplTest_Assign, Emit_Assign) { gen.increment_indent(); - ASSERT_TRUE(gen.EmitStatement(assign)) << gen.Diagnostics(); + gen.EmitStatement(assign); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), " lhs = rhs;\n"); } diff --git a/src/tint/writer/glsl/generator_impl_binary_test.cc b/src/tint/writer/glsl/generator_impl_binary_test.cc index 29e7136bc2..9be3fa4ff5 100644 --- a/src/tint/writer/glsl/generator_impl_binary_test.cc +++ b/src/tint/writer/glsl/generator_impl_binary_test.cc @@ -17,6 +17,8 @@ #include "src/tint/utils/string_stream.h" #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::glsl { @@ -59,7 +61,8 @@ TEST_P(GlslBinaryTest, Emit_f32) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), params.result); } TEST_P(GlslBinaryTest, Emit_f16) { @@ -87,7 +90,8 @@ TEST_P(GlslBinaryTest, Emit_f16) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), params.result); } TEST_P(GlslBinaryTest, Emit_u32) { @@ -106,7 +110,8 @@ TEST_P(GlslBinaryTest, Emit_u32) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), params.result); } TEST_P(GlslBinaryTest, Emit_i32) { @@ -130,7 +135,8 @@ TEST_P(GlslBinaryTest, Emit_i32) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), params.result); } INSTANTIATE_TEST_SUITE_P( @@ -165,7 +171,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Multiply_VectorScalar_f32) { GeneratorImpl& gen = Build(); utils::StringStream out; - EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "(a * 1.0f)"); } @@ -183,7 +190,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Multiply_VectorScalar_f16) { GeneratorImpl& gen = Build(); utils::StringStream out; - EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "(a * 1.0hf)"); } @@ -199,7 +207,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Multiply_ScalarVector_f32) { GeneratorImpl& gen = Build(); utils::StringStream out; - EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "(1.0f * a)"); } @@ -217,7 +226,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Multiply_ScalarVector_f16) { GeneratorImpl& gen = Build(); utils::StringStream out; - EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "(1.0hf * a)"); } @@ -232,7 +242,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Multiply_MatrixScalar_f32) { GeneratorImpl& gen = Build(); utils::StringStream out; - EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "(mat * 1.0f)"); } @@ -249,7 +260,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Multiply_MatrixScalar_f16) { GeneratorImpl& gen = Build(); utils::StringStream out; - EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "(mat * 1.0hf)"); } @@ -264,7 +276,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Multiply_ScalarMatrix_f32) { GeneratorImpl& gen = Build(); utils::StringStream out; - EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "(1.0f * mat)"); } @@ -281,7 +294,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Multiply_ScalarMatrix_f16) { GeneratorImpl& gen = Build(); utils::StringStream out; - EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "(1.0hf * mat)"); } @@ -296,7 +310,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Multiply_MatrixVector_f32) { GeneratorImpl& gen = Build(); utils::StringStream out; - EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "(mat * vec3(1.0f))"); } @@ -313,7 +328,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Multiply_MatrixVector_f16) { GeneratorImpl& gen = Build(); utils::StringStream out; - EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "(mat * f16vec3(1.0hf))"); } @@ -328,7 +344,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Multiply_VectorMatrix_f32) { GeneratorImpl& gen = Build(); utils::StringStream out; - EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "(vec3(1.0f) * mat)"); } @@ -345,7 +362,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Multiply_VectorMatrix_f16) { GeneratorImpl& gen = Build(); utils::StringStream out; - EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "(f16vec3(1.0hf) * mat)"); } @@ -359,7 +377,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Multiply_MatrixMatrix_f32) { GeneratorImpl& gen = Build(); utils::StringStream out; - EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "(lhs * rhs)"); } @@ -375,7 +394,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Multiply_MatrixMatrix_f16) { GeneratorImpl& gen = Build(); utils::StringStream out; - EXPECT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "(lhs * rhs)"); } @@ -389,7 +409,8 @@ TEST_F(GlslGeneratorImplTest_Binary, ModF32) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "tint_float_modulo(a, b)"); } @@ -405,7 +426,8 @@ TEST_F(GlslGeneratorImplTest_Binary, ModF16) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "tint_float_modulo(a, b)"); } @@ -419,7 +441,8 @@ TEST_F(GlslGeneratorImplTest_Binary, ModVec3F32) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "tint_float_modulo(a, b)"); } @@ -435,7 +458,8 @@ TEST_F(GlslGeneratorImplTest_Binary, ModVec3F16) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "tint_float_modulo(a, b)"); } @@ -449,7 +473,8 @@ TEST_F(GlslGeneratorImplTest_Binary, ModVec3F32ScalarF32) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "tint_float_modulo(a, b)"); } @@ -465,7 +490,8 @@ TEST_F(GlslGeneratorImplTest_Binary, ModVec3F16ScalarF16) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "tint_float_modulo(a, b)"); } @@ -479,7 +505,8 @@ TEST_F(GlslGeneratorImplTest_Binary, ModScalarF32Vec3F32) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "tint_float_modulo(a, b)"); } @@ -495,7 +522,8 @@ TEST_F(GlslGeneratorImplTest_Binary, ModScalarF16Vec3F16) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "tint_float_modulo(a, b)"); } @@ -513,7 +541,8 @@ TEST_F(GlslGeneratorImplTest_Binary, ModMixedVec3ScalarF32) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es vec3 tint_float_modulo(vec3 lhs, vec3 rhs) { @@ -557,7 +586,8 @@ TEST_F(GlslGeneratorImplTest_Binary, ModMixedVec3ScalarF16) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_AMD_gpu_shader_half_float : require @@ -596,7 +626,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Logical_And) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "(tint_tmp)"); EXPECT_EQ(gen.result(), R"(bool tint_tmp = a; if (tint_tmp) { @@ -621,7 +652,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Logical_Multi) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "(tint_tmp)"); EXPECT_EQ(gen.result(), R"(bool tint_tmp_1 = a; if (tint_tmp_1) { @@ -648,7 +680,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Logical_Or) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, expr)) << gen.Diagnostics(); + gen.EmitExpression(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "(tint_tmp)"); EXPECT_EQ(gen.result(), R"(bool tint_tmp = a; if (!tint_tmp) { @@ -679,7 +712,8 @@ TEST_F(GlslGeneratorImplTest_Binary, If_WithLogical) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.EmitStatement(expr)) << gen.Diagnostics(); + gen.EmitStatement(expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(bool tint_tmp = a; if (tint_tmp) { tint_tmp = b; @@ -715,7 +749,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Return_WithLogical) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.EmitStatement(expr)) << gen.Diagnostics(); + gen.EmitStatement(expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(bool tint_tmp_1 = a; if (tint_tmp_1) { tint_tmp_1 = b; @@ -746,7 +781,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Assign_WithLogical) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.EmitStatement(expr)) << gen.Diagnostics(); + gen.EmitStatement(expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(bool tint_tmp_1 = b; if (!tint_tmp_1) { tint_tmp_1 = c; @@ -778,7 +814,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Decl_WithLogical) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.EmitStatement(decl)) << gen.Diagnostics(); + gen.EmitStatement(decl); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(bool tint_tmp_1 = b; if (tint_tmp_1) { tint_tmp_1 = c; @@ -820,7 +857,8 @@ TEST_F(GlslGeneratorImplTest_Binary, Call_WithLogical) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.EmitStatement(expr)) << gen.Diagnostics(); + gen.EmitStatement(expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(bool tint_tmp = a; if (tint_tmp) { tint_tmp = b; diff --git a/src/tint/writer/glsl/generator_impl_bitcast_test.cc b/src/tint/writer/glsl/generator_impl_bitcast_test.cc index fc75cafa91..f3a7af028e 100644 --- a/src/tint/writer/glsl/generator_impl_bitcast_test.cc +++ b/src/tint/writer/glsl/generator_impl_bitcast_test.cc @@ -16,6 +16,8 @@ #include "src/tint/utils/string_stream.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::glsl { @@ -31,7 +33,8 @@ TEST_F(GlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Float) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, bitcast)) << gen.Diagnostics(); + gen.EmitExpression(out, bitcast); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "intBitsToFloat(a)"); } @@ -43,7 +46,8 @@ TEST_F(GlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Int) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, bitcast)) << gen.Diagnostics(); + gen.EmitExpression(out, bitcast); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "int(a)"); } @@ -55,7 +59,8 @@ TEST_F(GlslGeneratorImplTest_Bitcast, EmitExpression_Bitcast_Uint) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, bitcast)) << gen.Diagnostics(); + gen.EmitExpression(out, bitcast); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "uint(a)"); } diff --git a/src/tint/writer/glsl/generator_impl_block_test.cc b/src/tint/writer/glsl/generator_impl_block_test.cc index d9aec9fd93..1d76883e56 100644 --- a/src/tint/writer/glsl/generator_impl_block_test.cc +++ b/src/tint/writer/glsl/generator_impl_block_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::glsl { namespace { @@ -26,8 +28,8 @@ TEST_F(GlslGeneratorImplTest_Block, Emit_Block) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(b)) << gen.Diagnostics(); + gen.EmitStatement(b); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( { return; } diff --git a/src/tint/writer/glsl/generator_impl_break_test.cc b/src/tint/writer/glsl/generator_impl_break_test.cc index f3143ebffe..4912e0b4f9 100644 --- a/src/tint/writer/glsl/generator_impl_break_test.cc +++ b/src/tint/writer/glsl/generator_impl_break_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::glsl { namespace { @@ -26,8 +28,8 @@ TEST_F(GlslGeneratorImplTest_Break, Emit_Break) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(b)) << gen.Diagnostics(); + gen.EmitStatement(b); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), " break;\n"); } diff --git a/src/tint/writer/glsl/generator_impl_builtin_test.cc b/src/tint/writer/glsl/generator_impl_builtin_test.cc index 835db7ca93..e7d1a61547 100644 --- a/src/tint/writer/glsl/generator_impl_builtin_test.cc +++ b/src/tint/writer/glsl/generator_impl_builtin_test.cc @@ -351,7 +351,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Builtin_Call) { gen.increment_indent(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.Diagnostics(); + gen.EmitExpression(out, call); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "dot(param1, param2)"); } @@ -364,7 +365,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Select_Scalar) { gen.increment_indent(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.Diagnostics(); + gen.EmitExpression(out, call); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "(true ? b : a)"); } @@ -377,7 +379,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Select_Vector) { gen.increment_indent(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.Diagnostics(); + gen.EmitExpression(out, call); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "tint_select(a, b, bvec2(true, false))"); } @@ -394,7 +397,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, FMA_f32) { gen.increment_indent(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.Diagnostics(); + gen.EmitExpression(out, call); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "((a) * (b) + (c))"); } @@ -412,7 +416,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, FMA_f16) { gen.increment_indent(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.Diagnostics(); + gen.EmitExpression(out, call); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "((a) * (b) + (c))"); } @@ -422,7 +427,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Runtime_Modf_Scalar_f32) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es struct modf_result_f32 { @@ -458,7 +464,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Runtime_Modf_Scalar_f16) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_AMD_gpu_shader_half_float : require @@ -493,7 +500,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Runtime_Modf_Vector_f32) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es struct modf_result_vec3_f32 { @@ -529,7 +537,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Runtime_Modf_Vector_f16) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_AMD_gpu_shader_half_float : require @@ -563,7 +572,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Const_Modf_Scalar_f32) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es struct modf_result_f32 { @@ -591,7 +601,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Const_Modf_Scalar_f16) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_AMD_gpu_shader_half_float : require @@ -618,7 +629,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Const_Modf_Vector_f32) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es struct modf_result_vec3_f32 { @@ -646,7 +658,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Const_Modf_Vector_f16) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_AMD_gpu_shader_half_float : require @@ -674,7 +687,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Runtime_Frexp_Scalar_f32) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es struct frexp_result_f32 { @@ -710,7 +724,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Runtime_Frexp_Scalar_f16) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_AMD_gpu_shader_half_float : require @@ -745,7 +760,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Runtime_Frexp_Vector_f32) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es struct frexp_result_vec3_f32 { @@ -781,7 +797,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Runtime_Frexp_Vector_f16) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_AMD_gpu_shader_half_float : require @@ -815,7 +832,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Const_Frexp_Scalar_f32) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es struct frexp_result_f32 { @@ -843,7 +861,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Const_Frexp_Scalar_f16) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_AMD_gpu_shader_half_float : require @@ -870,7 +889,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Const_Frexp_Vector_f32) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es struct frexp_result_vec3_f32 { @@ -898,7 +918,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Const_Frexp_Vector_f16) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_AMD_gpu_shader_half_float : require @@ -927,7 +948,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Degrees_Scalar_f32) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es float tint_degrees(float param_0) { @@ -955,7 +977,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Degrees_Vector_f32) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es vec3 tint_degrees(vec3 param_0) { @@ -985,7 +1008,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Degrees_Scalar_f16) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_AMD_gpu_shader_half_float : require @@ -1016,7 +1040,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Degrees_Vector_f16) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_AMD_gpu_shader_half_float : require @@ -1045,7 +1070,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Radians_Scalar_f32) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es float tint_radians(float param_0) { @@ -1073,7 +1099,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Radians_Vector_f32) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es vec3 tint_radians(vec3 param_0) { @@ -1103,7 +1130,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Radians_Scalar_f16) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_AMD_gpu_shader_half_float : require @@ -1134,7 +1162,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Radians_Vector_f16) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_AMD_gpu_shader_half_float : require @@ -1165,7 +1194,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, ExtractBits) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es uvec3 tint_extract_bits(uvec3 v, uint offset, uint count) { @@ -1199,7 +1229,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, InsertBits) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es uvec3 tint_insert_bits(uvec3 v, uvec3 n, uint offset, uint count) { @@ -1230,7 +1261,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Pack4x8Snorm) { WrapInFunction(Decl(Var("r", call))); GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es vec4 p1 = vec4(0.0f, 0.0f, 0.0f, 0.0f); @@ -1248,7 +1280,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Pack4x8Unorm) { WrapInFunction(Decl(Var("r", call))); GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es vec4 p1 = vec4(0.0f, 0.0f, 0.0f, 0.0f); @@ -1266,7 +1299,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Pack2x16Snorm) { WrapInFunction(Decl(Var("r", call))); GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es vec2 p1 = vec2(0.0f, 0.0f); @@ -1284,7 +1318,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Pack2x16Unorm) { WrapInFunction(Decl(Var("r", call))); GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es vec2 p1 = vec2(0.0f, 0.0f); @@ -1302,7 +1337,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Pack2x16Float) { WrapInFunction(Decl(Var("r", call))); GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es vec2 p1 = vec2(0.0f, 0.0f); @@ -1320,7 +1356,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Unpack4x8Snorm) { WrapInFunction(Decl(Var("r", call))); GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es uint p1 = 0u; @@ -1338,7 +1375,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Unpack4x8Unorm) { WrapInFunction(Decl(Var("r", call))); GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es uint p1 = 0u; @@ -1356,7 +1394,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Unpack2x16Snorm) { WrapInFunction(Decl(Var("r", call))); GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es uint p1 = 0u; @@ -1374,7 +1413,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Unpack2x16Unorm) { WrapInFunction(Decl(Var("r", call))); GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es uint p1 = 0u; @@ -1392,7 +1432,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, Unpack2x16Float) { WrapInFunction(Decl(Var("r", call))); GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es uint p1 = 0u; @@ -1416,7 +1457,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, StorageBarrier) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; @@ -1439,7 +1481,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, WorkgroupBarrier) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; @@ -1456,7 +1499,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, DotI32) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es int tint_int_dot(ivec3 a, ivec3 b) { @@ -1482,7 +1526,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, DotU32) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es uint tint_int_dot(uvec3 a, uvec3 b) { @@ -1508,7 +1553,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, QuantizeToF16_Scalar) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es float tint_quantizeToF16(float param_0) { @@ -1535,7 +1581,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, QuantizeToF16_Vec2) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es vec2 tint_quantizeToF16(vec2 param_0) { @@ -1562,7 +1609,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, QuantizeToF16_Vec3) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es vec3 tint_quantizeToF16(vec3 param_0) { @@ -1591,7 +1639,8 @@ TEST_F(GlslGeneratorImplTest_Builtin, QuantizeToF16_Vec4) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es vec4 tint_quantizeToF16(vec4 param_0) { diff --git a/src/tint/writer/glsl/generator_impl_builtin_texture_test.cc b/src/tint/writer/glsl/generator_impl_builtin_texture_test.cc index acd2faab40..ca8abe4143 100644 --- a/src/tint/writer/glsl/generator_impl_builtin_texture_test.cc +++ b/src/tint/writer/glsl/generator_impl_builtin_texture_test.cc @@ -289,7 +289,8 @@ TEST_P(GlslGeneratorBuiltinTextureTest, Call) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); auto expected = expected_texture_overload(param.overload); diff --git a/src/tint/writer/glsl/generator_impl_call_test.cc b/src/tint/writer/glsl/generator_impl_call_test.cc index a1da7acdfe..b14cc9a8f8 100644 --- a/src/tint/writer/glsl/generator_impl_call_test.cc +++ b/src/tint/writer/glsl/generator_impl_call_test.cc @@ -16,6 +16,8 @@ #include "src/tint/utils/string_stream.h" #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::glsl { @@ -32,7 +34,8 @@ TEST_F(GlslGeneratorImplTest_Call, EmitExpression_Call_WithoutParams) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.Diagnostics(); + gen.EmitExpression(out, call); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "my_func()"); } @@ -52,7 +55,8 @@ TEST_F(GlslGeneratorImplTest_Call, EmitExpression_Call_WithParams) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, call)) << gen.Diagnostics(); + gen.EmitExpression(out, call); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "my_func(param1, param2)"); } @@ -72,7 +76,8 @@ TEST_F(GlslGeneratorImplTest_Call, EmitStatement_Call) { GeneratorImpl& gen = Build(); gen.increment_indent(); - ASSERT_TRUE(gen.EmitStatement(call)) << gen.Diagnostics(); + gen.EmitStatement(call); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), " my_func(param1, param2);\n"); } diff --git a/src/tint/writer/glsl/generator_impl_case_test.cc b/src/tint/writer/glsl/generator_impl_case_test.cc index 39d5081fb4..3707f6b905 100644 --- a/src/tint/writer/glsl/generator_impl_case_test.cc +++ b/src/tint/writer/glsl/generator_impl_case_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::glsl { @@ -29,8 +31,7 @@ TEST_F(GlslGeneratorImplTest_Case, Emit_Case) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.Diagnostics(); + gen.EmitCase(s->body[0]); EXPECT_EQ(gen.result(), R"( case 5: { break; } @@ -44,8 +45,8 @@ TEST_F(GlslGeneratorImplTest_Case, Emit_Case_BreaksByDefault) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.Diagnostics(); + gen.EmitCase(s->body[0]); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( case 5: { break; } @@ -66,8 +67,8 @@ TEST_F(GlslGeneratorImplTest_Case, Emit_Case_MultipleSelectors) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.Diagnostics(); + gen.EmitCase(s->body[0]); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( case 5: case 6: { break; @@ -82,8 +83,8 @@ TEST_F(GlslGeneratorImplTest_Case, Emit_Case_Default) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitCase(s->body[0])) << gen.Diagnostics(); + gen.EmitCase(s->body[0]); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( default: { break; } diff --git a/src/tint/writer/glsl/generator_impl_cast_test.cc b/src/tint/writer/glsl/generator_impl_cast_test.cc index 9b57e4bd2c..4773a4b34c 100644 --- a/src/tint/writer/glsl/generator_impl_cast_test.cc +++ b/src/tint/writer/glsl/generator_impl_cast_test.cc @@ -15,6 +15,8 @@ #include "src/tint/utils/string_stream.h" #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::glsl { @@ -29,7 +31,8 @@ TEST_F(GlslGeneratorImplTest_Cast, EmitExpression_Cast_Scalar) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, cast)) << gen.Diagnostics(); + gen.EmitExpression(out, cast); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "1.0f"); } @@ -40,7 +43,8 @@ TEST_F(GlslGeneratorImplTest_Cast, EmitExpression_Cast_Vector) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, cast)) << gen.Diagnostics(); + gen.EmitExpression(out, cast); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "vec3(1.0f, 2.0f, 3.0f)"); } diff --git a/src/tint/writer/glsl/generator_impl_constructor_test.cc b/src/tint/writer/glsl/generator_impl_constructor_test.cc index 35bd2fb8aa..2983382e4d 100644 --- a/src/tint/writer/glsl/generator_impl_constructor_test.cc +++ b/src/tint/writer/glsl/generator_impl_constructor_test.cc @@ -28,8 +28,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Bool) { WrapInFunction(Expr(false)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("false")); } @@ -37,8 +37,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Int) { WrapInFunction(Expr(-12345_i)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("-12345")); } @@ -46,8 +46,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, UInt) { WrapInFunction(Expr(56779_u)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("56779u")); } @@ -56,8 +56,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Float) { WrapInFunction(Expr(f32((1 << 30) - 4))); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("1073741824.0f")); } @@ -68,8 +68,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, F16) { WrapInFunction(Expr(f16((1 << 15) - 8))); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("32752.0hf")); } @@ -77,8 +77,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Float) { WrapInFunction(Call(-1.2e-5_f)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("-0.00001200000042445026f")); } @@ -88,8 +88,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_F16) { WrapInFunction(Call(-1.2e-3_h)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("-0.0011997222900390625hf")); } @@ -97,8 +97,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Bool) { WrapInFunction(Call(true)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("true")); } @@ -106,8 +106,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Int) { WrapInFunction(Call(-12345_i)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("-12345")); } @@ -115,8 +115,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Uint) { WrapInFunction(Call(12345_u)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("12345u")); } @@ -124,8 +124,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Vec_F32) { WrapInFunction(vec3(1_f, 2_f, 3_f)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("vec3(1.0f, 2.0f, 3.0f)")); } @@ -135,8 +135,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Vec_F16) { WrapInFunction(vec3(1_h, 2_h, 3_h)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("f16vec3(1.0hf, 2.0hf, 3.0hf)")); } @@ -144,8 +144,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Vec_Empty_F32) { WrapInFunction(vec3()); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("vec3(0.0f)")); } @@ -155,8 +155,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Vec_Empty_F16) { WrapInFunction(vec3()); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("f16vec3(0.0hf)")); } @@ -164,8 +164,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Vec_SingleScalar_F32_Literal) { WrapInFunction(vec3(2_f)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("vec3(2.0f)")); } @@ -175,8 +175,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Vec_SingleScalar_F16_Literal) { WrapInFunction(vec3(2_h)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("f16vec3(2.0hf)")); } @@ -186,8 +186,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Vec_SingleScalar_F32_Var) { WrapInFunction(var, cast); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr(R"(float v = 2.0f; vec3 tint_symbol = vec3(v);)")); } @@ -200,8 +200,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Vec_SingleScalar_F16_Var) { WrapInFunction(var, cast); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr(R"(float16_t v = 2.0hf; f16vec3 tint_symbol = f16vec3(v);)")); } @@ -210,8 +210,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Vec_SingleScalar_Bool) { WrapInFunction(vec3(true)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("bvec3(true)")); } @@ -219,8 +219,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Vec_SingleScalar_Int) { WrapInFunction(vec3(2_i)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("ivec3(2)")); } @@ -228,8 +228,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Vec_SingleScalar_UInt) { WrapInFunction(vec3(2_u)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("uvec3(2u)")); } @@ -237,9 +237,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Mat_F32) { WrapInFunction(mat2x3(vec3(1_f, 2_f, 3_f), vec3(3_f, 4_f, 5_f))); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("mat2x3(vec3(1.0f, 2.0f, 3.0f), vec3(3.0f, 4.0f, 5.0f))")); } @@ -249,9 +248,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Mat_F16) { WrapInFunction(mat2x3(vec3(1_h, 2_h, 3_h), vec3(3_h, 4_h, 5_h))); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("f16mat2x3(f16vec3(1.0hf, 2.0hf, 3.0hf), f16vec3(3.0hf, 4.0hf, 5.0hf))")); } @@ -276,9 +274,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Mat_Complex_F32) { WrapInFunction(ctor); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("mat4(vec4(2.0f, 3.0f, 4.0f, 8.0f), vec4(0.0f), " "vec4(7.0f), vec4(42.0f, 21.0f, 6.0f, -5.0f))")); } @@ -305,9 +302,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Mat_Complex_F16) { WrapInFunction(ctor); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("f16mat4(f16vec4(2.0hf, 3.0hf, 4.0hf, 8.0hf), f16vec4(0.0hf), " "f16vec4(7.0hf), f16vec4(42.0hf, 21.0hf, 6.0hf, -5.0hf))")); @@ -317,9 +313,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Mat_Empty_F32) { WrapInFunction(mat2x3()); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("mat2x3 tint_symbol = mat2x3(vec3(0.0f), vec3(0.0f))")); } @@ -329,9 +324,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Mat_Empty_F16) { WrapInFunction(mat2x3()); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("f16mat2x3 tint_symbol = f16mat2x3(f16vec3(0.0hf), f16vec3(0.0hf))")); } @@ -348,9 +342,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Mat_Identity_F32) { WrapInFunction(m_1, m_2); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("mat4 m_2 = mat4(m_1);")); } @@ -368,9 +361,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Mat_Identity_F16) { WrapInFunction(m_1, m_2); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("f16mat4 m_2 = f16mat4(m_1);")); } @@ -379,8 +371,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Array) { vec3(4_f, 5_f, 6_f), vec3(7_f, 8_f, 9_f))); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("vec3[3](vec3(1.0f, 2.0f, 3.0f), " "vec3(4.0f, 5.0f, 6.0f), " "vec3(7.0f, 8.0f, 9.0f))")); @@ -390,8 +382,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Array_Empty) { WrapInFunction(Call(ty.array(ty.vec3(), 3_u))); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("vec3[3](vec3(0.0f), vec3(0.0f), vec3(0.0f))")); } @@ -405,8 +397,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Struct) { WrapInFunction(Call(ty.Of(str), 1_i, 2_f, vec3(3_i, 4_i, 5_i))); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("S(1, 2.0f, ivec3(3, 4, 5))")); } @@ -420,8 +412,8 @@ TEST_F(GlslGeneratorImplTest_Constructor, Type_Struct_Empty) { WrapInFunction(Call(ty.Of(str))); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("S(0")); } diff --git a/src/tint/writer/glsl/generator_impl_continue_test.cc b/src/tint/writer/glsl/generator_impl_continue_test.cc index 3ea8db6eb0..2c4cdfb734 100644 --- a/src/tint/writer/glsl/generator_impl_continue_test.cc +++ b/src/tint/writer/glsl/generator_impl_continue_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::glsl { namespace { @@ -27,7 +29,8 @@ TEST_F(GlslGeneratorImplTest_Continue, Emit_Continue) { gen.increment_indent(); - ASSERT_TRUE(gen.EmitStatement(loop)) << gen.Diagnostics(); + gen.EmitStatement(loop); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( while (true) { if (false) { break; diff --git a/src/tint/writer/glsl/generator_impl_discard_test.cc b/src/tint/writer/glsl/generator_impl_discard_test.cc index a66ac1cf5c..cb92414c51 100644 --- a/src/tint/writer/glsl/generator_impl_discard_test.cc +++ b/src/tint/writer/glsl/generator_impl_discard_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::glsl { namespace { @@ -28,8 +30,8 @@ TEST_F(GlslGeneratorImplTest_Discard, Emit_Discard) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.Diagnostics(); + gen.EmitStatement(stmt); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), " discard;\n"); } diff --git a/src/tint/writer/glsl/generator_impl_function_test.cc b/src/tint/writer/glsl/generator_impl_function_test.cc index ec72ef7688..a0bfef952a 100644 --- a/src/tint/writer/glsl/generator_impl_function_test.cc +++ b/src/tint/writer/glsl/generator_impl_function_test.cc @@ -36,8 +36,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Function) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( #version 310 es void my_func() { @@ -56,8 +56,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Function_Name_Collision) { GeneratorImpl& gen = SanitizeAndBuild(); gen.increment_indent(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr(R"( void tint_symbol() { return; })")); @@ -77,8 +77,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Function_WithParams) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( #version 310 es void my_func(float a, int b) { @@ -95,8 +95,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_NoReturn_Void) }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es precision highp float; @@ -114,8 +114,8 @@ TEST_F(GlslGeneratorImplTest_Function, PtrParameter) { ty.f32(), utils::Vector{Return(Deref("foo"))}); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr(R"(float f(inout float foo) { return foo; } @@ -142,8 +142,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_WithInOutVars) }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es precision highp float; @@ -183,8 +183,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_WithInOut_Built }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es precision highp float; @@ -236,8 +236,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_SharedStruct_Di utils::Vector{Stage(ast::PipelineStage::kFragment)}); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es precision highp float; @@ -375,8 +375,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_Uniform) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es precision highp float; @@ -416,8 +416,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_UniformStr }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es precision highp float; @@ -457,8 +457,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_RW_Storage }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es precision highp float; @@ -504,8 +504,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_RO_Storage }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es precision highp float; @@ -550,8 +550,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_WO_Storage }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es precision highp float; @@ -595,8 +595,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_With_StorageBuf }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es precision highp float; @@ -642,8 +642,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_Called_By_EntryPoint_With_ }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es precision highp float; @@ -688,8 +688,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_Called_By_EntryPoint_With_ }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es precision highp float; @@ -725,8 +725,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_WithNameCollisi }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es precision highp float; @@ -751,8 +751,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_Compute) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in; @@ -770,8 +770,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_Compute_WithWor }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es layout(local_size_x = 2, local_size_y = 4, local_size_z = 6) in; @@ -792,8 +792,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Attribute_EntryPoint_Compute_WithWor }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es layout(local_size_x = 2, local_size_y = 3, local_size_z = 4) in; @@ -815,11 +815,13 @@ TEST_F(GlslGeneratorImplTest_Function, }); GeneratorImpl& gen = Build(); - - EXPECT_FALSE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); EXPECT_EQ( gen.Diagnostics().str(), - R"(error: override-expressions should have been removed with the SubstituteOverride transform)"); + R"(error: override-expressions should have been removed with the SubstituteOverride transform +error: override-expressions should have been removed with the SubstituteOverride transform +error: override-expressions should have been removed with the SubstituteOverride transform +error: override-expressions should have been removed with the SubstituteOverride transform)"); } TEST_F(GlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) { @@ -829,8 +831,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Function_WithArrayParams) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void my_func(float a[5]) { @@ -847,8 +849,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Function_WithArrayReturn) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es float[5] my_func() { @@ -911,8 +913,8 @@ TEST_F(GlslGeneratorImplTest_Function, Emit_Multiple_EntryPoint_With_Same_Module } GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es struct Data { diff --git a/src/tint/writer/glsl/generator_impl_identifier_test.cc b/src/tint/writer/glsl/generator_impl_identifier_test.cc index 35602951cb..61f0236d76 100644 --- a/src/tint/writer/glsl/generator_impl_identifier_test.cc +++ b/src/tint/writer/glsl/generator_impl_identifier_test.cc @@ -15,6 +15,8 @@ #include "src/tint/utils/string_stream.h" #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::glsl { namespace { @@ -29,7 +31,8 @@ TEST_F(GlslGeneratorImplTest_Identifier, EmitIdentifierExpression) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, i)) << gen.Diagnostics(); + gen.EmitExpression(out, i); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "foo"); } diff --git a/src/tint/writer/glsl/generator_impl_if_test.cc b/src/tint/writer/glsl/generator_impl_if_test.cc index b474d2c214..8fb302a615 100644 --- a/src/tint/writer/glsl/generator_impl_if_test.cc +++ b/src/tint/writer/glsl/generator_impl_if_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::glsl { namespace { @@ -30,7 +32,8 @@ TEST_F(GlslGeneratorImplTest_If, Emit_If) { GeneratorImpl& gen = Build(); gen.increment_indent(); - ASSERT_TRUE(gen.EmitStatement(i)) << gen.Diagnostics(); + gen.EmitStatement(i); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( if (cond) { return; } @@ -52,8 +55,8 @@ TEST_F(GlslGeneratorImplTest_If, Emit_IfWithElseIf) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(i)) << gen.Diagnostics(); + gen.EmitStatement(i); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( if (cond) { return; } else { @@ -77,8 +80,8 @@ TEST_F(GlslGeneratorImplTest_If, Emit_IfWithElse) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(i)) << gen.Diagnostics(); + gen.EmitStatement(i); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( if (cond) { return; } else { @@ -92,9 +95,7 @@ TEST_F(GlslGeneratorImplTest_If, Emit_IfWithMultiple) { GlobalVar("else_cond", ty.bool_(), builtin::AddressSpace::kPrivate); auto* else_cond = Expr("else_cond"); - auto* else_body = Block(Return()); - auto* else_body_2 = Block(Return()); auto* cond = Expr("cond"); @@ -105,8 +106,8 @@ TEST_F(GlslGeneratorImplTest_If, Emit_IfWithMultiple) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(i)) << gen.Diagnostics(); + gen.EmitStatement(i); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( if (cond) { return; } else { diff --git a/src/tint/writer/glsl/generator_impl_import_test.cc b/src/tint/writer/glsl/generator_impl_import_test.cc index c7e3a9720c..6f772ea080 100644 --- a/src/tint/writer/glsl/generator_impl_import_test.cc +++ b/src/tint/writer/glsl/generator_impl_import_test.cc @@ -15,6 +15,8 @@ #include "src/tint/utils/string_stream.h" #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::glsl { @@ -41,7 +43,8 @@ TEST_P(GlslImportData_SingleParamTest, FloatScalar) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.Diagnostics(); + gen.EmitCall(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), std::string(param.glsl_name) + "(1.0f)"); } INSTANTIATE_TEST_SUITE_P(GlslGeneratorImplTest_Import, @@ -80,7 +83,8 @@ TEST_P(GlslImportData_SingleIntParamTest, IntScalar) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.Diagnostics(); + gen.EmitCall(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), std::string(param.glsl_name) + "(1)"); } INSTANTIATE_TEST_SUITE_P(GlslGeneratorImplTest_Import, @@ -97,7 +101,8 @@ TEST_P(GlslImportData_SingleVectorParamTest, FloatVector) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.Diagnostics(); + gen.EmitCall(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ( out.str(), std::string(param.glsl_name) + @@ -140,7 +145,8 @@ TEST_P(GlslImportData_DualParam_ScalarTest, Float) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.Diagnostics(); + gen.EmitCall(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), std::string(param.glsl_name) + "(1.0f, 2.0f)"); } INSTANTIATE_TEST_SUITE_P(GlslGeneratorImplTest_Import, @@ -162,7 +168,8 @@ TEST_P(GlslImportData_DualParam_VectorTest, Float) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.Diagnostics(); + gen.EmitCall(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), std::string(param.glsl_name) + "(vec3(1.0f, 2.0f, 3.0f), vec3(4.0f, 5.0f, 6.0f))"); } @@ -187,7 +194,8 @@ TEST_P(GlslImportData_DualParam_Int_Test, IntScalar) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.Diagnostics(); + gen.EmitCall(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), std::string(param.glsl_name) + "(1, 2)"); } INSTANTIATE_TEST_SUITE_P(GlslGeneratorImplTest_Import, @@ -205,7 +213,8 @@ TEST_P(GlslImportData_TripleParam_ScalarTest, Float) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.Diagnostics(); + gen.EmitCall(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), std::string(param.glsl_name) + "(1.0f, 2.0f, 3.0f)"); } INSTANTIATE_TEST_SUITE_P(GlslGeneratorImplTest_Import, @@ -225,7 +234,8 @@ TEST_P(GlslImportData_TripleParam_VectorTest, Float) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.Diagnostics(); + gen.EmitCall(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), std::string(param.glsl_name) + R"((vec3(1.0f, 2.0f, 3.0f), vec3(4.0f, 5.0f, 6.0f), vec3(7.0f, 8.0f, 9.0f)))"); @@ -246,7 +256,8 @@ TEST_P(GlslImportData_TripleParam_Int_Test, IntScalar) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.Diagnostics(); + gen.EmitCall(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), std::string(param.glsl_name) + "(1, 2, 3)"); } INSTANTIATE_TEST_SUITE_P(GlslGeneratorImplTest_Import, @@ -262,7 +273,8 @@ TEST_F(GlslGeneratorImplTest_Import, GlslImportData_Determinant) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitCall(out, expr)) << gen.Diagnostics(); + gen.EmitCall(out, expr); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), std::string("determinant(var)")); } diff --git a/src/tint/writer/glsl/generator_impl_loop_test.cc b/src/tint/writer/glsl/generator_impl_loop_test.cc index 3d23e1e681..714d38b5bb 100644 --- a/src/tint/writer/glsl/generator_impl_loop_test.cc +++ b/src/tint/writer/glsl/generator_impl_loop_test.cc @@ -15,6 +15,8 @@ #include "src/tint/ast/variable_decl_statement.h" #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::glsl { @@ -33,8 +35,8 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_Loop) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(l)) << gen.Diagnostics(); + gen.EmitStatement(l); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( while (true) { break; } @@ -54,8 +56,8 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_LoopWithContinuing) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(l)) << gen.Diagnostics(); + gen.EmitStatement(l); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( while (true) { break; { @@ -78,8 +80,8 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_LoopWithContinuing_BreakIf) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(l)) << gen.Diagnostics(); + gen.EmitStatement(l); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( while (true) { break; { @@ -115,8 +117,8 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_LoopNestedWithContinuing) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(outer)) << gen.Diagnostics(); + gen.EmitStatement(outer); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( while (true) { while (true) { break; @@ -154,8 +156,8 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_LoopWithVarUsedInContinuing) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(outer)) << gen.Diagnostics(); + gen.EmitStatement(outer); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( while (true) { float lhs = 2.5f; float other = 0.0f; @@ -179,8 +181,8 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoop) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); + gen.EmitStatement(f); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( { for(; ; ) { return; @@ -201,8 +203,8 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithSimpleInit) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); + gen.EmitStatement(f); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( { for(int i = 0; ; ) { return; @@ -225,8 +227,8 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtInit) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); + gen.EmitStatement(f); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( { bool tint_tmp = t; if (tint_tmp) { @@ -253,8 +255,8 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithSimpleCond) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); + gen.EmitStatement(f); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( { for(; true; ) { a_statement(); @@ -278,8 +280,8 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtCond) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); + gen.EmitStatement(f); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( { while (true) { bool tint_tmp = t; @@ -306,8 +308,8 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithSimpleCont) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); + gen.EmitStatement(f); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( { for(; ; i = (i + 1)) { return; @@ -332,8 +334,8 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtCont) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); + gen.EmitStatement(f); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( { while (true) { return; @@ -358,8 +360,8 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithSimpleInitCondCont) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); + gen.EmitStatement(f); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( { for(int i = 0; true; i = (i + 1)) { return; @@ -386,8 +388,8 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_ForLoopWithMultiStmtInitCondCont) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); + gen.EmitStatement(f); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( { bool tint_tmp = t; if (tint_tmp) { @@ -422,8 +424,8 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_While) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); + gen.EmitStatement(f); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( while(true) { return; } @@ -441,8 +443,8 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_While_WithContinue) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); + gen.EmitStatement(f); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( while(true) { continue; } @@ -465,8 +467,8 @@ TEST_F(GlslGeneratorImplTest_Loop, Emit_WhileWithMultiStmtCond) { GeneratorImpl& gen = Build(); gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(f)) << gen.Diagnostics(); + gen.EmitStatement(f); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( while (true) { bool tint_tmp = t; if (tint_tmp) { diff --git a/src/tint/writer/glsl/generator_impl_member_accessor_test.cc b/src/tint/writer/glsl/generator_impl_member_accessor_test.cc index cfb36ead72..041e72c997 100644 --- a/src/tint/writer/glsl/generator_impl_member_accessor_test.cc +++ b/src/tint/writer/glsl/generator_impl_member_accessor_test.cc @@ -12,10 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "gmock/gmock.h" #include "src/tint/ast/stage_attribute.h" #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::glsl { @@ -118,8 +119,8 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, EmitExpression_MemberAccessor) { WrapInFunction(Var("expr", ty.f32(), expr)); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es struct Data { @@ -169,8 +170,8 @@ TEST_P(GlslGeneratorImplTest_MemberAccessor_StorageBufferLoad, Test) { }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr(p.expected)); } @@ -222,7 +223,8 @@ TEST_P(GlslGeneratorImplTest_MemberAccessor_StorageBufferStore, Test) { GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr(p.expected)); } @@ -277,8 +279,9 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, StorageBuffer_Store_Matrix_Empty) { }); GeneratorImpl& gen = SanitizeAndBuild(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); auto* expected = R"(#version 310 es precision highp float; @@ -330,8 +333,8 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, StorageBuffer_Load_Matrix_Single_El }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); auto* expected = R"(#version 310 es precision highp float; @@ -378,8 +381,8 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); auto* expected = R"(#version 310 es precision highp float; @@ -426,8 +429,8 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); auto* expected = R"(#version 310 es precision highp float; @@ -473,8 +476,8 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, StorageBuffer_Store_ToArray) { }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); auto* expected = R"(#version 310 es precision highp float; @@ -526,8 +529,8 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, StorageBuffer_Load_MultiLevel) { }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); auto* expected = R"(#version 310 es precision highp float; @@ -587,8 +590,8 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, StorageBuffer_Load_MultiLevel_Swizz }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); auto* expected = R"(#version 310 es precision highp float; @@ -649,8 +652,8 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); auto* expected = R"(#version 310 es precision highp float; @@ -710,8 +713,8 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, StorageBuffer_Load_MultiLevel_Index }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); auto* expected = R"(#version 310 es precision highp float; @@ -770,8 +773,8 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, StorageBuffer_Store_MultiLevel) { }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); auto* expected = R"(#version 310 es precision highp float; @@ -831,8 +834,8 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, StorageBuffer_Store_Swizzle_SingleL }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); auto* expected = R"(#version 310 es precision highp float; @@ -870,7 +873,8 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, Swizzle_xyz) { WrapInFunction(var, expr); GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("my_vec.xyz")); } @@ -880,7 +884,8 @@ TEST_F(GlslGeneratorImplTest_MemberAccessor, Swizzle_gbr) { WrapInFunction(var, expr); GeneratorImpl& gen = SanitizeAndBuild(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("my_vec.gbr")); } diff --git a/src/tint/writer/glsl/generator_impl_module_constant_test.cc b/src/tint/writer/glsl/generator_impl_module_constant_test.cc index adcfa50ce4..8de0dd00aa 100644 --- a/src/tint/writer/glsl/generator_impl_module_constant_test.cc +++ b/src/tint/writer/glsl/generator_impl_module_constant_test.cc @@ -15,6 +15,8 @@ #include "src/tint/ast/id_attribute.h" #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::glsl { @@ -27,8 +29,8 @@ TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_GlobalLet) { WrapInFunction(Decl(var)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.EmitProgramConstVariable(var)) << gen.Diagnostics(); + gen.EmitProgramConstVariable(var); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), "const float pos[3] = float[3](1.0f, 2.0f, 3.0f);\n"); } @@ -40,9 +42,8 @@ TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_AInt) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -60,9 +61,8 @@ TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_AFloat) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -80,9 +80,8 @@ TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_i32) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -100,9 +99,8 @@ TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_u32) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -120,9 +118,8 @@ TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_f32) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -142,9 +139,8 @@ TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_f16) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_AMD_gpu_shader_half_float : require @@ -163,9 +159,8 @@ TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_vec3_AInt) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -183,9 +178,8 @@ TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_vec3_AFloat) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -203,9 +197,8 @@ TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_vec3_f32) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -225,9 +218,8 @@ TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_vec3_f16) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_AMD_gpu_shader_half_float : require @@ -246,9 +238,8 @@ TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_mat2x3_AFloat) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -266,9 +257,8 @@ TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_mat2x3_f32) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -288,9 +278,8 @@ TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_mat2x3_f16) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_AMD_gpu_shader_half_float : require @@ -309,9 +298,8 @@ TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_arr_f32) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -332,9 +320,8 @@ TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_arr_vec2_bool) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { diff --git a/src/tint/writer/glsl/generator_impl_return_test.cc b/src/tint/writer/glsl/generator_impl_return_test.cc index ce082d8b49..d8ddc4c296 100644 --- a/src/tint/writer/glsl/generator_impl_return_test.cc +++ b/src/tint/writer/glsl/generator_impl_return_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::glsl { @@ -26,10 +28,9 @@ TEST_F(GlslGeneratorImplTest_Return, Emit_Return) { WrapInFunction(r); GeneratorImpl& gen = Build(); - gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(r)) << gen.Diagnostics(); + gen.EmitStatement(r); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), " return;\n"); } @@ -38,10 +39,9 @@ TEST_F(GlslGeneratorImplTest_Return, Emit_ReturnWithValue) { Func("f", utils::Empty, ty.i32(), utils::Vector{r}); GeneratorImpl& gen = Build(); - gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(r)) << gen.Diagnostics(); + gen.EmitStatement(r); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), " return 123;\n"); } diff --git a/src/tint/writer/glsl/generator_impl_sanitizer_test.cc b/src/tint/writer/glsl/generator_impl_sanitizer_test.cc index 097b519503..5a690a5019 100644 --- a/src/tint/writer/glsl/generator_impl_sanitizer_test.cc +++ b/src/tint/writer/glsl/generator_impl_sanitizer_test.cc @@ -17,6 +17,8 @@ #include "src/tint/ast/variable_decl_statement.h" #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::glsl { @@ -38,8 +40,8 @@ TEST_F(GlslSanitizerTest, Call_ArrayLength) { }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); auto got = gen.result(); auto* expect = R"(#version 310 es @@ -78,8 +80,8 @@ TEST_F(GlslSanitizerTest, Call_ArrayLength_OtherMembersInStruct) { }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); auto got = gen.result(); auto* expect = R"(#version 310 es @@ -122,8 +124,8 @@ TEST_F(GlslSanitizerTest, Call_ArrayLength_ViaLets) { }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); auto got = gen.result(); auto* expect = R"(#version 310 es @@ -159,8 +161,8 @@ TEST_F(GlslSanitizerTest, PromoteArrayInitializerToConstVar) { }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); auto got = gen.result(); auto* expect = R"(#version 310 es @@ -201,8 +203,8 @@ TEST_F(GlslSanitizerTest, PromoteStructInitializerToConstVar) { }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); auto got = gen.result(); auto* expect = R"(#version 310 es @@ -247,8 +249,8 @@ TEST_F(GlslSanitizerTest, SimplifyPointersBasic) { }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); auto got = gen.result(); auto* expect = R"(#version 310 es @@ -296,8 +298,8 @@ TEST_F(GlslSanitizerTest, SimplifyPointersComplexChain) { }); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); auto got = gen.result(); auto* expect = R"(#version 310 es diff --git a/src/tint/writer/glsl/generator_impl_storage_buffer_test.cc b/src/tint/writer/glsl/generator_impl_storage_buffer_test.cc index 4251cb37ad..821b0e9ddd 100644 --- a/src/tint/writer/glsl/generator_impl_storage_buffer_test.cc +++ b/src/tint/writer/glsl/generator_impl_storage_buffer_test.cc @@ -12,10 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "gmock/gmock.h" #include "src/tint/number.h" #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + using ::testing::HasSubstr; using namespace tint::number_suffixes; // NOLINT @@ -48,7 +49,8 @@ TEST_F(GlslGeneratorImplTest_StorageBuffer, Align) { // TODO(crbug.com/tint/1421) offsets do not currently work on GLSL ES. // They will likely require manual padding. - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es struct Nephews { @@ -70,8 +72,8 @@ TEST_F(GlslGeneratorImplTest_StorageBuffer, Align_Desktop) { TestAlign(this); GeneratorImpl& gen = Build(Version(Version::Standard::kDesktop, 4, 4)); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 440 struct Nephews { diff --git a/src/tint/writer/glsl/generator_impl_switch_test.cc b/src/tint/writer/glsl/generator_impl_switch_test.cc index 34184cffcc..f5b7e1bc51 100644 --- a/src/tint/writer/glsl/generator_impl_switch_test.cc +++ b/src/tint/writer/glsl/generator_impl_switch_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::glsl { @@ -35,10 +37,9 @@ TEST_F(GlslGeneratorImplTest_Switch, Emit_Switch) { WrapInFunction(s); GeneratorImpl& gen = Build(); - gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(s)) << gen.Diagnostics(); + gen.EmitStatement(s); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( switch(cond) { case 5: { break; @@ -62,10 +63,9 @@ TEST_F(GlslGeneratorImplTest_Switch, Emit_Switch_MixedDefault) { WrapInFunction(s); GeneratorImpl& gen = Build(); - gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(s)) << gen.Diagnostics(); + gen.EmitStatement(s); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"( switch(cond) { case 5: default: { diff --git a/src/tint/writer/glsl/generator_impl_test.cc b/src/tint/writer/glsl/generator_impl_test.cc index e5ce52e484..a1b08b760d 100644 --- a/src/tint/writer/glsl/generator_impl_test.cc +++ b/src/tint/writer/glsl/generator_impl_test.cc @@ -14,6 +14,8 @@ #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::glsl { namespace { @@ -32,8 +34,8 @@ TEST_F(GlslGeneratorImplTest, Generate) { Func("my_func", utils::Empty, ty.void_(), utils::Empty); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void my_func() { @@ -46,8 +48,8 @@ TEST_F(GlslGeneratorImplTest, GenerateDesktop) { Func("my_func", utils::Empty, ty.void_(), utils::Empty); GeneratorImpl& gen = Build(Version(Version::Standard::kDesktop, 4, 4)); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 440 void my_func() { @@ -69,8 +71,8 @@ TEST_F(GlslGeneratorImplTest, GenerateSampleIndexES) { }); GeneratorImpl& gen = Build(Version(Version::Standard::kES, 3, 1)); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_OES_sample_variables : require @@ -94,8 +96,8 @@ TEST_F(GlslGeneratorImplTest, GenerateSampleIndexDesktop) { }); GeneratorImpl& gen = Build(Version(Version::Standard::kDesktop, 4, 4)); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 440 int my_func() { diff --git a/src/tint/writer/glsl/generator_impl_type_test.cc b/src/tint/writer/glsl/generator_impl_type_test.cc index 3da9cd7344..0e85155a72 100644 --- a/src/tint/writer/glsl/generator_impl_type_test.cc +++ b/src/tint/writer/glsl/generator_impl_type_test.cc @@ -12,7 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "gmock/gmock.h" #include "src/tint/ast/call_statement.h" #include "src/tint/ast/stage_attribute.h" #include "src/tint/type/depth_texture.h" @@ -24,6 +23,8 @@ #include "src/tint/utils/string_stream.h" #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + using ::testing::HasSubstr; using namespace tint::number_suffixes; // NOLINT @@ -40,9 +41,9 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Array) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), builtin::AddressSpace::kUndefined, - builtin::Access::kReadWrite, "ary")) - << gen.Diagnostics(); + gen.EmitType(out, program->TypeOf(ty), builtin::AddressSpace::kUndefined, + builtin::Access::kReadWrite, "ary"); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "bool ary[4]"); } @@ -53,9 +54,9 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_ArrayOfArray) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), builtin::AddressSpace::kUndefined, - builtin::Access::kReadWrite, "ary")) - << gen.Diagnostics(); + gen.EmitType(out, program->TypeOf(ty), builtin::AddressSpace::kUndefined, + builtin::Access::kReadWrite, "ary"); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "bool ary[5][4]"); } @@ -66,9 +67,9 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_ArrayOfArrayOfArray) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), builtin::AddressSpace::kUndefined, - builtin::Access::kReadWrite, "ary")) - << gen.Diagnostics(); + gen.EmitType(out, program->TypeOf(ty), builtin::AddressSpace::kUndefined, + builtin::Access::kReadWrite, "ary"); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "bool ary[6][5][4]"); } @@ -79,9 +80,9 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Array_WithoutName) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), builtin::AddressSpace::kUndefined, - builtin::Access::kReadWrite, "")) - << gen.Diagnostics(); + gen.EmitType(out, program->TypeOf(ty), builtin::AddressSpace::kUndefined, + builtin::Access::kReadWrite, ""); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "bool[4]"); } @@ -91,9 +92,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Bool) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitType(out, bool_, builtin::AddressSpace::kUndefined, - builtin::Access::kReadWrite, "")) - << gen.Diagnostics(); + gen.EmitType(out, bool_, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "bool"); } @@ -103,9 +103,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_F32) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE( - gen.EmitType(out, f32, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, "")) - << gen.Diagnostics(); + gen.EmitType(out, f32, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "float"); } @@ -117,9 +116,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_F16) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE( - gen.EmitType(out, f16, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, "")) - << gen.Diagnostics(); + gen.EmitType(out, f16, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "float16_t"); } @@ -129,9 +127,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_I32) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE( - gen.EmitType(out, i32, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, "")) - << gen.Diagnostics(); + gen.EmitType(out, i32, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "int"); } @@ -143,9 +140,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Matrix_F32) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitType(out, mat2x3, builtin::AddressSpace::kUndefined, - builtin::Access::kReadWrite, "")) - << gen.Diagnostics(); + gen.EmitType(out, mat2x3, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "mat2x3"); } @@ -159,9 +155,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Matrix_F16) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitType(out, mat2x3, builtin::AddressSpace::kUndefined, - builtin::Access::kReadWrite, "")) - << gen.Diagnostics(); + gen.EmitType(out, mat2x3, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "f16mat2x3"); } @@ -176,7 +171,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_StructDecl) { TextGenerator::TextBuffer buf; auto* sem_s = program->TypeOf(s)->As(); - ASSERT_TRUE(gen.EmitStructType(&buf, sem_s)) << gen.Diagnostics(); + gen.EmitStructType(&buf, sem_s); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(buf.String(), R"(struct S { int a; float b; @@ -196,9 +192,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Struct) { auto* sem_s = program->TypeOf(s)->As(); utils::StringStream out; - ASSERT_TRUE(gen.EmitType(out, sem_s, builtin::AddressSpace::kUndefined, - builtin::Access::kReadWrite, "")) - << gen.Diagnostics(); + gen.EmitType(out, sem_s, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "S"); } @@ -210,8 +205,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Struct_NameCollision) { GlobalVar("g", ty.Of(s), builtin::AddressSpace::kPrivate); GeneratorImpl& gen = SanitizeAndBuild(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr(R"(struct S { int tint_symbol; float tint_symbol_1; @@ -230,7 +225,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Struct_WithOffsetAttributes) { TextGenerator::TextBuffer buf; auto* sem_s = program->TypeOf(s)->As(); - ASSERT_TRUE(gen.EmitStructType(&buf, sem_s)) << gen.Diagnostics(); + gen.EmitStructType(&buf, sem_s); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(buf.String(), R"(struct S { int a; float b; @@ -245,9 +241,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_U32) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE( - gen.EmitType(out, u32, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, "")) - << gen.Diagnostics(); + gen.EmitType(out, u32, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "uint"); } @@ -258,9 +253,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Vector_F32) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE( - gen.EmitType(out, vec3, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, "")) - << gen.Diagnostics(); + gen.EmitType(out, vec3, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "vec3"); } @@ -273,9 +267,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Vector_F16) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE( - gen.EmitType(out, vec3, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, "")) - << gen.Diagnostics(); + gen.EmitType(out, vec3, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "f16vec3"); } @@ -285,9 +278,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitType_Void) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitType(out, void_, builtin::AddressSpace::kUndefined, - builtin::Access::kReadWrite, "")) - << gen.Diagnostics(); + gen.EmitType(out, void_, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "void"); } @@ -297,9 +289,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitSampler) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_FALSE(gen.EmitType(out, sampler, builtin::AddressSpace::kUndefined, - builtin::Access::kReadWrite, "")) - << gen.Diagnostics(); + gen.EmitType(out, sampler, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); } TEST_F(GlslGeneratorImplTest_Type, EmitSamplerComparison) { @@ -308,9 +299,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitSamplerComparison) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_FALSE(gen.EmitType(out, sampler, builtin::AddressSpace::kUndefined, - builtin::Access::kReadWrite, "")) - << gen.Diagnostics(); + gen.EmitType(out, sampler, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); } struct GlslDepthTextureData { @@ -341,7 +331,8 @@ TEST_P(GlslDepthTexturesTest, Emit) { GeneratorImpl& gen = Build(); - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr(params.result)); } INSTANTIATE_TEST_SUITE_P( @@ -368,8 +359,8 @@ TEST_F(GlslDepthMultisampledTexturesTest, Emit) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("sampler2DMS tex;")); } @@ -414,8 +405,8 @@ TEST_P(GlslSampledTexturesTest, Emit) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr(params.result)); } INSTANTIATE_TEST_SUITE_P(GlslGeneratorImplTest_Type, @@ -519,9 +510,8 @@ TEST_F(GlslGeneratorImplTest_Type, EmitMultisampledTexture) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE( - gen.EmitType(out, s, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, "")) - << gen.Diagnostics(); + gen.EmitType(out, s, builtin::AddressSpace::kUndefined, builtin::Access::kReadWrite, ""); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "highp sampler2DMS"); } @@ -552,8 +542,8 @@ TEST_P(GlslStorageTexturesTest, Emit) { }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr(params.result)); } INSTANTIATE_TEST_SUITE_P( diff --git a/src/tint/writer/glsl/generator_impl_unary_op_test.cc b/src/tint/writer/glsl/generator_impl_unary_op_test.cc index f8548ff9c8..0daaa3375c 100644 --- a/src/tint/writer/glsl/generator_impl_unary_op_test.cc +++ b/src/tint/writer/glsl/generator_impl_unary_op_test.cc @@ -15,6 +15,8 @@ #include "src/tint/utils/string_stream.h" #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + namespace tint::writer::glsl { namespace { @@ -28,7 +30,8 @@ TEST_F(GlslUnaryOpTest, AddressOf) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.Diagnostics(); + gen.EmitExpression(out, op); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "expr"); } @@ -40,7 +43,8 @@ TEST_F(GlslUnaryOpTest, Complement) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.Diagnostics(); + gen.EmitExpression(out, op); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "~(expr)"); } @@ -53,7 +57,8 @@ TEST_F(GlslUnaryOpTest, Indirection) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.Diagnostics(); + gen.EmitExpression(out, op); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "expr"); } @@ -65,7 +70,8 @@ TEST_F(GlslUnaryOpTest, Not) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.Diagnostics(); + gen.EmitExpression(out, op); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "!(expr)"); } @@ -77,7 +83,8 @@ TEST_F(GlslUnaryOpTest, Negation) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.Diagnostics(); + gen.EmitExpression(out, op); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "-(expr)"); } @@ -88,7 +95,8 @@ TEST_F(GlslUnaryOpTest, IntMin) { GeneratorImpl& gen = Build(); utils::StringStream out; - ASSERT_TRUE(gen.EmitExpression(out, op)) << gen.Diagnostics(); + gen.EmitExpression(out, op); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(out.str(), "(-2147483647 - 1)"); } diff --git a/src/tint/writer/glsl/generator_impl_uniform_buffer_test.cc b/src/tint/writer/glsl/generator_impl_uniform_buffer_test.cc index 9274d7a89c..2cf8c38ec8 100644 --- a/src/tint/writer/glsl/generator_impl_uniform_buffer_test.cc +++ b/src/tint/writer/glsl/generator_impl_uniform_buffer_test.cc @@ -12,9 +12,10 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "gmock/gmock.h" #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + using ::testing::HasSubstr; namespace tint::writer::glsl { @@ -29,8 +30,8 @@ TEST_F(GlslGeneratorImplTest_UniformBuffer, Simple) { GlobalVar("simple", ty.Of(simple), builtin::AddressSpace::kUniform, Group(0_a), Binding(0_a)); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es struct Simple { @@ -49,8 +50,8 @@ TEST_F(GlslGeneratorImplTest_UniformBuffer, Simple_Desktop) { GlobalVar("simple", ty.Of(simple), builtin::AddressSpace::kUniform, Group(0_a), Binding(0_a)); GeneratorImpl& gen = Build(Version(Version::Standard::kDesktop, 4, 4)); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 440 struct Simple { diff --git a/src/tint/writer/glsl/generator_impl_variable_decl_statement_test.cc b/src/tint/writer/glsl/generator_impl_variable_decl_statement_test.cc index d5dbb15033..80a1fa0f22 100644 --- a/src/tint/writer/glsl/generator_impl_variable_decl_statement_test.cc +++ b/src/tint/writer/glsl/generator_impl_variable_decl_statement_test.cc @@ -12,10 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "gmock/gmock.h" #include "src/tint/ast/variable_decl_statement.h" #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + using namespace tint::number_suffixes; // NOLINT namespace tint::writer::glsl { @@ -31,10 +32,9 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement) { WrapInFunction(stmt); GeneratorImpl& gen = Build(); - gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.Diagnostics(); + gen.EmitStatement(stmt); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), " float a = 0.0f;\n"); } @@ -44,10 +44,9 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Let) { WrapInFunction(stmt); GeneratorImpl& gen = Build(); - gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.Diagnostics(); + gen.EmitStatement(stmt); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), " float a = 0.0f;\n"); } @@ -57,10 +56,9 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const) { WrapInFunction(stmt); GeneratorImpl& gen = Build(); - gen.increment_indent(); - - ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.Diagnostics(); + gen.EmitStatement(stmt); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), ""); // Not a mistake - 'const' is inlined } @@ -73,9 +71,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_AInt }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -94,9 +91,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_AFlo }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -115,9 +111,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_i32) }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -136,9 +131,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_u32) }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -157,9 +151,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_f32) }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -180,9 +173,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_f16) }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_AMD_gpu_shader_half_float : require @@ -202,9 +194,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_vec3 }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -223,9 +214,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_vec3 }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -244,9 +234,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_vec3 }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -267,9 +256,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_vec3 }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_AMD_gpu_shader_half_float : require @@ -289,9 +277,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_mat2 }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -310,9 +297,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_mat2 }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -333,9 +319,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_mat2 }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es #extension GL_AMD_gpu_shader_half_float : require @@ -355,9 +340,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_arr_ }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -376,9 +360,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_arr_ }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -397,9 +380,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_arr_ }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -419,9 +401,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_arr_ }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es struct S { @@ -448,9 +429,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_arr_ }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); - + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(#version 310 es void f() { @@ -466,10 +446,9 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Array) { WrapInFunction(var, Expr("a")); GeneratorImpl& gen = Build(); - gen.increment_indent(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr(" float a[5] = float[5](0.0f, 0.0f, 0.0f, 0.0f, 0.0f);\n")); } @@ -480,10 +459,9 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Private) { WrapInFunction(Expr("a")); GeneratorImpl& gen = Build(); - gen.increment_indent(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr(" float a = 0.0f;\n")); } @@ -494,8 +472,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Initialize WrapInFunction(stmt); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.Diagnostics(); + gen.EmitStatement(stmt); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(vec3 a = vec3(0.0f); )"); } @@ -509,8 +487,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Initialize WrapInFunction(stmt); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.Diagnostics(); + gen.EmitStatement(stmt); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(f16vec3 a = f16vec3(0.0hf); )"); } @@ -522,8 +500,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Initialize WrapInFunction(stmt); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.Diagnostics(); + gen.EmitStatement(stmt); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(mat2x3 a = mat2x3(vec3(0.0f), vec3(0.0f)); )"); @@ -538,8 +516,8 @@ TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Initialize WrapInFunction(stmt); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.EmitStatement(stmt)) << gen.Diagnostics(); + gen.EmitStatement(stmt); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_EQ(gen.result(), R"(f16mat2x3 a = f16mat2x3(f16vec3(0.0hf), f16vec3(0.0hf)); )"); diff --git a/src/tint/writer/glsl/generator_impl_workgroup_var_test.cc b/src/tint/writer/glsl/generator_impl_workgroup_var_test.cc index d2529f4537..6edf313c9c 100644 --- a/src/tint/writer/glsl/generator_impl_workgroup_var_test.cc +++ b/src/tint/writer/glsl/generator_impl_workgroup_var_test.cc @@ -12,11 +12,12 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "gmock/gmock.h" #include "src/tint/ast/id_attribute.h" #include "src/tint/ast/stage_attribute.h" #include "src/tint/writer/glsl/test_helper.h" +#include "gmock/gmock.h" + using ::testing::HasSubstr; using namespace tint::number_suffixes; // NOLINT @@ -35,8 +36,8 @@ TEST_F(GlslGeneratorImplTest_WorkgroupVar, Basic) { WorkgroupSize(1_i), }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("shared float wg;\n")); } @@ -51,8 +52,8 @@ TEST_F(GlslGeneratorImplTest_WorkgroupVar, Aliased) { WorkgroupSize(1_i), }); GeneratorImpl& gen = Build(); - - ASSERT_TRUE(gen.Generate()) << gen.Diagnostics(); + gen.Generate(); + EXPECT_THAT(gen.Diagnostics(), testing::IsEmpty()); EXPECT_THAT(gen.result(), HasSubstr("shared float wg;\n")); }