Browse Source

* DLL index used for win32 target with DEF file
+ DLL initialization/finalization support

pierre 26 years ago
parent
commit
8025581bfd
3 changed files with 82 additions and 34 deletions
  1. 13 3
      compiler/pexports.pas
  2. 30 1
      compiler/pmodules.pas
  3. 39 30
      compiler/pstatmnt.pas

+ 13 - 3
compiler/pexports.pas

@@ -74,7 +74,10 @@ unit pexports;
                          begin
                           ProcName:=hp^.sym^.name;
                           InternalProcName:=hp^.sym^.mangledname;
-                          delete(InternalProcName,1,1);
+                          { This is wrong if the first is not
+                            an underline }
+                          if InternalProcName[1]='_' then
+                            delete(InternalProcName,1,1);
                           if length(InternalProcName)<2 then
                            Message(parser_e_procname_to_short_for_export);
                           DefString:=ProcName+'='+InternalProcName;
@@ -85,7 +88,10 @@ unit pexports;
                              hp^.options:=hp^.options or eo_index;
                              val(pattern,hp^.index,code);
                              consume(_INTCONST);
-                             DefString:=ProcName+'='+InternalProcName; {Index ignored!}
+                             if target_os.id=os_i386_win32 then
+                               DefString:=ProcName+' @'+tostr(hp^.index)+'='+InternalProcName
+                             else
+                               DefString:=ProcName+'='+InternalProcName; {Index ignored!}
                           end;
                         if (idtoken=_NAME) then
                           begin
@@ -130,7 +136,11 @@ end.
 
 {
   $Log$
-  Revision 1.13  1999-10-26 12:30:44  peter
+  Revision 1.14  1999-11-20 01:19:10  pierre
+    * DLL index used for win32 target with DEF file
+    + DLL initialization/finalization support
+
+  Revision 1.13  1999/10/26 12:30:44  peter
     * const parameter is now checked
     * better and generic check if a node can be used for assigning
     * export fixes

+ 30 - 1
compiler/pmodules.pas

@@ -210,6 +210,14 @@ unit pmodules;
             end;
            hp:=Pused_unit(hp^.next);
          end;
+        if current_module^.islibrary then
+          if (current_module^.flags and uf_finalize)<>0 then
+            begin
+              { INIT code is done by PASCALMAIN calling }
+              unitinits.concat(new(pai_const,init_32bit(0)));
+              unitinits.concat(new(pai_const_symbol,initname('FINALIZE$$'+current_module^.modulename^)));
+              inc(count);
+            end;
         { TableCount,InitCount }
         unitinits.insert(new(pai_const,init_32bit(0)));
         unitinits.insert(new(pai_const,init_32bit(count)));
@@ -1444,6 +1452,23 @@ unit pmodules;
 
          codegen_doneprocedure;
 
+         { finalize? }
+         if token=_FINALIZATION then
+           begin
+              { set module options }
+              current_module^.flags:=current_module^.flags or uf_finalize;
+
+              { Compile the finalize }
+              codegen_newprocedure;
+              gen_main_procsym(current_module^.modulename^+'_finalize',potype_unitfinalize,st);
+              names.init;
+              names.insert('FINALIZE$$'+current_module^.modulename^);
+              names.insert(target_os.cprefix+current_module^.modulename^+'_finalize');
+              compile_proc_body(names,true,false);
+              names.done;
+              codegen_doneprocedure;
+           end;
+
          { consume the last point }
          consume(_POINT);
 
@@ -1526,7 +1551,11 @@ unit pmodules;
 end.
 {
   $Log$
-  Revision 1.168  1999-11-18 23:35:40  pierre
+  Revision 1.169  1999-11-20 01:19:10  pierre
+    * DLL index used for win32 target with DEF file
+    + DLL initialization/finalization support
+
+  Revision 1.168  1999/11/18 23:35:40  pierre
    * avoid double warnings
 
   Revision 1.167  1999/11/18 15:34:47  pierre

+ 39 - 30
compiler/pstatmnt.pas

@@ -1220,35 +1220,40 @@ unit pstatmnt;
            end;
 
          {Unit initialization?.}
-         if (lexlevel=unit_init_level) and (current_module^.is_unit) then
-           if (token=_END) then
-             begin
-                consume(_END);
-                block:=nil;
-             end
-           else
-             begin
-                if token=_INITIALIZATION then
-                  begin
-                     current_module^.flags:=current_module^.flags or uf_init;
-                     block:=statement_block(_INITIALIZATION);
-                  end
-                else if (token=_FINALIZATION) then
-                  begin
-                     if (current_module^.flags and uf_finalize)<>0 then
-                       block:=statement_block(_FINALIZATION)
-                     else
-                       begin
-                          block:=nil;
-                          exit;
-                       end;
-                  end
-                else
-                  begin
-                     current_module^.flags:=current_module^.flags or uf_init;
-                     block:=statement_block(_BEGIN);
-                  end;
-             end
+         if (lexlevel=unit_init_level) and (current_module^.is_unit)
+            or islibrary then
+           begin
+             if (token=_END) then
+                begin
+                   consume(_END);
+                   block:=nil;
+                end
+              else
+                begin
+                   if token=_INITIALIZATION then
+                     begin
+                        current_module^.flags:=current_module^.flags or uf_init;
+                        block:=statement_block(_INITIALIZATION);
+                     end
+                   else if (token=_FINALIZATION) then
+                     begin
+                        if (current_module^.flags and uf_finalize)<>0 then
+                          block:=statement_block(_FINALIZATION)
+                        else
+                          begin
+                          { can we allow no INITIALIZATION for DLL ??
+                            I think it should work PM }
+                             block:=nil;
+                             exit;
+                          end;
+                     end
+                   else
+                     begin
+                        current_module^.flags:=current_module^.flags or uf_init;
+                        block:=statement_block(_BEGIN);
+                     end;
+                end;
+            end
          else
             block:=statement_block(_BEGIN);
       end;
@@ -1318,7 +1323,11 @@ unit pstatmnt;
 end.
 {
   $Log$
-  Revision 1.111  1999-11-18 15:34:48  pierre
+  Revision 1.112  1999-11-20 01:19:10  pierre
+    * DLL index used for win32 target with DEF file
+    + DLL initialization/finalization support
+
+  Revision 1.111  1999/11/18 15:34:48  pierre
     * Notes/Hints for local syms changed to
       Set_varstate function