ProgramBuilder: Generate type pairs for primitives

Emit the new typ::I32, typ::U32, typ::F32, typ::Void, typ::Bool types instead of the just the sem::Types.

Used as a stepping stone to emitting the ast::Types instead.

Bug: tint:724
Change-Id: Ic492e33bc909e0821b581af05242d956631db2e3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48602
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2021-04-21 13:37:22 +00:00 committed by Commit Bot service account
parent 440636c15c
commit a922e65d72
9 changed files with 68 additions and 50 deletions

View File

@ -21,10 +21,13 @@
#include "src/ast/array_accessor_expression.h"
#include "src/ast/assignment_statement.h"
#include "src/ast/binary_expression.h"
#include "src/ast/bool.h"
#include "src/ast/bool_literal.h"
#include "src/ast/call_expression.h"
#include "src/ast/case_statement.h"
#include "src/ast/f32.h"
#include "src/ast/float_literal.h"
#include "src/ast/i32.h"
#include "src/ast/if_statement.h"
#include "src/ast/loop_statement.h"
#include "src/ast/member_accessor_expression.h"
@ -39,8 +42,10 @@
#include "src/ast/struct_member_size_decoration.h"
#include "src/ast/switch_statement.h"
#include "src/ast/type_constructor_expression.h"
#include "src/ast/u32.h"
#include "src/ast/uint_literal.h"
#include "src/ast/variable_decl_statement.h"
#include "src/ast/void.h"
#include "src/program.h"
#include "src/program_id.h"
#include "src/sem/access_control_type.h"
@ -55,6 +60,7 @@
#include "src/sem/u32_type.h"
#include "src/sem/vector_type.h"
#include "src/sem/void_type.h"
#include "src/typepair.h"
namespace tint {
@ -329,19 +335,29 @@ class ProgramBuilder {
}
/// @returns a boolean type
sem::Bool* bool_() const { return builder->create<sem::Bool>(); }
typ::Bool bool_() const {
return {builder->create<ast::Bool>(), builder->create<sem::Bool>()};
}
/// @returns a f32 type
sem::F32* f32() const { return builder->create<sem::F32>(); }
typ::F32 f32() const {
return {builder->create<ast::F32>(), builder->create<sem::F32>()};
}
/// @returns a i32 type
sem::I32* i32() const { return builder->create<sem::I32>(); }
typ::I32 i32() const {
return {builder->create<ast::I32>(), builder->create<sem::I32>()};
}
/// @returns a u32 type
sem::U32* u32() const { return builder->create<sem::U32>(); }
typ::U32 u32() const {
return {builder->create<ast::U32>(), builder->create<sem::U32>()};
}
/// @returns a void type
sem::Void* void_() const { return builder->create<sem::Void>(); }
typ::Void void_() const {
return {builder->create<ast::Void>(), builder->create<sem::Void>()};
}
/// @param type vector subtype
/// @return the tint AST type for a 2-element vector of `type`.

View File

@ -33,7 +33,7 @@ TEST_F(ProgramBuilderTest, IDsAreUnique) {
TEST_F(ProgramBuilderTest, WrapDoesntAffectInner) {
Program inner([] {
ProgramBuilder builder;
auto* ty = builder.ty.f32();
auto ty = builder.ty.f32();
builder.Func("a", {}, ty, {}, {});
return builder;
}());
@ -54,7 +54,7 @@ TEST_F(ProgramBuilderTest, WrapDoesntAffectInner) {
EXPECT_FALSE(inner.Symbols().Get("b").IsValid());
EXPECT_FALSE(outer.Symbols().Get("b").IsValid());
auto* ty = outer.ty.f32();
auto ty = outer.ty.f32();
outer.Func("b", {}, ty, {}, {});
ASSERT_EQ(inner.AST().Functions().size(), 1u);

View File

@ -23,7 +23,7 @@ TEST_F(ParserImplTest, StructMember_Parses) {
auto p = parser("a : i32;");
auto& builder = p->builder();
auto* i32 = builder.ty.i32();
auto i32 = builder.ty.i32();
auto decos = p->decoration_list();
EXPECT_FALSE(decos.errored);
@ -49,7 +49,7 @@ TEST_F(ParserImplTest, StructMember_ParsesWithOffsetDecoration_DEPRECATED) {
auto p = parser("[[offset(2)]] a : i32;");
auto& builder = p->builder();
auto* i32 = builder.ty.i32();
auto i32 = builder.ty.i32();
auto decos = p->decoration_list();
EXPECT_FALSE(decos.errored);
@ -79,7 +79,7 @@ TEST_F(ParserImplTest, StructMember_ParsesWithAlignDecoration) {
auto p = parser("[[align(2)]] a : i32;");
auto& builder = p->builder();
auto* i32 = builder.ty.i32();
auto i32 = builder.ty.i32();
auto decos = p->decoration_list();
EXPECT_FALSE(decos.errored);
@ -108,7 +108,7 @@ TEST_F(ParserImplTest, StructMember_ParsesWithSizeDecoration) {
auto p = parser("[[size(2)]] a : i32;");
auto& builder = p->builder();
auto* i32 = builder.ty.i32();
auto i32 = builder.ty.i32();
auto decos = p->decoration_list();
EXPECT_FALSE(decos.errored);
@ -137,7 +137,7 @@ TEST_F(ParserImplTest, StructMember_ParsesWithDecoration) {
auto p = parser("[[size(2)]] a : i32;");
auto& builder = p->builder();
auto* i32 = builder.ty.i32();
auto i32 = builder.ty.i32();
auto decos = p->decoration_list();
EXPECT_FALSE(decos.errored);
@ -167,7 +167,7 @@ TEST_F(ParserImplTest, StructMember_ParsesWithMultipleDecorations) {
[[align(4)]] a : i32;)");
auto& builder = p->builder();
auto* i32 = builder.ty.i32();
auto i32 = builder.ty.i32();
auto decos = p->decoration_list();
EXPECT_FALSE(decos.errored);

View File

@ -245,7 +245,8 @@ bool Resolver::ResolveInternal() {
for (auto* node : builder_->ASTNodes().Objects()) {
if (marked_.count(node) == 0) {
if (node->IsAnyOf<ast::AccessDecoration, ast::StrideDecoration>()) {
if (node->IsAnyOf<ast::AccessDecoration, ast::StrideDecoration,
ast::Type>()) {
// TODO(crbug.com/tint/724) - Remove once tint:724 is complete.
// ast::AccessDecorations are generated by the WGSL parser, used to
// build sem::AccessControls and then leaked.
@ -253,6 +254,7 @@ bool Resolver::ResolveInternal() {
// multiple arrays of the same stride, size and element type are
// currently de-duplicated by the type manager, and we leak these
// decorations.
// ast::Types are being built, but not yet being handled. This is WIP.
continue;
}
TINT_ICE(diagnostics_) << "AST node '" << node->TypeInfo().name

View File

@ -105,7 +105,7 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_RuntimeArray) {
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_Bool) {
auto* bool_ = ty.bool_();
auto bool_ = ty.bool_();
GeneratorImpl& gen = Build();
@ -115,7 +115,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Bool) {
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_F32) {
auto* f32 = ty.f32();
auto f32 = ty.f32();
GeneratorImpl& gen = Build();
@ -125,7 +125,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_F32) {
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_I32) {
auto* i32 = ty.i32();
auto i32 = ty.i32();
GeneratorImpl& gen = Build();
@ -265,7 +265,7 @@ TEST_F(HlslGeneratorImplTest_Type, DISABLED_EmitType_Struct_WithDecoration) {
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_U32) {
auto* u32 = ty.u32();
auto u32 = ty.u32();
GeneratorImpl& gen = Build();
@ -285,7 +285,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_Vector) {
}
TEST_F(HlslGeneratorImplTest_Type, EmitType_Void) {
auto* void_ = ty.void_();
auto void_ = ty.void_();
GeneratorImpl& gen = Build();

View File

@ -127,7 +127,7 @@ TEST_F(MslGeneratorImplTest, EmitType_RuntimeArray) {
}
TEST_F(MslGeneratorImplTest, EmitType_Bool) {
auto* bool_ = ty.bool_();
auto bool_ = ty.bool_();
GeneratorImpl& gen = Build();
@ -136,7 +136,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Bool) {
}
TEST_F(MslGeneratorImplTest, EmitType_F32) {
auto* f32 = ty.f32();
auto f32 = ty.f32();
GeneratorImpl& gen = Build();
@ -145,7 +145,7 @@ TEST_F(MslGeneratorImplTest, EmitType_F32) {
}
TEST_F(MslGeneratorImplTest, EmitType_I32) {
auto* i32 = ty.i32();
auto i32 = ty.i32();
GeneratorImpl& gen = Build();
@ -604,7 +604,7 @@ TEST_F(MslGeneratorImplTest, DISABLED_EmitType_Struct_WithDecoration) {
}
TEST_F(MslGeneratorImplTest, EmitType_U32) {
auto* u32 = ty.u32();
auto u32 = ty.u32();
GeneratorImpl& gen = Build();
@ -622,7 +622,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Vector) {
}
TEST_F(MslGeneratorImplTest, EmitType_Void) {
auto* void_ = ty.void_();
auto void_ = ty.void_();
GeneratorImpl& gen = Build();

View File

@ -42,7 +42,7 @@ TEST_F(BuilderTest, EntryPoint_Parameters) {
// [[location(1)]] loc1 : f32) {
// var col : f32 = (coord.x * loc1);
// }
auto* f32 = ty.f32();
auto f32 = ty.f32();
auto* vec4 = ty.vec4<float>();
auto* coord = Param(
"coord", vec4, {create<ast::BuiltinDecoration>(ast::Builtin::kPosition)});
@ -106,8 +106,8 @@ TEST_F(BuilderTest, EntryPoint_ReturnValue) {
// }
// return 1.0;
// }
auto* f32 = ty.f32();
auto* u32 = ty.u32();
auto f32 = ty.f32();
auto u32 = ty.u32();
auto* loc_in = Param("loc_in", u32, {create<ast::LocationDecoration>(0)});
auto* cond = create<ast::BinaryExpression>(ast::BinaryOp::kGreaterThan,
Expr("loc_in"), Expr(10u));

View File

@ -41,8 +41,8 @@ TEST_F(BuilderTest_Type, GenerateAlias) {
}
TEST_F(BuilderTest_Type, ReturnsGeneratedAlias) {
auto* i32 = ty.i32();
auto* f32 = ty.f32();
auto i32 = ty.i32();
auto f32 = ty.f32();
auto* alias_type = ty.alias("my_type", f32);
spirv::Builder& b = Build();
@ -148,7 +148,7 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedArray) {
}
TEST_F(BuilderTest_Type, GenerateBool) {
auto* bool_ = ty.bool_();
auto bool_ = ty.bool_();
spirv::Builder& b = Build();
@ -162,8 +162,8 @@ TEST_F(BuilderTest_Type, GenerateBool) {
}
TEST_F(BuilderTest_Type, ReturnsGeneratedBool) {
auto* bool_ = ty.bool_();
auto* i32 = ty.i32();
auto bool_ = ty.bool_();
auto i32 = ty.i32();
spirv::Builder& b = Build();
@ -176,7 +176,7 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedBool) {
}
TEST_F(BuilderTest_Type, GenerateF32) {
auto* f32 = ty.f32();
auto f32 = ty.f32();
spirv::Builder& b = Build();
@ -190,8 +190,8 @@ TEST_F(BuilderTest_Type, GenerateF32) {
}
TEST_F(BuilderTest_Type, ReturnsGeneratedF32) {
auto* f32 = ty.f32();
auto* i32 = ty.i32();
auto f32 = ty.f32();
auto i32 = ty.i32();
spirv::Builder& b = Build();
@ -204,7 +204,7 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedF32) {
}
TEST_F(BuilderTest_Type, GenerateI32) {
auto* i32 = ty.i32();
auto i32 = ty.i32();
spirv::Builder& b = Build();
@ -218,8 +218,8 @@ TEST_F(BuilderTest_Type, GenerateI32) {
}
TEST_F(BuilderTest_Type, ReturnsGeneratedI32) {
auto* f32 = ty.f32();
auto* i32 = ty.i32();
auto f32 = ty.f32();
auto i32 = ty.i32();
spirv::Builder& b = Build();
@ -249,7 +249,7 @@ TEST_F(BuilderTest_Type, GenerateMatrix) {
TEST_F(BuilderTest_Type, ReturnsGeneratedMatrix) {
auto* mat = ty.mat4x3<i32>();
auto* i32 = ty.i32();
auto i32 = ty.i32();
spirv::Builder& b = Build();
@ -500,7 +500,7 @@ OpDecorate %11 ArrayStride 64
}
TEST_F(BuilderTest_Type, GenerateU32) {
auto* u32 = ty.u32();
auto u32 = ty.u32();
spirv::Builder& b = Build();
@ -514,8 +514,8 @@ TEST_F(BuilderTest_Type, GenerateU32) {
}
TEST_F(BuilderTest_Type, ReturnsGeneratedU32) {
auto* u32 = ty.u32();
auto* f32 = ty.f32();
auto u32 = ty.u32();
auto f32 = ty.f32();
spirv::Builder& b = Build();
@ -544,7 +544,7 @@ TEST_F(BuilderTest_Type, GenerateVector) {
TEST_F(BuilderTest_Type, ReturnsGeneratedVector) {
auto* vec = ty.vec3<i32>();
auto* i32 = ty.i32();
auto i32 = ty.i32();
spirv::Builder& b = Build();
@ -557,7 +557,7 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedVector) {
}
TEST_F(BuilderTest_Type, GenerateVoid) {
auto* void_ = ty.void_();
auto void_ = ty.void_();
spirv::Builder& b = Build();
@ -571,8 +571,8 @@ TEST_F(BuilderTest_Type, GenerateVoid) {
}
TEST_F(BuilderTest_Type, ReturnsGeneratedVoid) {
auto* void_ = ty.void_();
auto* i32 = ty.i32();
auto void_ = ty.void_();
auto i32 = ty.i32();
spirv::Builder& b = Build();

View File

@ -110,7 +110,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_RuntimeArray) {
}
TEST_F(WgslGeneratorImplTest, EmitType_Bool) {
auto* bool_ = ty.bool_();
auto bool_ = ty.bool_();
AST().AddConstructedType(ty.alias("make_type_reachable", bool_));
GeneratorImpl& gen = Build();
@ -120,7 +120,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Bool) {
}
TEST_F(WgslGeneratorImplTest, EmitType_F32) {
auto* f32 = ty.f32();
auto f32 = ty.f32();
AST().AddConstructedType(ty.alias("make_type_reachable", f32));
GeneratorImpl& gen = Build();
@ -130,7 +130,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_F32) {
}
TEST_F(WgslGeneratorImplTest, EmitType_I32) {
auto* i32 = ty.i32();
auto i32 = ty.i32();
AST().AddConstructedType(ty.alias("make_type_reachable", i32));
GeneratorImpl& gen = Build();
@ -294,7 +294,7 @@ struct S {
}
TEST_F(WgslGeneratorImplTest, EmitType_U32) {
auto* u32 = ty.u32();
auto u32 = ty.u32();
AST().AddConstructedType(ty.alias("make_type_reachable", u32));
GeneratorImpl& gen = Build();