fppu.pas 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956
  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 fppu;
  18. {$i fpcdefs.inc}
  19. { $define DEBUG_UNIT_CRC_CHANGES}
  20. { close ppufiles on system that are
  21. short on file handles like DOS system PM }
  22. {$ifdef GO32V2}
  23. {$define SHORT_ON_FILE_HANDLES}
  24. {$endif GO32V2}
  25. {$ifdef WATCOM}
  26. {$define SHORT_ON_FILE_HANDLES}
  27. {$endif WATCOM}
  28. interface
  29. uses
  30. cmsgs,verbose,
  31. cutils,cclasses,cstreams,
  32. globtype,globals,finput,fmodule,
  33. symbase,ppu,symtype;
  34. type
  35. { tppumodule }
  36. tppumodule = class(tmodule)
  37. ppufile : tcompilerppufile; { the PPU file }
  38. sourcefn : TPathStr; { Source specified with "uses .. in '..'" }
  39. comments : TCmdStrList;
  40. {$ifdef Test_Double_checksum}
  41. crc_array : pointer;
  42. crc_size : longint;
  43. crc_array2 : pointer;
  44. crc_size2 : longint;
  45. {$endif def Test_Double_checksum}
  46. constructor create(LoadedFrom:TModule;const amodulename: string; const afilename:TPathStr;_is_unit:boolean);
  47. destructor destroy;override;
  48. procedure reset;override;
  49. function openppufile:boolean;
  50. function openppustream(strm:TCStream):boolean;
  51. procedure getppucrc;
  52. procedure writeppu;
  53. procedure loadppu;
  54. function needrecompile:boolean;
  55. procedure setdefgeneration;
  56. procedure reload_flagged_units;
  57. procedure end_of_parsing;override;
  58. private
  59. { Each time a unit's defs are (re)created, its defsgeneration is
  60. set to the value of a global counter, and the global counter is
  61. increased. We only reresolve its dependent units' defs in case
  62. they have been resolved only for an older generation, in order to
  63. avoid endless resolving loops in case of cyclic dependencies. }
  64. defsgeneration : longint;
  65. function openppu(ppufiletime:longint):boolean;
  66. function search_unit_files(onlysource:boolean):boolean;
  67. function search_unit(onlysource,shortname:boolean):boolean;
  68. function loadfrompackage:boolean;
  69. procedure load_interface;
  70. procedure load_implementation;
  71. procedure load_usedunits;
  72. procedure printcomments;
  73. procedure queuecomment(const s:TMsgStr;v,w:longint);
  74. procedure writesourcefiles;
  75. procedure writeusedunit(intf:boolean);
  76. procedure writelinkcontainer(var p:tlinkcontainer;id:byte;strippath:boolean);
  77. procedure writederefmap;
  78. procedure writederefdata;
  79. procedure writeImportSymbols;
  80. procedure writeResources;
  81. procedure readsourcefiles;
  82. procedure readloadunit;
  83. procedure readlinkcontainer(var p:tlinkcontainer);
  84. procedure readderefmap;
  85. procedure readderefdata;
  86. procedure readImportSymbols;
  87. procedure readResources;
  88. procedure readwpofile;
  89. {$IFDEF MACRO_DIFF_HINT}
  90. procedure writeusedmacro(p:TNamedIndexItem;arg:pointer);
  91. procedure writeusedmacros;
  92. procedure readusedmacros;
  93. {$ENDIF}
  94. end;
  95. function registerunit(callermodule:tmodule;const s : TIDString;const fn:string) : tppumodule;
  96. implementation
  97. uses
  98. SysUtils,
  99. cfileutl,
  100. systems,version,
  101. symtable, symsym,
  102. wpoinfo,
  103. scanner,
  104. aasmbase,ogbase,
  105. parser,
  106. comphook,
  107. entfile,fpkg;
  108. var
  109. currentdefgeneration: longint;
  110. {****************************************************************************
  111. TPPUMODULE
  112. ****************************************************************************}
  113. constructor tppumodule.create(LoadedFrom:TModule;const amodulename: string; const afilename:TPathStr;_is_unit:boolean);
  114. begin
  115. inherited create(LoadedFrom,amodulename,afilename,_is_unit);
  116. ppufile:=nil;
  117. sourcefn:=afilename;
  118. end;
  119. destructor tppumodule.Destroy;
  120. begin
  121. if assigned(ppufile) then
  122. ppufile.free;
  123. ppufile:=nil;
  124. comments.free;
  125. comments:=nil;
  126. inherited Destroy;
  127. end;
  128. procedure tppumodule.reset;
  129. begin
  130. inc(currentdefgeneration);
  131. if assigned(ppufile) then
  132. begin
  133. ppufile.free;
  134. ppufile:=nil;
  135. end;
  136. inherited reset;
  137. end;
  138. procedure tppumodule.queuecomment(const s:TMsgStr;v,w:longint);
  139. begin
  140. if comments = nil then
  141. comments := TCmdStrList.create;
  142. comments.insert(s);
  143. end;
  144. procedure tppumodule.printcomments;
  145. var
  146. comment: string;
  147. begin
  148. if comments = nil then
  149. exit;
  150. { comments are inserted in reverse order }
  151. repeat
  152. comment := comments.getlast;
  153. if length(comment) = 0 then
  154. exit;
  155. do_comment(v_normal, comment);
  156. until false;
  157. end;
  158. function tppumodule.openppufile:boolean;
  159. var
  160. ppufiletime : longint;
  161. begin
  162. openppufile:=false;
  163. Message1(unit_t_ppu_loading,ppufilename,@queuecomment);
  164. { Get ppufile time (also check if the file exists) }
  165. ppufiletime:=getnamedfiletime(ppufilename);
  166. if ppufiletime=-1 then
  167. exit;
  168. { Open the ppufile }
  169. Message1(unit_u_ppu_name,ppufilename);
  170. ppufile:=tcompilerppufile.create(ppufilename);
  171. if not ppufile.openfile then
  172. begin
  173. ppufile.free;
  174. ppufile:=nil;
  175. Message(unit_u_ppu_file_too_short);
  176. exit;
  177. end;
  178. result:=openppu(ppufiletime);
  179. end;
  180. function tppumodule.openppustream(strm:TCStream):boolean;
  181. begin
  182. result:=false;
  183. { Open the ppufile }
  184. Message1(unit_u_ppu_name,ppufilename);
  185. ppufile:=tcompilerppufile.create(ppufilename);
  186. if not ppufile.openstream(strm) then
  187. begin
  188. ppufile.free;
  189. ppufile:=nil;
  190. Message(unit_u_ppu_file_too_short);
  191. exit;
  192. end;
  193. result:=openppu(-1);
  194. end;
  195. function tppumodule.openppu(ppufiletime:longint):boolean;
  196. begin
  197. openppu:=false;
  198. { check for a valid PPU file }
  199. if not ppufile.CheckPPUId then
  200. begin
  201. ppufile.free;
  202. ppufile:=nil;
  203. Message(unit_u_ppu_invalid_header);
  204. exit;
  205. end;
  206. { check for allowed PPU versions }
  207. if not (ppufile.getversion = CurrentPPUVersion) then
  208. begin
  209. Message1(unit_u_ppu_invalid_version,tostr(ppufile.getversion),@queuecomment);
  210. ppufile.free;
  211. ppufile:=nil;
  212. exit;
  213. end;
  214. { check the target processor }
  215. if tsystemcpu(ppufile.header.common.cpu)<>target_cpu then
  216. begin
  217. ppufile.free;
  218. ppufile:=nil;
  219. Message(unit_u_ppu_invalid_processor,@queuecomment);
  220. exit;
  221. end;
  222. { check target }
  223. if tsystem(ppufile.header.common.target)<>target_info.system then
  224. begin
  225. ppufile.free;
  226. ppufile:=nil;
  227. Message(unit_u_ppu_invalid_target,@queuecomment);
  228. exit;
  229. end;
  230. {$ifdef i8086}
  231. { check i8086 memory model flags }
  232. if ((ppufile.header.common.flags and uf_i8086_far_code)<>0) xor
  233. (current_settings.x86memorymodel in [mm_medium,mm_large,mm_huge]) then
  234. begin
  235. ppufile.free;
  236. ppufile:=nil;
  237. Message(unit_u_ppu_invalid_memory_model,@queuecomment);
  238. exit;
  239. end;
  240. if ((ppufile.header.common.flags and uf_i8086_far_data)<>0) xor
  241. (current_settings.x86memorymodel in [mm_compact,mm_large]) then
  242. begin
  243. ppufile.free;
  244. ppufile:=nil;
  245. Message(unit_u_ppu_invalid_memory_model,@queuecomment);
  246. exit;
  247. end;
  248. if ((ppufile.header.common.flags and uf_i8086_huge_data)<>0) xor
  249. (current_settings.x86memorymodel=mm_huge) then
  250. begin
  251. ppufile.free;
  252. ppufile:=nil;
  253. Message(unit_u_ppu_invalid_memory_model,@queuecomment);
  254. exit;
  255. end;
  256. if ((ppufile.header.common.flags and uf_i8086_cs_equals_ds)<>0) xor
  257. (current_settings.x86memorymodel=mm_tiny) then
  258. begin
  259. ppufile.free;
  260. ppufile:=nil;
  261. Message(unit_u_ppu_invalid_memory_model,@queuecomment);
  262. exit;
  263. end;
  264. {$endif i8086}
  265. {$ifdef cpufpemu}
  266. { check if floating point emulation is on?
  267. fpu emulation isn't unit levelwise because it affects calling convention }
  268. if ((ppufile.header.common.flags and uf_fpu_emulation)<>0) xor
  269. (cs_fp_emulation in current_settings.moduleswitches) then
  270. begin
  271. ppufile.free;
  272. ppufile:=nil;
  273. Message(unit_u_ppu_invalid_fpumode,@queuecomment);
  274. exit;
  275. end;
  276. {$endif cpufpemu}
  277. { Load values to be access easier }
  278. flags:=ppufile.header.common.flags;
  279. crc:=ppufile.header.checksum;
  280. interface_crc:=ppufile.header.interface_checksum;
  281. indirect_crc:=ppufile.header.indirect_checksum;
  282. { Show Debug info }
  283. if ppufiletime<>-1 then
  284. Message1(unit_u_ppu_time,filetimestring(ppufiletime))
  285. else
  286. Message1(unit_u_ppu_time,'unknown');
  287. Message1(unit_u_ppu_flags,tostr(flags));
  288. Message1(unit_u_ppu_crc,hexstr(ppufile.header.checksum,8));
  289. Message1(unit_u_ppu_crc,hexstr(ppufile.header.interface_checksum,8)+' (intfc)');
  290. Message1(unit_u_ppu_crc,hexstr(ppufile.header.indirect_checksum,8)+' (indc)');
  291. Comment(V_used,'Number of definitions: '+tostr(ppufile.header.deflistsize));
  292. Comment(V_used,'Number of symbols: '+tostr(ppufile.header.symlistsize));
  293. do_compile:=false;
  294. openppu:=true;
  295. end;
  296. function tppumodule.search_unit_files(onlysource:boolean):boolean;
  297. var
  298. found : boolean;
  299. begin
  300. found:=false;
  301. if search_unit(onlysource,false) then
  302. found:=true;
  303. if (not found) and
  304. (length(modulename^)>8) and
  305. search_unit(onlysource,true) then
  306. found:=true;
  307. search_unit_files:=found;
  308. end;
  309. function tppumodule.search_unit(onlysource,shortname:boolean):boolean;
  310. var
  311. singlepathstring,
  312. filename : TCmdStr;
  313. Function UnitExists(const ext:string;var foundfile:TCmdStr):boolean;
  314. begin
  315. if CheckVerbosity(V_Tried) then
  316. Message1(unit_t_unitsearch,Singlepathstring+filename+ext);
  317. UnitExists:=FindFile(FileName+ext,Singlepathstring,true,foundfile);
  318. end;
  319. Function PPUSearchPath(const s:TCmdStr):boolean;
  320. var
  321. found : boolean;
  322. hs : TCmdStr;
  323. begin
  324. Found:=false;
  325. singlepathstring:=FixPath(s,false);
  326. { Check for PPU file }
  327. Found:=UnitExists(target_info.unitext,hs);
  328. if Found then
  329. Begin
  330. SetFileName(hs,false);
  331. Found:=openppufile;
  332. End;
  333. PPUSearchPath:=Found;
  334. end;
  335. Function SourceSearchPath(const s:TCmdStr):boolean;
  336. var
  337. found : boolean;
  338. hs : TCmdStr;
  339. begin
  340. Found:=false;
  341. singlepathstring:=FixPath(s,false);
  342. { Check for Sources }
  343. ppufile:=nil;
  344. do_compile:=true;
  345. recompile_reason:=rr_noppu;
  346. {Check for .pp file}
  347. Found:=UnitExists(sourceext,hs);
  348. if not Found then
  349. begin
  350. { Check for .pas }
  351. Found:=UnitExists(pasext,hs);
  352. end;
  353. if not Found and
  354. ((m_mac in current_settings.modeswitches) or
  355. (tf_p_ext_support in target_info.flags)) then
  356. begin
  357. { Check for .p, if mode is macpas}
  358. Found:=UnitExists(pext,hs);
  359. end;
  360. mainsource:='';
  361. if Found then
  362. begin
  363. sources_avail:=true;
  364. { Load Filenames when found }
  365. mainsource:=hs;
  366. SetFileName(hs,false);
  367. end
  368. else
  369. sources_avail:=false;
  370. SourceSearchPath:=Found;
  371. end;
  372. Function SearchPath(const s:TCmdStr):boolean;
  373. var
  374. found : boolean;
  375. begin
  376. { First check for a ppu, then for the source }
  377. found:=false;
  378. if not onlysource then
  379. found:=PPUSearchPath(s);
  380. if not found then
  381. found:=SourceSearchPath(s);
  382. SearchPath:=found;
  383. end;
  384. Function SearchPathList(list:TSearchPathList):boolean;
  385. var
  386. hp : TCmdStrListItem;
  387. found : boolean;
  388. begin
  389. found:=false;
  390. hp:=TCmdStrListItem(list.First);
  391. while assigned(hp) do
  392. begin
  393. found:=SearchPath(hp.Str);
  394. if found then
  395. break;
  396. hp:=TCmdStrListItem(hp.next);
  397. end;
  398. SearchPathList:=found;
  399. end;
  400. var
  401. fnd : boolean;
  402. hs : TPathStr;
  403. begin
  404. if shortname then
  405. filename:=FixFileName(Copy(realmodulename^,1,8))
  406. else
  407. filename:=FixFileName(realmodulename^);
  408. { try to find unit
  409. 1. look for ppu in cwd
  410. 2. look for ppu in outputpath if set, this is tp7 compatible (PFV)
  411. 3. look for ppu in maindir
  412. 4. look for the specified source file (from the uses line)
  413. 5. look for source in cwd
  414. 6. look for source in maindir
  415. 7. local unit pathlist
  416. 8. global unit pathlist }
  417. fnd:=false;
  418. if not onlysource then
  419. begin
  420. fnd:=PPUSearchPath('.');
  421. if (not fnd) and (outputpath<>'') then
  422. fnd:=PPUSearchPath(outputpath);
  423. if (not fnd) and Assigned(main_module) and (main_module.Path<>'') then
  424. fnd:=PPUSearchPath(main_module.Path);
  425. end;
  426. if (not fnd) and (sourcefn<>'') then
  427. begin
  428. { the full filename is specified so we can't use here the
  429. searchpath (PFV) }
  430. if CheckVerbosity(V_Tried) then
  431. Message1(unit_t_unitsearch,ChangeFileExt(sourcefn,sourceext));
  432. fnd:=FindFile(ChangeFileExt(sourcefn,sourceext),'',true,hs);
  433. if not fnd then
  434. begin
  435. if CheckVerbosity(V_Tried) then
  436. Message1(unit_t_unitsearch,ChangeFileExt(sourcefn,pasext));
  437. fnd:=FindFile(ChangeFileExt(sourcefn,pasext),'',true,hs);
  438. end;
  439. if not fnd and
  440. ((m_mac in current_settings.modeswitches) or
  441. (tf_p_ext_support in target_info.flags)) then
  442. begin
  443. if CheckVerbosity(V_Tried) then
  444. Message1(unit_t_unitsearch,ChangeFileExt(sourcefn,pext));
  445. fnd:=FindFile(ChangeFileExt(sourcefn,pext),'',true,hs);
  446. end;
  447. if fnd then
  448. begin
  449. sources_avail:=true;
  450. do_compile:=true;
  451. recompile_reason:=rr_noppu;
  452. mainsource:=hs;
  453. SetFileName(hs,false);
  454. end;
  455. end;
  456. if not fnd then
  457. fnd:=SourceSearchPath('.');
  458. if (not fnd) and Assigned(main_module) and (main_module.Path<>'') then
  459. fnd:=SourceSearchPath(main_module.Path);
  460. if (not fnd) and Assigned(loaded_from) then
  461. fnd:=SearchPathList(loaded_from.LocalUnitSearchPath);
  462. if not fnd then
  463. fnd:=SearchPathList(UnitSearchPath);
  464. search_unit:=fnd;
  465. end;
  466. function tppumodule.loadfrompackage: boolean;
  467. var
  468. singlepathstring,
  469. filename : TCmdStr;
  470. Function UnitExists(const ext:string;var foundfile:TCmdStr):boolean;
  471. begin
  472. if CheckVerbosity(V_Tried) then
  473. Message1(unit_t_unitsearch,Singlepathstring+filename);
  474. UnitExists:=FindFile(FileName,Singlepathstring,true,foundfile);
  475. end;
  476. Function PPUSearchPath(const s:TCmdStr):boolean;
  477. var
  478. found : boolean;
  479. hs : TCmdStr;
  480. begin
  481. Found:=false;
  482. singlepathstring:=FixPath(s,false);
  483. { Check for PPU file }
  484. Found:=UnitExists(target_info.unitext,hs);
  485. if Found then
  486. Begin
  487. SetFileName(hs,false);
  488. Found:=openppufile;
  489. End;
  490. PPUSearchPath:=Found;
  491. end;
  492. Function SearchPathList(list:TSearchPathList):boolean;
  493. var
  494. hp : TCmdStrListItem;
  495. found : boolean;
  496. begin
  497. found:=false;
  498. hp:=TCmdStrListItem(list.First);
  499. while assigned(hp) do
  500. begin
  501. found:=PPUSearchPath(hp.Str);
  502. if found then
  503. break;
  504. hp:=TCmdStrListItem(hp.next);
  505. end;
  506. SearchPathList:=found;
  507. end;
  508. var
  509. pkg : ppackageentry;
  510. pkgunit : pcontainedunit;
  511. i,idx : longint;
  512. begin
  513. result:=false;
  514. for i:=0 to packagelist.count-1 do
  515. begin
  516. pkg:=ppackageentry(packagelist[i]);
  517. if not assigned(pkg^.package) then
  518. internalerror(2013053103);
  519. idx:=pkg^.package.containedmodules.FindIndexOf(modulename^);
  520. if idx>=0 then
  521. begin
  522. { the unit is part of this package }
  523. pkgunit:=pcontainedunit(pkg^.package.containedmodules[idx]);
  524. if not assigned(pkgunit^.module) then
  525. pkgunit^.module:=self;
  526. filename:=pkgunit^.ppufile;
  527. if not SearchPathList(unitsearchpath) then
  528. exit;
  529. { now load the unit and all used units }
  530. load_interface;
  531. setdefgeneration;
  532. load_usedunits;
  533. Message1(unit_u_finished_loading_unit,modulename^);
  534. result:=true;
  535. break;
  536. end;
  537. end;
  538. end;
  539. {**********************************
  540. PPU Reading/Writing Helpers
  541. ***********************************}
  542. {$IFDEF MACRO_DIFF_HINT}
  543. var
  544. is_initial: Boolean;
  545. procedure tppumodule.writeusedmacro(p:TNamedIndexItem;arg:pointer);
  546. begin
  547. if tmacro(p).is_used or is_initial then
  548. begin
  549. ppufile.putstring(p.name);
  550. ppufile.putbyte(byte(is_initial));
  551. ppufile.putbyte(byte(tmacro(p).is_used));
  552. end;
  553. end;
  554. procedure tppumodule.writeusedmacros;
  555. begin
  556. ppufile.do_crc:=false;
  557. is_initial:= true;
  558. initialmacrosymtable.foreach(@writeusedmacro,nil);
  559. is_initial:= false;
  560. if assigned(globalmacrosymtable) then
  561. globalmacrosymtable.foreach(@writeusedmacro,nil);
  562. localmacrosymtable.foreach(@writeusedmacro,nil);
  563. ppufile.writeentry(ibusedmacros);
  564. ppufile.do_crc:=true;
  565. end;
  566. {$ENDIF}
  567. procedure tppumodule.writesourcefiles;
  568. var
  569. hp : tinputfile;
  570. i,j : longint;
  571. begin
  572. { second write the used source files }
  573. ppufile.do_crc:=false;
  574. hp:=sourcefiles.files;
  575. { write source files directly in good order }
  576. j:=0;
  577. while assigned(hp) do
  578. begin
  579. inc(j);
  580. hp:=hp.ref_next;
  581. end;
  582. while j>0 do
  583. begin
  584. hp:=sourcefiles.files;
  585. for i:=1 to j-1 do
  586. hp:=hp.ref_next;
  587. ppufile.putstring(hp.inc_path+hp.name);
  588. ppufile.putlongint(hp.getfiletime);
  589. dec(j);
  590. end;
  591. ppufile.writeentry(ibsourcefiles);
  592. ppufile.do_crc:=true;
  593. end;
  594. procedure tppumodule.writeusedunit(intf:boolean);
  595. var
  596. hp : tused_unit;
  597. oldcrc : boolean;
  598. begin
  599. { write a reference for each used unit }
  600. hp:=tused_unit(used_units.first);
  601. while assigned(hp) do
  602. begin
  603. if hp.in_interface=intf then
  604. begin
  605. ppufile.putstring(hp.u.realmodulename^);
  606. { the checksum should not affect the crc of this unit ! (PFV) }
  607. oldcrc:=ppufile.do_crc;
  608. ppufile.do_crc:=false;
  609. ppufile.putlongint(longint(hp.checksum));
  610. ppufile.putlongint(longint(hp.interface_checksum));
  611. ppufile.putlongint(longint(hp.indirect_checksum));
  612. ppufile.do_crc:=oldcrc;
  613. { combine all indirect checksums from units used by this unit }
  614. if intf then
  615. ppufile.indirect_crc:=ppufile.indirect_crc xor hp.indirect_checksum;
  616. end;
  617. hp:=tused_unit(hp.next);
  618. end;
  619. ppufile.do_interface_crc:=true;
  620. ppufile.writeentry(ibloadunit);
  621. end;
  622. procedure tppumodule.writelinkcontainer(var p:tlinkcontainer;id:byte;strippath:boolean);
  623. var
  624. hcontainer : tlinkcontainer;
  625. s : TPathStr;
  626. mask : cardinal;
  627. begin
  628. hcontainer:=TLinkContainer.Create;
  629. while not p.empty do
  630. begin
  631. s:=p.get(mask);
  632. if strippath then
  633. ppufile.putstring(ExtractFileName(s))
  634. else
  635. ppufile.putstring(s);
  636. ppufile.putlongint(mask);
  637. hcontainer.add(s,mask);
  638. end;
  639. ppufile.writeentry(id);
  640. p.Free;
  641. p:=hcontainer;
  642. end;
  643. procedure tppumodule.writederefmap;
  644. var
  645. i : longint;
  646. oldcrc : boolean;
  647. begin
  648. { This does not influence crc }
  649. oldcrc:=ppufile.do_crc;
  650. ppufile.do_crc:=false;
  651. { The unit map used for resolving }
  652. ppufile.putlongint(derefmapcnt);
  653. for i:=0 to derefmapcnt-1 do
  654. begin
  655. if not assigned(derefmap[i].u) then
  656. internalerror(2005011512);
  657. ppufile.putstring(derefmap[i].u.modulename^)
  658. end;
  659. ppufile.writeentry(ibderefmap);
  660. ppufile.do_crc:=oldcrc;
  661. end;
  662. procedure tppumodule.writederefdata;
  663. var
  664. oldcrc : boolean;
  665. len,hlen : longint;
  666. buf : array[0..1023] of byte;
  667. begin
  668. if longword(derefdataintflen)>derefdata.size then
  669. internalerror(200310223);
  670. derefdata.seek(0);
  671. { Write interface data }
  672. len:=derefdataintflen;
  673. while (len>0) do
  674. begin
  675. if len>1024 then
  676. hlen:=1024
  677. else
  678. hlen:=len;
  679. derefdata.read(buf,hlen);
  680. ppufile.putdata(buf,hlen);
  681. dec(len,hlen);
  682. end;
  683. { Write implementation data, this does not influence crc }
  684. oldcrc:=ppufile.do_crc;
  685. ppufile.do_crc:=false;
  686. len:=derefdata.size-derefdataintflen;
  687. while (len>0) do
  688. begin
  689. if len>1024 then
  690. hlen:=1024
  691. else
  692. hlen:=len;
  693. derefdata.read(buf,hlen);
  694. ppufile.putdata(buf,hlen);
  695. dec(len,hlen);
  696. end;
  697. if derefdata.pos<>derefdata.size then
  698. internalerror(200310224);
  699. ppufile.do_crc:=oldcrc;
  700. ppufile.writeentry(ibderefdata);
  701. end;
  702. procedure tppumodule.writeImportSymbols;
  703. var
  704. i,j : longint;
  705. ImportLibrary : TImportLibrary;
  706. ImportSymbol : TImportSymbol;
  707. begin
  708. for i:=0 to ImportLibraryList.Count-1 do
  709. begin
  710. ImportLibrary:=TImportLibrary(ImportLibraryList[i]);
  711. ppufile.putstring(ImportLibrary.Name);
  712. ppufile.putlongint(ImportLibrary.ImportSymbolList.Count);
  713. for j:=0 to ImportLibrary.ImportSymbolList.Count-1 do
  714. begin
  715. ImportSymbol:=TImportSymbol(ImportLibrary.ImportSymbolList[j]);
  716. ppufile.putstring(ImportSymbol.Name);
  717. ppufile.putstring(ImportSymbol.MangledName);
  718. ppufile.putlongint(ImportSymbol.OrdNr);
  719. ppufile.putbyte(byte(ImportSymbol.IsVar));
  720. end;
  721. end;
  722. ppufile.writeentry(ibImportSymbols);
  723. end;
  724. procedure tppumodule.writeResources;
  725. var
  726. res : TCmdStrListItem;
  727. begin
  728. res:=TCmdStrListItem(ResourceFiles.First);
  729. while res<>nil do
  730. begin
  731. ppufile.putstring(res.FPStr);
  732. res:=TCmdStrListItem(res.Next);
  733. end;
  734. ppufile.writeentry(ibresources);
  735. end;
  736. {$IFDEF MACRO_DIFF_HINT}
  737. {
  738. Define MACRO_DIFF_HINT for the whole compiler (and ppudump)
  739. to turn this facility on. Also the hint messages defined
  740. below must be commented in in the msg/errore.msg file.
  741. There is some problems with this, thats why it is shut off:
  742. At the first compilation, consider a macro which is not initially
  743. defined, but it is used (e g the check that it is undefined is true).
  744. Since it do not exist, there is no macro object where the is_used
  745. flag can be set. Later on when the macro is defined, and the ppu
  746. is opened, the check cannot detect this.
  747. Also, in which macro object should this flag be set ? It cant be set
  748. for macros in the initialmacrosymboltable since this table is shared
  749. between different files.
  750. }
  751. procedure tppumodule.readusedmacros;
  752. var
  753. hs : string;
  754. mac : tmacro;
  755. was_initial,
  756. was_used : boolean;
  757. {Reads macros which was defined or used when the module was compiled.
  758. This is done when a ppu file is open, before it possibly is parsed.}
  759. begin
  760. while not ppufile.endofentry do
  761. begin
  762. hs:=ppufile.getstring;
  763. was_initial:=boolean(ppufile.getbyte);
  764. was_used:=boolean(ppufile.getbyte);
  765. mac:=tmacro(initialmacrosymtable.Find(hs));
  766. if assigned(mac) then
  767. begin
  768. {$ifndef EXTDEBUG}
  769. { if we don't have the sources why tell }
  770. if sources_avail then
  771. {$endif ndef EXTDEBUG}
  772. if (not was_initial) and was_used then
  773. Message2(unit_h_cond_not_set_in_last_compile,hs,mainsource^);
  774. end
  775. else { not assigned }
  776. if was_initial and
  777. was_used then
  778. Message2(unit_h_cond_set_in_last_compile,hs,mainsource^);
  779. end;
  780. end;
  781. {$ENDIF}
  782. procedure tppumodule.readsourcefiles;
  783. var
  784. temp,hs : string;
  785. inc_path : string;
  786. temp_dir : TCmdStr;
  787. main_dir : TCmdStr;
  788. found,
  789. is_main : boolean;
  790. orgfiletime,
  791. source_time : longint;
  792. hp : tinputfile;
  793. begin
  794. sources_avail:=(flags and uf_release) = 0;
  795. is_main:=true;
  796. main_dir:='';
  797. while not ppufile.endofentry do
  798. begin
  799. hs:=SetDirSeparators(ppufile.getstring);
  800. inc_path:=ExtractFilePath(hs);
  801. orgfiletime:=ppufile.getlongint;
  802. temp_dir:='';
  803. if sources_avail then
  804. begin
  805. if (flags and uf_in_library)<>0 then
  806. begin
  807. sources_avail:=false;
  808. temp:=' library';
  809. end
  810. else if pos('Macro ',hs)=1 then
  811. begin
  812. { we don't want to find this file }
  813. { but there is a problem with file indexing !! }
  814. temp:='';
  815. end
  816. else
  817. begin
  818. { check the date of the source files:
  819. 1 path of ppu
  820. 2 path of main source
  821. 3 current dir
  822. 4 include/unit path }
  823. Source_Time:=GetNamedFileTime(path+hs);
  824. found:=false;
  825. if Source_Time<>-1 then
  826. hs:=path+hs
  827. else
  828. if not(is_main) then
  829. begin
  830. Source_Time:=GetNamedFileTime(main_dir+hs);
  831. if Source_Time<>-1 then
  832. hs:=main_dir+hs;
  833. end;
  834. if Source_Time=-1 then
  835. Source_Time:=GetNamedFileTime(hs);
  836. if (Source_Time=-1) then
  837. begin
  838. if is_main then
  839. found:=unitsearchpath.FindFile(hs,true,temp_dir)
  840. else
  841. found:=includesearchpath.FindFile(hs,true,temp_dir);
  842. if found then
  843. begin
  844. Source_Time:=GetNamedFileTime(temp_dir);
  845. if Source_Time<>-1 then
  846. hs:=temp_dir;
  847. end;
  848. end;
  849. if Source_Time<>-1 then
  850. begin
  851. if is_main then
  852. main_dir:=ExtractFilePath(hs);
  853. temp:=' time '+filetimestring(source_time);
  854. if (orgfiletime<>-1) and
  855. (source_time<>orgfiletime) then
  856. begin
  857. do_compile:=true;
  858. recompile_reason:=rr_sourcenewer;
  859. Message2(unit_u_source_modified,hs,ppufilename,@queuecomment);
  860. temp:=temp+' *';
  861. end;
  862. end
  863. else
  864. begin
  865. sources_avail:=false;
  866. temp:=' not found';
  867. end;
  868. hp:=tdosinputfile.create(hs);
  869. hp.inc_path:=inc_path;
  870. { the indexing is wrong here PM }
  871. sourcefiles.register_file(hp);
  872. end;
  873. end
  874. else
  875. begin
  876. { still register the source module for proper error messages
  877. since source_avail for the module is still false, this should not hurt }
  878. sourcefiles.register_file(tdosinputfile.create(hs));
  879. temp:=' not available';
  880. end;
  881. if is_main then
  882. begin
  883. mainsource:=hs;
  884. end;
  885. Message1(unit_u_ppu_source,hs+temp,@queuecomment);
  886. is_main:=false;
  887. end;
  888. { check if we want to rebuild every unit, only if the sources are
  889. available }
  890. if do_build and sources_avail then
  891. begin
  892. do_compile:=true;
  893. recompile_reason:=rr_build;
  894. end;
  895. end;
  896. procedure tppumodule.readloadunit;
  897. var
  898. hs : string;
  899. pu : tused_unit;
  900. hp : tppumodule;
  901. indchecksum,
  902. intfchecksum,
  903. checksum : cardinal;
  904. begin
  905. while not ppufile.endofentry do
  906. begin
  907. hs:=ppufile.getstring;
  908. checksum:=cardinal(ppufile.getlongint);
  909. intfchecksum:=cardinal(ppufile.getlongint);
  910. indchecksum:=cardinal(ppufile.getlongint);
  911. { set the state of this unit before registering, this is
  912. needed for a correct circular dependency check }
  913. hp:=registerunit(self,hs,'');
  914. pu:=addusedunit(hp,false,nil);
  915. pu.checksum:=checksum;
  916. pu.interface_checksum:=intfchecksum;
  917. pu.indirect_checksum:=indchecksum;
  918. end;
  919. in_interface:=false;
  920. end;
  921. procedure tppumodule.readlinkcontainer(var p:tlinkcontainer);
  922. var
  923. s : string;
  924. m : longint;
  925. begin
  926. while not ppufile.endofentry do
  927. begin
  928. s:=ppufile.getstring;
  929. m:=ppufile.getlongint;
  930. p.add(s,m);
  931. end;
  932. end;
  933. procedure tppumodule.readderefmap;
  934. var
  935. i : longint;
  936. begin
  937. { Load unit map used for resolving }
  938. derefmapsize:=ppufile.getlongint;
  939. derefmapcnt:=derefmapsize;
  940. getmem(derefmap,derefmapsize*sizeof(tderefmaprec));
  941. fillchar(derefmap^,derefmapsize*sizeof(tderefmaprec),0);
  942. for i:=0 to derefmapsize-1 do
  943. derefmap[i].modulename:=stringdup(ppufile.getstring);
  944. end;
  945. procedure tppumodule.readderefdata;
  946. var
  947. len,hlen : longint;
  948. buf : array[0..1023] of byte;
  949. begin
  950. len:=ppufile.entrysize;
  951. while (len>0) do
  952. begin
  953. if len>1024 then
  954. hlen:=1024
  955. else
  956. hlen:=len;
  957. ppufile.getdata(buf,hlen);
  958. derefdata.write(buf,hlen);
  959. dec(len,hlen);
  960. end;
  961. end;
  962. procedure tppumodule.readImportSymbols;
  963. var
  964. j,
  965. extsymcnt : longint;
  966. ImportLibrary : TImportLibrary;
  967. extsymname : string;
  968. extsymmangledname : string;
  969. extsymordnr : longint;
  970. extsymisvar : boolean;
  971. begin
  972. while not ppufile.endofentry do
  973. begin
  974. ImportLibrary:=TImportLibrary.Create(ImportLibraryList,ppufile.getstring);
  975. extsymcnt:=ppufile.getlongint;
  976. for j:=0 to extsymcnt-1 do
  977. begin
  978. extsymname:=ppufile.getstring;
  979. extsymmangledname:=ppufile.getstring;
  980. extsymordnr:=ppufile.getlongint;
  981. extsymisvar:=(ppufile.getbyte<>0);
  982. TImportSymbol.Create(ImportLibrary.ImportSymbolList,extsymname,
  983. extsymmangledname,extsymordnr,extsymisvar);
  984. end;
  985. end;
  986. end;
  987. procedure tppumodule.readResources;
  988. begin
  989. while not ppufile.endofentry do
  990. resourcefiles.Insert(ppufile.getstring);
  991. end;
  992. procedure tppumodule.readwpofile;
  993. var
  994. orgwpofilename: string;
  995. orgwpofiletime: longint;
  996. begin
  997. { check whether we are using the same wpo feedback input file as when
  998. this unit was compiled (same file name and file date)
  999. }
  1000. orgwpofilename:=ppufile.getstring;
  1001. orgwpofiletime:=ppufile.getlongint;
  1002. if (extractfilename(orgwpofilename)<>extractfilename(wpofeedbackinput)) or
  1003. (orgwpofiletime<>GetNamedFileTime(orgwpofilename)) then
  1004. { make sure we don't throw away a precompiled unit if the user simply
  1005. forgot to specify the right wpo feedback file
  1006. }
  1007. message3(unit_e_different_wpo_file,ppufilename,orgwpofilename,filetimestring(orgwpofiletime));
  1008. end;
  1009. procedure tppumodule.load_interface;
  1010. var
  1011. b : byte;
  1012. newmodulename : string;
  1013. begin
  1014. { read interface part }
  1015. repeat
  1016. b:=ppufile.readentry;
  1017. case b of
  1018. ibjvmnamespace :
  1019. begin
  1020. namespace:=stringdup(ppufile.getstring);
  1021. end;
  1022. ibmodulename :
  1023. begin
  1024. newmodulename:=ppufile.getstring;
  1025. if (cs_check_unit_name in current_settings.globalswitches) and
  1026. (upper(newmodulename)<>modulename^) then
  1027. Message2(unit_f_unit_name_error,realmodulename^,newmodulename);
  1028. stringdispose(modulename);
  1029. stringdispose(realmodulename);
  1030. modulename:=stringdup(upper(newmodulename));
  1031. realmodulename:=stringdup(newmodulename);
  1032. end;
  1033. ibmoduleoptions:
  1034. begin
  1035. ppufile.getsmallset(moduleoptions);
  1036. if mo_has_deprecated_msg in moduleoptions then
  1037. begin
  1038. stringdispose(deprecatedmsg);
  1039. deprecatedmsg:=stringdup(ppufile.getstring);
  1040. end;
  1041. end;
  1042. ibsourcefiles :
  1043. readsourcefiles;
  1044. {$IFDEF MACRO_DIFF_HINT}
  1045. ibusedmacros :
  1046. readusedmacros;
  1047. {$ENDIF}
  1048. ibloadunit :
  1049. readloadunit;
  1050. iblinkunitofiles :
  1051. readlinkcontainer(LinkUnitOFiles);
  1052. iblinkunitstaticlibs :
  1053. readlinkcontainer(LinkUnitStaticLibs);
  1054. iblinkunitsharedlibs :
  1055. readlinkcontainer(LinkUnitSharedLibs);
  1056. iblinkotherofiles :
  1057. readlinkcontainer(LinkotherOFiles);
  1058. iblinkotherstaticlibs :
  1059. readlinkcontainer(LinkotherStaticLibs);
  1060. iblinkothersharedlibs :
  1061. readlinkcontainer(LinkotherSharedLibs);
  1062. iblinkotherframeworks :
  1063. readlinkcontainer(LinkOtherFrameworks);
  1064. ibmainname:
  1065. begin
  1066. mainname:=stringdup(ppufile.getstring);
  1067. if (mainaliasname<>defaultmainaliasname) then
  1068. Message1(scan_w_multiple_main_name_overrides,mainaliasname);
  1069. mainaliasname:=mainname^;
  1070. end;
  1071. ibImportSymbols :
  1072. readImportSymbols;
  1073. ibderefmap :
  1074. readderefmap;
  1075. ibderefdata :
  1076. readderefdata;
  1077. ibresources:
  1078. readResources;
  1079. ibwpofile:
  1080. readwpofile;
  1081. ibendinterface :
  1082. break;
  1083. else
  1084. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1085. end;
  1086. { we can already stop when we know that we must recompile }
  1087. if do_compile then
  1088. exit;
  1089. until false;
  1090. end;
  1091. procedure tppumodule.load_implementation;
  1092. var
  1093. b : byte;
  1094. begin
  1095. { read implementation part }
  1096. repeat
  1097. b:=ppufile.readentry;
  1098. case b of
  1099. ibloadunit :
  1100. readloadunit;
  1101. ibasmsymbols :
  1102. { TODO: Remove ibasmsymbols}
  1103. ;
  1104. ibendimplementation :
  1105. break;
  1106. else
  1107. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1108. end;
  1109. until false;
  1110. end;
  1111. procedure tppumodule.writeppu;
  1112. begin
  1113. Message1(unit_u_ppu_write,realmodulename^);
  1114. { create unit flags }
  1115. if do_release then
  1116. flags:=flags or uf_release;
  1117. if assigned(localsymtable) then
  1118. flags:=flags or uf_local_symtable;
  1119. {$ifdef i8086}
  1120. if current_settings.x86memorymodel in [mm_medium,mm_large,mm_huge] then
  1121. flags:=flags or uf_i8086_far_code;
  1122. if current_settings.x86memorymodel in [mm_compact,mm_large] then
  1123. flags:=flags or uf_i8086_far_data;
  1124. if current_settings.x86memorymodel=mm_huge then
  1125. flags:=flags or uf_i8086_huge_data;
  1126. if current_settings.x86memorymodel=mm_tiny then
  1127. flags:=flags or uf_i8086_cs_equals_ds;
  1128. {$endif i8086}
  1129. {$ifdef cpufpemu}
  1130. if (cs_fp_emulation in current_settings.moduleswitches) then
  1131. flags:=flags or uf_fpu_emulation;
  1132. {$endif cpufpemu}
  1133. {$ifdef Test_Double_checksum_write}
  1134. Assign(CRCFile,s+'.IMP');
  1135. Rewrite(CRCFile);
  1136. {$endif def Test_Double_checksum_write}
  1137. { create new ppufile }
  1138. ppufile:=tcompilerppufile.create(ppufilename);
  1139. if not ppufile.createfile then
  1140. Message(unit_f_ppu_cannot_write);
  1141. { first the (JVM) namespace }
  1142. if assigned(namespace) then
  1143. begin
  1144. ppufile.putstring(namespace^);
  1145. ppufile.writeentry(ibjvmnamespace);
  1146. end;
  1147. { the unitname }
  1148. ppufile.putstring(realmodulename^);
  1149. ppufile.writeentry(ibmodulename);
  1150. ppufile.putsmallset(moduleoptions);
  1151. if mo_has_deprecated_msg in moduleoptions then
  1152. ppufile.putstring(deprecatedmsg^);
  1153. ppufile.writeentry(ibmoduleoptions);
  1154. { write the alternate main procedure name if any }
  1155. if assigned(mainname) then
  1156. begin
  1157. ppufile.putstring(mainname^);
  1158. ppufile.writeentry(ibmainname);
  1159. end;
  1160. writesourcefiles;
  1161. {$IFDEF MACRO_DIFF_HINT}
  1162. writeusedmacros;
  1163. {$ENDIF}
  1164. { write interface uses }
  1165. writeusedunit(true);
  1166. { write the objectfiles and libraries that come for this unit,
  1167. preserve the containers because they are still needed to load
  1168. the link.res.
  1169. All doesn't depend on the crc! It doesn't matter
  1170. if a unit is in a .o or .a file }
  1171. ppufile.do_crc:=false;
  1172. { write after source files, so that we know whether or not the compiler
  1173. will recompile the unit when checking whether the correct wpo file is
  1174. used (if it will recompile the unit anyway, it doesn't matter)
  1175. }
  1176. if (wpofeedbackinput<>'') then
  1177. begin
  1178. ppufile.putstring(wpofeedbackinput);
  1179. ppufile.putlongint(getnamedfiletime(wpofeedbackinput));
  1180. ppufile.writeentry(ibwpofile);
  1181. end;
  1182. writelinkcontainer(linkunitofiles,iblinkunitofiles,true);
  1183. writelinkcontainer(linkunitstaticlibs,iblinkunitstaticlibs,true);
  1184. writelinkcontainer(linkunitsharedlibs,iblinkunitsharedlibs,true);
  1185. writelinkcontainer(linkotherofiles,iblinkotherofiles,false);
  1186. writelinkcontainer(linkotherstaticlibs,iblinkotherstaticlibs,true);
  1187. writelinkcontainer(linkothersharedlibs,iblinkothersharedlibs,true);
  1188. writelinkcontainer(linkotherframeworks,iblinkotherframeworks,true);
  1189. writeImportSymbols;
  1190. writeResources;
  1191. ppufile.do_crc:=true;
  1192. { generate implementation deref data, the interface deref data is
  1193. already generated when calculating the interface crc }
  1194. if (cs_compilesystem in current_settings.moduleswitches) then
  1195. begin
  1196. tstoredsymtable(globalsymtable).buildderef;
  1197. derefdataintflen:=derefdata.size;
  1198. end
  1199. else
  1200. { the unit may have been re-resolved, in which case the current
  1201. position in derefdata is not necessarily at the end }
  1202. derefdata.seek(derefdata.size);
  1203. tstoredsymtable(globalsymtable).buildderefimpl;
  1204. tunitwpoinfo(wpoinfo).buildderef;
  1205. tunitwpoinfo(wpoinfo).buildderefimpl;
  1206. if (flags and uf_local_symtable)<>0 then
  1207. tstoredsymtable(localsymtable).buildderef_registered;
  1208. writederefmap;
  1209. writederefdata;
  1210. ppufile.writeentry(ibendinterface);
  1211. { write the symtable entries }
  1212. tstoredsymtable(globalsymtable).ppuwrite(ppufile);
  1213. if assigned(globalmacrosymtable) and (globalmacrosymtable.SymList.count > 0) then
  1214. begin
  1215. ppufile.putbyte(byte(true));
  1216. ppufile.writeentry(ibexportedmacros);
  1217. tstoredsymtable(globalmacrosymtable).ppuwrite(ppufile);
  1218. end
  1219. else
  1220. begin
  1221. ppufile.putbyte(byte(false));
  1222. ppufile.writeentry(ibexportedmacros);
  1223. end;
  1224. { everything after this doesn't affect the crc }
  1225. ppufile.do_crc:=false;
  1226. { write implementation uses }
  1227. writeusedunit(false);
  1228. { end of implementation }
  1229. ppufile.writeentry(ibendimplementation);
  1230. { write static symtable
  1231. needed for local debugging of unit functions }
  1232. if (flags and uf_local_symtable)<>0 then
  1233. tstoredsymtable(localsymtable).ppuwrite(ppufile);
  1234. { write whole program optimisation-related information }
  1235. tunitwpoinfo(wpoinfo).ppuwrite(ppufile);
  1236. { the last entry ibend is written automatically }
  1237. { flush to be sure }
  1238. ppufile.flush;
  1239. { create and write header }
  1240. ppufile.header.common.size:=ppufile.size;
  1241. ppufile.header.checksum:=ppufile.crc;
  1242. ppufile.header.interface_checksum:=ppufile.interface_crc;
  1243. ppufile.header.indirect_checksum:=ppufile.indirect_crc;
  1244. ppufile.header.common.compiler:=wordversion;
  1245. ppufile.header.common.cpu:=word(target_cpu);
  1246. ppufile.header.common.target:=word(target_info.system);
  1247. ppufile.header.common.flags:=flags;
  1248. ppufile.header.deflistsize:=current_module.deflist.count;
  1249. ppufile.header.symlistsize:=current_module.symlist.count;
  1250. ppufile.writeheader;
  1251. { save crc in current module also }
  1252. crc:=ppufile.crc;
  1253. interface_crc:=ppufile.interface_crc;
  1254. indirect_crc:=ppufile.indirect_crc;
  1255. {$ifdef Test_Double_checksum_write}
  1256. close(CRCFile);
  1257. {$endif Test_Double_checksum_write}
  1258. ppufile.closefile;
  1259. ppufile.free;
  1260. ppufile:=nil;
  1261. end;
  1262. procedure tppumodule.getppucrc;
  1263. begin
  1264. {$ifdef Test_Double_checksum_write}
  1265. Assign(CRCFile,s+'.INT')
  1266. Rewrite(CRCFile);
  1267. {$endif def Test_Double_checksum_write}
  1268. { create new ppufile }
  1269. ppufile:=tcompilerppufile.create(ppufilename);
  1270. ppufile.crc_only:=true;
  1271. if not ppufile.createfile then
  1272. Message(unit_f_ppu_cannot_write);
  1273. { first the (JVM) namespace }
  1274. if assigned(namespace) then
  1275. begin
  1276. ppufile.putstring(namespace^);
  1277. ppufile.writeentry(ibjvmnamespace);
  1278. end;
  1279. { the unitname }
  1280. ppufile.putstring(realmodulename^);
  1281. ppufile.writeentry(ibmodulename);
  1282. ppufile.putsmallset(moduleoptions);
  1283. if mo_has_deprecated_msg in moduleoptions then
  1284. ppufile.putstring(deprecatedmsg^);
  1285. ppufile.writeentry(ibmoduleoptions);
  1286. { the interface units affect the crc }
  1287. writeusedunit(true);
  1288. { deref data of interface that affect the crc }
  1289. derefdata.reset;
  1290. tstoredsymtable(globalsymtable).buildderef;
  1291. derefdataintflen:=derefdata.size;
  1292. writederefmap;
  1293. writederefdata;
  1294. ppufile.writeentry(ibendinterface);
  1295. { write the symtable entries }
  1296. tstoredsymtable(globalsymtable).ppuwrite(ppufile);
  1297. if assigned(globalmacrosymtable) and (globalmacrosymtable.SymList.count > 0) then
  1298. begin
  1299. ppufile.putbyte(byte(true));
  1300. ppufile.writeentry(ibexportedmacros);
  1301. tstoredsymtable(globalmacrosymtable).ppuwrite(ppufile);
  1302. end
  1303. else
  1304. begin
  1305. ppufile.putbyte(byte(false));
  1306. ppufile.writeentry(ibexportedmacros);
  1307. end;
  1308. { save crc }
  1309. crc:=ppufile.crc;
  1310. interface_crc:=ppufile.interface_crc;
  1311. indirect_crc:=ppufile.indirect_crc;
  1312. { end of implementation, to generate a correct ppufile
  1313. for ppudump when using INTFPPU define }
  1314. ppufile.writeentry(ibendimplementation);
  1315. {$ifdef Test_Double_checksum}
  1316. crc_array:=ppufile.crc_test;
  1317. ppufile.crc_test:=nil;
  1318. crc_size:=ppufile.crc_index2;
  1319. crc_array2:=ppufile.crc_test2;
  1320. ppufile.crc_test2:=nil;
  1321. crc_size2:=ppufile.crc_index2;
  1322. {$endif Test_Double_checksum}
  1323. {$ifdef Test_Double_checksum_write}
  1324. close(CRCFile);
  1325. {$endif Test_Double_checksum_write}
  1326. { create and write header, this will only be used
  1327. for debugging purposes }
  1328. ppufile.header.common.size:=ppufile.size;
  1329. ppufile.header.checksum:=ppufile.crc;
  1330. ppufile.header.interface_checksum:=ppufile.interface_crc;
  1331. ppufile.header.indirect_checksum:=ppufile.indirect_crc;
  1332. ppufile.header.common.compiler:=wordversion;
  1333. ppufile.header.common.cpu:=word(target_cpu);
  1334. ppufile.header.common.target:=word(target_info.system);
  1335. ppufile.header.common.flags:=flags;
  1336. ppufile.writeheader;
  1337. ppufile.closefile;
  1338. ppufile.free;
  1339. ppufile:=nil;
  1340. end;
  1341. procedure tppumodule.load_usedunits;
  1342. var
  1343. pu : tused_unit;
  1344. begin
  1345. if current_module<>self then
  1346. internalerror(200212284);
  1347. { load the used units from interface }
  1348. in_interface:=true;
  1349. pu:=tused_unit(used_units.first);
  1350. while assigned(pu) do
  1351. begin
  1352. if pu.in_interface then
  1353. begin
  1354. tppumodule(pu.u).loadppu;
  1355. { if this unit is compiled we can stop }
  1356. if state=ms_compiled then
  1357. exit;
  1358. { add this unit to the dependencies }
  1359. pu.u.adddependency(self);
  1360. { need to recompile the current unit, check the interface
  1361. crc. And when not compiled with -Ur then check the complete
  1362. crc }
  1363. if (pu.u.interface_crc<>pu.interface_checksum) or
  1364. (pu.u.indirect_crc<>pu.indirect_checksum) or
  1365. (
  1366. ((ppufile.header.common.flags and uf_release)=0) and
  1367. (pu.u.crc<>pu.checksum)
  1368. ) then
  1369. begin
  1370. Message2(unit_u_recompile_crc_change,realmodulename^,pu.u.realmodulename^,@queuecomment);
  1371. {$ifdef DEBUG_UNIT_CRC_CHANGES}
  1372. if (pu.u.interface_crc<>pu.interface_checksum) then
  1373. writeln(' intfcrc change: ',hexstr(pu.u.interface_crc,8),' <> ',hexstr(pu.interface_checksum,8))
  1374. else if (pu.u.indirect_crc<>pu.indirect_checksum) then
  1375. writeln(' indcrc change: ',hexstr(pu.u.indirect_crc,8),' <> ',hexstr(pu.indirect_checksum,8))
  1376. else
  1377. writeln(' implcrc change: ',hexstr(pu.u.crc,8),' <> ',hexstr(pu.checksum,8));
  1378. {$endif DEBUG_UNIT_CRC_CHANGES}
  1379. recompile_reason:=rr_crcchanged;
  1380. do_compile:=true;
  1381. exit;
  1382. end;
  1383. end;
  1384. pu:=tused_unit(pu.next);
  1385. end;
  1386. { ok, now load the interface of this unit }
  1387. if current_module<>self then
  1388. internalerror(200208187);
  1389. deflist.count:=ppufile.header.deflistsize;
  1390. symlist.count:=ppufile.header.symlistsize;
  1391. globalsymtable:=tglobalsymtable.create(modulename^,moduleid);
  1392. tstoredsymtable(globalsymtable).ppuload(ppufile);
  1393. if ppufile.readentry<>ibexportedmacros then
  1394. Message(unit_f_ppu_read_error);
  1395. if boolean(ppufile.getbyte) then
  1396. begin
  1397. globalmacrosymtable:=tmacrosymtable.Create(true);
  1398. tstoredsymtable(globalmacrosymtable).ppuload(ppufile)
  1399. end;
  1400. interface_compiled:=true;
  1401. { read the implementation part, containing
  1402. the implementation uses and ObjData }
  1403. in_interface:=false;
  1404. load_implementation;
  1405. { now only read the implementation uses }
  1406. pu:=tused_unit(used_units.first);
  1407. while assigned(pu) do
  1408. begin
  1409. if (not pu.in_interface) then
  1410. begin
  1411. tppumodule(pu.u).loadppu;
  1412. { if this unit is compiled we can stop }
  1413. if state=ms_compiled then
  1414. exit;
  1415. { add this unit to the dependencies }
  1416. pu.u.adddependency(self);
  1417. { need to recompile the current unit ? }
  1418. if (pu.u.interface_crc<>pu.interface_checksum) or
  1419. (pu.u.indirect_crc<>pu.indirect_checksum) then
  1420. begin
  1421. Message2(unit_u_recompile_crc_change,realmodulename^,pu.u.realmodulename^+' {impl}',@queuecomment);
  1422. {$ifdef DEBUG_UNIT_CRC_CHANGES}
  1423. if (pu.u.interface_crc<>pu.interface_checksum) then
  1424. writeln(' intfcrc change (2): ',hexstr(pu.u.interface_crc,8),' <> ',hexstr(pu.interface_checksum,8))
  1425. else if (pu.u.indirect_crc<>pu.indirect_checksum) then
  1426. writeln(' indcrc change (2): ',hexstr(pu.u.indirect_crc,8),' <> ',hexstr(pu.indirect_checksum,8));
  1427. {$endif DEBUG_UNIT_CRC_CHANGES}
  1428. recompile_reason:=rr_crcchanged;
  1429. do_compile:=true;
  1430. exit;
  1431. end;
  1432. end;
  1433. pu:=tused_unit(pu.next);
  1434. end;
  1435. { load implementation symtable }
  1436. if (flags and uf_local_symtable)<>0 then
  1437. begin
  1438. localsymtable:=tstaticsymtable.create(modulename^,moduleid);
  1439. tstaticsymtable(localsymtable).ppuload(ppufile);
  1440. end;
  1441. { we can now derefence all pointers to the implementation parts }
  1442. tstoredsymtable(globalsymtable).derefimpl(false);
  1443. { we've just loaded the localsymtable from the ppu file, so everything
  1444. in it was registered by definition (otherwise it wouldn't have been in
  1445. there) }
  1446. if assigned(localsymtable) then
  1447. tstoredsymtable(localsymtable).derefimpl(false);
  1448. { read whole program optimisation-related information }
  1449. wpoinfo:=tunitwpoinfo.ppuload(ppufile);
  1450. tunitwpoinfo(wpoinfo).deref;
  1451. tunitwpoinfo(wpoinfo).derefimpl;
  1452. end;
  1453. function tppumodule.needrecompile:boolean;
  1454. var
  1455. pu : tused_unit;
  1456. begin
  1457. result:=false;
  1458. pu:=tused_unit(used_units.first);
  1459. while assigned(pu) do
  1460. begin
  1461. { need to recompile the current unit, check the interface
  1462. crc. And when not compiled with -Ur then check the complete
  1463. crc }
  1464. if (pu.u.interface_crc<>pu.interface_checksum) or
  1465. (pu.u.indirect_crc<>pu.indirect_checksum) or
  1466. (
  1467. (pu.in_interface) and
  1468. (pu.u.crc<>pu.checksum)
  1469. ) then
  1470. begin
  1471. {$ifdef DEBUG_UNIT_CRC_CHANGES}
  1472. if (pu.u.interface_crc<>pu.interface_checksum) then
  1473. writeln(' intfcrc change (3): ',hexstr(pu.u.interface_crc,8),' <> ',hexstr(pu.interface_checksum,8))
  1474. else if (pu.u.indirect_crc<>pu.indirect_checksum) then
  1475. writeln(' indcrc change (3): ',hexstr(pu.u.indirect_crc,8),' <> ',hexstr(pu.indirect_checksum,8))
  1476. else
  1477. writeln(' implcrc change (3): ',hexstr(pu.u.crc,8),' <> ',hexstr(pu.checksum,8));
  1478. {$endif DEBUG_UNIT_CRC_CHANGES}
  1479. result:=true;
  1480. exit;
  1481. end;
  1482. pu:=tused_unit(pu.next);
  1483. end;
  1484. end;
  1485. procedure tppumodule.setdefgeneration;
  1486. begin
  1487. defsgeneration:=currentdefgeneration;
  1488. inc(currentdefgeneration);
  1489. end;
  1490. procedure tppumodule.reload_flagged_units;
  1491. var
  1492. hp : tppumodule;
  1493. begin
  1494. { now reload all dependent units with outdated defs }
  1495. hp:=tppumodule(loaded_units.first);
  1496. while assigned(hp) do
  1497. begin
  1498. if hp.do_reload and
  1499. (hp.defsgeneration<defsgeneration) then
  1500. begin
  1501. hp.defsgeneration:=defsgeneration;
  1502. hp.loadppu
  1503. end
  1504. else
  1505. hp.do_reload:=false;
  1506. hp:=tppumodule(hp.next);
  1507. end;
  1508. end;
  1509. procedure tppumodule.end_of_parsing;
  1510. begin
  1511. { module is now compiled }
  1512. state:=ms_compiled;
  1513. { free ppu }
  1514. if assigned(ppufile) then
  1515. begin
  1516. ppufile.free;
  1517. ppufile:=nil;
  1518. end;
  1519. inherited end_of_parsing;
  1520. end;
  1521. procedure tppumodule.loadppu;
  1522. const
  1523. ImplIntf : array[boolean] of string[15]=('implementation','interface');
  1524. var
  1525. do_load,
  1526. second_time : boolean;
  1527. old_current_module : tmodule;
  1528. pu : tused_unit;
  1529. begin
  1530. old_current_module:=current_module;
  1531. Message3(unit_u_load_unit,old_current_module.modulename^,
  1532. ImplIntf[old_current_module.in_interface],
  1533. modulename^);
  1534. { Update loaded_from to detect cycles }
  1535. loaded_from:=old_current_module;
  1536. { check if the globalsymtable is already available, but
  1537. we must reload when the do_reload flag is set }
  1538. if (not do_reload) and
  1539. assigned(globalsymtable) then
  1540. exit;
  1541. { reset }
  1542. do_load:=true;
  1543. second_time:=false;
  1544. set_current_module(self);
  1545. { try to load it as a package unit first }
  1546. if (packagelist.count>0) and loadfrompackage then
  1547. begin
  1548. do_load:=false;
  1549. do_reload:=false;
  1550. state:=ms_load;
  1551. { add the unit to the used units list of the program }
  1552. usedunits.concat(tused_unit.create(self,true,false,nil));
  1553. end;
  1554. { A force reload }
  1555. if do_reload then
  1556. begin
  1557. Message(unit_u_forced_reload);
  1558. do_reload:=false;
  1559. { When the unit is already loaded or being loaded
  1560. we can maybe skip a complete reload/recompile }
  1561. if assigned(globalsymtable) and
  1562. (not needrecompile) then
  1563. begin
  1564. { When we don't have any data stored yet there
  1565. is nothing to resolve }
  1566. if interface_compiled then
  1567. begin
  1568. Message1(unit_u_reresolving_unit,modulename^);
  1569. tstoredsymtable(globalsymtable).deref(false);
  1570. tstoredsymtable(globalsymtable).derefimpl(false);
  1571. if assigned(localsymtable) then
  1572. begin
  1573. { we have only builderef(impl)'d the registered symbols of
  1574. the localsymtable -> also only deref those again }
  1575. tstoredsymtable(localsymtable).deref(true);
  1576. tstoredsymtable(localsymtable).derefimpl(true);
  1577. end;
  1578. if assigned(wpoinfo) then
  1579. begin
  1580. tunitwpoinfo(wpoinfo).deref;
  1581. tunitwpoinfo(wpoinfo).derefimpl;
  1582. end;
  1583. { We have to flag the units that depend on this unit even
  1584. though it didn't change, because they might also
  1585. indirectly depend on the unit that did change (e.g.,
  1586. in case rgobj, rgx86 and rgcpu have been compiled
  1587. already, and then rgobj is recompiled for some reason
  1588. -> rgx86 is re-reresolved, but the vmtentries of trgcpu
  1589. must also be re-resolved, because they will also contain
  1590. pointers to procdefs in the old trgobj (in case of a
  1591. recompile, all old defs are freed) }
  1592. flagdependent(old_current_module);
  1593. reload_flagged_units;
  1594. end
  1595. else
  1596. Message1(unit_u_skipping_reresolving_unit,modulename^);
  1597. do_load:=false;
  1598. end;
  1599. end;
  1600. if do_load then
  1601. begin
  1602. { loading the unit for a second time? }
  1603. if state=ms_registered then
  1604. state:=ms_load
  1605. else
  1606. begin
  1607. { try to load the unit a second time first }
  1608. Message1(unit_u_second_load_unit,modulename^);
  1609. Message2(unit_u_previous_state,modulename^,ModuleStateStr[state]);
  1610. { Flag modules to reload }
  1611. flagdependent(old_current_module);
  1612. { Reset the module }
  1613. reset;
  1614. if state in [ms_compile,ms_second_compile] then
  1615. begin
  1616. Message1(unit_u_second_compile_unit,modulename^);
  1617. state:=ms_second_compile;
  1618. do_compile:=true;
  1619. end
  1620. else
  1621. state:=ms_second_load;
  1622. second_time:=true;
  1623. end;
  1624. { close old_current_ppu on system that are
  1625. short on file handles like DOS PM }
  1626. {$ifdef SHORT_ON_FILE_HANDLES}
  1627. if old_current_module.is_unit and
  1628. assigned(tppumodule(old_current_module).ppufile) then
  1629. tppumodule(old_current_module).ppufile.tempclose;
  1630. {$endif SHORT_ON_FILE_HANDLES}
  1631. { try to opening ppu, skip this when we already
  1632. know that we need to compile the unit }
  1633. if not do_compile then
  1634. begin
  1635. Message1(unit_u_loading_unit,modulename^);
  1636. search_unit_files(false);
  1637. if not do_compile then
  1638. begin
  1639. load_interface;
  1640. setdefgeneration;
  1641. if not do_compile then
  1642. begin
  1643. load_usedunits;
  1644. if not do_compile then
  1645. Message1(unit_u_finished_loading_unit,modulename^);
  1646. end;
  1647. end;
  1648. { PPU is not needed anymore }
  1649. if assigned(ppufile) then
  1650. begin
  1651. ppufile.closefile;
  1652. ppufile.free;
  1653. ppufile:=nil;
  1654. end;
  1655. end;
  1656. { Do we need to recompile the unit }
  1657. if do_compile then
  1658. begin
  1659. { recompile the unit or give a fatal error if sources not available }
  1660. if not(sources_avail) then
  1661. begin
  1662. search_unit_files(true);
  1663. if not(sources_avail) then
  1664. begin
  1665. printcomments;
  1666. if recompile_reason=rr_noppu then
  1667. begin
  1668. pu:=tused_unit(loaded_from.used_units.first);
  1669. while assigned(pu) do
  1670. begin
  1671. if pu.u=self then
  1672. break;
  1673. pu:=tused_unit(pu.next);
  1674. end;
  1675. if assigned(pu) and assigned(pu.unitsym) then
  1676. MessagePos2(pu.unitsym.fileinfo,unit_f_cant_find_ppu,realmodulename^,loaded_from.realmodulename^)
  1677. else
  1678. Message2(unit_f_cant_find_ppu,realmodulename^,loaded_from.realmodulename^);
  1679. end
  1680. else
  1681. Message1(unit_f_cant_compile_unit,realmodulename^);
  1682. end;
  1683. end;
  1684. { we found the sources, we do not need the verbose messages anymore }
  1685. if comments <> nil then
  1686. begin
  1687. comments.free;
  1688. comments:=nil;
  1689. end;
  1690. { Flag modules to reload }
  1691. flagdependent(old_current_module);
  1692. { Reset the module }
  1693. reset;
  1694. { compile this module }
  1695. if not(state in [ms_compile,ms_second_compile]) then
  1696. state:=ms_compile;
  1697. compile(mainsource);
  1698. setdefgeneration;
  1699. end
  1700. else
  1701. state:=ms_compiled;
  1702. if current_module<>self then
  1703. internalerror(200212282);
  1704. if in_interface then
  1705. internalerror(200212283);
  1706. { for a second_time recompile reload all dependent units,
  1707. for a first time compile register the unit _once_ }
  1708. if second_time then
  1709. reload_flagged_units
  1710. else
  1711. usedunits.concat(tused_unit.create(self,true,false,nil));
  1712. { reopen the old module }
  1713. {$ifdef SHORT_ON_FILE_HANDLES}
  1714. if old_current_module.is_unit and
  1715. assigned(tppumodule(old_current_module).ppufile) then
  1716. tppumodule(old_current_module).ppufile.tempopen;
  1717. {$endif SHORT_ON_FILE_HANDLES}
  1718. end;
  1719. { we are back, restore current_module }
  1720. set_current_module(old_current_module);
  1721. end;
  1722. {*****************************************************************************
  1723. RegisterUnit
  1724. *****************************************************************************}
  1725. function registerunit(callermodule:tmodule;const s : TIDString;const fn:string) : tppumodule;
  1726. var
  1727. ups : TIDString;
  1728. hp : tppumodule;
  1729. hp2 : tmodule;
  1730. begin
  1731. { Info }
  1732. ups:=upper(s);
  1733. { search all loaded units }
  1734. hp:=tppumodule(loaded_units.first);
  1735. while assigned(hp) do
  1736. begin
  1737. if hp.modulename^=ups then
  1738. begin
  1739. { only check for units. The main program is also
  1740. as a unit in the loaded_units list. We simply need
  1741. to ignore this entry (PFV) }
  1742. if hp.is_unit then
  1743. begin
  1744. { both units in interface ? }
  1745. if callermodule.in_interface and
  1746. hp.in_interface then
  1747. begin
  1748. { check for a cycle }
  1749. hp2:=callermodule.loaded_from;
  1750. while assigned(hp2) and (hp2<>hp) do
  1751. begin
  1752. if hp2.in_interface then
  1753. hp2:=hp2.loaded_from
  1754. else
  1755. hp2:=nil;
  1756. end;
  1757. if assigned(hp2) then
  1758. Message2(unit_f_circular_unit_reference,callermodule.realmodulename^,hp.realmodulename^);
  1759. end;
  1760. break;
  1761. end;
  1762. end;
  1763. { the next unit }
  1764. hp:=tppumodule(hp.next);
  1765. end;
  1766. { the unit is not in the loaded units,
  1767. we create an entry and register the unit }
  1768. if not assigned(hp) then
  1769. begin
  1770. Message1(unit_u_registering_new_unit,Upper(s));
  1771. hp:=tppumodule.create(callermodule,s,fn,true);
  1772. hp.loaded_from:=callermodule;
  1773. addloadedunit(hp);
  1774. end;
  1775. { return }
  1776. registerunit:=hp;
  1777. end;
  1778. end.