[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:
David Neto 2020-04-07 19:55:54 +00:00
parent e70e10953b
commit 574bce6746
2 changed files with 22 additions and 0 deletions

View File

@ -39,11 +39,26 @@ FunctionEmitter::FunctionEmitter(ParserImpl* pi,
FunctionEmitter::~FunctionEmitter() = default; FunctionEmitter::~FunctionEmitter() = default;
bool FunctionEmitter::Emit() { bool FunctionEmitter::Emit() {
if (failed()) {
return false;
}
// We only care about functions with bodies. // We only care about functions with bodies.
if (function_.cbegin() == function_.cend()) { if (function_.cbegin() == function_.cend()) {
return true; return true;
} }
if (!EmitFunctionDeclaration()) {
return false;
}
return success();
}
bool FunctionEmitter::EmitFunctionDeclaration() {
if (failed()) {
return false;
}
const auto name = namer_.Name(function_.result_id()); const auto name = namer_.Name(function_.result_id());
// Surprisingly, the "type id" on an OpFunction is the result type of the // 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 // function, not the type of the function. This is the one exceptional case

View File

@ -50,6 +50,12 @@ class FunctionEmitter {
/// @returns a FailStream on which to emit diagnostics. /// @returns a FailStream on which to emit diagnostics.
FailStream& Fail() { return fail_stream_.Fail(); } 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: private:
ParserImpl& parser_impl_; ParserImpl& parser_impl_;
ast::Module& ast_module_; ast::Module& ast_module_;
@ -57,6 +63,7 @@ class FunctionEmitter {
FailStream& fail_stream_; FailStream& fail_stream_;
Namer& namer_; Namer& namer_;
const spvtools::opt::Function& function_; const spvtools::opt::Function& function_;
std::vector<std::unique_ptr<ast::Statement>> ast_body_;
}; };
} // namespace spirv } // namespace spirv