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