fmodule.pas 43 KB

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