Browse Source

* moved "reverseparameters" from ninl.pas to ncal.pas
+ support for non-persistent temps in ttempcreatenode.create, for use
with typeconversion nodes

Jonas Maebe 24 years ago
parent
commit
fc1b58c22c
4 changed files with 71 additions and 30 deletions
  1. 20 5
      compiler/nbas.pas
  2. 32 1
      compiler/ncal.pas
  3. 10 2
      compiler/ncgbas.pas
  4. 9 22
      compiler/ninl.pas

+ 20 - 5
compiler/nbas.pas

@@ -80,16 +80,25 @@ interface
          valid: boolean;
        end;
 
-       { a node which will create a *persistent* temp of a given type with a given size }
-       { (the size is separate to allow creating "void" temps with a custom size)       }
+       { a node which will create a (non)persistent temp of a given type with a given  }
+       { size (the size is separate to allow creating "void" temps with a custom size) }
        ttempcreatenode = class(tnode)
           size: longint;
           tempinfo: ptempinfo;
-          constructor create(const _restype: ttype; _size: longint); virtual;
+          { * persistent temps are used in manually written code where the temp }
+          { be usable among different statements and where you can manually say }
+          { when the temp has to be freed (using a ttempdeletenode)             }
+          { * non-persistent temps are mostly used in typeconversion helpers,   }
+          { where the node that receives the temp becomes responsible for       }
+          { freeing it. In this last case, you should use only one reference    }
+          { to it and *not* generate a ttempdeletenode                          }
+          constructor create(const _restype: ttype; _size: longint; _persistent: boolean); virtual;
           function getcopy: tnode; override;
           function pass_1 : tnode; override;
           function det_resulttype: tnode; override;
           function docompare(p: tnode): boolean; override;
+         protected
+          persistent: boolean;
         end;
 
         { a node which is a reference to a certain temp }
@@ -442,13 +451,14 @@ implementation
                           TEMPCREATENODE
 *****************************************************************************}
 
-    constructor ttempcreatenode.create(const _restype: ttype; _size: longint);
+    constructor ttempcreatenode.create(const _restype: ttype; _size: longint; _persistent: boolean);
       begin
         inherited create(tempn);
         size := _size;
         new(tempinfo);
         fillchar(tempinfo^,sizeof(tempinfo^),0);
         tempinfo^.restype := _restype;
+        persistent := _persistent;
       end;
 
     function ttempcreatenode.getcopy: tnode;
