[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>
diff --git a/src/reader/spirv/function.cc b/src/reader/spirv/function.cc
index 28a710c..9c84161 100644
--- a/src/reader/spirv/function.cc
+++ b/src/reader/spirv/function.cc
@@ -39,11 +39,26 @@
 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 9e1347b..4083575 100644
--- a/src/reader/spirv/function.h
+++ b/src/reader/spirv/function.h
@@ -50,6 +50,12 @@
   /// @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 @@
   FailStream& fail_stream_;
   Namer& namer_;
   const spvtools::opt::Function& function_;
+  std::vector<std::unique_ptr<ast::Statement>> ast_body_;
 };
 
 }  // namespace spirv