Explorar o código

+ support for floating point constants

git-svn-id: branches/jvmbackend@18333 -
Jonas Maebe %!s(int64=14) %!d(string=hai) anos
pai
achega
dd2862e25a
Modificáronse 4 ficheiros con 95 adicións e 2 borrados
  1. 1 0
      .gitattributes
  2. 1 1
      compiler/jvm/cpunode.pas
  3. 33 1
      compiler/jvm/hlcgcpu.pas
  4. 60 0
      compiler/jvm/njvmcon.pas

+ 1 - 0
.gitattributes

@@ -220,6 +220,7 @@ compiler/jvm/itcpujas.pas svneol=native#text/plain
 compiler/jvm/jvmreg.dat svneol=native#text/plain
 compiler/jvm/njvmadd.pas svneol=native#text/plain
 compiler/jvm/njvmcal.pas svneol=native#text/plain
+compiler/jvm/njvmcon.pas svneol=native#text/plain
 compiler/jvm/njvmmat.pas svneol=native#text/plain
 compiler/jvm/rgcpu.pas svneol=native#text/plain
 compiler/jvm/rjvmcon.inc svneol=native#text/plain

+ 1 - 1
compiler/jvm/cpunode.pas

@@ -32,7 +32,7 @@ implementation
   uses
     ncgbas,ncgflw,ncgcnv,ncgld,ncgmem,ncgcon,ncgset,
     ncgadd, ncgcal,ncgmat,ncginl,
-    njvmadd,njvmcal,njvmmat
+    njvmadd,njvmcal,njvmmat,njvmcon
 {    ncpuadd,ncpucall,ncpumat,ncpuinln,ncpucnv,ncpuset, }
     { this not really a node }
 {    rgcpu},tgcpu;

+ 33 - 1
compiler/jvm/hlcgcpu.pas

@@ -98,6 +98,8 @@ uses
 
       procedure a_load_loc_stack(list : TAsmList;size: tdef;const loc: tlocation);
 
+      procedure a_loadfpu_const_stack(list : TAsmList;size: tdef;a :double);
+
       procedure a_op_stack(list : TAsmList;op: topcg; size: tdef; trunc32: boolean);
       procedure a_op_const_stack(list : TAsmList;op: topcg; size: tdef;a : aint);
       procedure a_op_reg_stack(list : TAsmList;op: topcg; size: tdef;reg: tregister);
@@ -151,7 +153,7 @@ uses
 
   const
     opcmp2if: array[topcmp] of tasmop = (A_None,
-      a_ifeq,a_ifgt,a_if_icmplt,a_ifge,a_ifle,
+      a_ifeq,a_ifgt,a_iflt,a_ifge,a_ifle,
       a_ifne,a_ifle,a_iflt,a_ifge,a_ifgt);
 
 implementation
@@ -270,6 +272,36 @@ implementation
         end;
       end;
 
+  procedure thlcgjvm.a_loadfpu_const_stack(list: TAsmList; size: tdef; a: double);
+    begin
+      case tfloatdef(size).floattype of
+        s32real:
+          begin
+            if a=0.0 then
+              list.concat(taicpu.op_none(a_fconst_0))
+            else if a=1.0 then
+              list.concat(taicpu.op_none(a_fconst_1))
+            else if a=2.0 then
+              list.concat(taicpu.op_none(a_fconst_2))
+            else
+              list.concat(taicpu.op_single(a_ldc,a));
+            incstack(1);
+          end;
+        s64real:
+          begin
+            if a=0.0 then
+              list.concat(taicpu.op_none(a_dconst_0))
+            else if a=1.0 then
+              list.concat(taicpu.op_none(a_dconst_1))
+            else
+              list.concat(taicpu.op_double(a_ldc2_w,a));
+            incstack(2);
+          end
+        else
+          internalerror(2011010501);
+      end;
+    end;
+
   procedure thlcgjvm.a_op_stack(list: TAsmList; op: topcg; size: tdef; trunc32: boolean);
     var
       cgsize: tcgsize;

+ 60 - 0
compiler/jvm/njvmcon.pas

@@ -0,0 +1,60 @@
+{
+    Copyright (c) 1998-2011 by Florian Klaempfl and Jonas Maebe
+
+    Generate assembler for constant nodes for the JVM
+
+    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 njvmcon;
+
+{$i fpcdefs.inc}
+
+interface
+
+    uses
+       node,ncon,ncgcon;
+
+    type
+       tjvmrealconstnode = class(tcgrealconstnode)
+          procedure pass_generate_code;override;
+       end;
+
+implementation
+
+    uses
+      globtype,
+      aasmdata,defutil,
+      cgbase,hlcgobj,hlcgcpu,cgutils
+      ;
+
+
+{*****************************************************************************
+                           TJVMREALCONSTNODE
+*****************************************************************************}
+
+    procedure tjvmrealconstnode.pass_generate_code;
+      begin
+        location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
+        location.register:=hlcg.getfpuregister(current_asmdata.CurrAsmList,resultdef);
+        thlcgjvm(hlcg).a_loadfpu_const_stack(current_asmdata.CurrAsmList,resultdef,value_real);
+        thlcgjvm(hlcg).a_load_stack_reg(current_asmdata.CurrAsmList,resultdef,location.register);
+      end;
+
+
+begin
+   crealconstnode:=tjvmrealconstnode;
+end.