import.pas 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. end;
  53. TDLLScanner=class
  54. function Scan(const binname:string):boolean;virtual;abstract;
  55. end;
  56. TImportLibClass=class of TImportLib;
  57. TDLLScannerClass=class of TDLLScanner;
  58. var
  59. CImportLib : array[tsystem] of TImportLibClass;
  60. CDLLScanner : array[tsystem] of TDLLScannerClass;
  61. ImportLib : TImportLib;
  62. procedure RegisterImport(t:tsystem;c:TImportLibClass);
  63. procedure RegisterDLLScanner(t:tsystem;c:TDLLScannerClass);
  64. procedure InitImport;
  65. procedure DoneImport;
  66. implementation
  67. uses
  68. verbose,globals;
  69. {****************************************************************************
  70. Timported_item
  71. ****************************************************************************}
  72. constructor timported_item.Create(const n,s : string;o : longint);
  73. begin
  74. inherited Create;
  75. func:=stringdup(n);
  76. name:=stringdup(s);
  77. ordnr:=o;
  78. lab:=nil;
  79. is_var:=false;
  80. end;
  81. constructor timported_item.create_var(const n,s : string);
  82. begin
  83. inherited Create;
  84. func:=stringdup(n);
  85. name:=stringdup(s);
  86. ordnr:=0;
  87. lab:=nil;
  88. is_var:=true;
  89. end;
  90. destructor timported_item.destroy;
  91. begin
  92. stringdispose(name);
  93. stringdispose(func);
  94. inherited destroy;
  95. end;
  96. {****************************************************************************
  97. TImportlist
  98. ****************************************************************************}
  99. constructor timportlist.Create(const n : string);
  100. begin
  101. inherited Create;
  102. dllname:=stringdup(n);
  103. imported_items:=Tlinkedlist.Create;
  104. end;
  105. destructor timportlist.destroy;
  106. begin
  107. imported_items.free;
  108. stringdispose(dllname);
  109. end;
  110. {****************************************************************************
  111. TImportLib
  112. ****************************************************************************}
  113. constructor timportlib.Create;
  114. begin
  115. notsupmsg:=false;
  116. end;
  117. destructor timportlib.Destroy;
  118. begin
  119. end;
  120. procedure timportlib.NotSupported;
  121. begin
  122. { show the message only once }
  123. if not notsupmsg then
  124. begin
  125. Message(exec_e_dll_not_supported);
  126. notsupmsg:=true;
  127. end;
  128. end;
  129. procedure timportlib.preparelib(const s:string);
  130. begin
  131. NotSupported;
  132. end;
  133. procedure timportlib.importprocedure(aprocdef:tprocdef;const module:string;index:longint;const name:string);
  134. begin
  135. NotSupported;
  136. end;
  137. procedure timportlib.importvariable(vs:tglobalvarsym;const name,module:string);
  138. begin
  139. NotSupported;
  140. end;
  141. procedure timportlib.generatelib;
  142. begin
  143. NotSupported;
  144. end;
  145. {*****************************************************************************
  146. Init/Done
  147. *****************************************************************************}
  148. procedure RegisterImport(t:tsystem;c:TImportLibClass);
  149. begin
  150. CImportLib[t]:=c;
  151. end;
  152. procedure RegisterDLLScanner(t:tsystem;c:TDLLScannerClass);
  153. begin
  154. CDLLScanner[t]:=c;
  155. end;
  156. procedure InitImport;
  157. begin
  158. if assigned(CImportLib[target_info.system]) then
  159. importlib:=CImportLib[target_info.system].Create
  160. else
  161. importlib:=TImportLib.Create;
  162. end;
  163. procedure DoneImport;
  164. begin
  165. if assigned(importlib) then
  166. importlib.free;
  167. end;
  168. end.