fppu.pas 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit implements the first loading and searching of the modules
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit fppu;
  19. {$i fpcdefs.inc}
  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. cutils,cclasses,
  31. globtype,globals,finput,fmodule,
  32. symbase,symppu,ppu;
  33. type
  34. tppumodule = class(tmodule)
  35. ppufile : tcompilerppufile; { the PPU file }
  36. sourcefn : pstring; { Source specified with "uses .. in '..'" }
  37. {$ifdef Test_Double_checksum}
  38. crc_array : pointer;
  39. crc_size : longint;
  40. crc_array2 : pointer;
  41. crc_size2 : longint;
  42. {$endif def Test_Double_checksum}
  43. constructor create(LoadedFrom:TModule;const s:string;const fn:string;_is_unit:boolean);
  44. destructor destroy;override;
  45. procedure reset;override;
  46. function openppu:boolean;
  47. procedure getppucrc;
  48. procedure writeppu;
  49. procedure loadppu;
  50. function needrecompile:boolean;
  51. private
  52. function search_unit(onlysource,shortname:boolean):boolean;
  53. procedure load_interface;
  54. procedure load_implementation;
  55. procedure load_symtable_refs;
  56. procedure load_usedunits;
  57. procedure writeusedmacro(p:TNamedIndexItem;arg:pointer);
  58. procedure writeusedmacros;
  59. procedure writesourcefiles;
  60. procedure writeusedunit(intf:boolean);
  61. procedure writelinkcontainer(var p:tlinkcontainer;id:byte;strippath:boolean);
  62. procedure putasmsymbol_in_idx(s:tnamedindexitem;arg:pointer);
  63. procedure writeasmsymbols;
  64. procedure readusedmacros;
  65. procedure readsourcefiles;
  66. procedure readloadunit;
  67. procedure readlinkcontainer(var p:tlinkcontainer);
  68. procedure readasmsymbols;
  69. end;
  70. procedure reload_flagged_units;
  71. function registerunit(callermodule:tmodule;const s : stringid;const fn:string) : tppumodule;
  72. implementation
  73. uses
  74. verbose,systems,version,
  75. symtable,
  76. scanner,
  77. aasmbase,
  78. parser;
  79. {****************************************************************************
  80. Helpers
  81. ****************************************************************************}
  82. procedure reload_flagged_units;
  83. var
  84. hp : tmodule;
  85. begin
  86. { now reload all dependent units }
  87. hp:=tmodule(loaded_units.first);
  88. while assigned(hp) do
  89. begin
  90. if hp.do_reload then
  91. tppumodule(hp).loadppu;
  92. hp:=tmodule(hp.next);
  93. end;
  94. end;
  95. {****************************************************************************
  96. TPPUMODULE
  97. ****************************************************************************}
  98. constructor tppumodule.create(LoadedFrom:TModule;const s:string;const fn:string;_is_unit:boolean);
  99. begin
  100. inherited create(LoadedFrom,s,_is_unit);
  101. ppufile:=nil;
  102. sourcefn:=stringdup(fn);
  103. end;
  104. destructor tppumodule.Destroy;
  105. begin
  106. if assigned(ppufile) then
  107. ppufile.free;
  108. ppufile:=nil;
  109. stringdispose(sourcefn);
  110. inherited Destroy;
  111. end;
  112. procedure tppumodule.reset;
  113. begin
  114. if assigned(ppufile) then
  115. begin
  116. ppufile.free;
  117. ppufile:=nil;
  118. end;
  119. inherited reset;
  120. end;
  121. function tppumodule.openppu:boolean;
  122. var
  123. ppufiletime : longint;
  124. begin
  125. openppu:=false;
  126. Message1(unit_t_ppu_loading,ppufilename^);
  127. { Get ppufile time (also check if the file exists) }
  128. ppufiletime:=getnamedfiletime(ppufilename^);
  129. if ppufiletime=-1 then
  130. exit;
  131. { Open the ppufile }
  132. Message1(unit_u_ppu_name,ppufilename^);
  133. ppufile:=tcompilerppufile.create(ppufilename^);
  134. if not ppufile.openfile then
  135. begin
  136. ppufile.free;
  137. ppufile:=nil;
  138. Message(unit_u_ppu_file_too_short);
  139. exit;
  140. end;
  141. { check for a valid PPU file }
  142. if not ppufile.CheckPPUId then
  143. begin
  144. ppufile.free;
  145. ppufile:=nil;
  146. Message(unit_u_ppu_invalid_header);
  147. exit;
  148. end;
  149. { check for allowed PPU versions }
  150. if not (ppufile.GetPPUVersion = CurrentPPUVersion) then
  151. begin
  152. Message1(unit_u_ppu_invalid_version,tostr(ppufile.GetPPUVersion));
  153. ppufile.free;
  154. ppufile:=nil;
  155. exit;
  156. end;
  157. { check the target processor }
  158. if tsystemcpu(ppufile.header.cpu)<>target_cpu then
  159. begin
  160. ppufile.free;
  161. ppufile:=nil;
  162. Message(unit_u_ppu_invalid_processor);
  163. exit;
  164. end;
  165. { check target }
  166. if tsystem(ppufile.header.target)<>target_info.system then
  167. begin
  168. ppufile.free;
  169. ppufile:=nil;
  170. Message(unit_u_ppu_invalid_target);
  171. exit;
  172. end;
  173. {$ifdef cpufpemu}
  174. { check if floating point emulation is on?}
  175. if ((ppufile.header.flags and uf_fpu_emulation)<>0) and
  176. (cs_fp_emulation in aktmoduleswitches) then
  177. begin
  178. ppufile.free;
  179. ppufile:=nil;
  180. Message(unit_u_ppu_invalid_fpumode);
  181. exit;
  182. end;
  183. {$endif cpufpemu}
  184. { Load values to be access easier }
  185. flags:=ppufile.header.flags;
  186. crc:=ppufile.header.checksum;
  187. interface_crc:=ppufile.header.interface_checksum;
  188. { Show Debug info }
  189. Message1(unit_u_ppu_time,filetimestring(ppufiletime));
  190. Message1(unit_u_ppu_flags,tostr(flags));
  191. Message1(unit_u_ppu_crc,hexstr(ppufile.header.checksum,8));
  192. Message1(unit_u_ppu_crc,hexstr(ppufile.header.interface_checksum,8)+' (intfc)');
  193. do_compile:=false;
  194. openppu:=true;
  195. end;
  196. function tppumodule.search_unit(onlysource,shortname:boolean):boolean;
  197. var
  198. singlepathstring,
  199. filename : string;
  200. Function UnitExists(const ext:string;var foundfile:string):boolean;
  201. begin
  202. Message1(unit_t_unitsearch,Singlepathstring+filename+ext);
  203. UnitExists:=FindFile(FileName+ext,Singlepathstring,foundfile);
  204. end;
  205. Function PPUSearchPath(const s:string):boolean;
  206. var
  207. found : boolean;
  208. hs : string;
  209. begin
  210. Found:=false;
  211. singlepathstring:=FixPath(s,false);
  212. { Check for PPU file }
  213. Found:=UnitExists(target_info.unitext,hs);
  214. if Found then
  215. Begin
  216. SetFileName(hs,false);
  217. Found:=OpenPPU;
  218. End;
  219. PPUSearchPath:=Found;
  220. end;
  221. Function SourceSearchPath(const s:string):boolean;
  222. var
  223. found : boolean;
  224. hs : string;
  225. begin
  226. Found:=false;
  227. singlepathstring:=FixPath(s,false);
  228. { Check for Sources }
  229. ppufile:=nil;
  230. do_compile:=true;
  231. recompile_reason:=rr_noppu;
  232. {Check for .pp file}
  233. Found:=UnitExists(target_info.sourceext,hs);
  234. if not Found then
  235. begin
  236. { Check for .pas }
  237. Found:=UnitExists(target_info.pasext,hs);
  238. end;
  239. stringdispose(mainsource);
  240. if Found then
  241. begin
  242. sources_avail:=true;
  243. { Load Filenames when found }
  244. mainsource:=StringDup(hs);
  245. SetFileName(hs,false);
  246. end
  247. else
  248. sources_avail:=false;
  249. SourceSearchPath:=Found;
  250. end;
  251. Function SearchPath(const s:string):boolean;
  252. var
  253. found : boolean;
  254. begin
  255. { First check for a ppu, then for the source }
  256. found:=false;
  257. if not onlysource then
  258. found:=PPUSearchPath(s);
  259. if not found then
  260. found:=SourceSearchPath(s);
  261. SearchPath:=found;
  262. end;
  263. Function SearchPathList(list:TSearchPathList):boolean;
  264. var
  265. hp : TStringListItem;
  266. found : boolean;
  267. begin
  268. found:=false;
  269. hp:=TStringListItem(list.First);
  270. while assigned(hp) do
  271. begin
  272. found:=SearchPath(hp.Str);
  273. if found then
  274. break;
  275. hp:=TStringListItem(hp.next);
  276. end;
  277. SearchPathList:=found;
  278. end;
  279. var
  280. fnd : boolean;
  281. hs : string;
  282. begin
  283. if shortname then
  284. filename:=FixFileName(Copy(realmodulename^,1,8))
  285. else
  286. filename:=FixFileName(realmodulename^);
  287. { try to find unit
  288. 1. look for ppu in cwd
  289. 2. look for ppu in outputpath if set, this is tp7 compatible (PFV)
  290. 3. look for the specified source file (from the uses line)
  291. 4. look for source in cwd
  292. 5. local unit pathlist
  293. 6. global unit pathlist }
  294. fnd:=false;
  295. if not onlysource then
  296. begin
  297. fnd:=PPUSearchPath('.');
  298. if (not fnd) and (outputpath^<>'') then
  299. fnd:=PPUSearchPath(outputpath^);
  300. end;
  301. if (not fnd) and (sourcefn^<>'') then
  302. begin
  303. { the full filename is specified so we can't use here the
  304. searchpath (PFV) }
  305. Message1(unit_t_unitsearch,AddExtension(sourcefn^,target_info.sourceext));
  306. fnd:=FindFile(AddExtension(sourcefn^,target_info.sourceext),'',hs);
  307. if not fnd then
  308. begin
  309. Message1(unit_t_unitsearch,AddExtension(sourcefn^,target_info.pasext));
  310. fnd:=FindFile(AddExtension(sourcefn^,target_info.pasext),'',hs);
  311. end;
  312. if fnd then
  313. begin
  314. sources_avail:=true;
  315. do_compile:=true;
  316. recompile_reason:=rr_noppu;
  317. stringdispose(mainsource);
  318. mainsource:=StringDup(hs);
  319. SetFileName(hs,false);
  320. end;
  321. end;
  322. if not fnd then
  323. fnd:=SourceSearchPath('.');
  324. if (not fnd) and Assigned(Loaded_From) then
  325. fnd:=SearchPathList(Loaded_From.LocalUnitSearchPath);
  326. if not fnd then
  327. fnd:=SearchPathList(UnitSearchPath);
  328. { try to find a file with the first 8 chars of the modulename, like
  329. dos }
  330. if (not fnd) and (length(filename)>8) then
  331. begin
  332. filename:=copy(filename,1,8);
  333. fnd:=SearchPath('.');
  334. if (not fnd) then
  335. fnd:=SearchPathList(LocalUnitSearchPath);
  336. if not fnd then
  337. fnd:=SearchPathList(UnitSearchPath);
  338. end;
  339. search_unit:=fnd;
  340. end;
  341. {**********************************
  342. PPU Reading/Writing Helpers
  343. ***********************************}
  344. procedure tppumodule.writeusedmacro(p:TNamedIndexItem;arg:pointer);
  345. begin
  346. if tmacro(p).is_used or tmacro(p).defined_at_startup then
  347. begin
  348. ppufile.putstring(p.name);
  349. ppufile.putbyte(byte(tmacro(p).defined_at_startup));
  350. ppufile.putbyte(byte(tmacro(p).is_used));
  351. end;
  352. end;
  353. procedure tppumodule.writeusedmacros;
  354. begin
  355. ppufile.do_crc:=false;
  356. tscannerfile(scanner).macros.foreach({$ifdef FPCPROCVAR}@{$endif}writeusedmacro,nil);
  357. ppufile.writeentry(ibusedmacros);
  358. ppufile.do_crc:=true;
  359. end;
  360. procedure tppumodule.writesourcefiles;
  361. var
  362. hp : tinputfile;
  363. i,j : longint;
  364. begin
  365. { second write the used source files }
  366. ppufile.do_crc:=false;
  367. hp:=sourcefiles.files;
  368. { write source files directly in good order }
  369. j:=0;
  370. while assigned(hp) do
  371. begin
  372. inc(j);
  373. hp:=hp.ref_next;
  374. end;
  375. while j>0 do
  376. begin
  377. hp:=sourcefiles.files;
  378. for i:=1 to j-1 do
  379. hp:=hp.ref_next;
  380. ppufile.putstring(hp.name^);
  381. ppufile.putlongint(hp.getfiletime);
  382. dec(j);
  383. end;
  384. ppufile.writeentry(ibsourcefiles);
  385. ppufile.do_crc:=true;
  386. end;
  387. procedure tppumodule.writeusedunit(intf:boolean);
  388. var
  389. hp : tused_unit;
  390. oldcrc : boolean;
  391. begin
  392. { renumber the units for derefence writing }
  393. numberunits;
  394. { write a reference for each used unit }
  395. hp:=tused_unit(used_units.first);
  396. while assigned(hp) do
  397. begin
  398. if hp.in_interface=intf then
  399. begin
  400. ppufile.putstring(hp.u.realmodulename^);
  401. { the checksum should not affect the crc of this unit ! (PFV) }
  402. oldcrc:=ppufile.do_crc;
  403. ppufile.do_crc:=false;
  404. ppufile.putlongint(longint(hp.checksum));
  405. ppufile.putlongint(longint(hp.interface_checksum));
  406. ppufile.do_crc:=oldcrc;
  407. end;
  408. hp:=tused_unit(hp.next);
  409. end;
  410. ppufile.do_interface_crc:=true;
  411. ppufile.writeentry(ibloadunit);
  412. end;
  413. procedure tppumodule.writelinkcontainer(var p:tlinkcontainer;id:byte;strippath:boolean);
  414. var
  415. hcontainer : tlinkcontainer;
  416. s : string;
  417. mask : cardinal;
  418. begin
  419. hcontainer:=TLinkContainer.Create;
  420. while not p.empty do
  421. begin
  422. s:=p.get(mask);
  423. if strippath then
  424. ppufile.putstring(SplitFileName(s))
  425. else
  426. ppufile.putstring(s);
  427. ppufile.putlongint(mask);
  428. hcontainer.add(s,mask);
  429. end;
  430. ppufile.writeentry(id);
  431. p.Free;
  432. p:=hcontainer;
  433. end;
  434. procedure tppumodule.putasmsymbol_in_idx(s:tnamedindexitem;arg:pointer);
  435. begin
  436. if tasmsymbol(s).ppuidx<>-1 then
  437. librarydata.asmsymbolidx^[tasmsymbol(s).ppuidx-1]:=tasmsymbol(s);
  438. end;
  439. procedure tppumodule.writeasmsymbols;
  440. var
  441. s : tasmsymbol;
  442. i : longint;
  443. asmsymtype : byte;
  444. begin
  445. { get an ordered list of all symbols to put in the ppu }
  446. getmem(librarydata.asmsymbolidx,librarydata.asmsymbolppuidx*sizeof(pointer));
  447. fillchar(librarydata.asmsymbolidx^,librarydata.asmsymbolppuidx*sizeof(pointer),0);
  448. librarydata.symbolsearch.foreach({$ifdef FPCPROCVAR}@{$endif}putasmsymbol_in_idx,nil);
  449. { write the number of symbols }
  450. ppufile.putlongint(librarydata.asmsymbolppuidx);
  451. { write the symbols from the indexed list to the ppu }
  452. for i:=1 to librarydata.asmsymbolppuidx do
  453. begin
  454. s:=librarydata.asmsymbolidx^[i-1];
  455. if not assigned(s) then
  456. internalerror(200208071);
  457. asmsymtype:=1;
  458. if s.Classtype=tasmlabel then
  459. begin
  460. if tasmlabel(s).is_addr then
  461. asmsymtype:=4
  462. else if tasmlabel(s).typ=AT_DATA then
  463. asmsymtype:=3
  464. else
  465. asmsymtype:=2;
  466. end;
  467. ppufile.putbyte(asmsymtype);
  468. case asmsymtype of
  469. 1 :
  470. ppufile.putstring(s.name);
  471. 2 :
  472. ppufile.putlongint(tasmlabel(s).labelnr);
  473. end;
  474. ppufile.putbyte(byte(s.defbind));
  475. ppufile.putbyte(byte(s.typ));
  476. end;
  477. ppufile.writeentry(ibasmsymbols);
  478. end;
  479. procedure tppumodule.readusedmacros;
  480. var
  481. hs : string;
  482. mac : tmacro;
  483. was_defined_at_startup,
  484. was_used : boolean;
  485. begin
  486. { only possible when we've a scanner of the current file }
  487. if not assigned(current_scanner) then
  488. exit;
  489. while not ppufile.endofentry do
  490. begin
  491. hs:=ppufile.getstring;
  492. was_defined_at_startup:=boolean(ppufile.getbyte);
  493. was_used:=boolean(ppufile.getbyte);
  494. mac:=tmacro(tscannerfile(current_scanner).macros.search(hs));
  495. if assigned(mac) then
  496. begin
  497. {$ifndef EXTDEBUG}
  498. { if we don't have the sources why tell }
  499. if sources_avail then
  500. {$endif ndef EXTDEBUG}
  501. if (not was_defined_at_startup) and
  502. was_used and
  503. mac.defined_at_startup then
  504. Message2(unit_h_cond_not_set_in_last_compile,hs,mainsource^);
  505. end
  506. else { not assigned }
  507. if was_defined_at_startup and
  508. was_used then
  509. Message2(unit_h_cond_set_in_last_compile,hs,mainsource^);
  510. end;
  511. end;
  512. procedure tppumodule.readsourcefiles;
  513. var
  514. temp,hs : string;
  515. temp_dir : string;
  516. main_dir : string;
  517. incfile_found,
  518. main_found,
  519. is_main : boolean;
  520. orgfiletime,
  521. source_time : longint;
  522. hp : tinputfile;
  523. begin
  524. sources_avail:=true;
  525. is_main:=true;
  526. main_dir:='';
  527. while not ppufile.endofentry do
  528. begin
  529. hs:=ppufile.getstring;
  530. orgfiletime:=ppufile.getlongint;
  531. temp_dir:='';
  532. if (flags and uf_in_library)<>0 then
  533. begin
  534. sources_avail:=false;
  535. temp:=' library';
  536. end
  537. else if pos('Macro ',hs)=1 then
  538. begin
  539. { we don't want to find this file }
  540. { but there is a problem with file indexing !! }
  541. temp:='';
  542. end
  543. else
  544. begin
  545. { check the date of the source files }
  546. Source_Time:=GetNamedFileTime(path^+hs);
  547. incfile_found:=false;
  548. main_found:=false;
  549. if Source_Time<>-1 then
  550. hs:=path^+hs
  551. else
  552. if not(is_main) then
  553. begin
  554. Source_Time:=GetNamedFileTime(main_dir+hs);
  555. if Source_Time<>-1 then
  556. hs:=main_dir+hs;
  557. end;
  558. if (Source_Time=-1) then
  559. begin
  560. if is_main then
  561. main_found:=unitsearchpath.FindFile(hs,temp_dir)
  562. else
  563. incfile_found:=includesearchpath.FindFile(hs,temp_dir);
  564. if incfile_found or main_found then
  565. begin
  566. Source_Time:=GetNamedFileTime(temp_dir);
  567. if Source_Time<>-1 then
  568. hs:=temp_dir;
  569. end;
  570. end;
  571. if Source_Time=-1 then
  572. begin
  573. sources_avail:=false;
  574. temp:=' not found';
  575. end
  576. else
  577. begin
  578. if main_found then
  579. main_dir:=temp_dir;
  580. { time newer? But only allow if the file is not searched
  581. in the include path (PFV), else you've problems with
  582. units which use the same includefile names }
  583. if incfile_found then
  584. temp:=' found'
  585. else
  586. begin
  587. temp:=' time '+filetimestring(source_time);
  588. if (orgfiletime<>-1) and
  589. (source_time<>orgfiletime) then
  590. begin
  591. if ((flags and uf_release)=0) then
  592. begin
  593. do_compile:=true;
  594. recompile_reason:=rr_sourcenewer;
  595. end
  596. else
  597. Message2(unit_h_source_modified,hs,ppufilename^);
  598. temp:=temp+' *';
  599. end;
  600. end;
  601. end;
  602. hp:=tinputfile.create(hs);
  603. { the indexing is wrong here PM }
  604. sourcefiles.register_file(hp);
  605. end;
  606. if is_main then
  607. begin
  608. stringdispose(mainsource);
  609. mainsource:=stringdup(hs);
  610. end;
  611. Message1(unit_u_ppu_source,hs+temp);
  612. is_main:=false;
  613. end;
  614. { check if we want to rebuild every unit, only if the sources are
  615. available }
  616. if do_build and sources_avail and
  617. ((flags and uf_release)=0) then
  618. begin
  619. do_compile:=true;
  620. recompile_reason:=rr_build;
  621. end;
  622. end;
  623. procedure tppumodule.readloadunit;
  624. var
  625. hs : string;
  626. pu : tused_unit;
  627. hp : tppumodule;
  628. intfchecksum,
  629. checksum : cardinal;
  630. begin
  631. while not ppufile.endofentry do
  632. begin
  633. hs:=ppufile.getstring;
  634. checksum:=cardinal(ppufile.getlongint);
  635. intfchecksum:=cardinal(ppufile.getlongint);
  636. { set the state of this unit before registering, this is
  637. needed for a correct circular dependency check }
  638. hp:=registerunit(self,hs,'');
  639. pu:=addusedunit(hp,false,nil);
  640. pu.checksum:=checksum;
  641. pu.interface_checksum:=intfchecksum;
  642. end;
  643. in_interface:=false;
  644. end;
  645. procedure tppumodule.readlinkcontainer(var p:tlinkcontainer);
  646. var
  647. s : string;
  648. m : longint;
  649. begin
  650. while not ppufile.endofentry do
  651. begin
  652. s:=ppufile.getstring;
  653. m:=ppufile.getlongint;
  654. p.add(s,m);
  655. end;
  656. end;
  657. procedure tppumodule.readasmsymbols;
  658. var
  659. labelnr,
  660. i : longint;
  661. name : string;
  662. bind : TAsmSymBind;
  663. typ : TAsmSymType;
  664. asmsymtype : byte;
  665. begin
  666. librarydata.asmsymbolppuidx:=ppufile.getlongint;
  667. if librarydata.asmsymbolppuidx>0 then
  668. begin
  669. getmem(librarydata.asmsymbolidx,librarydata.asmsymbolppuidx*sizeof(pointer));
  670. fillchar(librarydata.asmsymbolidx^,librarydata.asmsymbolppuidx*sizeof(pointer),0);
  671. for i:=1 to librarydata.asmsymbolppuidx do
  672. begin
  673. asmsymtype:=ppufile.getbyte;
  674. case asmsymtype of
  675. 1 :
  676. name:=ppufile.getstring;
  677. 2..4 :
  678. labelnr:=ppufile.getlongint;
  679. else
  680. internalerror(200208192);
  681. end;
  682. bind:=tasmsymbind(ppufile.getbyte);
  683. typ:=tasmsymtype(ppufile.getbyte);
  684. case asmsymtype of
  685. 1 :
  686. librarydata.asmsymbolidx^[i-1]:=librarydata.newasmsymboltype(name,bind,typ);
  687. 2 :
  688. librarydata.asmsymbolidx^[i-1]:=librarydata.newasmlabel(labelnr,false,false);
  689. 3 :
  690. librarydata.asmsymbolidx^[i-1]:=librarydata.newasmlabel(labelnr,true,false);
  691. 4 :
  692. librarydata.asmsymbolidx^[i-1]:=librarydata.newasmlabel(labelnr,false,true);
  693. end;
  694. end;
  695. end;
  696. end;
  697. procedure tppumodule.load_interface;
  698. var
  699. b : byte;
  700. newmodulename : string;
  701. begin
  702. { read interface part }
  703. repeat
  704. b:=ppufile.readentry;
  705. case b of
  706. ibmodulename :
  707. begin
  708. newmodulename:=ppufile.getstring;
  709. if (cs_check_unit_name in aktglobalswitches) and
  710. (upper(newmodulename)<>modulename^) then
  711. Message2(unit_f_unit_name_error,realmodulename^,newmodulename);
  712. stringdispose(modulename);
  713. stringdispose(realmodulename);
  714. modulename:=stringdup(upper(newmodulename));
  715. realmodulename:=stringdup(newmodulename);
  716. end;
  717. ibsourcefiles :
  718. readsourcefiles;
  719. ibusedmacros :
  720. readusedmacros;
  721. ibloadunit :
  722. readloadunit;
  723. iblinkunitofiles :
  724. readlinkcontainer(LinkUnitOFiles);
  725. iblinkunitstaticlibs :
  726. readlinkcontainer(LinkUnitStaticLibs);
  727. iblinkunitsharedlibs :
  728. readlinkcontainer(LinkUnitSharedLibs);
  729. iblinkotherofiles :
  730. readlinkcontainer(LinkotherOFiles);
  731. iblinkotherstaticlibs :
  732. readlinkcontainer(LinkotherStaticLibs);
  733. iblinkothersharedlibs :
  734. readlinkcontainer(LinkotherSharedLibs);
  735. ibendinterface :
  736. break;
  737. else
  738. Message1(unit_f_ppu_invalid_entry,tostr(b));
  739. end;
  740. until false;
  741. end;
  742. procedure tppumodule.load_implementation;
  743. var
  744. b : byte;
  745. oldobjectlibrary : tasmlibrarydata;
  746. begin
  747. { read implementation part }
  748. repeat
  749. b:=ppufile.readentry;
  750. case b of
  751. ibloadunit :
  752. readloadunit;
  753. ibasmsymbols :
  754. readasmsymbols;
  755. ibendimplementation :
  756. break;
  757. else
  758. Message1(unit_f_ppu_invalid_entry,tostr(b));
  759. end;
  760. until false;
  761. { we can now derefence all pointers to the implementation parts }
  762. oldobjectlibrary:=objectlibrary;
  763. objectlibrary:=librarydata;
  764. tstoredsymtable(globalsymtable).derefimpl;
  765. if assigned(localsymtable) then
  766. tstoredsymtable(localsymtable).derefimpl;
  767. objectlibrary:=oldobjectlibrary;
  768. end;
  769. procedure tppumodule.load_symtable_refs;
  770. var
  771. b : byte;
  772. i : longint;
  773. begin
  774. { load local symtable first }
  775. if ((flags and uf_local_browser)<>0) then
  776. begin
  777. localsymtable:=tstaticsymtable.create(modulename^);
  778. tstaticsymtable(localsymtable).ppuload(ppufile);
  779. end;
  780. { load browser }
  781. if (flags and uf_has_browser)<>0 then
  782. begin
  783. tstoredsymtable(globalsymtable).load_references(ppufile,true);
  784. for i:=0 to mapsize-1 do
  785. tstoredsymtable(globalsymtable).load_references(ppufile,false);
  786. b:=ppufile.readentry;
  787. if b<>ibendbrowser then
  788. Message1(unit_f_ppu_invalid_entry,tostr(b));
  789. end;
  790. if ((flags and uf_local_browser)<>0) then
  791. tstaticsymtable(localsymtable).load_references(ppufile,true);
  792. end;
  793. procedure tppumodule.writeppu;
  794. var
  795. pu : tused_unit;
  796. begin
  797. Message1(unit_u_ppu_write,realmodulename^);
  798. { create unit flags }
  799. {$ifdef GDB}
  800. if cs_gdb_dbx in aktglobalswitches then
  801. flags:=flags or uf_has_dbx;
  802. {$endif GDB}
  803. if cs_browser in aktmoduleswitches then
  804. flags:=flags or uf_has_browser;
  805. if cs_local_browser in aktmoduleswitches then
  806. flags:=flags or uf_local_browser;
  807. if do_release then
  808. flags:=flags or uf_release;
  809. {$ifdef cpufpemu}
  810. if (cs_fp_emulation in aktmoduleswitches) then
  811. flags:=flags or uf_fpu_emulation;
  812. {$endif cpufpemu}
  813. {$ifdef Test_Double_checksum_write}
  814. Assign(CRCFile,s+'.IMP');
  815. Rewrite(CRCFile);
  816. {$endif def Test_Double_checksum_write}
  817. { create new ppufile }
  818. ppufile:=tcompilerppufile.create(ppufilename^);
  819. if not ppufile.createfile then
  820. Message(unit_f_ppu_cannot_write);
  821. { first the unitname }
  822. ppufile.putstring(realmodulename^);
  823. ppufile.writeentry(ibmodulename);
  824. writesourcefiles;
  825. writeusedmacros;
  826. { write interface uses }
  827. writeusedunit(true);
  828. { write the objectfiles and libraries that come for this unit,
  829. preserve the containers becuase they are still needed to load
  830. the link.res. All doesn't depend on the crc! It doesn't matter
  831. if a unit is in a .o or .a file }
  832. ppufile.do_crc:=false;
  833. writelinkcontainer(linkunitofiles,iblinkunitofiles,true);
  834. writelinkcontainer(linkunitstaticlibs,iblinkunitstaticlibs,true);
  835. writelinkcontainer(linkunitsharedlibs,iblinkunitsharedlibs,true);
  836. writelinkcontainer(linkotherofiles,iblinkotherofiles,false);
  837. writelinkcontainer(linkotherstaticlibs,iblinkotherstaticlibs,true);
  838. writelinkcontainer(linkothersharedlibs,iblinkothersharedlibs,true);
  839. ppufile.do_crc:=true;
  840. ppufile.writeentry(ibendinterface);
  841. { write the symtable entries }
  842. tstoredsymtable(globalsymtable).ppuwrite(ppufile);
  843. { everything after this doesn't affect the crc }
  844. ppufile.do_crc:=false;
  845. { write implementation uses }
  846. writeusedunit(false);
  847. { write asmsymbols }
  848. writeasmsymbols;
  849. { end of implementation }
  850. ppufile.writeentry(ibendimplementation);
  851. { write static symtable
  852. needed for local debugging of unit functions }
  853. if ((flags and uf_local_browser)<>0) and
  854. assigned(localsymtable) then
  855. tstoredsymtable(localsymtable).ppuwrite(ppufile);
  856. { write all browser section }
  857. if (flags and uf_has_browser)<>0 then
  858. begin
  859. tstoredsymtable(globalsymtable).write_references(ppufile,true);
  860. pu:=tused_unit(used_units.first);
  861. while assigned(pu) do
  862. begin
  863. tstoredsymtable(pu.u.globalsymtable).write_references(ppufile,false);
  864. pu:=tused_unit(pu.next);
  865. end;
  866. ppufile.writeentry(ibendbrowser);
  867. end;
  868. if ((flags and uf_local_browser)<>0) and
  869. assigned(localsymtable) then
  870. tstaticsymtable(localsymtable).write_references(ppufile,true);
  871. { the last entry ibend is written automaticly }
  872. { flush to be sure }
  873. ppufile.flush;
  874. { create and write header }
  875. ppufile.header.size:=ppufile.size;
  876. ppufile.header.checksum:=ppufile.crc;
  877. ppufile.header.interface_checksum:=ppufile.interface_crc;
  878. ppufile.header.compiler:=wordversion;
  879. ppufile.header.cpu:=word(target_cpu);
  880. ppufile.header.target:=word(target_info.system);
  881. ppufile.header.flags:=flags;
  882. ppufile.writeheader;
  883. { save crc in current module also }
  884. crc:=ppufile.crc;
  885. interface_crc:=ppufile.interface_crc;
  886. {$ifdef Test_Double_checksum_write}
  887. close(CRCFile);
  888. {$endif Test_Double_checksum_write}
  889. ppufile.closefile;
  890. ppufile.free;
  891. ppufile:=nil;
  892. end;
  893. procedure tppumodule.getppucrc;
  894. begin
  895. {$ifdef Test_Double_checksum_write}
  896. Assign(CRCFile,s+'.INT')
  897. Rewrite(CRCFile);
  898. {$endif def Test_Double_checksum_write}
  899. { create new ppufile }
  900. ppufile:=tcompilerppufile.create(ppufilename^);
  901. ppufile.crc_only:=true;
  902. if not ppufile.createfile then
  903. Message(unit_f_ppu_cannot_write);
  904. { first the unitname }
  905. ppufile.putstring(realmodulename^);
  906. ppufile.writeentry(ibmodulename);
  907. { the interface units affect the crc }
  908. writeusedunit(true);
  909. ppufile.writeentry(ibendinterface);
  910. { write the symtable entries }
  911. tstoredsymtable(globalsymtable).ppuwrite(ppufile);
  912. { save crc }
  913. crc:=ppufile.crc;
  914. interface_crc:=ppufile.interface_crc;
  915. { end of implementation, to generate a correct ppufile
  916. for ppudump when using INTFPPU define }
  917. ppufile.writeentry(ibendimplementation);
  918. {$ifdef Test_Double_checksum}
  919. crc_array:=ppufile.crc_test;
  920. ppufile.crc_test:=nil;
  921. crc_size:=ppufile.crc_index2;
  922. crc_array2:=ppufile.crc_test2;
  923. ppufile.crc_test2:=nil;
  924. crc_size2:=ppufile.crc_index2;
  925. {$endif Test_Double_checksum}
  926. {$ifdef Test_Double_checksum_write}
  927. close(CRCFile);
  928. {$endif Test_Double_checksum_write}
  929. { create and write header, this will only be used
  930. for debugging purposes }
  931. ppufile.header.size:=ppufile.size;
  932. ppufile.header.checksum:=ppufile.crc;
  933. ppufile.header.interface_checksum:=ppufile.interface_crc;
  934. ppufile.header.compiler:=wordversion;
  935. ppufile.header.cpu:=word(target_cpu);
  936. ppufile.header.target:=word(target_info.system);
  937. ppufile.header.flags:=flags;
  938. ppufile.writeheader;
  939. ppufile.closefile;
  940. ppufile.free;
  941. ppufile:=nil;
  942. end;
  943. procedure tppumodule.load_usedunits;
  944. var
  945. pu : tused_unit;
  946. load_refs : boolean;
  947. begin
  948. if current_module<>self then
  949. internalerror(200212284);
  950. load_refs:=true;
  951. { load the used units from interface }
  952. in_interface:=true;
  953. pu:=tused_unit(used_units.first);
  954. while assigned(pu) do
  955. begin
  956. if pu.in_interface then
  957. begin
  958. tppumodule(pu.u).loadppu;
  959. { if this unit is compiled we can stop }
  960. if state=ms_compiled then
  961. exit;
  962. { add this unit to the dependencies }
  963. pu.u.adddependency(self);
  964. { need to recompile the current unit, check the interface
  965. crc. And when not compiled with -Ur then check the complete
  966. crc }
  967. if (pu.u.interface_crc<>pu.interface_checksum) or
  968. (
  969. ((ppufile.header.flags and uf_release)=0) and
  970. (pu.u.crc<>pu.checksum)
  971. ) then
  972. begin
  973. Message2(unit_u_recompile_crc_change,realmodulename^,pu.u.realmodulename^);
  974. recompile_reason:=rr_crcchanged;
  975. do_compile:=true;
  976. exit;
  977. end;
  978. end;
  979. pu:=tused_unit(pu.next);
  980. end;
  981. numberunits;
  982. { ok, now load the interface of this unit }
  983. if current_module<>self then
  984. internalerror(200208187);
  985. globalsymtable:=tglobalsymtable.create(modulename^);
  986. tstoredsymtable(globalsymtable).ppuload(ppufile);
  987. interface_compiled:=true;
  988. { read the implementation part, containing
  989. the implementation uses and objectdata }
  990. in_interface:=false;
  991. load_implementation;
  992. { now only read the implementation uses }
  993. pu:=tused_unit(used_units.first);
  994. while assigned(pu) do
  995. begin
  996. if (not pu.in_interface) then
  997. begin
  998. tppumodule(pu.u).loadppu;
  999. { if this unit is compiled we can stop }
  1000. if state=ms_compiled then
  1001. exit;
  1002. { add this unit to the dependencies }
  1003. pu.u.adddependency(self);
  1004. { need to recompile the current unit ? }
  1005. if (pu.u.interface_crc<>pu.interface_checksum) then
  1006. begin
  1007. Message2(unit_u_recompile_crc_change,realmodulename^,pu.u.realmodulename^+' {impl}');
  1008. recompile_reason:=rr_crcchanged;
  1009. do_compile:=true;
  1010. exit;
  1011. end;
  1012. end;
  1013. pu:=tused_unit(pu.next);
  1014. end;
  1015. numberunits;
  1016. { load browser info if stored }
  1017. if ((flags and uf_has_browser)<>0) and load_refs then
  1018. begin
  1019. if current_module<>self then
  1020. internalerror(200208188);
  1021. load_symtable_refs;
  1022. end;
  1023. end;
  1024. function tppumodule.needrecompile:boolean;
  1025. var
  1026. pu : tused_unit;
  1027. begin
  1028. result:=false;
  1029. pu:=tused_unit(used_units.first);
  1030. while assigned(pu) do
  1031. begin
  1032. { need to recompile the current unit, check the interface
  1033. crc. And when not compiled with -Ur then check the complete
  1034. crc }
  1035. if (pu.u.interface_crc<>pu.interface_checksum) or
  1036. (
  1037. (pu.in_interface) and
  1038. (pu.u.crc<>pu.checksum)
  1039. ) then
  1040. begin
  1041. result:=true;
  1042. exit;
  1043. end;
  1044. pu:=tused_unit(pu.next);
  1045. end;
  1046. end;
  1047. procedure tppumodule.loadppu;
  1048. const
  1049. ImplIntf : array[boolean] of string[15]=('implementation','interface');
  1050. var
  1051. do_load,
  1052. second_time : boolean;
  1053. old_current_module : tmodule;
  1054. begin
  1055. old_current_module:=current_module;
  1056. Message3(unit_u_load_unit,old_current_module.modulename^,
  1057. ImplIntf[old_current_module.in_interface],
  1058. modulename^);
  1059. { check if the globalsymtable is already available, but
  1060. we must reload when the do_reload flag is set }
  1061. if (not do_reload) and
  1062. assigned(globalsymtable) then
  1063. exit;
  1064. { reset }
  1065. do_load:=true;
  1066. second_time:=false;
  1067. current_module:=self;
  1068. SetCompileModule(current_module);
  1069. Fillchar(aktfilepos,0,sizeof(aktfilepos));
  1070. { A force reload }
  1071. if do_reload then
  1072. begin
  1073. Message(unit_u_forced_reload);
  1074. do_reload:=false;
  1075. { When the unit is already loaded or being loaded
  1076. we can maybe skip a complete reload/recompile }
  1077. if assigned(globalsymtable) and
  1078. (not needrecompile) then
  1079. begin
  1080. { When we don't have any data stored yet there
  1081. is nothing to resolve }
  1082. if interface_compiled then
  1083. begin
  1084. Message1(unit_u_reresolving_unit,modulename^);
  1085. aktglobalsymtable:=tstoredsymtable(globalsymtable);
  1086. tstoredsymtable(globalsymtable).deref;
  1087. tstoredsymtable(globalsymtable).derefimpl;
  1088. if assigned(localsymtable) then
  1089. begin
  1090. aktstaticsymtable:=tstoredsymtable(localsymtable);
  1091. tstoredsymtable(localsymtable).deref;
  1092. tstoredsymtable(localsymtable).derefimpl;
  1093. end;
  1094. end
  1095. else
  1096. Message1(unit_u_skipping_reresolving_unit,modulename^);
  1097. do_load:=false;
  1098. end;
  1099. end;
  1100. if do_load then
  1101. begin
  1102. { we are loading a new module, save the state of the scanner
  1103. and reset scanner+module }
  1104. if assigned(current_scanner) then
  1105. current_scanner.tempcloseinputfile;
  1106. current_scanner:=nil;
  1107. { loading the unit for a second time? }
  1108. if state=ms_registered then
  1109. state:=ms_load
  1110. else
  1111. begin
  1112. { try to load the unit a second time first }
  1113. Message1(unit_u_second_load_unit,modulename^);
  1114. Message2(unit_u_previous_state,modulename^,ModuleStateStr[state]);
  1115. { Flag modules to reload }
  1116. flagdependent(old_current_module);
  1117. { Reset the module }
  1118. reset;
  1119. if state=ms_compile then
  1120. begin
  1121. Message1(unit_u_second_compile_unit,modulename^);
  1122. state:=ms_second_compile;
  1123. do_compile:=true;
  1124. end
  1125. else
  1126. state:=ms_second_load;
  1127. second_time:=true;
  1128. end;
  1129. { close old_current_ppu on system that are
  1130. short on file handles like DOS PM }
  1131. {$ifdef SHORT_ON_FILE_HANDLES}
  1132. if old_current_module.is_unit and
  1133. assigned(tppumodule(old_current_module).ppufile) then
  1134. tppumodule(old_current_module).ppufile.tempclose;
  1135. {$endif SHORT_ON_FILE_HANDLES}
  1136. { try to opening ppu, skip this when we already
  1137. know that we need to compile the unit }
  1138. if not do_compile then
  1139. begin
  1140. Message1(unit_u_loading_unit,modulename^);
  1141. if modulename^='SYMSYM' then
  1142. modulename:=modulename;
  1143. search_unit(false,false);
  1144. if not do_compile then
  1145. begin
  1146. load_interface;
  1147. if not do_compile then
  1148. begin
  1149. load_usedunits;
  1150. if not do_compile then
  1151. Message1(unit_u_finished_loading_unit,modulename^);
  1152. end;
  1153. end;
  1154. { PPU is not needed anymore }
  1155. if assigned(ppufile) then
  1156. begin
  1157. ppufile.closefile;
  1158. ppufile.free;
  1159. ppufile:=nil;
  1160. end;
  1161. end;
  1162. { Do we need to recompile the unit }
  1163. if do_compile then
  1164. begin
  1165. { recompile the unit or give a fatal error if sources not available }
  1166. if not(sources_avail) then
  1167. begin
  1168. if (not search_unit(true,false)) and
  1169. (length(modulename^)>8) then
  1170. search_unit(true,true);
  1171. if not(sources_avail) then
  1172. begin
  1173. if recompile_reason=rr_noppu then
  1174. Message1(unit_f_cant_find_ppu,modulename^)
  1175. else
  1176. Message1(unit_f_cant_compile_unit,modulename^);
  1177. end;
  1178. end;
  1179. { Flag modules to reload }
  1180. flagdependent(old_current_module);
  1181. { Reset the module }
  1182. reset;
  1183. { compile this module }
  1184. if not(state in [ms_compile,ms_second_compile]) then
  1185. state:=ms_compile;
  1186. compile(mainsource^);
  1187. end;
  1188. { set compiled flag }
  1189. if current_module<>self then
  1190. internalerror(200212282);
  1191. state:=ms_compiled;
  1192. if in_interface then
  1193. internalerror(200212283);
  1194. { for a second_time recompile reload all dependent units,
  1195. for a first time compile register the unit _once_ }
  1196. if second_time then
  1197. reload_flagged_units
  1198. else
  1199. usedunits.concat(tused_unit.create(self,true,false,nil));
  1200. { reopen the old module }
  1201. {$ifdef SHORT_ON_FILE_HANDLES}
  1202. if old_current_module.is_unit and
  1203. assigned(tppumodule(old_current_module).ppufile) then
  1204. tppumodule(old_current_module).ppufile.tempopen;
  1205. {$endif SHORT_ON_FILE_HANDLES}
  1206. { reload old scanner }
  1207. current_scanner:=tscannerfile(old_current_module.scanner);
  1208. if assigned(current_scanner) then
  1209. begin
  1210. current_scanner.tempopeninputfile;
  1211. current_scanner.gettokenpos
  1212. end
  1213. else
  1214. fillchar(aktfilepos,sizeof(aktfilepos),0);
  1215. end;
  1216. { we are back, restore current_module }
  1217. current_module:=old_current_module;
  1218. SetCompileModule(current_module);
  1219. end;
  1220. {*****************************************************************************
  1221. RegisterUnit
  1222. *****************************************************************************}
  1223. function registerunit(callermodule:tmodule;const s : stringid;const fn:string) : tppumodule;
  1224. var
  1225. ups : stringid;
  1226. hp : tppumodule;
  1227. hp2,
  1228. shortnamehp : tmodule;
  1229. begin
  1230. { Info }
  1231. ups:=upper(s);
  1232. { search all loaded units }
  1233. shortnamehp:=nil;
  1234. hp:=tppumodule(loaded_units.first);
  1235. while assigned(hp) do
  1236. begin
  1237. if hp.modulename^=ups then
  1238. begin
  1239. { only check for units. The main program is also
  1240. as a unit in the loaded_units list. We simply need
  1241. to ignore this entry (PFV) }
  1242. if hp.is_unit then
  1243. begin
  1244. { both units in interface ? }
  1245. if callermodule.in_interface and
  1246. hp.in_interface then
  1247. begin
  1248. { check for a cycle }
  1249. hp2:=callermodule.loaded_from;
  1250. while assigned(hp2) and (hp2<>hp) do
  1251. begin
  1252. if hp2.in_interface then
  1253. hp2:=hp2.loaded_from
  1254. else
  1255. hp2:=nil;
  1256. end;
  1257. if assigned(hp2) then
  1258. Message2(unit_f_circular_unit_reference,callermodule.modulename^,hp.modulename^);
  1259. end;
  1260. break;
  1261. end;
  1262. end
  1263. else
  1264. if copy(hp.modulename^,1,8)=ups then
  1265. shortnamehp:=hp;
  1266. { the next unit }
  1267. hp:=tppumodule(hp.next);
  1268. end;
  1269. if assigned(shortnamehp) and not assigned(hp) then
  1270. Message2(unit_w_unit_name_error,s,shortnamehp.modulename^);
  1271. { the unit is not in the loaded units,
  1272. we create an entry and register the unit }
  1273. if not assigned(hp) then
  1274. begin
  1275. Message1(unit_u_registering_new_unit,Upper(s));
  1276. hp:=tppumodule.create(callermodule,s,fn,true);
  1277. hp.loaded_from:=callermodule;
  1278. loaded_units.insert(hp);
  1279. end;
  1280. { return }
  1281. registerunit:=hp;
  1282. end;
  1283. end.
  1284. {
  1285. $Log$
  1286. Revision 1.41 2003-10-22 17:38:25 peter
  1287. * write implementation units in implementation part of the ppu
  1288. so it doesn't confuse the unit loading
  1289. Revision 1.40 2003/10/22 15:22:33 peter
  1290. * fixed unitsym-globalsymtable relation so the uses of a unit
  1291. is counted correctly
  1292. Revision 1.39 2003/09/05 17:41:12 florian
  1293. * merged Wiktor's Watcom patches in 1.1
  1294. Revision 1.38 2003/08/23 22:29:24 peter
  1295. * reload flagged units when interface is loaded
  1296. Revision 1.37 2003/06/08 11:40:14 peter
  1297. * moved message to msg file
  1298. Revision 1.36 2003/06/07 20:26:32 peter
  1299. * re-resolving added instead of reloading from ppu
  1300. * tderef object added to store deref info for resolving
  1301. Revision 1.35 2003/05/25 10:27:12 peter
  1302. * moved Comment calls to messge file
  1303. Revision 1.34 2003/05/23 17:04:37 peter
  1304. * write interface crc to .ppu.intf when enabled
  1305. * when a unit is compiled with -Ur check only interface crc
  1306. Revision 1.33 2003/04/27 11:21:32 peter
  1307. * aktprocdef renamed to current_procdef
  1308. * procinfo renamed to current_procinfo
  1309. * procinfo will now be stored in current_module so it can be
  1310. cleaned up properly
  1311. * gen_main_procsym changed to create_main_proc and release_main_proc
  1312. to also generate a tprocinfo structure
  1313. * fixed unit implicit initfinal
  1314. Revision 1.32 2003/04/27 07:29:50 peter
  1315. * current_procdef cleanup, current_procdef is now always nil when parsing
  1316. a new procdef declaration
  1317. * aktprocsym removed
  1318. * lexlevel removed, use symtable.symtablelevel instead
  1319. * implicit init/final code uses the normal genentry/genexit
  1320. * funcret state checking updated for new funcret handling
  1321. Revision 1.31 2003/04/26 00:30:52 peter
  1322. * reset aktfilepos when setting new module for compile
  1323. Revision 1.30 2003/03/27 17:44:13 peter
  1324. * fixed small mem leaks
  1325. Revision 1.29 2002/12/29 14:57:50 peter
  1326. * unit loading changed to first register units and load them
  1327. afterwards. This is needed to support uses xxx in yyy correctly
  1328. * unit dependency check fixed
  1329. Revision 1.28 2002/12/06 16:56:57 peter
  1330. * only compile cs_fp_emulation support when cpufpuemu is defined
  1331. * define cpufpuemu for m68k only
  1332. Revision 1.27 2002/11/20 12:36:24 mazen
  1333. * $UNITPATH directive is now working
  1334. Revision 1.26 2002/11/15 01:58:46 peter
  1335. * merged changes from 1.0.7 up to 04-11
  1336. - -V option for generating bug report tracing
  1337. - more tracing for option parsing
  1338. - errors for cdecl and high()
  1339. - win32 import stabs
  1340. - win32 records<=8 are returned in eax:edx (turned off by default)
  1341. - heaptrc update
  1342. - more info for temp management in .s file with EXTDEBUG
  1343. Revision 1.25 2002/10/20 14:49:31 peter
  1344. * store original source time in ppu so it can be compared instead of
  1345. comparing with the ppu time
  1346. Revision 1.24 2002/10/04 20:13:10 peter
  1347. * set in_second_load flag before resetting the module, this is
  1348. required to skip some checkings
  1349. Revision 1.23 2002/08/19 19:36:42 peter
  1350. * More fixes for cross unit inlining, all tnodes are now implemented
  1351. * Moved pocall_internconst to po_internconst because it is not a
  1352. calling type at all and it conflicted when inlining of these small
  1353. functions was requested
  1354. Revision 1.22 2002/08/18 19:58:28 peter
  1355. * more current_scanner fixes
  1356. Revision 1.21 2002/08/15 15:09:41 carl
  1357. + fpu emulation helpers (ppu checking also)
  1358. Revision 1.20 2002/08/12 16:46:04 peter
  1359. * tscannerfile is now destroyed in tmodule.reset and current_scanner
  1360. is updated accordingly. This removes all the loading and saving of
  1361. the old scanner and the invalid flag marking
  1362. Revision 1.19 2002/08/11 14:28:19 peter
  1363. * TScannerFile.SetInvalid added that will also reset inputfile
  1364. Revision 1.18 2002/08/11 13:24:11 peter
  1365. * saving of asmsymbols in ppu supported
  1366. * asmsymbollist global is removed and moved into a new class
  1367. tasmlibrarydata that will hold the info of a .a file which
  1368. corresponds with a single module. Added librarydata to tmodule
  1369. to keep the library info stored for the module. In the future the
  1370. objectfiles will also be stored to the tasmlibrarydata class
  1371. * all getlabel/newasmsymbol and friends are moved to the new class
  1372. Revision 1.17 2002/07/26 21:15:37 florian
  1373. * rewrote the system handling
  1374. Revision 1.16 2002/05/16 19:46:36 carl
  1375. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1376. + try to fix temp allocation (still in ifdef)
  1377. + generic constructor calls
  1378. + start of tassembler / tmodulebase class cleanup
  1379. Revision 1.15 2002/05/14 19:34:41 peter
  1380. * removed old logs and updated copyright year
  1381. Revision 1.14 2002/05/12 16:53:05 peter
  1382. * moved entry and exitcode to ncgutil and cgobj
  1383. * foreach gets extra argument for passing local data to the
  1384. iterator function
  1385. * -CR checks also class typecasts at runtime by changing them
  1386. into as
  1387. * fixed compiler to cycle with the -CR option
  1388. * fixed stabs with elf writer, finally the global variables can
  1389. be watched
  1390. * removed a lot of routines from cga unit and replaced them by
  1391. calls to cgobj
  1392. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1393. u32bit then the other is typecasted also to u32bit without giving
  1394. a rangecheck warning/error.
  1395. * fixed pascal calling method with reversing also the high tree in
  1396. the parast, detected by tcalcst3 test
  1397. Revision 1.13 2002/04/04 19:05:56 peter
  1398. * removed unused units
  1399. * use tlocation.size in cg.a_*loc*() routines
  1400. Revision 1.12 2002/03/28 20:46:44 carl
  1401. - remove go32v1 support
  1402. Revision 1.11 2002/01/19 14:20:13 peter
  1403. * check for -Un when loading ppu with wrong name
  1404. }