fmodule.pas 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  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;
  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,0,sizeof(current_filepos));
  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. deflist.free;
  663. symlist.free;
  664. ptrdefs.free;
  665. arraydefs.free;
  666. procaddrdefs.free;
  667. {$ifdef llvm}
  668. llvmdefs.free;
  669. llvmusedsyms.free;
  670. llvmcompilerusedsyms.free;
  671. llvminitprocs.free;
  672. llvmfiniprocs.free;
  673. llvmmetadatastrings.free;
  674. {$endif llvm}
  675. ansistrdef:=nil;
  676. wpoinfo.free;
  677. checkforwarddefs.free;
  678. globalsymtable.free;
  679. localsymtable.free;
  680. globalmacrosymtable.free;
  681. localmacrosymtable.free;
  682. {$ifdef MEMDEBUG}
  683. memsymtable.stop;
  684. {$endif}
  685. inherited Destroy;
  686. end;
  687. procedure tmodule.reset;
  688. var
  689. i : longint;
  690. current_debuginfo_reset : boolean;
  691. begin
  692. if assigned(scanner) then
  693. begin
  694. { also update current_scanner if it was pointing
  695. to this module }
  696. if current_scanner=tscannerfile(scanner) then
  697. current_scanner:=nil;
  698. tscannerfile(scanner).free;
  699. scanner:=nil;
  700. end;
  701. if assigned(procinfo) then
  702. begin
  703. if current_procinfo=tprocinfo(procinfo) then
  704. begin
  705. current_procinfo:=nil;
  706. current_structdef:=nil;
  707. current_genericdef:=nil;
  708. current_specializedef:=nil;
  709. end;
  710. { release procinfo tree }
  711. tprocinfo(procinfo).destroy_tree;
  712. end;
  713. if assigned(asmdata) then
  714. begin
  715. if current_asmdata=asmdata then
  716. current_asmdata:=nil;
  717. asmdata.free;
  718. asmdata:=nil;
  719. end;
  720. DoneDebugInfo(self,current_debuginfo_reset);
  721. globalsymtable.free;
  722. globalsymtable:=nil;
  723. localsymtable.free;
  724. localsymtable:=nil;
  725. globalmacrosymtable.free;
  726. globalmacrosymtable:=nil;
  727. localmacrosymtable.free;
  728. localmacrosymtable:=nil;
  729. deflist.free;
  730. deflist:=TFPObjectList.Create(false);
  731. symlist.free;
  732. symlist:=TFPObjectList.Create(false);
  733. ptrdefs.free;
  734. ptrdefs:=THashSet.Create(64,true,false);
  735. arraydefs.free;
  736. arraydefs:=THashSet.Create(64,true,false);
  737. procaddrdefs.free;
  738. procaddrdefs:=THashSet.Create(64,true,false);
  739. {$ifdef llvm}
  740. llvmdefs.free;
  741. llvmdefs:=THashSet.Create(64,true,false);
  742. llvmusedsyms.free;
  743. llvmusedsyms:=TFPObjectList.Create(true);
  744. llvmcompilerusedsyms.free;
  745. llvmcompilerusedsyms:=TFPObjectList.Create(true);
  746. llvminitprocs.free;
  747. llvminitprocs:=TFPList.Create;
  748. llvmfiniprocs.free;
  749. llvmfiniprocs:=TFPList.Create;
  750. llvmmetadatastrings.free;
  751. llvmmetadatastrings:=TFPHashList.Create;
  752. {$endif llvm}
  753. wpoinfo.free;
  754. wpoinfo:=nil;
  755. checkforwarddefs.free;
  756. checkforwarddefs:=TFPObjectList.Create(false);
  757. publicasmsyms.free;
  758. publicasmsyms:=TFPHashObjectList.Create(true);
  759. externasmsyms.free;
  760. externasmsyms:=TFPHashObjectList.Create(true);
  761. unitimportsyms.free;
  762. unitimportsyms:=TFPObjectList.Create(false);
  763. derefdata.free;
  764. derefdata:=TDynamicArray.Create(1024);
  765. if assigned(unitmap) then
  766. begin
  767. freemem(unitmap);
  768. unitmap:=nil;
  769. end;
  770. if assigned(derefmap) then
  771. begin
  772. for i:=0 to derefmapcnt-1 do
  773. stringdispose(derefmap[i].modulename);
  774. freemem(derefmap);
  775. derefmap:=nil;
  776. end;
  777. unitmapsize:=0;
  778. derefmapsize:=0;
  779. derefmapcnt:=0;
  780. derefdataintflen:=0;
  781. sourcefiles.free;
  782. sourcefiles:=tinputfilemanager.create;
  783. asmdata:=casmdata.create(modulename);
  784. InitDebugInfo(self,current_debuginfo_reset);
  785. _exports.free;
  786. _exports:=tlinkedlist.create;
  787. dllscannerinputlist.free;
  788. dllscannerinputlist:=TFPHashList.create;
  789. used_units.free;
  790. used_units:=TLinkedList.Create;
  791. dependent_units.free;
  792. dependent_units:=TLinkedList.Create;
  793. resourcefiles.Free;
  794. resourcefiles:=TCmdStrList.Create;
  795. linkorderedsymbols.Free;
  796. linkorderedsymbols:=TCmdStrList.Create;;
  797. pendingspecializations.free;
  798. pendingspecializations:=tfphashobjectlist.create(false);
  799. if assigned(waitingforunit) and
  800. (waitingforunit.count<>0) then
  801. internalerror(2016070501);
  802. waitingforunit.free;
  803. waitingforunit:=tfpobjectlist.create(false);;
  804. linkunitofiles.Free;
  805. linkunitofiles:=TLinkContainer.Create;
  806. linkunitstaticlibs.Free;
  807. linkunitstaticlibs:=TLinkContainer.Create;
  808. linkunitsharedlibs.Free;
  809. linkunitsharedlibs:=TLinkContainer.Create;
  810. linkotherofiles.Free;
  811. linkotherofiles:=TLinkContainer.Create;
  812. linkotherstaticlibs.Free;
  813. linkotherstaticlibs:=TLinkContainer.Create;
  814. linkothersharedlibs.Free;
  815. linkothersharedlibs:=TLinkContainer.Create;
  816. linkotherframeworks.Free;
  817. linkotherframeworks:=TLinkContainer.Create;
  818. stringdispose(mainname);
  819. FImportLibraryList.Free;
  820. FImportLibraryList:=TFPHashObjectList.Create;
  821. do_compile:=false;
  822. do_reload:=false;
  823. interface_compiled:=false;
  824. in_interface:=true;
  825. in_global:=true;
  826. mode_switch_allowed:=true;
  827. stringdispose(deprecatedmsg);
  828. stringdispose(namespace);
  829. tcinitcode.free;
  830. tcinitcode:=nil;
  831. localunitsearchpath.Free;
  832. localunitsearchpath:=TSearchPathList.Create;
  833. localobjectsearchpath.free;
  834. localobjectsearchpath:=TSearchPathList.Create;
  835. localincludesearchpath.free;
  836. localincludesearchpath:=TSearchPathList.Create;
  837. locallibrarysearchpath.free;
  838. locallibrarysearchpath:=TSearchPathList.Create;
  839. localframeworksearchpath.free;
  840. localframeworksearchpath:=TSearchPathList.Create;
  841. moduleoptions:=[];
  842. is_dbginfo_written:=false;
  843. crc:=0;
  844. interface_crc:=0;
  845. indirect_crc:=0;
  846. headerflags:=0;
  847. longversion:=0;
  848. moduleflags:=[];
  849. mainfilepos.line:=0;
  850. mainfilepos.column:=0;
  851. mainfilepos.fileindex:=0;
  852. recompile_reason:=rr_unknown;
  853. {
  854. The following fields should not
  855. be reset:
  856. mainsource
  857. state
  858. loaded_from
  859. sources_avail
  860. }
  861. end;
  862. procedure tmodule.adddependency(callermodule:tmodule);
  863. begin
  864. { This is not needed for programs }
  865. if not callermodule.is_unit then
  866. exit;
  867. Message2(unit_u_add_depend_to,callermodule.modulename^,modulename^);
  868. dependent_units.concat(tdependent_unit.create(callermodule));
  869. end;
  870. procedure tmodule.flagdependent(callermodule:tmodule);
  871. var
  872. pm : tdependent_unit;
  873. begin
  874. { flag all units that depend on this unit for reloading }
  875. pm:=tdependent_unit(current_module.dependent_units.first);
  876. while assigned(pm) do
  877. begin
  878. { We do not have to reload the unit that wants to load
  879. this unit, unless this unit is already compiled during
  880. the loading }
  881. if (pm.u=callermodule) and
  882. (pm.u.state<>ms_compiled) then
  883. Message1(unit_u_no_reload_is_caller,pm.u.modulename^)
  884. else
  885. if pm.u.state=ms_second_compile then
  886. Message1(unit_u_no_reload_in_second_compile,pm.u.modulename^)
  887. else
  888. begin
  889. pm.u.do_reload:=true;
  890. Message1(unit_u_flag_for_reload,pm.u.modulename^);
  891. end;
  892. pm:=tdependent_unit(pm.next);
  893. end;
  894. end;
  895. procedure tmodule.addimportedsym(sym:TSymEntry);
  896. begin
  897. if unitimportsyms.IndexOf(sym)<0 then
  898. unitimportsyms.Add(sym);
  899. end;
  900. function tmodule.addusedunit(hp:tmodule;inuses:boolean;usym:tunitsym):tused_unit;
  901. var
  902. pu : tused_unit;
  903. begin
  904. pu:=tused_unit.create(hp,in_interface,inuses,usym);
  905. used_units.concat(pu);
  906. addusedunit:=pu;
  907. end;
  908. procedure tmodule.updatemaps;
  909. var
  910. oldmapsize : longint;
  911. hp : tmodule;
  912. i : longint;
  913. begin
  914. { Extend unitmap }
  915. oldmapsize:=unitmapsize;
  916. unitmapsize:=loaded_units.count;
  917. reallocmem(unitmap,unitmapsize*sizeof(tunitmaprec));
  918. fillchar(unitmap[oldmapsize],(unitmapsize-oldmapsize)*sizeof(tunitmaprec),0);
  919. { Extend Derefmap }
  920. oldmapsize:=derefmapsize;
  921. derefmapsize:=loaded_units.count;
  922. reallocmem(derefmap,derefmapsize*sizeof(tderefmaprec));
  923. fillchar(derefmap[oldmapsize],(derefmapsize-oldmapsize)*sizeof(tderefmaprec),0);
  924. { Add all units to unitmap }
  925. hp:=tmodule(loaded_units.first);
  926. i:=0;
  927. while assigned(hp) do
  928. begin
  929. if hp.moduleid>=unitmapsize then
  930. internalerror(200501151);
  931. { Verify old entries }
  932. if (i<oldmapsize) then
  933. begin
  934. if (hp.moduleid<>i) or
  935. (unitmap[hp.moduleid].u<>hp) then
  936. internalerror(200501156);
  937. end
  938. else
  939. begin
  940. unitmap[hp.moduleid].u:=hp;
  941. unitmap[hp.moduleid].derefidx:=-1;
  942. end;
  943. inc(i);
  944. hp:=tmodule(hp.next);
  945. end;
  946. end;
  947. function tmodule.derefidx_unit(id:longint):longint;
  948. begin
  949. if id>=unitmapsize then
  950. internalerror(2005011511);
  951. if unitmap[id].derefidx=-1 then
  952. begin
  953. unitmap[id].derefidx:=derefmapcnt;
  954. inc(derefmapcnt);
  955. derefmap[unitmap[id].derefidx].u:=unitmap[id].u;
  956. end;
  957. if unitmap[id].derefidx>=derefmapsize then
  958. internalerror(2005011514);
  959. result:=unitmap[id].derefidx;
  960. end;
  961. function tmodule.resolve_unit(id:longint):tmodule;
  962. var
  963. hp : tmodule;
  964. begin
  965. if id>=derefmapsize then
  966. internalerror(200306231);
  967. result:=derefmap[id].u;
  968. if not assigned(result) then
  969. begin
  970. if not assigned(derefmap[id].modulename) or
  971. (derefmap[id].modulename^='') then
  972. internalerror(200501159);
  973. hp:=tmodule(loaded_units.first);
  974. while assigned(hp) do
  975. begin
  976. { only check for units. The main program is also
  977. as a unit in the loaded_units list. We simply need
  978. to ignore this entry (PFV) }
  979. if hp.is_unit and
  980. (hp.modulename^=derefmap[id].modulename^) then
  981. break;
  982. hp:=tmodule(hp.next);
  983. end;
  984. if not assigned(hp) then
  985. internalerror(2005011510);
  986. derefmap[id].u:=hp;
  987. result:=hp;
  988. end;
  989. end;
  990. procedure tmodule.allunitsused;
  991. var
  992. pu : tused_unit;
  993. begin
  994. pu:=tused_unit(used_units.first);
  995. while assigned(pu) do
  996. begin
  997. if assigned(pu.u.globalsymtable) then
  998. begin
  999. if unitmap[pu.u.moduleid].u<>pu.u then
  1000. internalerror(200501157);
  1001. { Give a note when the unit is not referenced, skip
  1002. this is for units with an initialization/finalization }
  1003. if (unitmap[pu.u.moduleid].refs=0) and
  1004. pu.in_uses and
  1005. ((pu.u.moduleflags * [mf_init,mf_finalize])=[]) then
  1006. CGMessagePos2(pu.unitsym.fileinfo,sym_n_unit_not_used,pu.u.realmodulename^,realmodulename^);
  1007. end;
  1008. pu:=tused_unit(pu.next);
  1009. end;
  1010. end;
  1011. procedure tmodule.end_of_parsing;
  1012. begin
  1013. { free asmdata }
  1014. if assigned(asmdata) then
  1015. begin
  1016. asmdata.free;
  1017. asmdata:=nil;
  1018. end;
  1019. { free scanner }
  1020. if assigned(scanner) then
  1021. begin
  1022. if current_scanner=tscannerfile(scanner) then
  1023. current_scanner:=nil;
  1024. tscannerfile(scanner).free;
  1025. scanner:=nil;
  1026. end;
  1027. { free symtable stack }
  1028. if assigned(symtablestack) then
  1029. begin
  1030. symtablestack.free;
  1031. symtablestack:=nil;
  1032. end;
  1033. if assigned(macrosymtablestack) then
  1034. begin
  1035. macrosymtablestack.free;
  1036. macrosymtablestack:=nil;
  1037. end;
  1038. waitingforunit.free;
  1039. waitingforunit:=nil;
  1040. localmacrosymtable.free;
  1041. localmacrosymtable:=nil;
  1042. ptrdefs.free;
  1043. ptrdefs:=nil;
  1044. arraydefs.free;
  1045. arraydefs:=nil;
  1046. procaddrdefs.free;
  1047. procaddrdefs:=nil;
  1048. {$ifdef llvm}
  1049. llvmdefs.free;
  1050. llvmdefs:=nil;
  1051. {$endif llvm}
  1052. checkforwarddefs.free;
  1053. checkforwarddefs:=nil;
  1054. tcinitcode.free;
  1055. tcinitcode:=nil;
  1056. localunitsearchpath.free;
  1057. localunitsearchpath:=nil;
  1058. localobjectsearchpath.free;
  1059. localobjectsearchpath:=nil;
  1060. localincludesearchpath.free;
  1061. localincludesearchpath:=nil;
  1062. locallibrarysearchpath.free;
  1063. locallibrarysearchpath:=nil;
  1064. localframeworksearchpath.free;
  1065. localframeworksearchpath:=nil;
  1066. end;
  1067. procedure tmodule.setmodulename(const s:string);
  1068. begin
  1069. stringdispose(modulename);
  1070. stringdispose(realmodulename);
  1071. modulename:=stringdup(upper(s));
  1072. realmodulename:=stringdup(s);
  1073. { also update asmlibrary names }
  1074. current_asmdata.name:=modulename;
  1075. end;
  1076. procedure TModule.AddExternalImport(const libname,symname,symmangledname:string;
  1077. OrdNr: longint;isvar:boolean;ImportByOrdinalOnly:boolean);
  1078. var
  1079. ImportLibrary,OtherIL : TImportLibrary;
  1080. ImportSymbol : TImportSymbol;
  1081. i : longint;
  1082. begin
  1083. ImportLibrary:=TImportLibrary(ImportLibraryList.Find(libname));
  1084. if not assigned(ImportLibrary) then
  1085. ImportLibrary:=TImportLibrary.Create(ImportLibraryList,libname);
  1086. ImportSymbol:=TImportSymbol(ImportLibrary.ImportSymbolList.Find(symname));
  1087. if not assigned(ImportSymbol) then
  1088. begin
  1089. { Check that the same name does not exist in another library }
  1090. { If it does and the same mangled name is used, issue a warning }
  1091. if ImportLibraryList.Count>1 then
  1092. for i:=0 To ImportLibraryList.Count-1 do
  1093. begin
  1094. OtherIL:=TImportLibrary(ImportLibraryList.Items[i]);
  1095. ImportSymbol:=TImportSymbol(OtherIL.ImportSymbolList.Find(symname));
  1096. if assigned(ImportSymbol) then
  1097. begin
  1098. if ImportSymbol.MangledName=symmangledname then
  1099. begin
  1100. CGMessage3(sym_w_library_overload,symname,libname,OtherIL.Name);
  1101. break;
  1102. end;
  1103. end;
  1104. end;
  1105. if not ImportByOrdinalOnly then
  1106. { negative ordinal number indicates import by name with ordinal number as hint }
  1107. OrdNr:=-OrdNr;
  1108. ImportSymbol:=TImportSymbol.Create(ImportLibrary.ImportSymbolList,
  1109. symname,symmangledname,OrdNr,isvar);
  1110. end;
  1111. end;
  1112. procedure tmodule.add_public_asmsym(sym:TAsmSymbol);
  1113. begin
  1114. add_public_asmsym(sym.name,sym.bind,sym.typ);
  1115. end;
  1116. procedure tmodule.add_public_asmsym(const name:TSymStr;bind:TAsmsymbind;typ:Tasmsymtype);
  1117. var
  1118. sym : tasmsymbol;
  1119. begin
  1120. { ToDo: check for AB_GLOBAL, AB_EXTERNAL? }
  1121. sym:=tasmsymbol(publicasmsyms.find(name));
  1122. if assigned(sym) then
  1123. begin
  1124. if (sym.bind<>bind) or (sym.typ<>typ) then
  1125. internalerror(2016070101);
  1126. exit;
  1127. end;
  1128. tasmsymbol.create(publicasmsyms,name,bind,typ);
  1129. end;
  1130. procedure tmodule.add_extern_asmsym(sym:TAsmSymbol);
  1131. begin
  1132. add_extern_asmsym(sym.name,sym.bind,sym.typ);
  1133. end;
  1134. procedure tmodule.add_extern_asmsym(const name:TSymStr;bind:TAsmsymbind;typ:Tasmsymtype);
  1135. var
  1136. sym : tasmsymbol;
  1137. begin
  1138. { ToDo: check for AB_EXTERNAL? }
  1139. sym:=tasmsymbol(externasmsyms.find(name));
  1140. if assigned(sym) then
  1141. begin
  1142. if (sym.bind<>bind) or (sym.typ<>typ) then
  1143. internalerror(2016070102);
  1144. exit;
  1145. end;
  1146. tasmsymbol.create(externasmsyms,name,bind,typ);
  1147. end;
  1148. initialization
  1149. {$ifdef MEMDEBUG}
  1150. memsymtable:=TMemDebug.create('Symtables');
  1151. memsymtable.stop;
  1152. {$endif MEMDEBUG}
  1153. finalization
  1154. {$ifdef MEMDEBUG}
  1155. memsymtable.free;
  1156. {$endif MEMDEBUG}
  1157. end.