fmodule.pas 44 KB

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