pmodules.pas 50 KB

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