瀏覽代碼

* with temp vars now use a reference with a persistant temp instead
of setting datasize

peter 26 年之前
父節點
當前提交
12313fbed8
共有 10 個文件被更改,包括 140 次插入88 次删除
  1. 12 21
      compiler/cg386cal.pas
  2. 20 7
      compiler/cg386ld.pas
  3. 44 29
      compiler/cg386mem.pas
  4. 5 7
      compiler/pstatmnt.pas
  5. 5 5
      compiler/symtable.pas
  6. 5 3
      compiler/tccal.pas
  7. 4 6
      compiler/tcld.pas
  8. 5 3
      compiler/tcmem.pas
  9. 32 3
      compiler/temp_gen.pas
  10. 8 4
      compiler/tree.pas

+ 12 - 21
compiler/cg386cal.pas

@@ -402,40 +402,28 @@ implementation
                      if we can init from base class for a child
                      class that the wrong VMT will be
                      transfered to constructor !! }
-{$ifdef NODIRECTWITH}
-                   p^.methodpointer^.resulttype:=p^.symtable^.defowner;
-{$else NODIRECTWITH}
                    p^.methodpointer^.resulttype:=
                      ptree(pwithsymtable(p^.symtable)^.withnode)^.left^.resulttype;
-{$endif def NODIRECTWITH}
                    { change dispose type !! }
                    p^.disposetyp:=dt_mbleft_and_method;
                    { make a reference }
                    new(r);
                    reset_reference(r^);
-{$ifndef NODIRECTWITH}
-                   if assigned(ptree(pwithsymtable(p^.symtable)^.withnode)^.pref) then
+                   { if assigned(ptree(pwithsymtable(p^.symtable)^.withnode)^.pref) then
                      begin
                         r^:=ptree(pwithsymtable(p^.symtable)^.withnode)^.pref^;
-                        {if assigned(r^.symbol) then
-                          r^.symbol:=stringdup(r^.symbol^);}
                      end
                    else
-{$endif def NODIRECTWITH}
                      begin
                         r^.offset:=p^.symtable^.datasize;
                         r^.base:=procinfo.framepointer;
-                     end;
-{$ifndef NODIRECTWITH}
+                     end; }
+                   r^:=ptree(pwithsymtable(p^.symtable)^.withnode)^.withreference^;
                    if (not pwithsymtable(p^.symtable)^.direct_with) or
                       pobjectdef(p^.methodpointer^.resulttype)^.isclass then
-{$endif def NODIRECTWITH}
                      exprasmlist^.concat(new(pai386,op_ref_reg(A_MOV,S_L,r,R_ESI)))
-{$ifndef NODIRECTWITH}
                    else
-                     exprasmlist^.concat(new(pai386,op_ref_reg(A_LEA,S_L,r,R_ESI)))
-{$endif def NODIRECTWITH}
-                     ;
+                     exprasmlist^.concat(new(pai386,op_ref_reg(A_LEA,S_L,r,R_ESI)));
                 end;
 
               { push self }
@@ -803,8 +791,7 @@ implementation
                    { process the inlinecode }
                    secondpass(inlinecode);
                    { free the args }
-                   ungetpersistanttemp(p^.procdefinition^.parast^.address_fixup,
-                     p^.procdefinition^.parast^.datasize);
+                   ungetpersistanttemp(p^.procdefinition^.parast^.address_fixup);
                 end;
            end
          else
@@ -1102,7 +1089,7 @@ implementation
               pp:=pp^.right;
            end;
          if inlined then
-           ungetpersistanttemp(inlinecode^.retoffset,4);
+           ungetpersistanttemp(inlinecode^.retoffset);
          disposetree(params);
 
 
@@ -1183,7 +1170,7 @@ implementation
           {we can free the local data now, reset also the fixup address }
           if st^.datasize>0 then
             begin
-              ungetpersistanttemp(st^.address_fixup,st^.datasize);
+              ungetpersistanttemp(st^.address_fixup);
               st^.address_fixup:=0;
             end;
           aktprocsym:=oldprocsym;
