瀏覽代碼

* made ttgobj.alloctemp/freetemp protected, and alloctemp also virtual
* made ttgobj.create virtual, added a "tgobjclass: class of ttgobj = ttgobj"
variable and use that one to instantiate new temp allocators
* created ttgjvm descendant that only allows allocations of 4 or 8 bytes
(rounding allocations < 4 bytes up to 4 bytes), and that divides the
offsets/sizes by 4 so we get stack slot numbers

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

Jonas Maebe 14 年之前
父節點
當前提交
1e96eab55d
共有 4 個文件被更改,包括 69 次插入4 次删除
  1. 1 0
      .gitattributes
  2. 62 0
      compiler/jvm/tgcpu.pas
  3. 1 1
      compiler/psub.pas
  4. 5 3
      compiler/tgobj.pas

+ 1 - 0
.gitattributes

@@ -206,6 +206,7 @@ compiler/ia64/cpuinfo.pas svneol=native#text/plain
 compiler/ia64/ia64reg.dat svneol=native#text/plain
 compiler/ia64/ia64reg.dat svneol=native#text/plain
 compiler/impdef.pas svneol=native#text/plain
 compiler/impdef.pas svneol=native#text/plain
 compiler/import.pas svneol=native#text/plain
 compiler/import.pas svneol=native#text/plain
+compiler/jvm/tgcpu.pas svneol=native#text/plain
 compiler/link.pas svneol=native#text/plain
 compiler/link.pas svneol=native#text/plain
 compiler/m68k/aasmcpu.pas svneol=native#text/plain
 compiler/m68k/aasmcpu.pas svneol=native#text/plain
 compiler/m68k/ag68kgas.pas svneol=native#text/plain
 compiler/m68k/ag68kgas.pas svneol=native#text/plain

+ 62 - 0
compiler/jvm/tgcpu.pas

@@ -0,0 +1,62 @@
+{
+    Copyright (C) 2010 by Jonas Maebe
+
+    This unit handles the temporary variables 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.
+
+ ****************************************************************************
+}
+{
+  This unit handles the temporary variables for the JVM.
+}
+unit tgcpu;
+
+{$i fpcdefs.inc}
+
+  interface
+
+    uses
+       tgobj;
+
+    type
+
+       { ttgjvm }
+
+       ttgjvm = class(ttgobj)
+        protected
+         function alloctemp(list: TAsmList; size, alignment: longint; temptype: ttemptype; def: tdef): longint; override;
+       end;
+
+implementation
+
+{ ttgjvm }
+
+function ttgjvm.alloctemp(list: TAsmList; size, alignment: longint; temptype: ttemptype; def: tdef): longint;
+begin
+  { the JVM only support s1 slot (= 4 bytes in FPC) and 2 slot (= 8 bytes in
+    FPC) temps on the stack. double and int64 are 2 slots, the rest is one slot.
+    There are no problems with reusing the same slot for a vakue of a different
+    type. There are no alignment requirements either. }
+  if size<4 then
+    size:=4;
+  if not(size in [4,8]) then
+    internalerror(2010121401);
+  Result:=inherited alloctemp(list, size div 4, 1, temptype, def);
+end;
+
+begin
+  tgclass:=ttgjvm;
+end.

+ 1 - 1
compiler/psub.pas

@@ -948,7 +948,7 @@ implementation
             create_hlcodegen;
             create_hlcodegen;
 
 
             { set the start offset to the start of the temp area in the stack }
             { set the start offset to the start of the temp area in the stack }
-            tg:=ttgobj.create;
+            tg:=tgobjclass.create;
 
 
 {$if defined(x86) or defined(arm)}
 {$if defined(x86) or defined(arm)}
             { try to strip the stack frame }
             { try to strip the stack frame }

+ 5 - 3
compiler/tgobj.pas

@@ -56,10 +56,10 @@ unit tgobj;
 
 
        {# Generates temporary variables }
        {# Generates temporary variables }
        ttgobj = class
        ttgobj = class
-       private
+       protected
           { contains all free temps using nextfree links }
           { contains all free temps using nextfree links }
           tempfreelist  : ptemprecord;
           tempfreelist  : ptemprecord;
-          function alloctemp(list: TAsmList; size,alignment : longint; temptype : ttemptype; def:tdef) : longint;
+          function alloctemp(list: TAsmList; size,alignment : longint; temptype : ttemptype; def:tdef) : longint; virtual;
           procedure freetemp(list: TAsmList; pos:longint;temptypes:ttemptypeset);
           procedure freetemp(list: TAsmList; pos:longint;temptypes:ttemptypeset);
        public
        public
           { contains all temps }
           { contains all temps }
@@ -68,7 +68,7 @@ unit tgobj;
           firsttemp,
           firsttemp,
           lasttemp      : longint;
           lasttemp      : longint;
           direction : shortint;
           direction : shortint;
-          constructor create;
+          constructor create;virtual;reintroduce;
           {# Clear and free the complete linked list of temporary memory
           {# Clear and free the complete linked list of temporary memory
              locations. The list is set to nil.}
              locations. The list is set to nil.}
           procedure resettempgen;
           procedure resettempgen;
@@ -105,9 +105,11 @@ unit tgobj;
           procedure getlocal(list: TAsmList; size : longint; alignment : shortint; def:tdef;var ref : treference);
           procedure getlocal(list: TAsmList; size : longint; alignment : shortint; def:tdef;var ref : treference);
           procedure UnGetLocal(list: TAsmList; const ref : treference);
           procedure UnGetLocal(list: TAsmList; const ref : treference);
        end;
        end;
+       ttgobjclass = class of ttgobj;
 
 
      var
      var
        tg: ttgobj;
        tg: ttgobj;
+       tgobjclass: ttgobjclass = ttgobj;
 
 
     procedure location_freetemp(list:TAsmList; const l : tlocation);
     procedure location_freetemp(list:TAsmList; const l : tlocation);