Browse Source

+ AfterConstruction and BeforeDestruction impemented

florian 25 years ago
parent
commit
f89ea69e76
2 changed files with 63 additions and 21 deletions
  1. 12 4
      compiler/i386/cgai386.pas
  2. 51 17
      compiler/i386/n386cal.pas

+ 12 - 4
compiler/i386/cgai386.pas

@@ -2680,10 +2680,15 @@ implementation
 
 
                   emitlab(okexitlabel);
                   emitlab(okexitlabel);
 
 
-                  exprasmlist^.concat(new(pairegalloc,alloc(R_EAX)));
-                  emit_reg_reg(A_MOV,S_L,R_ESI,R_EAX);
+                  { for classes this is done after the call to }
+                  { AfterConstruction                          }
+                  if is_object(procinfo^._class) then
+                    begin
+                       exprasmlist^.concat(new(pairegalloc,alloc(R_EAX)));
+                       emit_reg_reg(A_MOV,S_L,R_ESI,R_EAX);
+                       uses_eax:=true;
+                    end;
                   emit_reg_reg(A_TEST,S_L,R_ESI,R_ESI);
                   emit_reg_reg(A_TEST,S_L,R_ESI,R_ESI);
-                  uses_eax:=true;
                   uses_esi:=true;
                   uses_esi:=true;
               end;
               end;
 
 
@@ -2931,7 +2936,10 @@ implementation
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.9  2000-11-06 23:49:20  florian
+  Revision 1.10  2000-11-07 23:40:48  florian
+    + AfterConstruction and BeforeDestruction impemented
+
+  Revision 1.9  2000/11/06 23:49:20  florian
     * fixed init_paras call
     * fixed init_paras call
 
 
   Revision 1.8  2000/11/06 23:15:01  peter
   Revision 1.8  2000/11/06 23:15:01  peter

+ 51 - 17
compiler/i386/n386cal.pas

@@ -808,6 +808,28 @@ implementation
                      end;
                      end;
                 end;
                 end;
 
 
+                { call to BeforeDestruction? }
+                if (procdefinition^.proctypeoption=potype_destructor) and
+                   assigned(methodpointer) and
+                   (methodpointer.nodetype<>typen) and
+                   is_class(pobjectdef(methodpointer.resulttype)) and
+                   (inlined or
+                   (right=nil)) then
+                  begin
+                     emit_reg(A_PUSH,S_L,R_ESI);
+                     new(r);
+                     reset_reference(r^);
+                     r^.base:=R_ESI;
+                     getexplicitregister32(R_EDI);
+                     emit_ref_reg(A_MOV,S_L,r,R_EDI);
+                     new(r);
+                     reset_reference(r^);
+                     r^.offset:=72;
+                     r^.base:=R_EDI;
+                     emit_ref(A_CALL,S_NO,r);
+                     ungetregister32(R_EDI);
+                  end;
+
               { push base pointer ?}
               { push base pointer ?}
               if (lexlevel>=normal_function_level) and assigned(pprocdef(procdefinition)^.parast) and
               if (lexlevel>=normal_function_level) and assigned(pprocdef(procdefinition)^.parast) and
                 ((pprocdef(procdefinition)^.parast^.symtablelevel)>normal_function_level) then
                 ((pprocdef(procdefinition)^.parast^.symtablelevel)>normal_function_level) then
@@ -895,9 +917,7 @@ implementation
                             r^.base:=R_ESI;
                             r^.base:=R_ESI;
                             { this is one point where we need vmt_offset (PM) }
                             { this is one point where we need vmt_offset (PM) }
                             r^.offset:= pprocdef(procdefinition)^._class^.vmt_offset;
                             r^.offset:= pprocdef(procdefinition)^._class^.vmt_offset;
-{$ifndef noAllocEdi}
                             getexplicitregister32(R_EDI);
                             getexplicitregister32(R_EDI);
-{$endif noAllocEdi}
                             emit_ref_reg(A_MOV,S_L,r,R_EDI);
                             emit_ref_reg(A_MOV,S_L,r,R_EDI);
                             new(r);
                             new(r);
                             reset_reference(r^);
                             reset_reference(r^);
@@ -983,9 +1003,7 @@ implementation
                       (right.location.reference.index=R_ESI) then
                       (right.location.reference.index=R_ESI) then
                      begin
                      begin
                         del_reference(right.location.reference);
                         del_reference(right.location.reference);
-{$ifndef noAllocEdi}
                         getexplicitregister32(R_EDI);
                         getexplicitregister32(R_EDI);