@@ -610,7 +620,12 @@ begin
 end.
 {
   $Log$
-  Revision 1.14  2001-08-23 14:28:35  jonas
+  Revision 1.15  2001-08-24 13:47:26  jonas
+    * moved "reverseparameters" from ninl.pas to ncal.pas
+    + support for non-persistent temps in ttempcreatenode.create, for use
+      with typeconversion nodes
+
+  Revision 1.14  2001/08/23 14:28:35  jonas
     + tempcreate/ref/delete nodes (allows the use of temps in the
       resulttype and first pass)
     * made handling of read(ln)/write(ln) processor independent

+ 32 - 1
compiler/ncal.pas

@@ -96,6 +96,9 @@ interface
           function docompare(p: tnode): boolean; override;
        end;
 
+    function reverseparameters(p: tcallparanode): tcallparanode;
+
+
     var
        ccallnode : class of tcallnode;
        ccallparanode : class of tcallparanode;
@@ -116,6 +119,29 @@ implementation
       ;
 
 
+{****************************************************************************
+                             HELPERS
+ ****************************************************************************}
+
+    function reverseparameters(p: tcallparanode): tcallparanode;
+      var
+        hp1, hp2: tcallparanode;
+      begin
+        hp1:=nil;
+        while assigned(p) do
+          begin
+             { pull out }
+             hp2:=p;
+             p:=tcallparanode(p.right);
+             { pull in }
+             hp2.right:=hp1;
+             hp1:=hp2;
+          end;
+        reverseparameters:=hp1;
+      end;
+
+
+
 {****************************************************************************
                              TCALLPARANODE
  ****************************************************************************}
@@ -1691,7 +1717,12 @@ begin
 end.
 {
   $Log$
-  Revision 1.43  2001-08-23 14:28:35  jonas
+  Revision 1.44  2001-08-24 13:47:27  jonas
+    * moved "reverseparameters" from ninl.pas to ncal.pas
+    + support for non-persistent temps in ttempcreatenode.create, for use
+      with typeconversion nodes
+
+  Revision 1.43  2001/08/23 14:28:35  jonas
     + tempcreate/ref/delete nodes (allows the use of temps in the
       resulttype and first pass)
     * made handling of read(ln)/write(ln) processor independent

+ 10 - 2
compiler/ncgbas.pas

@@ -242,7 +242,10 @@ interface
           internalerror(200108222);
 
         { get a (persistent) temp }
-        gettempofsizereferencepersistant(size,tempinfo^.ref);
+        if persistent then
+          gettempofsizereferencepersistant(size,tempinfo^.ref)
+        else
+          gettempofsizereference(size,tempinfo^.ref);
         tempinfo^.valid := true;
       end;
 
@@ -282,7 +285,12 @@ begin
 end.
 {
   $Log$
-  Revision 1.5  2001-08-23 14:28:35  jonas
+  Revision 1.6  2001-08-24 13:47:27  jonas
+    * moved "reverseparameters" from ninl.pas to ncal.pas
+    + support for non-persistent temps in ttempcreatenode.create, for use
+      with typeconversion nodes
+
+  Revision 1.5  2001/08/23 14:28:35  jonas
     + tempcreate/ref/delete nodes (allows the use of temps in the
       resulttype and first pass)
     * made handling of read(ln)/write(ln) processor independent

+ 9 - 22
compiler/ninl.pas

@@ -99,24 +99,6 @@ implementation
 
 {$ifdef hascompilerproc}
 
-      { helper, doesn't really belong here (JM) }
-      function reverseparameters(p: tcallparanode): tcallparanode;
-        var
-          hp1, hp2: tcallparanode;
-        begin
-          hp1:=nil;
-          while assigned(p) do
-            begin
-               { pull out }
-               hp2:=p;
-               p:=tcallparanode(p.right);
-               { pull in }
-               hp2.right:=hp1;
-               hp1:=hp2;
-            end;
-          reverseparameters:=hp1;
-        end;
-
       function tinlinenode.handle_str : tnode;
       var
         lenpara,
@@ -394,7 +376,7 @@ implementation
             if (filepara.left.nodetype <> loadn) then
               begin
                 { create a temp which will hold a pointer to the file }
-                filetemp := ctempcreatenode.create(voidpointertype,voidpointertype.def.size);
+                filetemp := ctempcreatenode.create(voidpointertype,voidpointertype.def.size,true);
 
                 { add it to the statements }
                 newstatement.left := cstatementnode.create(nil,filetemp);
@@ -704,7 +686,7 @@ implementation
                           restype := @u32bittype;
 
                         { create the parameter list: the temp ... }
-                        temp := ctempcreatenode.create(restype^,restype^.def.size);
+                        temp := ctempcreatenode.create(restype^,restype^.def.size,true);
                         newstatement.left := cstatementnode.create(nil,temp);
                         newstatement := tstatementnode(newstatement.left);
 
@@ -879,7 +861,7 @@ implementation
         if not assigned(codepara) or
            (torddef(codepara.resulttype.def).typ in [u8bit,u16bit,s8bit,s16bit]) then
           begin
-            tempcode := ctempcreatenode.create(s32bittype,4);
+            tempcode := ctempcreatenode.create(s32bittype,4,true);
             newstatement.left := cstatementnode.create(nil,tempcode);
             newstatement := tstatementnode(newstatement.left);
             { set the resulttype of the temp (needed to be able to get }
@@ -2730,7 +2712,12 @@ begin
 end.
 {
   $Log$
-  Revision 1.50  2001-08-24 12:33:54  jonas
+  Revision 1.51  2001-08-24 13:47:27  jonas
+    * moved "reverseparameters" from ninl.pas to ncal.pas
+    + support for non-persistent temps in ttempcreatenode.create, for use
+      with typeconversion nodes
+
+  Revision 1.50  2001/08/24 12:33:54  jonas
     * fixed big bug in handle_str that caused it to (almost) always call
       fpc_<stringtype>_longint
     * fixed small bug in handle_read_write that caused wrong warnigns about