fmodule.pas 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303
  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. {create creates a new module which name is stored in 's'. LoadedFrom
  210. points to the module calling it. It is nil for the first compiled
  211. module. This allow inheritence of all path lists. MUST pay attention
  212. to that when creating link.res!!!!(mazen)}
  213. constructor create(LoadedFrom:TModule;const amodulename: string; const afilename:TPathStr;_is_unit:boolean);
  214. destructor destroy;override;
  215. procedure reset;virtual;
  216. procedure loadlocalnamespacelist;
  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. localnamespacelist:=TCmdStrList.Create;
  508. resourcefiles:=TCmdStrList.Create;
  509. linkorderedsymbols:=TCmdStrList.Create;
  510. linkunitofiles:=TLinkContainer.Create;
  511. linkunitstaticlibs:=TLinkContainer.Create;
  512. linkunitsharedlibs:=TLinkContainer.Create;
  513. linkotherofiles:=TLinkContainer.Create;
  514. linkotherstaticlibs:=TLinkContainer.Create;
  515. linkothersharedlibs:=TLinkContainer.Create;
  516. linkotherframeworks:=TLinkContainer.Create;
  517. mainname:=nil;
  518. FImportLibraryList:=TFPHashObjectList.Create(true);
  519. crc:=0;
  520. interface_crc:=0;
  521. indirect_crc:=0;
  522. headerflags:=0;
  523. longversion:=0;
  524. moduleflags:=[];
  525. scanner:=nil;
  526. unitmap:=nil;
  527. unitmapsize:=0;
  528. derefmap:=nil;
  529. derefmapsize:=0;
  530. derefmapcnt:=0;
  531. derefdata:=TDynamicArray.Create(1024);
  532. derefdataintflen:=0;
  533. deflist:=TFPObjectList.Create(false);
  534. symlist:=TFPObjectList.Create(false);
  535. ptrdefs:=THashSet.Create(64,true,false);
  536. arraydefs:=THashSet.Create(64,true,false);
  537. procaddrdefs:=THashSet.Create(64,true,false);
  538. {$ifdef llvm}
  539. llvmdefs:=THashSet.Create(64,true,false);
  540. llvmusedsyms:=TFPObjectList.Create(true);
  541. llvmcompilerusedsyms:=TFPObjectList.Create(true);
  542. llvminitprocs:=TFPList.Create;
  543. llvmfiniprocs:=TFPList.Create;
  544. llvmmetadatastrings:=TFPHashList.Create;
  545. {$endif llvm}
  546. ansistrdef:=nil;
  547. wpoinfo:=nil;
  548. checkforwarddefs:=TFPObjectList.Create(false);
  549. forwardgenericdefs:=TFPHashObjectList.Create(true);
  550. extendeddefs:=TFPHashObjectList.Create(true);
  551. genericdummysyms:=tfphashobjectlist.create(true);
  552. pendingspecializations:=tfphashobjectlist.create(false);
  553. waitingforunit:=tfpobjectlist.create(false);
  554. waitingunits:=tfpobjectlist.create(false);
  555. used_rtti_attrs:=tfpobjectlist.create(false);
  556. globalsymtable:=nil;
  557. localsymtable:=nil;
  558. globalmacrosymtable:=nil;
  559. localmacrosymtable:=nil;
  560. loaded_from:=LoadedFrom;
  561. do_reload:=false;
  562. do_compile:=false;
  563. sources_avail:=true;
  564. mainfilepos.line:=0;
  565. mainfilepos.column:=0;
  566. mainfilepos.fileindex:=0;
  567. recompile_reason:=rr_unknown;
  568. in_interface:=true;
  569. in_global:=true;
  570. is_unit:=_is_unit;
  571. islibrary:=false;
  572. ispackage:=false;
  573. change_endian:=false;
  574. is_dbginfo_written:=false;
  575. mode_switch_allowed:= true;
  576. moduleoptions:=[];
  577. deprecatedmsg:=nil;
  578. namespace:=nil;
  579. tcinitcode:=nil;
  580. _exports:=TLinkedList.Create;
  581. dllscannerinputlist:=TFPHashList.Create;
  582. asmdata:=casmdata.create(modulename);
  583. unitimportsyms:=TFPObjectList.Create(false);
  584. publicasmsyms:=TFPHashObjectList.Create(true);
  585. externasmsyms:=TFPHashObjectList.Create(true);
  586. InitDebugInfo(self,false);
  587. end;
  588. destructor tmodule.Destroy;
  589. var
  590. i : longint;
  591. current_debuginfo_reset : boolean;
  592. begin
  593. if assigned(unitmap) then
  594. freemem(unitmap);
  595. if assigned(derefmap) then
  596. begin
  597. for i:=0 to derefmapcnt-1 do
  598. stringdispose(derefmap[i].modulename);
  599. freemem(derefmap);
  600. end;
  601. if assigned(_exports) then
  602. _exports.free;
  603. if assigned(dllscannerinputlist) then
  604. dllscannerinputlist.free;
  605. if assigned(scanner) then
  606. begin
  607. { also update current_scanner if it was pointing
  608. to this module }
  609. if current_scanner=tscannerfile(scanner) then
  610. current_scanner:=nil;
  611. tscannerfile(scanner).free;
  612. end;
  613. if assigned(asmdata) then
  614. begin
  615. if current_asmdata=asmdata then
  616. current_asmdata:=nil;
  617. asmdata.free;
  618. end;
  619. if assigned(procinfo) then
  620. begin
  621. if current_procinfo=tprocinfo(procinfo) then
  622. begin
  623. current_procinfo:=nil;
  624. current_structdef:=nil;
  625. current_genericdef:=nil;
  626. current_specializedef:=nil;
  627. end;
  628. { release procinfo tree }
  629. tprocinfo(procinfo).destroy_tree;
  630. end;
  631. DoneDebugInfo(self,current_debuginfo_reset);
  632. used_units.free;
  633. dependent_units.free;
  634. resourcefiles.Free;
  635. linkorderedsymbols.Free;
  636. linkunitofiles.Free;
  637. linkunitstaticlibs.Free;
  638. linkunitsharedlibs.Free;
  639. linkotherofiles.Free;
  640. linkotherstaticlibs.Free;
  641. linkothersharedlibs.Free;
  642. linkotherframeworks.Free;
  643. stringdispose(mainname);
  644. externasmsyms.Free;
  645. publicasmsyms.Free;
  646. unitimportsyms.Free;
  647. FImportLibraryList.Free;
  648. extendeddefs.Free;
  649. genericdummysyms.free;
  650. pendingspecializations.free;
  651. waitingforunit.free;
  652. waitingunits.free;
  653. used_rtti_attrs.free;
  654. stringdispose(asmprefix);
  655. stringdispose(deprecatedmsg);
  656. stringdispose(namespace);
  657. tcinitcode.free;
  658. localunitsearchpath.Free;
  659. localobjectsearchpath.free;
  660. localincludesearchpath.free;
  661. locallibrarysearchpath.free;
  662. localframeworksearchpath.free;
  663. {$ifdef MEMDEBUG}
  664. memsymtable.start;
  665. {$endif}
  666. derefdata.free;
  667. if assigned(deflist) then
  668. begin
  669. for i:=0 to deflist.Count-1 do
  670. if assigned(deflist[i]) and
  671. (tdef(deflist[i]).registered_in_module=self) then
  672. tdef(deflist[i]).registered_in_module:=nil;
  673. deflist.free;
  674. end;
  675. symlist.free;
  676. ptrdefs.free;
  677. arraydefs.free;
  678. procaddrdefs.free;
  679. {$ifdef llvm}
  680. llvmdefs.free;
  681. llvmusedsyms.free;
  682. llvmcompilerusedsyms.free;
  683. llvminitprocs.free;
  684. llvmfiniprocs.free;
  685. llvmmetadatastrings.free;
  686. {$endif llvm}
  687. ansistrdef:=nil;
  688. wpoinfo.free;
  689. checkforwarddefs.free;
  690. forwardgenericdefs.free;
  691. globalsymtable.free;
  692. localsymtable.free;
  693. globalmacrosymtable.free;
  694. localmacrosymtable.free;
  695. {$ifdef MEMDEBUG}
  696. memsymtable.stop;
  697. {$endif}
  698. inherited Destroy;
  699. end;
  700. procedure tmodule.reset;
  701. var
  702. i : longint;
  703. current_debuginfo_reset : boolean;
  704. begin
  705. if assigned(scanner) then
  706. begin
  707. { also update current_scanner if it was pointing
  708. to this module }
  709. if current_scanner=tscannerfile(scanner) then
  710. current_scanner:=nil;
  711. tscannerfile(scanner).free;
  712. scanner:=nil;
  713. end;
  714. if assigned(procinfo) then
  715. begin
  716. if current_procinfo=tprocinfo(procinfo) then
  717. begin
  718. current_procinfo:=nil;
  719. current_structdef:=nil;
  720. current_genericdef:=nil;
  721. current_specializedef:=nil;
  722. end;
  723. { release procinfo tree }
  724. tprocinfo(procinfo).destroy_tree;
  725. end;
  726. if assigned(asmdata) then
  727. begin
  728. if current_asmdata=asmdata then
  729. current_asmdata:=nil;
  730. asmdata.free;
  731. asmdata:=nil;
  732. end;
  733. DoneDebugInfo(self,current_debuginfo_reset);
  734. globalsymtable.free;
  735. globalsymtable:=nil;
  736. localsymtable.free;
  737. localsymtable:=nil;
  738. globalmacrosymtable.free;
  739. globalmacrosymtable:=nil;
  740. localmacrosymtable.free;
  741. localmacrosymtable:=nil;
  742. deflist.free;
  743. deflist:=TFPObjectList.Create(false);
  744. symlist.free;
  745. symlist:=TFPObjectList.Create(false);
  746. ptrdefs.free;
  747. ptrdefs:=THashSet.Create(64,true,false);
  748. arraydefs.free;
  749. arraydefs:=THashSet.Create(64,true,false);
  750. procaddrdefs.free;
  751. procaddrdefs:=THashSet.Create(64,true,false);
  752. {$ifdef llvm}
  753. llvmdefs.free;
  754. llvmdefs:=THashSet.Create(64,true,false);
  755. llvmusedsyms.free;
  756. llvmusedsyms:=TFPObjectList.Create(true);
  757. llvmcompilerusedsyms.free;
  758. llvmcompilerusedsyms:=TFPObjectList.Create(true);
  759. llvminitprocs.free;
  760. llvminitprocs:=TFPList.Create;
  761. llvmfiniprocs.free;
  762. llvmfiniprocs:=TFPList.Create;
  763. llvmmetadatastrings.free;
  764. llvmmetadatastrings:=TFPHashList.Create;
  765. {$endif llvm}
  766. wpoinfo.free;
  767. wpoinfo:=nil;
  768. checkforwarddefs.free;
  769. checkforwarddefs:=TFPObjectList.Create(false);
  770. forwardgenericdefs.free;
  771. forwardgenericdefs:=TFPHashObjectList.Create(true);
  772. publicasmsyms.free;
  773. publicasmsyms:=TFPHashObjectList.Create(true);
  774. externasmsyms.free;
  775. externasmsyms:=TFPHashObjectList.Create(true);
  776. unitimportsyms.free;
  777. unitimportsyms:=TFPObjectList.Create(false);
  778. derefdata.free;
  779. derefdata:=TDynamicArray.Create(1024);
  780. if assigned(unitmap) then
  781. begin
  782. freemem(unitmap);
  783. unitmap:=nil;
  784. end;
  785. if assigned(derefmap) then
  786. begin
  787. for i:=0 to derefmapcnt-1 do
  788. stringdispose(derefmap[i].modulename);
  789. freemem(derefmap);
  790. derefmap:=nil;
  791. end;
  792. unitmapsize:=0;
  793. derefmapsize:=0;
  794. derefmapcnt:=0;
  795. derefdataintflen:=0;
  796. sourcefiles.free;
  797. sourcefiles:=tinputfilemanager.create;
  798. asmdata:=casmdata.create(modulename);
  799. InitDebugInfo(self,current_debuginfo_reset);
  800. _exports.free;
  801. _exports:=tlinkedlist.create;
  802. dllscannerinputlist.free;
  803. dllscannerinputlist:=TFPHashList.create;
  804. used_units.free;
  805. used_units:=TLinkedList.Create;
  806. dependent_units.free;
  807. dependent_units:=TLinkedList.Create;
  808. resourcefiles.Free;
  809. resourcefiles:=TCmdStrList.Create;
  810. linkorderedsymbols.Free;
  811. linkorderedsymbols:=TCmdStrList.Create;
  812. pendingspecializations.free;
  813. pendingspecializations:=tfphashobjectlist.create(false);
  814. if assigned(waitingforunit) and
  815. (waitingforunit.count<>0) then
  816. internalerror(2016070501);
  817. waitingforunit.free;
  818. waitingforunit:=tfpobjectlist.create(false);
  819. linkunitofiles.Free;
  820. linkunitofiles:=TLinkContainer.Create;
  821. linkunitstaticlibs.Free;
  822. linkunitstaticlibs:=TLinkContainer.Create;
  823. linkunitsharedlibs.Free;
  824. linkunitsharedlibs:=TLinkContainer.Create;
  825. linkotherofiles.Free;
  826. linkotherofiles:=TLinkContainer.Create;
  827. linkotherstaticlibs.Free;
  828. linkotherstaticlibs:=TLinkContainer.Create;
  829. linkothersharedlibs.Free;
  830. linkothersharedlibs:=TLinkContainer.Create;
  831. linkotherframeworks.Free;
  832. linkotherframeworks:=TLinkContainer.Create;
  833. stringdispose(mainname);
  834. FImportLibraryList.Free;
  835. FImportLibraryList:=TFPHashObjectList.Create;
  836. do_compile:=false;
  837. do_reload:=false;
  838. interface_compiled:=false;
  839. in_interface:=true;
  840. in_global:=true;
  841. mode_switch_allowed:=true;
  842. stringdispose(deprecatedmsg);
  843. stringdispose(namespace);
  844. tcinitcode.free;
  845. tcinitcode:=nil;
  846. localunitsearchpath.Free;
  847. localunitsearchpath:=TSearchPathList.Create;
  848. localobjectsearchpath.free;
  849. localobjectsearchpath:=TSearchPathList.Create;
  850. localincludesearchpath.free;
  851. localincludesearchpath:=TSearchPathList.Create;
  852. locallibrarysearchpath.free;
  853. locallibrarysearchpath:=TSearchPathList.Create;
  854. localframeworksearchpath.free;
  855. localframeworksearchpath:=TSearchPathList.Create;
  856. moduleoptions:=[];
  857. is_dbginfo_written:=false;
  858. crc:=0;
  859. interface_crc:=0;
  860. indirect_crc:=0;
  861. headerflags:=0;
  862. longversion:=0;
  863. moduleflags:=[];
  864. mainfilepos.line:=0;
  865. mainfilepos.column:=0;
  866. mainfilepos.fileindex:=0;
  867. recompile_reason:=rr_unknown;
  868. {
  869. The following fields should not
  870. be reset:
  871. mainsource
  872. state
  873. loaded_from
  874. sources_avail
  875. }
  876. end;
  877. procedure tmodule.loadlocalnamespacelist;
  878. var
  879. nsitem : TCmdStrListItem;
  880. begin
  881. // Copying local namespace list
  882. if premodule_namespacelist.Count>0 then
  883. begin
  884. nsitem:=TCmdStrListItem(premodule_namespacelist.First);
  885. while assigned(nsItem) do
  886. begin
  887. localnamespacelist.Concat(nsitem.Str);
  888. nsItem:=TCmdStrListItem(nsitem.Next);
  889. end;
  890. premodule_namespacelist.Clear;
  891. end;
  892. current_namespacelist:=localnamespacelist;
  893. end;
  894. procedure tmodule.adddependency(callermodule:tmodule);
  895. begin
  896. { This is not needed for programs }
  897. if not callermodule.is_unit then
  898. exit;
  899. Message2(unit_u_add_depend_to,callermodule.modulename^,modulename^);
  900. dependent_units.concat(tdependent_unit.create(callermodule));
  901. end;
  902. procedure tmodule.flagdependent(callermodule:tmodule);
  903. var
  904. pm : tdependent_unit;
  905. begin
  906. { flag all units that depend on this unit for reloading }
  907. pm:=tdependent_unit(current_module.dependent_units.first);
  908. while assigned(pm) do
  909. begin
  910. { We do not have to reload the unit that wants to load
  911. this unit, unless this unit is already compiled during
  912. the loading }
  913. if (pm.u=callermodule) and
  914. (pm.u.state<>ms_compiled) then
  915. Message1(unit_u_no_reload_is_caller,pm.u.modulename^)
  916. else
  917. if pm.u.state=ms_second_compile then
  918. Message1(unit_u_no_reload_in_second_compile,pm.u.modulename^)
  919. else
  920. begin
  921. pm.u.do_reload:=true;
  922. Message1(unit_u_flag_for_reload,pm.u.modulename^);
  923. end;
  924. pm:=tdependent_unit(pm.next);
  925. end;
  926. end;
  927. procedure tmodule.addimportedsym(sym:TSymEntry);
  928. begin
  929. if unitimportsyms.IndexOf(sym)<0 then
  930. unitimportsyms.Add(sym);
  931. end;
  932. function tmodule.addusedunit(hp:tmodule;inuses:boolean;usym:tunitsym):tused_unit;
  933. var
  934. pu : tused_unit;
  935. begin
  936. pu:=tused_unit.create(hp,in_interface,inuses,usym);
  937. used_units.concat(pu);
  938. addusedunit:=pu;
  939. end;
  940. procedure tmodule.updatemaps;
  941. var
  942. oldmapsize : longint;
  943. hp : tmodule;
  944. i : longint;
  945. begin
  946. { Extend unitmap }
  947. oldmapsize:=unitmapsize;
  948. unitmapsize:=loaded_units.count;
  949. reallocmem(unitmap,unitmapsize*sizeof(tunitmaprec));
  950. fillchar(unitmap[oldmapsize],(unitmapsize-oldmapsize)*sizeof(tunitmaprec),0);
  951. { Extend Derefmap }
  952. oldmapsize:=derefmapsize;
  953. derefmapsize:=loaded_units.count;
  954. reallocmem(derefmap,derefmapsize*sizeof(tderefmaprec));
  955. fillchar(derefmap[oldmapsize],(derefmapsize-oldmapsize)*sizeof(tderefmaprec),0);
  956. { Add all units to unitmap }
  957. hp:=tmodule(loaded_units.first);
  958. i:=0;
  959. while assigned(hp) do
  960. begin
  961. if hp.moduleid>=unitmapsize then
  962. internalerror(200501151);
  963. { Verify old entries }
  964. if (i<oldmapsize) then
  965. begin
  966. if (hp.moduleid<>i) or
  967. (unitmap[hp.moduleid].u<>hp) then
  968. internalerror(200501156);
  969. end
  970. else
  971. begin
  972. unitmap[hp.moduleid].u:=hp;
  973. unitmap[hp.moduleid].derefidx:=-1;
  974. end;
  975. inc(i);
  976. hp:=tmodule(hp.next);
  977. end;
  978. end;
  979. function tmodule.derefidx_unit(id:longint):longint;
  980. begin
  981. if id>=unitmapsize then
  982. internalerror(2005011511);
  983. if unitmap[id].derefidx=-1 then
  984. begin
  985. unitmap[id].derefidx:=derefmapcnt;
  986. inc(derefmapcnt);
  987. derefmap[unitmap[id].derefidx].u:=unitmap[id].u;
  988. end;
  989. if unitmap[id].derefidx>=derefmapsize then
  990. internalerror(2005011514);
  991. result:=unitmap[id].derefidx;
  992. end;
  993. function tmodule.resolve_unit(id:longint):tmodule;
  994. var
  995. hp : tmodule;
  996. begin
  997. if id>=derefmapsize then
  998. internalerror(200306231);
  999. result:=derefmap[id].u;
  1000. if not assigned(result) then
  1001. begin
  1002. if not assigned(derefmap[id].modulename) or
  1003. (derefmap[id].modulename^='') then
  1004. internalerror(200501159);
  1005. hp:=tmodule(loaded_units.first);
  1006. while assigned(hp) do
  1007. begin
  1008. { only check for units. The main program is also
  1009. as a unit in the loaded_units list. We simply need
  1010. to ignore this entry (PFV) }
  1011. if hp.is_unit and
  1012. (hp.modulename^=derefmap[id].modulename^) then
  1013. break;
  1014. hp:=tmodule(hp.next);
  1015. end;
  1016. if not assigned(hp) then
  1017. internalerror(2005011510);
  1018. derefmap[id].u:=hp;
  1019. result:=hp;
  1020. end;
  1021. end;
  1022. procedure tmodule.allunitsused;
  1023. var
  1024. pu : tused_unit;
  1025. begin
  1026. pu:=tused_unit(used_units.first);
  1027. while assigned(pu) do
  1028. begin
  1029. if assigned(pu.u.globalsymtable) then
  1030. begin
  1031. if unitmap[pu.u.moduleid].u<>pu.u then
  1032. internalerror(200501157);
  1033. { Give a note when the unit is not referenced, skip
  1034. this is for units with an initialization/finalization }
  1035. if (unitmap[pu.u.moduleid].refs=0) and
  1036. pu.in_uses and
  1037. ((pu.u.moduleflags * [mf_init,mf_finalize])=[]) then
  1038. CGMessagePos2(pu.unitsym.fileinfo,sym_n_unit_not_used,pu.u.realmodulename^,realmodulename^);
  1039. end;
  1040. pu:=tused_unit(pu.next);
  1041. end;
  1042. end;
  1043. procedure tmodule.end_of_parsing;
  1044. begin
  1045. { free asmdata }
  1046. if assigned(asmdata) then
  1047. begin
  1048. asmdata.free;
  1049. asmdata:=nil;
  1050. end;
  1051. { free scanner }
  1052. if assigned(scanner) then
  1053. begin
  1054. if current_scanner=tscannerfile(scanner) then
  1055. current_scanner:=nil;
  1056. tscannerfile(scanner).free;
  1057. scanner:=nil;
  1058. end;
  1059. { free symtable stack }
  1060. if assigned(symtablestack) then
  1061. begin
  1062. symtablestack.free;
  1063. symtablestack:=nil;
  1064. end;
  1065. if assigned(macrosymtablestack) then
  1066. begin
  1067. macrosymtablestack.free;
  1068. macrosymtablestack:=nil;
  1069. end;
  1070. waitingforunit.free;
  1071. waitingforunit:=nil;
  1072. localmacrosymtable.free;
  1073. localmacrosymtable:=nil;
  1074. ptrdefs.free;
  1075. ptrdefs:=nil;
  1076. arraydefs.free;
  1077. arraydefs:=nil;
  1078. procaddrdefs.free;
  1079. procaddrdefs:=nil;
  1080. {$ifdef llvm}
  1081. llvmdefs.free;
  1082. llvmdefs:=nil;
  1083. {$endif llvm}
  1084. checkforwarddefs.free;
  1085. checkforwarddefs:=nil;
  1086. tcinitcode.free;
  1087. tcinitcode:=nil;
  1088. localunitsearchpath.free;
  1089. localunitsearchpath:=nil;
  1090. localobjectsearchpath.free;
  1091. localobjectsearchpath:=nil;
  1092. localincludesearchpath.free;
  1093. localincludesearchpath:=nil;
  1094. locallibrarysearchpath.free;
  1095. locallibrarysearchpath:=nil;
  1096. localframeworksearchpath.free;
  1097. localframeworksearchpath:=nil;
  1098. end;
  1099. procedure tmodule.setmodulename(const s:string);
  1100. begin
  1101. stringdispose(modulename);
  1102. stringdispose(realmodulename);
  1103. modulename:=stringdup(upper(s));
  1104. realmodulename:=stringdup(s);
  1105. { also update asmlibrary names }
  1106. current_asmdata.name:=modulename;
  1107. end;
  1108. procedure TModule.AddExternalImport(const libname,symname,symmangledname:string;
  1109. OrdNr: longint;isvar:boolean;ImportByOrdinalOnly:boolean);
  1110. var
  1111. ImportLibrary,OtherIL : TImportLibrary;
  1112. ImportSymbol : TImportSymbol;
  1113. i : longint;
  1114. begin
  1115. ImportLibrary:=TImportLibrary(ImportLibraryList.Find(libname));
  1116. if not assigned(ImportLibrary) then
  1117. ImportLibrary:=TImportLibrary.Create(ImportLibraryList,libname);
  1118. ImportSymbol:=TImportSymbol(ImportLibrary.ImportSymbolList.Find(symname));
  1119. if not assigned(ImportSymbol) then
  1120. begin
  1121. { Check that the same name does not exist in another library }
  1122. { If it does and the same mangled name is used, issue a warning }
  1123. if ImportLibraryList.Count>1 then
  1124. for i:=0 To ImportLibraryList.Count-1 do
  1125. begin
  1126. OtherIL:=TImportLibrary(ImportLibraryList.Items[i]);
  1127. ImportSymbol:=TImportSymbol(OtherIL.ImportSymbolList.Find(symname));
  1128. if assigned(ImportSymbol) then
  1129. begin
  1130. if ImportSymbol.MangledName=symmangledname then
  1131. begin
  1132. CGMessage3(sym_w_library_overload,symname,libname,OtherIL.Name);
  1133. break;
  1134. end;
  1135. end;
  1136. end;
  1137. if not ImportByOrdinalOnly then
  1138. { negative ordinal number indicates import by name with ordinal number as hint }
  1139. OrdNr:=-OrdNr;
  1140. ImportSymbol:=TImportSymbol.Create(ImportLibrary.ImportSymbolList,
  1141. symname,symmangledname,OrdNr,isvar);
  1142. end;
  1143. end;
  1144. procedure tmodule.add_public_asmsym(sym:TAsmSymbol);
  1145. begin
  1146. add_public_asmsym(sym.name,sym.bind,sym.typ);
  1147. end;
  1148. procedure tmodule.add_public_asmsym(const name:TSymStr;bind:TAsmsymbind;typ:Tasmsymtype);
  1149. var
  1150. sym : tasmsymbol;
  1151. begin
  1152. { ToDo: check for AB_GLOBAL, AB_EXTERNAL? }
  1153. sym:=tasmsymbol(publicasmsyms.find(name));
  1154. if assigned(sym) then
  1155. begin
  1156. if (sym.bind<>bind) or (sym.typ<>typ) then
  1157. internalerror(2016070101);
  1158. exit;
  1159. end;
  1160. tasmsymbol.create(publicasmsyms,name,bind,typ);
  1161. end;
  1162. procedure tmodule.add_extern_asmsym(sym:TAsmSymbol);
  1163. begin
  1164. add_extern_asmsym(sym.name,sym.bind,sym.typ);
  1165. end;
  1166. procedure tmodule.add_extern_asmsym(const name:TSymStr;bind:TAsmsymbind;typ:Tasmsymtype);
  1167. var
  1168. sym : tasmsymbol;
  1169. begin
  1170. { ToDo: check for AB_EXTERNAL? }
  1171. sym:=tasmsymbol(externasmsyms.find(name));
  1172. if assigned(sym) then
  1173. begin
  1174. if (sym.bind<>bind) or (sym.typ<>typ) then
  1175. internalerror(2016070102);
  1176. exit;
  1177. end;
  1178. tasmsymbol.create(externasmsyms,name,bind,typ);
  1179. end;
  1180. initialization
  1181. {$ifdef MEMDEBUG}
  1182. memsymtable:=TMemDebug.create('Symtables');
  1183. memsymtable.stop;
  1184. {$endif MEMDEBUG}
  1185. finalization
  1186. {$ifdef MEMDEBUG}
  1187. memsymtable.free;
  1188. {$endif MEMDEBUG}
  1189. end.