[ir] Add error helper to ir builder.
This CL adds a `add_error` to the IR builder. Bug: tint:1718 Change-Id: Ifd7a2f6e015d423dbe23405816dba00f237a6c8c Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/122602 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Dan Sinclair <dsinclair@chromium.org> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
724a70f7a1
commit
43c5efa7e8
|
@ -109,6 +109,10 @@ BuilderImpl::BuilderImpl(const Program* program)
|
||||||
|
|
||||||
BuilderImpl::~BuilderImpl() = default;
|
BuilderImpl::~BuilderImpl() = default;
|
||||||
|
|
||||||
|
void BuilderImpl::add_error(const Source& s, const std::string& err) {
|
||||||
|
diagnostics_.add_error(tint::diag::System::IR, err, s);
|
||||||
|
}
|
||||||
|
|
||||||
void BuilderImpl::BranchTo(FlowNode* node, utils::VectorRef<Value*> args) {
|
void BuilderImpl::BranchTo(FlowNode* node, utils::VectorRef<Value*> args) {
|
||||||
TINT_ASSERT(IR, current_flow_block);
|
TINT_ASSERT(IR, current_flow_block);
|
||||||
TINT_ASSERT(IR, !IsBranched(current_flow_block));
|
TINT_ASSERT(IR, !IsBranched(current_flow_block));
|
||||||
|
@ -171,9 +175,7 @@ ResultType BuilderImpl::Build() {
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
[&](Default) {
|
[&](Default) {
|
||||||
diagnostics_.add_warning(tint::diag::System::IR,
|
add_error(decl->source, "unknown type: " + std::string(decl->TypeInfo().name));
|
||||||
"unknown type: " + std::string(decl->TypeInfo().name),
|
|
||||||
decl->source);
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
|
@ -266,9 +268,8 @@ bool BuilderImpl::EmitStatement(const ast::Statement* stmt) {
|
||||||
return true; // Not emitted
|
return true; // Not emitted
|
||||||
},
|
},
|
||||||
[&](Default) {
|
[&](Default) {
|
||||||
diagnostics_.add_warning(
|
add_error(stmt->source,
|
||||||
tint::diag::System::IR,
|
"unknown statement type: " + std::string(stmt->TypeInfo().name));
|
||||||
"unknown statement type: " + std::string(stmt->TypeInfo().name), stmt->source);
|
|
||||||
// TODO(dsinclair): This should return `false`, switch back when all
|
// TODO(dsinclair): This should return `false`, switch back when all
|
||||||
// the cases are handled.
|
// the cases are handled.
|
||||||
return true;
|
return true;
|
||||||
|
@ -616,9 +617,8 @@ utils::Result<Value*> BuilderImpl::EmitExpression(const ast::Expression* expr) {
|
||||||
// TODO(dsinclair): Implement
|
// TODO(dsinclair): Implement
|
||||||
// },
|
// },
|
||||||
[&](Default) {
|
[&](Default) {
|
||||||
diagnostics_.add_warning(
|
add_error(expr->source,
|
||||||
tint::diag::System::IR,
|
"unknown expression type: " + std::string(expr->TypeInfo().name));
|
||||||
"unknown expression type: " + std::string(expr->TypeInfo().name), expr->source);
|
|
||||||
// TODO(dsinclair): This should return utils::Failure; Switch back
|
// TODO(dsinclair): This should return utils::Failure; Switch back
|
||||||
// once all the above cases are handled.
|
// once all the above cases are handled.
|
||||||
auto* v = builder.ir.types.Get<type::Void>();
|
auto* v = builder.ir.types.Get<type::Void>();
|
||||||
|
@ -636,19 +636,16 @@ bool BuilderImpl::EmitVariable(const ast::Variable* var) {
|
||||||
// TODO(dsinclair): Implement
|
// TODO(dsinclair): Implement
|
||||||
// },
|
// },
|
||||||
[&](const ast::Override*) {
|
[&](const ast::Override*) {
|
||||||
diagnostics_.add_warning(tint::diag::System::IR,
|
add_error(var->source,
|
||||||
"found an `Override` variable. The SubstituteOverrides "
|
"found an `Override` variable. The SubstituteOverrides "
|
||||||
"transform must be run before converting to IR",
|
"transform must be run before converting to IR");
|
||||||
var->source);
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
// [&](const ast::Const* c) {
|
// [&](const ast::Const* c) {
|
||||||
// TODO(dsinclair): Implement
|
// TODO(dsinclair): Implement
|
||||||
// },
|
// },
|
||||||
[&](Default) {
|
[&](Default) {
|
||||||
diagnostics_.add_warning(tint::diag::System::IR,
|
add_error(var->source, "unknown variable: " + std::string(var->TypeInfo().name));
|
||||||
"unknown variable: " + std::string(var->TypeInfo().name),
|
|
||||||
var->source);
|
|
||||||
|
|
||||||
// TODO(dsinclair): This should return `false`, switch back when all
|
// TODO(dsinclair): This should return `false`, switch back when all
|
||||||
// the cases are handled.
|
// the cases are handled.
|
||||||
|
@ -761,8 +758,7 @@ utils::Result<Value*> BuilderImpl::EmitCall(const ast::CallExpression* expr) {
|
||||||
for (const auto* arg : expr->args) {
|
for (const auto* arg : expr->args) {
|
||||||
auto value = EmitExpression(arg);
|
auto value = EmitExpression(arg);
|
||||||
if (!value) {
|
if (!value) {
|
||||||
diagnostics_.add_error(tint::diag::System::IR, "Failed to convert arguments",
|
add_error(arg->source, "Failed to convert arguments");
|
||||||
arg->source);
|
|
||||||
return utils::Failure;
|
return utils::Failure;
|
||||||
}
|
}
|
||||||
args.Push(value.Get());
|
args.Push(value.Get());
|
||||||
|
@ -770,10 +766,8 @@ utils::Result<Value*> BuilderImpl::EmitCall(const ast::CallExpression* expr) {
|
||||||
|
|
||||||
auto* sem = program_->Sem().Get<sem::Call>(expr);
|
auto* sem = program_->Sem().Get<sem::Call>(expr);
|
||||||
if (!sem) {
|
if (!sem) {
|
||||||
diagnostics_.add_error(
|
add_error(expr->source, "Failed to get semantic information for call " +
|
||||||
tint::diag::System::IR,
|
std::string(expr->TypeInfo().name));
|
||||||
"Failed to get semantic information for call " + std::string(expr->TypeInfo().name),
|
|
||||||
expr->source);
|
|
||||||
return utils::Failure;
|
return utils::Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -784,8 +778,7 @@ utils::Result<Value*> BuilderImpl::EmitCall(const ast::CallExpression* expr) {
|
||||||
// If this is a builtin function, emit the specific builtin value
|
// If this is a builtin function, emit the specific builtin value
|
||||||
if (sem->Target()->As<sem::Builtin>()) {
|
if (sem->Target()->As<sem::Builtin>()) {
|
||||||
// TODO(dsinclair): .. something ...
|
// TODO(dsinclair): .. something ...
|
||||||
diagnostics_.add_error(tint::diag::System::IR, "Missing builtin function support",
|
add_error(expr->source, "Missing builtin function support");
|
||||||
expr->source);
|
|
||||||
} else if (sem->Target()->As<sem::ValueConstructor>()) {
|
} else if (sem->Target()->As<sem::ValueConstructor>()) {
|
||||||
instr = builder.Construct(ty, std::move(args));
|
instr = builder.Construct(ty, std::move(args));
|
||||||
} else if (auto* conv = sem->Target()->As<sem::ValueConversion>()) {
|
} else if (auto* conv = sem->Target()->As<sem::ValueConversion>()) {
|
||||||
|
@ -809,19 +802,15 @@ utils::Result<Value*> BuilderImpl::EmitCall(const ast::CallExpression* expr) {
|
||||||
utils::Result<Value*> BuilderImpl::EmitLiteral(const ast::LiteralExpression* lit) {
|
utils::Result<Value*> BuilderImpl::EmitLiteral(const ast::LiteralExpression* lit) {
|
||||||
auto* sem = program_->Sem().Get(lit);
|
auto* sem = program_->Sem().Get(lit);
|
||||||
if (!sem) {
|
if (!sem) {
|
||||||
diagnostics_.add_error(
|
add_error(lit->source, "Failed to get semantic information for node " +
|
||||||
tint::diag::System::IR,
|
std::string(lit->TypeInfo().name));
|
||||||
"Failed to get semantic information for node " + std::string(lit->TypeInfo().name),
|
|
||||||
lit->source);
|
|
||||||
return utils::Failure;
|
return utils::Failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* cv = sem->ConstantValue()->Clone(clone_ctx_);
|
auto* cv = sem->ConstantValue()->Clone(clone_ctx_);
|
||||||
if (!cv) {
|
if (!cv) {
|
||||||
diagnostics_.add_error(
|
add_error(lit->source,
|
||||||
tint::diag::System::IR,
|
"Failed to get constant value for node " + std::string(lit->TypeInfo().name));
|
||||||
"Failed to get constant value for node " + std::string(lit->TypeInfo().name),
|
|
||||||
lit->source);
|
|
||||||
return utils::Failure;
|
return utils::Failure;
|
||||||
}
|
}
|
||||||
return builder.Constant(cv);
|
return builder.Constant(cv);
|
||||||
|
@ -867,10 +856,9 @@ bool BuilderImpl::EmitAttribute(const ast::Attribute* attr) {
|
||||||
// TODO(dsinclair): Implement
|
// TODO(dsinclair): Implement
|
||||||
// },
|
// },
|
||||||
[&](const ast::IdAttribute*) {
|
[&](const ast::IdAttribute*) {
|
||||||
diagnostics_.add_warning(tint::diag::System::IR,
|
add_error(attr->source,
|
||||||
"found an `Id` attribute. The SubstituteOverrides transform "
|
"found an `Id` attribute. The SubstituteOverrides transform "
|
||||||
"must be run before converting to IR",
|
"must be run before converting to IR");
|
||||||
attr->source);
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
[&](const ast::StructMemberSizeAttribute*) {
|
[&](const ast::StructMemberSizeAttribute*) {
|
||||||
|
@ -890,9 +878,7 @@ bool BuilderImpl::EmitAttribute(const ast::Attribute* attr) {
|
||||||
// TODO(dsinclair): Implement
|
// TODO(dsinclair): Implement
|
||||||
// },
|
// },
|
||||||
[&](Default) {
|
[&](Default) {
|
||||||
diagnostics_.add_warning(tint::diag::System::IR,
|
add_error(attr->source, "unknown attribute: " + std::string(attr->TypeInfo().name));
|
||||||
"unknown attribute: " + std::string(attr->TypeInfo().name),
|
|
||||||
attr->source);
|
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,6 +222,8 @@ class BuilderImpl {
|
||||||
|
|
||||||
FlowNode* FindEnclosingControl(ControlFlags flags);
|
FlowNode* FindEnclosingControl(ControlFlags flags);
|
||||||
|
|
||||||
|
void add_error(const Source& s, const std::string& err);
|
||||||
|
|
||||||
const Program* program_ = nullptr;
|
const Program* program_ = nullptr;
|
||||||
|
|
||||||
Symbol CloneSymbol(Symbol sym) const;
|
Symbol CloneSymbol(Symbol sym) const;
|
||||||
|
|
Loading…
Reference in New Issue