pmodules.pas 51 KB

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