pmodules.pas 50 KB

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