Browse Source

* factored out releasing an unused return value into
release_unused_return_value_cpu(), so it can be cleanly
overridden by cpu-specific code

git-svn-id: branches/jvmbackend@18322 -

Jonas Maebe 14 years ago
parent
commit
b837694207
5 changed files with 85 additions and 12 deletions
  1. 1 0
      .gitattributes
  2. 2 2
      compiler/i386/n386cal.pas
  3. 13 8
      compiler/ncgcal.pas
  4. 67 0
      compiler/x86/nx86cal.pas
  5. 2 2
      compiler/x86_64/nx64cal.pas

+ 1 - 0
.gitattributes

@@ -656,6 +656,7 @@ compiler/x86/hlcgx86.pas svneol=native#text/plain
 compiler/x86/itcpugas.pas svneol=native#text/plain
 compiler/x86/itcpugas.pas svneol=native#text/plain
 compiler/x86/itx86int.pas svneol=native#text/plain
 compiler/x86/itx86int.pas svneol=native#text/plain
 compiler/x86/nx86add.pas svneol=native#text/plain
 compiler/x86/nx86add.pas svneol=native#text/plain
+compiler/x86/nx86cal.pas svneol=native#text/plain
 compiler/x86/nx86cnv.pas svneol=native#text/plain
 compiler/x86/nx86cnv.pas svneol=native#text/plain
 compiler/x86/nx86con.pas svneol=native#text/plain
 compiler/x86/nx86con.pas svneol=native#text/plain
 compiler/x86/nx86inl.pas svneol=native#text/plain
 compiler/x86/nx86inl.pas svneol=native#text/plain

+ 2 - 2
compiler/i386/n386cal.pas

@@ -28,10 +28,10 @@ interface
 { $define AnsiStrRef}
 { $define AnsiStrRef}
 
 
     uses
     uses
-      ncgcal;
+      nx86cal;
 
 
     type
     type
-       ti386callnode = class(tcgcallnode)
+       ti386callnode = class(tx86callnode)
        protected
        protected
           procedure pop_parasize(pop_size:longint);override;
           procedure pop_parasize(pop_size:longint);override;
           procedure extra_interrupt_code;override;
           procedure extra_interrupt_code;override;

+ 13 - 8
compiler/ncgcal.pas

@@ -75,6 +75,11 @@ interface
             can work with it. This routine decides what the most appropriate
             can work with it. This routine decides what the most appropriate
             tlocation is and sets self.location based on that. }
             tlocation is and sets self.location based on that. }
           procedure set_result_location(realresdef: tstoreddef);virtual;
           procedure set_result_location(realresdef: tstoreddef);virtual;
+
+          { if an unused return value is in another location than a
+            LOC_REFERENCE, this method will be called to perform the necessary
+            cleanups. By default it does not do anything }
+          procedure release_unused_return_value_cpu;virtual;
        public
        public
           procedure pass_generate_code;override;
           procedure pass_generate_code;override;
           destructor destroy;override;
           destructor destroy;override;
@@ -309,6 +314,12 @@ implementation
       end;
       end;
 
 
 
 
+    procedure tcgcallnode.release_unused_return_value_cpu;
+      begin
+        { do nothing }
+      end;
+
+
     procedure tcgcallnode.pop_parasize(pop_size:longint);
     procedure tcgcallnode.pop_parasize(pop_size:longint);
       begin
       begin
       end;
       end;
@@ -431,14 +442,8 @@ implementation
                      cg.g_finalize(current_asmdata.CurrAsmList,resultdef,location.reference);
                      cg.g_finalize(current_asmdata.CurrAsmList,resultdef,location.reference);
                    tg.ungetiftemp(current_asmdata.CurrAsmList,location.reference);
                    tg.ungetiftemp(current_asmdata.CurrAsmList,location.reference);
                 end;
                 end;
-{$ifdef x86}
-              LOC_FPUREGISTER :
-                 begin
-                   { release FPU stack }
-                   emit_reg(A_FSTP,S_NO,NR_FPU_RESULT_REG);
-                   tcgx86(cg).dec_fpu_stack;
-                 end;
-{$endif x86}
+              else
+                release_unused_return_value_cpu;
             end;
             end;
             if (retloc.intsize<>0) then
             if (retloc.intsize<>0) then
               paramanager.freecgpara(current_asmdata.CurrAsmList,retloc);
               paramanager.freecgpara(current_asmdata.CurrAsmList,retloc);

+ 67 - 0
compiler/x86/nx86cal.pas

@@ -0,0 +1,67 @@
+{
+    Copyright (c) 1998-2002 by Florian Klaempfl
+
+    Common x86 support for call nodes
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit nx86cal;
+
+{$i fpcdefs.inc}
+
+interface
+
+{ $define AnsiStrRef}
+
+    uses
+      ncgcal;
+
+    type
+
+       { tx86callnode }
+
+       tx86callnode = class(tcgcallnode)
+        protected
+         procedure release_unused_return_value_cpu;override;
+       end;
+
+
+implementation
+
+    uses
+      cgobj,
+      cgbase,cpubase,cgx86,cga;
+
+
+{*****************************************************************************
+                             TX86CALLNODE
+*****************************************************************************}
+
+    procedure tx86callnode.release_unused_return_value_cpu;
+      begin
+        case location.loc of
+          LOC_FPUREGISTER :
+             begin
+               { release FPU stack }
+               emit_reg(A_FSTP,S_NO,NR_FPU_RESULT_REG);
+               tcgx86(cg).dec_fpu_stack;
+             end;
+        end;
+      end;
+
+
+end.

+ 2 - 2
compiler/x86_64/nx64cal.pas

@@ -27,10 +27,10 @@ interface
 
 
     uses
     uses
       symdef,
       symdef,
-      ncal,ncgcal;
+      ncal,nx86cal;
 
 
     type
     type
-       tx8664callnode = class(tcgcallnode)
+       tx8664callnode = class(tx86callnode)
         protected
         protected
          procedure extra_call_code;override;
          procedure extra_call_code;override;
          procedure set_result_location(realresdef: tstoreddef);override;
          procedure set_result_location(realresdef: tstoreddef);override;