@@ -1200,7 +1187,11 @@ implementation
 end.
 {
   $Log$
-  Revision 1.79  1999-05-17 21:56:59  florian
+  Revision 1.80  1999-05-17 23:51:37  peter
+    * with temp vars now use a reference with a persistant temp instead
+      of setting datasize
+
+  Revision 1.79  1999/05/17 21:56:59  florian
     * new temporary ansistring handling
 
   Revision 1.78  1999/05/01 13:24:02  peter

+ 20 - 7
compiler/cg386ld.pas

@@ -196,19 +196,28 @@ implementation
                                      end;
                                    withsymtable:
                                      begin
-                                        hregister:=getregister32;
-                                        p^.location.reference.base:=hregister;
                                         { make a reference }
                                         { symtable datasize field
                                           contains the offset of the temp
                                           stored }
-                                        hp:=new_reference(procinfo.framepointer,
+{                                        hp:=new_reference(procinfo.framepointer,
                                           p^.symtable^.datasize);
 
-                                        exprasmlist^.concat(new(pai386,op_ref_reg(A_MOV,S_L,hp,hregister)));
+                                        exprasmlist^.concat(new(pai386,op_ref_reg(A_MOV,S_L,hp,hregister)));}
 
-                                        p^.location.reference.offset:=
-                                          pvarsym(p^.symtableentry)^.address;
+                                        if ptree(pwithsymtable(p^.symtable)^.withnode)^.islocal then
+                                         begin
+                                           p^.location.reference:=ptree(pwithsymtable(p^.symtable)^.withnode)^.withreference^;
+                                         end
+                                        else
+                                         begin
+                                           hregister:=getregister32;
+                                           p^.location.reference.base:=hregister;
+                                           exprasmlist^.concat(new(pai386,op_ref_reg(A_MOV,S_L,
+                                             newreference(ptree(pwithsymtable(p^.symtable)^.withnode)^.withreference^),
+                                             hregister)));
+                                         end;
+                                        inc(p^.location.reference.offset,pvarsym(p^.symtableentry)^.address);
                                      end;
                                 end;
                            end;
@@ -845,7 +854,11 @@ implementation
 end.
 {
   $Log$
-  Revision 1.55  1999-05-17 21:57:04  florian
+  Revision 1.56  1999-05-17 23:51:38  peter
+    * with temp vars now use a reference with a persistant temp instead
+      of setting datasize
+
+  Revision 1.55  1999/05/17 21:57:04  florian
     * new temporary ansistring handling
 
   Revision 1.54  1999/05/12 00:19:43  peter

+ 44 - 29
compiler/cg386mem.pas

@@ -827,56 +827,67 @@ implementation
         ref : treference;
         symtable : psymtable;
         i : longint;
-        load : boolean;
+        usetemp : boolean;
       begin
          if assigned(p^.left) then
             begin
                secondpass(p^.left);
-               load:=true;
                if p^.left^.location.reference.segment<>R_NO then
                  message(parser_e_no_with_for_variable_in_other_segments);
-               ref.symbol:=nil;
-               gettempofsizereference(4,ref);
+
+               new(p^.withreference);
+
+               usetemp:=false;
                if (p^.left^.treetype=loadn) and
                   (p^.left^.symtable=aktprocsym^.definition^.localst) then
                  begin
-                    { for local class just use the local storage }
-                    ungetiftemp(ref);
-                    new(p^.pref);
-                    p^.pref^:=p^.left^.location.reference;
-                    { don't discard symbol if in main procedure }
-                    p^.left^.location.reference.symbol:=nil;
-                    load:=false;
+                    { for locals use the local storage }
+                    p^.withreference^:=p^.left^.location.reference;
+                    p^.islocal:=true;
                  end
-               else if (p^.left^.resulttype^.deftype=objectdef) and
-                  pobjectdef(p^.left^.resulttype)^.isclass then
+               else
+                if (p^.left^.resulttype^.deftype=objectdef) and
+                   pobjectdef(p^.left^.resulttype)^.isclass then
                  begin
                     exprasmlist^.concat(new(pai386,op_ref_reg(A_MOV,S_L,
-                      newreference(p^.left^.location.reference),R_EDI)))
+                      newreference(p^.left^.location.reference),R_EDI)));
+                    usetemp:=true;
                  end
                else
-                 exprasmlist^.concat(new(pai386,op_ref_reg(A_LEA,S_L,
-                   newreference(p^.left^.location.reference),R_EDI)));
-               if load then
-                 exprasmlist^.concat(new(pai386,op_reg_ref(A_MOV,S_L,
-                 R_EDI,newreference(ref))));
-               del_reference(p^.left^.location.reference);
+                 begin
+                   exprasmlist^.concat(new(pai386,op_ref_reg(A_LEA,S_L,
+                     newreference(p^.left^.location.reference),R_EDI)));
+                   usetemp:=true;
+                 end;
+
+               { if usetemp is set the value must be in %edi }
+               if usetemp then
+                begin
+                  gettempofsizereference(4,p^.withreference^);
+                  normaltemptopersistant(p^.withreference^.offset);
+                  { move to temp reference }
+                  exprasmlist^.concat(new(pai386,op_reg_ref(A_MOV,S_L,
+                    R_EDI,newreference(p^.withreference^))));
+                  del_reference(p^.left^.location.reference);
+                end;
+
                { the offset relative to (%ebp) is only needed here! }
-               symtable:=p^.withsymtable;
+{               symtable:=p^.withsymtable;
                for i:=1 to p^.tablecount do
                  begin
                     symtable^.datasize:=ref.offset;
                     symtable:=symtable^.next;
-                 end;
+                 end; }
 
                { p^.right can be optimize out !!! }
-               if p^.right<>nil then
+               if assigned(p^.right) then
                  secondpass(p^.right);
-               { clear some stuff }
-               if assigned(p^.pref) then
-                 dispose(p^.pref);
-               if load then
-                 ungetiftemp(ref);
+
+               if usetemp then
+                 ungetpersistanttemp(p^.withreference^.offset);
+
+               dispose(p^.withreference);
+               p^.withreference:=nil;
             end;
        end;
 
@@ -884,7 +895,11 @@ implementation
 end.
 {
   $Log$
-  Revision 1.38  1999-05-17 21:57:05  florian
+  Revision 1.39  1999-05-17 23:51:39  peter
+    * with temp vars now use a reference with a persistant temp instead
+      of setting datasize
+
+  Revision 1.38  1999/05/17 21:57:05  florian
     * new temporary ansistring handling
 
   Revision 1.37  1999/05/17 14:14:14  pierre

+ 5 - 7
compiler/pstatmnt.pas

@@ -376,13 +376,11 @@ unit pstatmnt;
                            withsymtable^.symsearch:=obj^.publicsyms^.symsearch;
                            withsymtable^.defowner:=obj;
                            symtab:=withsymtable;
-{$ifndef NODIRECTWITH}
                            if (p^.treetype=loadn) and
                               (p^.symtable=aktprocsym^.definition^.localst) then
                              pwithsymtable(symtab)^.direct_with:=true;
                            {symtab^.withnode:=p; not yet allocated !! }
                            pwithsymtable(symtab)^.withrefnode:=p;
-{$endif ndef NODIRECTWITH}
                            levelcount:=1;
                            obj:=obj^.childof;
                            while assigned(obj) do
@@ -390,13 +388,11 @@ unit pstatmnt;
                               symtab^.next:=new(pwithsymtable,init);
                               symtab:=symtab^.next;
                               symtab^.symsearch:=obj^.publicsyms^.symsearch;
-{$ifndef NODIRECTWITH}
                               if (p^.treetype=loadn) and
                                  (p^.symtable=aktprocsym^.definition^.localst) then
                                 pwithsymtable(symtab)^.direct_with:=true;
                               {symtab^.withnode:=p; not yet allocated !! }
                               pwithsymtable(symtab)^.withrefnode:=p;
-{$endif ndef NODIRECTWITH}
                               symtab^.defowner:=obj;
                               obj:=obj^.childof;
                               inc(levelcount);
@@ -410,13 +406,11 @@ unit pstatmnt;
                            withsymtable:=new(pwithsymtable,init);
                            withsymtable^.symsearch:=symtab^.symsearch;
                            withsymtable^.next:=symtablestack;
-{$ifndef NODIRECTWITH}
                               if (p^.treetype=loadn) and
                                  (p^.symtable=aktprocsym^.definition^.localst) then
                                 pwithsymtable(withsymtable)^.direct_with:=true;
                               {symtab^.withnode:=p; not yet allocated !! }
                               pwithsymtable(withsymtable)^.withrefnode:=p;
-{$endif ndef NODIRECTWITH}
                            withsymtable^.defowner:=obj;
                            symtablestack:=withsymtable;
                         end;
@@ -1273,7 +1267,11 @@ unit pstatmnt;
 end.
 {
   $Log$
-  Revision 1.84  1999-05-13 21:59:38  peter
+  Revision 1.85  1999-05-17 23:51:40  peter
+    * with temp vars now use a reference with a persistant temp instead
+      of setting datasize
+
+  Revision 1.84  1999/05/13 21:59:38  peter
     * removed oldppu code
     * warning if objpas is loaded from uses
     * first things for new deref writing

+ 5 - 5
compiler/symtable.pas

@@ -226,7 +226,6 @@ unit symtable;
 
        pwithsymtable = ^twithsymtable;
        twithsymtable = object(tsymtable)
-{$ifndef NODIRECTWITH}
           { used for withsymtable for allowing constructors }
           direct_with : boolean;
           { in fact it is a ptree }
@@ -235,7 +234,6 @@ unit symtable;
           { already usable before firstwith
             needed for firstpass of function parameters PM }
           withrefnode : pointer;
-{$endif def NODIRECTWITH}
           constructor init;
           destructor  done;virtual;
         end;
@@ -1041,11 +1039,9 @@ const localsymtablestack : psymtable = nil;
     constructor twithsymtable.init;
       begin
          inherited init(withsymtable);
-{$ifndef NODIRECTWITH}
          direct_with:=false;
          withnode:=nil;
          withrefnode:=nil;
-{$endif def NODIRECTWITH}
       end;
 
 
@@ -2349,7 +2345,11 @@ const localsymtablestack : psymtable = nil;
 end.
 {
   $Log$
-  Revision 1.14  1999-05-14 17:52:29  peter
+  Revision 1.15  1999-05-17 23:51:41  peter
+    * with temp vars now use a reference with a persistant temp instead
+      of setting datasize
+
+  Revision 1.14  1999/05/14 17:52:29  peter
     * new deref code
 
   Revision 1.13  1999/05/13 21:59:48  peter

+ 5 - 3
compiler/tccal.pas

@@ -1073,7 +1073,6 @@ implementation
                 typen,hnewn : ;
                 else
                   begin
-{$ifndef NODIRECTWITH}
                      if ((p^.procdefinition^.options and (poconstructor or podestructor)) <> 0) and
                         assigned(p^.symtable) and (p^.symtable^.symtabletype=withsymtable) and
                         not pwithsymtable(p^.symtable)^.direct_with then
@@ -1082,7 +1081,6 @@ implementation
                        end; { Is accepted by Delphi !! }
                      { this is not a good reason to accept it in FPC if we produce
                        wrong code for it !!! (PM) }
-{$endif ndef NODIRECTWITH}
 
                      { R.Assign is not a constructor !!! }
                      { but for R^.Assign, R must be valid !! }
@@ -1149,7 +1147,11 @@ implementation
 end.
 {
   $Log$
-  Revision 1.41  1999-05-13 21:59:50  peter
+  Revision 1.42  1999-05-17 23:51:43  peter
+    * with temp vars now use a reference with a persistant temp instead
+      of setting datasize
+
+  Revision 1.41  1999/05/13 21:59:50  peter
     * removed oldppu code
     * warning if objpas is loaded from uses
     * first things for new deref writing

+ 4 - 6
compiler/tcld.pas

@@ -63,10 +63,8 @@ implementation
          p1 : ptree;
 
       begin
-{$ifndef NODIRECTWITH}
          if (p^.symtable^.symtabletype=withsymtable) and
-            (pwithsymtable(p^.symtable)^.direct_with) and
-            (p^.symtableentry^.typ=varsym) then
+            (pwithsymtable(p^.symtable)^.direct_with) then
            begin
               p1:=getcopy(ptree(pwithsymtable(p^.symtable)^.withrefnode));
               p1:=gensubscriptnode(pvarsym(p^.symtableentry),p1);
@@ -75,7 +73,6 @@ implementation
               firstpass(p);
               exit;
            end;
-{$endif ndef NODIRECTWITH}
 
          p^.location.loc:=LOC_REFERENCE;
          p^.registers32:=0;
@@ -452,8 +449,9 @@ implementation
 end.
 {
   $Log$
-  Revision 1.28  1999-05-16 17:04:39  peter
-    * fixed with and procsym
+  Revision 1.29  1999-05-17 23:51:45  peter
+    * with temp vars now use a reference with a persistant temp instead
+      of setting datasize
 
   Revision 1.27  1999/05/12 00:20:02  peter
     * removed R_DEFAULT_SEG

+ 5 - 3
compiler/tcmem.pas

@@ -525,7 +525,6 @@ implementation
                firstpass(p^.left);
                if codegenerror then
                  exit;
-{$ifndef NODIRECTWITH}
                symtable:=p^.withsymtable;
                for i:=1 to p^.tablecount do
                  begin
@@ -535,7 +534,6 @@ implementation
                     symtable^.withnode:=p;
                     symtable:=pwithsymtable(symtable^.next);
                   end;
-{$endif ndef NODIRECTWITH}
                firstpass(p^.right);
                if codegenerror then
                  exit;
@@ -555,7 +553,11 @@ implementation
 end.
 {
   $Log$
-  Revision 1.14  1999-05-01 13:24:57  peter
+  Revision 1.15  1999-05-17 23:51:46  peter
+    * with temp vars now use a reference with a persistant temp instead
+      of setting datasize
+
+  Revision 1.14  1999/05/01 13:24:57  peter
     * merged nasm compiler
     * old asm moved to oldasm/
 

+ 32 - 3
compiler/temp_gen.pas

@@ -72,9 +72,10 @@ unit temp_gen;
     { special call for inlined procedures }
     function gettempofsizepersistant(size : longint) : longint;
     { for parameter func returns }
+    procedure normaltemptopersistant(pos : longint);
     procedure persistanttemptonormal(pos : longint);
     {procedure ungettemp(pos : longint;size : longint);}
-    procedure ungetpersistanttemp(pos : longint;size : longint);
+    procedure ungetpersistanttemp(pos : longint);
     procedure gettempofsizereference(l : longint;var ref : treference);
     function istemp(const ref : treference) : boolean;
     procedure ungetiftemp(const ref : treference);
@@ -394,6 +395,30 @@ unit temp_gen;
       end;
 
 
+    procedure normaltemptopersistant(pos : longint);
+      var
+        hp : ptemprecord;
+      begin
+         hp:=templist;
+         while assigned(hp) do
+           if (hp^.pos=pos) and (hp^.temptype=tt_normal) then
+             begin
+{$ifdef EXTDEBUG}
+               Comment(V_Debug,'temp managment : normaltemptopersistant()'+
+                  ' at pos '+tostr(pos)+ ' found !');
+{$endif}
+                hp^.temptype:=tt_persistant;
+                exit;
+             end
+           else
+             hp:=hp^.next;
+{$ifdef EXTDEBUG}
+         Comment(V_Debug,'temp managment problem : normaltemptopersistant()'+
+            ' at pos '+tostr(pos)+ ' not found !');
+{$endif}
+      end;
+
+
     function ungettemp(pos:longint;allowtype:ttemptype):ttemptype;
       var
          hp,hnext,hprev,hprevfree : ptemprecord;
@@ -454,7 +479,7 @@ unit temp_gen;
       end;
 
 
-    procedure ungetpersistanttemp(pos : longint;size : longint);
+    procedure ungetpersistanttemp(pos : longint);
       begin
 {$ifdef EXTDEBUG}
         if ungettemp(pos,tt_persistant)<>tt_persistant then
@@ -497,7 +522,11 @@ begin
 end.
 {
   $Log$
-  Revision 1.24  1999-05-17 21:57:17  florian
+  Revision 1.25  1999-05-17 23:51:47  peter
+    * with temp vars now use a reference with a persistant temp instead
+      of setting datasize
+
+  Revision 1.24  1999/05/17 21:57:17  florian
     * new temporary ansistring handling
 
   Revision 1.23  1999/05/17 12:49:16  pierre

+ 8 - 4
compiler/tree.pas

@@ -240,8 +240,7 @@ unit tree;
              asmn : (p_asm : paasmoutput;object_preserved : boolean);
              casen : (nodes : pcaserecord;elseblock : ptree);
              labeln,goton : (labelnr : plabel);
-             withn : (withsymtable : pwithsymtable;tablecount : longint;
-                     pref : preference);
+             withn : (withsymtable : pwithsymtable;tablecount : longint;withreference:preference;islocal:boolean);
              onn : (exceptsymtable : psymtable;excepttype : pobjectdef);
              arrayconstructn : (cargs,cargswap: boolean);
            end;
@@ -600,7 +599,8 @@ unit tree;
          p^.resulttype:=nil;
          p^.withsymtable:=symtable;
          p^.tablecount:=count;
-         p^.pref:=nil;
+         p^.withreference:=nil;
+         p^.islocal:=false;
          set_file_line(l,p);
          genwithnode:=p;
       end;
@@ -1708,7 +1708,11 @@ unit tree;
 end.
 {
   $Log$
-  Revision 1.79  1999-05-17 13:00:36  pierre
+  Revision 1.80  1999-05-17 23:51:48  peter
+    * with temp vars now use a reference with a persistant temp instead
+      of setting datasize
+
+  Revision 1.79  1999/05/17 13:00:36  pierre
    * old field suppressed was still in debug code
 
   Revision 1.78  1999/05/12 00:20:03  peter