Create a semantic class for block statements

Semantic information about block statements the resolver would
temporarily create while resolving is now exposed in a
sem::BlockStatement class.

In the process, semantic information about statements in general is
overhauled so that a statement has a reference to its parent
statement, regardless of whether this is a block.

Bug: tint:799
Bug: tint:800
Change-Id: I8771511c5274ea74741b8c86f0f55cbc39810888
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/50904
Commit-Queue: Alastair Donaldson <allydonaldson@googlemail.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
Alastair F. Donaldson
2021-05-15 14:48:46 +00:00
committed by Commit Bot service account
parent 43f50eaf86
commit ac90829e1c
13 changed files with 343 additions and 131 deletions

View File

@@ -19,6 +19,7 @@
#include "src/ast/call_statement.h"
#include "src/program_builder.h"
#include "src/sem/block_statement.h"
#include "src/sem/call.h"
#include "src/sem/statement.h"
#include "src/sem/struct.h"
@@ -155,12 +156,7 @@ Output CalculateArrayLength::Run(const Program* in, const DataMap&) {
}
// Find the current statement block
auto* block = call->Stmt()->Block();
if (!block) {
TINT_ICE(ctx.dst->Diagnostics())
<< "arrayLength() statement is outside a BlockStatement";
break;
}
auto* block = call->Stmt()->Block()->Declaration();
// If the storage_buffer_expr is resolves to a variable (typically
// true) then key the array_length from the variable. If not, key off

View File

@@ -19,6 +19,7 @@
#include <vector>
#include "src/program_builder.h"
#include "src/sem/block_statement.h"
#include "src/sem/function.h"
#include "src/sem/statement.h"
#include "src/sem/struct.h"
@@ -257,7 +258,8 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap&) {
auto* ty = CreateASTTypeFor(&ctx, ret_type);
auto* temp_var =
ctx.dst->Decl(ctx.dst->Const(temp, ty, new_ret_value()));
ctx.InsertBefore(ret_sem->Block()->statements(), ret, temp_var);
ctx.InsertBefore(ret_sem->Block()->Declaration()->statements(), ret,
temp_var);
new_ret_value = [&ctx, temp] { return ctx.dst->Expr(temp); };
}

View File

@@ -19,6 +19,7 @@
#include "src/ast/stage_decoration.h"
#include "src/ast/variable_decl_statement.h"
#include "src/program_builder.h"
#include "src/sem/block_statement.h"
#include "src/sem/expression.h"
#include "src/sem/statement.h"
#include "src/sem/variable.h"
@@ -113,8 +114,8 @@ void Hlsl::PromoteInitializersToConstVar(CloneContext& ctx) const {
auto* dst_ident = ctx.dst->Expr(dst_symbol);
// Insert the constant before the usage
ctx.InsertBefore(src_sem_stmt->Block()->statements(), src_stmt,
dst_var_decl);
ctx.InsertBefore(src_sem_stmt->Block()->Declaration()->statements(),
src_stmt, dst_var_decl);
// Replace the inlined initializer with a reference to the constant
ctx.Replace(src_init, dst_ident);
}

View File

@@ -21,6 +21,7 @@
#include "src/ast/return_statement.h"
#include "src/ast/stage_decoration.h"
#include "src/program_builder.h"
#include "src/sem/block_statement.h"
#include "src/sem/function.h"
#include "src/sem/statement.h"
#include "src/sem/struct.h"
@@ -188,7 +189,7 @@ void Spirv::HandleEntryPointIOTypes(CloneContext& ctx) const {
for (auto* ret : func->ReturnStatements()) {
auto* ret_sem = ctx.src->Sem().Get(ret);
auto* call = ctx.dst->Call(return_func_symbol, ctx.Clone(ret->value()));
ctx.InsertBefore(ret_sem->Block()->statements(), ret,
ctx.InsertBefore(ret_sem->Block()->Declaration()->statements(), ret,
ctx.dst->create<ast::CallStatement>(call));
ctx.Replace(ret, ctx.dst->Return());
}