pmodules.pas 50 KB

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