fppu.pas 85 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. This unit implements the first loading and searching of the modules
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit fppu;
  18. {$i fpcdefs.inc}
  19. { $define DEBUG_UNIT_CRC_CHANGES}
  20. { close ppufiles on system that are
  21. short on file handles like DOS system PM }
  22. {$ifdef GO32V2}
  23. {$define SHORT_ON_FILE_HANDLES}
  24. {$endif GO32V2}
  25. {$ifdef WATCOM}
  26. {$define SHORT_ON_FILE_HANDLES}
  27. {$endif WATCOM}
  28. interface
  29. uses
  30. cmsgs,verbose,
  31. cutils,cclasses,cstreams,
  32. globtype,globals,finput,fmodule,
  33. symbase,ppu,symtype;
  34. type
  35. { tppumodule }
  36. tppumodule = class(tmodule)
  37. ppufile : tcompilerppufile; { the PPU file }
  38. sourcefn : TPathStr; { Source specified with "uses .. in '..'" }
  39. comments : TCmdStrList;
  40. nsprefix : TCmdStr; { Namespace prefix the unit was found with }
  41. {$ifdef Test_Double_checksum}
  42. interface_read_crc_index,
  43. interface_write_crc_index,
  44. indirect_read_crc_index,
  45. indirect_write_crc_index,
  46. implementation_read_crc_index,
  47. implementation_write_crc_index : cardinal;
  48. interface_crc_array,
  49. indirect_crc_array,
  50. implementation_crc_array : pointer;
  51. {$endif def Test_Double_checksum}
  52. constructor create(LoadedFrom:TModule;const amodulename: string; const afilename:TPathStr;_is_unit:boolean);
  53. destructor destroy;override;
  54. procedure reset;override;
  55. procedure re_resolve(loadfrom: tmodule);
  56. function openppufile:boolean;
  57. function openppustream(strm:TCStream):boolean;
  58. procedure getppucrc;
  59. procedure writeppu;
  60. procedure loadppu(from_module : tmodule);
  61. procedure discardppu;
  62. function needrecompile:boolean;
  63. procedure setdefgeneration;
  64. procedure reload_flagged_units;
  65. procedure end_of_parsing;override;
  66. private
  67. unitimportsymsderefs : tfplist;
  68. { Each time a unit's defs are (re)created, its defsgeneration is
  69. set to the value of a global counter, and the global counter is
  70. increased. We only reresolve its dependent units' defs in case
  71. they have been resolved only for an older generation, in order to
  72. avoid endless resolving loops in case of cyclic dependencies. }
  73. defsgeneration : longint;
  74. function check_loadfrompackage: boolean;
  75. procedure check_reload(from_module: tmodule; var do_load: boolean);
  76. function openppu(ppufiletime:longint):boolean;
  77. procedure post_load_or_compile(second_time: boolean);
  78. procedure prepare_second_load(from_module: tmodule);
  79. procedure recompile_from_sources(from_module: tmodule);
  80. function search_unit_files(loaded_from : tmodule; onlysource:boolean):boolean;
  81. function search_unit(loaded_from : tmodule; onlysource,shortname:boolean):boolean;
  82. function loadfrompackage:boolean;
  83. procedure load_interface;
  84. procedure load_implementation;
  85. procedure load_usedunits;
  86. procedure printcomments;
  87. procedure queuecomment(const s:TMsgStr;v,w:longint);
  88. procedure buildderefunitimportsyms;
  89. procedure derefunitimportsyms;
  90. procedure freederefunitimportsyms;
  91. procedure try_load_ppufile(from_module: tmodule);
  92. procedure writesourcefiles;
  93. procedure writeusedunit(intf:boolean);
  94. procedure writelinkcontainer(var p:tlinkcontainer;id:byte;strippath:boolean);
  95. procedure writederefmap;
  96. procedure writederefdata;
  97. procedure writeImportSymbols;
  98. procedure writeResources;
  99. procedure writeOrderedSymbols;
  100. procedure writeunitimportsyms;
  101. procedure writeasmsyms(kind:tunitasmlisttype;list:tfphashobjectlist);
  102. procedure writeextraheader;
  103. procedure readsourcefiles;
  104. procedure readloadunit;
  105. procedure readlinkcontainer(var p:tlinkcontainer);
  106. procedure readderefmap;
  107. procedure readderefdata;
  108. procedure readImportSymbols;
  109. procedure readResources;
  110. procedure readOrderedSymbols;
  111. procedure readwpofile;
  112. procedure readunitimportsyms;
  113. procedure readasmsyms;
  114. procedure readextraheader;
  115. {$IFDEF MACRO_DIFF_HINT}
  116. procedure writeusedmacro(p:TNamedIndexItem;arg:pointer);
  117. procedure writeusedmacros;
  118. procedure readusedmacros;
  119. {$ENDIF}
  120. end;
  121. function registerunit(callermodule:tmodule;const s : TIDString;const fn:string) : tppumodule;
  122. implementation
  123. uses
  124. SysUtils,
  125. cfileutl,
  126. systems,version,options,
  127. symtable, symsym,
  128. wpoinfo,
  129. scanner,
  130. aasmbase,ogbase,
  131. parser,
  132. comphook,
  133. entfile,fpkg,fpcp;
  134. var
  135. currentdefgeneration: longint;
  136. {****************************************************************************
  137. TPPUMODULE
  138. ****************************************************************************}
  139. constructor tppumodule.create(LoadedFrom:TModule;const amodulename: string; const afilename:TPathStr;_is_unit:boolean);
  140. begin
  141. inherited create(LoadedFrom,amodulename,afilename,_is_unit);
  142. ppufile:=nil;
  143. sourcefn:=afilename;
  144. unitimportsymsderefs:=tfplist.create;
  145. end;
  146. destructor tppumodule.destroy;
  147. begin
  148. discardppu;
  149. comments.free;
  150. comments:=nil;
  151. { all derefs allocated with new
  152. are dispose'd inside this method }
  153. freederefunitimportsyms;
  154. unitimportsymsderefs.free;
  155. unitimportsymsderefs:=nil;
  156. inherited Destroy;
  157. end;
  158. procedure tppumodule.reset;
  159. begin
  160. inc(currentdefgeneration);
  161. discardppu;
  162. freederefunitimportsyms;
  163. unitimportsymsderefs.free;
  164. unitimportsymsderefs:=tfplist.create;
  165. inherited reset;
  166. end;
  167. procedure tppumodule.re_resolve(loadfrom: tmodule);
  168. begin
  169. Message1(unit_u_reresolving_unit,modulename^);
  170. if tstoredsymtable(globalsymtable).is_deref_built then
  171. tstoredsymtable(globalsymtable).deref(false);
  172. if tstoredsymtable(globalsymtable).is_derefimpl_built then
  173. tstoredsymtable(globalsymtable).derefimpl(false);
  174. if assigned(localsymtable) then
  175. begin
  176. { we have only builderef(impl)'d the registered symbols of
  177. the localsymtable -> also only deref those again }
  178. if tstoredsymtable(localsymtable).is_deref_built then
  179. tstoredsymtable(localsymtable).deref(true);
  180. if tstoredsymtable(localsymtable).is_derefimpl_built then
  181. tstoredsymtable(localsymtable).derefimpl(true);
  182. end;
  183. if assigned(wpoinfo) then
  184. begin
  185. tunitwpoinfo(wpoinfo).deref;
  186. tunitwpoinfo(wpoinfo).derefimpl;
  187. end;
  188. { We have to flag the units that depend on this unit even
  189. though it didn't change, because they might also
  190. indirectly depend on the unit that did change (e.g.,
  191. in case rgobj, rgx86 and rgcpu have been compiled
  192. already, and then rgobj is recompiled for some reason
  193. -> rgx86 is re-reresolved, but the vmtentries of trgcpu
  194. must also be re-resolved, because they will also contain
  195. pointers to procdefs in the old trgobj (in case of a
  196. recompile, all old defs are freed) }
  197. flagdependent(loadfrom);
  198. reload_flagged_units;
  199. end;
  200. procedure tppumodule.queuecomment(const s:TMsgStr;v,w:longint);
  201. begin
  202. if comments = nil then
  203. comments := TCmdStrList.create;
  204. comments.insert(s);
  205. end;
  206. procedure tppumodule.printcomments;
  207. var
  208. comment: string;
  209. begin
  210. if comments = nil then
  211. exit;
  212. { comments are inserted in reverse order }
  213. repeat
  214. comment := comments.getlast;
  215. if length(comment) = 0 then
  216. exit;
  217. do_comment(v_normal, comment);
  218. until false;
  219. end;
  220. function tppumodule.openppufile:boolean;
  221. var
  222. ppufiletime : longint;
  223. begin
  224. openppufile:=false;
  225. Message1(unit_t_ppu_loading,ppufilename,@queuecomment);
  226. { Get ppufile time (also check if the file exists) }
  227. ppufiletime:=getnamedfiletime(ppufilename);
  228. if ppufiletime=-1 then
  229. exit;
  230. { Open the ppufile }
  231. Message1(unit_u_ppu_name,ppufilename);
  232. ppufile:=tcompilerppufile.create(ppufilename);
  233. if not ppufile.openfile then
  234. begin
  235. discardppu;
  236. Message(unit_u_ppu_file_too_short);
  237. exit;
  238. end;
  239. result:=openppu(ppufiletime);
  240. end;
  241. function tppumodule.openppustream(strm:TCStream):boolean;
  242. begin
  243. result:=false;
  244. { Open the ppufile }
  245. Message1(unit_u_ppu_name,ppufilename);
  246. ppufile:=tcompilerppufile.create(ppufilename);
  247. if not ppufile.openstream(strm) then
  248. begin
  249. discardppu;
  250. Message(unit_u_ppu_file_too_short);
  251. exit;
  252. end;
  253. result:=openppu(-1);
  254. end;
  255. function tppumodule.openppu(ppufiletime:longint):boolean;
  256. function checkheader: boolean;
  257. begin
  258. result:=false;
  259. { check for a valid PPU file }
  260. if not ppufile.CheckPPUId then
  261. begin
  262. Message(unit_u_ppu_invalid_header);
  263. exit;
  264. end;
  265. { check for allowed PPU versions }
  266. if not (ppufile.getversion = CurrentPPUVersion) then
  267. begin
  268. Message1(unit_u_ppu_invalid_version,tostr(ppufile.getversion),@queuecomment);
  269. exit;
  270. end;
  271. { check the target processor }
  272. if tsystemcpu(ppufile.header.common.cpu)<>target_cpu then
  273. begin
  274. Message(unit_u_ppu_invalid_processor,@queuecomment);
  275. exit;
  276. end;
  277. { check target }
  278. if tsystem(ppufile.header.common.target)<>target_info.system then
  279. begin
  280. Message(unit_u_ppu_invalid_target,@queuecomment);
  281. exit;
  282. end;
  283. {$ifdef cpufpemu}
  284. { check if floating point emulation is on?
  285. fpu emulation isn't unit levelwise because it affects calling convention }
  286. if ((ppufile.header.common.flags and uf_fpu_emulation)<>0) <>
  287. (cs_fp_emulation in current_settings.moduleswitches) then
  288. begin
  289. Message(unit_u_ppu_invalid_fpumode,@queuecomment);
  290. exit;
  291. end;
  292. {$endif cpufpemu}
  293. result:=true;
  294. end;
  295. function checkextraheader: boolean;
  296. begin
  297. result:=false;
  298. if ppufile.readentry<>ibextraheader then
  299. begin
  300. Message(unit_u_ppu_invalid_header);
  301. exit;
  302. end;
  303. readextraheader;
  304. if (longversion<>CurrentPPULongVersion) or
  305. not ppufile.EndOfEntry then
  306. begin
  307. Message(unit_u_ppu_invalid_header);
  308. exit;
  309. end;
  310. {$ifdef i8086}
  311. { check i8086 memory model flags }
  312. if (mf_i8086_far_code in moduleflags) <>
  313. (current_settings.x86memorymodel in [mm_medium,mm_large,mm_huge]) then
  314. begin
  315. Message(unit_u_ppu_invalid_memory_model,@queuecomment);
  316. exit;
  317. end;
  318. if (mf_i8086_far_data in moduleflags) <>
  319. (current_settings.x86memorymodel in [mm_compact,mm_large]) then
  320. begin
  321. Message(unit_u_ppu_invalid_memory_model,@queuecomment);
  322. exit;
  323. end;
  324. if (mf_i8086_huge_data in moduleflags) <>
  325. (current_settings.x86memorymodel=mm_huge) then
  326. begin
  327. Message(unit_u_ppu_invalid_memory_model,@queuecomment);
  328. exit;
  329. end;
  330. if (mf_i8086_cs_equals_ds in moduleflags) <>
  331. (current_settings.x86memorymodel=mm_tiny) then
  332. begin
  333. Message(unit_u_ppu_invalid_memory_model,@queuecomment);
  334. exit;
  335. end;
  336. if (mf_i8086_ss_equals_ds in moduleflags) <>
  337. (current_settings.x86memorymodel in [mm_tiny,mm_small,mm_medium]) then
  338. begin
  339. Message(unit_u_ppu_invalid_memory_model,@queuecomment);
  340. exit;
  341. end;
  342. {$endif i8086}
  343. {$ifdef wasm}
  344. { check WebAssembly exceptions mode flag }
  345. if ((mf_wasm_no_exceptions in moduleflags) <>
  346. (ts_wasm_no_exceptions in current_settings.targetswitches)) or
  347. ((mf_wasm_bf_exceptions in moduleflags) <>
  348. (ts_wasm_bf_exceptions in current_settings.targetswitches)) or
  349. ((mf_wasm_js_exceptions in moduleflags) <>
  350. (ts_wasm_js_exceptions in current_settings.targetswitches)) or
  351. ((mf_wasm_native_exceptions in moduleflags) <>
  352. (ts_wasm_native_exceptions in current_settings.targetswitches)) then
  353. begin
  354. Message(unit_u_ppu_invalid_wasm_exceptions_mode,@queuecomment);
  355. exit;
  356. end;
  357. if (mf_wasm_threads in moduleflags) <>
  358. (ts_wasm_threads in current_settings.targetswitches) then
  359. begin
  360. Message(unit_u_ppu_wasm_threads_mismatch,@queuecomment);
  361. exit;
  362. end;
  363. {$endif}
  364. if {$ifdef symansistr}not{$endif}(mf_symansistr in moduleflags) then
  365. begin
  366. Message(unit_u_ppu_symansistr_mismatch,@queuecomment);
  367. exit;
  368. end;
  369. if {$ifdef llvm}not{$endif}(mf_llvm in moduleflags) then
  370. begin
  371. Message(unit_u_ppu_llvm_mismatch,@queuecomment);
  372. exit;
  373. end;
  374. result:=true;
  375. end;
  376. begin
  377. openppu:=false;
  378. if not checkheader or
  379. not checkextraheader then
  380. begin
  381. discardppu;
  382. exit;
  383. end;
  384. { Load values to be access easier }
  385. headerflags:=ppufile.header.common.flags;
  386. crc:=ppufile.header.checksum;
  387. interface_crc:=ppufile.header.interface_checksum;
  388. indirect_crc:=ppufile.header.indirect_checksum;
  389. change_endian:=ppufile.change_endian;
  390. { Show Debug info }
  391. if ppufiletime<>-1 then
  392. Message1(unit_u_ppu_time,filetimestring(ppufiletime))
  393. else
  394. Message1(unit_u_ppu_time,'unknown');
  395. Message1(unit_u_ppu_flags,tostr(headerflags));
  396. Message1(unit_u_ppu_crc,hexstr(ppufile.header.checksum,8));
  397. Message1(unit_u_ppu_crc,hexstr(ppufile.header.interface_checksum,8)+' (intfc)');
  398. Message1(unit_u_ppu_crc,hexstr(ppufile.header.indirect_checksum,8)+' (indc)');
  399. Comment(V_used,'Number of definitions: '+tostr(ppufile.header.deflistsize));
  400. Comment(V_used,'Number of symbols: '+tostr(ppufile.header.symlistsize));
  401. do_compile:=false;
  402. openppu:=true;
  403. end;
  404. function tppumodule.search_unit_files(loaded_from : tmodule; onlysource:boolean):boolean;
  405. var
  406. found : boolean;
  407. begin
  408. found:=false;
  409. if search_unit(loaded_from,onlysource,false) then
  410. found:=true;
  411. if (not found) and
  412. (ft83 in AllowedFilenameTransFormations) and
  413. (length(modulename^)>8) and
  414. search_unit(loaded_from,onlysource,true) then
  415. found:=true;
  416. search_unit_files:=found;
  417. end;
  418. function tppumodule.search_unit(loaded_from : tmodule; onlysource,shortname:boolean):boolean;
  419. var
  420. singlepathstring,
  421. filename : TCmdStr;
  422. Function UnitExists(const ext:string;var foundfile:TCmdStr;const prefix:TCmdStr):boolean;
  423. var
  424. s : tcmdstr;
  425. begin
  426. if CheckVerbosity(V_Tried) then
  427. Message1(unit_t_unitsearch,Singlepathstring+filename+ext);
  428. s:=FileName+ext;
  429. if prefix<>'' then
  430. s:=prefix+'.'+s;
  431. UnitExists:=FindFile(s,Singlepathstring,true,foundfile);
  432. end;
  433. Function PPUSearchPath(const s,prefix:TCmdStr):boolean;
  434. var
  435. found : boolean;
  436. hs,
  437. newname : TCmdStr;
  438. begin
  439. Found:=false;
  440. singlepathstring:=FixPath(s,false);
  441. { Check for PPU file }
  442. Found:=UnitExists(target_info.unitext,hs,prefix);
  443. if Found then
  444. Begin
  445. SetFileName(hs,false);
  446. if prefix<>'' then
  447. begin
  448. newname:=prefix+'.'+realmodulename^;
  449. stringdispose(realmodulename);
  450. realmodulename:=stringdup(newname);
  451. stringdispose(modulename);
  452. modulename:=stringdup(upper(newname));
  453. end;
  454. Found:=openppufile;
  455. End;
  456. PPUSearchPath:=Found;
  457. end;
  458. Function SourceSearchPath(const s,prefix:TCmdStr):boolean;
  459. var
  460. found : boolean;
  461. hs,
  462. newname : TCmdStr;
  463. begin
  464. Found:=false;
  465. singlepathstring:=FixPath(s,false);
  466. { Check for Sources }
  467. ppufile:=nil;
  468. do_compile:=true;
  469. recompile_reason:=rr_noppu;
  470. {Check for .pp file}
  471. Found:=UnitExists(sourceext,hs,prefix);
  472. if not Found then
  473. begin
  474. { Check for .pas }
  475. Found:=UnitExists(pasext,hs,prefix);
  476. end;
  477. if not Found and
  478. ((m_mac in current_settings.modeswitches) or
  479. (tf_p_ext_support in target_info.flags)) then
  480. begin
  481. { Check for .p, if mode is macpas}
  482. Found:=UnitExists(pext,hs,prefix);
  483. end;
  484. mainsource:='';
  485. if Found then
  486. begin
  487. sources_avail:=true;
  488. { Load Filenames when found }
  489. mainsource:=hs;
  490. SetFileName(hs,false);
  491. if prefix<>'' then
  492. begin
  493. newname:=prefix+'.'+realmodulename^;
  494. stringdispose(realmodulename);
  495. realmodulename:=stringdup(newname);
  496. stringdispose(modulename);
  497. modulename:=stringdup(upper(newname));
  498. end;
  499. end
  500. else
  501. sources_avail:=false;
  502. SourceSearchPath:=Found;
  503. end;
  504. Function SearchPath(const s,prefix:TCmdStr):boolean;
  505. var
  506. found : boolean;
  507. begin
  508. { First check for a ppu, then for the source }
  509. found:=false;
  510. if not onlysource then
  511. found:=PPUSearchPath(s,prefix);
  512. if not found then
  513. found:=SourceSearchPath(s,prefix);
  514. SearchPath:=found;
  515. end;
  516. Function SearchPathList(list:TSearchPathList;const prefix:TCmdStr):boolean;
  517. var
  518. hp : TCmdStrListItem;
  519. found : boolean;
  520. begin
  521. found:=false;
  522. hp:=TCmdStrListItem(list.First);
  523. while assigned(hp) do
  524. begin
  525. found:=SearchPath(hp.Str,prefix);
  526. if found then
  527. break;
  528. hp:=TCmdStrListItem(hp.next);
  529. end;
  530. SearchPathList:=found;
  531. end;
  532. function SearchPPUPaths(const prefix:TCmdStr):boolean;
  533. begin
  534. result:=PPUSearchPath('.',prefix);
  535. if (not result) and (outputpath<>'') then
  536. result:=PPUSearchPath(outputpath,prefix);
  537. if (not result) and Assigned(main_module) and (main_module.Path<>'') then
  538. result:=PPUSearchPath(main_module.Path,prefix);
  539. end;
  540. function SearchSourcePaths(const prefix:TCmdStr):boolean;
  541. begin
  542. result:=SourceSearchPath('.',prefix);
  543. if (not result) and Assigned(main_module) and (main_module.Path<>'') then
  544. result:=SourceSearchPath(main_module.Path,prefix);
  545. if (not result) and Assigned(loaded_from) then
  546. result:=SearchPathList(loaded_from.LocalUnitSearchPath,prefix);
  547. if not result then
  548. result:=SearchPathList(UnitSearchPath,prefix);
  549. end;
  550. function SearchNamespaceList(const prefixes:TCmdStrList):boolean;
  551. var
  552. nsitem : TCmdStrListItem;
  553. res : Boolean;
  554. begin
  555. res:=false;
  556. nsitem:=TCmdStrListItem(prefixes.first);
  557. while assigned(nsitem) do
  558. begin
  559. if not onlysource then
  560. begin
  561. res:=SearchPPUPaths(nsitem.str);
  562. if res then
  563. break;
  564. end;
  565. res:=SearchSourcePaths(nsitem.str);
  566. if res then
  567. break;
  568. nsitem:=TCmdStrListItem(nsitem.next);
  569. end;
  570. if assigned(nsitem) then
  571. nsprefix:=nsitem.str;
  572. result:=res;
  573. end;
  574. var
  575. fnd : boolean;
  576. hs : TPathStr;
  577. begin
  578. if shortname then
  579. filename:=FixFileName(Copy(realmodulename^,1,8))
  580. else
  581. filename:=FixFileName(realmodulename^);
  582. { try to find unit
  583. 1. look for ppu in cwd
  584. 2. look for ppu in outputpath if set, this is tp7 compatible (PFV)
  585. 3. look for ppu in maindir
  586. 4. look for the specified source file (from the uses line)
  587. 5. look for source in cwd
  588. 6. look for source in maindir
  589. 7. local unit pathlist
  590. 8. global unit pathlist
  591. 9. for each default namespace:
  592. repeat 1 - 3 and 5 - 8 with namespace as prefix }
  593. fnd:=false;
  594. if not onlysource then
  595. fnd:=SearchPPUPaths('');
  596. if (not fnd) and (sourcefn<>'') then
  597. begin
  598. { the full filename is specified so we can't use here the
  599. searchpath (PFV) }
  600. if CheckVerbosity(V_Tried) then
  601. Message1(unit_t_unitsearch,ChangeFileExt(sourcefn,sourceext));
  602. fnd:=FindFile(ChangeFileExt(sourcefn,sourceext),'',true,hs);
  603. if not fnd then
  604. begin
  605. if CheckVerbosity(V_Tried) then
  606. Message1(unit_t_unitsearch,ChangeFileExt(sourcefn,pasext));
  607. fnd:=FindFile(ChangeFileExt(sourcefn,pasext),'',true,hs);
  608. end;
  609. if not fnd and
  610. ((m_mac in current_settings.modeswitches) or
  611. (tf_p_ext_support in target_info.flags)) then
  612. begin
  613. if CheckVerbosity(V_Tried) then
  614. Message1(unit_t_unitsearch,ChangeFileExt(sourcefn,pext));
  615. fnd:=FindFile(ChangeFileExt(sourcefn,pext),'',true,hs);
  616. end;
  617. if fnd then
  618. begin
  619. sources_avail:=true;
  620. do_compile:=true;
  621. recompile_reason:=rr_noppu;
  622. mainsource:=hs;
  623. SetFileName(hs,false);
  624. end;
  625. end;
  626. if not fnd then
  627. begin
  628. fnd:=SearchSourcePaths('');
  629. // current_namespacelist is set to the current module's namespacelist.
  630. if not fnd and assigned(current_namespacelist) and (current_namespacelist.count>0) then
  631. fnd:=SearchNameSpaceList(current_namespacelist);
  632. if not fnd and (namespacelist.count>0) then
  633. fnd:=SearchNameSpaceList(namespacelist);
  634. end;
  635. search_unit:=fnd;
  636. end;
  637. function tppumodule.loadfrompackage: boolean;
  638. (*var
  639. singlepathstring,
  640. filename : TCmdStr;
  641. Function UnitExists(const ext:string;var foundfile:TCmdStr):boolean;
  642. begin
  643. if CheckVerbosity(V_Tried) then
  644. Message1(unit_t_unitsearch,Singlepathstring+filename);
  645. UnitExists:=FindFile(FileName,Singlepathstring,true,foundfile);
  646. end;
  647. Function PPUSearchPath(const s:TCmdStr):boolean;
  648. var
  649. found : boolean;
  650. hs : TCmdStr;
  651. begin
  652. Found:=false;
  653. singlepathstring:=FixPath(s,false);
  654. { Check for PPU file }
  655. Found:=UnitExists(target_info.unitext,hs);
  656. if Found then
  657. Begin
  658. SetFileName(hs,false);
  659. //Found:=OpenPPU;
  660. End;
  661. PPUSearchPath:=Found;
  662. end;
  663. Function SearchPathList(list:TSearchPathList):boolean;
  664. var
  665. hp : TCmdStrListItem;
  666. found : boolean;
  667. begin
  668. found:=false;
  669. hp:=TCmdStrListItem(list.First);
  670. while assigned(hp) do
  671. begin
  672. found:=PPUSearchPath(hp.Str);
  673. if found then
  674. break;
  675. hp:=TCmdStrListItem(hp.next);
  676. end;
  677. SearchPathList:=found;
  678. end;*)
  679. var
  680. pkg : ppackageentry;
  681. pkgunit : pcontainedunit;
  682. i,idx : longint;
  683. strm : TCStream;
  684. begin
  685. result:=false;
  686. for i:=0 to packagelist.count-1 do
  687. begin
  688. pkg:=ppackageentry(packagelist[i]);
  689. if not assigned(pkg^.package) then
  690. internalerror(2013053103);
  691. idx:=pkg^.package.containedmodules.FindIndexOf(modulename^);
  692. if idx>=0 then
  693. begin
  694. { the unit is part of this package }
  695. pkgunit:=pcontainedunit(pkg^.package.containedmodules[idx]);
  696. if not assigned(pkgunit^.module) then
  697. pkgunit^.module:=self;
  698. { ToDo: check whether we really don't need this anymore }
  699. {filename:=pkgunit^.ppufile;
  700. if not SearchPathList(unitsearchpath) then
  701. exit};
  702. strm:=tpcppackage(pkg^.package).getmodulestream(self);
  703. if not assigned(strm) then
  704. internalerror(2015103002);
  705. if not openppustream(strm) then
  706. exit;
  707. package:=pkg^.package;
  708. Message2(unit_u_loading_from_package,modulename^,pkg^.package.packagename^);
  709. { now load the unit and all used units }
  710. load_interface;
  711. setdefgeneration;
  712. load_usedunits;
  713. Message1(unit_u_finished_loading_unit,modulename^);
  714. result:=true;
  715. break;
  716. end;
  717. end;
  718. end;
  719. procedure tppumodule.buildderefunitimportsyms;
  720. var
  721. i : longint;
  722. deref : pderef;
  723. begin
  724. for i:=0 to unitimportsyms.count-1 do
  725. begin
  726. new(deref);
  727. deref^.build(unitimportsyms[i]);
  728. unitimportsymsderefs.add(deref);
  729. end;
  730. end;
  731. procedure tppumodule.derefunitimportsyms;
  732. var
  733. i : longint;
  734. sym : tsym;
  735. begin
  736. for i:=0 to unitimportsymsderefs.count-1 do
  737. begin
  738. sym:=tsym(pderef(unitimportsymsderefs[i])^.resolve);
  739. unitimportsyms.add(sym);
  740. end;
  741. end;
  742. procedure tppumodule.freederefunitimportsyms;
  743. var
  744. i : longint;
  745. deref : pderef;
  746. begin
  747. for i:=0 to unitimportsymsderefs.count-1 do
  748. begin
  749. deref:=pderef(unitimportsymsderefs[i]);
  750. system.dispose(deref);
  751. end;
  752. end;
  753. {**********************************
  754. PPU Reading/Writing Helpers
  755. ***********************************}
  756. {$IFDEF MACRO_DIFF_HINT}
  757. var
  758. is_initial: Boolean;
  759. procedure tppumodule.writeusedmacro(p:TNamedIndexItem;arg:pointer);
  760. begin
  761. if tmacro(p).is_used or is_initial then
  762. begin
  763. ppufile.putstring(p.name);
  764. ppufile.putboolean(is_initial);
  765. ppufile.putboolean(tmacro(p).is_used);
  766. end;
  767. end;
  768. procedure tppumodule.writeusedmacros;
  769. begin
  770. ppufile.do_crc:=false;
  771. is_initial:= true;
  772. initialmacrosymtable.foreach(@writeusedmacro,nil);
  773. is_initial:= false;
  774. if assigned(globalmacrosymtable) then
  775. globalmacrosymtable.foreach(@writeusedmacro,nil);
  776. localmacrosymtable.foreach(@writeusedmacro,nil);
  777. ppufile.writeentry(ibusedmacros);
  778. ppufile.do_crc:=true;
  779. end;
  780. {$ENDIF}
  781. procedure tppumodule.writesourcefiles;
  782. var
  783. hp : tinputfile;
  784. ifile : sizeint;
  785. begin
  786. { second write the used source files }
  787. ppufile.do_crc:=false;
  788. { write source files directly in good order }
  789. for ifile:=0 to sourcefiles.nfiles-1 do
  790. begin
  791. hp:=sourcefiles.files[ifile];
  792. ppufile.putstring(hp.inc_path+hp.name);
  793. ppufile.putlongint(hp.getfiletime);
  794. end;
  795. ppufile.writeentry(ibsourcefiles);
  796. ppufile.do_crc:=true;
  797. end;
  798. procedure tppumodule.writeusedunit(intf:boolean);
  799. var
  800. hp : tused_unit;
  801. oldcrc : boolean;
  802. begin
  803. { write a reference for each used unit }
  804. hp:=tused_unit(used_units.first);
  805. while assigned(hp) do
  806. begin
  807. if hp.in_interface=intf then
  808. begin
  809. ppufile.putstring(hp.u.realmodulename^);
  810. { the checksum should not affect the crc of this unit ! (PFV) }
  811. oldcrc:=ppufile.do_crc;
  812. ppufile.do_crc:=false;
  813. ppufile.putlongint(longint(hp.checksum));
  814. ppufile.putlongint(longint(hp.interface_checksum));
  815. ppufile.putlongint(longint(hp.indirect_checksum));
  816. ppufile.do_crc:=oldcrc;
  817. { combine all indirect checksums from units used by this unit }
  818. if intf then
  819. ppufile.indirect_crc:=ppufile.indirect_crc xor hp.indirect_checksum;
  820. end;
  821. hp:=tused_unit(hp.next);
  822. end;
  823. ppufile.do_interface_crc:=true;
  824. ppufile.writeentry(ibloadunit);
  825. end;
  826. procedure tppumodule.writelinkcontainer(var p:tlinkcontainer;id:byte;strippath:boolean);
  827. var
  828. hcontainer : tlinkcontainer;
  829. s : TPathStr;
  830. mask : cardinal;
  831. begin
  832. hcontainer:=TLinkContainer.Create;
  833. while not p.empty do
  834. begin
  835. s:=p.get(mask);
  836. if strippath then
  837. ppufile.putstring(ExtractFileName(s))
  838. else
  839. ppufile.putstring(s);
  840. ppufile.putlongint(mask);
  841. hcontainer.add(s,mask);
  842. end;
  843. ppufile.writeentry(id);
  844. p.Free;
  845. p:=hcontainer;
  846. end;
  847. procedure tppumodule.writederefmap;
  848. var
  849. i : longint;
  850. oldcrc : boolean;
  851. begin
  852. { This does not influence crc }
  853. oldcrc:=ppufile.do_crc;
  854. ppufile.do_crc:=false;
  855. { The unit map used for resolving }
  856. ppufile.putlongint(derefmapcnt);
  857. for i:=0 to derefmapcnt-1 do
  858. begin
  859. if not assigned(derefmap[i].u) then
  860. internalerror(2005011512);
  861. ppufile.putstring(derefmap[i].u.modulename^)
  862. end;
  863. ppufile.writeentry(ibderefmap);
  864. ppufile.do_crc:=oldcrc;
  865. end;
  866. procedure tppumodule.writederefdata;
  867. var
  868. oldcrc : boolean;
  869. len,hlen : longint;
  870. buf : array[0..1023] of byte;
  871. begin
  872. if longword(derefdataintflen)>derefdata.size then
  873. internalerror(200310223);
  874. derefdata.seek(0);
  875. { Write interface data }
  876. len:=derefdataintflen;
  877. while (len>0) do
  878. begin
  879. if len>1024 then
  880. hlen:=1024
  881. else
  882. hlen:=len;
  883. derefdata.read(buf,hlen);
  884. ppufile.putdata(buf,hlen);
  885. dec(len,hlen);
  886. end;
  887. { Write implementation data, this does not influence crc }
  888. oldcrc:=ppufile.do_crc;
  889. ppufile.do_crc:=false;
  890. len:=derefdata.size-derefdataintflen;
  891. while (len>0) do
  892. begin
  893. if len>1024 then
  894. hlen:=1024
  895. else
  896. hlen:=len;
  897. derefdata.read(buf,hlen);
  898. ppufile.putdata(buf,hlen);
  899. dec(len,hlen);
  900. end;
  901. if derefdata.pos<>derefdata.size then
  902. internalerror(200310224);
  903. ppufile.do_crc:=oldcrc;
  904. ppufile.writeentry(ibderefdata);
  905. end;
  906. procedure tppumodule.writeImportSymbols;
  907. var
  908. i,j : longint;
  909. ImportLibrary : TImportLibrary;
  910. ImportSymbol : TImportSymbol;
  911. begin
  912. for i:=0 to ImportLibraryList.Count-1 do
  913. begin
  914. ImportLibrary:=TImportLibrary(ImportLibraryList[i]);
  915. ppufile.putstring(ImportLibrary.Name);
  916. ppufile.putlongint(ImportLibrary.ImportSymbolList.Count);
  917. for j:=0 to ImportLibrary.ImportSymbolList.Count-1 do
  918. begin
  919. ImportSymbol:=TImportSymbol(ImportLibrary.ImportSymbolList[j]);
  920. ppufile.putstring(ImportSymbol.Name);
  921. ppufile.putstring(ImportSymbol.MangledName);
  922. ppufile.putlongint(ImportSymbol.OrdNr);
  923. ppufile.putbyte(byte(ImportSymbol.IsVar));
  924. end;
  925. end;
  926. ppufile.writeentry(ibImportSymbols);
  927. end;
  928. procedure tppumodule.writeResources;
  929. var
  930. res : TCmdStrListItem;
  931. begin
  932. res:=TCmdStrListItem(ResourceFiles.First);
  933. while res<>nil do
  934. begin
  935. ppufile.putstring(res.FPStr);
  936. res:=TCmdStrListItem(res.Next);
  937. end;
  938. ppufile.writeentry(ibresources);
  939. end;
  940. procedure tppumodule.writeOrderedSymbols;
  941. var
  942. res : TCmdStrListItem;
  943. begin
  944. res:=TCmdStrListItem(linkorderedsymbols.First);
  945. while res<>nil do
  946. begin
  947. ppufile.putstring(res.FPStr);
  948. res:=TCmdStrListItem(res.Next);
  949. end;
  950. ppufile.writeentry(iborderedsymbols);
  951. end;
  952. procedure tppumodule.writeunitimportsyms;
  953. var
  954. i : longint;
  955. begin
  956. ppufile.putlongint(unitimportsymsderefs.count);
  957. for i:=0 to unitimportsymsderefs.count-1 do
  958. ppufile.putderef(pderef(unitimportsymsderefs[i])^);
  959. ppufile.writeentry(ibunitimportsyms);
  960. end;
  961. procedure tppumodule.writeasmsyms(kind:tunitasmlisttype;list:tfphashobjectlist);
  962. var
  963. i : longint;
  964. sym : TAsmSymbol;
  965. begin
  966. ppufile.putbyte(ord(kind));
  967. ppufile.putlongint(list.count);
  968. for i:=0 to list.count-1 do
  969. begin
  970. sym:=TAsmSymbol(list[i]);
  971. ppufile.putstring(sym.Name);
  972. ppufile.putbyte(ord(sym.bind));
  973. ppufile.putbyte(ord(sym.typ));
  974. end;
  975. ppufile.writeentry(ibasmsymbols);
  976. end;
  977. procedure tppumodule.writeextraheader;
  978. var
  979. old_docrc: boolean;
  980. begin
  981. { create unit flags }
  982. if do_release then
  983. include(moduleflags,mf_release);
  984. if assigned(localsymtable) then
  985. include(moduleflags,mf_local_symtable);
  986. if cs_checkpointer_called in current_settings.moduleswitches then
  987. include(moduleflags,mf_checkpointer_called);
  988. if cs_compilesystem in current_settings.moduleswitches then
  989. include(moduleflags,mf_system_unit);
  990. {$ifdef i8086}
  991. if current_settings.x86memorymodel in [mm_medium,mm_large,mm_huge] then
  992. include(moduleflags,mf_i8086_far_code);
  993. if current_settings.x86memorymodel in [mm_compact,mm_large] then
  994. include(moduleflags,mf_i8086_far_data);
  995. if current_settings.x86memorymodel=mm_huge then
  996. include(moduleflags,mf_i8086_huge_data);
  997. if current_settings.x86memorymodel=mm_tiny then
  998. include(moduleflags,mf_i8086_cs_equals_ds);
  999. if current_settings.x86memorymodel in [mm_tiny,mm_small,mm_medium] then
  1000. include(moduleflags,mf_i8086_ss_equals_ds);
  1001. {$endif i8086}
  1002. {$ifdef wasm}
  1003. if ts_wasm_no_exceptions in current_settings.targetswitches then
  1004. include(moduleflags,mf_wasm_no_exceptions);
  1005. if ts_wasm_native_exceptions in current_settings.targetswitches then
  1006. include(moduleflags,mf_wasm_native_exceptions);
  1007. if ts_wasm_js_exceptions in current_settings.targetswitches then
  1008. include(moduleflags,mf_wasm_js_exceptions);
  1009. if ts_wasm_bf_exceptions in current_settings.targetswitches then
  1010. include(moduleflags,mf_wasm_bf_exceptions);
  1011. if ts_wasm_threads in current_settings.targetswitches then
  1012. include(moduleflags,mf_wasm_threads);
  1013. {$endif wasm}
  1014. {$ifdef llvm}
  1015. include(moduleflags,mf_llvm);
  1016. {$endif}
  1017. {$ifdef symansistr}
  1018. include(moduleflags,mf_symansistr);
  1019. {$endif}
  1020. old_docrc:=ppufile.do_crc;
  1021. ppufile.do_crc:=false;
  1022. ppufile.putlongint(longint(CurrentPPULongVersion));
  1023. ppufile.putset(tppuset4(moduleflags));
  1024. ppufile.writeentry(ibextraheader);
  1025. ppufile.do_crc:=old_docrc;
  1026. end;
  1027. {$IFDEF MACRO_DIFF_HINT}
  1028. {
  1029. Define MACRO_DIFF_HINT for the whole compiler (and ppudump)
  1030. to turn this facility on. Also the hint messages defined
  1031. below must be commented in in the msg/errore.msg file.
  1032. There is some problems with this, thats why it is shut off:
  1033. At the first compilation, consider a macro which is not initially
  1034. defined, but it is used (e g the check that it is undefined is true).
  1035. Since it do not exist, there is no macro object where the is_used
  1036. flag can be set. Later on when the macro is defined, and the ppu
  1037. is opened, the check cannot detect this.
  1038. Also, in which macro object should this flag be set ? It cant be set
  1039. for macros in the initialmacrosymboltable since this table is shared
  1040. between different files.
  1041. }
  1042. procedure tppumodule.readusedmacros;
  1043. var
  1044. hs : string;
  1045. mac : tmacro;
  1046. was_initial,
  1047. was_used : boolean;
  1048. {Reads macros which was defined or used when the module was compiled.
  1049. This is done when a ppu file is open, before it possibly is parsed.}
  1050. begin
  1051. while not ppufile.endofentry do
  1052. begin
  1053. hs:=ppufile.getstring;
  1054. was_initial:=ppufile.getboolean;
  1055. was_used:=ppufile.getboolean;
  1056. mac:=tmacro(initialmacrosymtable.Find(hs));
  1057. if assigned(mac) then
  1058. begin
  1059. {$ifndef EXTDEBUG}
  1060. { if we don't have the sources why tell }
  1061. if sources_avail then
  1062. {$endif ndef EXTDEBUG}
  1063. if (not was_initial) and was_used then
  1064. Message2(unit_h_cond_not_set_in_last_compile,hs,mainsource^);
  1065. end
  1066. else { not assigned }
  1067. if was_initial and
  1068. was_used then
  1069. Message2(unit_h_cond_set_in_last_compile,hs,mainsource^);
  1070. end;
  1071. end;
  1072. {$ENDIF}
  1073. procedure tppumodule.readsourcefiles;
  1074. var
  1075. temp,hs : string;
  1076. inc_path : string;
  1077. temp_dir : TCmdStr;
  1078. main_dir : TCmdStr;
  1079. found,
  1080. is_main : boolean;
  1081. orgfiletime,
  1082. source_time : longint;
  1083. hp : tinputfile;
  1084. begin
  1085. sources_avail:=not(mf_release in moduleflags);
  1086. is_main:=true;
  1087. main_dir:='';
  1088. while not ppufile.endofentry do
  1089. begin
  1090. hs:=SetDirSeparators(ppufile.getstring);
  1091. inc_path:=ExtractFilePath(hs);
  1092. orgfiletime:=ppufile.getlongint;
  1093. temp_dir:='';
  1094. if sources_avail then
  1095. begin
  1096. if (headerflags and uf_in_library)<>0 then
  1097. begin
  1098. sources_avail:=false;
  1099. temp:=' library';
  1100. end
  1101. else if pos('Macro ',hs)=1 then
  1102. begin
  1103. { we don't want to find this file }
  1104. { but there is a problem with file indexing !! }
  1105. temp:='';
  1106. end
  1107. else
  1108. begin
  1109. { check the date of the source files:
  1110. 1 path of sourcefn
  1111. 2 path of ppu
  1112. 3 path of main source
  1113. 4 current dir
  1114. 5 include/unit path }
  1115. found:=false;
  1116. if sourcefn<>'' then
  1117. begin
  1118. temp_dir:=ExtractFilePath(SetDirSeparators(sourcefn));
  1119. Source_Time:=GetNamedFileTime(temp_dir+hs);
  1120. if Source_Time<>-1 then
  1121. hs:=temp_dir+hs;
  1122. end else
  1123. Source_Time:=-1;
  1124. if Source_Time=-1 then
  1125. begin
  1126. Source_Time:=GetNamedFileTime(path+hs);
  1127. if Source_Time<>-1 then
  1128. hs:=path+hs
  1129. else
  1130. if not(is_main) then
  1131. begin
  1132. Source_Time:=GetNamedFileTime(main_dir+hs);
  1133. if Source_Time<>-1 then
  1134. hs:=main_dir+hs;
  1135. end;
  1136. end;
  1137. if Source_Time=-1 then
  1138. Source_Time:=GetNamedFileTime(hs);
  1139. if (Source_Time=-1) then
  1140. begin
  1141. if is_main then
  1142. found:=unitsearchpath.FindFile(hs,true,temp_dir)
  1143. else
  1144. found:=includesearchpath.FindFile(hs,true,temp_dir);
  1145. if found then
  1146. begin
  1147. Source_Time:=GetNamedFileTime(temp_dir);
  1148. if Source_Time<>-1 then
  1149. hs:=temp_dir;
  1150. end;
  1151. end;
  1152. if Source_Time<>-1 then
  1153. begin
  1154. if is_main then
  1155. main_dir:=ExtractFilePath(hs);
  1156. temp:=' time '+filetimestring(source_time);
  1157. if (orgfiletime<>-1) and
  1158. (source_time<>orgfiletime) then
  1159. begin
  1160. do_compile:=true;
  1161. recompile_reason:=rr_sourcenewer;
  1162. Message2(unit_u_source_modified,hs,ppufilename,@queuecomment);
  1163. temp:=temp+' *';
  1164. end;
  1165. end
  1166. else
  1167. begin
  1168. sources_avail:=false;
  1169. temp:=' not found';
  1170. end;
  1171. hp:=tdosinputfile.create(hs);
  1172. hp.inc_path:=inc_path;
  1173. { the indexing is wrong here PM }
  1174. sourcefiles.register_file(hp);
  1175. end;
  1176. end
  1177. else
  1178. begin
  1179. { still register the source module for proper error messages
  1180. since source_avail for the module is still false, this should not hurt }
  1181. sourcefiles.register_file(tdosinputfile.create(hs));
  1182. temp:=' not available';
  1183. end;
  1184. if is_main then
  1185. begin
  1186. mainsource:=hs;
  1187. end;
  1188. Message1(unit_u_ppu_source,hs+temp,@queuecomment);
  1189. is_main:=false;
  1190. end;
  1191. { check if we want to rebuild every unit, only if the sources are
  1192. available }
  1193. if do_build and sources_avail then
  1194. begin
  1195. do_compile:=true;
  1196. recompile_reason:=rr_build;
  1197. end;
  1198. end;
  1199. procedure tppumodule.readloadunit;
  1200. var
  1201. hs : string;
  1202. pu : tused_unit;
  1203. hp : tppumodule;
  1204. indchecksum,
  1205. intfchecksum,
  1206. checksum : cardinal;
  1207. begin
  1208. while not ppufile.endofentry do
  1209. begin
  1210. hs:=ppufile.getstring;
  1211. checksum:=cardinal(ppufile.getlongint);
  1212. intfchecksum:=cardinal(ppufile.getlongint);
  1213. indchecksum:=cardinal(ppufile.getlongint);
  1214. { set the state of this unit before registering, this is
  1215. needed for a correct circular dependency check }
  1216. hp:=registerunit(self,hs,'');
  1217. pu:=addusedunit(hp,false,nil);
  1218. pu.checksum:=checksum;
  1219. pu.interface_checksum:=intfchecksum;
  1220. pu.indirect_checksum:=indchecksum;
  1221. end;
  1222. in_interface:=false;
  1223. end;
  1224. procedure tppumodule.readlinkcontainer(var p:tlinkcontainer);
  1225. var
  1226. s : string;
  1227. m : longint;
  1228. begin
  1229. while not ppufile.endofentry do
  1230. begin
  1231. s:=ppufile.getstring;
  1232. m:=ppufile.getlongint;
  1233. p.add(s,m);
  1234. end;
  1235. end;
  1236. procedure tppumodule.readderefmap;
  1237. var
  1238. i : longint;
  1239. begin
  1240. { Load unit map used for resolving }
  1241. derefmapsize:=ppufile.getlongint;
  1242. derefmapcnt:=derefmapsize;
  1243. getmem(derefmap,derefmapsize*sizeof(tderefmaprec));
  1244. fillchar(derefmap^,derefmapsize*sizeof(tderefmaprec),0);
  1245. for i:=0 to derefmapsize-1 do
  1246. derefmap[i].modulename:=ppufile.getpshortstring;
  1247. end;
  1248. procedure tppumodule.readderefdata;
  1249. var
  1250. len,hlen : longint;
  1251. buf : array[0..1023] of byte;
  1252. begin
  1253. len:=ppufile.entrysize;
  1254. while (len>0) do
  1255. begin
  1256. if len>1024 then
  1257. hlen:=1024
  1258. else
  1259. hlen:=len;
  1260. ppufile.getdata(buf,hlen);
  1261. derefdata.write(buf,hlen);
  1262. dec(len,hlen);
  1263. end;
  1264. end;
  1265. procedure tppumodule.readImportSymbols;
  1266. var
  1267. j,
  1268. extsymcnt : longint;
  1269. ImportLibrary : TImportLibrary;
  1270. extsymname : string;
  1271. extsymmangledname : string;
  1272. extsymordnr : longint;
  1273. extsymisvar : boolean;
  1274. begin
  1275. while not ppufile.endofentry do
  1276. begin
  1277. ImportLibrary:=TImportLibrary.Create(ImportLibraryList,ppufile.getstring);
  1278. extsymcnt:=ppufile.getlongint;
  1279. for j:=0 to extsymcnt-1 do
  1280. begin
  1281. extsymname:=ppufile.getstring;
  1282. extsymmangledname:=ppufile.getstring;
  1283. extsymordnr:=ppufile.getlongint;
  1284. extsymisvar:=(ppufile.getbyte<>0);
  1285. TImportSymbol.Create(ImportLibrary.ImportSymbolList,extsymname,
  1286. extsymmangledname,extsymordnr,extsymisvar);
  1287. end;
  1288. end;
  1289. end;
  1290. procedure tppumodule.readResources;
  1291. begin
  1292. while not ppufile.endofentry do
  1293. resourcefiles.Insert(ppufile.getstring);
  1294. end;
  1295. procedure tppumodule.readOrderedSymbols;
  1296. begin
  1297. while not ppufile.endofentry do
  1298. linkorderedsymbols.Concat(ppufile.getstring);
  1299. end;
  1300. procedure tppumodule.readwpofile;
  1301. var
  1302. orgwpofilename: string;
  1303. orgwpofiletime: longint;
  1304. begin
  1305. { check whether we are using the same wpo feedback input file as when
  1306. this unit was compiled (same file name and file date)
  1307. }
  1308. orgwpofilename:=ppufile.getstring;
  1309. orgwpofiletime:=ppufile.getlongint;
  1310. if (extractfilename(orgwpofilename)<>extractfilename(wpofeedbackinput)) or
  1311. (orgwpofiletime<>GetNamedFileTime(orgwpofilename)) then
  1312. { make sure we don't throw away a precompiled unit if the user simply
  1313. forgot to specify the right wpo feedback file
  1314. }
  1315. message3(unit_e_different_wpo_file,ppufilename,orgwpofilename,filetimestring(orgwpofiletime));
  1316. end;
  1317. procedure tppumodule.readunitimportsyms;
  1318. var
  1319. c,i : longint;
  1320. deref : pderef;
  1321. begin
  1322. c:=ppufile.getlongint;
  1323. for i:=0 to c-1 do
  1324. begin
  1325. new(deref);
  1326. ppufile.getderef(deref^);
  1327. unitimportsymsderefs.add(deref);
  1328. end;
  1329. end;
  1330. procedure tppumodule.readasmsyms;
  1331. var
  1332. c,i : longint;
  1333. name : TSymStr;
  1334. bind : TAsmsymbind;
  1335. typ : TAsmsymtype;
  1336. list : tfphashobjectlist;
  1337. begin
  1338. case tunitasmlisttype(ppufile.getbyte) of
  1339. ualt_public:
  1340. list:=publicasmsyms;
  1341. ualt_extern:
  1342. list:=externasmsyms;
  1343. end;
  1344. c:=ppufile.getlongint;
  1345. for i:=0 to c-1 do
  1346. begin
  1347. name:=ppufile.getstring;
  1348. bind:=TAsmsymbind(ppufile.getbyte);
  1349. typ:=TAsmsymtype(ppufile.getbyte);
  1350. TAsmSymbol.Create(list,name,bind,typ);
  1351. end;
  1352. end;
  1353. procedure tppumodule.readextraheader;
  1354. begin
  1355. longversion:=cardinal(ppufile.getlongint);
  1356. ppufile.getset(tppuset4(moduleflags));
  1357. end;
  1358. procedure tppumodule.load_interface;
  1359. var
  1360. b : byte;
  1361. newmodulename : string;
  1362. begin
  1363. { read interface part }
  1364. repeat
  1365. b:=ppufile.readentry;
  1366. case b of
  1367. ibjvmnamespace :
  1368. begin
  1369. namespace:=ppufile.getpshortstring;
  1370. end;
  1371. ibmodulename :
  1372. begin
  1373. newmodulename:=ppufile.getstring;
  1374. if (cs_check_unit_name in current_settings.globalswitches) and
  1375. (upper(newmodulename)<>modulename^) then
  1376. Message2(unit_f_unit_name_error,realmodulename^,newmodulename);
  1377. stringdispose(modulename);
  1378. stringdispose(realmodulename);
  1379. modulename:=stringdup(upper(newmodulename));
  1380. realmodulename:=stringdup(newmodulename);
  1381. end;
  1382. ibextraheader:
  1383. begin
  1384. readextraheader;
  1385. end;
  1386. ibfeatures :
  1387. begin
  1388. ppufile.getset(tppuset4(features));
  1389. end;
  1390. ibmoduleoptions:
  1391. begin
  1392. ppufile.getset(tppuset1(moduleoptions));
  1393. if mo_has_deprecated_msg in moduleoptions then
  1394. begin
  1395. stringdispose(deprecatedmsg);
  1396. deprecatedmsg:=ppufile.getpshortstring;
  1397. end;
  1398. end;
  1399. ibsourcefiles :
  1400. readsourcefiles;
  1401. {$IFDEF MACRO_DIFF_HINT}
  1402. ibusedmacros :
  1403. readusedmacros;
  1404. {$ENDIF}
  1405. ibloadunit :
  1406. readloadunit;
  1407. iblinkunitofiles :
  1408. readlinkcontainer(LinkUnitOFiles);
  1409. iblinkunitstaticlibs :
  1410. readlinkcontainer(LinkUnitStaticLibs);
  1411. iblinkunitsharedlibs :
  1412. readlinkcontainer(LinkUnitSharedLibs);
  1413. iblinkotherofiles :
  1414. readlinkcontainer(LinkotherOFiles);
  1415. iblinkotherstaticlibs :
  1416. readlinkcontainer(LinkotherStaticLibs);
  1417. iblinkothersharedlibs :
  1418. readlinkcontainer(LinkotherSharedLibs);
  1419. iblinkotherframeworks :
  1420. readlinkcontainer(LinkOtherFrameworks);
  1421. ibmainname:
  1422. begin
  1423. mainname:=ppufile.getpshortstring;
  1424. if (mainaliasname<>defaultmainaliasname) then
  1425. Message1(scan_w_multiple_main_name_overrides,mainaliasname);
  1426. mainaliasname:=mainname^;
  1427. end;
  1428. ibImportSymbols :
  1429. readImportSymbols;
  1430. ibderefmap :
  1431. readderefmap;
  1432. ibderefdata :
  1433. readderefdata;
  1434. ibresources:
  1435. readResources;
  1436. iborderedsymbols:
  1437. readOrderedSymbols;
  1438. ibwpofile:
  1439. readwpofile;
  1440. ibendinterface :
  1441. break;
  1442. else
  1443. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1444. end;
  1445. { we can already stop when we know that we must recompile }
  1446. if do_compile then
  1447. exit;
  1448. until false;
  1449. end;
  1450. procedure tppumodule.load_implementation;
  1451. var
  1452. b : byte;
  1453. begin
  1454. { read implementation part }
  1455. repeat
  1456. b:=ppufile.readentry;
  1457. case b of
  1458. ibloadunit :
  1459. readloadunit;
  1460. ibasmsymbols :
  1461. readasmsyms;
  1462. ibunitimportsyms:
  1463. readunitimportsyms;
  1464. ibendimplementation :
  1465. break;
  1466. else
  1467. Message1(unit_f_ppu_invalid_entry,tostr(b));
  1468. end;
  1469. until false;
  1470. end;
  1471. procedure tppumodule.writeppu;
  1472. begin
  1473. Message1(unit_u_ppu_write,realmodulename^);
  1474. { create unit flags }
  1475. {$ifdef cpufpemu}
  1476. if (cs_fp_emulation in current_settings.moduleswitches) then
  1477. headerflags:=headerflags or uf_fpu_emulation;
  1478. {$endif cpufpemu}
  1479. { create new ppufile }
  1480. ppufile:=tcompilerppufile.create(ppufilename);
  1481. if not ppufile.createfile then
  1482. Message(unit_f_ppu_cannot_write);
  1483. {$ifdef Test_Double_checksum_write}
  1484. { Re-use the values collected in .INT part }
  1485. if assigned(interface_crc_array) then
  1486. begin
  1487. ppufile.implementation_write_crc_index:=implementation_write_crc_index;
  1488. ppufile.interface_write_crc_index:=interface_write_crc_index;
  1489. ppufile.indirect_write_crc_index:=indirect_write_crc_index;
  1490. if assigned(ppufile.interface_crc_array) then
  1491. begin
  1492. dispose(ppufile.interface_crc_array);
  1493. ppufile.interface_crc_array:=interface_crc_array;
  1494. end;
  1495. if assigned(ppufile.implementation_crc_array) then
  1496. begin
  1497. dispose(ppufile.implementation_crc_array);
  1498. ppufile.implementation_crc_array:=implementation_crc_array;
  1499. end;
  1500. if assigned(ppufile.indirect_crc_array) then
  1501. begin
  1502. dispose(ppufile.indirect_crc_array);
  1503. ppufile.indirect_crc_array:=indirect_crc_array;
  1504. end;
  1505. end;
  1506. if FileExists(ppufilename+'.IMP',false) then
  1507. RenameFile(ppufilename+'.IMP',ppufilename+'.IMP-old');
  1508. Assign(ppufile.CRCFile,ppufilename+'.IMP');
  1509. Rewrite(ppufile.CRCFile);
  1510. Writeln(ppufile.CRCFile,'CRC in writeppu method of implementation of ',ppufilename,' defsgeneration=',defsgeneration);
  1511. {$endif def Test_Double_checksum_write}
  1512. { extra header (sub version, module flags) }
  1513. writeextraheader;
  1514. { first the (JVM) namespace }
  1515. if assigned(namespace) then
  1516. begin
  1517. ppufile.putstring(namespace^);
  1518. ppufile.writeentry(ibjvmnamespace);
  1519. end;
  1520. { the unitname }
  1521. ppufile.putstring(realmodulename^);
  1522. ppufile.writeentry(ibmodulename);
  1523. ppufile.putset(tppuset1(moduleoptions));
  1524. if mo_has_deprecated_msg in moduleoptions then
  1525. ppufile.putstring(deprecatedmsg^);
  1526. ppufile.writeentry(ibmoduleoptions);
  1527. { write the alternate main procedure name if any }
  1528. if assigned(mainname) then
  1529. begin
  1530. ppufile.putstring(mainname^);
  1531. ppufile.writeentry(ibmainname);
  1532. end;
  1533. if cs_compilesystem in current_settings.moduleswitches then
  1534. begin
  1535. ppufile.putset(tppuset4(features));
  1536. ppufile.writeentry(ibfeatures);
  1537. end;
  1538. writesourcefiles;
  1539. {$IFDEF MACRO_DIFF_HINT}
  1540. writeusedmacros;
  1541. {$ENDIF}
  1542. { write interface uses }
  1543. writeusedunit(true);
  1544. { write the objectfiles and libraries that come for this unit,
  1545. preserve the containers because they are still needed to load
  1546. the link.res.
  1547. All doesn't depend on the crc! It doesn't matter
  1548. if a unit is in a .o or .a file }
  1549. ppufile.do_crc:=false;
  1550. { write after source files, so that we know whether or not the compiler
  1551. will recompile the unit when checking whether the correct wpo file is
  1552. used (if it will recompile the unit anyway, it doesn't matter)
  1553. }
  1554. if (wpofeedbackinput<>'') then
  1555. begin
  1556. ppufile.putstring(wpofeedbackinput);
  1557. ppufile.putlongint(getnamedfiletime(wpofeedbackinput));
  1558. ppufile.writeentry(ibwpofile);
  1559. end;
  1560. writelinkcontainer(linkunitofiles,iblinkunitofiles,true);
  1561. writelinkcontainer(linkunitstaticlibs,iblinkunitstaticlibs,true);
  1562. writelinkcontainer(linkunitsharedlibs,iblinkunitsharedlibs,true);
  1563. writelinkcontainer(linkotherofiles,iblinkotherofiles,false);
  1564. writelinkcontainer(linkotherstaticlibs,iblinkotherstaticlibs,true);
  1565. writelinkcontainer(linkothersharedlibs,iblinkothersharedlibs,true);
  1566. writelinkcontainer(linkotherframeworks,iblinkotherframeworks,true);
  1567. writeImportSymbols;
  1568. writeResources;
  1569. writeOrderedSymbols;
  1570. ppufile.do_crc:=true;
  1571. { generate implementation deref data, the interface deref data is
  1572. already generated when calculating the interface crc }
  1573. if (cs_compilesystem in current_settings.moduleswitches) then
  1574. begin
  1575. tstoredsymtable(globalsymtable).buildderef;
  1576. derefdataintflen:=derefdata.size;
  1577. end
  1578. else
  1579. { the unit may have been re-resolved, in which case the current
  1580. position in derefdata is not necessarily at the end }
  1581. derefdata.seek(derefdata.size);
  1582. tstoredsymtable(globalsymtable).buildderefimpl;
  1583. tunitwpoinfo(wpoinfo).buildderef;
  1584. tunitwpoinfo(wpoinfo).buildderefimpl;
  1585. if assigned(globalmacrosymtable) and (globalmacrosymtable.SymList.count > 0) then
  1586. begin
  1587. tstoredsymtable(globalmacrosymtable).buildderef;
  1588. tstoredsymtable(globalmacrosymtable).buildderefimpl;
  1589. end;
  1590. if mf_local_symtable in moduleflags then
  1591. tstoredsymtable(localsymtable).buildderef_registered;
  1592. buildderefunitimportsyms;
  1593. writederefmap;
  1594. writederefdata;
  1595. ppufile.writeentry(ibendinterface);
  1596. { write the symtable entries }
  1597. tstoredsymtable(globalsymtable).ppuwrite(ppufile);
  1598. if assigned(globalmacrosymtable) and (globalmacrosymtable.SymList.count > 0) then
  1599. begin
  1600. ppufile.putbyte(byte(true));
  1601. ppufile.writeentry(ibexportedmacros);
  1602. tstoredsymtable(globalmacrosymtable).ppuwrite(ppufile);
  1603. end
  1604. else
  1605. begin
  1606. ppufile.putbyte(byte(false));
  1607. ppufile.writeentry(ibexportedmacros);
  1608. end;
  1609. { everything after this doesn't affect the crc }
  1610. ppufile.do_crc:=false;
  1611. { write implementation uses }
  1612. writeusedunit(false);
  1613. { write all public assembler symbols }
  1614. writeasmsyms(ualt_public,publicasmsyms);
  1615. { write all external assembler symbols }
  1616. writeasmsyms(ualt_extern,externasmsyms);
  1617. { write all symbols imported from another unit }
  1618. writeunitimportsyms;
  1619. { end of implementation }
  1620. ppufile.writeentry(ibendimplementation);
  1621. { write static symtable
  1622. needed for local debugging of unit functions }
  1623. if mf_local_symtable in moduleflags then
  1624. tstoredsymtable(localsymtable).ppuwrite(ppufile);
  1625. { write whole program optimisation-related information }
  1626. tunitwpoinfo(wpoinfo).ppuwrite(ppufile);
  1627. { the last entry ibend is written automatically }
  1628. { flush to be sure }
  1629. ppufile.flush;
  1630. { create and write header }
  1631. ppufile.header.common.size:=ppufile.size;
  1632. ppufile.header.checksum:=ppufile.crc;
  1633. ppufile.header.interface_checksum:=ppufile.interface_crc;
  1634. ppufile.header.indirect_checksum:=ppufile.indirect_crc;
  1635. ppufile.header.common.compiler:=wordversion;
  1636. ppufile.header.common.cpu:=word(target_cpu);
  1637. ppufile.header.common.target:=word(target_info.system);
  1638. ppufile.header.common.flags:=headerflags;
  1639. ppufile.header.deflistsize:=current_module.deflist.count;
  1640. ppufile.header.symlistsize:=current_module.symlist.count;
  1641. ppufile.writeheader;
  1642. { save crc in current module also }
  1643. crc:=ppufile.crc;
  1644. interface_crc:=ppufile.interface_crc;
  1645. indirect_crc:=ppufile.indirect_crc;
  1646. {$ifdef Test_Double_checksum_write}
  1647. Writeln(ppufile.CRCFile,'End of implementation CRC in writeppu method of ',ppufilename,
  1648. ' implementation_crc=$',hexstr(ppufile.crc,8),
  1649. ' interface_crc=$',hexstr(ppufile.interface_crc,8),
  1650. ' indirect_crc=$',hexstr(ppufile.indirect_crc,8),
  1651. ' implementation_crc_size=',ppufile.implementation_read_crc_index,
  1652. ' interface_crc_size=',ppufile.interface_read_crc_index,
  1653. ' indirect_crc_size=',ppufile.indirect_read_crc_index,
  1654. ' defsgeneration=',defsgeneration);
  1655. close(ppufile.CRCFile);
  1656. {$endif Test_Double_checksum_write}
  1657. discardppu;
  1658. end;
  1659. procedure tppumodule.getppucrc;
  1660. begin
  1661. { create new ppufile }
  1662. ppufile:=tcompilerppufile.create(ppufilename);
  1663. ppufile.crc_only:=true;
  1664. if not ppufile.createfile then
  1665. Message(unit_f_ppu_cannot_write);
  1666. {$ifdef Test_Double_checksum_write}
  1667. if FileExists(ppufilename+'.INT',false) then
  1668. RenameFile(ppufilename+'.INT',ppufilename+'.INT-old');
  1669. Assign(ppufile.CRCFile,ppufilename+'.INT');
  1670. Rewrite(ppufile.CRCFile);
  1671. Writeln(ppufile.CRCFile,'CRC of getppucrc of ',ppufilename,
  1672. ' defsgeneration=',defsgeneration);
  1673. {$endif def Test_Double_checksum_write}
  1674. { first the (JVM) namespace }
  1675. if assigned(namespace) then
  1676. begin
  1677. ppufile.putstring(namespace^);
  1678. ppufile.writeentry(ibjvmnamespace);
  1679. end;
  1680. { the unitname }
  1681. ppufile.putstring(realmodulename^);
  1682. ppufile.writeentry(ibmodulename);
  1683. { extra header (sub version, module flags) }
  1684. writeextraheader;
  1685. ppufile.putset(tppuset1(moduleoptions));
  1686. if mo_has_deprecated_msg in moduleoptions then
  1687. ppufile.putstring(deprecatedmsg^);
  1688. ppufile.writeentry(ibmoduleoptions);
  1689. { the interface units affect the crc }
  1690. writeusedunit(true);
  1691. { deref data of interface that affect the crc }
  1692. derefdata.reset;
  1693. tstoredsymtable(globalsymtable).buildderef;
  1694. derefdataintflen:=derefdata.size;
  1695. writederefmap;
  1696. writederefdata;
  1697. ppufile.writeentry(ibendinterface);
  1698. { write the symtable entries }
  1699. tstoredsymtable(globalsymtable).ppuwrite(ppufile);
  1700. if assigned(globalmacrosymtable) and (globalmacrosymtable.SymList.count > 0) then
  1701. begin
  1702. ppufile.putbyte(byte(true));
  1703. ppufile.writeentry(ibexportedmacros);
  1704. tstoredsymtable(globalmacrosymtable).ppuwrite(ppufile);
  1705. end
  1706. else
  1707. begin
  1708. ppufile.putbyte(byte(false));
  1709. ppufile.writeentry(ibexportedmacros);
  1710. end;
  1711. { save crc }
  1712. crc:=ppufile.crc;
  1713. interface_crc:=ppufile.interface_crc;
  1714. indirect_crc:=ppufile.indirect_crc;
  1715. { end of implementation, to generate a correct ppufile
  1716. for ppudump when using INTFPPU define }
  1717. ppufile.writeentry(ibendimplementation);
  1718. {$ifdef Test_Double_checksum_write}
  1719. Writeln(ppufile.CRCFile,'End of CRC of getppucrc of ',ppufilename,
  1720. ' implementation_crc=$',hexstr(ppufile.crc,8),
  1721. ' interface_crc=$',hexstr(ppufile.interface_crc,8),
  1722. ' indirect_crc=$',hexstr(ppufile.indirect_crc,8),
  1723. ' implementation_crc_size=',ppufile.implementation_write_crc_index,
  1724. ' interface_crc_size=',ppufile.interface_write_crc_index,
  1725. ' indirect_crc_size=',ppufile.indirect_write_crc_index,
  1726. ' defsgeneration=',defsgeneration);
  1727. close(ppufile.CRCFile);
  1728. { Remember the values generated in .INT part }
  1729. implementation_write_crc_index:=ppufile.implementation_write_crc_index;
  1730. interface_write_crc_index:=ppufile.interface_write_crc_index;
  1731. indirect_write_crc_index:=ppufile.indirect_write_crc_index;
  1732. interface_crc_array:=ppufile.interface_crc_array;
  1733. ppufile.interface_crc_array:=nil;
  1734. implementation_crc_array:=ppufile.implementation_crc_array;
  1735. ppufile.implementation_crc_array:=nil;
  1736. indirect_crc_array:=ppufile.indirect_crc_array;
  1737. ppufile.indirect_crc_array:=nil;
  1738. {$endif Test_Double_checksum_write}
  1739. { create and write header, this will only be used
  1740. for debugging purposes }
  1741. ppufile.header.common.size:=ppufile.size;
  1742. ppufile.header.checksum:=ppufile.crc;
  1743. ppufile.header.interface_checksum:=ppufile.interface_crc;
  1744. ppufile.header.indirect_checksum:=ppufile.indirect_crc;
  1745. ppufile.header.common.compiler:=wordversion;
  1746. ppufile.header.common.cpu:=word(target_cpu);
  1747. ppufile.header.common.target:=word(target_info.system);
  1748. ppufile.header.common.flags:=headerflags;
  1749. ppufile.writeheader;
  1750. discardppu;
  1751. end;
  1752. procedure tppumodule.load_usedunits;
  1753. var
  1754. pu : tused_unit;
  1755. begin
  1756. if current_module<>self then
  1757. internalerror(200212284);
  1758. { load the used units from interface }
  1759. in_interface:=true;
  1760. pu:=tused_unit(used_units.first);
  1761. while assigned(pu) do
  1762. begin
  1763. if pu.in_interface then
  1764. begin
  1765. tppumodule(pu.u).loadppu(self);
  1766. { if this unit is compiled we can stop }
  1767. if state=ms_compiled then
  1768. exit;
  1769. { add this unit to the dependencies }
  1770. pu.u.adddependency(self,true);
  1771. { need to recompile the current unit, check the interface
  1772. crc. And when not compiled with -Ur then check the complete
  1773. crc }
  1774. if (pu.u.interface_crc<>pu.interface_checksum) or
  1775. (pu.u.indirect_crc<>pu.indirect_checksum) or
  1776. (
  1777. (not(mf_release in moduleflags)) and
  1778. (pu.u.crc<>pu.checksum)
  1779. ) then
  1780. begin
  1781. Message2(unit_u_recompile_crc_change,realmodulename^,pu.u.ppufilename,@queuecomment);
  1782. {$ifdef DEBUG_UNIT_CRC_CHANGES}
  1783. if (pu.u.interface_crc<>pu.interface_checksum) then
  1784. Comment(V_Normal,' intfcrc change: '+hexstr(pu.u.interface_crc,8)+' for '+pu.u.ppufilename+' <> '+hexstr(pu.interface_checksum,8)+' in unit '+realmodulename^)
  1785. else if (pu.u.indirect_crc<>pu.indirect_checksum) then
  1786. Comment(V_Normal,' indcrc change: '+hexstr(pu.u.indirect_crc,8)+' for '+pu.u.ppufilename+' <> '+hexstr(pu.indirect_checksum,8)+' in unit '+realmodulename^)
  1787. else
  1788. Comment(V_Normal,' implcrc change: '+hexstr(pu.u.crc,8)+' for '+pu.u.ppufilename+' <> '+hexstr(pu.checksum,8)+' in unit '+realmodulename^);
  1789. {$endif DEBUG_UNIT_CRC_CHANGES}
  1790. recompile_reason:=rr_crcchanged;
  1791. do_compile:=true;
  1792. exit;
  1793. end;
  1794. end;
  1795. pu:=tused_unit(pu.next);
  1796. end;
  1797. { ok, now load the interface of this unit }
  1798. if current_module<>self then
  1799. internalerror(200208187);
  1800. deflist.count:=ppufile.header.deflistsize;
  1801. symlist.count:=ppufile.header.symlistsize;
  1802. globalsymtable:=tglobalsymtable.create(modulename^,moduleid);
  1803. tstoredsymtable(globalsymtable).ppuload(ppufile);
  1804. if ppufile.readentry<>ibexportedmacros then
  1805. Message(unit_f_ppu_read_error);
  1806. if boolean(ppufile.getbyte) then
  1807. begin
  1808. globalmacrosymtable:=tmacrosymtable.Create(true);
  1809. tstoredsymtable(globalmacrosymtable).ppuload(ppufile)
  1810. end;
  1811. interface_compiled:=true;
  1812. { read the implementation part, containing
  1813. the implementation uses and ObjData }
  1814. in_interface:=false;
  1815. load_implementation;
  1816. { now only read the implementation uses }
  1817. pu:=tused_unit(used_units.first);
  1818. while assigned(pu) do
  1819. begin
  1820. if (not pu.in_interface) then
  1821. begin
  1822. tppumodule(pu.u).loadppu(self);
  1823. { if this unit is compiled we can stop }
  1824. if state=ms_compiled then
  1825. exit;
  1826. { add this unit to the dependencies }
  1827. pu.u.adddependency(self,false);
  1828. { need to recompile the current unit ? }
  1829. if (pu.u.interface_crc<>pu.interface_checksum) or
  1830. (pu.u.indirect_crc<>pu.indirect_checksum) then
  1831. begin
  1832. Message2(unit_u_recompile_crc_change,realmodulename^,pu.u.ppufilename+' {impl}',@queuecomment);
  1833. {$ifdef DEBUG_UNIT_CRC_CHANGES}
  1834. if (pu.u.interface_crc<>pu.interface_checksum) then
  1835. Comment(V_Normal,' intfcrc change (2): '+hexstr(pu.u.interface_crc,8)+' for '+pu.u.ppufilename+' <> '+hexstr(pu.interface_checksum,8)+' in unit '+realmodulename^)
  1836. else if (pu.u.indirect_crc<>pu.indirect_checksum) then
  1837. Comment(V_Normal,' indcrc change (2): '+hexstr(pu.u.indirect_crc,8)+' for '+pu.u.ppufilename+' <> '+hexstr(pu.indirect_checksum,8)+' in unit '+realmodulename^);
  1838. {$endif DEBUG_UNIT_CRC_CHANGES}
  1839. recompile_reason:=rr_crcchanged;
  1840. do_compile:=true;
  1841. exit;
  1842. end;
  1843. end;
  1844. pu:=tused_unit(pu.next);
  1845. end;
  1846. { load implementation symtable }
  1847. if mf_local_symtable in moduleflags then
  1848. begin
  1849. localsymtable:=tstaticsymtable.create(modulename^,moduleid);
  1850. tstaticsymtable(localsymtable).ppuload(ppufile);
  1851. end;
  1852. { we can now derefence all pointers to the implementation parts }
  1853. tstoredsymtable(globalsymtable).derefimpl(false);
  1854. { we've just loaded the localsymtable from the ppu file, so everything
  1855. in it was registered by definition (otherwise it wouldn't have been in
  1856. there) }
  1857. if assigned(localsymtable) then
  1858. tstoredsymtable(localsymtable).derefimpl(false);
  1859. derefunitimportsyms;
  1860. { read whole program optimisation-related information }
  1861. wpoinfo:=tunitwpoinfo.ppuload(ppufile);
  1862. tunitwpoinfo(wpoinfo).deref;
  1863. tunitwpoinfo(wpoinfo).derefimpl;
  1864. end;
  1865. function tppumodule.needrecompile:boolean;
  1866. var
  1867. pu : tused_unit;
  1868. begin
  1869. result:=false;
  1870. pu:=tused_unit(used_units.first);
  1871. while assigned(pu) do
  1872. begin
  1873. { need to recompile the current unit, check the interface
  1874. crc. And when not compiled with -Ur then check the complete
  1875. crc }
  1876. if (pu.u.interface_crc<>pu.interface_checksum) or
  1877. (pu.u.indirect_crc<>pu.indirect_checksum) or
  1878. (
  1879. (pu.in_interface) and
  1880. (pu.u.crc<>pu.checksum)
  1881. ) then
  1882. begin
  1883. {$ifdef DEBUG_UNIT_CRC_CHANGES}
  1884. if (pu.u.interface_crc<>pu.interface_checksum) then
  1885. Comment(V_Normal,' intfcrc change (3): '+hexstr(pu.u.interface_crc,8)+' for '+pu.u.ppufilename+' <> '+hexstr(pu.interface_checksum,8)+' in unit '+realmodulename^)
  1886. else if (pu.u.indirect_crc<>pu.indirect_checksum) then
  1887. Comment(V_Normal,' indcrc change (3): '+hexstr(pu.u.indirect_crc,8)+' for '+pu.u.ppufilename+' <> '+hexstr(pu.indirect_checksum,8)+' in unit '+realmodulename^)
  1888. else
  1889. Comment(V_Normal,' implcrc change (3): '+hexstr(pu.u.crc,8)+' for '+pu.u.ppufilename+' <> '+hexstr(pu.checksum,8)+' in unit '+realmodulename^);
  1890. {$endif DEBUG_UNIT_CRC_CHANGES}
  1891. result:=true;
  1892. exit;
  1893. end;
  1894. pu:=tused_unit(pu.next);
  1895. end;
  1896. end;
  1897. procedure tppumodule.setdefgeneration;
  1898. begin
  1899. defsgeneration:=currentdefgeneration;
  1900. inc(currentdefgeneration);
  1901. end;
  1902. procedure tppumodule.reload_flagged_units;
  1903. var
  1904. hp : tppumodule;
  1905. begin
  1906. { now reload all dependent units with outdated defs }
  1907. hp:=tppumodule(loaded_units.first);
  1908. while assigned(hp) do
  1909. begin
  1910. if hp.do_reload and
  1911. (hp.defsgeneration<defsgeneration) then
  1912. begin
  1913. hp.defsgeneration:=defsgeneration;
  1914. hp.loadppu(self)
  1915. end
  1916. else
  1917. hp.do_reload:=false;
  1918. hp:=tppumodule(hp.next);
  1919. end;
  1920. end;
  1921. procedure tppumodule.end_of_parsing;
  1922. begin
  1923. { module is now compiled }
  1924. state:=ms_compiled;
  1925. { free ppu }
  1926. discardppu;
  1927. inherited end_of_parsing;
  1928. end;
  1929. procedure tppumodule.check_reload(from_module : tmodule; var do_load : boolean);
  1930. begin
  1931. { A force reload }
  1932. if not do_reload then
  1933. exit;
  1934. Message(unit_u_forced_reload);
  1935. do_reload:=false;
  1936. { When the unit is already loaded or being loaded
  1937. we can maybe skip a complete reload/recompile }
  1938. if assigned(globalsymtable) and
  1939. (not needrecompile) then
  1940. begin
  1941. { When we don't have any data stored yet there
  1942. is nothing to resolve }
  1943. if interface_compiled and
  1944. { it makes no sense to re-resolve the unit if it is already finally compiled }
  1945. not(state=ms_compiled) then
  1946. begin
  1947. re_resolve(from_module);
  1948. end
  1949. else
  1950. Message1(unit_u_skipping_reresolving_unit,modulename^);
  1951. do_load:=false;
  1952. end;
  1953. end;
  1954. { Returns true if the module was loaded from package }
  1955. function tppumodule.check_loadfrompackage : boolean;
  1956. begin
  1957. { try to load it as a package unit first }
  1958. Result:=(packagelist.count>0) and loadfrompackage;
  1959. if Result then
  1960. begin
  1961. do_reload:=false;
  1962. state:=ms_compiled;
  1963. { PPU is not needed anymore }
  1964. if assigned(ppufile) then
  1965. begin
  1966. discardppu;
  1967. end;
  1968. { add the unit to the used units list of the program }
  1969. usedunits.concat(tused_unit.create(self,true,false,nil));
  1970. end;
  1971. end;
  1972. procedure tppumodule.prepare_second_load(from_module: tmodule);
  1973. begin
  1974. { try to load the unit a second time first }
  1975. Message1(unit_u_second_load_unit,modulename^);
  1976. Message2(unit_u_previous_state,modulename^,ModuleStateStr[state]);
  1977. { Flag modules to reload }
  1978. flagdependent(from_module);
  1979. { Reset the module }
  1980. reset;
  1981. if state in [ms_compile,ms_second_compile] then
  1982. begin
  1983. Message1(unit_u_second_compile_unit,modulename^);
  1984. state:=ms_second_compile;
  1985. do_compile:=true;
  1986. end
  1987. else
  1988. state:=ms_second_load;
  1989. end;
  1990. procedure tppumodule.try_load_ppufile(from_module : tmodule);
  1991. begin
  1992. Message1(unit_u_loading_unit,modulename^);
  1993. search_unit_files(from_module,false);
  1994. if not do_compile then
  1995. begin
  1996. load_interface;
  1997. setdefgeneration;
  1998. if not do_compile then
  1999. begin
  2000. load_usedunits;
  2001. if not do_compile then
  2002. Message1(unit_u_finished_loading_unit,modulename^);
  2003. end;
  2004. end;
  2005. { PPU is not needed anymore }
  2006. if assigned(ppufile) then
  2007. discardppu;
  2008. end;
  2009. procedure tppumodule.recompile_from_sources(from_module : tmodule);
  2010. var
  2011. pu : tused_unit;
  2012. begin
  2013. { recompile the unit or give a fatal error if sources not available }
  2014. if not(sources_avail) then
  2015. begin
  2016. search_unit_files(from_module,true);
  2017. if not(sources_avail) then
  2018. begin
  2019. printcomments;
  2020. if recompile_reason=rr_noppu then
  2021. begin
  2022. pu:=tused_unit(from_module.used_units.first);
  2023. while assigned(pu) do
  2024. begin
  2025. if pu.u=self then
  2026. break;
  2027. pu:=tused_unit(pu.next);
  2028. end;
  2029. if assigned(pu) and assigned(pu.unitsym) then
  2030. MessagePos2(pu.unitsym.fileinfo,unit_f_cant_find_ppu,realmodulename^,from_module.realmodulename^)
  2031. else
  2032. Message2(unit_f_cant_find_ppu,realmodulename^,from_module.realmodulename^);
  2033. end
  2034. else
  2035. Message1(unit_f_cant_compile_unit,realmodulename^);
  2036. end;
  2037. end;
  2038. { we found the sources, we do not need the verbose messages anymore }
  2039. if comments <> nil then
  2040. begin
  2041. comments.free;
  2042. comments:=nil;
  2043. end;
  2044. { Flag modules to reload }
  2045. flagdependent(from_module);
  2046. { Reset the module }
  2047. reset;
  2048. { compile this module }
  2049. if not(state in [ms_compile,ms_second_compile]) then
  2050. state:=ms_compile;
  2051. compile_module(self);
  2052. setdefgeneration;
  2053. end;
  2054. procedure tppumodule.post_load_or_compile(second_time : boolean);
  2055. begin
  2056. if current_module<>self then
  2057. internalerror(200212282);
  2058. if in_interface then
  2059. internalerror(200212283);
  2060. { for a second_time recompile reload all dependent units,
  2061. for a first time compile register the unit _once_ }
  2062. if second_time then
  2063. reload_flagged_units
  2064. else
  2065. usedunits.concat(tused_unit.create(self,true,false,nil));
  2066. { reopen the old module }
  2067. {$ifdef SHORT_ON_FILE_HANDLES}
  2068. if old_current_module.is_unit and
  2069. assigned(tppumodule(old_current_module).ppufile) then
  2070. tppumodule(old_current_module).ppufile.tempopen;
  2071. {$endif SHORT_ON_FILE_HANDLES}
  2072. end;
  2073. procedure tppumodule.loadppu(from_module : tmodule);
  2074. const
  2075. ImplIntf : array[boolean] of string[15]=('implementation','interface');
  2076. var
  2077. do_load,
  2078. second_time : boolean;
  2079. begin
  2080. Message3(unit_u_load_unit,from_module.modulename^,
  2081. ImplIntf[from_module.in_interface],
  2082. modulename^);
  2083. { check if the globalsymtable is already available, but
  2084. we must reload when the do_reload flag is set }
  2085. if (not do_reload) and
  2086. assigned(globalsymtable) then
  2087. exit;
  2088. { reset }
  2089. do_load:=true;
  2090. second_time:=false;
  2091. set_current_module(self);
  2092. do_load:=not check_loadfrompackage;
  2093. { A force reload }
  2094. check_reload(from_module, do_load);
  2095. if not do_load then
  2096. begin
  2097. // No need to do anything, restore situation and exit.
  2098. set_current_module(from_module);
  2099. exit;
  2100. end;
  2101. { loading the unit for a second time? }
  2102. if state=ms_registered then
  2103. state:=ms_load
  2104. else
  2105. begin
  2106. second_time:=true;
  2107. prepare_second_load(from_module);
  2108. end;
  2109. { close old_current_ppu on system that are
  2110. short on file handles like DOS PM }
  2111. {$ifdef SHORT_ON_FILE_HANDLES}
  2112. if old_current_module.is_unit and
  2113. assigned(tppumodule(old_current_module).ppufile) then
  2114. tppumodule(old_current_module).ppufile.tempclose;
  2115. {$endif SHORT_ON_FILE_HANDLES}
  2116. { try to opening ppu, skip this when we already
  2117. know that we need to compile the unit }
  2118. if not do_compile then
  2119. try_load_ppufile(from_module);
  2120. { Do we need to recompile the unit }
  2121. if do_compile then
  2122. recompile_from_sources(from_module)
  2123. else
  2124. state:=ms_compiled;
  2125. post_load_or_compile(second_time);
  2126. { we are back, restore current_module }
  2127. set_current_module(from_module);
  2128. end;
  2129. procedure tppumodule.discardppu;
  2130. begin
  2131. { PPU is not needed anymore }
  2132. if not assigned(ppufile) then
  2133. exit;
  2134. ppufile.closefile;
  2135. ppufile.free;
  2136. ppufile:=nil;
  2137. end;
  2138. {*****************************************************************************
  2139. RegisterUnit
  2140. *****************************************************************************}
  2141. function registerunit(callermodule:tmodule;const s : TIDString;const fn:string) : tppumodule;
  2142. function FindCycle(aFile, SearchFor: TModule; var Cycle: TFPList): boolean;
  2143. // Note: when traversing, add every search file to Cycle, to avoid running in circles.
  2144. // When a cycle is detected, clear the Cycle list and build the cycle path
  2145. var
  2146. aParent: tdependent_unit;
  2147. begin
  2148. Cycle.Add(aFile);
  2149. aParent:=tdependent_unit(afile.dependent_units.First);
  2150. While Assigned(aParent) do
  2151. begin
  2152. if aParent.in_interface then
  2153. begin
  2154. // writeln('Registering ',Callermodule.get_modulename,': checking cyclic dependency of ',aFile.get_modulename, ' on ',aparent.u.get_modulename);
  2155. if aParent.u=SearchFor then
  2156. begin
  2157. // unit cycle found
  2158. Cycle.Clear;
  2159. Cycle.Add(aParent.u);
  2160. Cycle.Add(aFile);
  2161. // Writeln('exit at ',aParent.u.get_modulename);
  2162. exit(true);
  2163. end;
  2164. if Cycle.IndexOf(aParent.u)<0 then
  2165. if FindCycle(aParent.u,SearchFor,Cycle) then
  2166. begin
  2167. // Writeln('Cycle found, exit at ',aParent.u.get_modulename);
  2168. Cycle.Add(aFile);
  2169. exit(true);
  2170. end;
  2171. end;
  2172. aParent:=tdependent_unit(aParent.Next);
  2173. end;
  2174. Result:=false;
  2175. end;
  2176. var
  2177. ups : TIDString;
  2178. hp : tppumodule;
  2179. hp2 : tmodule;
  2180. cycle : TFPList;
  2181. havecycle: boolean;
  2182. {$IFDEF DEBUGCYCLE}
  2183. cyclepath : ansistring
  2184. {$ENDIF}
  2185. begin
  2186. { Info }
  2187. ups:=upper(s);
  2188. { search all loaded units }
  2189. hp:=tppumodule(loaded_units.first);
  2190. hp2:=nil;
  2191. while assigned(hp) do
  2192. begin
  2193. if hp.modulename^=ups then
  2194. begin
  2195. { only check for units. The main program is also
  2196. as a unit in the loaded_units list. We simply need
  2197. to ignore this entry (PFV) }
  2198. if hp.is_unit then
  2199. begin
  2200. { both units in interface ? }
  2201. if hp.in_interface and callermodule.usesmodule_in_interface(hp) then
  2202. begin
  2203. { check for a cycle }
  2204. Cycle:=TFPList.Create;
  2205. try
  2206. HaveCycle:=FindCycle(CallerModule,hp,Cycle);
  2207. Writeln('Done cycle check, have cycle: ',HaveCycle);
  2208. if HaveCycle then
  2209. begin
  2210. {$IFDEF DEBUGCYCLE}
  2211. Writeln('Done cycle check');
  2212. CyclePath:='';
  2213. hp2:=TModule(Cycle[Cycle.Count-1]);
  2214. for i:=0 to Cycle.Count-1 do begin
  2215. if i>0 then CyclePath:=CyclePath+',';
  2216. CyclePath:=CyclePath+TModule(Cycle[i]).realmodulename^;
  2217. end;
  2218. Writeln('Unit cycle detected: ',CyclePath);
  2219. {$ENDIF}
  2220. Message2(unit_f_circular_unit_reference,callermodule.realmodulename^,hp.realmodulename^);
  2221. end;
  2222. finally
  2223. Cycle.Free;
  2224. end;
  2225. if assigned(hp2) then
  2226. Message2(unit_f_circular_unit_reference,callermodule.realmodulename^,hp.realmodulename^);
  2227. end;
  2228. break;
  2229. end;
  2230. end;
  2231. { the next unit }
  2232. hp:=tppumodule(hp.next);
  2233. end;
  2234. { the unit is not in the loaded units,
  2235. we create an entry and register the unit }
  2236. if not assigned(hp) then
  2237. begin
  2238. Message1(unit_u_registering_new_unit,ups);
  2239. hp:=tppumodule.create(callermodule,s,fn,true);
  2240. addloadedunit(hp);
  2241. end;
  2242. { return }
  2243. registerunit:=hp;
  2244. end;
  2245. end.