fmodule.pas 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements the first loading and searching of the modules
  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. }
  17. unit fmodule;
  18. {$i fpcdefs.inc}
  19. {$ifdef go32v2}
  20. {$define shortasmprefix}
  21. {$endif}
  22. {$ifdef watcom}
  23. {$define shortasmprefix}
  24. {$endif}
  25. {$ifdef atari}
  26. {$define shortasmprefix}
  27. {$endif}
  28. {$ifdef OS2}
  29. { Allthough OS/2 supports long filenames I play it safe and
  30. use 8.3 filenames, because this allows the compiler to run
  31. on a FAT partition. (DM) }
  32. {$define shortasmprefix}
  33. {$endif}
  34. interface
  35. uses
  36. cutils,cclasses,cfileutl,
  37. globtype,finput,ogbase,fpkg,
  38. symbase,symsym,
  39. wpobase,
  40. aasmbase,aasmdata;
  41. const
  42. UNSPECIFIED_LIBRARY_NAME = '<none>';
  43. type
  44. trecompile_reason = (rr_unknown,
  45. rr_noppu,rr_sourcenewer,rr_build,rr_crcchanged
  46. );
  47. { unit options }
  48. tmoduleoption = (mo_none,
  49. mo_hint_deprecated,
  50. mo_hint_platform,
  51. mo_hint_library,
  52. mo_hint_unimplemented,
  53. mo_hint_experimental,
  54. mo_has_deprecated_msg
  55. );
  56. tmoduleoptions = set of tmoduleoption;
  57. tlinkcontaineritem=class(tlinkedlistitem)
  58. public
  59. data : TPathStr;
  60. needlink : cardinal;
  61. constructor Create(const s:TPathStr;m:cardinal);
  62. end;
  63. tlinkcontainer=class(tlinkedlist)
  64. procedure add(const s : TPathStr;m:cardinal);
  65. function get(var m:cardinal) : TPathStr;
  66. function getusemask(mask:cardinal) : TPathStr;
  67. function find(const s:TPathStr):boolean;
  68. end;
  69. tmodule = class;
  70. tused_unit = class;
  71. tunitmaprec = record
  72. u : tmodule;
  73. { number of references }
  74. refs : longint;
  75. { index in the derefmap }
  76. derefidx : longint;
  77. end;
  78. punitmap = ^tunitmaprec;
  79. tderefmaprec = record
  80. u : tmodule;
  81. { modulename, used during ppu load }
  82. modulename : pshortstring;
  83. end;
  84. pderefmap = ^tderefmaprec;
  85. { tmodule }
  86. tmodule = class(tmodulebase)
  87. private
  88. FImportLibraryList : TFPHashObjectList;
  89. public
  90. do_reload, { force reloading of the unit }
  91. do_compile, { need to compile the sources }
  92. sources_avail, { if all sources are reachable }
  93. interface_compiled, { if the interface section has been parsed/compiled/loaded }
  94. is_dbginfo_written,
  95. is_unit,
  96. in_interface, { processing the implementation part? }
  97. { allow global settings }
  98. in_global : boolean;
  99. { Whether a mode switch is still allowed at this point in the parsing.}
  100. mode_switch_allowed,
  101. { generate pic helper which loads eip in ecx (for leave procedures) }
  102. requires_ecx_pic_helper,
  103. { generate pic helper which loads eip in ebx (for non leave procedures) }
  104. requires_ebx_pic_helper : boolean;
  105. interface_only: boolean; { interface-only macpas unit; flag does not need saving/restoring to ppu }
  106. mainfilepos : tfileposinfo;
  107. recompile_reason : trecompile_reason; { the reason why the unit should be recompiled }
  108. crc,
  109. interface_crc,
  110. indirect_crc : cardinal;
  111. headerflags : cardinal; { the PPU header flags }
  112. longversion : cardinal; { longer version than what fits in the ppu header }
  113. moduleflags : tmoduleflags; { ppu flags that do not need to be known by just reading the ppu header }
  114. islibrary : boolean; { if it is a library (win32 dll) }
  115. IsPackage : boolean;
  116. change_endian : boolean; { if the unit is loaded on a system with a different endianess than it was compiled on }
  117. moduleid : longint;
  118. unitmap : punitmap; { mapping of all used units }
  119. unitmapsize : longint; { number of units in the map }
  120. derefmap : pderefmap; { mapping of all units needed for deref }
  121. derefmapcnt : longint; { number of units in the map }
  122. derefmapsize : longint; { number of units in the map }
  123. derefdataintflen : longint;
  124. derefdata : tdynamicarray;
  125. checkforwarddefs,
  126. deflist,
  127. symlist : TFPObjectList;
  128. ptrdefs : THashSet; { list of pointerdefs created in this module so we can reuse them (not saved/restored) }
  129. arraydefs : THashSet; { list of single-element-arraydefs created in this module so we can reuse them (not saved/restored) }
  130. procaddrdefs : THashSet; { list of procvardefs created when getting the address of a procdef (not saved/restored) }
  131. {$ifdef llvm}
  132. llvmdefs : THashSet; { defs added for llvm-specific reasons (not saved/restored) }
  133. llvmusedsyms : TFPObjectList; { a list of asmsymbols and their defs that need to be added to llvm.used (so they're not removed by llvm optimisation passes nor by the linker) }
  134. llvmcompilerusedsyms : TFPObjectList; { a list of asmsymbols and their defs that need to be added to llvm.compiler.used (so they're not removed by llvm optimisation passes) }
  135. llvminitprocs,
  136. llvmfiniprocs : TFPList;
  137. llvmmetadatastrings: TFPHashList; { metadata strings (mapping string -> superregister) }
  138. {$endif llvm}
  139. ansistrdef : tobject; { an ansistring def redefined for the current module }
  140. wpoinfo : tunitwpoinfobase; { whole program optimization-related information that is generated during the current run for this unit }
  141. globalsymtable, { pointer to the global symtable of this unit }
  142. localsymtable : TSymtable;{ pointer to the local symtable of this unit }
  143. globalmacrosymtable, { pointer to the global macro symtable of this unit }
  144. localmacrosymtable : TSymtable;{ pointer to the local macro symtable of this unit }
  145. scanner : TObject; { scanner object used }
  146. procinfo : TObject; { current procedure being compiled }
  147. asmdata : TObject; { Assembler data }
  148. asmprefix : pshortstring; { prefix for the smartlink asmfiles }
  149. publicasmsyms : TFPHashObjectList; { contains the assembler symbols which need to be exported from a package }
  150. externasmsyms : TFPHashObjectList; { contains the assembler symbols which are imported from another unit }
  151. unitimportsyms : tfpobjectlist; { list of symbols that are imported from other units }
  152. debuginfo : TObject;
  153. loaded_from : tmodule;
  154. _exports : tlinkedlist;
  155. dllscannerinputlist : TFPHashList;
  156. resourcefiles,
  157. linkorderedsymbols : TCmdStrList;
  158. linkunitofiles,
  159. linkunitstaticlibs,
  160. linkunitsharedlibs,
  161. linkotherofiles, { objects,libs loaded from the source }
  162. linkothersharedlibs, { using $L or $LINKLIB or import lib (for linux) }
  163. linkotherstaticlibs,
  164. linkotherframeworks : tlinkcontainer;
  165. mainname : pshortstring; { alternate name for "main" procedure }
  166. package : tpackage;
  167. used_units : tlinkedlist;
  168. dependent_units : tlinkedlist;
  169. localunitsearchpath, { local searchpaths }
  170. localobjectsearchpath,
  171. localincludesearchpath,
  172. locallibrarysearchpath,
  173. localframeworksearchpath : TSearchPathList;
  174. moduleoptions: tmoduleoptions;
  175. deprecatedmsg: pshortstring;
  176. { contains a list of types that are extended by helper types; the key is
  177. the full name of the type and the data is a TFPObjectList of
  178. tobjectdef instances (the helper defs) }
  179. extendeddefs: TFPHashObjectList;
  180. { contains a list of the current topmost non-generic symbol for a
  181. typename of which at least one generic exists; the key is the
  182. non-generic typename and the data is a TFPObjectList of tgenericdummyentry
  183. instances whereby the last one is the current top most one }
  184. genericdummysyms: TFPHashObjectList;
  185. { contains a list of specializations for which the method bodies need
  186. to be generated }
  187. pendingspecializations : TFPHashObjectList;
  188. { list of attributes that are used and thus need their construction
  189. functions generated }
  190. used_rtti_attrs: tfpobjectlist;
  191. { this contains a list of units that needs to be waited for until the
  192. unit can be finished (code generated, etc.); this is needed to handle
  193. specializations in circular unit usages correctly }
  194. waitingforunit: tfpobjectlist;
  195. { this contains a list of all units that are waiting for this unit to be
  196. finished }
  197. waitingunits: tfpobjectlist;
  198. finishstate: pointer;
  199. globalstate: pointer;
  200. namespace: pshortstring; { for JVM target: corresponds to Java package name }
  201. { for targets that initialise typed constants via explicit assignments
  202. instead of by generating an initialised data section (holds typed
  203. constant assignments at the module level; does not have to be saved
  204. into the ppu file, because translated into code during compilation)
  205. -- actual type: tnode (but fmodule should not depend on node) }
  206. tcinitcode : tobject;
  207. {create creates a new module which name is stored in 's'. LoadedFrom
  208. points to the module calling it. It is nil for the first compiled
  209. module. This allow inheritence of all path lists. MUST pay attention
  210. to that when creating link.res!!!!(mazen)}
  211. constructor create(LoadedFrom:TModule;const amodulename: string; const afilename:TPathStr;_is_unit:boolean);
  212. destructor destroy;override;
  213. procedure reset;virtual;
  214. procedure adddependency(callermodule:tmodule);
  215. procedure flagdependent(callermodule:tmodule);
  216. procedure addimportedsym(sym:TSymEntry);
  217. function addusedunit(hp:tmodule;inuses:boolean;usym:tunitsym):tused_unit;
  218. procedure updatemaps;
  219. function derefidx_unit(id:longint):longint;
  220. function resolve_unit(id:longint):tmodule;
  221. procedure allunitsused;
  222. procedure end_of_parsing;virtual;
  223. procedure setmodulename(const s:string);
  224. procedure AddExternalImport(const libname,symname,symmangledname:string;OrdNr: longint;isvar:boolean;ImportByOrdinalOnly:boolean);
  225. procedure add_public_asmsym(sym:TAsmSymbol);
  226. procedure add_public_asmsym(const name:TSymStr;bind:TAsmsymbind;typ:Tasmsymtype);
  227. procedure add_extern_asmsym(sym:TAsmSymbol);
  228. procedure add_extern_asmsym(const name:TSymStr;bind:TAsmsymbind;typ:Tasmsymtype);
  229. property ImportLibraryList : TFPHashObjectList read FImportLibraryList;
  230. end;
  231. tused_unit = class(tlinkedlistitem)
  232. checksum,
  233. interface_checksum,
  234. indirect_checksum: cardinal;
  235. in_uses,
  236. in_interface : boolean;
  237. u : tmodule;
  238. unitsym : tunitsym;
  239. constructor create(_u : tmodule;intface,inuses:boolean;usym:tunitsym);
  240. procedure check_hints;
  241. end;
  242. tdependent_unit = class(tlinkedlistitem)
  243. u : tmodule;
  244. constructor create(_u : tmodule);
  245. end;
  246. var
  247. main_module : tmodule; { Main module of the program }
  248. current_module : tmodule; { Current module which is compiled or loaded }
  249. compiled_module : tmodule; { Current module which is compiled }
  250. usedunits : tlinkedlist; { Used units for this program }
  251. loaded_units : tlinkedlist; { All loaded units }
  252. unloaded_units : tlinkedlist; { Units removed from loaded_units, to be freed }
  253. SmartLinkOFiles : TCmdStrList; { List of .o files which are generated,
  254. used to delete them after linking }
  255. procedure set_current_module(p:tmodule);
  256. function get_module(moduleindex : longint) : tmodule;
  257. function get_source_file(moduleindex,fileindex : longint) : tinputfile;
  258. procedure addloadedunit(hp:tmodule);
  259. function find_module_from_symtable(st:tsymtable):tmodule;
  260. implementation
  261. uses
  262. SysUtils,globals,
  263. verbose,systems,
  264. scanner,ppu,dbgbase,
  265. procinfo,symdef,symtype;
  266. {$ifdef MEMDEBUG}
  267. var
  268. memsymtable : TMemDebug;
  269. {$endif}
  270. {*****************************************************************************
  271. Global Functions
  272. *****************************************************************************}
  273. function find_module_from_symtable(st:tsymtable):tmodule;
  274. var
  275. hp : tmodule;
  276. begin
  277. result:=nil;
  278. hp:=tmodule(loaded_units.first);
  279. while assigned(hp) do
  280. begin
  281. if (hp.moduleid=st.moduleid) then
  282. begin
  283. result:=hp;
  284. exit;
  285. end;
  286. hp:=tmodule(hp.next);
  287. end;
  288. end;
  289. procedure set_current_module(p:tmodule);
  290. begin
  291. { save the state of the scanner }
  292. if assigned(current_scanner) then
  293. current_scanner.tempcloseinputfile;
  294. { set new module }
  295. current_module:=p;
  296. { restore previous module settings }
  297. Fillchar(current_filepos,sizeof(current_filepos),0);
  298. if assigned(current_module) then
  299. begin
  300. current_asmdata:=tasmdata(current_module.asmdata);
  301. current_debuginfo:=tdebuginfo(current_module.debuginfo);
  302. { restore scanner and file positions }
  303. current_scanner:=tscannerfile(current_module.scanner);
  304. if assigned(current_scanner) then
  305. begin
  306. current_scanner.tempopeninputfile;
  307. current_scanner.gettokenpos;
  308. parser_current_file:=current_scanner.inputfile.name;
  309. end
  310. else
  311. begin
  312. current_filepos.moduleindex:=current_module.unit_index;
  313. parser_current_file:='';
  314. end;
  315. end
  316. else
  317. begin
  318. current_asmdata:=nil;
  319. current_scanner:=nil;
  320. current_debuginfo:=nil;
  321. end;
  322. end;
  323. function get_module(moduleindex : longint) : tmodule;
  324. var
  325. hp : tmodule;
  326. begin
  327. result:=nil;
  328. if moduleindex=0 then
  329. exit;
  330. result:=current_module;
  331. if not(assigned(loaded_units)) then
  332. exit;
  333. hp:=tmodule(loaded_units.first);
  334. while assigned(hp) and (hp.unit_index<>moduleindex) do
  335. hp:=tmodule(hp.next);
  336. result:=hp;
  337. end;
  338. function get_source_file(moduleindex,fileindex : longint) : tinputfile;
  339. var
  340. hp : tmodule;
  341. begin
  342. hp:=get_module(moduleindex);
  343. if assigned(hp) then
  344. get_source_file:=hp.sourcefiles.get_file(fileindex)
  345. else
  346. get_source_file:=nil;
  347. end;
  348. procedure addloadedunit(hp:tmodule);
  349. begin
  350. hp.moduleid:=loaded_units.count;
  351. loaded_units.concat(hp);
  352. end;
  353. {****************************************************************************
  354. TLinkContainerItem
  355. ****************************************************************************}
  356. constructor TLinkContainerItem.Create(const s:TPathStr;m:cardinal);
  357. begin
  358. inherited Create;
  359. data:=s;
  360. needlink:=m;
  361. end;
  362. {****************************************************************************
  363. TLinkContainer
  364. ****************************************************************************}
  365. procedure TLinkContainer.add(const s : TPathStr;m:cardinal);
  366. begin
  367. inherited concat(TLinkContainerItem.Create(s,m));
  368. end;
  369. function TLinkContainer.get(var m:cardinal) : TPathStr;
  370. var
  371. p : tlinkcontaineritem;
  372. begin
  373. p:=tlinkcontaineritem(inherited getfirst);
  374. if p=nil then
  375. begin
  376. get:='';
  377. m:=0;
  378. end
  379. else
  380. begin
  381. get:=p.data;
  382. m:=p.needlink;
  383. p.free;
  384. end;
  385. end;
  386. function TLinkContainer.getusemask(mask:cardinal) : TPathStr;
  387. var
  388. p : tlinkcontaineritem;
  389. found : boolean;
  390. begin
  391. found:=false;
  392. repeat
  393. p:=tlinkcontaineritem(inherited getfirst);
  394. if p=nil then
  395. begin
  396. getusemask:='';
  397. exit;
  398. end;
  399. getusemask:=p.data;
  400. found:=(p.needlink and mask)<>0;
  401. p.free;
  402. until found;
  403. end;
  404. function TLinkContainer.find(const s:TPathStr):boolean;
  405. var
  406. newnode : tlinkcontaineritem;
  407. begin
  408. find:=false;
  409. newnode:=tlinkcontaineritem(First);
  410. while assigned(newnode) do
  411. begin
  412. if newnode.data=s then
  413. begin
  414. find:=true;
  415. exit;
  416. end;
  417. newnode:=tlinkcontaineritem(newnode.next);
  418. end;
  419. end;
  420. {****************************************************************************
  421. TUSED_UNIT
  422. ****************************************************************************}
  423. constructor tused_unit.create(_u : tmodule;intface,inuses:boolean;usym:tunitsym);
  424. begin
  425. u:=_u;
  426. in_interface:=intface;
  427. in_uses:=inuses;
  428. unitsym:=usym;
  429. if _u.state=ms_compiled then
  430. begin
  431. checksum:=u.crc;
  432. interface_checksum:=u.interface_crc;
  433. indirect_checksum:=u.indirect_crc;
  434. end
  435. else
  436. begin
  437. checksum:=0;
  438. interface_checksum:=0;
  439. indirect_checksum:=0;
  440. end;
  441. end;
  442. procedure tused_unit.check_hints;
  443. var
  444. uname: pshortstring;
  445. begin
  446. uname:=u.realmodulename;
  447. if mo_hint_deprecated in u.moduleoptions then
  448. if (mo_has_deprecated_msg in u.moduleoptions) and (u.deprecatedmsg <> nil) then
  449. MessagePos2(unitsym.fileinfo,sym_w_deprecated_unit_with_msg,uname^,u.deprecatedmsg^)
  450. else
  451. MessagePos1(unitsym.fileinfo,sym_w_deprecated_unit,uname^);
  452. if mo_hint_experimental in u.moduleoptions then
  453. MessagePos1(unitsym.fileinfo,sym_w_experimental_unit,uname^);
  454. if mo_hint_platform in u.moduleoptions then
  455. MessagePos1(unitsym.fileinfo,sym_w_non_portable_unit,uname^);
  456. if mo_hint_library in u.moduleoptions then
  457. MessagePos1(unitsym.fileinfo,sym_w_library_unit,uname^);
  458. if mo_hint_unimplemented in u.moduleoptions then
  459. MessagePos1(unitsym.fileinfo,sym_w_non_implemented_unit,uname^);
  460. end;
  461. {****************************************************************************
  462. TDENPENDENT_UNIT
  463. ****************************************************************************}
  464. constructor tdependent_unit.create(_u : tmodule);
  465. begin
  466. u:=_u;
  467. end;
  468. {****************************************************************************
  469. TMODULE
  470. ****************************************************************************}
  471. constructor tmodule.create(LoadedFrom:TModule;const amodulename: string; const afilename:TPathStr;_is_unit:boolean);
  472. var
  473. n:string;
  474. fn:TPathStr;
  475. begin
  476. if amodulename='' then
  477. n:=ChangeFileExt(ExtractFileName(afilename),'')
  478. else
  479. n:=amodulename;
  480. if afilename='' then
  481. fn:=amodulename
  482. else
  483. fn:=afilename;
  484. { Programs have the name 'Program' to don't conflict with dup id's }
  485. if _is_unit then
  486. inherited create(amodulename)
  487. else
  488. inherited create('Program');
  489. mainsource:=fn;
  490. { Dos has the famous 8.3 limit :( }
  491. {$ifdef shortasmprefix}
  492. asmprefix:=stringdup(FixFileName('as'));
  493. {$else}
  494. asmprefix:=stringdup(FixFileName(n));
  495. {$endif}
  496. setfilename(fn,true);
  497. localunitsearchpath:=TSearchPathList.Create;
  498. localobjectsearchpath:=TSearchPathList.Create;
  499. localincludesearchpath:=TSearchPathList.Create;
  500. locallibrarysearchpath:=TSearchPathList.Create;
  501. localframeworksearchpath:=TSearchPathList.Create;
  502. used_units:=TLinkedList.Create;
  503. dependent_units:=TLinkedList.Create;
  504. resourcefiles:=TCmdStrList.Create;
  505. linkorderedsymbols:=TCmdStrList.Create;
  506. linkunitofiles:=TLinkContainer.Create;
  507. linkunitstaticlibs:=TLinkContainer.Create;
  508. linkunitsharedlibs:=TLinkContainer.Create;
  509. linkotherofiles:=TLinkContainer.Create;
  510. linkotherstaticlibs:=TLinkContainer.Create;
  511. linkothersharedlibs:=TLinkContainer.Create;
  512. linkotherframeworks:=TLinkContainer.Create;
  513. mainname:=nil;
  514. FImportLibraryList:=TFPHashObjectList.Create(true);
  515. crc:=0;
  516. interface_crc:=0;
  517. indirect_crc:=0;
  518. headerflags:=0;
  519. longversion:=0;
  520. moduleflags:=[];
  521. scanner:=nil;
  522. unitmap:=nil;
  523. unitmapsize:=0;
  524. derefmap:=nil;
  525. derefmapsize:=0;
  526. derefmapcnt:=0;
  527. derefdata:=TDynamicArray.Create(1024);
  528. derefdataintflen:=0;
  529. deflist:=TFPObjectList.Create(false);
  530. symlist:=TFPObjectList.Create(false);
  531. ptrdefs:=THashSet.Create(64,true,false);
  532. arraydefs:=THashSet.Create(64,true,false);
  533. procaddrdefs:=THashSet.Create(64,true,false);
  534. {$ifdef llvm}
  535. llvmdefs:=THashSet.Create(64,true,false);
  536. llvmusedsyms:=TFPObjectList.Create(true);
  537. llvmcompilerusedsyms:=TFPObjectList.Create(true);
  538. llvminitprocs:=TFPList.Create;
  539. llvmfiniprocs:=TFPList.Create;
  540. llvmmetadatastrings:=TFPHashList.Create;
  541. {$endif llvm}
  542. ansistrdef:=nil;
  543. wpoinfo:=nil;
  544. checkforwarddefs:=TFPObjectList.Create(false);
  545. extendeddefs:=TFPHashObjectList.Create(true);
  546. genericdummysyms:=tfphashobjectlist.create(true);
  547. pendingspecializations:=tfphashobjectlist.create(false);
  548. waitingforunit:=tfpobjectlist.create(false);
  549. waitingunits:=tfpobjectlist.create(false);
  550. used_rtti_attrs:=tfpobjectlist.create(false);
  551. globalsymtable:=nil;
  552. localsymtable:=nil;
  553. globalmacrosymtable:=nil;
  554. localmacrosymtable:=nil;
  555. loaded_from:=LoadedFrom;
  556. do_reload:=false;
  557. do_compile:=false;
  558. sources_avail:=true;
  559. mainfilepos.line:=0;
  560. mainfilepos.column:=0;
  561. mainfilepos.fileindex:=0;
  562. recompile_reason:=rr_unknown;
  563. in_interface:=true;
  564. in_global:=true;
  565. is_unit:=_is_unit;
  566. islibrary:=false;
  567. ispackage:=false;
  568. change_endian:=false;
  569. is_dbginfo_written:=false;
  570. mode_switch_allowed:= true;
  571. moduleoptions:=[];
  572. deprecatedmsg:=nil;
  573. namespace:=nil;
  574. tcinitcode:=nil;
  575. _exports:=TLinkedList.Create;
  576. dllscannerinputlist:=TFPHashList.Create;
  577. asmdata:=casmdata.create(modulename);
  578. unitimportsyms:=TFPObjectList.Create(false);
  579. publicasmsyms:=TFPHashObjectList.Create(true);
  580. externasmsyms:=TFPHashObjectList.Create(true);
  581. InitDebugInfo(self,false);
  582. end;
  583. destructor tmodule.Destroy;
  584. var
  585. i : longint;
  586. current_debuginfo_reset : boolean;
  587. begin
  588. if assigned(unitmap) then
  589. freemem(unitmap);
  590. if assigned(derefmap) then
  591. begin
  592. for i:=0 to derefmapcnt-1 do
  593. stringdispose(derefmap[i].modulename);
  594. freemem(derefmap);
  595. end;
  596. if assigned(_exports) then
  597. _exports.free;
  598. if assigned(dllscannerinputlist) then
  599. dllscannerinputlist.free;
  600. if assigned(scanner) then
  601. begin
  602. { also update current_scanner if it was pointing
  603. to this module }
  604. if current_scanner=tscannerfile(scanner) then
  605. current_scanner:=nil;
  606. tscannerfile(scanner).free;
  607. end;
  608. if assigned(asmdata) then
  609. begin
  610. if current_asmdata=asmdata then
  611. current_asmdata:=nil;
  612. asmdata.free;
  613. end;
  614. if assigned(procinfo) then
  615. begin
  616. if current_procinfo=tprocinfo(procinfo) then
  617. begin
  618. current_procinfo:=nil;
  619. current_structdef:=nil;
  620. current_genericdef:=nil;
  621. current_specializedef:=nil;
  622. end;
  623. { release procinfo tree }
  624. tprocinfo(procinfo).destroy_tree;
  625. end;
  626. DoneDebugInfo(self,current_debuginfo_reset);
  627. used_units.free;
  628. dependent_units.free;
  629. resourcefiles.Free;
  630. linkorderedsymbols.Free;
  631. linkunitofiles.Free;
  632. linkunitstaticlibs.Free;
  633. linkunitsharedlibs.Free;
  634. linkotherofiles.Free;
  635. linkotherstaticlibs.Free;
  636. linkothersharedlibs.Free;
  637. linkotherframeworks.Free;
  638. stringdispose(mainname);
  639. externasmsyms.Free;
  640. publicasmsyms.Free;
  641. unitimportsyms.Free;
  642. FImportLibraryList.Free;
  643. extendeddefs.Free;
  644. genericdummysyms.free;
  645. pendingspecializations.free;
  646. waitingforunit.free;
  647. waitingunits.free;
  648. used_rtti_attrs.free;
  649. stringdispose(asmprefix);
  650. stringdispose(deprecatedmsg);
  651. stringdispose(namespace);
  652. tcinitcode.free;
  653. localunitsearchpath.Free;
  654. localobjectsearchpath.free;
  655. localincludesearchpath.free;
  656. locallibrarysearchpath.free;
  657. localframeworksearchpath.free;
  658. {$ifdef MEMDEBUG}
  659. memsymtable.start;
  660. {$endif}
  661. derefdata.free;
  662. if assigned(deflist) then
  663. begin
  664. for i:=0 to deflist.Count-1 do
  665. if assigned(deflist[i]) and
  666. (tdef(deflist[i]).registered_in_module=self) then
  667. tdef(deflist[i]).registered_in_module:=nil;
  668. deflist.free;
  669. end;
  670. symlist.free;
  671. ptrdefs.free;
  672. arraydefs.free;
  673. procaddrdefs.free;
  674. {$ifdef llvm}
  675. llvmdefs.free;
  676. llvmusedsyms.free;
  677. llvmcompilerusedsyms.free;
  678. llvminitprocs.free;
  679. llvmfiniprocs.free;
  680. llvmmetadatastrings.free;
  681. {$endif llvm}
  682. ansistrdef:=nil;
  683. wpoinfo.free;
  684. checkforwarddefs.free;
  685. globalsymtable.free;
  686. localsymtable.free;
  687. globalmacrosymtable.free;
  688. localmacrosymtable.free;
  689. {$ifdef MEMDEBUG}
  690. memsymtable.stop;
  691. {$endif}
  692. inherited Destroy;
  693. end;
  694. procedure tmodule.reset;
  695. var
  696. i : longint;
  697. current_debuginfo_reset : boolean;
  698. begin
  699. if assigned(scanner) then
  700. begin
  701. { also update current_scanner if it was pointing
  702. to this module }
  703. if current_scanner=tscannerfile(scanner) then
  704. current_scanner:=nil;
  705. tscannerfile(scanner).free;
  706. scanner:=nil;
  707. end;
  708. if assigned(procinfo) then
  709. begin
  710. if current_procinfo=tprocinfo(procinfo) then
  711. begin
  712. current_procinfo:=nil;
  713. current_structdef:=nil;
  714. current_genericdef:=nil;
  715. current_specializedef:=nil;
  716. end;
  717. { release procinfo tree }
  718. tprocinfo(procinfo).destroy_tree;
  719. end;
  720. if assigned(asmdata) then
  721. begin
  722. if current_asmdata=asmdata then
  723. current_asmdata:=nil;
  724. asmdata.free;
  725. asmdata:=nil;
  726. end;
  727. DoneDebugInfo(self,current_debuginfo_reset);
  728. globalsymtable.free;
  729. globalsymtable:=nil;
  730. localsymtable.free;
  731. localsymtable:=nil;
  732. globalmacrosymtable.free;
  733. globalmacrosymtable:=nil;
  734. localmacrosymtable.free;
  735. localmacrosymtable:=nil;
  736. deflist.free;
  737. deflist:=TFPObjectList.Create(false);
  738. symlist.free;
  739. symlist:=TFPObjectList.Create(false);
  740. ptrdefs.free;
  741. ptrdefs:=THashSet.Create(64,true,false);
  742. arraydefs.free;
  743. arraydefs:=THashSet.Create(64,true,false);
  744. procaddrdefs.free;
  745. procaddrdefs:=THashSet.Create(64,true,false);
  746. {$ifdef llvm}
  747. llvmdefs.free;
  748. llvmdefs:=THashSet.Create(64,true,false);
  749. llvmusedsyms.free;
  750. llvmusedsyms:=TFPObjectList.Create(true);
  751. llvmcompilerusedsyms.free;
  752. llvmcompilerusedsyms:=TFPObjectList.Create(true);
  753. llvminitprocs.free;
  754. llvminitprocs:=TFPList.Create;
  755. llvmfiniprocs.free;
  756. llvmfiniprocs:=TFPList.Create;
  757. llvmmetadatastrings.free;
  758. llvmmetadatastrings:=TFPHashList.Create;
  759. {$endif llvm}
  760. wpoinfo.free;
  761. wpoinfo:=nil;
  762. checkforwarddefs.free;
  763. checkforwarddefs:=TFPObjectList.Create(false);
  764. publicasmsyms.free;
  765. publicasmsyms:=TFPHashObjectList.Create(true);
  766. externasmsyms.free;
  767. externasmsyms:=TFPHashObjectList.Create(true);
  768. unitimportsyms.free;
  769. unitimportsyms:=TFPObjectList.Create(false);
  770. derefdata.free;
  771. derefdata:=TDynamicArray.Create(1024);
  772. if assigned(unitmap) then
  773. begin
  774. freemem(unitmap);
  775. unitmap:=nil;
  776. end;
  777. if assigned(derefmap) then
  778. begin
  779. for i:=0 to derefmapcnt-1 do
  780. stringdispose(derefmap[i].modulename);
  781. freemem(derefmap);
  782. derefmap:=nil;
  783. end;
  784. unitmapsize:=0;
  785. derefmapsize:=0;
  786. derefmapcnt:=0;
  787. derefdataintflen:=0;
  788. sourcefiles.free;
  789. sourcefiles:=tinputfilemanager.create;
  790. asmdata:=casmdata.create(modulename);
  791. InitDebugInfo(self,current_debuginfo_reset);
  792. _exports.free;
  793. _exports:=tlinkedlist.create;
  794. dllscannerinputlist.free;
  795. dllscannerinputlist:=TFPHashList.create;
  796. used_units.free;
  797. used_units:=TLinkedList.Create;
  798. dependent_units.free;
  799. dependent_units:=TLinkedList.Create;
  800. resourcefiles.Free;
  801. resourcefiles:=TCmdStrList.Create;
  802. linkorderedsymbols.Free;
  803. linkorderedsymbols:=TCmdStrList.Create;
  804. pendingspecializations.free;
  805. pendingspecializations:=tfphashobjectlist.create(false);
  806. if assigned(waitingforunit) and
  807. (waitingforunit.count<>0) then
  808. internalerror(2016070501);
  809. waitingforunit.free;
  810. waitingforunit:=tfpobjectlist.create(false);
  811. linkunitofiles.Free;
  812. linkunitofiles:=TLinkContainer.Create;
  813. linkunitstaticlibs.Free;
  814. linkunitstaticlibs:=TLinkContainer.Create;
  815. linkunitsharedlibs.Free;
  816. linkunitsharedlibs:=TLinkContainer.Create;
  817. linkotherofiles.Free;
  818. linkotherofiles:=TLinkContainer.Create;
  819. linkotherstaticlibs.Free;
  820. linkotherstaticlibs:=TLinkContainer.Create;
  821. linkothersharedlibs.Free;
  822. linkothersharedlibs:=TLinkContainer.Create;
  823. linkotherframeworks.Free;
  824. linkotherframeworks:=TLinkContainer.Create;
  825. stringdispose(mainname);
  826. FImportLibraryList.Free;
  827. FImportLibraryList:=TFPHashObjectList.Create;
  828. do_compile:=false;
  829. do_reload:=false;
  830. interface_compiled:=false;
  831. in_interface:=true;
  832. in_global:=true;
  833. mode_switch_allowed:=true;
  834. stringdispose(deprecatedmsg);
  835. stringdispose(namespace);
  836. tcinitcode.free;
  837. tcinitcode:=nil;
  838. localunitsearchpath.Free;
  839. localunitsearchpath:=TSearchPathList.Create;
  840. localobjectsearchpath.free;
  841. localobjectsearchpath:=TSearchPathList.Create;
  842. localincludesearchpath.free;
  843. localincludesearchpath:=TSearchPathList.Create;
  844. locallibrarysearchpath.free;
  845. locallibrarysearchpath:=TSearchPathList.Create;
  846. localframeworksearchpath.free;
  847. localframeworksearchpath:=TSearchPathList.Create;
  848. moduleoptions:=[];
  849. is_dbginfo_written:=false;
  850. crc:=0;
  851. interface_crc:=0;
  852. indirect_crc:=0;
  853. headerflags:=0;
  854. longversion:=0;
  855. moduleflags:=[];
  856. mainfilepos.line:=0;
  857. mainfilepos.column:=0;
  858. mainfilepos.fileindex:=0;
  859. recompile_reason:=rr_unknown;
  860. {
  861. The following fields should not
  862. be reset:
  863. mainsource
  864. state
  865. loaded_from
  866. sources_avail
  867. }
  868. end;
  869. procedure tmodule.adddependency(callermodule:tmodule);
  870. begin
  871. { This is not needed for programs }
  872. if not callermodule.is_unit then
  873. exit;
  874. Message2(unit_u_add_depend_to,callermodule.modulename^,modulename^);
  875. dependent_units.concat(tdependent_unit.create(callermodule));
  876. end;
  877. procedure tmodule.flagdependent(callermodule:tmodule);
  878. var
  879. pm : tdependent_unit;
  880. begin
  881. { flag all units that depend on this unit for reloading }
  882. pm:=tdependent_unit(current_module.dependent_units.first);
  883. while assigned(pm) do
  884. begin
  885. { We do not have to reload the unit that wants to load
  886. this unit, unless this unit is already compiled during
  887. the loading }
  888. if (pm.u=callermodule) and
  889. (pm.u.state<>ms_compiled) then
  890. Message1(unit_u_no_reload_is_caller,pm.u.modulename^)
  891. else
  892. if pm.u.state=ms_second_compile then
  893. Message1(unit_u_no_reload_in_second_compile,pm.u.modulename^)
  894. else
  895. begin
  896. pm.u.do_reload:=true;
  897. Message1(unit_u_flag_for_reload,pm.u.modulename^);
  898. end;
  899. pm:=tdependent_unit(pm.next);
  900. end;
  901. end;
  902. procedure tmodule.addimportedsym(sym:TSymEntry);
  903. begin
  904. if unitimportsyms.IndexOf(sym)<0 then
  905. unitimportsyms.Add(sym);
  906. end;
  907. function tmodule.addusedunit(hp:tmodule;inuses:boolean;usym:tunitsym):tused_unit;
  908. var
  909. pu : tused_unit;
  910. begin
  911. pu:=tused_unit.create(hp,in_interface,inuses,usym);
  912. used_units.concat(pu);
  913. addusedunit:=pu;
  914. end;
  915. procedure tmodule.updatemaps;
  916. var
  917. oldmapsize : longint;
  918. hp : tmodule;
  919. i : longint;
  920. begin
  921. { Extend unitmap }
  922. oldmapsize:=unitmapsize;
  923. unitmapsize:=loaded_units.count;
  924. reallocmem(unitmap,unitmapsize*sizeof(tunitmaprec));
  925. fillchar(unitmap[oldmapsize],(unitmapsize-oldmapsize)*sizeof(tunitmaprec),0);
  926. { Extend Derefmap }
  927. oldmapsize:=derefmapsize;
  928. derefmapsize:=loaded_units.count;
  929. reallocmem(derefmap,derefmapsize*sizeof(tderefmaprec));
  930. fillchar(derefmap[oldmapsize],(derefmapsize-oldmapsize)*sizeof(tderefmaprec),0);
  931. { Add all units to unitmap }
  932. hp:=tmodule(loaded_units.first);
  933. i:=0;
  934. while assigned(hp) do
  935. begin
  936. if hp.moduleid>=unitmapsize then
  937. internalerror(200501151);
  938. { Verify old entries }
  939. if (i<oldmapsize) then
  940. begin
  941. if (hp.moduleid<>i) or
  942. (unitmap[hp.moduleid].u<>hp) then
  943. internalerror(200501156);
  944. end
  945. else
  946. begin
  947. unitmap[hp.moduleid].u:=hp;
  948. unitmap[hp.moduleid].derefidx:=-1;
  949. end;
  950. inc(i);
  951. hp:=tmodule(hp.next);
  952. end;
  953. end;
  954. function tmodule.derefidx_unit(id:longint):longint;
  955. begin
  956. if id>=unitmapsize then
  957. internalerror(2005011511);
  958. if unitmap[id].derefidx=-1 then
  959. begin
  960. unitmap[id].derefidx:=derefmapcnt;
  961. inc(derefmapcnt);
  962. derefmap[unitmap[id].derefidx].u:=unitmap[id].u;
  963. end;
  964. if unitmap[id].derefidx>=derefmapsize then
  965. internalerror(2005011514);
  966. result:=unitmap[id].derefidx;
  967. end;
  968. function tmodule.resolve_unit(id:longint):tmodule;
  969. var
  970. hp : tmodule;
  971. begin
  972. if id>=derefmapsize then
  973. internalerror(200306231);
  974. result:=derefmap[id].u;
  975. if not assigned(result) then
  976. begin
  977. if not assigned(derefmap[id].modulename) or
  978. (derefmap[id].modulename^='') then
  979. internalerror(200501159);
  980. hp:=tmodule(loaded_units.first);
  981. while assigned(hp) do
  982. begin
  983. { only check for units. The main program is also
  984. as a unit in the loaded_units list. We simply need
  985. to ignore this entry (PFV) }
  986. if hp.is_unit and
  987. (hp.modulename^=derefmap[id].modulename^) then
  988. break;
  989. hp:=tmodule(hp.next);
  990. end;
  991. if not assigned(hp) then
  992. internalerror(2005011510);
  993. derefmap[id].u:=hp;
  994. result:=hp;
  995. end;
  996. end;
  997. procedure tmodule.allunitsused;
  998. var
  999. pu : tused_unit;
  1000. begin
  1001. pu:=tused_unit(used_units.first);
  1002. while assigned(pu) do
  1003. begin
  1004. if assigned(pu.u.globalsymtable) then
  1005. begin
  1006. if unitmap[pu.u.moduleid].u<>pu.u then
  1007. internalerror(200501157);
  1008. { Give a note when the unit is not referenced, skip
  1009. this is for units with an initialization/finalization }
  1010. if (unitmap[pu.u.moduleid].refs=0) and
  1011. pu.in_uses and
  1012. ((pu.u.moduleflags * [mf_init,mf_finalize])=[]) then
  1013. CGMessagePos2(pu.unitsym.fileinfo,sym_n_unit_not_used,pu.u.realmodulename^,realmodulename^);
  1014. end;
  1015. pu:=tused_unit(pu.next);
  1016. end;
  1017. end;
  1018. procedure tmodule.end_of_parsing;
  1019. begin
  1020. { free asmdata }
  1021. if assigned(asmdata) then
  1022. begin
  1023. asmdata.free;
  1024. asmdata:=nil;
  1025. end;
  1026. { free scanner }
  1027. if assigned(scanner) then
  1028. begin
  1029. if current_scanner=tscannerfile(scanner) then
  1030. current_scanner:=nil;
  1031. tscannerfile(scanner).free;
  1032. scanner:=nil;
  1033. end;
  1034. { free symtable stack }
  1035. if assigned(symtablestack) then
  1036. begin
  1037. symtablestack.free;
  1038. symtablestack:=nil;
  1039. end;
  1040. if assigned(macrosymtablestack) then
  1041. begin
  1042. macrosymtablestack.free;
  1043. macrosymtablestack:=nil;
  1044. end;
  1045. waitingforunit.free;
  1046. waitingforunit:=nil;
  1047. localmacrosymtable.free;
  1048. localmacrosymtable:=nil;
  1049. ptrdefs.free;
  1050. ptrdefs:=nil;
  1051. arraydefs.free;
  1052. arraydefs:=nil;
  1053. procaddrdefs.free;
  1054. procaddrdefs:=nil;
  1055. {$ifdef llvm}
  1056. llvmdefs.free;
  1057. llvmdefs:=nil;
  1058. {$endif llvm}
  1059. checkforwarddefs.free;
  1060. checkforwarddefs:=nil;
  1061. tcinitcode.free;
  1062. tcinitcode:=nil;
  1063. localunitsearchpath.free;
  1064. localunitsearchpath:=nil;
  1065. localobjectsearchpath.free;
  1066. localobjectsearchpath:=nil;
  1067. localincludesearchpath.free;
  1068. localincludesearchpath:=nil;
  1069. locallibrarysearchpath.free;
  1070. locallibrarysearchpath:=nil;
  1071. localframeworksearchpath.free;
  1072. localframeworksearchpath:=nil;
  1073. end;
  1074. procedure tmodule.setmodulename(const s:string);
  1075. begin
  1076. stringdispose(modulename);
  1077. stringdispose(realmodulename);
  1078. modulename:=stringdup(upper(s));
  1079. realmodulename:=stringdup(s);
  1080. { also update asmlibrary names }
  1081. current_asmdata.name:=modulename;
  1082. end;
  1083. procedure TModule.AddExternalImport(const libname,symname,symmangledname:string;
  1084. OrdNr: longint;isvar:boolean;ImportByOrdinalOnly:boolean);
  1085. var
  1086. ImportLibrary,OtherIL : TImportLibrary;
  1087. ImportSymbol : TImportSymbol;
  1088. i : longint;
  1089. begin
  1090. ImportLibrary:=TImportLibrary(ImportLibraryList.Find(libname));
  1091. if not assigned(ImportLibrary) then
  1092. ImportLibrary:=TImportLibrary.Create(ImportLibraryList,libname);
  1093. ImportSymbol:=TImportSymbol(ImportLibrary.ImportSymbolList.Find(symname));
  1094. if not assigned(ImportSymbol) then
  1095. begin
  1096. { Check that the same name does not exist in another library }
  1097. { If it does and the same mangled name is used, issue a warning }
  1098. if ImportLibraryList.Count>1 then
  1099. for i:=0 To ImportLibraryList.Count-1 do
  1100. begin
  1101. OtherIL:=TImportLibrary(ImportLibraryList.Items[i]);
  1102. ImportSymbol:=TImportSymbol(OtherIL.ImportSymbolList.Find(symname));
  1103. if assigned(ImportSymbol) then
  1104. begin
  1105. if ImportSymbol.MangledName=symmangledname then
  1106. begin
  1107. CGMessage3(sym_w_library_overload,symname,libname,OtherIL.Name);
  1108. break;
  1109. end;
  1110. end;
  1111. end;
  1112. if not ImportByOrdinalOnly then
  1113. { negative ordinal number indicates import by name with ordinal number as hint }
  1114. OrdNr:=-OrdNr;
  1115. ImportSymbol:=TImportSymbol.Create(ImportLibrary.ImportSymbolList,
  1116. symname,symmangledname,OrdNr,isvar);
  1117. end;
  1118. end;
  1119. procedure tmodule.add_public_asmsym(sym:TAsmSymbol);
  1120. begin
  1121. add_public_asmsym(sym.name,sym.bind,sym.typ);
  1122. end;
  1123. procedure tmodule.add_public_asmsym(const name:TSymStr;bind:TAsmsymbind;typ:Tasmsymtype);
  1124. var
  1125. sym : tasmsymbol;
  1126. begin
  1127. { ToDo: check for AB_GLOBAL, AB_EXTERNAL? }
  1128. sym:=tasmsymbol(publicasmsyms.find(name));
  1129. if assigned(sym) then
  1130. begin
  1131. if (sym.bind<>bind) or (sym.typ<>typ) then
  1132. internalerror(2016070101);
  1133. exit;
  1134. end;
  1135. tasmsymbol.create(publicasmsyms,name,bind,typ);
  1136. end;
  1137. procedure tmodule.add_extern_asmsym(sym:TAsmSymbol);
  1138. begin
  1139. add_extern_asmsym(sym.name,sym.bind,sym.typ);
  1140. end;
  1141. procedure tmodule.add_extern_asmsym(const name:TSymStr;bind:TAsmsymbind;typ:Tasmsymtype);
  1142. var
  1143. sym : tasmsymbol;
  1144. begin
  1145. { ToDo: check for AB_EXTERNAL? }
  1146. sym:=tasmsymbol(externasmsyms.find(name));
  1147. if assigned(sym) then
  1148. begin
  1149. if (sym.bind<>bind) or (sym.typ<>typ) then
  1150. internalerror(2016070102);
  1151. exit;
  1152. end;
  1153. tasmsymbol.create(externasmsyms,name,bind,typ);
  1154. end;
  1155. initialization
  1156. {$ifdef MEMDEBUG}
  1157. memsymtable:=TMemDebug.create('Symtables');
  1158. memsymtable.stop;
  1159. {$endif MEMDEBUG}
  1160. finalization
  1161. {$ifdef MEMDEBUG}
  1162. memsymtable.free;
  1163. {$endif MEMDEBUG}
  1164. end.