pmodules.pas 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. Handles the parsing and loading of the modules (ppufiles)
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit pmodules;
  19. {$i defines.inc}
  20. {$define New_GDB}
  21. interface
  22. procedure proc_unit;
  23. procedure proc_program(islibrary : boolean);
  24. implementation
  25. uses
  26. globtype,version,systems,tokens,
  27. cutils,cclasses,comphook,
  28. globals,verbose,fmodule,finput,fppu,
  29. symconst,symbase,symppu,symdef,symsym,symtable,aasm,
  30. cgbase,
  31. cga,
  32. link,assemble,import,export,gendef,ppu,comprsrc,
  33. cresstr,cpubase,cpuasm,
  34. {$ifdef GDB}
  35. gdb,
  36. {$endif GDB}
  37. scanner,pbase,pexpr,psystem,psub,parser;
  38. procedure create_objectfile;
  39. var
  40. DLLScanner : TDLLScanner;
  41. s : string;
  42. KeepShared : TStringList;
  43. begin
  44. { try to create import entries from system dlls }
  45. if target_info.DllScanSupported and
  46. (not current_module.linkOtherSharedLibs.Empty) then
  47. begin
  48. { Init DLLScanner }
  49. if assigned(CDLLScanner[target_info.target]) then
  50. DLLScanner:=CDLLScanner[target_info.target].Create
  51. else
  52. internalerror(200104121);
  53. KeepShared:=TStringList.Create;
  54. { Walk all shared libs }
  55. While not current_module.linkOtherSharedLibs.Empty do
  56. begin
  57. S:=current_module.linkOtherSharedLibs.Getusemask(link_allways);
  58. if not DLLScanner.scan(s) then
  59. KeepShared.Concat(s);
  60. end;
  61. DLLscanner.Free;
  62. { Recreate import section }
  63. if (target_info.target=target_i386_win32) then
  64. begin
  65. if assigned(importssection)then
  66. importssection.clear
  67. else
  68. importssection:=taasmoutput.Create;
  69. importlib.generatelib;
  70. end;
  71. { Readd the not processed files }
  72. while not KeepShared.Empty do
  73. begin
  74. s:=KeepShared.GetFirst;
  75. current_module.linkOtherSharedLibs.add(s,link_allways);
  76. end;
  77. KeepShared.Free;
  78. end;
  79. { create the .s file and assemble it }
  80. GenerateAsm(false);
  81. { Also create a smartlinked version ? }
  82. if (cs_create_smart in aktmoduleswitches) then
  83. begin
  84. { regenerate the importssection for win32 }
  85. if assigned(importssection) and
  86. (target_info.target=target_i386_win32) then
  87. begin
  88. importsSection.clear;
  89. importlib.generatesmartlib;
  90. end;
  91. GenerateAsm(true);
  92. if target_asm.needar then
  93. Linker.MakeStaticLibrary;
  94. end;
  95. { resource files }
  96. CompileResourceFiles;
  97. end;
  98. procedure insertobjectfile;
  99. { Insert the used object file for this unit in the used list for this unit }
  100. begin
  101. current_module.linkunitofiles.add(current_module.objfilename^,link_static);
  102. current_module.flags:=current_module.flags or uf_static_linked;
  103. if (cs_create_smart in aktmoduleswitches) then
  104. begin
  105. current_module.linkunitstaticlibs.add(current_module.staticlibfilename^,link_smart);
  106. current_module.flags:=current_module.flags or uf_smart_linked;
  107. end;
  108. end;
  109. procedure insertsegment;
  110. procedure fixseg(p:TAAsmoutput;sec:tsection);
  111. begin
  112. p.insert(Tai_section.Create(sec));
  113. if (cs_create_smart in aktmoduleswitches) then
  114. p.insert(Tai_cut.Create);
  115. p.concat(Tai_section.Create(sec_none));
  116. end;
  117. begin
  118. { Insert Ident of the compiler }
  119. if (not (cs_create_smart in aktmoduleswitches))
  120. {$ifndef EXTDEBUG}
  121. and (not current_module.is_unit)
  122. {$endif}
  123. then
  124. begin
  125. dataSegment.insert(Tai_align.Create(4));
  126. dataSegment.insert(Tai_string.Create('FPC '+full_version_string+
  127. ' ['+date_string+'] for '+target_cpu_string+' - '+target_info.shortname));
  128. end;
  129. { finish codesegment }
  130. {$ifdef i386}
  131. codeSegment.concat(Tai_align.Create(16));
  132. {$else}
  133. if cs_littlesize in aktglobalswitches then
  134. codesegment.concat(tai_align.create(2))
  135. else
  136. codesegment.concat(tai_align.create(4));
  137. {$endif}
  138. { Insert start and end of sections }
  139. fixseg(codesegment,sec_code);
  140. fixseg(datasegment,sec_data);
  141. fixseg(bsssegment,sec_bss);
  142. { we should use .rdata section for these two no ? }
  143. { .rdata is a read only data section (PM) }
  144. fixseg(rttilist,sec_data);
  145. fixseg(consts,sec_data);
  146. if assigned(resourcestringlist) then
  147. fixseg(resourcestringlist,sec_data);
  148. {$ifdef GDB}
  149. if assigned(debuglist) then
  150. begin
  151. debugList.insert(Tai_symbol.Createname('gcc2_compiled',0));
  152. debugList.insert(Tai_symbol.Createname('fpc_compiled',0));
  153. fixseg(debuglist,sec_code);
  154. end;
  155. {$endif GDB}
  156. end;
  157. Procedure InsertResourceTablesTable;
  158. var
  159. hp : tused_unit;
  160. ResourceStringTables : taasmoutput;
  161. count : longint;
  162. begin
  163. ResourceStringTables:=TAAsmOutput.Create;
  164. count:=0;
  165. hp:=tused_unit(usedunits.first);
  166. while assigned(hp) do
  167. begin
  168. If (hp.u.flags and uf_has_resources)=uf_has_resources then
  169. begin
  170. ResourceStringTables.concat(Tai_const_symbol.Createname(hp.u.modulename^+'_RESOURCESTRINGLIST'));
  171. inc(count);
  172. end;
  173. hp:=tused_unit(hp.next);
  174. end;
  175. { Add program resources, if any }
  176. If ResourceStringList<>Nil then
  177. begin
  178. ResourceStringTables.concat(Tai_const_symbol.Createname(current_module.modulename^+'_RESOURCESTRINGLIST'));
  179. Inc(Count);
  180. end;
  181. { TableCount }
  182. ResourceStringTables.insert(Tai_const.Create_32bit(count));
  183. ResourceStringTables.insert(Tai_symbol.Createdataname_global('FPC_RESOURCESTRINGTABLES',0));
  184. ResourceStringTables.concat(Tai_symbol_end.Createname('FPC_RESOURCESTRINGTABLES'));
  185. { insert in data segment }
  186. if (cs_create_smart in aktmoduleswitches) then
  187. dataSegment.concat(Tai_cut.Create);
  188. dataSegment.concatlist(ResourceStringTables);
  189. ResourceStringTables.free;
  190. end;
  191. procedure InsertInitFinalTable;
  192. var
  193. hp : tused_unit;
  194. unitinits : taasmoutput;
  195. count : longint;
  196. begin
  197. unitinits:=TAAsmOutput.Create;
  198. count:=0;
  199. hp:=tused_unit(usedunits.first);
  200. while assigned(hp) do
  201. begin
  202. { call the unit init code and make it external }
  203. if (hp.u.flags and (uf_init or uf_finalize))<>0 then
  204. begin
  205. if (hp.u.flags and uf_init)<>0 then
  206. unitinits.concat(Tai_const_symbol.Createname('INIT$$'+hp.u.modulename^))
  207. else
  208. unitinits.concat(Tai_const.Create_32bit(0));
  209. if (hp.u.flags and uf_finalize)<>0 then
  210. unitinits.concat(Tai_const_symbol.Createname('FINALIZE$$'+hp.u.modulename^))
  211. else
  212. unitinits.concat(Tai_const.Create_32bit(0));
  213. inc(count);
  214. end;
  215. hp:=tused_unit(hp.next);
  216. end;
  217. if current_module.islibrary then
  218. if (current_module.flags and uf_finalize)<>0 then
  219. begin
  220. { INIT code is done by PASCALMAIN calling }
  221. unitinits.concat(Tai_const.Create_32bit(0));
  222. unitinits.concat(Tai_const_symbol.Createname('FINALIZE$$'+current_module.modulename^));
  223. inc(count);
  224. end;
  225. { TableCount,InitCount }
  226. unitinits.insert(Tai_const.Create_32bit(0));
  227. unitinits.insert(Tai_const.Create_32bit(count));
  228. unitinits.insert(Tai_symbol.Createdataname_global('INITFINAL',0));
  229. unitinits.concat(Tai_symbol_end.Createname('INITFINAL'));
  230. { insert in data segment }
  231. if (cs_create_smart in aktmoduleswitches) then
  232. dataSegment.concat(Tai_cut.Create);
  233. dataSegment.concatlist(unitinits);
  234. unitinits.free;
  235. end;
  236. procedure insertheap;
  237. begin
  238. if (cs_create_smart in aktmoduleswitches) then
  239. begin
  240. bssSegment.concat(Tai_cut.Create);
  241. dataSegment.concat(Tai_cut.Create);
  242. end;
  243. { On the Macintosh Classic M68k Architecture
  244. The Heap variable is simply a POINTER to the
  245. real HEAP. The HEAP must be set up by the RTL
  246. and must store the pointer in this value.
  247. On OS/2 the heap is also intialized by the RTL. We do
  248. not output a pointer }
  249. case target_info.target of
  250. {$ifdef i386}
  251. target_i386_OS2:
  252. ;
  253. {$endif i386}
  254. {$ifdef alpha}
  255. target_alpha_linux:
  256. ;
  257. {$endif alpha}
  258. {$ifdef powerpc}
  259. target_powerpc_linux:
  260. ;
  261. {$endif powerpc}
  262. {$ifdef m68k}
  263. target_m68k_Mac:
  264. bssSegment.concat(Tai_datablock.Create_global('HEAP',4));
  265. target_m68k_PalmOS:
  266. ;
  267. {$endif m68k}
  268. else
  269. bssSegment.concat(Tai_datablock.Create_global('HEAP',heapsize));
  270. end;
  271. {$ifdef m68k}
  272. if target_info.target<>target_m68k_PalmOS then
  273. begin
  274. dataSegment.concat(Tai_symbol.Createdataname_global('HEAPSIZE',4));
  275. dataSegment.concat(Tai_const.Create_32bit(heapsize));
  276. end;
  277. {$else m68k}
  278. dataSegment.concat(Tai_symbol.Createdataname_global('HEAPSIZE',4));
  279. dataSegment.concat(Tai_const.Create_32bit(heapsize));
  280. {$endif m68k}
  281. end;
  282. procedure inserttargetspecific;
  283. begin
  284. case target_info.target of
  285. {$ifdef alpha}
  286. target_alpha_linux:
  287. ;
  288. {$endif alpha}
  289. {$ifdef powerpc}
  290. target_powerpc_linux:
  291. ;
  292. {$endif powerpc}
  293. {$ifdef i386}
  294. target_i386_BeOS,
  295. target_i386_SunOS,
  296. target_i386_GO32V2 :
  297. begin
  298. { stacksize can be specified }
  299. dataSegment.concat(Tai_symbol.Createdataname_global('__stklen',4));
  300. dataSegment.concat(Tai_const.Create_32bit(stacksize));
  301. end;
  302. {$endif i386}
  303. {$ifdef m68k}
  304. target_m68k_Atari :
  305. begin
  306. { stacksize can be specified }
  307. dataSegment.concat(Tai_symbol.Createdataname_global('__stklen',4));
  308. dataSegment.concat(Tai_const.Create_32bit(stacksize));
  309. end;
  310. {$endif m68k}
  311. end;
  312. end;
  313. procedure loaddefaultunits;
  314. var
  315. hp : tmodule;
  316. unitsym : tunitsym;
  317. begin
  318. { are we compiling the system unit? }
  319. if (cs_compilesystem in aktmoduleswitches) then
  320. begin
  321. { create system defines }
  322. createconstdefs;
  323. { we don't need to reset anything, it's already done in parser.pas }
  324. exit;
  325. end;
  326. { insert the system unit, it is allways the first }
  327. hp:=loadunit('System','');
  328. systemunit:=tglobalsymtable(hp.globalsymtable);
  329. { it's always the first unit }
  330. systemunit.next:=nil;
  331. symtablestack:=systemunit;
  332. { add to the used units }
  333. current_module.used_units.concat(tused_unit.create(hp,true));
  334. unitsym:=tunitsym.create('System',systemunit);
  335. inc(unitsym.refs);
  336. refsymtable.insert(unitsym);
  337. { read default constant definitions }
  338. make_ref:=false;
  339. readconstdefs;
  340. make_ref:=true;
  341. { Objpas unit? }
  342. if m_objpas in aktmodeswitches then
  343. begin
  344. hp:=loadunit('ObjPas','');
  345. tsymtable(hp.globalsymtable).next:=symtablestack;
  346. symtablestack:=hp.globalsymtable;
  347. { add to the used units }
  348. current_module.used_units.concat(tused_unit.create(hp,true));
  349. unitsym:=tunitsym.create('ObjPas',hp.globalsymtable);
  350. inc(unitsym.refs);
  351. refsymtable.insert(unitsym);
  352. end;
  353. { Profile unit? Needed for go32v2 only }
  354. if (cs_profile in aktmoduleswitches) and (target_info.target=target_i386_go32v2) then
  355. begin
  356. hp:=loadunit('Profile','');
  357. tsymtable(hp.globalsymtable).next:=symtablestack;
  358. symtablestack:=hp.globalsymtable;
  359. { add to the used units }
  360. current_module.used_units.concat(tused_unit.create(hp,true));
  361. unitsym:=tunitsym.create('Profile',hp.globalsymtable);
  362. inc(unitsym.refs);
  363. refsymtable.insert(unitsym);
  364. end;
  365. { Units only required for main module }
  366. if not(current_module.is_unit) then
  367. begin
  368. { Heaptrc unit }
  369. if (cs_gdb_heaptrc in aktglobalswitches) then
  370. begin
  371. hp:=loadunit('HeapTrc','');
  372. tsymtable(hp.globalsymtable).next:=symtablestack;
  373. symtablestack:=hp.globalsymtable;
  374. { add to the used units }
  375. current_module.used_units.concat(tused_unit.create(hp,true));
  376. unitsym:=tunitsym.create('HeapTrc',hp.globalsymtable);
  377. inc(unitsym.refs);
  378. refsymtable.insert(unitsym);
  379. end;
  380. { Lineinfo unit }
  381. if (cs_gdb_lineinfo in aktglobalswitches) then
  382. begin
  383. hp:=loadunit('LineInfo','');
  384. tsymtable(hp.globalsymtable).next:=symtablestack;
  385. symtablestack:=hp.globalsymtable;
  386. { add to the used units }
  387. current_module.used_units.concat(tused_unit.create(hp,true));
  388. unitsym:=tunitsym.create('LineInfo',hp.globalsymtable);
  389. inc(unitsym.refs);
  390. refsymtable.insert(unitsym);
  391. end;
  392. end;
  393. { save default symtablestack }
  394. defaultsymtablestack:=symtablestack;
  395. end;
  396. procedure loadunits;
  397. var
  398. s,sorg : stringid;
  399. fn : string;
  400. pu,
  401. hp : tused_unit;
  402. hp2 : tmodule;
  403. hp3 : tsymtable;
  404. oldprocsym:tprocsym;
  405. oldprocdef:tprocdef;
  406. unitsym : tunitsym;
  407. begin
  408. oldprocsym:=aktprocsym;
  409. oldprocdef:=aktprocdef;
  410. consume(_USES);
  411. {$ifdef DEBUG}
  412. test_symtablestack;
  413. {$endif DEBUG}
  414. repeat
  415. s:=pattern;
  416. sorg:=orgpattern;
  417. consume(_ID);
  418. { support "<unit> in '<file>'" construct, but not for tp7 }
  419. if not(m_tp7 in aktmodeswitches) then
  420. begin
  421. if try_to_consume(_OP_IN) then
  422. fn:=get_stringconst
  423. else
  424. fn:='';
  425. end;
  426. { Give a warning if objpas is loaded }
  427. if s='OBJPAS' then
  428. Message(parser_w_no_objpas_use_mode);
  429. { check if the unit is already used }
  430. pu:=tused_unit(current_module.used_units.first);
  431. while assigned(pu) do
  432. begin
  433. if (pu.name^=s) then
  434. break;
  435. pu:=tused_unit(pu.next);
  436. end;
  437. { avoid uses of itself }
  438. if not assigned(pu) and (s<>current_module.modulename^) then
  439. begin
  440. { load the unit }
  441. hp2:=loadunit(sorg,fn);
  442. { the current module uses the unit hp2 }
  443. current_module.used_units.concat(tused_unit.create(hp2,not current_module.in_implementation));
  444. tused_unit(current_module.used_units.last).in_uses:=true;
  445. if current_module.compiled then
  446. exit;
  447. unitsym:=tunitsym.create(sorg,hp2.globalsymtable);
  448. { never claim about unused unit if
  449. there is init or finalize code PM }
  450. if (hp2.flags and (uf_init or uf_finalize))<>0 then
  451. inc(unitsym.refs);
  452. refsymtable.insert(unitsym);
  453. end
  454. else
  455. Message1(sym_e_duplicate_id,s);
  456. if token=_COMMA then
  457. begin
  458. pattern:='';
  459. consume(_COMMA);
  460. end
  461. else
  462. break;
  463. until false;
  464. consume(_SEMICOLON);
  465. { set the symtable to systemunit so it gets reorderd correctly }
  466. symtablestack:=defaultsymtablestack;
  467. { now insert the units in the symtablestack }
  468. hp:=tused_unit(current_module.used_units.first);
  469. while assigned(hp) do
  470. begin
  471. {$IfDef GDB}
  472. if (cs_debuginfo in aktmoduleswitches) and
  473. (cs_gdb_dbx in aktglobalswitches) and
  474. not hp.is_stab_written then
  475. begin
  476. tglobalsymtable(hp.u.globalsymtable).concattypestabto(debuglist);
  477. hp.is_stab_written:=true;
  478. hp.unitid:=tsymtable(hp.u.globalsymtable).unitid;
  479. end;
  480. {$EndIf GDB}
  481. if hp.in_uses then
  482. begin
  483. hp3:=symtablestack;
  484. while assigned(hp3) do
  485. begin
  486. { insert units only once ! }
  487. if hp.u.globalsymtable=hp3 then
  488. break;
  489. hp3:=hp3.next;
  490. { unit isn't inserted }
  491. if hp3=nil then
  492. begin
  493. tsymtable(hp.u.globalsymtable).next:=symtablestack;
  494. symtablestack:=tsymtable(hp.u.globalsymtable);
  495. {$ifdef DEBUG}
  496. test_symtablestack;
  497. {$endif DEBUG}
  498. end;
  499. end;
  500. end;
  501. hp:=tused_unit(hp.next);
  502. end;
  503. aktprocsym:=oldprocsym;
  504. aktprocdef:=oldprocdef;
  505. end;
  506. procedure write_gdb_info;
  507. {$IfDef GDB}
  508. var
  509. hp : tused_unit;
  510. begin
  511. if not (cs_debuginfo in aktmoduleswitches) then
  512. exit;
  513. if (cs_gdb_dbx in aktglobalswitches) then
  514. begin
  515. debugList.concat(Tai_asm_comment.Create(strpnew('EINCL of global '+
  516. tglobalsymtable(current_module.globalsymtable).name^+' has index '+
  517. tostr(tglobalsymtable(current_module.globalsymtable).unitid))));
  518. debugList.concat(Tai_stabs.Create(strpnew('"'+
  519. tglobalsymtable(current_module.globalsymtable).name^+'",'+
  520. tostr(N_EINCL)+',0,0,0')));
  521. tglobalsymtable(current_module.globalsymtable).dbx_count_ok:={true}false;
  522. dbx_counter:=tglobalsymtable(current_module.globalsymtable).prev_dbx_counter;
  523. do_count_dbx:=false;
  524. end;
  525. { now insert the units in the symtablestack }
  526. hp:=tused_unit(current_module.used_units.first);
  527. while assigned(hp) do
  528. begin
  529. if (cs_debuginfo in aktmoduleswitches) and
  530. not hp.is_stab_written then
  531. begin
  532. tglobalsymtable(hp.u.globalsymtable).concattypestabto(debuglist);
  533. hp.is_stab_written:=true;
  534. hp.unitid:=tsymtable(hp.u.globalsymtable).unitid;
  535. end;
  536. hp:=tused_unit(hp.next);
  537. end;
  538. if current_module.in_implementation and
  539. assigned(current_module.localsymtable) then
  540. begin
  541. { all types }
  542. tstaticsymtable(current_module.localsymtable).concattypestabto(debuglist);
  543. { and all local symbols}
  544. tstaticsymtable(current_module.localsymtable).concatstabto(debuglist);
  545. end
  546. else if assigned(current_module.globalsymtable) then
  547. begin
  548. { all types }
  549. tglobalsymtable(current_module.globalsymtable).concattypestabto(debuglist);
  550. { and all local symbols}
  551. tglobalsymtable(current_module.globalsymtable).concatstabto(debuglist);
  552. end;
  553. end;
  554. {$Else GDB}
  555. begin
  556. end;
  557. {$EndIf GDB}
  558. procedure parse_implementation_uses(symt:tsymtable);
  559. begin
  560. if token=_USES then
  561. begin
  562. loadunits;
  563. {$ifdef DEBUG}
  564. test_symtablestack;
  565. {$endif DEBUG}
  566. end;
  567. end;
  568. procedure setupglobalswitches;
  569. begin
  570. { can't have local browser when no global browser }
  571. if (cs_local_browser in aktmoduleswitches) and
  572. not(cs_browser in aktmoduleswitches) then
  573. exclude(aktmoduleswitches,cs_local_browser);
  574. { define a symbol in delphi,objfpc,tp,gpc mode }
  575. if (m_delphi in aktmodeswitches) then
  576. current_scanner.def_macro('FPC_DELPHI')
  577. else
  578. if (m_tp7 in aktmodeswitches) then
  579. current_scanner.def_macro('FPC_TP')
  580. else
  581. if (m_objfpc in aktmodeswitches) then
  582. current_scanner.def_macro('FPC_OBJFPC')
  583. else
  584. if (m_gpc in aktmodeswitches) then
  585. current_scanner.def_macro('FPC_GPC');
  586. end;
  587. procedure gen_main_procsym(const name:string;options:tproctypeoption;st:tsymtable);
  588. var
  589. stt : tsymtable;
  590. procdefs : pprocdeflist;
  591. begin
  592. {Generate a procsym for main}
  593. make_ref:=false;
  594. aktprocsym:=tprocsym.create('$'+name);
  595. { main are allways used }
  596. inc(aktprocsym.refs);
  597. {Try to insert in in static symtable ! }
  598. stt:=symtablestack;
  599. symtablestack:=st;
  600. aktprocdef:=tprocdef.create;
  601. new(procdefs);
  602. procdefs^.def:=aktprocdef;
  603. procdefs^.next:=aktprocsym.defs;
  604. aktprocsym.defs:=procdefs;
  605. aktprocdef.procsym:=aktprocsym;
  606. symtablestack:=stt;
  607. aktprocdef.proctypeoption:=options;
  608. aktprocdef.setmangledname(target_info.cprefix+name);
  609. aktprocdef.forwarddef:=false;
  610. make_ref:=true;
  611. { The localst is a local symtable. Change it into the static
  612. symtable }
  613. aktprocdef.localst.free;
  614. aktprocdef.localst:=st;
  615. { and insert the procsym in symtable }
  616. st.insert(aktprocsym);
  617. { set some informations about the main program }
  618. with procinfo^ do
  619. begin
  620. _class:=nil;
  621. para_offset:=8;
  622. framepointer:=frame_pointer;
  623. flags:=0;
  624. procdef:=aktprocdef;
  625. end;
  626. end;
  627. procedure proc_unit;
  628. function is_assembler_generated:boolean;
  629. begin
  630. is_assembler_generated:=(Errorcount=0) and
  631. not(
  632. codeSegment.empty and
  633. dataSegment.empty and
  634. bssSegment.empty and
  635. ((importssection=nil) or importsSection.empty) and
  636. ((resourcesection=nil) or resourceSection.empty) and
  637. ((resourcestringlist=nil) or resourcestringList.empty)
  638. );
  639. end;
  640. var
  641. main_file: tinputfile;
  642. st : tsymtable;
  643. unitst : tglobalsymtable;
  644. {$ifdef GDB}
  645. pu : tused_unit;
  646. {$endif GDB}
  647. store_crc,store_interface_crc : cardinal;
  648. s2 : ^string; {Saves stack space}
  649. force_init_final : boolean;
  650. begin
  651. consume(_UNIT);
  652. if compile_level=1 then
  653. Status.IsExe:=false;
  654. if token=_ID then
  655. begin
  656. { create filenames and unit name }
  657. main_file := current_scanner.inputfile;
  658. while assigned(main_file.next) do
  659. main_file := main_file.next;
  660. current_module.SetFileName(main_file.path^+main_file.name^,true);
  661. stringdispose(current_module.modulename);
  662. stringdispose(current_module.realmodulename);
  663. current_module.modulename:=stringdup(pattern);
  664. current_module.realmodulename:=stringdup(orgpattern);
  665. { check for system unit }
  666. new(s2);
  667. s2^:=upper(SplitName(main_file.name^));
  668. if (cs_check_unit_name in aktglobalswitches) and
  669. not((current_module.modulename^=s2^) or
  670. ((length(current_module.modulename^)>8) and
  671. (copy(current_module.modulename^,1,8)=s2^))) then
  672. Message1(unit_e_illegal_unit_name,current_module.realmodulename^);
  673. if (current_module.modulename^='SYSTEM') then
  674. include(aktmoduleswitches,cs_compilesystem);
  675. dispose(s2);
  676. end;
  677. consume(_ID);
  678. consume(_SEMICOLON);
  679. consume(_INTERFACE);
  680. { global switches are read, so further changes aren't allowed }
  681. current_module.in_global:=false;
  682. { handle the global switches }
  683. setupglobalswitches;
  684. Message1(unit_u_start_parse_interface,current_module.realmodulename^);
  685. { update status }
  686. status.currentmodule:=current_module.realmodulename^;
  687. { maybe turn off m_objpas if we are compiling objpas }
  688. if (current_module.modulename^='OBJPAS') then
  689. exclude(aktmodeswitches,m_objpas);
  690. { this should be placed after uses !!}
  691. {$ifndef UseNiceNames}
  692. procprefix:='_'+current_module.modulename^+'$$';
  693. {$else UseNiceNames}
  694. procprefix:='_'+tostr(length(current_module.modulename^))+lowercase(current_module.modulename^)+'_';
  695. {$endif UseNiceNames}
  696. parse_only:=true;
  697. { generate now the global symboltable }
  698. st:=tglobalsymtable.create(current_module.modulename^);
  699. refsymtable:=st;
  700. unitst:=tglobalsymtable(st);
  701. { define first as local to overcome dependency conflicts }
  702. current_module.localsymtable:=st;
  703. { the unit name must be usable as a unit specifier }
  704. { inside the unit itself (PM) }
  705. { this also forbids to have another symbol }
  706. { with the same name as the unit }
  707. refsymtable.insert(tunitsym.create(current_module.realmodulename^,unitst));
  708. { load default units, like the system unit }
  709. loaddefaultunits;
  710. { reset }
  711. make_ref:=true;
  712. lexlevel:=0;
  713. { insert qualifier for the system unit (allows system.writeln) }
  714. if not(cs_compilesystem in aktmoduleswitches) then
  715. begin
  716. if token=_USES then
  717. begin
  718. loadunits;
  719. { has it been compiled at a higher level ?}
  720. if current_module.compiled then
  721. begin
  722. { this unit symtable is obsolete }
  723. { dispose(unitst,done);
  724. disposed as localsymtable !! }
  725. RestoreUnitSyms;
  726. exit;
  727. end;
  728. end;
  729. { ... but insert the symbol table later }
  730. st.next:=symtablestack;
  731. symtablestack:=st;
  732. end
  733. else
  734. { while compiling a system unit, some types are directly inserted }
  735. begin
  736. st.next:=symtablestack;
  737. symtablestack:=st;
  738. insert_intern_types(st);
  739. end;
  740. { now we know the place to insert the constants }
  741. constsymtable:=symtablestack;
  742. { move the global symtab from the temporary local to global }
  743. current_module.globalsymtable:=current_module.localsymtable;
  744. current_module.localsymtable:=nil;
  745. reset_global_defs;
  746. { number all units, so we know if a unit is used by this unit or
  747. needs to be added implicitly }
  748. current_module.numberunits;
  749. { ... parse the declarations }
  750. Message1(parser_u_parsing_interface,current_module.realmodulename^);
  751. read_interface_declarations;
  752. { leave when we got an error }
  753. if (Errorcount>0) and not status.skip_error then
  754. begin
  755. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  756. status.skip_error:=true;
  757. exit;
  758. end;
  759. {else in inteface its somatimes necessary even if unused
  760. st^.allunitsused; }
  761. {$ifdef New_GDB}
  762. write_gdb_info;
  763. {$endIf Def New_GDB}
  764. if not(cs_compilesystem in aktmoduleswitches) then
  765. if (Errorcount=0) then
  766. tppumodule(current_module).getppucrc;
  767. { Parse the implementation section }
  768. consume(_IMPLEMENTATION);
  769. current_module.in_implementation:=true;
  770. Message1(unit_u_start_parse_implementation,current_module.modulename^);
  771. parse_only:=false;
  772. { generates static symbol table }
  773. st:=tstaticsymtable.create(current_module.modulename^);
  774. current_module.localsymtable:=st;
  775. { remove the globalsymtable from the symtable stack }
  776. { to reinsert it after loading the implementation units }
  777. symtablestack:=unitst.next;
  778. { we don't want implementation units symbols in unitsymtable !! PM }
  779. refsymtable:=st;
  780. { Read the implementation units }
  781. parse_implementation_uses(unitst);
  782. if current_module.compiled then
  783. begin
  784. RestoreUnitSyms;
  785. exit;
  786. end;
  787. { reset ranges/stabs in exported definitions }
  788. reset_global_defs;
  789. { All units are read, now give them a number }
  790. current_module.numberunits;
  791. { now we can change refsymtable }
  792. refsymtable:=st;
  793. { but reinsert the global symtable as lasts }
  794. unitst.next:=symtablestack;
  795. symtablestack:=unitst;
  796. tstoredsymtable(symtablestack).chainoperators;
  797. {$ifdef DEBUG}
  798. test_symtablestack;
  799. {$endif DEBUG}
  800. constsymtable:=symtablestack;
  801. {$ifdef Splitheap}
  802. if testsplit then
  803. begin
  804. Split_Heap;
  805. allow_special:=true;
  806. Switch_to_temp_heap;
  807. end;
  808. { it will report all crossings }
  809. allow_special:=false;
  810. {$endif Splitheap}
  811. Message1(parser_u_parsing_implementation,current_module.realmodulename^);
  812. { Compile the unit }
  813. codegen_newprocedure;
  814. gen_main_procsym(current_module.modulename^+'_init',potype_unitinit,st);
  815. aktprocdef.aliasnames.insert('INIT$$'+current_module.modulename^);
  816. aktprocdef.aliasnames.insert(target_info.cprefix+current_module.modulename^+'_init');
  817. compile_proc_body(true,false);
  818. codegen_doneprocedure;
  819. { avoid self recursive destructor call !! PM }
  820. aktprocdef.localst:=nil;
  821. { if the unit contains ansi/widestrings, initialization and
  822. finalization code must be forced }
  823. force_init_final:=tglobalsymtable(current_module.globalsymtable).needs_init_final or
  824. tstaticsymtable(current_module.localsymtable).needs_init_final;
  825. { should we force unit initialization? }
  826. { this is a hack, but how can it be done better ? }
  827. if force_init_final and ((current_module.flags and uf_init)=0) then
  828. begin
  829. current_module.flags:=current_module.flags or uf_init;
  830. { now we can insert a cut }
  831. if (cs_create_smart in aktmoduleswitches) then
  832. codeSegment.concat(Tai_cut.Create);
  833. genimplicitunitinit(codesegment);
  834. end;
  835. { finalize? }
  836. if token=_FINALIZATION then
  837. begin
  838. { set module options }
  839. current_module.flags:=current_module.flags or uf_finalize;
  840. { Compile the finalize }
  841. codegen_newprocedure;
  842. gen_main_procsym(current_module.modulename^+'_finalize',potype_unitfinalize,st);
  843. aktprocdef.aliasnames.insert('FINALIZE$$'+current_module.modulename^);
  844. aktprocdef.aliasnames.insert(target_info.cprefix+current_module.modulename^+'_finalize');
  845. compile_proc_body(true,false);
  846. codegen_doneprocedure;
  847. end
  848. else if force_init_final then
  849. begin
  850. current_module.flags:=current_module.flags or uf_finalize;
  851. { now we can insert a cut }
  852. if (cs_create_smart in aktmoduleswitches) then
  853. codeSegment.concat(Tai_cut.Create);
  854. genimplicitunitfinal(codesegment);
  855. end;
  856. { the last char should always be a point }
  857. consume(_POINT);
  858. If ResourceStrings.ResStrCount>0 then
  859. begin
  860. ResourceStrings.CreateResourceStringList;
  861. current_module.flags:=current_module.flags or uf_has_resources;
  862. { only write if no errors found }
  863. if (Errorcount=0) then
  864. ResourceStrings.WriteResourceFile(ForceExtension(current_module.ppufilename^,'.rst'));
  865. end;
  866. { avoid self recursive destructor call !! PM }
  867. aktprocdef.localst:=nil;
  868. { absence does not matter here !! }
  869. aktprocdef.forwarddef:=false;
  870. { test static symtable }
  871. if (Errorcount=0) then
  872. begin
  873. tstoredsymtable(st).allsymbolsused;
  874. tstoredsymtable(st).allunitsused;
  875. tstoredsymtable(st).allprivatesused;
  876. end;
  877. { size of the static data }
  878. datasize:=st.datasize;
  879. {$ifdef GDB}
  880. { add all used definitions even for implementation}
  881. if (cs_debuginfo in aktmoduleswitches) then
  882. begin
  883. {$IfnDef New_GDB}
  884. if assigned(current_module.globalsymtable) then
  885. begin
  886. { all types }
  887. tglobalsymtable(current_module.globalsymtable).concattypestabto(debuglist);
  888. { and all local symbols}
  889. tglobalsymtable(current_module.globalsymtable).concatstabto(debuglist);
  890. end;
  891. { all local types }
  892. tglobalsymtable(st)^.concattypestabto(debuglist);
  893. { and all local symbols}
  894. st^.concatstabto(debuglist);
  895. {$else New_GDB}
  896. write_gdb_info;
  897. {$endIf Def New_GDB}
  898. end;
  899. {$endif GDB}
  900. reset_global_defs;
  901. if (Errorcount=0) then
  902. begin
  903. { tests, if all (interface) forwards are resolved }
  904. tstoredsymtable(symtablestack).check_forwards;
  905. { check if all private fields are used }
  906. tstoredsymtable(symtablestack).allprivatesused;
  907. { remove cross unit overloads }
  908. tstoredsymtable(symtablestack).unchain_overloaded;
  909. end;
  910. current_module.in_implementation:=false;
  911. {$ifdef GDB}
  912. tglobalsymtable(symtablestack).is_stab_written:=false;
  913. {$endif GDB}
  914. { leave when we got an error }
  915. if (Errorcount>0) and not status.skip_error then
  916. begin
  917. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  918. status.skip_error:=true;
  919. exit;
  920. end;
  921. { generate imports }
  922. if current_module.uses_imports then
  923. importlib.generatelib;
  924. { insert own objectfile, or say that it's in a library
  925. (no check for an .o when loading) }
  926. if is_assembler_generated then
  927. insertobjectfile
  928. else
  929. current_module.flags:=current_module.flags or uf_no_link;
  930. if cs_local_browser in aktmoduleswitches then
  931. current_module.localsymtable:=refsymtable;
  932. {$ifdef GDB}
  933. pu:=tused_unit(usedunits.first);
  934. while assigned(pu) do
  935. begin
  936. if assigned(pu.u.globalsymtable) then
  937. tglobalsymtable(pu.u.globalsymtable).is_stab_written:=false;
  938. pu:=tused_unit(pu.next);
  939. end;
  940. {$endif GDB}
  941. if is_assembler_generated then
  942. begin
  943. { finish asmlist by adding segment starts }
  944. insertsegment;
  945. { assemble }
  946. create_objectfile;
  947. end;
  948. { Write out the ppufile after the object file has been created }
  949. store_interface_crc:=current_module.interface_crc;
  950. store_crc:=current_module.crc;
  951. if (Errorcount=0) then
  952. tppumodule(current_module).writeppu;
  953. if not(cs_compilesystem in aktmoduleswitches) then
  954. if store_interface_crc<>current_module.interface_crc then
  955. Comment(V_Warning,current_module.ppufilename^+' Interface CRC changed '+
  956. hexstr(store_crc,8)+'<>'+hexstr(current_module.interface_crc,8));
  957. {$ifdef EXTDEBUG}
  958. if not(cs_compilesystem in aktmoduleswitches) then
  959. if (store_crc<>current_module.crc) and simplify_ppu then
  960. Comment(V_Warning,current_module.ppufilename^+' implementation CRC changed '+
  961. hexstr(store_crc,8)+'<>'+hexstr(current_module.crc,8));
  962. {$endif EXTDEBUG}
  963. { remove static symtable (=refsymtable) here to save some mem }
  964. if not (cs_local_browser in aktmoduleswitches) then
  965. begin
  966. st.free;
  967. current_module.localsymtable:=nil;
  968. end;
  969. RestoreUnitSyms;
  970. { leave when we got an error }
  971. if (Errorcount>0) and not status.skip_error then
  972. begin
  973. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  974. status.skip_error:=true;
  975. exit;
  976. end;
  977. end;
  978. procedure proc_program(islibrary : boolean);
  979. var
  980. main_file: tinputfile;
  981. st : tsymtable;
  982. hp : tmodule;
  983. begin
  984. DLLsource:=islibrary;
  985. Status.IsLibrary:=IsLibrary;
  986. Status.IsExe:=true;
  987. parse_only:=false;
  988. { relocation works only without stabs under win32 !! PM }
  989. { internal assembler uses rva for stabs info
  990. so it should work with relocated DLLs }
  991. if RelocSection and
  992. (target_info.target=target_i386_win32) and
  993. (target_info.assem<>as_i386_pecoff) then
  994. begin
  995. include(aktglobalswitches,cs_link_strip);
  996. { Warning stabs info does not work with reloc section !! }
  997. if cs_debuginfo in aktmoduleswitches then
  998. begin
  999. Message1(parser_w_parser_reloc_no_debug,current_module.mainsource^);
  1000. Message(parser_w_parser_win32_debug_needs_WN);
  1001. exclude(aktmoduleswitches,cs_debuginfo);
  1002. end;
  1003. end;
  1004. { get correct output names }
  1005. main_file := current_scanner.inputfile;
  1006. while assigned(main_file.next) do
  1007. main_file := main_file.next;
  1008. current_module.SetFileName(main_file.path^+main_file.name^,true);
  1009. if islibrary then
  1010. begin
  1011. consume(_LIBRARY);
  1012. stringdispose(current_module.modulename);
  1013. current_module.modulename:=stringdup(pattern);
  1014. current_module.islibrary:=true;
  1015. exportlib.preparelib(pattern);
  1016. consume(_ID);
  1017. consume(_SEMICOLON);
  1018. end
  1019. else
  1020. { is there an program head ? }
  1021. if token=_PROGRAM then
  1022. begin
  1023. consume(_PROGRAM);
  1024. stringdispose(current_module.modulename);
  1025. stringdispose(current_module.realmodulename);
  1026. current_module.modulename:=stringdup(pattern);
  1027. current_module.realmodulename:=stringdup(orgpattern);
  1028. if (target_info.target=target_i386_WIN32) then
  1029. exportlib.preparelib(pattern);
  1030. consume(_ID);
  1031. if token=_LKLAMMER then
  1032. begin
  1033. consume(_LKLAMMER);
  1034. consume_idlist;
  1035. consume(_RKLAMMER);
  1036. end;
  1037. consume(_SEMICOLON);
  1038. end
  1039. else if (target_info.target=target_i386_WIN32) then
  1040. exportlib.preparelib(current_module.modulename^);
  1041. { global switches are read, so further changes aren't allowed }
  1042. current_module.in_global:=false;
  1043. { setup things using the global switches }
  1044. setupglobalswitches;
  1045. { set implementation flag }
  1046. current_module.in_implementation:=true;
  1047. { insert after the unit symbol tables the static symbol table }
  1048. { of the program }
  1049. st:=tstaticsymtable.create(current_module.modulename^);;
  1050. current_module.localsymtable:=st;
  1051. refsymtable:=st;
  1052. { load standard units (system,objpas,profile unit) }
  1053. loaddefaultunits;
  1054. { reset }
  1055. lexlevel:=0;
  1056. {Load the units used by the program we compile.}
  1057. if token=_USES then
  1058. loadunits;
  1059. tstoredsymtable(symtablestack).chainoperators;
  1060. { reset ranges/stabs in exported definitions }
  1061. reset_global_defs;
  1062. { All units are read, now give them a number }
  1063. current_module.numberunits;
  1064. {Insert the name of the main program into the symbol table.}
  1065. if current_module.realmodulename^<>'' then
  1066. st.insert(tunitsym.create(current_module.realmodulename^,tglobalsymtable(st)));
  1067. { ...is also constsymtable, this is the symtable where }
  1068. { the elements of enumeration types are inserted }
  1069. constsymtable:=st;
  1070. Message1(parser_u_parsing_implementation,current_module.mainsource^);
  1071. { reset }
  1072. procprefix:='';
  1073. {The program intialization needs an alias, so it can be called
  1074. from the bootstrap code.}
  1075. codegen_newprocedure;
  1076. if islibrary then
  1077. begin
  1078. gen_main_procsym(current_module.modulename^+'_main',potype_proginit,st);
  1079. aktprocdef.aliasnames.insert(target_info.cprefix+current_module.modulename^+'_main');
  1080. aktprocdef.aliasnames.insert('PASCALMAIN');
  1081. { this code is called from C so we need to save some
  1082. registers }
  1083. include(aktprocdef.procoptions,po_savestdregs);
  1084. end
  1085. else
  1086. begin
  1087. gen_main_procsym('main',potype_proginit,st);
  1088. aktprocdef.aliasnames.insert('program_init');
  1089. aktprocdef.aliasnames.insert('PASCALMAIN');
  1090. aktprocdef.aliasnames.insert(target_info.cprefix+'main');
  1091. end;
  1092. compile_proc_body(true,false);
  1093. { Add symbol to the exports section for win32 so smartlinking a
  1094. DLL will include the edata section }
  1095. if assigned(exportlib) and
  1096. (target_info.target=target_i386_win32) and
  1097. assigned(current_module._exports.first) then
  1098. codesegment.concat(tai_const_symbol.create(exportlib.edatalabel));
  1099. { avoid self recursive destructor call !! PM }
  1100. aktprocdef.localst:=nil;
  1101. { consider these symbols as global ones for browser
  1102. but the typecasting of the globalsymtable with tglobalsymtable
  1103. can then lead to problems (PFV)
  1104. current_module.globalsymtable:=current_module.localsymtable;
  1105. current_module.localsymtable:=nil;}
  1106. If ResourceStrings.ResStrCount>0 then
  1107. begin
  1108. ResourceStrings.CreateResourceStringList;
  1109. { only write if no errors found }
  1110. if (Errorcount=0) then
  1111. ResourceStrings.WriteResourceFile(ForceExtension(current_module.ppufilename^,'.rst'));
  1112. end;
  1113. codegen_doneprocedure;
  1114. { finalize? }
  1115. if token=_FINALIZATION then
  1116. begin
  1117. { set module options }
  1118. current_module.flags:=current_module.flags or uf_finalize;
  1119. { Compile the finalize }
  1120. codegen_newprocedure;
  1121. gen_main_procsym(current_module.modulename^+'_finalize',potype_unitfinalize,st);
  1122. aktprocdef.aliasnames.insert('FINALIZE$$'+current_module.modulename^);
  1123. aktprocdef.aliasnames.insert(target_info.cprefix+current_module.modulename^+'_finalize');
  1124. compile_proc_body(true,false);
  1125. codegen_doneprocedure;
  1126. end;
  1127. { consume the last point }
  1128. consume(_POINT);
  1129. {$ifdef New_GDB}
  1130. write_gdb_info;
  1131. {$endIf Def New_GDB}
  1132. { leave when we got an error }
  1133. if (Errorcount>0) and not status.skip_error then
  1134. begin
  1135. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  1136. status.skip_error:=true;
  1137. exit;
  1138. end;
  1139. { test static symtable }
  1140. if (Errorcount=0) then
  1141. begin
  1142. tstoredsymtable(st).allsymbolsused;
  1143. tstoredsymtable(st).allunitsused;
  1144. tstoredsymtable(st).allprivatesused;
  1145. end;
  1146. { generate imports }
  1147. if current_module.uses_imports then
  1148. importlib.generatelib;
  1149. if islibrary or
  1150. (target_info.target=target_i386_WIN32) then
  1151. exportlib.generatelib;
  1152. { insert heap }
  1153. insertResourceTablesTable;
  1154. insertinitfinaltable;
  1155. insertheap;
  1156. inserttargetspecific;
  1157. datasize:=symtablestack.datasize;
  1158. { finish asmlist by adding segment starts }
  1159. insertsegment;
  1160. { insert own objectfile }
  1161. insertobjectfile;
  1162. { assemble and link }
  1163. create_objectfile;
  1164. { leave when we got an error }
  1165. if (Errorcount>0) and not status.skip_error then
  1166. begin
  1167. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  1168. status.skip_error:=true;
  1169. exit;
  1170. end;
  1171. { create the executable when we are at level 1 }
  1172. if (compile_level=1) then
  1173. begin
  1174. { insert all .o files from all loaded units }
  1175. hp:=tmodule(loaded_units.first);
  1176. while assigned(hp) do
  1177. begin
  1178. linker.AddModuleFiles(hp);
  1179. hp:=tmodule(hp.next);
  1180. end;
  1181. { write .def file }
  1182. if (cs_link_deffile in aktglobalswitches) then
  1183. deffile.writefile;
  1184. { finally we can create a executable }
  1185. if (not current_module.is_unit) then
  1186. begin
  1187. if DLLSource then
  1188. linker.MakeSharedLibrary
  1189. else
  1190. linker.MakeExecutable;
  1191. end;
  1192. end;
  1193. end;
  1194. end.
  1195. {
  1196. $Log$
  1197. Revision 1.51 2002-01-24 18:25:49 peter
  1198. * implicit result variable generation for assembler routines
  1199. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  1200. Revision 1.50 2001/12/09 03:34:58 carl
  1201. + Stack checking for solaris
  1202. Revision 1.49 2001/11/02 23:16:51 peter
  1203. * removed obsolete chainprocsym and test_procsym code
  1204. Revision 1.48 2001/11/02 22:58:05 peter
  1205. * procsym definition rewrite
  1206. Revision 1.47 2001/09/18 11:30:48 michael
  1207. * Fixes win32 linking problems with import libraries
  1208. * LINKLIB Libraries are now looked for using C file extensions
  1209. * get_exepath fix
  1210. Revision 1.46 2001/09/13 14:47:47 michael
  1211. + Committed patch from peter
  1212. Revision 1.45 2001/08/26 13:36:46 florian
  1213. * some cg reorganisation
  1214. * some PPC updates
  1215. Revision 1.44 2001/08/19 11:22:23 peter
  1216. * palmos support from v10 merged
  1217. Revision 1.43 2001/08/12 19:59:49 peter
  1218. * typo in extdebug msg
  1219. Revision 1.42 2001/08/06 21:40:47 peter
  1220. * funcret moved from tprocinfo to tprocdef
  1221. Revision 1.41 2001/08/05 12:26:52 peter
  1222. * beos fix (merged)
  1223. Revision 1.40 2001/08/04 10:23:54 peter
  1224. * updates so it works with the ide
  1225. Revision 1.38 2001/07/30 20:59:27 peter
  1226. * m68k updates from v10 merged
  1227. Revision 1.37 2001/06/18 20:36:25 peter
  1228. * -Ur switch (merged)
  1229. * masm fixes (merged)
  1230. * quoted filenames for go32v2 and win32
  1231. Revision 1.36 2001/06/06 21:58:16 peter
  1232. * Win32 fixes for Makefile so it doesn't require sh.exe
  1233. Revision 1.35 2001/06/03 21:57:36 peter
  1234. + hint directive parsing support
  1235. Revision 1.34 2001/06/03 15:15:31 peter
  1236. * dllprt0 stub for linux shared libs
  1237. * pass -init and -fini for linux shared libs
  1238. * libprefix splitted into staticlibprefix and sharedlibprefix
  1239. Revision 1.33 2001/05/19 23:05:19 peter
  1240. * support uses <unit> in <file> construction
  1241. Revision 1.32 2001/05/18 22:26:36 peter
  1242. * merged alignment for non-i386
  1243. Revision 1.31 2001/05/09 14:11:10 jonas
  1244. * range check error fixes from Peter
  1245. Revision 1.30 2001/05/06 14:49:17 peter
  1246. * ppu object to class rewrite
  1247. * move ppu read and write stuff to fppu
  1248. Revision 1.29 2001/04/18 22:01:57 peter
  1249. * registration of targets and assemblers
  1250. Revision 1.28 2001/04/13 18:08:37 peter
  1251. * scanner object to class
  1252. Revision 1.27 2001/04/13 01:22:12 peter
  1253. * symtable change to classes
  1254. * range check generation and errors fixed, make cycle DEBUG=1 works
  1255. * memory leaks fixed
  1256. Revision 1.26 2001/04/02 21:20:33 peter
  1257. * resulttype rewrite
  1258. Revision 1.25 2001/03/13 18:45:07 peter
  1259. * fixed some memory leaks
  1260. Revision 1.24 2001/03/06 18:28:02 peter
  1261. * patch from Pavel with a new and much faster DLL Scanner for
  1262. automatic importing so $linklib works for DLLs. Thanks Pavel!
  1263. Revision 1.23 2001/02/24 10:44:56 peter
  1264. * generate .rst from ppufilename instead of modulename
  1265. Revision 1.22 2001/02/21 19:37:19 peter
  1266. * moved deref to be done after loading of implementation units. prederef
  1267. is still done directly after loading of symbols and definitions.
  1268. Revision 1.21 2001/01/14 22:13:52 peter
  1269. * fixed crash with program name as a important unit name
  1270. Revision 1.20 2000/12/25 00:07:27 peter
  1271. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1272. tlinkedlist objects)
  1273. Revision 1.19 2000/11/29 00:30:36 florian
  1274. * unused units removed from uses clause
  1275. * some changes for widestrings
  1276. Revision 1.18 2000/11/01 23:04:37 peter
  1277. * tprocdef.fullprocname added for better casesensitve writing of
  1278. procedures
  1279. Revision 1.17 2000/10/31 22:02:50 peter
  1280. * symtable splitted, no real code changes
  1281. Revision 1.16 2000/10/21 14:36:26 peter
  1282. * merged pierres fixes
  1283. Revision 1.15 2000/10/15 09:08:58 peter
  1284. * use System for the systemunit instead of target dependent
  1285. Revision 1.14 2000/10/15 07:47:51 peter
  1286. * unit names and procedure names are stored mixed case
  1287. Revision 1.13 2000/10/04 14:51:08 pierre
  1288. * IsExe restored
  1289. Revision 1.12 2000/09/30 16:07:40 peter
  1290. * filepos when unit not found (merged)
  1291. Revision 1.11 2000/09/24 21:33:47 peter
  1292. * message updates merges
  1293. Revision 1.10 2000/09/24 15:06:22 peter
  1294. * use defines.inc
  1295. Revision 1.9 2000/08/31 07:53:02 michael
  1296. + Applied patch from Peter
  1297. Revision 1.8 2000/08/29 19:00:01 peter
  1298. * _init and _finalize procsyms also need a $ prefix
  1299. Revision 1.7 2000/08/27 20:19:39 peter
  1300. * store strings with case in ppu, when an internal symbol is created
  1301. a '$' is prefixed so it's not automatic uppercased
  1302. Revision 1.6 2000/08/27 16:11:52 peter
  1303. * moved some util functions from globals,cobjects to cutils
  1304. * splitted files into finput,fmodule
  1305. Revision 1.5 2000/08/25 08:48:22 jonas
  1306. * fixed bug with include files at the very beginning of .pp/.pas files
  1307. (wrong name used for generating exe/checking unit name) (merged from
  1308. fixes branch)
  1309. Revision 1.4 2000/08/21 11:27:44 pierre
  1310. * fix the stabs problems
  1311. Revision 1.3 2000/07/13 12:08:26 michael
  1312. + patched to 1.1.0 with former 1.09patch from peter
  1313. Revision 1.2 2000/07/13 11:32:45 michael
  1314. + removed logs
  1315. }