diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc index 28a710c323..9c841619ad 100644 --- a/src/reader/spirv/function.cc +++ b/src/reader/spirv/function.cc @@ -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 diff --git a/src/reader/spirv/function.h b/src/reader/spirv/function.h index 9e1347b296..4083575d2d 100644 --- a/src/reader/spirv/function.h +++ b/src/reader/spirv/function.h @@ -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> ast_body_; }; } // namespace spirv