import.pas 5.4 KB

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