import.pas 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Peter Vreman
  4. This unit implements an uniform import object
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************}
  17. unit import;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cutils,cclasses,
  22. systems,
  23. aasmbase,
  24. symdef,symsym;
  25. type
  26. timported_item = class(TLinkedListItem)
  27. ordnr : word;
  28. name,
  29. func : pstring;
  30. lab : tasmlabel;
  31. is_var : boolean;
  32. constructor Create(const n,s : string;o : word);
  33. constructor Create_var(const n,s : string);
  34. destructor Destroy;override;
  35. end;
  36. timportlist = class(TLinkedListItem)
  37. dllname : pstring;
  38. imported_items : tlinkedlist;
  39. constructor Create(const n : string);
  40. destructor Destroy;Override;
  41. end;
  42. timportlib=class
  43. private
  44. notsupmsg : boolean;
  45. procedure NotSupported;
  46. public
  47. constructor Create;virtual;
  48. destructor Destroy;override;
  49. procedure preparelib(const s:string);virtual;
  50. procedure importproceduredef(aprocdef : tprocdef; const module:string;index:longint;const name:string);virtual;
  51. procedure importprocedure(const func,module:string;index:longint;const name:string);virtual;
  52. procedure importvariable(vs:tvarsym;const name,module:string);virtual;
  53. procedure generatelib;virtual;
  54. procedure generatesmartlib;virtual;
  55. end;
  56. TDLLScanner=class
  57. public
  58. f:file;
  59. impname:string;
  60. TheWord:array[0..1]of char;
  61. HeaderOffset:cardinal;
  62. loaded:integer;
  63. function isSuitableFileType(x:cardinal):longbool;virtual;abstract;
  64. function GetEdata(HeaderEntry:cardinal):longbool;virtual;abstract;
  65. function Scan(const binname:string):longbool;virtual;abstract;
  66. end;
  67. TImportLibClass=class of TImportLib;
  68. TDLLScannerClass=class of TDLLScanner;
  69. var
  70. CImportLib : array[tsystem] of TImportLibClass;
  71. CDLLScanner : array[tsystem] of TDLLScannerClass;
  72. ImportLib : TImportLib;
  73. procedure RegisterImport(t:tsystem;c:TImportLibClass);
  74. procedure RegisterDLLScanner(t:tsystem;c:TDLLScannerClass);
  75. procedure InitImport;
  76. procedure DoneImport;
  77. implementation
  78. uses
  79. verbose,globals;
  80. {****************************************************************************
  81. Timported_item
  82. ****************************************************************************}
  83. constructor timported_item.Create(const n,s : string;o : word);
  84. begin
  85. inherited Create;
  86. func:=stringdup(n);
  87. name:=stringdup(s);
  88. ordnr:=o;
  89. lab:=nil;
  90. is_var:=false;
  91. end;
  92. constructor timported_item.create_var(const n,s : string);
  93. begin
  94. inherited Create;
  95. func:=stringdup(n);
  96. name:=stringdup(s);
  97. ordnr:=0;
  98. lab:=nil;
  99. is_var:=true;
  100. end;
  101. destructor timported_item.destroy;
  102. begin
  103. stringdispose(name);
  104. stringdispose(func);
  105. inherited destroy;
  106. end;
  107. {****************************************************************************
  108. TImportlist
  109. ****************************************************************************}
  110. constructor timportlist.Create(const n : string);
  111. begin
  112. inherited Create;
  113. dllname:=stringdup(n);
  114. imported_items:=Tlinkedlist.Create;
  115. end;
  116. destructor timportlist.destroy;
  117. begin
  118. imported_items.free;
  119. stringdispose(dllname);
  120. end;
  121. {****************************************************************************
  122. TImportLib
  123. ****************************************************************************}
  124. constructor timportlib.Create;
  125. begin
  126. notsupmsg:=false;
  127. end;
  128. destructor timportlib.Destroy;
  129. begin
  130. end;
  131. procedure timportlib.NotSupported;
  132. begin
  133. { show the message only once }
  134. if not notsupmsg then
  135. begin
  136. Message(exec_e_dll_not_supported);
  137. notsupmsg:=true;
  138. end;
  139. end;
  140. procedure timportlib.preparelib(const s:string);
  141. begin
  142. NotSupported;
  143. end;
  144. procedure timportlib.importproceduredef(aprocdef : tprocdef; const module:string;index:longint;const name:string);
  145. begin
  146. importprocedure(aprocdef.mangledname, module, index, name);
  147. end;
  148. procedure timportlib.importprocedure(const func,module:string;index:longint;const name:string);
  149. begin
  150. NotSupported;
  151. end;
  152. procedure timportlib.importvariable(vs:tvarsym;const name,module:string);
  153. begin
  154. NotSupported;
  155. end;
  156. procedure timportlib.generatelib;
  157. begin
  158. NotSupported;
  159. end;
  160. procedure timportlib.generatesmartlib;
  161. begin
  162. NotSupported;
  163. end;
  164. {*****************************************************************************
  165. Init/Done
  166. *****************************************************************************}
  167. procedure RegisterImport(t:tsystem;c:TImportLibClass);
  168. begin
  169. CImportLib[t]:=c;
  170. end;
  171. procedure RegisterDLLScanner(t:tsystem;c:TDLLScannerClass);
  172. begin
  173. CDLLScanner[t]:=c;
  174. end;
  175. procedure InitImport;
  176. begin
  177. if assigned(CImportLib[target_info.system]) then
  178. importlib:=CImportLib[target_info.system].Create
  179. else
  180. importlib:=TImportLib.Create;
  181. end;
  182. procedure DoneImport;
  183. begin
  184. if assigned(importlib) then
  185. importlib.free;
  186. end;
  187. end.
  188. {
  189. $Log$
  190. Revision 1.21 2002-11-15 01:58:48 peter
  191. * merged changes from 1.0.7 up to 04-11
  192. - -V option for generating bug report tracing
  193. - more tracing for option parsing
  194. - errors for cdecl and high()
  195. - win32 import stabs
  196. - win32 records<=8 are returned in eax:edx (turned off by default)
  197. - heaptrc update
  198. - more info for temp management in .s file with EXTDEBUG
  199. Revision 1.20 2002/09/09 17:34:14 peter
  200. * tdicationary.replace added to replace and item in a dictionary. This
  201. is only allowed for the same name
  202. * varsyms are inserted in symtable before the types are parsed. This
  203. fixes the long standing "var longint : longint" bug
  204. - consume_idlist and idstringlist removed. The loops are inserted
  205. at the callers place and uses the symtable for duplicate id checking
  206. Revision 1.19 2002/07/26 21:15:38 florian
  207. * rewrote the system handling
  208. Revision 1.18 2002/07/01 18:46:22 peter
  209. * internal linker
  210. * reorganized aasm layer
  211. Revision 1.17 2002/05/18 13:34:08 peter
  212. * readded missing revisions
  213. Revision 1.16 2002/05/16 19:46:37 carl
  214. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  215. + try to fix temp allocation (still in ifdef)
  216. + generic constructor calls
  217. + start of tassembler / tmodulebase class cleanup
  218. }