fmodule.pas 44 KB

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