pmodules.pas 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418
  1. {
  2. Copyright (c) 1998-2008 by Florian Klaempfl
  3. Handles the parsing and loading of the modules (ppufiles)
  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 pmodules;
  18. {$i fpcdefs.inc}
  19. interface
  20. procedure proc_unit;
  21. procedure proc_package;
  22. procedure proc_program(islibrary : boolean);
  23. implementation
  24. uses
  25. SysUtils,
  26. globtype,version,systems,tokens,
  27. cutils,cfileutl,cclasses,comphook,
  28. globals,verbose,fmodule,finput,fppu,
  29. symconst,symbase,symtype,symdef,symsym,symtable,
  30. wpoinfo,
  31. aasmtai,aasmdata,aasmcpu,aasmbase,
  32. cgbase,cgobj,
  33. nbas,ncgutil,
  34. link,assemble,import,export,gendef,ppu,comprsrc,dbgbase,
  35. cresstr,procinfo,
  36. pexports,
  37. objcgutl,
  38. wpobase,
  39. scanner,pbase,pexpr,psystem,psub,pdecsub,ptype
  40. ,cpuinfo
  41. {$ifdef i386}
  42. { fix me! }
  43. ,cpubase
  44. {$endif i386}
  45. ;
  46. procedure create_objectfile;
  47. var
  48. DLLScanner : TDLLScanner;
  49. s : string;
  50. KeepShared : TCmdStrList;
  51. begin
  52. { try to create import entries from system dlls }
  53. if (tf_has_dllscanner in target_info.flags) and
  54. (not current_module.linkOtherSharedLibs.Empty) then
  55. begin
  56. { Init DLLScanner }
  57. if assigned(CDLLScanner[target_info.system]) then
  58. DLLScanner:=CDLLScanner[target_info.system].Create
  59. else
  60. internalerror(200104121);
  61. KeepShared:=TCmdStrList.Create;
  62. { Walk all shared libs }
  63. While not current_module.linkOtherSharedLibs.Empty do
  64. begin
  65. S:=current_module.linkOtherSharedLibs.Getusemask(link_always);
  66. if not DLLScanner.scan(s) then
  67. KeepShared.Concat(s);
  68. end;
  69. DLLscanner.Free;
  70. { Recreate import section }
  71. if (target_info.system in [system_i386_win32,system_i386_wdosx]) then
  72. begin
  73. if assigned(current_asmdata.asmlists[al_imports]) then
  74. current_asmdata.asmlists[al_imports].clear
  75. else
  76. current_asmdata.asmlists[al_imports]:=TAsmList.Create;
  77. importlib.generatelib;
  78. end;
  79. { Readd the not processed files }
  80. while not KeepShared.Empty do
  81. begin
  82. s:=KeepShared.GetFirst;
  83. current_module.linkOtherSharedLibs.add(s,link_always);
  84. end;
  85. KeepShared.Free;
  86. end;
  87. { Start and end module debuginfo, at least required for stabs
  88. to insert n_sourcefile lines }
  89. if (cs_debuginfo in current_settings.moduleswitches) or
  90. (cs_use_lineinfo in current_settings.globalswitches) then
  91. current_debuginfo.insertmoduleinfo;
  92. { create the .s file and assemble it }
  93. GenerateAsm(false);
  94. { Also create a smartlinked version ? }
  95. if create_smartlink_library then
  96. begin
  97. GenerateAsm(true);
  98. if (af_needar in target_asm.flags) then
  99. Linker.MakeStaticLibrary;
  100. end;
  101. { resource files }
  102. CompileResourceFiles;
  103. end;
  104. procedure insertobjectfile;
  105. { Insert the used object file for this unit in the used list for this unit }
  106. begin
  107. current_module.linkunitofiles.add(current_module.objfilename^,link_static);
  108. current_module.flags:=current_module.flags or uf_static_linked;
  109. if create_smartlink_library then
  110. begin
  111. current_module.linkunitstaticlibs.add(current_module.staticlibfilename^,link_smart);
  112. current_module.flags:=current_module.flags or uf_smart_linked;
  113. end;
  114. end;
  115. procedure create_dwarf_frame;
  116. begin
  117. { Dwarf conflicts with smartlinking in separate .a files }
  118. if create_smartlink_library then
  119. exit;
  120. { Call frame information }
  121. { MWE: we write our own info, so dwarf asm support is not really needed }
  122. { if (af_supports_dwarf in target_asm.flags) and }
  123. { CFI is currently broken for Darwin }
  124. if not(target_info.system in systems_darwin) and
  125. (
  126. (tf_needs_dwarf_cfi in target_info.flags) or
  127. (paratargetdbg in [dbg_dwarf2, dbg_dwarf3])
  128. ) then
  129. begin
  130. current_asmdata.asmlists[al_dwarf_frame].Free;
  131. current_asmdata.asmlists[al_dwarf_frame] := TAsmList.create;
  132. current_asmdata.asmcfi.generate_code(current_asmdata.asmlists[al_dwarf_frame]);
  133. end;
  134. end;
  135. procedure InsertThreadvarTablesTable;
  136. var
  137. hp : tused_unit;
  138. ltvTables : TAsmList;
  139. count : longint;
  140. begin
  141. if (tf_section_threadvars in target_info.flags) then
  142. exit;
  143. ltvTables:=TAsmList.Create;
  144. count:=0;
  145. hp:=tused_unit(usedunits.first);
  146. while assigned(hp) do
  147. begin
  148. If (hp.u.flags and uf_threadvars)=uf_threadvars then
  149. begin
  150. ltvTables.concat(Tai_const.Createname(make_mangledname('THREADVARLIST',hp.u.globalsymtable,''),0));
  151. inc(count);
  152. end;
  153. hp:=tused_unit(hp.next);
  154. end;
  155. { Add program threadvars, if any }
  156. If (current_module.flags and uf_threadvars)=uf_threadvars then
  157. begin
  158. ltvTables.concat(Tai_const.Createname(make_mangledname('THREADVARLIST',current_module.localsymtable,''),0));
  159. inc(count);
  160. end;
  161. { Insert TableCount at start }
  162. ltvTables.insert(Tai_const.Create_32bit(count));
  163. { insert in data segment }
  164. maybe_new_object_file(current_asmdata.asmlists[al_globals]);
  165. new_section(current_asmdata.asmlists[al_globals],sec_data,'FPC_THREADVARTABLES',sizeof(pint));
  166. current_asmdata.asmlists[al_globals].concat(Tai_symbol.Createname_global('FPC_THREADVARTABLES',AT_DATA,0));
  167. current_asmdata.asmlists[al_globals].concatlist(ltvTables);
  168. current_asmdata.asmlists[al_globals].concat(Tai_symbol_end.Createname('FPC_THREADVARTABLES'));
  169. ltvTables.free;
  170. end;
  171. procedure AddToThreadvarList(p:TObject;arg:pointer);
  172. var
  173. ltvTable : TAsmList;
  174. begin
  175. ltvTable:=TAsmList(arg);
  176. if (tsym(p).typ=staticvarsym) and
  177. (vo_is_thread_var in tstaticvarsym(p).varoptions) then
  178. begin
  179. { address of threadvar }
  180. ltvTable.concat(tai_const.Createname(tstaticvarsym(p).mangledname,0));
  181. { size of threadvar }
  182. ltvTable.concat(tai_const.create_32bit(tstaticvarsym(p).getsize));
  183. end;
  184. end;
  185. procedure InsertThreadvars;
  186. var
  187. s : string;
  188. ltvTable : TAsmList;
  189. begin
  190. if (tf_section_threadvars in target_info.flags) then
  191. exit;
  192. ltvTable:=TAsmList.create;
  193. if assigned(current_module.globalsymtable) then
  194. current_module.globalsymtable.SymList.ForEachCall(@AddToThreadvarList,ltvTable);
  195. current_module.localsymtable.SymList.ForEachCall(@AddToThreadvarList,ltvTable);
  196. if ltvTable.first<>nil then
  197. begin
  198. s:=make_mangledname('THREADVARLIST',current_module.localsymtable,'');
  199. { end of the list marker }
  200. ltvTable.concat(tai_const.create_sym(nil));
  201. { add to datasegment }
  202. maybe_new_object_file(current_asmdata.asmlists[al_globals]);
  203. new_section(current_asmdata.asmlists[al_globals],sec_data,s,sizeof(pint));
  204. current_asmdata.asmlists[al_globals].concat(Tai_symbol.Createname_global(s,AT_DATA,0));
  205. current_asmdata.asmlists[al_globals].concatlist(ltvTable);
  206. current_asmdata.asmlists[al_globals].concat(Tai_symbol_end.Createname(s));
  207. current_module.flags:=current_module.flags or uf_threadvars;
  208. end;
  209. ltvTable.Free;
  210. end;
  211. procedure InsertWideInits;
  212. var
  213. s: string;
  214. item: TTCInitItem;
  215. begin
  216. item:=TTCInitItem(current_asmdata.WideInits.First);
  217. if item=nil then
  218. exit;
  219. s:=make_mangledname('WIDEINITS',current_module.localsymtable,'');
  220. maybe_new_object_file(current_asmdata.asmlists[al_globals]);
  221. new_section(current_asmdata.asmlists[al_globals],sec_data,s,sizeof(pint));
  222. current_asmdata.asmlists[al_globals].concat(Tai_symbol.Createname_global(s,AT_DATA,0));
  223. repeat
  224. { address to initialize }
  225. current_asmdata.asmlists[al_globals].concat(Tai_const.createname(item.sym.mangledname, item.offset));
  226. { value with which to initialize }
  227. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(item.datalabel));
  228. item:=TTCInitItem(item.Next);
  229. until item=nil;
  230. { end-of-list marker }
  231. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_sym(nil));
  232. current_asmdata.asmlists[al_globals].concat(Tai_symbol_end.Createname(s));
  233. current_module.flags:=current_module.flags or uf_wideinits;
  234. end;
  235. procedure InsertWideInitsTablesTable;
  236. var
  237. hp: tused_unit;
  238. lwiTables: TAsmList;
  239. count: longint;
  240. begin
  241. lwiTables:=TAsmList.Create;
  242. count:=0;
  243. hp:=tused_unit(usedunits.first);
  244. while assigned(hp) do
  245. begin
  246. if (hp.u.flags and uf_wideinits)=uf_wideinits then
  247. begin
  248. lwiTables.concat(Tai_const.Createname(make_mangledname('WIDEINITS',hp.u.globalsymtable,''),0));
  249. inc(count);
  250. end;
  251. hp:=tused_unit(hp.next);
  252. end;
  253. { Add program widestring consts, if any }
  254. if (current_module.flags and uf_wideinits)=uf_wideinits then
  255. begin
  256. lwiTables.concat(Tai_const.Createname(make_mangledname('WIDEINITS',current_module.localsymtable,''),0));
  257. inc(count);
  258. end;
  259. { Insert TableCount at start }
  260. lwiTables.insert(Tai_const.Create_32bit(count));
  261. { insert in data segment }
  262. maybe_new_object_file(current_asmdata.asmlists[al_globals]);
  263. new_section(current_asmdata.asmlists[al_globals],sec_data,'FPC_WIDEINITTABLES',sizeof(pint));
  264. current_asmdata.asmlists[al_globals].concat(Tai_symbol.Createname_global('FPC_WIDEINITTABLES',AT_DATA,0));
  265. current_asmdata.asmlists[al_globals].concatlist(lwiTables);
  266. current_asmdata.asmlists[al_globals].concat(Tai_symbol_end.Createname('FPC_WIDEINITTABLES'));
  267. lwiTables.free;
  268. end;
  269. Function CheckResourcesUsed : boolean;
  270. var
  271. hp : tused_unit;
  272. found : Boolean;
  273. begin
  274. CheckResourcesUsed:=tf_has_winlike_resources in target_info.flags;
  275. if not CheckResourcesUsed then exit;
  276. hp:=tused_unit(usedunits.first);
  277. found:=((current_module.flags and uf_has_resourcefiles)=uf_has_resourcefiles);
  278. If not found then
  279. While Assigned(hp) and not found do
  280. begin
  281. Found:=((hp.u.flags and uf_has_resourcefiles)=uf_has_resourcefiles);
  282. hp:=tused_unit(hp.next);
  283. end;
  284. CheckResourcesUsed:=found;
  285. end;
  286. Procedure InsertResourceInfo(ResourcesUsed : boolean);
  287. var
  288. ResourceInfo : TAsmList;
  289. begin
  290. if (target_res.id in [res_elf,res_macho]) then
  291. begin
  292. ResourceInfo:=TAsmList.Create;
  293. maybe_new_object_file(ResourceInfo);
  294. new_section(ResourceInfo,sec_data,'FPC_RESLOCATION',sizeof(aint));
  295. ResourceInfo.concat(Tai_symbol.Createname_global('FPC_RESLOCATION',AT_DATA,0));
  296. if ResourcesUsed then
  297. { Valid pointer to resource information }
  298. ResourceInfo.concat(Tai_const.Createname('FPC_RESSYMBOL',0))
  299. else
  300. { Nil pointer to resource information }
  301. {$IFDEF CPU32}
  302. ResourceInfo.Concat(Tai_const.Create_32bit(0));
  303. {$ELSE}
  304. ResourceInfo.Concat(Tai_const.Create_64bit(0));
  305. {$ENDIF}
  306. maybe_new_object_file(current_asmdata.asmlists[al_globals]);
  307. current_asmdata.asmlists[al_globals].concatlist(ResourceInfo);
  308. ResourceInfo.free;
  309. end;
  310. end;
  311. Procedure InsertResourceTablesTable;
  312. var
  313. hp : tmodule;
  314. ResourceStringTables : tasmlist;
  315. count : longint;
  316. begin
  317. ResourceStringTables:=tasmlist.Create;
  318. count:=0;
  319. hp:=tmodule(loaded_units.first);
  320. while assigned(hp) do
  321. begin
  322. If (hp.flags and uf_has_resourcestrings)=uf_has_resourcestrings then
  323. begin
  324. ResourceStringTables.concat(Tai_const.Createname(make_mangledname('RESSTR',hp.localsymtable,'START'),0));
  325. ResourceStringTables.concat(Tai_const.Createname(make_mangledname('RESSTR',hp.localsymtable,'END'),0));
  326. inc(count);
  327. end;
  328. hp:=tmodule(hp.next);
  329. end;
  330. { Insert TableCount at start }
  331. ResourceStringTables.insert(Tai_const.Create_pint(count));
  332. { Add to data segment }
  333. maybe_new_object_file(current_asmdata.AsmLists[al_globals]);
  334. new_section(current_asmdata.AsmLists[al_globals],sec_data,'FPC_RESOURCESTRINGTABLES',sizeof(pint));
  335. current_asmdata.AsmLists[al_globals].concat(Tai_symbol.Createname_global('FPC_RESOURCESTRINGTABLES',AT_DATA,0));
  336. current_asmdata.AsmLists[al_globals].concatlist(ResourceStringTables);
  337. current_asmdata.AsmLists[al_globals].concat(Tai_symbol_end.Createname('FPC_RESOURCESTRINGTABLES'));
  338. ResourceStringTables.free;
  339. end;
  340. procedure InsertInitFinalTable;
  341. var
  342. hp : tused_unit;
  343. unitinits : TAsmList;
  344. count : longint;
  345. begin
  346. unitinits:=TAsmList.Create;
  347. count:=0;
  348. hp:=tused_unit(usedunits.first);
  349. while assigned(hp) do
  350. begin
  351. { call the unit init code and make it external }
  352. if (hp.u.flags and (uf_init or uf_finalize))<>0 then
  353. begin
  354. if (hp.u.flags and uf_init)<>0 then
  355. unitinits.concat(Tai_const.Createname(make_mangledname('INIT$',hp.u.globalsymtable,''),0))
  356. else
  357. unitinits.concat(Tai_const.Create_sym(nil));
  358. if (hp.u.flags and uf_finalize)<>0 then
  359. unitinits.concat(Tai_const.Createname(make_mangledname('FINALIZE$',hp.u.globalsymtable,''),0))
  360. else
  361. unitinits.concat(Tai_const.Create_sym(nil));
  362. inc(count);
  363. end;
  364. hp:=tused_unit(hp.next);
  365. end;
  366. { Insert initialization/finalization of the program }
  367. if (current_module.flags and (uf_init or uf_finalize))<>0 then
  368. begin
  369. if (current_module.flags and uf_init)<>0 then
  370. unitinits.concat(Tai_const.Createname(make_mangledname('INIT$',current_module.localsymtable,''),0))
  371. else
  372. unitinits.concat(Tai_const.Create_sym(nil));
  373. if (current_module.flags and uf_finalize)<>0 then
  374. unitinits.concat(Tai_const.Createname(make_mangledname('FINALIZE$',current_module.localsymtable,''),0))
  375. else
  376. unitinits.concat(Tai_const.Create_sym(nil));
  377. inc(count);
  378. end;
  379. { Insert TableCount,InitCount at start }
  380. unitinits.insert(Tai_const.Create_32bit(0));
  381. unitinits.insert(Tai_const.Create_32bit(count));
  382. { Add to data segment }
  383. maybe_new_object_file(current_asmdata.asmlists[al_globals]);
  384. new_section(current_asmdata.asmlists[al_globals],sec_data,'INITFINAL',sizeof(pint));
  385. current_asmdata.asmlists[al_globals].concat(Tai_symbol.Createname_global('INITFINAL',AT_DATA,0));
  386. current_asmdata.asmlists[al_globals].concatlist(unitinits);
  387. current_asmdata.asmlists[al_globals].concat(Tai_symbol_end.Createname('INITFINAL'));
  388. unitinits.free;
  389. end;
  390. procedure insertmemorysizes;
  391. {$IFDEF POWERPC}
  392. var
  393. stkcookie: string;
  394. {$ENDIF POWERPC}
  395. begin
  396. maybe_new_object_file(current_asmdata.asmlists[al_globals]);
  397. { Insert Ident of the compiler in the .fpc.version section }
  398. current_asmdata.asmlists[al_globals].concat(Tai_section.create(sec_fpc,'version',0));
  399. current_asmdata.asmlists[al_globals].concat(Tai_align.Create(const_align(32)));
  400. current_asmdata.asmlists[al_globals].concat(Tai_string.Create('FPC '+full_version_string+
  401. ' ['+date_string+'] for '+target_cpu_string+' - '+target_info.shortname));
  402. if not(tf_no_generic_stackcheck in target_info.flags) then
  403. begin
  404. { stacksize can be specified and is now simulated }
  405. new_section(current_asmdata.asmlists[al_globals],sec_data,'__stklen', sizeof(pint));
  406. current_asmdata.asmlists[al_globals].concat(Tai_symbol.Createname_global('__stklen',AT_DATA,sizeof(pint)));
  407. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_pint(stacksize));
  408. end;
  409. {$IFDEF POWERPC}
  410. { AmigaOS4 "stack cookie" support }
  411. if ( target_info.system = system_powerpc_amiga ) then
  412. begin
  413. { this symbol is needed to ignite powerpc amigaos' }
  414. { stack allocation magic for us with the given stack size. }
  415. { note: won't work for m68k amigaos or morphos. (KB) }
  416. str(stacksize,stkcookie);
  417. stkcookie:='$STACK: '+stkcookie+#0;
  418. maybe_new_object_file(current_asmdata.asmlists[al_globals]);
  419. new_section(current_asmdata.asmlists[al_globals],sec_data,'__stack_cookie',length(stkcookie));
  420. current_asmdata.asmlists[al_globals].concat(Tai_symbol.Createname_global('__stack_cookie',AT_DATA,length(stkcookie)));
  421. current_asmdata.asmlists[al_globals].concat(Tai_string.Create(stkcookie));
  422. end;
  423. {$ENDIF POWERPC}
  424. { Initial heapsize }
  425. maybe_new_object_file(current_asmdata.asmlists[al_globals]);
  426. new_section(current_asmdata.asmlists[al_globals],sec_data,'__heapsize',sizeof(pint));
  427. current_asmdata.asmlists[al_globals].concat(Tai_symbol.Createname_global('__heapsize',AT_DATA,sizeof(pint)));
  428. current_asmdata.asmlists[al_globals].concat(Tai_const.Create_pint(heapsize));
  429. { Initial heapsize }
  430. maybe_new_object_file(current_asmdata.asmlists[al_globals]);
  431. new_section(current_asmdata.asmlists[al_globals],sec_data,'__fpc_valgrind',sizeof(boolean));
  432. current_asmdata.asmlists[al_globals].concat(Tai_symbol.Createname_global('__fpc_valgrind',AT_DATA,sizeof(boolean)));
  433. current_asmdata.asmlists[al_globals].concat(Tai_const.create_8bit(byte(cs_gdb_valgrind in current_settings.globalswitches)));
  434. end;
  435. procedure AddUnit(const s:string);
  436. var
  437. hp : tppumodule;
  438. unitsym : tunitsym;
  439. begin
  440. { load unit }
  441. hp:=registerunit(current_module,s,'');
  442. hp.loadppu;
  443. hp.adddependency(current_module);
  444. { add to symtable stack }
  445. symtablestack.push(hp.globalsymtable);
  446. if (m_mac in current_settings.modeswitches) and
  447. assigned(hp.globalmacrosymtable) then
  448. macrosymtablestack.push(hp.globalmacrosymtable);
  449. { insert unitsym }
  450. unitsym:=tunitsym.create(s,hp);
  451. inc(unitsym.refs);
  452. current_module.localsymtable.insert(unitsym);
  453. { add to used units }
  454. current_module.addusedunit(hp,false,unitsym);
  455. end;
  456. procedure maybeloadvariantsunit;
  457. var
  458. hp : tmodule;
  459. begin
  460. { Do we need the variants unit? Skip this
  461. for VarUtils unit for bootstrapping }
  462. if (current_module.flags and uf_uses_variants=0) or
  463. (current_module.modulename^='VARUTILS') then
  464. exit;
  465. { Variants unit already loaded? }
  466. hp:=tmodule(loaded_units.first);
  467. while assigned(hp) do
  468. begin
  469. if hp.modulename^='VARIANTS' then
  470. exit;
  471. hp:=tmodule(hp.next);
  472. end;
  473. { Variants unit is not loaded yet, load it now }
  474. Message(parser_w_implicit_uses_of_variants_unit);
  475. AddUnit('variants');
  476. end;
  477. function MaybeRemoveResUnit : boolean;
  478. var
  479. resources_used : boolean;
  480. hp : tmodule;
  481. uu : tused_unit;
  482. unitname : shortstring;
  483. begin
  484. { We simply remove the unit from:
  485. - usedunit list, so that things like init/finalization table won't
  486. contain references to this unit
  487. - loaded_units list, so that the unit object file doesn't get linked
  488. with the executable. }
  489. { Note: on windows we always need resources! }
  490. resources_used:=(target_info.system in systems_all_windows)
  491. or CheckResourcesUsed;
  492. if (not resources_used) and (tf_has_winlike_resources in target_info.flags) then
  493. begin
  494. { resources aren't used, so we don't need this unit }
  495. if target_res.id=res_ext then
  496. unitname:='FPEXTRES'
  497. else
  498. unitname:='FPINTRES';
  499. Message1(unit_u_unload_resunit,unitname);
  500. { find the module }
  501. hp:=tmodule(loaded_units.first);
  502. while assigned(hp) do
  503. begin
  504. if hp.is_unit and (hp.modulename^=unitname) then break;
  505. hp:=tmodule(hp.next);
  506. end;
  507. if not assigned(hp) then
  508. internalerror(200801071);
  509. { find its tused_unit in the global list }
  510. uu:=tused_unit(usedunits.first);
  511. while assigned(uu) do
  512. begin
  513. if uu.u=hp then break;
  514. uu:=tused_unit(uu.next);
  515. end;
  516. if not assigned(uu) then
  517. internalerror(200801072);
  518. { remove the tused_unit }
  519. usedunits.Remove(uu);
  520. uu.Free;
  521. { remove the module }
  522. loaded_units.Remove(hp);
  523. unloaded_units.Concat(hp);
  524. end;
  525. MaybeRemoveResUnit:=resources_used;
  526. end;
  527. procedure loaddefaultunits;
  528. begin
  529. { we are going to rebuild the symtablestack, clear it first }
  530. symtablestack.clear;
  531. macrosymtablestack.clear;
  532. { macro symtable }
  533. macrosymtablestack.push(initialmacrosymtable);
  534. { are we compiling the system unit? }
  535. if (cs_compilesystem in current_settings.moduleswitches) then
  536. begin
  537. systemunit:=tglobalsymtable(current_module.localsymtable);
  538. { create system defines }
  539. create_intern_symbols;
  540. create_intern_types;
  541. { Set the owner of errorsym and errortype to symtable to
  542. prevent crashes when accessing .owner }
  543. generrorsym.owner:=systemunit;
  544. generrordef.owner:=systemunit;
  545. exit;
  546. end;
  547. { insert the system unit, it is allways the first. Load also the
  548. internal types from the system unit }
  549. AddUnit('system');
  550. systemunit:=tglobalsymtable(symtablestack.top);
  551. load_intern_types;
  552. { Set the owner of errorsym and errortype to symtable to
  553. prevent crashes when accessing .owner }
  554. generrorsym.owner:=systemunit;
  555. generrordef.owner:=systemunit;
  556. { Units only required for main module }
  557. if not(current_module.is_unit) then
  558. begin
  559. { Heaptrc unit, load heaptrace before any other units especially objpas }
  560. if (cs_use_heaptrc in current_settings.globalswitches) then
  561. AddUnit('heaptrc');
  562. { Lineinfo unit }
  563. if (cs_use_lineinfo in current_settings.globalswitches) then begin
  564. if (paratargetdbg = dbg_stabs) then
  565. AddUnit('lineinfo')
  566. else
  567. AddUnit('lnfodwrf');
  568. end;
  569. { Valgrind requires c memory manager }
  570. if (cs_gdb_valgrind in current_settings.globalswitches) then
  571. AddUnit('cmem');
  572. {$ifdef cpufpemu}
  573. { Floating point emulation unit?
  574. softfpu must be in the system unit anyways (FK)
  575. if (cs_fp_emulation in current_settings.moduleswitches) and not(target_info.system in system_wince) then
  576. AddUnit('softfpu');
  577. }
  578. {$endif cpufpemu}
  579. { Which kind of resource support?
  580. Note: if resources aren't used this unit will be removed later,
  581. otherwise we need it here since it must be loaded quite early }
  582. if (tf_has_winlike_resources in target_info.flags) then
  583. if target_res.id=res_ext then
  584. AddUnit('fpextres')
  585. else
  586. AddUnit('fpintres');
  587. end;
  588. { Objpas unit? }
  589. if m_objpas in current_settings.modeswitches then
  590. AddUnit('objpas');
  591. { Macpas unit? }
  592. if m_mac in current_settings.modeswitches then
  593. AddUnit('macpas');
  594. { Objective-C 1.0 support unit? }
  595. if (m_objectivec1 in current_settings.modeswitches) then
  596. begin
  597. { interface to Objective-C run time }
  598. AddUnit('objc');
  599. loadobjctypes;
  600. { NSObject }
  601. if not(current_module.is_unit) or
  602. (current_module.modulename^<>'OBJCBASE') then
  603. AddUnit('objcbase');
  604. end;
  605. { Profile unit? Needed for go32v2 only }
  606. if (cs_profile in current_settings.moduleswitches) and
  607. (target_info.system in [system_i386_go32v2,system_i386_watcom]) then
  608. AddUnit('profile');
  609. if (cs_load_fpcylix_unit in current_settings.globalswitches) then
  610. begin
  611. AddUnit('fpcylix');
  612. AddUnit('dynlibs');
  613. end;
  614. { CPU targets with microcontroller support can add a controller specific unit }
  615. {$if defined(ARM)}
  616. if (target_info.system in systems_embedded) and (current_settings.controllertype<>ct_none) then
  617. AddUnit(controllerunitstr[current_settings.controllertype]);
  618. {$endif ARM}
  619. end;
  620. procedure loadautounits;
  621. var
  622. hs,s : string;
  623. begin
  624. hs:=autoloadunits;
  625. repeat
  626. s:=GetToken(hs,',');
  627. if s='' then
  628. break;
  629. AddUnit(s);
  630. until false;
  631. end;
  632. procedure loadunits;
  633. var
  634. s,sorg : TIDString;
  635. fn : string;
  636. pu : tused_unit;
  637. hp2 : tmodule;
  638. unitsym : tunitsym;
  639. begin
  640. consume(_USES);
  641. repeat
  642. s:=pattern;
  643. sorg:=orgpattern;
  644. consume(_ID);
  645. { support "<unit> in '<file>'" construct, but not for tp7 }
  646. fn:='';
  647. if not(m_tp7 in current_settings.modeswitches) and
  648. try_to_consume(_OP_IN) then
  649. fn:=FixFileName(get_stringconst);
  650. { Give a warning if lineinfo is loaded }
  651. if s='LINEINFO' then begin
  652. Message(parser_w_no_lineinfo_use_switch);
  653. if (paratargetdbg in [dbg_dwarf2, dbg_dwarf3]) then
  654. s := 'LNFODWRF';
  655. sorg := s;
  656. end;
  657. { Give a warning if objpas is loaded }
  658. if s='OBJPAS' then
  659. Message(parser_w_no_objpas_use_mode);
  660. { Using the unit itself is not possible }
  661. if (s<>current_module.modulename^) then
  662. begin
  663. { check if the unit is already used }
  664. hp2:=nil;
  665. pu:=tused_unit(current_module.used_units.first);
  666. while assigned(pu) do
  667. begin
  668. if (pu.u.modulename^=s) then
  669. begin
  670. hp2:=pu.u;
  671. break;
  672. end;
  673. pu:=tused_unit(pu.next);
  674. end;
  675. if not assigned(hp2) then
  676. hp2:=registerunit(current_module,sorg,fn)
  677. else
  678. Message1(sym_e_duplicate_id,s);
  679. { Create unitsym, we need to use the name as specified, we
  680. can not use the modulename because that can be different
  681. when -Un is used }
  682. unitsym:=tunitsym.create(sorg,nil);
  683. current_module.localsymtable.insert(unitsym);
  684. { the current module uses the unit hp2 }
  685. current_module.addusedunit(hp2,true,unitsym);
  686. end
  687. else
  688. Message1(sym_e_duplicate_id,s);
  689. if token=_COMMA then
  690. begin
  691. pattern:='';
  692. consume(_COMMA);
  693. end
  694. else
  695. break;
  696. until false;
  697. { Load the units }
  698. pu:=tused_unit(current_module.used_units.first);
  699. while assigned(pu) do
  700. begin
  701. { Only load the units that are in the current
  702. (interface/implementation) uses clause }
  703. if pu.in_uses and
  704. (pu.in_interface=current_module.in_interface) then
  705. begin
  706. tppumodule(pu.u).loadppu;
  707. { is our module compiled? then we can stop }
  708. if current_module.state=ms_compiled then
  709. exit;
  710. { add this unit to the dependencies }
  711. pu.u.adddependency(current_module);
  712. { save crc values }
  713. pu.checksum:=pu.u.crc;
  714. pu.interface_checksum:=pu.u.interface_crc;
  715. pu.indirect_checksum:=pu.u.indirect_crc;
  716. { connect unitsym to the module }
  717. pu.unitsym.module:=pu.u;
  718. { add to symtable stack }
  719. symtablestack.push(pu.u.globalsymtable);
  720. if (m_mac in current_settings.modeswitches) and
  721. assigned(pu.u.globalmacrosymtable) then
  722. macrosymtablestack.push(pu.u.globalmacrosymtable);
  723. { check hints }
  724. pu.u.check_hints;
  725. end;
  726. pu:=tused_unit(pu.next);
  727. end;
  728. consume(_SEMICOLON);
  729. end;
  730. procedure reset_all_defs;
  731. procedure reset_used_unit_defs(hp:tmodule);
  732. var
  733. pu : tused_unit;
  734. begin
  735. pu:=tused_unit(hp.used_units.first);
  736. while assigned(pu) do
  737. begin
  738. if not pu.u.is_reset then
  739. begin
  740. { prevent infinte loop for circular dependencies }
  741. pu.u.is_reset:=true;
  742. if assigned(pu.u.globalsymtable) then
  743. begin
  744. tglobalsymtable(pu.u.globalsymtable).reset_all_defs;
  745. reset_used_unit_defs(pu.u);
  746. end;
  747. end;
  748. pu:=tused_unit(pu.next);
  749. end;
  750. end;
  751. var
  752. hp2 : tmodule;
  753. begin
  754. hp2:=tmodule(loaded_units.first);
  755. while assigned(hp2) do
  756. begin
  757. hp2.is_reset:=false;
  758. hp2:=tmodule(hp2.next);
  759. end;
  760. reset_used_unit_defs(current_module);
  761. end;
  762. procedure free_localsymtables(st:TSymtable);
  763. var
  764. i : longint;
  765. def : tstoreddef;
  766. pd : tprocdef;
  767. begin
  768. for i:=0 to st.DefList.Count-1 do
  769. begin
  770. def:=tstoreddef(st.DefList[i]);
  771. if def.typ=procdef then
  772. begin
  773. pd:=tprocdef(def);
  774. if assigned(pd.localst) and
  775. (pd.localst.symtabletype<>staticsymtable) and
  776. not(po_inline in pd.procoptions) then
  777. begin
  778. free_localsymtables(pd.localst);
  779. pd.localst.free;
  780. pd.localst:=nil;
  781. end;
  782. end;
  783. end;
  784. end;
  785. procedure parse_implementation_uses;
  786. begin
  787. if token=_USES then
  788. loadunits;
  789. end;
  790. procedure setupglobalswitches;
  791. begin
  792. if (cs_create_pic in current_settings.moduleswitches) then
  793. begin
  794. def_system_macro('FPC_PIC');
  795. def_system_macro('PIC');
  796. end;
  797. end;
  798. function create_main_proc(const name:string;potype:tproctypeoption;st:TSymtable):tcgprocinfo;
  799. var
  800. ps : tprocsym;
  801. pd : tprocdef;
  802. begin
  803. { there should be no current_procinfo available }
  804. if assigned(current_procinfo) then
  805. internalerror(200304275);
  806. {Generate a procsym for main}
  807. ps:=tprocsym.create('$'+name);
  808. { main are allways used }
  809. inc(ps.refs);
  810. st.insert(ps);
  811. pd:=tprocdef.create(main_program_level);
  812. include(pd.procoptions,po_global);
  813. pd.procsym:=ps;
  814. ps.ProcdefList.Add(pd);
  815. { set procdef options }
  816. pd.proctypeoption:=potype;
  817. pd.proccalloption:=pocall_default;
  818. include(pd.procoptions,po_hascallingconvention);
  819. pd.forwarddef:=false;
  820. pd.setmangledname(target_info.cprefix+name);
  821. pd.aliasnames.insert(pd.mangledname);
  822. handle_calling_convention(pd);
  823. { We don't need is a local symtable. Change it into the static
  824. symtable }
  825. pd.localst.free;
  826. pd.localst:=st;
  827. { set procinfo and current_procinfo.procdef }
  828. result:=tcgprocinfo(cprocinfo.create(nil));
  829. result.procdef:=pd;
  830. { main proc does always a call e.g. to init system unit }
  831. include(result.flags,pi_do_call);
  832. end;
  833. procedure release_main_proc(pi:tcgprocinfo);
  834. begin
  835. { remove localst as it was replaced by staticsymtable }
  836. pi.procdef.localst:=nil;
  837. { remove procinfo }
  838. current_module.procinfo:=nil;
  839. pi.free;
  840. pi:=nil;
  841. end;
  842. function gen_implicit_initfinal(flag:word;st:TSymtable):tcgprocinfo;
  843. begin
  844. { update module flags }
  845. current_module.flags:=current_module.flags or flag;
  846. { create procdef }
  847. case flag of
  848. uf_init :
  849. begin
  850. result:=create_main_proc(make_mangledname('',current_module.localsymtable,'init_implicit'),potype_unitinit,st);
  851. result.procdef.aliasnames.insert(make_mangledname('INIT$',current_module.localsymtable,''));
  852. end;
  853. uf_finalize :
  854. begin
  855. result:=create_main_proc(make_mangledname('',current_module.localsymtable,'finalize_implicit'),potype_unitfinalize,st);
  856. result.procdef.aliasnames.insert(make_mangledname('FINALIZE$',current_module.localsymtable,''));
  857. if (not current_module.is_unit) then
  858. result.procdef.aliasnames.insert('PASCALFINALIZE');
  859. end;
  860. else
  861. internalerror(200304253);
  862. end;
  863. result.code:=cnothingnode.create;
  864. end;
  865. procedure copy_macro(p:TObject; arg:pointer);
  866. begin
  867. current_module.globalmacrosymtable.insert(tmacro(p).getcopy);
  868. end;
  869. function try_consume_hintdirective(var moduleopt:tmoduleoptions; var deprecatedmsg:pshortstring):boolean;
  870. var
  871. last_is_deprecated:boolean;
  872. begin
  873. try_consume_hintdirective:=false;
  874. repeat
  875. last_is_deprecated:=false;
  876. case idtoken of
  877. _LIBRARY :
  878. begin
  879. include(moduleopt,mo_hint_library);
  880. try_consume_hintdirective:=true;
  881. end;
  882. _DEPRECATED :
  883. begin
  884. include(moduleopt,mo_hint_deprecated);
  885. try_consume_hintdirective:=true;
  886. last_is_deprecated:=true;
  887. end;
  888. _EXPERIMENTAL :
  889. begin
  890. include(moduleopt,mo_hint_experimental);
  891. try_consume_hintdirective:=true;
  892. end;
  893. _PLATFORM :
  894. begin
  895. include(moduleopt,mo_hint_platform);
  896. try_consume_hintdirective:=true;
  897. end;
  898. _UNIMPLEMENTED :
  899. begin
  900. include(moduleopt,mo_hint_unimplemented);
  901. try_consume_hintdirective:=true;
  902. end;
  903. else
  904. break;
  905. end;
  906. consume(Token);
  907. { handle deprecated message }
  908. if ((token=_CSTRING) or (token=_CCHAR)) and last_is_deprecated then
  909. begin
  910. if deprecatedmsg<>nil then
  911. internalerror(201001221);
  912. if token=_CSTRING then
  913. deprecatedmsg:=stringdup(cstringpattern)
  914. else
  915. deprecatedmsg:=stringdup(pattern);
  916. consume(token);
  917. include(moduleopt,mo_has_deprecated_msg);
  918. end;
  919. until false;
  920. end;
  921. procedure proc_unit;
  922. function is_assembler_generated:boolean;
  923. var
  924. hal : tasmlisttype;
  925. begin
  926. result:=false;
  927. if Errorcount=0 then
  928. begin
  929. for hal:=low(TasmlistType) to high(TasmlistType) do
  930. if not current_asmdata.asmlists[hal].empty then
  931. begin
  932. result:=true;
  933. exit;
  934. end;
  935. end;
  936. end;
  937. var
  938. main_file: tinputfile;
  939. {$ifdef EXTDEBUG}
  940. store_crc,
  941. {$endif EXTDEBUG}
  942. store_interface_crc,
  943. store_indirect_crc: cardinal;
  944. s1,s2 : ^string; {Saves stack space}
  945. force_init_final : boolean;
  946. init_procinfo,
  947. finalize_procinfo : tcgprocinfo;
  948. unitname8 : string[8];
  949. ag: boolean;
  950. {$ifdef i386}
  951. gotvarsym : tstaticvarsym;
  952. {$endif i386}
  953. {$ifdef debug_devirt}
  954. i: longint;
  955. {$endif debug_devirt}
  956. begin
  957. init_procinfo:=nil;
  958. finalize_procinfo:=nil;
  959. if m_mac in current_settings.modeswitches then
  960. current_module.mode_switch_allowed:= false;
  961. consume(_UNIT);
  962. if compile_level=1 then
  963. Status.IsExe:=false;
  964. if token=_ID then
  965. begin
  966. { create filenames and unit name }
  967. main_file := current_scanner.inputfile;
  968. while assigned(main_file.next) do
  969. main_file := main_file.next;
  970. new(s1);
  971. s1^:=current_module.modulename^;
  972. current_module.SetFileName(main_file.path^+main_file.name^,true);
  973. current_module.SetModuleName(orgpattern);
  974. { check for system unit }
  975. new(s2);
  976. s2^:=upper(ChangeFileExt(ExtractFileName(main_file.name^),''));
  977. unitname8:=copy(current_module.modulename^,1,8);
  978. if (cs_check_unit_name in current_settings.globalswitches) and
  979. (
  980. not(
  981. (current_module.modulename^=s2^) or
  982. (
  983. (length(current_module.modulename^)>8) and
  984. (unitname8=s2^)
  985. )
  986. )
  987. or
  988. (
  989. (length(s1^)>8) and
  990. (s1^<>current_module.modulename^)
  991. )
  992. ) then
  993. Message1(unit_e_illegal_unit_name,current_module.realmodulename^);
  994. if (current_module.modulename^='SYSTEM') then
  995. include(current_settings.moduleswitches,cs_compilesystem);
  996. dispose(s2);
  997. dispose(s1);
  998. end;
  999. if (target_info.system in systems_unit_program_exports) then
  1000. exportlib.preparelib(current_module.realmodulename^);
  1001. consume(_ID);
  1002. { parse hint directives }
  1003. try_consume_hintdirective(current_module.moduleoptions, current_module.deprecatedmsg);
  1004. consume(_SEMICOLON);
  1005. consume(_INTERFACE);
  1006. { global switches are read, so further changes aren't allowed }
  1007. current_module.in_global:=false;
  1008. { handle the global switches }
  1009. setupglobalswitches;
  1010. message1(unit_u_loading_interface_units,current_module.modulename^);
  1011. { update status }
  1012. status.currentmodule:=current_module.realmodulename^;
  1013. { maybe turn off m_objpas if we are compiling objpas }
  1014. if (current_module.modulename^='OBJPAS') then
  1015. exclude(current_settings.modeswitches,m_objpas);
  1016. { maybe turn off m_mac if we are compiling macpas }
  1017. if (current_module.modulename^='MACPAS') then
  1018. exclude(current_settings.modeswitches,m_mac);
  1019. parse_only:=true;
  1020. { generate now the global symboltable,
  1021. define first as local to overcome dependency conflicts }
  1022. current_module.localsymtable:=tglobalsymtable.create(current_module.modulename^,current_module.moduleid);
  1023. { insert unitsym of this unit to prevent other units having
  1024. the same name }
  1025. current_module.localsymtable.insert(tunitsym.create(current_module.realmodulename^,current_module));
  1026. { load default units, like the system unit }
  1027. loaddefaultunits;
  1028. { insert qualifier for the system unit (allows system.writeln) }
  1029. if not(cs_compilesystem in current_settings.moduleswitches) and
  1030. (token=_USES) then
  1031. begin
  1032. loadunits;
  1033. { has it been compiled at a higher level ?}
  1034. if current_module.state=ms_compiled then
  1035. exit;
  1036. end;
  1037. { move the global symtable from the temporary local to global }
  1038. current_module.globalsymtable:=current_module.localsymtable;
  1039. current_module.localsymtable:=nil;
  1040. reset_all_defs;
  1041. { number all units, so we know if a unit is used by this unit or
  1042. needs to be added implicitly }
  1043. current_module.updatemaps;
  1044. { create whole program optimisation information (may already be
  1045. updated in the interface, e.g., in case of classrefdef typed
  1046. constants }
  1047. current_module.wpoinfo:=tunitwpoinfo.create;
  1048. { ... parse the declarations }
  1049. Message1(parser_u_parsing_interface,current_module.realmodulename^);
  1050. symtablestack.push(current_module.globalsymtable);
  1051. read_interface_declarations;
  1052. symtablestack.pop(current_module.globalsymtable);
  1053. { Export macros defined in the interface for macpas. The macros
  1054. are put in the globalmacrosymtable that will only be used by other
  1055. units. The current unit continues to use the localmacrosymtable }
  1056. if (m_mac in current_settings.modeswitches) then
  1057. begin
  1058. current_module.globalmacrosymtable:=tmacrosymtable.create(true);
  1059. current_module.localmacrosymtable.SymList.ForEachCall(@copy_macro,nil);
  1060. end;
  1061. { leave when we got an error }
  1062. if (Errorcount>0) and not status.skip_error then
  1063. begin
  1064. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  1065. status.skip_error:=true;
  1066. exit;
  1067. end;
  1068. { Our interface is compiled, generate CRC and switch to implementation }
  1069. if not(cs_compilesystem in current_settings.moduleswitches) and
  1070. (Errorcount=0) then
  1071. tppumodule(current_module).getppucrc;
  1072. current_module.in_interface:=false;
  1073. current_module.interface_compiled:=true;
  1074. { First reload all units depending on our interface, we need to do this
  1075. in the implementation part to prevent erroneous circular references }
  1076. tppumodule(current_module).setdefgeneration;
  1077. tppumodule(current_module).reload_flagged_units;
  1078. { Parse the implementation section }
  1079. if (m_mac in current_settings.modeswitches) and try_to_consume(_END) then
  1080. current_module.interface_only:=true
  1081. else
  1082. current_module.interface_only:=false;
  1083. parse_only:=false;
  1084. { create static symbol table }
  1085. current_module.localsymtable:=tstaticsymtable.create(current_module.modulename^,current_module.moduleid);
  1086. {$ifdef i386}
  1087. if cs_create_pic in current_settings.moduleswitches then
  1088. begin
  1089. { insert symbol for got access in assembler code}
  1090. gotvarsym:=tstaticvarsym.create('_GLOBAL_OFFSET_TABLE_',vs_value,voidpointertype,[vo_is_external]);
  1091. gotvarsym.set_mangledname('_GLOBAL_OFFSET_TABLE_');
  1092. current_module.localsymtable.insert(gotvarsym);
  1093. { avoid unnecessary warnings }
  1094. gotvarsym.varstate:=vs_read;
  1095. gotvarsym.refs:=1;
  1096. end;
  1097. {$endif i386}
  1098. if not current_module.interface_only then
  1099. begin
  1100. consume(_IMPLEMENTATION);
  1101. Message1(unit_u_loading_implementation_units,current_module.modulename^);
  1102. { Read the implementation units }
  1103. parse_implementation_uses;
  1104. end;
  1105. if current_module.state=ms_compiled then
  1106. exit;
  1107. { reset ranges/stabs in exported definitions }
  1108. reset_all_defs;
  1109. { All units are read, now give them a number }
  1110. current_module.updatemaps;
  1111. symtablestack.push(current_module.globalsymtable);
  1112. symtablestack.push(current_module.localsymtable);
  1113. if not current_module.interface_only then
  1114. begin
  1115. Message1(parser_u_parsing_implementation,current_module.modulename^);
  1116. if current_module.in_interface then
  1117. internalerror(200212285);
  1118. { Compile the unit }
  1119. init_procinfo:=create_main_proc(make_mangledname('',current_module.localsymtable,'init'),potype_unitinit,current_module.localsymtable);
  1120. init_procinfo.procdef.aliasnames.insert(make_mangledname('INIT$',current_module.localsymtable,''));
  1121. init_procinfo.parse_body;
  1122. { save file pos for debuginfo }
  1123. current_module.mainfilepos:=init_procinfo.entrypos;
  1124. end;
  1125. { Generate specializations of objectdefs methods }
  1126. generate_specialization_procs;
  1127. { if the unit contains ansi/widestrings, initialization and
  1128. finalization code must be forced }
  1129. force_init_final:=tglobalsymtable(current_module.globalsymtable).needs_init_final or
  1130. tstaticsymtable(current_module.localsymtable).needs_init_final;
  1131. { should we force unit initialization? }
  1132. { this is a hack, but how can it be done better ? }
  1133. if force_init_final and ((current_module.flags and uf_init)=0) then
  1134. begin
  1135. { first release the not used init procinfo }
  1136. if assigned(init_procinfo) then
  1137. release_main_proc(init_procinfo);
  1138. init_procinfo:=gen_implicit_initfinal(uf_init,current_module.localsymtable);
  1139. end;
  1140. { finalize? }
  1141. if not current_module.interface_only and (token=_FINALIZATION) then
  1142. begin
  1143. { the uf_finalize flag is only set after we checked that it
  1144. wasn't empty }
  1145. { Compile the finalize }
  1146. finalize_procinfo:=create_main_proc(make_mangledname('',current_module.localsymtable,'finalize'),potype_unitfinalize,current_module.localsymtable);
  1147. finalize_procinfo.procdef.aliasnames.insert(make_mangledname('FINALIZE$',current_module.localsymtable,''));
  1148. finalize_procinfo.parse_body;
  1149. end
  1150. else if force_init_final then
  1151. finalize_procinfo:=gen_implicit_initfinal(uf_finalize,current_module.localsymtable);
  1152. { Now both init and finalize bodies are read and it is known
  1153. which variables are used in both init and finalize we can now
  1154. generate the code. This is required to prevent putting a variable in
  1155. a register that is also used in the finalize body (PFV) }
  1156. if assigned(init_procinfo) then
  1157. begin
  1158. init_procinfo.generate_code;
  1159. init_procinfo.resetprocdef;
  1160. release_main_proc(init_procinfo);
  1161. end;
  1162. if assigned(finalize_procinfo) then
  1163. begin
  1164. finalize_procinfo.generate_code;
  1165. finalize_procinfo.resetprocdef;
  1166. release_main_proc(finalize_procinfo);
  1167. end;
  1168. symtablestack.pop(current_module.localsymtable);
  1169. symtablestack.pop(current_module.globalsymtable);
  1170. { the last char should always be a point }
  1171. consume(_POINT);
  1172. if (Errorcount=0) then
  1173. begin
  1174. { tests, if all (interface) forwards are resolved }
  1175. tstoredsymtable(current_module.globalsymtable).check_forwards;
  1176. { check if all private fields are used }
  1177. tstoredsymtable(current_module.globalsymtable).allprivatesused;
  1178. { test static symtable }
  1179. tstoredsymtable(current_module.localsymtable).allsymbolsused;
  1180. tstoredsymtable(current_module.localsymtable).allprivatesused;
  1181. tstoredsymtable(current_module.localsymtable).check_forwards;
  1182. tstoredsymtable(current_module.localsymtable).checklabels;
  1183. { used units }
  1184. current_module.allunitsused;
  1185. end;
  1186. { leave when we got an error }
  1187. if (Errorcount>0) and not status.skip_error then
  1188. begin
  1189. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  1190. status.skip_error:=true;
  1191. exit;
  1192. end;
  1193. { if an Objective-C module, generate rtti and module info }
  1194. MaybeGenerateObjectiveCImageInfo(current_module.globalsymtable,current_module.localsymtable);
  1195. { do we need to add the variants unit? }
  1196. maybeloadvariantsunit;
  1197. { generate wrappers for interfaces }
  1198. gen_intf_wrappers(current_asmdata.asmlists[al_procedures],current_module.globalsymtable);
  1199. gen_intf_wrappers(current_asmdata.asmlists[al_procedures],current_module.localsymtable);
  1200. { generate pic helpers to load eip if necessary }
  1201. gen_pic_helpers(current_asmdata.asmlists[al_procedures]);
  1202. { generate rtti/init tables }
  1203. write_persistent_type_info(current_module.globalsymtable);
  1204. write_persistent_type_info(current_module.localsymtable);
  1205. { Tables }
  1206. insertThreadVars;
  1207. { Resource strings }
  1208. GenerateResourceStrings;
  1209. { Widestring typed constants }
  1210. InsertWideInits;
  1211. { generate debuginfo }
  1212. if (cs_debuginfo in current_settings.moduleswitches) then
  1213. current_debuginfo.inserttypeinfo;
  1214. { generate imports }
  1215. if current_module.ImportLibraryList.Count>0 then
  1216. importlib.generatelib;
  1217. { insert own objectfile, or say that it's in a library
  1218. (no check for an .o when loading) }
  1219. ag:=is_assembler_generated;
  1220. if ag then
  1221. insertobjectfile
  1222. else
  1223. begin
  1224. current_module.flags:=current_module.flags or uf_no_link;
  1225. current_module.flags:=current_module.flags and not (uf_has_stabs_debuginfo or uf_has_dwarf_debuginfo);
  1226. end;
  1227. if ag then
  1228. begin
  1229. { create callframe info }
  1230. create_dwarf_frame;
  1231. { assemble }
  1232. create_objectfile;
  1233. end;
  1234. { Write out the ppufile after the object file has been created }
  1235. store_interface_crc:=current_module.interface_crc;
  1236. store_indirect_crc:=current_module.indirect_crc;
  1237. {$ifdef EXTDEBUG}
  1238. store_crc:=current_module.crc;
  1239. {$endif EXTDEBUG}
  1240. if (Errorcount=0) then
  1241. tppumodule(current_module).writeppu;
  1242. if not(cs_compilesystem in current_settings.moduleswitches) then
  1243. begin
  1244. if store_interface_crc<>current_module.interface_crc then
  1245. Message1(unit_u_interface_crc_changed,current_module.ppufilename^);
  1246. if store_indirect_crc<>current_module.indirect_crc then
  1247. Message1(unit_u_indirect_crc_changed,current_module.ppufilename^);
  1248. end;
  1249. {$ifdef EXTDEBUG}
  1250. if not(cs_compilesystem in current_settings.moduleswitches) then
  1251. if (store_crc<>current_module.crc) and simplify_ppu then
  1252. Message1(unit_u_implementation_crc_changed,current_module.ppufilename^);
  1253. {$endif EXTDEBUG}
  1254. { release local symtables that are not needed anymore }
  1255. free_localsymtables(current_module.globalsymtable);
  1256. free_localsymtables(current_module.localsymtable);
  1257. { leave when we got an error }
  1258. if (Errorcount>0) and not status.skip_error then
  1259. begin
  1260. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  1261. status.skip_error:=true;
  1262. exit;
  1263. end;
  1264. {$ifdef debug_devirt}
  1265. { print out all instantiated class/object types }
  1266. writeln('constructed object/class/classreftypes in ',current_module.realmodulename^);
  1267. for i := 0 to current_module.wpoinfo.createdobjtypes.count-1 do
  1268. begin
  1269. write(' ',tdef(current_module.wpoinfo.createdobjtypes[i]).GetTypeName);
  1270. case tdef(current_module.wpoinfo.createdobjtypes[i]).typ of
  1271. objectdef:
  1272. case tobjectdef(current_module.wpoinfo.createdobjtypes[i]).objecttype of
  1273. odt_object:
  1274. writeln(' (object)');
  1275. odt_class:
  1276. writeln(' (class)');
  1277. else
  1278. internalerror(2008101103);
  1279. end;
  1280. else
  1281. internalerror(2008101104);
  1282. end;
  1283. end;
  1284. for i := 0 to current_module.wpoinfo.createdclassrefobjtypes.count-1 do
  1285. begin
  1286. write(' Class Of ',tdef(current_module.wpoinfo.createdclassrefobjtypes[i]).GetTypeName);
  1287. case tdef(current_module.wpoinfo.createdclassrefobjtypes[i]).typ of
  1288. objectdef:
  1289. case tobjectdef(current_module.wpoinfo.createdclassrefobjtypes[i]).objecttype of
  1290. odt_class:
  1291. writeln(' (classrefdef)');
  1292. else
  1293. internalerror(2008101105);
  1294. end
  1295. else
  1296. internalerror(2008101102);
  1297. end;
  1298. end;
  1299. {$endif debug_devirt}
  1300. Message1(unit_u_finished_compiling,current_module.modulename^);
  1301. end;
  1302. procedure procexport(const s : string);
  1303. var
  1304. hp : texported_item;
  1305. begin
  1306. hp:=texported_item.create;
  1307. hp.name:=stringdup(s);
  1308. hp.options:=hp.options or eo_name;
  1309. exportlib.exportprocedure(hp);
  1310. end;
  1311. procedure varexport(const s : string);
  1312. var
  1313. hp : texported_item;
  1314. begin
  1315. hp:=texported_item.create;
  1316. hp.name:=stringdup(s);
  1317. hp.options:=hp.options or eo_name;
  1318. exportlib.exportvar(hp);
  1319. end;
  1320. procedure insert_export(sym : TObject;arg:pointer);
  1321. var
  1322. i : longint;
  1323. item : TCmdStrListItem;
  1324. begin
  1325. case TSym(sym).typ of
  1326. { ignore: }
  1327. unitsym,
  1328. syssym,
  1329. constsym,
  1330. enumsym,
  1331. typesym:
  1332. ;
  1333. procsym:
  1334. begin
  1335. for i:=0 to tprocsym(sym).ProcdefList.Count-1 do
  1336. begin
  1337. if not(tprocdef(tprocsym(sym).ProcdefList[i]).proccalloption in [pocall_internproc]) and
  1338. ((tprocdef(tprocsym(sym).ProcdefList[i]).procoptions*[po_external])=[]) and
  1339. ((tsymtable(arg).symtabletype=globalsymtable) or
  1340. ((tsymtable(arg).symtabletype=staticsymtable) and (po_public in tprocdef(tprocsym(sym).ProcdefList[i]).procoptions))
  1341. ) then
  1342. begin
  1343. procexport(tprocdef(tprocsym(sym).ProcdefList[i]).mangledname);
  1344. { walk through all aliases }
  1345. item:=TCmdStrListItem(tprocdef(tprocsym(sym).ProcdefList[i]).aliasnames.first);
  1346. while assigned(item) do
  1347. begin
  1348. { avoid duplicate entries, sometimes aliasnames contains the mangledname }
  1349. if item.str<>tprocdef(tprocsym(sym).ProcdefList[i]).mangledname then
  1350. procexport(item.str);
  1351. item:=TCmdStrListItem(item.next);
  1352. end;
  1353. end;
  1354. end;
  1355. end;
  1356. staticvarsym:
  1357. begin
  1358. varexport(tsym(sym).mangledname);
  1359. end;
  1360. else
  1361. begin
  1362. writeln('unknown: ',ord(TSym(sym).typ));
  1363. end;
  1364. end;
  1365. end;
  1366. Function RewritePPU(const PPUFn,PPLFn:String):Boolean;
  1367. Var
  1368. MakeStatic : Boolean;
  1369. Var
  1370. buffer : array[0..$1fff] of byte;
  1371. inppu,
  1372. outppu : tppufile;
  1373. b,
  1374. untilb : byte;
  1375. l,m : longint;
  1376. f : file;
  1377. ext,
  1378. s : string;
  1379. ppuversion : dword;
  1380. begin
  1381. Result:=false;
  1382. MakeStatic:=False;
  1383. inppu:=tppufile.create(PPUFn);
  1384. if not inppu.openfile then
  1385. begin
  1386. inppu.free;
  1387. Comment(V_Error,'Could not open : '+PPUFn);
  1388. Exit;
  1389. end;
  1390. { Check the ppufile }
  1391. if not inppu.CheckPPUId then
  1392. begin
  1393. inppu.free;
  1394. Comment(V_Error,'Not a PPU File : '+PPUFn);
  1395. Exit;
  1396. end;
  1397. ppuversion:=inppu.GetPPUVersion;
  1398. if ppuversion<CurrentPPUVersion then
  1399. begin
  1400. inppu.free;
  1401. Comment(V_Error,'Wrong PPU Version '+tostr(ppuversion)+' in '+PPUFn);
  1402. Exit;
  1403. end;
  1404. { No .o file generated for this ppu, just skip }
  1405. if (inppu.header.flags and uf_no_link)<>0 then
  1406. begin
  1407. inppu.free;
  1408. Result:=true;
  1409. Exit;
  1410. end;
  1411. { Already a lib? }
  1412. if (inppu.header.flags and uf_in_library)<>0 then
  1413. begin
  1414. inppu.free;
  1415. Comment(V_Error,'PPU is already in a library : '+PPUFn);
  1416. Exit;
  1417. end;
  1418. { We need a static linked unit }
  1419. if (inppu.header.flags and uf_static_linked)=0 then
  1420. begin
  1421. inppu.free;
  1422. Comment(V_Error,'PPU is not static linked : '+PPUFn);
  1423. Exit;
  1424. end;
  1425. { Check if shared is allowed }
  1426. if tsystem(inppu.header.target) in [system_i386_go32v2] then
  1427. begin
  1428. Comment(V_Error,'Shared library not supported for ppu target, switching to static library');
  1429. MakeStatic:=true;
  1430. end;
  1431. { Create the new ppu }
  1432. if PPUFn=PPLFn then
  1433. outppu:=tppufile.create('ppumove.$$$')
  1434. else
  1435. outppu:=tppufile.create(PPLFn);
  1436. outppu.createfile;
  1437. { Create new header, with the new flags }
  1438. outppu.header:=inppu.header;
  1439. outppu.header.flags:=outppu.header.flags or uf_in_library;
  1440. if MakeStatic then
  1441. outppu.header.flags:=outppu.header.flags or uf_static_linked
  1442. else
  1443. outppu.header.flags:=outppu.header.flags or uf_shared_linked;
  1444. { read until the object files are found }
  1445. untilb:=iblinkunitofiles;
  1446. repeat
  1447. b:=inppu.readentry;
  1448. if b in [ibendinterface,ibend] then
  1449. begin
  1450. inppu.free;
  1451. outppu.free;
  1452. Comment(V_Error,'No files to be linked found : '+PPUFn);
  1453. Exit;
  1454. end;
  1455. if b<>untilb then
  1456. begin
  1457. repeat
  1458. inppu.getdatabuf(buffer,sizeof(buffer),l);
  1459. outppu.putdata(buffer,l);
  1460. until l<sizeof(buffer);
  1461. outppu.writeentry(b);
  1462. end;
  1463. until (b=untilb);
  1464. { we have now reached the section for the files which need to be added,
  1465. now add them to the list }
  1466. case b of
  1467. iblinkunitofiles :
  1468. begin
  1469. { add all o files, and save the entry when not creating a static
  1470. library to keep staticlinking possible }
  1471. while not inppu.endofentry do
  1472. begin
  1473. s:=inppu.getstring;
  1474. m:=inppu.getlongint;
  1475. if not MakeStatic then
  1476. begin
  1477. outppu.putstring(s);
  1478. outppu.putlongint(m);
  1479. end;
  1480. current_module.linkotherofiles.add(s,link_always);;
  1481. end;
  1482. if not MakeStatic then
  1483. outppu.writeentry(b);
  1484. end;
  1485. { iblinkunitstaticlibs :
  1486. begin
  1487. AddToLinkFiles(ExtractLib(inppu.getstring));
  1488. if not inppu.endofentry then
  1489. begin
  1490. repeat
  1491. inppu.getdatabuf(buffer^,bufsize,l);
  1492. outppu.putdata(buffer^,l);
  1493. until l<bufsize;
  1494. outppu.writeentry(b);
  1495. end;
  1496. end; }
  1497. end;
  1498. { just add a new entry with the new lib }
  1499. if MakeStatic then
  1500. begin
  1501. outppu.putstring('imp'+current_module.realmodulename^);
  1502. outppu.putlongint(link_static);
  1503. outppu.writeentry(iblinkunitstaticlibs)
  1504. end
  1505. else
  1506. begin
  1507. outppu.putstring('imp'+current_module.realmodulename^);
  1508. outppu.putlongint(link_shared);
  1509. outppu.writeentry(iblinkunitsharedlibs);
  1510. end;
  1511. { read all entries until the end and write them also to the new ppu }
  1512. repeat
  1513. b:=inppu.readentry;
  1514. { don't write ibend, that's written automaticly }
  1515. if b<>ibend then
  1516. begin
  1517. if b=iblinkothersharedlibs then
  1518. begin
  1519. while not inppu.endofentry do
  1520. begin
  1521. s:=inppu.getstring;
  1522. m:=inppu.getlongint;
  1523. outppu.putstring(s);
  1524. outppu.putlongint(m);
  1525. { strip lib prefix }
  1526. if copy(s,1,3)='lib' then
  1527. delete(s,1,3);
  1528. ext:=ExtractFileExt(s);
  1529. if ext<>'' then
  1530. delete(s,length(s)-length(ext)+1,length(ext));
  1531. current_module.linkOtherSharedLibs.add(s,link_always);
  1532. end;
  1533. end
  1534. else
  1535. repeat
  1536. inppu.getdatabuf(buffer,sizeof(buffer),l);
  1537. outppu.putdata(buffer,l);
  1538. until l<sizeof(buffer);
  1539. outppu.writeentry(b);
  1540. end;
  1541. until b=ibend;
  1542. { write the last stuff and close }
  1543. outppu.flush;
  1544. outppu.writeheader;
  1545. outppu.free;
  1546. inppu.free;
  1547. { rename }
  1548. if PPUFn=PPLFn then
  1549. begin
  1550. {$I-}
  1551. assign(f,PPUFn);
  1552. erase(f);
  1553. assign(f,'ppumove.$$$');
  1554. rename(f,PPUFn);
  1555. {$I+}
  1556. if ioresult<>0 then;
  1557. end;
  1558. Result:=True;
  1559. end;
  1560. procedure createimportlibfromexports;
  1561. var
  1562. hp : texported_item;
  1563. begin
  1564. hp:=texported_item(current_module._exports.first);
  1565. while assigned(hp) do
  1566. begin
  1567. current_module.AddExternalImport(current_module.realmodulename^,hp.name^,hp.index,hp.is_var,false);
  1568. hp:=texported_item(hp.next);
  1569. end;
  1570. end;
  1571. procedure proc_package;
  1572. var
  1573. main_file : tinputfile;
  1574. hp,hp2 : tmodule;
  1575. {finalize_procinfo,
  1576. init_procinfo,
  1577. main_procinfo : tcgprocinfo;}
  1578. force_init_final : boolean;
  1579. uu : tused_unit;
  1580. begin
  1581. Status.IsPackage:=true;
  1582. Status.IsExe:=true;
  1583. parse_only:=false;
  1584. {main_procinfo:=nil;
  1585. init_procinfo:=nil;
  1586. finalize_procinfo:=nil;}
  1587. if not RelocSectionSetExplicitly then
  1588. RelocSection:=true;
  1589. { Relocation works only without stabs under Windows when }
  1590. { external linker (LD) is used. LD generates relocs for }
  1591. { stab sections which is not loaded in memory. It causes }
  1592. { AV error when DLL is loaded and relocation is needed. }
  1593. { Internal linker does not have this problem. }
  1594. if RelocSection and
  1595. (target_info.system in systems_all_windows+[system_i386_wdosx]) and
  1596. (cs_link_extern in current_settings.globalswitches) then
  1597. begin
  1598. include(current_settings.globalswitches,cs_link_strip);
  1599. { Warning stabs info does not work with reloc section !! }
  1600. if (cs_debuginfo in current_settings.moduleswitches) and
  1601. (target_dbg.id=dbg_stabs) then
  1602. begin
  1603. Message1(parser_w_parser_reloc_no_debug,current_module.mainsource^);
  1604. Message(parser_w_parser_win32_debug_needs_WN);
  1605. exclude(current_settings.moduleswitches,cs_debuginfo);
  1606. end;
  1607. end;
  1608. { get correct output names }
  1609. main_file := current_scanner.inputfile;
  1610. while assigned(main_file.next) do
  1611. main_file := main_file.next;
  1612. current_module.SetFileName(main_file.path^+main_file.name^,true);
  1613. consume(_ID);
  1614. current_module.setmodulename(orgpattern);
  1615. current_module.ispackage:=true;
  1616. exportlib.preparelib(orgpattern);
  1617. if tf_library_needs_pic in target_info.flags then
  1618. include(current_settings.moduleswitches,cs_create_pic);
  1619. consume(_ID);
  1620. consume(_SEMICOLON);
  1621. { global switches are read, so further changes aren't allowed }
  1622. current_module.in_global:=false;
  1623. { setup things using the switches }
  1624. setupglobalswitches;
  1625. { set implementation flag }
  1626. current_module.in_interface:=false;
  1627. current_module.interface_compiled:=true;
  1628. { insert after the unit symbol tables the static symbol table }
  1629. { of the program }
  1630. current_module.localsymtable:=tstaticsymtable.create(current_module.modulename^,current_module.moduleid);
  1631. {Load the units used by the program we compile.}
  1632. if token=_REQUIRES then
  1633. begin
  1634. end;
  1635. {Load the units used by the program we compile.}
  1636. if (token=_ID) and (idtoken=_CONTAINS) then
  1637. begin
  1638. consume(_ID);
  1639. while true do
  1640. begin
  1641. if token=_ID then
  1642. AddUnit(pattern);
  1643. consume(_ID);
  1644. if token=_COMMA then
  1645. consume(_COMMA)
  1646. else break;
  1647. end;
  1648. consume(_SEMICOLON);
  1649. end;
  1650. { reset ranges/stabs in exported definitions }
  1651. reset_all_defs;
  1652. { All units are read, now give them a number }
  1653. current_module.updatemaps;
  1654. {Insert the name of the main program into the symbol table.}
  1655. if current_module.realmodulename^<>'' then
  1656. current_module.localsymtable.insert(tunitsym.create(current_module.realmodulename^,current_module));
  1657. Message1(parser_u_parsing_implementation,current_module.mainsource^);
  1658. symtablestack.push(current_module.localsymtable);
  1659. { create whole program optimisation information }
  1660. current_module.wpoinfo:=tunitwpoinfo.create;
  1661. { should we force unit initialization? }
  1662. force_init_final:=tstaticsymtable(current_module.localsymtable).needs_init_final;
  1663. if force_init_final then
  1664. {init_procinfo:=gen_implicit_initfinal(uf_init,current_module.localsymtable)};
  1665. { Add symbol to the exports section for win32 so smartlinking a
  1666. DLL will include the edata section }
  1667. if assigned(exportlib) and
  1668. (target_info.system in [system_i386_win32,system_i386_wdosx]) and
  1669. ((current_module.flags and uf_has_exports)<>0) then
  1670. current_asmdata.asmlists[al_procedures].concat(tai_const.createname(make_mangledname('EDATA',current_module.localsymtable,''),0));
  1671. { all labels must be defined before generating code }
  1672. if Errorcount=0 then
  1673. tstoredsymtable(current_module.localsymtable).checklabels;
  1674. symtablestack.pop(current_module.localsymtable);
  1675. { consume the last point }
  1676. consume(_END);
  1677. consume(_POINT);
  1678. if (Errorcount=0) then
  1679. begin
  1680. { test static symtable }
  1681. tstoredsymtable(current_module.localsymtable).allsymbolsused;
  1682. tstoredsymtable(current_module.localsymtable).allprivatesused;
  1683. tstoredsymtable(current_module.localsymtable).check_forwards;
  1684. current_module.allunitsused;
  1685. end;
  1686. new_section(current_asmdata.asmlists[al_globals],sec_data,'_FPCDummy',4);
  1687. current_asmdata.asmlists[al_globals].concat(tai_symbol.createname_global('_FPCDummy',AT_DATA,0));
  1688. current_asmdata.asmlists[al_globals].concat(tai_const.create_32bit(0));
  1689. new_section(current_asmdata.asmlists[al_procedures],sec_code,'',0);
  1690. current_asmdata.asmlists[al_procedures].concat(tai_symbol.createname_global('_DLLMainCRTStartup',AT_FUNCTION,0));
  1691. {$ifdef i386}
  1692. { fix me! }
  1693. current_asmdata.asmlists[al_procedures].concat(Taicpu.Op_const_reg(A_MOV,S_L,1,NR_EAX));
  1694. current_asmdata.asmlists[al_procedures].concat(Taicpu.Op_const(A_RET,S_W,12));
  1695. {$endif i386}
  1696. current_asmdata.asmlists[al_procedures].concat(tai_const.createname('_FPCDummy',0));
  1697. { leave when we got an error }
  1698. if (Errorcount>0) and not status.skip_error then
  1699. begin
  1700. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  1701. status.skip_error:=true;
  1702. exit;
  1703. end;
  1704. { remove all unused units, this happends when units are removed
  1705. from the uses clause in the source and the ppu was already being loaded }
  1706. hp:=tmodule(loaded_units.first);
  1707. while assigned(hp) do
  1708. begin
  1709. hp2:=hp;
  1710. hp:=tmodule(hp.next);
  1711. if hp2.is_unit and
  1712. not assigned(hp2.globalsymtable) then
  1713. loaded_units.remove(hp2);
  1714. end;
  1715. { force exports }
  1716. uu:=tused_unit(usedunits.first);
  1717. while assigned(uu) do
  1718. begin
  1719. uu.u.globalsymtable.symlist.ForEachCall(@insert_export,uu.u.globalsymtable);
  1720. { check localsymtable for exports too to get public symbols }
  1721. uu.u.localsymtable.symlist.ForEachCall(@insert_export,uu.u.localsymtable);
  1722. { create special exports }
  1723. if (uu.u.flags and uf_init)<>0 then
  1724. procexport(make_mangledname('INIT$',uu.u.globalsymtable,''));
  1725. if (uu.u.flags and uf_finalize)<>0 then
  1726. procexport(make_mangledname('FINALIZE$',uu.u.globalsymtable,''));
  1727. if (uu.u.flags and uf_threadvars)=uf_threadvars then
  1728. varexport(make_mangledname('THREADVARLIST',uu.u.globalsymtable,''));
  1729. uu:=tused_unit(uu.next);
  1730. end;
  1731. {$ifdef arm}
  1732. { Insert .pdata section for arm-wince.
  1733. It is needed for exception handling. }
  1734. if target_info.system in [system_arm_wince] then
  1735. InsertPData;
  1736. {$endif arm}
  1737. { generate debuginfo }
  1738. if (cs_debuginfo in current_settings.moduleswitches) then
  1739. current_debuginfo.inserttypeinfo;
  1740. exportlib.generatelib;
  1741. { write all our exports to the import library,
  1742. needs to be done after exportlib.generatelib; }
  1743. createimportlibfromexports;
  1744. { generate imports }
  1745. if current_module.ImportLibraryList.Count>0 then
  1746. importlib.generatelib;
  1747. { Reference all DEBUGINFO sections from the main .fpc section }
  1748. if (cs_debuginfo in current_settings.moduleswitches) then
  1749. current_debuginfo.referencesections(current_asmdata.asmlists[al_procedures]);
  1750. { insert own objectfile }
  1751. insertobjectfile;
  1752. { assemble and link }
  1753. create_objectfile;
  1754. { We might need the symbols info if not using
  1755. the default do_extractsymbolinfo
  1756. which is a dummy function PM }
  1757. needsymbolinfo:=do_extractsymbolinfo<>@def_extractsymbolinfo;
  1758. { release all local symtables that are not needed anymore }
  1759. if (not needsymbolinfo) then
  1760. free_localsymtables(current_module.localsymtable);
  1761. { leave when we got an error }
  1762. if (Errorcount>0) and not status.skip_error then
  1763. begin
  1764. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  1765. status.skip_error:=true;
  1766. exit;
  1767. end;
  1768. if (not current_module.is_unit) then
  1769. begin
  1770. { finally rewrite all units included into the package }
  1771. uu:=tused_unit(usedunits.first);
  1772. while assigned(uu) do
  1773. begin
  1774. RewritePPU(uu.u.ppufilename^,uu.u.ppufilename^);
  1775. uu:=tused_unit(uu.next);
  1776. end;
  1777. { create the executable when we are at level 1 }
  1778. if (compile_level=1) then
  1779. begin
  1780. { create global resource file by collecting all resource files }
  1781. CollectResourceFiles;
  1782. { write .def file }
  1783. if (cs_link_deffile in current_settings.globalswitches) then
  1784. deffile.writefile;
  1785. { insert all .o files from all loaded units and
  1786. unload the units, we don't need them anymore.
  1787. Keep the current_module because that is still needed }
  1788. hp:=tmodule(loaded_units.first);
  1789. while assigned(hp) do
  1790. begin
  1791. { the package itself contains no code so far }
  1792. linker.AddModuleFiles(hp);
  1793. hp2:=tmodule(hp.next);
  1794. if (hp<>current_module) and
  1795. (not needsymbolinfo) then
  1796. begin
  1797. loaded_units.remove(hp);
  1798. hp.free;
  1799. end;
  1800. hp:=hp2;
  1801. end;
  1802. linker.MakeSharedLibrary
  1803. end;
  1804. { Give Fatal with error count for linker errors }
  1805. if (Errorcount>0) and not status.skip_error then
  1806. begin
  1807. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  1808. status.skip_error:=true;
  1809. end;
  1810. end;
  1811. end;
  1812. procedure proc_program(islibrary : boolean);
  1813. var
  1814. main_file : tinputfile;
  1815. hp,hp2 : tmodule;
  1816. finalize_procinfo,
  1817. init_procinfo,
  1818. main_procinfo : tcgprocinfo;
  1819. force_init_final : boolean;
  1820. resources_used : boolean;
  1821. begin
  1822. DLLsource:=islibrary;
  1823. Status.IsLibrary:=IsLibrary;
  1824. Status.IsPackage:=false;
  1825. Status.IsExe:=true;
  1826. parse_only:=false;
  1827. main_procinfo:=nil;
  1828. init_procinfo:=nil;
  1829. finalize_procinfo:=nil;
  1830. resources_used:=false;
  1831. { DLL defaults to create reloc info }
  1832. if islibrary then
  1833. begin
  1834. if not RelocSectionSetExplicitly then
  1835. RelocSection:=true;
  1836. end;
  1837. { Relocation works only without stabs under Windows when }
  1838. { external linker (LD) is used. LD generates relocs for }
  1839. { stab sections which is not loaded in memory. It causes }
  1840. { AV error when DLL is loaded and relocation is needed. }
  1841. { Internal linker does not have this problem. }
  1842. if RelocSection and
  1843. (target_info.system in systems_all_windows+[system_i386_wdosx]) and
  1844. (cs_link_extern in current_settings.globalswitches) then
  1845. begin
  1846. include(current_settings.globalswitches,cs_link_strip);
  1847. { Warning stabs info does not work with reloc section !! }
  1848. if (cs_debuginfo in current_settings.moduleswitches) and
  1849. (target_dbg.id=dbg_stabs) then
  1850. begin
  1851. Message1(parser_w_parser_reloc_no_debug,current_module.mainsource^);
  1852. Message(parser_w_parser_win32_debug_needs_WN);
  1853. exclude(current_settings.moduleswitches,cs_debuginfo);
  1854. end;
  1855. end;
  1856. { get correct output names }
  1857. main_file := current_scanner.inputfile;
  1858. while assigned(main_file.next) do
  1859. main_file := main_file.next;
  1860. current_module.SetFileName(main_file.path^+main_file.name^,true);
  1861. if islibrary then
  1862. begin
  1863. consume(_LIBRARY);
  1864. current_module.setmodulename(orgpattern);
  1865. current_module.islibrary:=true;
  1866. exportlib.preparelib(orgpattern);
  1867. if tf_library_needs_pic in target_info.flags then
  1868. include(current_settings.moduleswitches,cs_create_pic);
  1869. consume(_ID);
  1870. consume(_SEMICOLON);
  1871. end
  1872. else
  1873. { is there an program head ? }
  1874. if token=_PROGRAM then
  1875. begin
  1876. consume(_PROGRAM);
  1877. current_module.setmodulename(orgpattern);
  1878. if (target_info.system in systems_unit_program_exports) then
  1879. exportlib.preparelib(orgpattern);
  1880. consume(_ID);
  1881. if token=_LKLAMMER then
  1882. begin
  1883. consume(_LKLAMMER);
  1884. repeat
  1885. consume(_ID);
  1886. until not try_to_consume(_COMMA);
  1887. consume(_RKLAMMER);
  1888. end;
  1889. consume(_SEMICOLON);
  1890. end
  1891. else if (target_info.system in systems_unit_program_exports) then
  1892. exportlib.preparelib(current_module.realmodulename^);
  1893. { global switches are read, so further changes aren't allowed }
  1894. current_module.in_global:=false;
  1895. { setup things using the switches }
  1896. setupglobalswitches;
  1897. { set implementation flag }
  1898. current_module.in_interface:=false;
  1899. current_module.interface_compiled:=true;
  1900. { insert after the unit symbol tables the static symbol table }
  1901. { of the program }
  1902. current_module.localsymtable:=tstaticsymtable.create(current_module.modulename^,current_module.moduleid);
  1903. { load standard units (system,objpas,profile unit) }
  1904. loaddefaultunits;
  1905. { Load units provided on the command line }
  1906. loadautounits;
  1907. {Load the units used by the program we compile.}
  1908. if token=_USES then
  1909. loadunits;
  1910. { reset ranges/stabs in exported definitions }
  1911. reset_all_defs;
  1912. { All units are read, now give them a number }
  1913. current_module.updatemaps;
  1914. {Insert the name of the main program into the symbol table.}
  1915. if current_module.realmodulename^<>'' then
  1916. current_module.localsymtable.insert(tunitsym.create(current_module.realmodulename^,current_module));
  1917. Message1(parser_u_parsing_implementation,current_module.mainsource^);
  1918. symtablestack.push(current_module.localsymtable);
  1919. { create whole program optimisation information }
  1920. current_module.wpoinfo:=tunitwpoinfo.create;
  1921. { The program intialization needs an alias, so it can be called
  1922. from the bootstrap code.}
  1923. if islibrary then
  1924. begin
  1925. main_procinfo:=create_main_proc(make_mangledname('',current_module.localsymtable,mainaliasname),potype_proginit,current_module.localsymtable);
  1926. { Win32 startup code needs a single name }
  1927. if not(target_info.system in systems_darwin) then
  1928. main_procinfo.procdef.aliasnames.insert('PASCALMAIN')
  1929. else
  1930. main_procinfo.procdef.aliasnames.insert(target_info.Cprefix+'PASCALMAIN')
  1931. end
  1932. else if (target_info.system in ([system_i386_netware,system_i386_netwlibc,system_powerpc_macos]+systems_darwin)) then
  1933. begin
  1934. main_procinfo:=create_main_proc('PASCALMAIN',potype_proginit,current_module.localsymtable);
  1935. end
  1936. else
  1937. begin
  1938. main_procinfo:=create_main_proc(mainaliasname,potype_proginit,current_module.localsymtable);
  1939. main_procinfo.procdef.aliasnames.insert('PASCALMAIN');
  1940. end;
  1941. main_procinfo.parse_body;
  1942. { save file pos for debuginfo }
  1943. current_module.mainfilepos:=main_procinfo.entrypos;
  1944. { Generate specializations of objectdefs methods }
  1945. generate_specialization_procs;
  1946. { should we force unit initialization? }
  1947. force_init_final:=tstaticsymtable(current_module.localsymtable).needs_init_final;
  1948. if force_init_final then
  1949. init_procinfo:=gen_implicit_initfinal(uf_init,current_module.localsymtable);
  1950. { Add symbol to the exports section for win32 so smartlinking a
  1951. DLL will include the edata section }
  1952. if assigned(exportlib) and
  1953. (target_info.system in [system_i386_win32,system_i386_wdosx]) and
  1954. ((current_module.flags and uf_has_exports)<>0) then
  1955. current_asmdata.asmlists[al_procedures].concat(tai_const.createname(make_mangledname('EDATA',current_module.localsymtable,''),0));
  1956. { finalize? }
  1957. if token=_FINALIZATION then
  1958. begin
  1959. { the uf_finalize flag is only set after we checked that it
  1960. wasn't empty }
  1961. { Parse the finalize }
  1962. finalize_procinfo:=create_main_proc(make_mangledname('',current_module.localsymtable,'finalize'),potype_unitfinalize,current_module.localsymtable);
  1963. finalize_procinfo.procdef.aliasnames.insert(make_mangledname('FINALIZE$',current_module.localsymtable,''));
  1964. finalize_procinfo.procdef.aliasnames.insert('PASCALFINALIZE');
  1965. finalize_procinfo.parse_body;
  1966. end
  1967. else
  1968. if force_init_final then
  1969. finalize_procinfo:=gen_implicit_initfinal(uf_finalize,current_module.localsymtable);
  1970. { the finalization routine of libraries is generic (and all libraries need to }
  1971. { be finalized, so they can finalize any units they use }
  1972. if (islibrary) then
  1973. exportlib.setfininame(current_asmdata.asmlists[al_procedures],'FPC_LIB_EXIT');
  1974. { all labels must be defined before generating code }
  1975. if Errorcount=0 then
  1976. tstoredsymtable(current_module.localsymtable).checklabels;
  1977. { See remark in unit init/final }
  1978. main_procinfo.generate_code;
  1979. main_procinfo.resetprocdef;
  1980. release_main_proc(main_procinfo);
  1981. if assigned(init_procinfo) then
  1982. begin
  1983. init_procinfo.generate_code;
  1984. init_procinfo.resetprocdef;
  1985. release_main_proc(init_procinfo);
  1986. end;
  1987. if assigned(finalize_procinfo) then
  1988. begin
  1989. finalize_procinfo.generate_code;
  1990. finalize_procinfo.resetprocdef;
  1991. release_main_proc(finalize_procinfo);
  1992. end;
  1993. symtablestack.pop(current_module.localsymtable);
  1994. { consume the last point }
  1995. consume(_POINT);
  1996. if (Errorcount=0) then
  1997. begin
  1998. { test static symtable }
  1999. tstoredsymtable(current_module.localsymtable).allsymbolsused;
  2000. tstoredsymtable(current_module.localsymtable).allprivatesused;
  2001. tstoredsymtable(current_module.localsymtable).check_forwards;
  2002. current_module.allunitsused;
  2003. end;
  2004. { leave when we got an error }
  2005. if (Errorcount>0) and not status.skip_error then
  2006. begin
  2007. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  2008. status.skip_error:=true;
  2009. exit;
  2010. end;
  2011. { remove all unused units, this happens when units are removed
  2012. from the uses clause in the source and the ppu was already being loaded }
  2013. hp:=tmodule(loaded_units.first);
  2014. while assigned(hp) do
  2015. begin
  2016. hp2:=hp;
  2017. hp:=tmodule(hp.next);
  2018. if hp2.is_unit and
  2019. not assigned(hp2.globalsymtable) then
  2020. begin
  2021. loaded_units.remove(hp2);
  2022. unloaded_units.concat(hp2);
  2023. end;
  2024. end;
  2025. { do we need to add the variants unit? }
  2026. maybeloadvariantsunit;
  2027. { Now that everything has been compiled we know if we need resource
  2028. support. If not, remove the unit. }
  2029. resources_used:=MaybeRemoveResUnit;
  2030. linker.initsysinitunitname;
  2031. if target_info.system in systems_internal_sysinit then
  2032. begin
  2033. { add start/halt unit }
  2034. AddUnit(linker.sysinitunit);
  2035. end;
  2036. {$ifdef arm}
  2037. { Insert .pdata section for arm-wince.
  2038. It is needed for exception handling. }
  2039. if target_info.system in [system_arm_wince] then
  2040. InsertPData;
  2041. {$endif arm}
  2042. InsertThreadvars;
  2043. { generate pic helpers to load eip if necessary }
  2044. gen_pic_helpers(current_asmdata.asmlists[al_procedures]);
  2045. { generate rtti/init tables }
  2046. write_persistent_type_info(current_module.localsymtable);
  2047. { if an Objective-C module, generate rtti and module info }
  2048. MaybeGenerateObjectiveCImageInfo(nil,current_module.localsymtable);
  2049. { generate wrappers for interfaces }
  2050. gen_intf_wrappers(current_asmdata.asmlists[al_procedures],current_module.localsymtable);
  2051. { generate imports }
  2052. if current_module.ImportLibraryList.Count>0 then
  2053. importlib.generatelib;
  2054. { generate debuginfo }
  2055. if (cs_debuginfo in current_settings.moduleswitches) then
  2056. current_debuginfo.inserttypeinfo;
  2057. if islibrary or (target_info.system in systems_unit_program_exports) then
  2058. exportlib.generatelib;
  2059. { Reference all DEBUGINFO sections from the main .fpc section }
  2060. if (cs_debuginfo in current_settings.moduleswitches) then
  2061. current_debuginfo.referencesections(current_asmdata.asmlists[al_procedures]);
  2062. { Resource strings }
  2063. GenerateResourceStrings;
  2064. { Windows widestring needing initialization }
  2065. InsertWideInits;
  2066. { insert Tables and StackLength }
  2067. insertinitfinaltable;
  2068. InsertThreadvarTablesTable;
  2069. InsertResourceTablesTable;
  2070. InsertWideInitsTablesTable;
  2071. insertmemorysizes;
  2072. { Insert symbol to resource info }
  2073. InsertResourceInfo(resources_used);
  2074. { create callframe info }
  2075. create_dwarf_frame;
  2076. { insert own objectfile }
  2077. insertobjectfile;
  2078. { assemble and link }
  2079. create_objectfile;
  2080. { We might need the symbols info if not using
  2081. the default do_extractsymbolinfo
  2082. which is a dummy function PM }
  2083. needsymbolinfo:=
  2084. (do_extractsymbolinfo<>@def_extractsymbolinfo) or
  2085. ((current_settings.genwpoptimizerswitches*WPOptimizationsNeedingAllUnitInfo)<>[]);
  2086. { release all local symtables that are not needed anymore }
  2087. if (not needsymbolinfo) then
  2088. free_localsymtables(current_module.localsymtable);
  2089. { leave when we got an error }
  2090. if (Errorcount>0) and not status.skip_error then
  2091. begin
  2092. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  2093. status.skip_error:=true;
  2094. exit;
  2095. end;
  2096. if (not current_module.is_unit) then
  2097. begin
  2098. { create the executable when we are at level 1 }
  2099. if (compile_level=1) then
  2100. begin
  2101. { create global resource file by collecting all resource files }
  2102. CollectResourceFiles;
  2103. { write .def file }
  2104. if (cs_link_deffile in current_settings.globalswitches) then
  2105. deffile.writefile;
  2106. { insert all .o files from all loaded units and
  2107. unload the units, we don't need them anymore.
  2108. Keep the current_module because that is still needed }
  2109. hp:=tmodule(loaded_units.first);
  2110. while assigned(hp) do
  2111. begin
  2112. linker.AddModuleFiles(hp);
  2113. hp2:=tmodule(hp.next);
  2114. if (hp<>current_module) and
  2115. (not needsymbolinfo) then
  2116. begin
  2117. loaded_units.remove(hp);
  2118. hp.free;
  2119. end;
  2120. hp:=hp2;
  2121. end;
  2122. { free also unneeded units we didn't free before }
  2123. if not needsymbolinfo then
  2124. unloaded_units.Clear;
  2125. { finally we can create a executable }
  2126. if DLLSource then
  2127. linker.MakeSharedLibrary
  2128. else
  2129. linker.MakeExecutable;
  2130. { collect all necessary information for whole-program optimization }
  2131. wpoinfomanager.extractwpoinfofromprogram;
  2132. end;
  2133. { Give Fatal with error count for linker errors }
  2134. if (Errorcount>0) and not status.skip_error then
  2135. begin
  2136. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  2137. status.skip_error:=true;
  2138. end;
  2139. end;
  2140. end;
  2141. end.