[spirv-reader] Split function emission into parts
Bug: tint:3 Change-Id: Ifedf4e00c7d89641496330ab20bf797f656c761c Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/18703 Reviewed-by: dan sinclair <dsinclair@google.com>
This commit is contained in:
parent
e70e10953b
commit
574bce6746
|
@ -39,11 +39,26 @@ FunctionEmitter::FunctionEmitter(ParserImpl* pi,
|
|||
FunctionEmitter::~FunctionEmitter() = default;
|
||||
|
||||
bool FunctionEmitter::Emit() {
|
||||
if (failed()) {
|
||||
return false;
|
||||
}
|
||||
// We only care about functions with bodies.
|
||||
if (function_.cbegin() == function_.cend()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!EmitFunctionDeclaration()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return success();
|
||||
}
|
||||
|
||||
bool FunctionEmitter::EmitFunctionDeclaration() {
|
||||
if (failed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto name = namer_.Name(function_.result_id());
|
||||
// Surprisingly, the "type id" on an OpFunction is the result type of the
|
||||
// function, not the type of the function. This is the one exceptional case
|
||||
|
|
|
@ -50,6 +50,12 @@ class FunctionEmitter {
|
|||
/// @returns a FailStream on which to emit diagnostics.
|
||||
FailStream& Fail() { return fail_stream_.Fail(); }
|
||||
|
||||
/// Emits the declaration, which comprises the name, parameters, and
|
||||
/// return type. The function AST node is appended to the module
|
||||
/// AST node.
|
||||
/// @returns true if emission has not yet failed.
|
||||
bool EmitFunctionDeclaration();
|
||||
|
||||
private:
|
||||
ParserImpl& parser_impl_;
|
||||
ast::Module& ast_module_;
|
||||
|
@ -57,6 +63,7 @@ class FunctionEmitter {
|
|||
FailStream& fail_stream_;
|
||||
Namer& namer_;
|
||||
const spvtools::opt::Function& function_;
|
||||
std::vector<std::unique_ptr<ast::Statement>> ast_body_;
|
||||
};
|
||||
|
||||
} // namespace spirv
|
||||
|
|
Loading…
Reference in New Issue