From 74bac86711b57d5cfb4283023dc0656f8d467994 Mon Sep 17 00:00:00 2001
From: nickysn <nickysn@gmail.com>
Date: Tue, 1 Jun 2021 21:52:51 +0000
Subject: [PATCH] + support loading a function result (on the evaluation stack)
 to a register in   thlcgwasm.gen_load_cgpara_loc

git-svn-id: trunk@49449 -
---
 compiler/wasm32/hlcgcpu.pas | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/compiler/wasm32/hlcgcpu.pas b/compiler/wasm32/hlcgcpu.pas
index 91df2cd909..03aea20d29 100644
--- a/compiler/wasm32/hlcgcpu.pas
+++ b/compiler/wasm32/hlcgcpu.pas
@@ -225,6 +225,8 @@ uses
         twice. Returns how many stack slots have been consumed, disregarding
         the "dup". }
       function prepare_stack_for_ref(list: TAsmList; var ref: treference; dup: boolean): longint;
+
+      procedure gen_load_cgpara_loc(list: TAsmList; vardef: tdef; const para: TCGPara; var destloc: tlocation; reusepara: boolean);override;
      protected
       { return the load/store opcode to load/store from/to ref; if the result
         has to be and'ed after a load to get the final value, that constant
@@ -1061,6 +1063,20 @@ implementation
         end;
     end;
 
+  procedure thlcgwasm.gen_load_cgpara_loc(list: TAsmList; vardef: tdef; const para: TCGPara; var destloc: tlocation; reusepara: boolean);
+    begin
+      { support loading a function result (from the evaluation stack), to a register }
+      if assigned(para.location) and (not assigned(para.location^.next)) and
+         (para.location^.loc in [LOC_REFERENCE,LOC_CREFERENCE]) and
+         (para.location^.reference.index=NR_EVAL_STACK_BASE) and
+         (para.location^.reference.offset=0) and
+         (def_cgsize(para.location^.Def)=destloc.size) and
+         (destloc.loc=LOC_REGISTER) then
+        a_load_stack_loc(list,para.location^.Def,destloc)
+      else
+        inherited;
+    end;
+
   procedure thlcgwasm.a_load_const_reg(list: TAsmList; tosize: tdef; a: tcgint; register: tregister);
     begin
       a_load_const_stack(list,tosize,a,def2regtyp(tosize));