import.pas 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. {
  2. Copyright (c) 1998-2002 by Peter Vreman
  3. This unit implements an uniform import object
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************}
  16. unit import;
  17. {$i fpcdefs.inc}
  18. interface
  19. uses
  20. cutils,cclasses,
  21. systems,
  22. aasmbase,
  23. symdef,symsym;
  24. type
  25. timported_item = class(TLinkedListItem)
  26. ordnr : longint;
  27. name,
  28. func : pstring;
  29. lab : tasmlabel;
  30. is_var : boolean;
  31. constructor Create(const n,s : string;o : longint);
  32. constructor Create_var(const n,s : string);
  33. destructor Destroy;override;
  34. end;
  35. timportlist = class(TLinkedListItem)
  36. dllname : pstring;
  37. imported_items : tlinkedlist;
  38. constructor Create(const n : string);
  39. destructor Destroy;Override;
  40. end;
  41. timportlib=class
  42. private
  43. notsupmsg : boolean;
  44. procedure NotSupported;
  45. public
  46. constructor Create;virtual;
  47. destructor Destroy;override;
  48. procedure preparelib(const s:string);virtual;
  49. procedure importprocedure(aprocdef:tprocdef;const module:string;index:longint;const name:string);virtual;
  50. procedure importvariable(vs:tglobalvarsym;const name,module:string);virtual;
  51. procedure generatelib;virtual;
  52. procedure generatesmartlib;virtual;
  53. end;
  54. TDLLScanner=class
  55. function Scan(const binname:string):boolean;virtual;abstract;
  56. end;
  57. TImportLibClass=class of TImportLib;
  58. TDLLScannerClass=class of TDLLScanner;
  59. var
  60. CImportLib : array[tsystem] of TImportLibClass;
  61. CDLLScanner : array[tsystem] of TDLLScannerClass;
  62. ImportLib : TImportLib;
  63. procedure RegisterImport(t:tsystem;c:TImportLibClass);
  64. procedure RegisterDLLScanner(t:tsystem;c:TDLLScannerClass);
  65. procedure InitImport;
  66. procedure DoneImport;
  67. implementation
  68. uses
  69. verbose,globals;
  70. {****************************************************************************
  71. Timported_item
  72. ****************************************************************************}
  73. constructor timported_item.Create(const n,s : string;o : longint);
  74. begin
  75. inherited Create;
  76. func:=stringdup(n);
  77. name:=stringdup(s);
  78. ordnr:=o;
  79. lab:=nil;
  80. is_var:=false;
  81. end;
  82. constructor timported_item.create_var(const n,s : string);
  83. begin
  84. inherited Create;
  85. func:=stringdup(n);
  86. name:=stringdup(s);
  87. ordnr:=0;
  88. lab:=nil;
  89. is_var:=true;
  90. end;
  91. destructor timported_item.destroy;
  92. begin
  93. stringdispose(name);
  94. stringdispose(func);
  95. inherited destroy;
  96. end;
  97. {****************************************************************************
  98. TImportlist
  99. ****************************************************************************}
  100. constructor timportlist.Create(const n : string);
  101. begin
  102. inherited Create;
  103. dllname:=stringdup(n);
  104. imported_items:=Tlinkedlist.Create;
  105. end;
  106. destructor timportlist.destroy;
  107. begin
  108. imported_items.free;
  109. stringdispose(dllname);
  110. end;
  111. {****************************************************************************
  112. TImportLib
  113. ****************************************************************************}
  114. constructor timportlib.Create;
  115. begin
  116. notsupmsg:=false;
  117. end;
  118. destructor timportlib.Destroy;
  119. begin
  120. end;
  121. procedure timportlib.NotSupported;
  122. begin
  123. { show the message only once }
  124. if not notsupmsg then
  125. begin
  126. Message(exec_e_dll_not_supported);
  127. notsupmsg:=true;
  128. end;
  129. end;
  130. procedure timportlib.preparelib(const s:string);
  131. begin
  132. NotSupported;
  133. end;
  134. procedure timportlib.importprocedure(aprocdef:tprocdef;const module:string;index:longint;const name:string);
  135. begin
  136. NotSupported;
  137. end;
  138. procedure timportlib.importvariable(vs:tglobalvarsym;const name,module:string);
  139. begin
  140. NotSupported;
  141. end;
  142. procedure timportlib.generatelib;
  143. begin
  144. NotSupported;
  145. end;
  146. procedure timportlib.generatesmartlib;
  147. begin
  148. NotSupported;
  149. end;
  150. {*****************************************************************************
  151. Init/Done
  152. *****************************************************************************}
  153. procedure RegisterImport(t:tsystem;c:TImportLibClass);
  154. begin
  155. CImportLib[t]:=c;
  156. end;
  157. procedure RegisterDLLScanner(t:tsystem;c:TDLLScannerClass);
  158. begin
  159. CDLLScanner[t]:=c;
  160. end;
  161. procedure InitImport;
  162. begin
  163. if assigned(CImportLib[target_info.system]) then
  164. importlib:=CImportLib[target_info.system].Create
  165. else
  166. importlib:=TImportLib.Create;
  167. end;
  168. procedure DoneImport;
  169. begin
  170. if assigned(importlib) then
  171. importlib.free;
  172. end;
  173. end.