-{$endif noAllocEdi}
                         emit_ref_reg(A_MOV,S_L,
                         emit_ref_reg(A_MOV,S_L,
                           newreference(right.location.reference),R_EDI);
                           newreference(right.location.reference),R_EDI);
                         hregister:=R_EDI;
                         hregister:=R_EDI;
@@ -1046,13 +1064,9 @@ implementation
                 { better than an add on all processors }
                 { better than an add on all processors }
                 if pushedparasize=4 then
                 if pushedparasize=4 then
                   begin
                   begin
-{$ifndef noAllocEdi}
                     getexplicitregister32(R_EDI);
                     getexplicitregister32(R_EDI);
-{$endif noAllocEdi}
                     emit_reg(A_POP,S_L,R_EDI);
                     emit_reg(A_POP,S_L,R_EDI);
-{$ifndef noAllocEdi}
                     ungetregister32(R_EDI);
                     ungetregister32(R_EDI);
-{$endif noAllocEdi}
                   end
                   end
                 { the pentium has two pipes and pop reg is pairable }
                 { the pentium has two pipes and pop reg is pairable }
                 { but the registers must be different!        }
                 { but the registers must be different!        }
@@ -1061,20 +1075,12 @@ implementation
                   (aktoptprocessor=ClassP5) and
                   (aktoptprocessor=ClassP5) and
                   (procinfo^._class=nil) then
                   (procinfo^._class=nil) then
                     begin
                     begin
-{$ifndef noAllocEdi}
                        getexplicitregister32(R_EDI);
                        getexplicitregister32(R_EDI);
-{$endif noAllocEdi}
                        emit_reg(A_POP,S_L,R_EDI);
                        emit_reg(A_POP,S_L,R_EDI);
-{$ifndef noAllocEdi}
                        ungetregister32(R_EDI);
                        ungetregister32(R_EDI);
-{$endif noAllocEdi}
-{$ifndef noAllocEdi}
                        exprasmlist^.concat(new(pairegalloc,alloc(R_ESI)));
                        exprasmlist^.concat(new(pairegalloc,alloc(R_ESI)));
-{$endif noAllocEdi}
                        emit_reg(A_POP,S_L,R_ESI);
                        emit_reg(A_POP,S_L,R_ESI);
-{$ifndef noAllocEdi}
                        exprasmlist^.concat(new(pairegalloc,alloc(R_ESI)));
                        exprasmlist^.concat(new(pairegalloc,alloc(R_ESI)));
-{$endif noAllocEdi}
                     end
                     end
                 else if pushedparasize<>0 then
                 else if pushedparasize<>0 then
                   emit_const_reg(A_ADD,S_L,pushedparasize,R_ESP);
                   emit_const_reg(A_ADD,S_L,pushedparasize,R_ESP);
@@ -1102,6 +1108,31 @@ implementation
            begin
            begin
              emitjmp(C_Z,faillabel);
              emitjmp(C_Z,faillabel);
            end;
            end;
+
+         { call to AfterConstruction? }
+         if is_class(resulttype) and
+           (inlined or
+           (right=nil)) and
+           (procdefinition^.proctypeoption=potype_constructor) and
+           assigned(methodpointer) and
+           (methodpointer.nodetype<>typen) then
+           begin
+              emit_reg(A_PUSH,S_L,R_ESI);
+              new(r);
+              reset_reference(r^);
+              r^.base:=R_ESI;
+              getexplicitregister32(R_EDI);
+              emit_ref_reg(A_MOV,S_L,r,R_EDI);
+              new(r);
+              reset_reference(r^);
+              r^.offset:=68;
+              r^.base:=R_EDI;
+              emit_ref(A_CALL,S_NO,r);
+              ungetregister32(R_EDI);
+              exprasmlist^.concat(new(pairegalloc,alloc(R_EAX)));
+              emit_reg_reg(A_MOV,S_L,R_ESI,R_EAX);
+           end;
+
          { handle function results }
          { handle function results }
          { structured results are easy to handle.... }
          { structured results are easy to handle.... }
          { needed also when result_no_used !! }
          { needed also when result_no_used !! }
@@ -1556,7 +1587,10 @@ begin
 end.
 end.
 {
 {
   $Log$
   $Log$
-  Revision 1.5  2000-11-06 23:15:01  peter
+  Revision 1.6  2000-11-07 23:40:49  florian
+    + AfterConstruction and BeforeDestruction impemented
+
+  Revision 1.5  2000/11/06 23:15:01  peter
     * added copyvaluepara call again
     * added copyvaluepara call again
 
 
   Revision 1.4  2000/11/04 14:25:23  florian
   Revision 1.4  2000/11/04 14:25:23  florian