fppu.pas 49 KB

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