Run finalizeFunction before creating a FunctionDefinition.

Previously, finalizeFunction took the FunctionDefinition as its input.
This change makes it possible to calculate statistics in
finalizeFunction, such as "how many return statements exist in this
function?" and incorporate that data in the FunctionDefinition at
make_unique time.

Change-Id: I72bb67c802f5416588a5516dfcb61aa56ccf9684
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/386057
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/sksl/dsl/DSLFunction.cpp b/src/sksl/dsl/DSLFunction.cpp
index dc617e7..6c4e851 100644
--- a/src/sksl/dsl/DSLFunction.cpp
+++ b/src/sksl/dsl/DSLFunction.cpp
@@ -52,10 +52,11 @@
 void DSLFunction::define(DSLBlock block) {
     SkASSERT(fDecl);
     const SkSL::FunctionDeclaration* decl = static_cast<const SkSL::FunctionDeclaration*>(fDecl);
-    SkASSERTF(!decl->definition(), "function already defined");
+    SkASSERTF(!decl->definition(), "function '%s' already defined", decl->description().c_str());
+    std::unique_ptr<Statement> body = block.release();
+    DSLWriter::IRGenerator().finalizeFunction(*decl, body.get());
     auto function = std::make_unique<SkSL::FunctionDefinition>(/*offset=*/-1, decl,
-                                                               /*builtin=*/false, block.release());
-    DSLWriter::IRGenerator().finalizeFunction(*function);
+                                                               /*builtin=*/false, std::move(body));
     if (DSLWriter::Compiler().errorCount()) {
         DSLWriter::ReportError(DSLWriter::Compiler().errorText(/*showCount=*/false).c_str());
         DSLWriter::Compiler().setErrorCount(0);