[type-determiner] Move ast::Module to constructor.

This CL moves the ast::Module to be provided to the type determiner
constructor so we can access it for things like the imports.

Change-Id: I110fffe669a8a007461bf84d30d85d70405e37be
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/19761
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair
2020-04-20 14:20:01 +00:00
committed by dan sinclair
parent cd077b01a9
commit b950e80a59
7 changed files with 102 additions and 100 deletions

View File

@@ -61,10 +61,10 @@ TEST_P(BinaryArithSignedIntegerTest, Scalar) {
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@@ -102,13 +102,13 @@ TEST_P(BinaryArithSignedIntegerTest, Vector) {
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@@ -151,10 +151,10 @@ TEST_P(BinaryArithUnsignedIntegerTest, Scalar) {
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@@ -192,13 +192,13 @@ TEST_P(BinaryArithUnsignedIntegerTest, Vector) {
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@@ -241,10 +241,10 @@ TEST_P(BinaryArithFloatTest, Scalar) {
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@@ -283,13 +283,13 @@ TEST_P(BinaryArithFloatTest, Vector) {
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@@ -325,10 +325,10 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Scalar) {
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@@ -368,13 +368,13 @@ TEST_P(BinaryCompareUnsignedIntegerTest, Vector) {
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@@ -414,10 +414,10 @@ TEST_P(BinaryCompareSignedIntegerTest, Scalar) {
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@@ -457,13 +457,13 @@ TEST_P(BinaryCompareSignedIntegerTest, Vector) {
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@@ -503,10 +503,10 @@ TEST_P(BinaryCompareFloatTest, Scalar) {
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@@ -546,13 +546,13 @@ TEST_P(BinaryCompareFloatTest, Vector) {
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::BinaryExpression expr(param.op, std::move(lhs), std::move(rhs));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@@ -596,14 +596,14 @@ TEST_F(BuilderTest, Binary_Multiply_VectorScalar) {
std::make_unique<ast::FloatLiteral>(&f32, 1.f));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
std::move(rhs));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@@ -635,14 +635,14 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarVector) {
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
std::move(rhs));
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@@ -667,7 +667,8 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixScalar) {
std::make_unique<ast::FloatLiteral>(&f32, 1.f));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
@@ -675,7 +676,6 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixScalar) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@@ -705,7 +705,8 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix) {
auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
@@ -713,7 +714,6 @@ TEST_F(BuilderTest, Binary_Multiply_ScalarMatrix) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@@ -752,7 +752,8 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector) {
std::make_unique<ast::TypeConstructorExpression>(&vec3, std::move(vals));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
@@ -760,7 +761,6 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixVector) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@@ -801,7 +801,8 @@ TEST_F(BuilderTest, Binary_Multiply_VectorMatrix) {
auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
@@ -809,7 +810,6 @@ TEST_F(BuilderTest, Binary_Multiply_VectorMatrix) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@@ -840,7 +840,8 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix) {
auto rhs = std::make_unique<ast::IdentifierExpression>("mat");
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
ast::BinaryExpression expr(ast::BinaryOp::kMultiply, std::move(lhs),
@@ -848,7 +849,6 @@ TEST_F(BuilderTest, Binary_Multiply_MatrixMatrix) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();

View File

@@ -151,7 +151,8 @@ TEST_F(BuilderTest, IdentifierExpression_Load) {
ast::type::I32Type i32;
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::Variable var("var", ast::StorageClass::kPrivate, &i32);
@@ -165,7 +166,6 @@ TEST_F(BuilderTest, IdentifierExpression_Load) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(&var)) << b.error();
@@ -186,7 +186,8 @@ TEST_F(BuilderTest, IdentifierExpression_NoLoadConst) {
ast::type::I32Type i32;
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ast::Variable var("var", ast::StorageClass::kNone, &i32);
var.set_constructor(std::make_unique<ast::ScalarConstructorExpression>(
@@ -203,7 +204,6 @@ TEST_F(BuilderTest, IdentifierExpression_NoLoadConst) {
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(&var)) << b.error();

View File

@@ -47,10 +47,10 @@ TEST_F(BuilderTest, If_Empty) {
ast::IfStatement expr(std::move(cond), ast::StatementList{});
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
@@ -89,12 +89,12 @@ TEST_F(BuilderTest, If_WithStatements) {
ast::IfStatement expr(std::move(cond), std::move(body));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@@ -152,12 +152,12 @@ TEST_F(BuilderTest, If_WithElse) {
expr.set_else_statements(std::move(else_stmts));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@@ -222,12 +222,12 @@ TEST_F(BuilderTest, If_WithElseIf) {
expr.set_else_statements(std::move(else_stmts));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();
@@ -316,12 +316,12 @@ TEST_F(BuilderTest, If_WithMultiple) {
expr.set_else_statements(std::move(else_stmts));
Context ctx;
TypeDeterminer td(&ctx);
ast::Module mod;
TypeDeterminer td(&ctx, &mod);
td.RegisterVariableForTesting(var.get());
ASSERT_TRUE(td.DetermineResultType(&expr)) << td.error();
ast::Module mod;
Builder b(&mod);
b.push_function(Function{});
ASSERT_TRUE(b.GenerateGlobalVariable(var.get())) << b.error();