pmodules.pas 51 KB

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