pmodules.pas 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. Handles the parsing and loading of the modules (ppufiles)
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit pmodules;
  19. {$i defines.inc}
  20. {$define New_GDB}
  21. interface
  22. procedure proc_unit;
  23. procedure proc_program(islibrary : boolean);
  24. implementation
  25. uses
  26. globtype,version,systems,tokens,
  27. cutils,comphook,
  28. globals,verbose,fmodule,finput,fppu,
  29. symconst,symbase,symppu,symdef,symsym,symtable,aasm,
  30. {$ifdef newcg}
  31. cgbase,
  32. {$else newcg}
  33. hcodegen,
  34. {$ifdef i386}
  35. cgai386,
  36. {$endif i386}
  37. {$endif newcg}
  38. link,assemble,import,export,gendef,ppu,comprsrc,
  39. cresstr,cpubase,cpuasm,
  40. {$ifdef GDB}
  41. gdb,
  42. {$endif GDB}
  43. scanner,pbase,pexpr,psystem,psub,parser;
  44. procedure create_objectfile;
  45. var
  46. DLLScanner : TDLLScanner;
  47. s : string;
  48. begin
  49. { try to create import entries from system dlls }
  50. if target_info.DllScanSupported and
  51. (not current_module.linkOtherSharedLibs.Empty) then
  52. begin
  53. { Init DLLScanner }
  54. if assigned(CDLLScanner[target_info.target]) then
  55. DLLScanner:=CDLLScanner[target_info.target].Create
  56. else
  57. internalerror(200104121);
  58. { Walk all shared libs }
  59. While not current_module.linkOtherSharedLibs.Empty do
  60. begin
  61. S:=current_module.linkOtherSharedLibs.Getusemask(link_allways);
  62. DLLScanner.scan(s)
  63. end;
  64. DLLscanner.Free;
  65. { Recreate import section }
  66. if (target_info.target=target_i386_win32) then
  67. begin
  68. if assigned(importssection)then
  69. importssection.clear
  70. else
  71. importssection:=taasmoutput.Create;
  72. importlib.generatelib;
  73. end;
  74. end;
  75. { create the .s file and assemble it }
  76. GenerateAsm(false);
  77. { Also create a smartlinked version ? }
  78. if (cs_create_smart in aktmoduleswitches) then
  79. begin
  80. { regenerate the importssection for win32 }
  81. if assigned(importssection) and
  82. (target_info.target=target_i386_win32) then
  83. begin
  84. importsSection.clear;
  85. importlib.generatesmartlib;
  86. end;
  87. GenerateAsm(true);
  88. if target_asm.needar then
  89. Linker.MakeStaticLibrary;
  90. end;
  91. { resource files }
  92. CompileResourceFiles;
  93. end;
  94. procedure insertobjectfile;
  95. { Insert the used object file for this unit in the used list for this unit }
  96. begin
  97. current_module.linkunitofiles.add(current_module.objfilename^,link_static);
  98. current_module.flags:=current_module.flags or uf_static_linked;
  99. if (cs_create_smart in aktmoduleswitches) then
  100. begin
  101. current_module.linkunitstaticlibs.add(current_module.staticlibfilename^,link_smart);
  102. current_module.flags:=current_module.flags or uf_smart_linked;
  103. end;
  104. end;
  105. procedure insertsegment;
  106. procedure fixseg(p:TAAsmoutput;sec:tsection);
  107. begin
  108. p.insert(Tai_section.Create(sec));
  109. if (cs_create_smart in aktmoduleswitches) then
  110. p.insert(Tai_cut.Create);
  111. p.concat(Tai_section.Create(sec_none));
  112. end;
  113. begin
  114. { Insert Ident of the compiler }
  115. if (not (cs_create_smart in aktmoduleswitches))
  116. {$ifndef EXTDEBUG}
  117. and (not current_module.is_unit)
  118. {$endif}
  119. then
  120. begin
  121. dataSegment.insert(Tai_align.Create(4));
  122. dataSegment.insert(Tai_string.Create('FPC '+full_version_string+
  123. ' ['+date_string+'] for '+target_cpu_string+' - '+target_info.shortname));
  124. end;
  125. { finish codesegment }
  126. {$ifdef i386}
  127. codeSegment.concat(Tai_align.Create(16));
  128. {$else}
  129. if cs_littlesize in aktglobalswitches then
  130. codesegment.concat(tai_align.create(2))
  131. else
  132. codesegment.concat(tai_align.create(4));
  133. {$endif}
  134. { Insert start and end of sections }
  135. fixseg(codesegment,sec_code);
  136. fixseg(datasegment,sec_data);
  137. fixseg(bsssegment,sec_bss);
  138. { we should use .rdata section for these two no ? }
  139. { .rdata is a read only data section (PM) }
  140. fixseg(rttilist,sec_data);
  141. fixseg(consts,sec_data);
  142. if assigned(resourcestringlist) then
  143. fixseg(resourcestringlist,sec_data);
  144. {$ifdef GDB}
  145. if assigned(debuglist) then
  146. begin
  147. debugList.insert(Tai_symbol.Createname('gcc2_compiled',0));
  148. debugList.insert(Tai_symbol.Createname('fpc_compiled',0));
  149. fixseg(debuglist,sec_code);
  150. end;
  151. {$endif GDB}
  152. end;
  153. Procedure InsertResourceTablesTable;
  154. var
  155. hp : tused_unit;
  156. ResourceStringTables : taasmoutput;
  157. count : longint;
  158. begin
  159. ResourceStringTables:=TAAsmOutput.Create;
  160. count:=0;
  161. hp:=tused_unit(usedunits.first);
  162. while assigned(hp) do
  163. begin
  164. If (hp.u.flags and uf_has_resources)=uf_has_resources then
  165. begin
  166. ResourceStringTables.concat(Tai_const_symbol.Createname(hp.u.modulename^+'_RESOURCESTRINGLIST'));
  167. inc(count);
  168. end;
  169. hp:=tused_unit(hp.next);
  170. end;
  171. { Add program resources, if any }
  172. If ResourceStringList<>Nil then
  173. begin
  174. ResourceStringTables.concat(Tai_const_symbol.Createname(current_module.modulename^+'_RESOURCESTRINGLIST'));
  175. Inc(Count);
  176. end;
  177. { TableCount }
  178. ResourceStringTables.insert(Tai_const.Create_32bit(count));
  179. ResourceStringTables.insert(Tai_symbol.Createdataname_global('FPC_RESOURCESTRINGTABLES',0));
  180. ResourceStringTables.concat(Tai_symbol_end.Createname('FPC_RESOURCESTRINGTABLES'));
  181. { insert in data segment }
  182. if (cs_create_smart in aktmoduleswitches) then
  183. dataSegment.concat(Tai_cut.Create);
  184. dataSegment.concatlist(ResourceStringTables);
  185. ResourceStringTables.free;
  186. end;
  187. procedure InsertInitFinalTable;
  188. var
  189. hp : tused_unit;
  190. unitinits : taasmoutput;
  191. count : longint;
  192. begin
  193. unitinits:=TAAsmOutput.Create;
  194. count:=0;
  195. hp:=tused_unit(usedunits.first);
  196. while assigned(hp) do
  197. begin
  198. { call the unit init code and make it external }
  199. if (hp.u.flags and (uf_init or uf_finalize))<>0 then
  200. begin
  201. if (hp.u.flags and uf_init)<>0 then
  202. unitinits.concat(Tai_const_symbol.Createname('INIT$$'+hp.u.modulename^))
  203. else
  204. unitinits.concat(Tai_const.Create_32bit(0));
  205. if (hp.u.flags and uf_finalize)<>0 then
  206. unitinits.concat(Tai_const_symbol.Createname('FINALIZE$$'+hp.u.modulename^))
  207. else
  208. unitinits.concat(Tai_const.Create_32bit(0));
  209. inc(count);
  210. end;
  211. hp:=tused_unit(hp.next);
  212. end;
  213. if current_module.islibrary then
  214. if (current_module.flags and uf_finalize)<>0 then
  215. begin
  216. { INIT code is done by PASCALMAIN calling }
  217. unitinits.concat(Tai_const.Create_32bit(0));
  218. unitinits.concat(Tai_const_symbol.Createname('FINALIZE$$'+current_module.modulename^));
  219. inc(count);
  220. end;
  221. { TableCount,InitCount }
  222. unitinits.insert(Tai_const.Create_32bit(0));
  223. unitinits.insert(Tai_const.Create_32bit(count));
  224. unitinits.insert(Tai_symbol.Createdataname_global('INITFINAL',0));
  225. unitinits.concat(Tai_symbol_end.Createname('INITFINAL'));
  226. { insert in data segment }
  227. if (cs_create_smart in aktmoduleswitches) then
  228. dataSegment.concat(Tai_cut.Create);
  229. dataSegment.concatlist(unitinits);
  230. unitinits.free;
  231. end;
  232. procedure insertheap;
  233. begin
  234. if (cs_create_smart in aktmoduleswitches) then
  235. begin
  236. bssSegment.concat(Tai_cut.Create);
  237. dataSegment.concat(Tai_cut.Create);
  238. end;
  239. { On the Macintosh Classic M68k Architecture
  240. The Heap variable is simply a POINTER to the
  241. real HEAP. The HEAP must be set up by the RTL
  242. and must store the pointer in this value.
  243. On OS/2 the heap is also intialized by the RTL. We do
  244. not output a pointer }
  245. case target_info.target of
  246. {$ifdef i386}
  247. target_i386_OS2:
  248. ;
  249. {$endif i386}
  250. {$ifdef alpha}
  251. target_alpha_linux:
  252. ;
  253. {$endif alpha}
  254. {$ifdef powerpc}
  255. target_powerpc_linux:
  256. ;
  257. {$endif powerpc}
  258. {$ifdef m68k}
  259. target_m68k_Mac:
  260. bssSegment.concat(Tai_datablock.Create_global('HEAP',4));
  261. target_m68k_PalmOS:
  262. ;
  263. {$endif m68k}
  264. else
  265. bssSegment.concat(Tai_datablock.Create_global('HEAP',heapsize));
  266. end;
  267. {$ifdef m68k}
  268. if target_info.target<>target_m68k_PalmOS then
  269. begin
  270. dataSegment.concat(Tai_symbol.Createdataname_global('HEAP_SIZE',0));
  271. dataSegment.concat(Tai_const.Create_32bit(heapsize));
  272. end;
  273. {$else m68k}
  274. dataSegment.concat(Tai_symbol.Createdataname_global('HEAPSIZE',4));
  275. dataSegment.concat(Tai_const.Create_32bit(heapsize));
  276. {$endif m68k}
  277. end;
  278. procedure inserttargetspecific;
  279. begin
  280. case target_info.target of
  281. {$ifdef alpha}
  282. target_alpha_linux:
  283. ;
  284. {$endif alpha}
  285. {$ifdef powerpc}
  286. target_powerpc_linux:
  287. ;
  288. {$endif powerpc}
  289. {$ifdef i386}
  290. target_i386_Win32 :
  291. begin
  292. if islibrary then
  293. exportssection.concat(tai_const_symbol.create_rva(exportlib.edatalabel));
  294. end;
  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. returntype:=voidtype;
  614. _class:=nil;
  615. para_offset:=8;
  616. framepointer:=frame_pointer;
  617. flags:=0;
  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 token=_ID then
  646. begin
  647. { create filenames and unit name }
  648. main_file := current_scanner.inputfile;
  649. while assigned(main_file.next) do
  650. main_file := main_file.next;
  651. current_module.SetFileName(main_file.path^+main_file.name^,true);
  652. stringdispose(current_module.modulename);
  653. stringdispose(current_module.realmodulename);
  654. current_module.modulename:=stringdup(pattern);
  655. current_module.realmodulename:=stringdup(orgpattern);
  656. { check for system unit }
  657. new(s2);
  658. s2^:=upper(SplitName(main_file.name^));
  659. if (cs_check_unit_name in aktglobalswitches) and
  660. not((current_module.modulename^=s2^) or
  661. ((length(current_module.modulename^)>8) and
  662. (copy(current_module.modulename^,1,8)=s2^))) then
  663. Message1(unit_e_illegal_unit_name,current_module.realmodulename^);
  664. if (current_module.modulename^='SYSTEM') then
  665. include(aktmoduleswitches,cs_compilesystem);
  666. dispose(s2);
  667. end;
  668. consume(_ID);
  669. consume(_SEMICOLON);
  670. consume(_INTERFACE);
  671. { global switches are read, so further changes aren't allowed }
  672. current_module.in_global:=false;
  673. { handle the global switches }
  674. setupglobalswitches;
  675. Message1(unit_u_start_parse_interface,current_module.realmodulename^);
  676. { update status }
  677. status.currentmodule:=current_module.realmodulename^;
  678. { maybe turn off m_objpas if we are compiling objpas }
  679. if (current_module.modulename^='OBJPAS') then
  680. exclude(aktmodeswitches,m_objpas);
  681. { this should be placed after uses !!}
  682. {$ifndef UseNiceNames}
  683. procprefix:='_'+current_module.modulename^+'$$';
  684. {$else UseNiceNames}
  685. procprefix:='_'+tostr(length(current_module.modulename^))+lowercase(current_module.modulename^)+'_';
  686. {$endif UseNiceNames}
  687. parse_only:=true;
  688. { generate now the global symboltable }
  689. st:=tglobalsymtable.create(current_module.modulename^);
  690. refsymtable:=st;
  691. unitst:=tglobalsymtable(st);
  692. { define first as local to overcome dependency conflicts }
  693. current_module.localsymtable:=st;
  694. { the unit name must be usable as a unit specifier }
  695. { inside the unit itself (PM) }
  696. { this also forbids to have another symbol }
  697. { with the same name as the unit }
  698. refsymtable.insert(tunitsym.create(current_module.realmodulename^,unitst));
  699. { load default units, like the system unit }
  700. loaddefaultunits;
  701. { reset }
  702. make_ref:=true;
  703. lexlevel:=0;
  704. { insert qualifier for the system unit (allows system.writeln) }
  705. if not(cs_compilesystem in aktmoduleswitches) then
  706. begin
  707. if token=_USES then
  708. begin
  709. loadunits;
  710. { has it been compiled at a higher level ?}
  711. if current_module.compiled then
  712. begin
  713. { this unit symtable is obsolete }
  714. { dispose(unitst,done);
  715. disposed as localsymtable !! }
  716. RestoreUnitSyms;
  717. exit;
  718. end;
  719. end;
  720. { ... but insert the symbol table later }
  721. st.next:=symtablestack;
  722. symtablestack:=st;
  723. end
  724. else
  725. { while compiling a system unit, some types are directly inserted }
  726. begin
  727. st.next:=symtablestack;
  728. symtablestack:=st;
  729. insert_intern_types(st);
  730. end;
  731. { now we know the place to insert the constants }
  732. constsymtable:=symtablestack;
  733. { move the global symtab from the temporary local to global }
  734. current_module.globalsymtable:=current_module.localsymtable;
  735. current_module.localsymtable:=nil;
  736. reset_global_defs;
  737. { number all units, so we know if a unit is used by this unit or
  738. needs to be added implicitly }
  739. current_module.numberunits;
  740. { ... parse the declarations }
  741. Message1(parser_u_parsing_interface,current_module.realmodulename^);
  742. read_interface_declarations;
  743. { leave when we got an error }
  744. if (Errorcount>0) and not status.skip_error then
  745. begin
  746. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  747. status.skip_error:=true;
  748. exit;
  749. end;
  750. {else in inteface its somatimes necessary even if unused
  751. st^.allunitsused; }
  752. {$ifdef New_GDB}
  753. write_gdb_info;
  754. {$endIf Def New_GDB}
  755. if not(cs_compilesystem in aktmoduleswitches) then
  756. if (Errorcount=0) then
  757. tppumodule(current_module).getppucrc;
  758. { Parse the implementation section }
  759. consume(_IMPLEMENTATION);
  760. current_module.in_implementation:=true;
  761. Message1(unit_u_start_parse_implementation,current_module.modulename^);
  762. parse_only:=false;
  763. { generates static symbol table }
  764. st:=tstaticsymtable.create(current_module.modulename^);
  765. current_module.localsymtable:=st;
  766. { remove the globalsymtable from the symtable stack }
  767. { to reinsert it after loading the implementation units }
  768. symtablestack:=unitst.next;
  769. { we don't want implementation units symbols in unitsymtable !! PM }
  770. refsymtable:=st;
  771. { Read the implementation units }
  772. parse_implementation_uses(unitst);
  773. if current_module.compiled then
  774. begin
  775. RestoreUnitSyms;
  776. exit;
  777. end;
  778. { reset ranges/stabs in exported definitions }
  779. reset_global_defs;
  780. { All units are read, now give them a number }
  781. current_module.numberunits;
  782. { now we can change refsymtable }
  783. refsymtable:=st;
  784. { but reinsert the global symtable as lasts }
  785. unitst.next:=symtablestack;
  786. symtablestack:=unitst;
  787. tstoredsymtable(symtablestack).chainoperators;
  788. {$ifdef DEBUG}
  789. test_symtablestack;
  790. {$endif DEBUG}
  791. constsymtable:=symtablestack;
  792. {$ifdef Splitheap}
  793. if testsplit then
  794. begin
  795. Split_Heap;
  796. allow_special:=true;
  797. Switch_to_temp_heap;
  798. end;
  799. { it will report all crossings }
  800. allow_special:=false;
  801. {$endif Splitheap}
  802. Message1(parser_u_parsing_implementation,current_module.realmodulename^);
  803. { Compile the unit }
  804. codegen_newprocedure;
  805. gen_main_procsym(current_module.modulename^+'_init',potype_unitinit,st);
  806. aktprocsym.definition.aliasnames.insert('INIT$$'+current_module.modulename^);
  807. aktprocsym.definition.aliasnames.insert(target_info.cprefix+current_module.modulename^+'_init');
  808. compile_proc_body(true,false);
  809. codegen_doneprocedure;
  810. { avoid self recursive destructor call !! PM }
  811. aktprocsym.definition.localst:=nil;
  812. { if the unit contains ansi/widestrings, initialization and
  813. finalization code must be forced }
  814. force_init_final:=tglobalsymtable(current_module.globalsymtable).needs_init_final or
  815. tstaticsymtable(current_module.localsymtable).needs_init_final;
  816. { should we force unit initialization? }
  817. { this is a hack, but how can it be done better ? }
  818. if force_init_final and ((current_module.flags and uf_init)=0) then
  819. begin
  820. current_module.flags:=current_module.flags or uf_init;
  821. { now we can insert a cut }
  822. if (cs_create_smart in aktmoduleswitches) then
  823. codeSegment.concat(Tai_cut.Create);
  824. genimplicitunitinit(codesegment);
  825. end;
  826. { finalize? }
  827. if token=_FINALIZATION then
  828. begin
  829. { set module options }
  830. current_module.flags:=current_module.flags or uf_finalize;
  831. { Compile the finalize }
  832. codegen_newprocedure;
  833. gen_main_procsym(current_module.modulename^+'_finalize',potype_unitfinalize,st);
  834. aktprocsym.definition.aliasnames.insert('FINALIZE$$'+current_module.modulename^);
  835. aktprocsym.definition.aliasnames.insert(target_info.cprefix+current_module.modulename^+'_finalize');
  836. compile_proc_body(true,false);
  837. codegen_doneprocedure;
  838. end
  839. else if force_init_final then
  840. begin
  841. current_module.flags:=current_module.flags or uf_finalize;
  842. { now we can insert a cut }
  843. if (cs_create_smart in aktmoduleswitches) then
  844. codeSegment.concat(Tai_cut.Create);
  845. genimplicitunitfinal(codesegment);
  846. end;
  847. { the last char should always be a point }
  848. consume(_POINT);
  849. If ResourceStrings.ResStrCount>0 then
  850. begin
  851. ResourceStrings.CreateResourceStringList;
  852. current_module.flags:=current_module.flags or uf_has_resources;
  853. { only write if no errors found }
  854. if (Errorcount=0) then
  855. ResourceStrings.WriteResourceFile(ForceExtension(current_module.ppufilename^,'.rst'));
  856. end;
  857. { avoid self recursive destructor call !! PM }
  858. aktprocsym.definition.localst:=nil;
  859. { absence does not matter here !! }
  860. aktprocsym.definition.forwarddef:=false;
  861. { test static symtable }
  862. if (Errorcount=0) then
  863. begin
  864. tstoredsymtable(st).allsymbolsused;
  865. tstoredsymtable(st).allunitsused;
  866. tstoredsymtable(st).allprivatesused;
  867. end;
  868. { size of the static data }
  869. datasize:=st.datasize;
  870. {$ifdef GDB}
  871. { add all used definitions even for implementation}
  872. if (cs_debuginfo in aktmoduleswitches) then
  873. begin
  874. {$IfnDef New_GDB}
  875. if assigned(current_module.globalsymtable) then
  876. begin
  877. { all types }
  878. tglobalsymtable(current_module.globalsymtable).concattypestabto(debuglist);
  879. { and all local symbols}
  880. tglobalsymtable(current_module.globalsymtable).concatstabto(debuglist);
  881. end;
  882. { all local types }
  883. tglobalsymtable(st)^.concattypestabto(debuglist);
  884. { and all local symbols}
  885. st^.concatstabto(debuglist);
  886. {$else New_GDB}
  887. write_gdb_info;
  888. {$endIf Def New_GDB}
  889. end;
  890. {$endif GDB}
  891. reset_global_defs;
  892. { tests, if all (interface) forwards are resolved }
  893. if (Errorcount=0) then
  894. begin
  895. tstoredsymtable(symtablestack).check_forwards;
  896. tstoredsymtable(symtablestack).allprivatesused;
  897. end;
  898. current_module.in_implementation:=false;
  899. {$ifdef GDB}
  900. tglobalsymtable(symtablestack).is_stab_written:=false;
  901. {$endif GDB}
  902. { leave when we got an error }
  903. if (Errorcount>0) and not status.skip_error then
  904. begin
  905. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  906. status.skip_error:=true;
  907. exit;
  908. end;
  909. { generate imports }
  910. if current_module.uses_imports then
  911. importlib.generatelib;
  912. { insert own objectfile, or say that it's in a library
  913. (no check for an .o when loading) }
  914. if is_assembler_generated then
  915. insertobjectfile
  916. else
  917. current_module.flags:=current_module.flags or uf_no_link;
  918. if cs_local_browser in aktmoduleswitches then
  919. current_module.localsymtable:=refsymtable;
  920. {$ifdef GDB}
  921. pu:=tused_unit(usedunits.first);
  922. while assigned(pu) do
  923. begin
  924. if assigned(pu.u.globalsymtable) then
  925. tglobalsymtable(pu.u.globalsymtable).is_stab_written:=false;
  926. pu:=tused_unit(pu.next);
  927. end;
  928. {$endif GDB}
  929. if is_assembler_generated then
  930. begin
  931. { finish asmlist by adding segment starts }
  932. insertsegment;
  933. { assemble }
  934. create_objectfile;
  935. end;
  936. { Write out the ppufile after the object file has been created }
  937. store_interface_crc:=current_module.interface_crc;
  938. store_crc:=current_module.crc;
  939. if (Errorcount=0) then
  940. tppumodule(current_module).writeppu;
  941. if not(cs_compilesystem in aktmoduleswitches) then
  942. if store_interface_crc<>current_module.interface_crc then
  943. Comment(V_Warning,current_module.ppufilename^+' Interface CRC changed '+
  944. hexstr(store_crc,8)+'<>'+hexstr(current_module.interface_crc,8));
  945. {$ifdef EXTDEBUG}
  946. if not(cs_compilesystem in aktmoduleswitches) then
  947. if (store_crc<>current_module.crc) and simplify_ppu then
  948. Comment(V_Warning,current_module.ppufilename^+' implementation CRC changed '+
  949. hexstr(store_crc,8)+'<>'+hexstr(current_module.interface_crc,8));
  950. {$endif EXTDEBUG}
  951. { remove static symtable (=refsymtable) here to save some mem }
  952. if not (cs_local_browser in aktmoduleswitches) then
  953. begin
  954. st.free;
  955. current_module.localsymtable:=nil;
  956. end;
  957. RestoreUnitSyms;
  958. { leave when we got an error }
  959. if (Errorcount>0) and not status.skip_error then
  960. begin
  961. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  962. status.skip_error:=true;
  963. exit;
  964. end;
  965. end;
  966. procedure proc_program(islibrary : boolean);
  967. var
  968. main_file: tinputfile;
  969. st : tsymtable;
  970. hp : tmodule;
  971. begin
  972. DLLsource:=islibrary;
  973. IsExe:=true;
  974. parse_only:=false;
  975. { relocation works only without stabs under win32 !! PM }
  976. { internal assembler uses rva for stabs info
  977. so it should work with relocated DLLs }
  978. if RelocSection and
  979. (target_info.target=target_i386_win32) and
  980. (target_info.assem<>as_i386_pecoff) then
  981. begin
  982. include(aktglobalswitches,cs_link_strip);
  983. { Warning stabs info does not work with reloc section !! }
  984. if cs_debuginfo in aktmoduleswitches then
  985. begin
  986. Message1(parser_w_parser_reloc_no_debug,current_module.mainsource^);
  987. Message(parser_w_parser_win32_debug_needs_WN);
  988. exclude(aktmoduleswitches,cs_debuginfo);
  989. end;
  990. end;
  991. { get correct output names }
  992. main_file := current_scanner.inputfile;
  993. while assigned(main_file.next) do
  994. main_file := main_file.next;
  995. current_module.SetFileName(main_file.path^+main_file.name^,true);
  996. if islibrary then
  997. begin
  998. consume(_LIBRARY);
  999. stringdispose(current_module.modulename);
  1000. current_module.modulename:=stringdup(pattern);
  1001. current_module.islibrary:=true;
  1002. exportlib.preparelib(pattern);
  1003. consume(_ID);
  1004. consume(_SEMICOLON);
  1005. end
  1006. else
  1007. { is there an program head ? }
  1008. if token=_PROGRAM then
  1009. begin
  1010. consume(_PROGRAM);
  1011. stringdispose(current_module.modulename);
  1012. stringdispose(current_module.realmodulename);
  1013. current_module.modulename:=stringdup(pattern);
  1014. current_module.realmodulename:=stringdup(orgpattern);
  1015. if (target_info.target=target_i386_WIN32) then
  1016. exportlib.preparelib(pattern);
  1017. consume(_ID);
  1018. if token=_LKLAMMER then
  1019. begin
  1020. consume(_LKLAMMER);
  1021. consume_idlist;
  1022. consume(_RKLAMMER);
  1023. end;
  1024. consume(_SEMICOLON);
  1025. end
  1026. else if (target_info.target=target_i386_WIN32) then
  1027. exportlib.preparelib(current_module.modulename^);
  1028. { global switches are read, so further changes aren't allowed }
  1029. current_module.in_global:=false;
  1030. { setup things using the global switches }
  1031. setupglobalswitches;
  1032. { set implementation flag }
  1033. current_module.in_implementation:=true;
  1034. { insert after the unit symbol tables the static symbol table }
  1035. { of the program }
  1036. st:=tstaticsymtable.create(current_module.modulename^);;
  1037. current_module.localsymtable:=st;
  1038. refsymtable:=st;
  1039. { load standard units (system,objpas,profile unit) }
  1040. loaddefaultunits;
  1041. { reset }
  1042. lexlevel:=0;
  1043. {Load the units used by the program we compile.}
  1044. if token=_USES then
  1045. loadunits;
  1046. tstoredsymtable(symtablestack).chainoperators;
  1047. { reset ranges/stabs in exported definitions }
  1048. reset_global_defs;
  1049. { All units are read, now give them a number }
  1050. current_module.numberunits;
  1051. {Insert the name of the main program into the symbol table.}
  1052. if current_module.realmodulename^<>'' then
  1053. st.insert(tunitsym.create(current_module.realmodulename^,tglobalsymtable(st)));
  1054. { ...is also constsymtable, this is the symtable where }
  1055. { the elements of enumeration types are inserted }
  1056. constsymtable:=st;
  1057. Message1(parser_u_parsing_implementation,current_module.mainsource^);
  1058. { reset }
  1059. procprefix:='';
  1060. {The program intialization needs an alias, so it can be called
  1061. from the bootstrap code.}
  1062. codegen_newprocedure;
  1063. if islibrary then
  1064. begin
  1065. gen_main_procsym(current_module.modulename^+'_main',potype_proginit,st);
  1066. aktprocsym.definition.aliasnames.insert(target_info.cprefix+current_module.modulename^+'_main');
  1067. aktprocsym.definition.aliasnames.insert('PASCALMAIN');
  1068. { this code is called from C so we need to save some
  1069. registers }
  1070. include(aktprocsym.definition.procoptions,po_savestdregs);
  1071. end
  1072. else
  1073. begin
  1074. gen_main_procsym('main',potype_proginit,st);
  1075. aktprocsym.definition.aliasnames.insert('program_init');
  1076. aktprocsym.definition.aliasnames.insert('PASCALMAIN');
  1077. aktprocsym.definition.aliasnames.insert(target_info.cprefix+'main');
  1078. {$ifdef m68k}
  1079. if target_info.target=target_m68k_PalmOS then
  1080. aktprocsym.definition.aliasnames.insert('PilotMain');
  1081. {$endif m68k}
  1082. end;
  1083. compile_proc_body(true,false);
  1084. { avoid self recursive destructor call !! PM }
  1085. aktprocsym.definition.localst:=nil;
  1086. { consider these symbols as global ones for browser
  1087. but the typecasting of the globalsymtable with tglobalsymtable
  1088. can then lead to problems (PFV)
  1089. current_module.globalsymtable:=current_module.localsymtable;
  1090. current_module.localsymtable:=nil;}
  1091. If ResourceStrings.ResStrCount>0 then
  1092. begin
  1093. ResourceStrings.CreateResourceStringList;
  1094. { only write if no errors found }
  1095. if (Errorcount=0) then
  1096. ResourceStrings.WriteResourceFile(ForceExtension(current_module.ppufilename^,'.rst'));
  1097. end;
  1098. codegen_doneprocedure;
  1099. { finalize? }
  1100. if token=_FINALIZATION then
  1101. begin
  1102. { set module options }
  1103. current_module.flags:=current_module.flags or uf_finalize;
  1104. { Compile the finalize }
  1105. codegen_newprocedure;
  1106. gen_main_procsym(current_module.modulename^+'_finalize',potype_unitfinalize,st);
  1107. aktprocsym.definition.aliasnames.insert('FINALIZE$$'+current_module.modulename^);
  1108. aktprocsym.definition.aliasnames.insert(target_info.cprefix+current_module.modulename^+'_finalize');
  1109. compile_proc_body(true,false);
  1110. codegen_doneprocedure;
  1111. end;
  1112. { consume the last point }
  1113. consume(_POINT);
  1114. {$ifdef New_GDB}
  1115. write_gdb_info;
  1116. {$endIf Def New_GDB}
  1117. { leave when we got an error }
  1118. if (Errorcount>0) and not status.skip_error then
  1119. begin
  1120. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  1121. status.skip_error:=true;
  1122. exit;
  1123. end;
  1124. { test static symtable }
  1125. if (Errorcount=0) then
  1126. begin
  1127. tstoredsymtable(st).allsymbolsused;
  1128. tstoredsymtable(st).allunitsused;
  1129. tstoredsymtable(st).allprivatesused;
  1130. end;
  1131. { generate imports }
  1132. if current_module.uses_imports then
  1133. importlib.generatelib;
  1134. if islibrary or
  1135. (target_info.target=target_i386_WIN32) then
  1136. exportlib.generatelib;
  1137. { insert heap }
  1138. insertResourceTablesTable;
  1139. insertinitfinaltable;
  1140. insertheap;
  1141. inserttargetspecific;
  1142. datasize:=symtablestack.datasize;
  1143. { finish asmlist by adding segment starts }
  1144. insertsegment;
  1145. { insert own objectfile }
  1146. insertobjectfile;
  1147. { assemble and link }
  1148. create_objectfile;
  1149. { leave when we got an error }
  1150. if (Errorcount>0) and not status.skip_error then
  1151. begin
  1152. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  1153. status.skip_error:=true;
  1154. exit;
  1155. end;
  1156. { create the executable when we are at level 1 }
  1157. if (compile_level=1) then
  1158. begin
  1159. { insert all .o files from all loaded units }
  1160. hp:=tmodule(loaded_units.first);
  1161. while assigned(hp) do
  1162. begin
  1163. linker.AddModuleFiles(hp);
  1164. hp:=tmodule(hp.next);
  1165. end;
  1166. { write .def file }
  1167. if (cs_link_deffile in aktglobalswitches) then
  1168. deffile.writefile;
  1169. { finally we can create a executable }
  1170. if (not current_module.is_unit) then
  1171. begin
  1172. if DLLSource then
  1173. linker.MakeSharedLibrary
  1174. else
  1175. linker.MakeExecutable;
  1176. end;
  1177. end;
  1178. end;
  1179. end.
  1180. {
  1181. $Log$
  1182. Revision 1.36 2001-06-06 21:58:16 peter
  1183. * Win32 fixes for Makefile so it doesn't require sh.exe
  1184. Revision 1.35 2001/06/03 21:57:36 peter
  1185. + hint directive parsing support
  1186. Revision 1.34 2001/06/03 15:15:31 peter
  1187. * dllprt0 stub for linux shared libs
  1188. * pass -init and -fini for linux shared libs
  1189. * libprefix splitted into staticlibprefix and sharedlibprefix
  1190. Revision 1.33 2001/05/19 23:05:19 peter
  1191. * support uses <unit> in <file> construction
  1192. Revision 1.32 2001/05/18 22:26:36 peter
  1193. * merged alignment for non-i386
  1194. Revision 1.31 2001/05/09 14:11:10 jonas
  1195. * range check error fixes from Peter
  1196. Revision 1.30 2001/05/06 14:49:17 peter
  1197. * ppu object to class rewrite
  1198. * move ppu read and write stuff to fppu
  1199. Revision 1.29 2001/04/18 22:01:57 peter
  1200. * registration of targets and assemblers
  1201. Revision 1.28 2001/04/13 18:08:37 peter
  1202. * scanner object to class
  1203. Revision 1.27 2001/04/13 01:22:12 peter
  1204. * symtable change to classes
  1205. * range check generation and errors fixed, make cycle DEBUG=1 works
  1206. * memory leaks fixed
  1207. Revision 1.26 2001/04/02 21:20:33 peter
  1208. * resulttype rewrite
  1209. Revision 1.25 2001/03/13 18:45:07 peter
  1210. * fixed some memory leaks
  1211. Revision 1.24 2001/03/06 18:28:02 peter
  1212. * patch from Pavel with a new and much faster DLL Scanner for
  1213. automatic importing so $linklib works for DLLs. Thanks Pavel!
  1214. Revision 1.23 2001/02/24 10:44:56 peter
  1215. * generate .rst from ppufilename instead of modulename
  1216. Revision 1.22 2001/02/21 19:37:19 peter
  1217. * moved deref to be done after loading of implementation units. prederef
  1218. is still done directly after loading of symbols and definitions.
  1219. Revision 1.21 2001/01/14 22:13:52 peter
  1220. * fixed crash with program name as a important unit name
  1221. Revision 1.20 2000/12/25 00:07:27 peter
  1222. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1223. tlinkedlist objects)
  1224. Revision 1.19 2000/11/29 00:30:36 florian
  1225. * unused units removed from uses clause
  1226. * some changes for widestrings
  1227. Revision 1.18 2000/11/01 23:04:37 peter
  1228. * tprocdef.fullprocname added for better casesensitve writing of
  1229. procedures
  1230. Revision 1.17 2000/10/31 22:02:50 peter
  1231. * symtable splitted, no real code changes
  1232. Revision 1.16 2000/10/21 14:36:26 peter
  1233. * merged pierres fixes
  1234. Revision 1.15 2000/10/15 09:08:58 peter
  1235. * use System for the systemunit instead of target dependent
  1236. Revision 1.14 2000/10/15 07:47:51 peter
  1237. * unit names and procedure names are stored mixed case
  1238. Revision 1.13 2000/10/04 14:51:08 pierre
  1239. * IsExe restored
  1240. Revision 1.12 2000/09/30 16:07:40 peter
  1241. * filepos when unit not found (merged)
  1242. Revision 1.11 2000/09/24 21:33:47 peter
  1243. * message updates merges
  1244. Revision 1.10 2000/09/24 15:06:22 peter
  1245. * use defines.inc
  1246. Revision 1.9 2000/08/31 07:53:02 michael
  1247. + Applied patch from Peter
  1248. Revision 1.8 2000/08/29 19:00:01 peter
  1249. * _init and _finalize procsyms also need a $ prefix
  1250. Revision 1.7 2000/08/27 20:19:39 peter
  1251. * store strings with case in ppu, when an internal symbol is created
  1252. a '$' is prefixed so it's not automatic uppercased
  1253. Revision 1.6 2000/08/27 16:11:52 peter
  1254. * moved some util functions from globals,cobjects to cutils
  1255. * splitted files into finput,fmodule
  1256. Revision 1.5 2000/08/25 08:48:22 jonas
  1257. * fixed bug with include files at the very beginning of .pp/.pas files
  1258. (wrong name used for generating exe/checking unit name) (merged from
  1259. fixes branch)
  1260. Revision 1.4 2000/08/21 11:27:44 pierre
  1261. * fix the stabs problems
  1262. Revision 1.3 2000/07/13 12:08:26 michael
  1263. + patched to 1.1.0 with former 1.09patch from peter
  1264. Revision 1.2 2000/07/13 11:32:45 michael
  1265. + removed logs
  1266. }