ast: Remove Node::set_source()

All nodes that don't have a Source constructor will need to have one added.
We can then find all missing Source mappings with a search for `Source{}`

Bug: tint:396
Bug: tint:390
Change-Id: I06f9689d4da0f3fd1bd757c7358dcc65f15dc752
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35018
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
Ben Clayton
2020-12-12 01:24:53 +00:00
committed by Commit Bot service account
parent 4226b6a1d8
commit 604bc72dd9
5 changed files with 21 additions and 61 deletions

View File

@@ -608,12 +608,6 @@ class StructuredTraverser {
std::unordered_set<uint32_t> visited_;
};
/// @param src a source record
/// @returns true if `src` is a non-default Source
bool HasSource(const Source& src) {
return src.range.begin.line > 0 || src.range.begin.column != 0;
}
} // namespace
BlockInfo::BlockInfo(const spvtools::opt::BasicBlock& bb)
@@ -722,14 +716,6 @@ ast::Statement* FunctionEmitter::AddStatement(ast::Statement* statement) {
return result;
}
ast::Statement* FunctionEmitter::AddStatementForInstruction(
ast::Statement* statement,
const spvtools::opt::Instruction& inst) {
auto* node = AddStatement(statement);
ApplySourceForInstruction(node, inst);
return node;
}
ast::Statement* FunctionEmitter::LastStatement() {
assert(!statements_stack_.empty());
auto* statement_list = statements_stack_.back().statements_;
@@ -1880,7 +1866,7 @@ bool FunctionEmitter::EmitFunctionVariables() {
inst.result_id(), ast::StorageClass::kFunction, var_store_type, false,
constructor, ast::VariableDecorationList{});
auto* var_decl_stmt = create<ast::VariableDeclStatement>(var);
AddStatementForInstruction(var_decl_stmt, inst);
AddStatement(var_decl_stmt);
// Save this as an already-named value.
identifier_values_.insert(inst.result_id());
}
@@ -2762,8 +2748,7 @@ bool FunctionEmitter::EmitConstDefinition(
if (!ast_const) {
return false;
}
AddStatementForInstruction(create<ast::VariableDeclStatement>(ast_const),
inst);
AddStatement(create<ast::VariableDeclStatement>(ast_const));
// Save this as an already-named value.
identifier_values_.insert(inst.result_id());
return success();
@@ -2777,11 +2762,10 @@ bool FunctionEmitter::EmitConstDefOrWriteToHoistedVar(
if (def_info && def_info->requires_hoisted_def) {
auto name = namer_.Name(result_id);
// Emit an assignment of the expression to the hoisted variable.
AddStatementForInstruction(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(
ast_module_.RegisterSymbol(name), name),
ast_expr.expr),
inst);
AddStatement(create<ast::AssignmentStatement>(
create<ast::IdentifierExpression>(ast_module_.RegisterSymbol(name),
namer_.Name(result_id)),
ast_expr.expr));
return true;
}
return EmitConstDefinition(inst, ast_expr);
@@ -2848,8 +2832,7 @@ bool FunctionEmitter::EmitStatement(const spvtools::opt::Instruction& inst) {
// TODO(dneto): Order of evaluation?
auto lhs = MakeExpression(ptr_id);
auto rhs = MakeExpression(value_id);
AddStatementForInstruction(
create<ast::AssignmentStatement>(lhs.expr, rhs.expr), inst);
AddStatement(create<ast::AssignmentStatement>(lhs.expr, rhs.expr));
return success();
}
case SpvOpLoad: {
@@ -3751,8 +3734,7 @@ bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) {
}
if (result_type->Is<ast::type::Void>()) {
return nullptr != AddStatementForInstruction(
create<ast::CallStatement>(call_expr), inst);
return nullptr != AddStatement(create<ast::CallStatement>(call_expr));
}
return EmitConstDefOrWriteToHoistedVar(inst, {result_type, call_expr});
@@ -3816,16 +3798,9 @@ TypedExpression FunctionEmitter::MakeSimpleSelect(
return {};
}
void FunctionEmitter::ApplySourceForInstruction(
ast::Node* node,
const spvtools::opt::Instruction& inst) {
if (!node) {
return;
}
const Source& existing = node->source();
if (!HasSource(existing)) {
node->set_source(parser_impl_.GetSourceForInst(&inst));
}
Source FunctionEmitter::GetSourceForInst(
const spvtools::opt::Instruction& inst) const {
return parser_impl_.GetSourceForInst(&inst);
}
bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
@@ -4028,7 +4003,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) {
} else {
// It's an image write. No value is returned, so make a statement out
// of the call.
AddStatementForInstruction(create<ast::CallStatement>(call_expr), inst);
AddStatement(create<ast::CallStatement>(call_expr));
}
return success();
}

View File

@@ -803,22 +803,10 @@ class FunctionEmitter {
/// @returns a pointer to the statement.
ast::Statement* AddStatement(ast::Statement* statement);
/// Appends a new statement to the top of the statement stack, and attaches
/// source location information from the given instruction. Does nothing if
/// the statement is null.
/// @param statement the new statement
/// @returns a pointer to the statement.
ast::Statement* AddStatementForInstruction(
ast::Statement* statement,
const spvtools::opt::Instruction& inst);
/// Sets the source information for the given instruction to the given
/// node, if the node doesn't already have a source record. Does nothing
/// if `node` is null.
/// @param node the AST node
/// Returns the source record for the given instruction.
/// @param inst the SPIR-V instruction
void ApplySourceForInstruction(ast::Node* node,
const spvtools::opt::Instruction& inst);
/// @return the Source record, or a default one
Source GetSourceForInst(const spvtools::opt::Instruction& inst) const;
/// @returns the last statetment in the top of the statement stack.
ast::Statement* LastStatement();