소스 검색

+ support for indexing (dynamic) arrays on the JVM

git-svn-id: branches/jvmbackend@18379 -
Jonas Maebe 14 년 전
부모
커밋
e5ce390565
3개의 변경된 파일105개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 0
      .gitattributes
  2. 1 1
      compiler/jvm/cpunode.pas
  3. 103 0
      compiler/jvm/njvmmem.pas

+ 1 - 0
.gitattributes

@@ -225,6 +225,7 @@ compiler/jvm/njvmcnv.pas svneol=native#text/plain
 compiler/jvm/njvmcon.pas svneol=native#text/plain
 compiler/jvm/njvminl.pas svneol=native#text/plain
 compiler/jvm/njvmmat.pas svneol=native#text/plain
+compiler/jvm/njvmmem.pas svneol=native#text/plain
 compiler/jvm/njvmutil.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,njvmcnv,njvmcon,njvminl
+    njvmadd,njvmcal,njvmmat,njvmcnv,njvmcon,njvminl,njvmmem
 {    ncpuadd,ncpucall,ncpumat,ncpuinln,ncpucnv,ncpuset, }
     { this not really a node }
 {    rgcpu},tgcpu,njvmutil;

+ 103 - 0
compiler/jvm/njvmmem.pas

@@ -0,0 +1,103 @@
+{
+    Copyright (c) 2011 by Jonas Maebe
+
+    Generate JVM byetcode for in memory related 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 njvmmem;
+
+{$i fpcdefs.inc}
+
+interface
+
+    uses
+      globtype,
+      cgbase,cpubase,
+      node,nmem,ncgmem;
+
+    type
+       tjvmvecnode = class(tcgvecnode)
+         procedure pass_generate_code;override;
+       end;
+
+implementation
+
+    uses
+      systems,
+      cutils,verbose,
+      symdef,defutil,
+      aasmdata,pass_2,
+      cgutils,hlcgobj;
+
+{*****************************************************************************
+                             TJVMVECNODE
+*****************************************************************************}
+
+    procedure tjvmvecnode.pass_generate_code;
+      var
+        newsize: tcgsize;
+      begin
+        { This routine is not used for Strings, as they are a class type and
+          you have to use charAt() there to load a character (and you cannot
+          change characters; you have to create a new string in that case)
+
+          As far as arrays are concerned: we have to create a trefererence
+          with arrayreftype in [art_indexreg,art_indexref], and ref.base =
+          pointer to the array (i.e., left.location.register) }
+        secondpass(left);
+        newsize:=def_cgsize(resultdef);
+        if left.location.loc=LOC_CREFERENCE then
+          location_reset_ref(location,LOC_CREFERENCE,newsize,left.location.reference.alignment)
+        else
+          location_reset_ref(location,LOC_REFERENCE,newsize,left.location.reference.alignment);
+        hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
+        location.reference.base:=left.location.register;
+        secondpass(right);
+        { simplify index location if necessary, since array references support
+          an index in memory, but not an another array index }
+        if (right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) and
+           (right.location.reference.arrayreftype<>art_none) then
+          hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true);
+
+        case right.location.loc of
+          LOC_REGISTER,LOC_CREGISTER:
+            begin
+              location.reference.arrayreftype:=art_indexreg;
+              location.reference.index:=right.location.register;
+            end;
+          LOC_REFERENCE,LOC_CREFERENCE:
+            begin
+              location.reference.arrayreftype:=art_indexref;
+              location.reference.indexbase:=right.location.reference.base;
+              location.reference.indexsymbol:=right.location.reference.symbol;
+              location.reference.indexoffset:=right.location.reference.offset;
+            end;
+          LOC_CONSTANT:
+            begin
+              location.reference.arrayreftype:=art_indexconst;
+              location.reference.indexoffset:=right.location.value;
+            end
+          else
+            internalerror(2011012002);
+        end;
+      end;
+
+
+begin
+   cvecnode:=tjvmvecnode;
+end.