pmodules.pas 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 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 fpcdefs.inc}
  20. interface
  21. procedure proc_unit;
  22. procedure proc_program(islibrary : boolean);
  23. implementation
  24. uses
  25. globtype,version,systems,tokens,
  26. cutils,cclasses,comphook,
  27. globals,verbose,fmodule,finput,fppu,
  28. symconst,symbase,symtype,symdef,symsym,symtable,
  29. aasmtai,aasmcpu,aasmbase,
  30. cgbase,cpuinfo,cgobj,
  31. nbas,
  32. link,assemble,import,export,gendef,ppu,comprsrc,
  33. cresstr,procinfo,
  34. {$ifdef GDB}
  35. gdb,
  36. {$endif GDB}
  37. scanner,pbase,pexpr,psystem,psub;
  38. procedure fixseg(p:TAAsmoutput;sec:TSection);
  39. begin
  40. p.insert(Tai_section.Create(sec));
  41. if (cs_create_smart in aktmoduleswitches) then
  42. p.insert(Tai_cut.Create);
  43. p.concat(Tai_section.Create(sec_none));
  44. end;
  45. procedure create_objectfile;
  46. var
  47. DLLScanner : TDLLScanner;
  48. s : string;
  49. KeepShared : TStringList;
  50. begin
  51. { try to create import entries from system dlls }
  52. if target_info.DllScanSupported and
  53. (not current_module.linkOtherSharedLibs.Empty) then
  54. begin
  55. { Init DLLScanner }
  56. if assigned(CDLLScanner[target_info.system]) then
  57. DLLScanner:=CDLLScanner[target_info.system].Create
  58. else
  59. internalerror(200104121);
  60. KeepShared:=TStringList.Create;
  61. { Walk all shared libs }
  62. While not current_module.linkOtherSharedLibs.Empty do
  63. begin
  64. S:=current_module.linkOtherSharedLibs.Getusemask(link_allways);
  65. if not DLLScanner.scan(s) then
  66. KeepShared.Concat(s);
  67. end;
  68. DLLscanner.Free;
  69. { Recreate import section }
  70. if (target_info.system in [system_i386_win32,system_i386_wdosx]) then
  71. begin
  72. if assigned(importssection)then
  73. importssection.clear
  74. else
  75. importssection:=taasmoutput.Create;
  76. importlib.generatelib;
  77. end;
  78. { Readd the not processed files }
  79. while not KeepShared.Empty do
  80. begin
  81. s:=KeepShared.GetFirst;
  82. current_module.linkOtherSharedLibs.add(s,link_allways);
  83. end;
  84. KeepShared.Free;
  85. end;
  86. { create the .s file and assemble it }
  87. GenerateAsm(false);
  88. { Also create a smartlinked version ? }
  89. if (cs_create_smart in aktmoduleswitches) then
  90. begin
  91. { regenerate the importssection for win32 }
  92. if assigned(importssection) and
  93. (target_info.system in [system_i386_win32,system_i386_wdosx]) then
  94. begin
  95. importsSection.clear;
  96. importlib.generatesmartlib;
  97. end;
  98. GenerateAsm(true);
  99. if target_asm.needar then
  100. Linker.MakeStaticLibrary;
  101. end;
  102. { resource files }
  103. CompileResourceFiles;
  104. end;
  105. procedure insertobjectfile;
  106. { Insert the used object file for this unit in the used list for this unit }
  107. begin
  108. current_module.linkunitofiles.add(current_module.objfilename^,link_static);
  109. current_module.flags:=current_module.flags or uf_static_linked;
  110. if (cs_create_smart in aktmoduleswitches) then
  111. begin
  112. current_module.linkunitstaticlibs.add(current_module.staticlibfilename^,link_smart);
  113. current_module.flags:=current_module.flags or uf_smart_linked;
  114. end;
  115. end;
  116. procedure insertsegment;
  117. var
  118. oldaktfilepos : tfileposinfo;
  119. begin
  120. { Insert Ident of the compiler }
  121. if (not (cs_create_smart in aktmoduleswitches))
  122. {$ifndef EXTDEBUG}
  123. and (not current_module.is_unit)
  124. {$endif}
  125. then
  126. begin
  127. { align the first data }
  128. dataSegment.insert(Tai_align.Create(const_align(32)));
  129. dataSegment.insert(Tai_string.Create('FPC '+full_version_string+
  130. ' ['+date_string+'] for '+target_cpu_string+' - '+target_info.shortname));
  131. end;
  132. { align code segment }
  133. codeSegment.concat(Tai_align.Create(aktalignment.procalign));
  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. fixseg(picdata,sec_data);
  143. if assigned(resourcestringlist) then
  144. fixseg(resourcestringlist,sec_data);
  145. {$ifdef GDB}
  146. if assigned(debuglist) then
  147. begin
  148. oldaktfilepos:=aktfilepos;
  149. aktfilepos.line:=0;
  150. debugList.insert(Tai_symbol.Createname('gcc2_compiled',AT_DATA,0));
  151. debugList.insert(Tai_symbol.Createname('fpc_compiled',AT_DATA,0));
  152. fixseg(debuglist,sec_code);
  153. aktfilepos:=oldaktfilepos;
  154. end;
  155. {$endif GDB}
  156. end;
  157. procedure InsertThreadvarTablesTable;
  158. var
  159. hp : tused_unit;
  160. ltvTables : taasmoutput;
  161. count : longint;
  162. begin
  163. ltvTables:=TAAsmOutput.Create;
  164. count:=0;
  165. hp:=tused_unit(usedunits.first);
  166. while assigned(hp) do
  167. begin
  168. If (hp.u.flags and uf_threadvars)=uf_threadvars then
  169. begin
  170. ltvTables.concat(Tai_const_symbol.Createname(make_mangledname('THREADVARLIST',hp.u.globalsymtable,''),AT_DATA,0));
  171. inc(count);
  172. end;
  173. hp:=tused_unit(hp.next);
  174. end;
  175. { Add program threadvars, if any }
  176. If (current_module.flags and uf_threadvars)=uf_threadvars then
  177. begin
  178. ltvTables.concat(Tai_const_symbol.Createname(make_mangledname('THREADVARLIST',current_module.localsymtable,''),AT_DATA,0));
  179. inc(count);
  180. end;
  181. { TableCount }
  182. ltvTables.insert(Tai_const.Create_32bit(count));
  183. ltvTables.insert(Tai_symbol.Createname_global('FPC_THREADVARTABLES',AT_DATA,0));
  184. ltvTables.insert(Tai_align.Create(const_align(pointer_size)));
  185. ltvTables.concat(Tai_symbol_end.Createname('FPC_THREADVARTABLES'));
  186. { insert in data segment }
  187. if (cs_create_smart in aktmoduleswitches) then
  188. dataSegment.concat(Tai_cut.Create);
  189. dataSegment.concatlist(ltvTables);
  190. ltvTables.free;
  191. end;
  192. procedure AddToThreadvarList(p:tnamedindexitem;arg:pointer);
  193. var
  194. ltvTable : taasmoutput;
  195. begin
  196. ltvTable:=taasmoutput(arg);
  197. if (tsym(p).typ=varsym) and
  198. (vo_is_thread_var in tvarsym(p).varoptions) then
  199. begin
  200. { address of threadvar }
  201. ltvTable.concat(tai_const_symbol.Createname(tvarsym(p).mangledname,AT_DATA,0));
  202. { size of threadvar }
  203. ltvTable.concat(tai_const.create_32bit(tvarsym(p).getsize));
  204. end;
  205. end;
  206. procedure InsertThreadvars;
  207. var
  208. s : string;
  209. ltvTable : TAAsmoutput;
  210. begin
  211. ltvTable:=TAAsmoutput.create;
  212. if assigned(current_module.globalsymtable) then
  213. current_module.globalsymtable.foreach_static({$ifdef FPCPROCVAR}@{$endif}AddToThreadvarList,ltvTable);
  214. current_module.localsymtable.foreach_static({$ifdef FPCPROCVAR}@{$endif}AddToThreadvarList,ltvTable);
  215. if ltvTable.first<>nil then
  216. begin
  217. s:=make_mangledname('THREADVARLIST',current_module.localsymtable,'');
  218. { add begin and end of the list }
  219. ltvTable.insert(tai_symbol.Createname_global(s,AT_DATA,0));
  220. ltvTable.concat(tai_const.create_ptr(0)); { end of list marker }
  221. ltvTable.concat(tai_symbol_end.createname(s));
  222. if (cs_create_smart in aktmoduleswitches) then
  223. dataSegment.concat(Tai_cut.Create);
  224. dataSegment.concatlist(ltvTable);
  225. current_module.flags:=current_module.flags or uf_threadvars;
  226. end;
  227. ltvTable.Free;
  228. end;
  229. Procedure InsertResourceTablesTable;
  230. var
  231. hp : tused_unit;
  232. ResourceStringTables : taasmoutput;
  233. count : longint;
  234. begin
  235. ResourceStringTables:=TAAsmOutput.Create;
  236. count:=0;
  237. hp:=tused_unit(usedunits.first);
  238. while assigned(hp) do
  239. begin
  240. If (hp.u.flags and uf_has_resources)=uf_has_resources then
  241. begin
  242. ResourceStringTables.concat(Tai_const_symbol.Createname(make_mangledname('RESOURCESTRINGLIST',hp.u.globalsymtable,''),AT_DATA,0));
  243. inc(count);
  244. end;
  245. hp:=tused_unit(hp.next);
  246. end;
  247. { Add program resources, if any }
  248. If ResourceStringList<>Nil then
  249. begin
  250. ResourceStringTables.concat(Tai_const_symbol.Createname(make_mangledname('RESOURCESTRINGLIST',current_module.localsymtable,''),AT_DATA,0));
  251. Inc(Count);
  252. end;
  253. { TableCount }
  254. ResourceStringTables.insert(Tai_const.Create_32bit(count));
  255. ResourceStringTables.insert(Tai_symbol.Createname_global('FPC_RESOURCESTRINGTABLES',AT_DATA,0));
  256. ResourceStringTables.insert(Tai_align.Create(const_align(4)));
  257. ResourceStringTables.concat(Tai_symbol_end.Createname('FPC_RESOURCESTRINGTABLES'));
  258. { insert in data segment }
  259. if (cs_create_smart in aktmoduleswitches) then
  260. dataSegment.concat(Tai_cut.Create);
  261. dataSegment.concatlist(ResourceStringTables);
  262. ResourceStringTables.free;
  263. end;
  264. procedure InsertInitFinalTable;
  265. var
  266. hp : tused_unit;
  267. unitinits : taasmoutput;
  268. count : longint;
  269. begin
  270. unitinits:=TAAsmOutput.Create;
  271. count:=0;
  272. hp:=tused_unit(usedunits.first);
  273. while assigned(hp) do
  274. begin
  275. { call the unit init code and make it external }
  276. if (hp.u.flags and (uf_init or uf_finalize))<>0 then
  277. begin
  278. if (hp.u.flags and uf_init)<>0 then
  279. unitinits.concat(Tai_const_symbol.Createname(make_mangledname('INIT$',hp.u.globalsymtable,''),AT_FUNCTION,0))
  280. else
  281. unitinits.concat(Tai_const.Create_ptr(0));
  282. if (hp.u.flags and uf_finalize)<>0 then
  283. unitinits.concat(Tai_const_symbol.Createname(make_mangledname('FINALIZE$',hp.u.globalsymtable,''),AT_FUNCTION,0))
  284. else
  285. unitinits.concat(Tai_const.Create_ptr(0));
  286. inc(count);
  287. end;
  288. hp:=tused_unit(hp.next);
  289. end;
  290. { Insert initialization/finalization of the program }
  291. if (current_module.flags and (uf_init or uf_finalize))<>0 then
  292. begin
  293. if (current_module.flags and uf_init)<>0 then
  294. unitinits.concat(Tai_const_symbol.Createname(make_mangledname('INIT$',current_module.localsymtable,''),AT_FUNCTION,0))
  295. else
  296. unitinits.concat(Tai_const.Create_ptr(0));
  297. if (current_module.flags and uf_finalize)<>0 then
  298. unitinits.concat(Tai_const_symbol.Createname(make_mangledname('FINALIZE$',current_module.localsymtable,''),AT_FUNCTION,0))
  299. else
  300. unitinits.concat(Tai_const.Create_ptr(0));
  301. inc(count);
  302. end;
  303. { TableCount,InitCount }
  304. unitinits.insert(Tai_const.Create_32bit(0));
  305. unitinits.insert(Tai_const.Create_32bit(count));
  306. unitinits.insert(Tai_symbol.Createname_global('INITFINAL',AT_DATA,0));
  307. unitinits.insert(Tai_align.Create(const_align(4)));
  308. unitinits.concat(Tai_symbol_end.Createname('INITFINAL'));
  309. { insert in data segment }
  310. if (cs_create_smart in aktmoduleswitches) then
  311. dataSegment.concat(Tai_cut.Create);
  312. dataSegment.concatlist(unitinits);
  313. unitinits.free;
  314. end;
  315. procedure insertheap;
  316. begin
  317. if (cs_create_smart in aktmoduleswitches) then
  318. begin
  319. bssSegment.concat(Tai_cut.Create);
  320. dataSegment.concat(Tai_cut.Create);
  321. end;
  322. { On the Macintosh Classic M68k Architecture
  323. The Heap variable is simply a POINTER to the
  324. real HEAP. The HEAP must be set up by the RTL
  325. and must store the pointer in this value.
  326. On OS/2 the heap is also intialized by the RTL. We do
  327. not output a pointer }
  328. case target_info.system of
  329. system_i386_OS2:
  330. bssSegment.concat(Tai_datablock.Create_global('HEAP',4));
  331. system_i386_EMX:
  332. ;
  333. system_powerpc_macos:
  334. ;
  335. system_i386_watcom:
  336. ;
  337. system_alpha_linux:
  338. ;
  339. system_m68k_Mac:
  340. bssSegment.concat(Tai_datablock.Create_global('HEAP',4));
  341. system_m68k_PalmOS:
  342. ;
  343. else
  344. begin
  345. bssSegment.concat(Tai_align.Create(var_align(heapsize)));
  346. bssSegment.concat(Tai_datablock.Create_global('HEAP',heapsize));
  347. end;
  348. end;
  349. {$ifdef m68k}
  350. if target_info.system<>system_m68k_PalmOS then
  351. begin
  352. dataSegment.concat(Tai_align.Create(const_align(4)));
  353. dataSegment.concat(Tai_symbol.Createname_global('HEAPSIZE',AT_DATA,4));
  354. dataSegment.concat(Tai_const.Create_32bit(heapsize));
  355. end;
  356. {$else m68k}
  357. dataSegment.concat(Tai_align.Create(const_align(4)));
  358. dataSegment.concat(Tai_symbol.Createname_global('HEAPSIZE',AT_DATA,4));
  359. dataSegment.concat(Tai_const.Create_32bit(heapsize));
  360. {$endif m68k}
  361. end;
  362. procedure insertstacklength;
  363. begin
  364. { stacksize can be specified and is now simulated }
  365. dataSegment.concat(Tai_align.Create(const_align(4)));
  366. dataSegment.concat(Tai_symbol.Createname_global('__stklen',AT_DATA,4));
  367. dataSegment.concat(Tai_const.Create_32bit(stacksize));
  368. end;
  369. procedure loaddefaultunits;
  370. procedure AddUnit(const s:string);
  371. var
  372. hp : tppumodule;
  373. unitsym : tunitsym;
  374. begin
  375. { load unit }
  376. hp:=registerunit(current_module,s,'');
  377. hp.loadppu;
  378. hp.adddependency(current_module);
  379. { add to symtable stack }
  380. tsymtable(hp.globalsymtable).next:=symtablestack;
  381. symtablestack:=hp.globalsymtable;
  382. { insert unitsym }
  383. unitsym:=tunitsym.create(s,hp.globalsymtable);
  384. inc(unitsym.refs);
  385. refsymtable.insert(unitsym);
  386. { add to used units }
  387. current_module.addusedunit(hp,false,unitsym);
  388. end;
  389. begin
  390. { are we compiling the system unit? }
  391. if (cs_compilesystem in aktmoduleswitches) then
  392. begin
  393. { create system defines }
  394. createconstdefs;
  395. { we don't need to reset anything, it's already done in parser.pas }
  396. exit;
  397. end;
  398. { insert the system unit, it is allways the first }
  399. Symtablestack:=nil;
  400. AddUnit('System');
  401. SystemUnit:=TGlobalSymtable(Symtablestack);
  402. { read default constant definitions }
  403. make_ref:=false;
  404. readconstdefs;
  405. make_ref:=true;
  406. {$ifdef cpufpemu}
  407. { Floating point emulation unit? }
  408. if (cs_fp_emulation in aktmoduleswitches) then
  409. AddUnit('SoftFpu');
  410. {$endif cpufpemu}
  411. { Thread support unit? }
  412. if (cs_threading in aktmoduleswitches) then
  413. AddUnit('SysThrds');
  414. { Objpas unit? }
  415. if m_objpas in aktmodeswitches then
  416. AddUnit('ObjPas');
  417. { Profile unit? Needed for go32v2 only }
  418. if (cs_profile in aktmoduleswitches) and
  419. (target_info.system in [system_i386_go32v2,system_i386_watcom]) then
  420. AddUnit('Profile');
  421. { Units only required for main module }
  422. if not(current_module.is_unit) then
  423. begin
  424. { Heaptrc unit }
  425. if (cs_gdb_heaptrc in aktglobalswitches) then
  426. AddUnit('HeapTrc');
  427. { Lineinfo unit }
  428. if (cs_gdb_lineinfo in aktglobalswitches) then
  429. AddUnit('LineInfo');
  430. { Lineinfo unit }
  431. if (cs_gdb_valgrind in aktglobalswitches) then
  432. AddUnit('CMem');
  433. end;
  434. { save default symtablestack }
  435. defaultsymtablestack:=symtablestack;
  436. end;
  437. procedure loadunits;
  438. var
  439. s,sorg : stringid;
  440. fn : string;
  441. pu : tused_unit;
  442. hp2 : tmodule;
  443. hp3 : tsymtable;
  444. unitsym : tunitsym;
  445. begin
  446. consume(_USES);
  447. {$ifdef DEBUG}
  448. test_symtablestack;
  449. {$endif DEBUG}
  450. repeat
  451. s:=pattern;
  452. sorg:=orgpattern;
  453. consume(_ID);
  454. { support "<unit> in '<file>'" construct, but not for tp7 }
  455. if not(m_tp7 in aktmodeswitches) then
  456. begin
  457. if try_to_consume(_OP_IN) then
  458. fn:=FixFileName(get_stringconst)
  459. else
  460. fn:='';
  461. end;
  462. { Give a warning if objpas is loaded }
  463. if s='OBJPAS' then
  464. Message(parser_w_no_objpas_use_mode);
  465. { Using the unit itself is not possible }
  466. if (s<>current_module.modulename^) then
  467. begin
  468. { check if the unit is already used }
  469. hp2:=nil;
  470. pu:=tused_unit(current_module.used_units.first);
  471. while assigned(pu) do
  472. begin
  473. if (pu.u.modulename^=s) then
  474. begin
  475. hp2:=pu.u;
  476. break;
  477. end;
  478. pu:=tused_unit(pu.next);
  479. end;
  480. if not assigned(hp2) then
  481. hp2:=registerunit(current_module,sorg,fn)
  482. else
  483. Message1(sym_e_duplicate_id,s);
  484. { Create unitsym, we need to use the name as specified, we
  485. can not use the modulename because that can be different
  486. when -Un is used }
  487. unitsym:=tunitsym.create(sorg,nil);
  488. refsymtable.insert(unitsym);
  489. { the current module uses the unit hp2 }
  490. current_module.addusedunit(hp2,true,unitsym);
  491. end
  492. else
  493. Message1(sym_e_duplicate_id,s);
  494. if token=_COMMA then
  495. begin
  496. pattern:='';
  497. consume(_COMMA);
  498. end
  499. else
  500. break;
  501. until false;
  502. consume(_SEMICOLON);
  503. { Load the units }
  504. pu:=tused_unit(current_module.used_units.first);
  505. while assigned(pu) do
  506. begin
  507. { Only load the units that are in the current
  508. (interface/implementation) uses clause }
  509. if pu.in_uses and
  510. (pu.in_interface=current_module.in_interface) then
  511. begin
  512. tppumodule(pu.u).loadppu;
  513. { is our module compiled? then we can stop }
  514. if current_module.state=ms_compiled then
  515. exit;
  516. { add this unit to the dependencies }
  517. pu.u.adddependency(current_module);
  518. { save crc values }
  519. pu.checksum:=pu.u.crc;
  520. pu.interface_checksum:=pu.u.interface_crc;
  521. { connect unitsym to the globalsymtable of the unit }
  522. pu.unitsym.unitsymtable:=pu.u.globalsymtable;
  523. { increase refs of the unitsym when the unit contains
  524. initialization/finalization code so it doesn't trigger
  525. the unit not used hint }
  526. if (pu.u.flags and (uf_init or uf_finalize))<>0 then
  527. inc(pu.unitsym.refs);
  528. end;
  529. pu:=tused_unit(pu.next);
  530. end;
  531. { set the symtable to systemunit so it gets reorderd correctly,
  532. then insert the units in the symtablestack }
  533. pu:=tused_unit(current_module.used_units.first);
  534. symtablestack:=defaultsymtablestack;
  535. while assigned(pu) do
  536. begin
  537. if pu.in_uses then
  538. begin
  539. { Reinsert in symtablestack }
  540. hp3:=symtablestack;
  541. while assigned(hp3) do
  542. begin
  543. { insert units only once ! }
  544. if pu.u.globalsymtable=hp3 then
  545. break;
  546. hp3:=hp3.next;
  547. { unit isn't inserted }
  548. if hp3=nil then
  549. begin
  550. tsymtable(pu.u.globalsymtable).next:=symtablestack;
  551. symtablestack:=tsymtable(pu.u.globalsymtable);
  552. {$ifdef DEBUG}
  553. test_symtablestack;
  554. {$endif DEBUG}
  555. end;
  556. end;
  557. end;
  558. pu:=tused_unit(pu.next);
  559. end;
  560. end;
  561. {$IfDef GDB}
  562. procedure write_gdb_info;
  563. procedure reset_unit_type_info;
  564. var
  565. hp : tmodule;
  566. begin
  567. hp:=tmodule(loaded_units.first);
  568. while assigned(hp) do
  569. begin
  570. hp.is_stab_written:=false;
  571. hp:=tmodule(hp.next);
  572. end;
  573. end;
  574. procedure write_used_unit_type_info(hp:tmodule);
  575. var
  576. pu : tused_unit;
  577. begin
  578. pu:=tused_unit(hp.used_units.first);
  579. while assigned(pu) do
  580. begin
  581. if not pu.u.is_stab_written then
  582. begin
  583. { prevent infinte loop for circular dependencies }
  584. pu.u.is_stab_written:=true;
  585. { write type info from used units, use a depth first
  586. strategy to reduce the recursion in writing all
  587. dependent stabs }
  588. write_used_unit_type_info(pu.u);
  589. if assigned(pu.u.globalsymtable) then
  590. tglobalsymtable(pu.u.globalsymtable).concattypestabto(debuglist);
  591. end;
  592. pu:=tused_unit(pu.next);
  593. end;
  594. end;
  595. begin
  596. if not (cs_debuginfo in aktmoduleswitches) then
  597. exit;
  598. { reset unit type info flag }
  599. reset_unit_type_info;
  600. { write used types from the used units }
  601. write_used_unit_type_info(current_module);
  602. { first write the types from this unit }
  603. if assigned(current_module.globalsymtable) then
  604. begin
  605. { all types }
  606. tglobalsymtable(current_module.globalsymtable).concattypestabto(debuglist);
  607. { and all local symbols}
  608. tglobalsymtable(current_module.globalsymtable).concatstabto(debuglist);
  609. end;
  610. if assigned(current_module.localsymtable) then
  611. begin
  612. { all types }
  613. tstaticsymtable(current_module.localsymtable).concattypestabto(debuglist);
  614. { and all local symbols}
  615. tstaticsymtable(current_module.localsymtable).concatstabto(debuglist);
  616. end;
  617. if (cs_gdb_dbx in aktglobalswitches) then
  618. begin
  619. debugList.concat(tai_comment.Create(strpnew('EINCL of global '+
  620. tglobalsymtable(current_module.globalsymtable).name^+' has index '+
  621. tostr(tglobalsymtable(current_module.globalsymtable).unitid))));
  622. debugList.concat(Tai_stabs.Create(strpnew('"'+
  623. tglobalsymtable(current_module.globalsymtable).name^+'",'+
  624. tostr(N_EINCL)+',0,0,0')));
  625. tglobalsymtable(current_module.globalsymtable).dbx_count_ok:={true}false;
  626. dbx_counter:=tglobalsymtable(current_module.globalsymtable).prev_dbx_counter;
  627. do_count_dbx:=false;
  628. end;
  629. end;
  630. {$EndIf GDB}
  631. procedure reset_all_defs;
  632. procedure reset_used_unit_defs(hp:tmodule);
  633. var
  634. pu : tused_unit;
  635. begin
  636. pu:=tused_unit(hp.used_units.first);
  637. while assigned(pu) do
  638. begin
  639. if not pu.u.is_reset then
  640. begin
  641. { prevent infinte loop for circular dependencies }
  642. pu.u.is_reset:=true;
  643. if assigned(pu.u.globalsymtable) then
  644. begin
  645. tglobalsymtable(pu.u.globalsymtable).reset_all_defs;
  646. reset_used_unit_defs(pu.u);
  647. end;
  648. end;
  649. pu:=tused_unit(pu.next);
  650. end;
  651. end;
  652. var
  653. hp2 : tmodule;
  654. begin
  655. hp2:=tmodule(loaded_units.first);
  656. while assigned(hp2) do
  657. begin
  658. hp2.is_reset:=false;
  659. hp2:=tmodule(hp2.next);
  660. end;
  661. reset_used_unit_defs(current_module);
  662. end;
  663. procedure parse_implementation_uses;
  664. begin
  665. if token=_USES then
  666. begin
  667. loadunits;
  668. {$ifdef DEBUG}
  669. test_symtablestack;
  670. {$endif DEBUG}
  671. end;
  672. end;
  673. procedure setupglobalswitches;
  674. begin
  675. { can't have local browser when no global browser }
  676. if (cs_local_browser in aktmoduleswitches) and
  677. not(cs_browser in aktmoduleswitches) then
  678. exclude(aktmoduleswitches,cs_local_browser);
  679. { define a symbol in delphi,objfpc,tp,gpc mode }
  680. if (m_delphi in aktmodeswitches) then
  681. current_scanner.def_macro('FPC_DELPHI')
  682. else
  683. if (m_tp7 in aktmodeswitches) then
  684. current_scanner.def_macro('FPC_TP')
  685. else
  686. if (m_objfpc in aktmodeswitches) then
  687. current_scanner.def_macro('FPC_OBJFPC')
  688. else
  689. if (m_gpc in aktmodeswitches) then
  690. current_scanner.def_macro('FPC_GPC');
  691. end;
  692. function create_main_proc(const name:string;potype:tproctypeoption;st:tsymtable):tprocdef;
  693. var
  694. stt : tsymtable;
  695. ps : tprocsym;
  696. pd : tprocdef;
  697. begin
  698. { there should be no current_procinfo available }
  699. if assigned(current_procinfo) then
  700. internalerror(200304275);
  701. {Generate a procsym for main}
  702. make_ref:=false;
  703. { try to insert in in static symtable ! }
  704. stt:=symtablestack;
  705. symtablestack:=st;
  706. { generate procsym }
  707. ps:=tprocsym.create('$'+name);
  708. { main are allways used }
  709. inc(ps.refs);
  710. symtablestack.insert(ps);
  711. pd:=tprocdef.create(main_program_level);
  712. include(pd.procoptions,po_public);
  713. pd.procsym:=ps;
  714. ps.addprocdef(pd);
  715. { restore symtable }
  716. make_ref:=true;
  717. symtablestack:=stt;
  718. { set procdef options }
  719. pd.proctypeoption:=potype;
  720. pd.proccalloption:=pocall_default;
  721. pd.forwarddef:=false;
  722. pd.setmangledname(target_info.cprefix+name);
  723. pd.aliasnames.insert(pd.mangledname);
  724. { We don't need is a local symtable. Change it into the static
  725. symtable }
  726. pd.localst.free;
  727. pd.localst:=st;
  728. { set procinfo and current_procinfo.procdef }
  729. current_procinfo:=cprocinfo.create(nil);
  730. current_module.procinfo:=current_procinfo;
  731. current_procinfo.procdef:=pd;
  732. { return procdef }
  733. create_main_proc:=pd;
  734. { main proc does always a call e.g. to init system unit }
  735. include(current_procinfo.flags,pi_do_call);
  736. end;
  737. procedure release_main_proc(pd:tprocdef);
  738. begin
  739. { this is a main proc, so there should be no parent }
  740. if not(assigned(current_procinfo)) or
  741. assigned(current_procinfo.parent) or
  742. not(current_procinfo.procdef=pd) then
  743. internalerror(200304276);
  744. { remove procinfo }
  745. current_module.procinfo:=nil;
  746. current_procinfo.free;
  747. current_procinfo:=nil;
  748. { remove localst as it was replaced by staticsymtable }
  749. pd.localst:=nil;
  750. end;
  751. procedure gen_implicit_initfinal(flag:word;st:tsymtable);
  752. var
  753. pd : tprocdef;
  754. begin
  755. { update module flags }
  756. current_module.flags:=current_module.flags or flag;
  757. { create procdef }
  758. case flag of
  759. uf_init :
  760. begin
  761. pd:=create_main_proc(make_mangledname('',current_module.localsymtable,'init_implicit'),potype_unitinit,st);
  762. pd.aliasnames.insert(make_mangledname('INIT$',current_module.localsymtable,''));
  763. end;
  764. uf_finalize :
  765. begin
  766. pd:=create_main_proc(make_mangledname('',current_module.localsymtable,'finalize_implicit'),potype_unitfinalize,st);
  767. pd.aliasnames.insert(make_mangledname('FINALIZE$',current_module.localsymtable,''));
  768. end;
  769. else
  770. internalerror(200304253);
  771. end;
  772. tcgprocinfo(current_procinfo).code:=cnothingnode.create;
  773. tcgprocinfo(current_procinfo).add_entry_exit_code;
  774. tcgprocinfo(current_procinfo).generate_code;
  775. release_main_proc(pd);
  776. end;
  777. procedure proc_unit;
  778. function is_assembler_generated:boolean;
  779. begin
  780. is_assembler_generated:=(Errorcount=0) and
  781. not(
  782. codeSegment.empty and
  783. dataSegment.empty and
  784. bssSegment.empty and
  785. ((importssection=nil) or importsSection.empty) and
  786. ((resourcesection=nil) or resourceSection.empty) and
  787. ((resourcestringlist=nil) or resourcestringList.empty)
  788. );
  789. end;
  790. var
  791. main_file: tinputfile;
  792. st : tsymtable;
  793. unitst : tglobalsymtable;
  794. store_crc,store_interface_crc : cardinal;
  795. s1,s2 : ^string; {Saves stack space}
  796. force_init_final : boolean;
  797. pd : tprocdef;
  798. unitname8 : string[8];
  799. begin
  800. consume(_UNIT);
  801. if compile_level=1 then
  802. Status.IsExe:=false;
  803. if token=_ID then
  804. begin
  805. { create filenames and unit name }
  806. main_file := current_scanner.inputfile;
  807. while assigned(main_file.next) do
  808. main_file := main_file.next;
  809. new(s1);
  810. s1^:=current_module.modulename^;
  811. current_module.SetFileName(main_file.path^+main_file.name^,true);
  812. current_module.SetModuleName(orgpattern);
  813. { check for system unit }
  814. new(s2);
  815. s2^:=upper(SplitName(main_file.name^));
  816. unitname8:=copy(current_module.modulename^,1,8);
  817. if (cs_check_unit_name in aktglobalswitches) and
  818. (
  819. not(
  820. (current_module.modulename^=s2^) or
  821. (
  822. (length(current_module.modulename^)>8) and
  823. (unitname8=s2^)
  824. )
  825. )
  826. or
  827. (
  828. (length(s1^)>8) and
  829. (s1^<>current_module.modulename^)
  830. )
  831. ) then
  832. Message1(unit_e_illegal_unit_name,current_module.realmodulename^);
  833. if (current_module.modulename^='SYSTEM') then
  834. include(aktmoduleswitches,cs_compilesystem);
  835. dispose(s2);
  836. dispose(s1);
  837. end;
  838. consume(_ID);
  839. consume(_SEMICOLON);
  840. consume(_INTERFACE);
  841. { global switches are read, so further changes aren't allowed }
  842. current_module.in_global:=false;
  843. { handle the global switches }
  844. setupglobalswitches;
  845. message1(unit_u_loading_interface_units,current_module.modulename^);
  846. { update status }
  847. status.currentmodule:=current_module.realmodulename^;
  848. { maybe turn off m_objpas if we are compiling objpas }
  849. if (current_module.modulename^='OBJPAS') then
  850. exclude(aktmodeswitches,m_objpas);
  851. parse_only:=true;
  852. { generate now the global symboltable }
  853. st:=tglobalsymtable.create(current_module.modulename^);
  854. refsymtable:=st;
  855. unitst:=tglobalsymtable(st);
  856. { define first as local to overcome dependency conflicts }
  857. current_module.localsymtable:=st;
  858. { the unit name must be usable as a unit specifier }
  859. { inside the unit itself (PM) }
  860. { this also forbids to have another symbol }
  861. { with the same name as the unit }
  862. refsymtable.insert(tunitsym.create(current_module.realmodulename^,unitst));
  863. { load default units, like the system unit }
  864. loaddefaultunits;
  865. { reset }
  866. make_ref:=true;
  867. { insert qualifier for the system unit (allows system.writeln) }
  868. if not(cs_compilesystem in aktmoduleswitches) then
  869. begin
  870. if token=_USES then
  871. begin
  872. loadunits;
  873. { has it been compiled at a higher level ?}
  874. if current_module.state=ms_compiled then
  875. exit;
  876. end;
  877. { ... but insert the symbol table later }
  878. st.next:=symtablestack;
  879. symtablestack:=st;
  880. end
  881. else
  882. { while compiling a system unit, some types are directly inserted }
  883. begin
  884. st.next:=symtablestack;
  885. symtablestack:=st;
  886. insert_intern_types(st);
  887. end;
  888. { now we know the place to insert the constants }
  889. constsymtable:=symtablestack;
  890. { move the global symtab from the temporary local to global }
  891. current_module.globalsymtable:=current_module.localsymtable;
  892. current_module.localsymtable:=nil;
  893. reset_all_defs;
  894. { number all units, so we know if a unit is used by this unit or
  895. needs to be added implicitly }
  896. current_module.numberunits;
  897. { ... parse the declarations }
  898. Message1(parser_u_parsing_interface,current_module.realmodulename^);
  899. read_interface_declarations;
  900. { leave when we got an error }
  901. if (Errorcount>0) and not status.skip_error then
  902. begin
  903. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  904. status.skip_error:=true;
  905. exit;
  906. end;
  907. { Our interface is compiled, generate CRC and switch to implementation }
  908. if not(cs_compilesystem in aktmoduleswitches) and
  909. (Errorcount=0) then
  910. tppumodule(current_module).getppucrc;
  911. current_module.in_interface:=false;
  912. current_module.interface_compiled:=true;
  913. { First reload all units depending on our interface, we need to do this
  914. in the implementation part to prevent errorneous circular references }
  915. reload_flagged_units;
  916. { Parse the implementation section }
  917. consume(_IMPLEMENTATION);
  918. Message1(unit_u_loading_implementation_units,current_module.modulename^);
  919. parse_only:=false;
  920. { generates static symbol table }
  921. st:=tstaticsymtable.create(current_module.modulename^);
  922. current_module.localsymtable:=st;
  923. { remove the globalsymtable from the symtable stack }
  924. { to reinsert it after loading the implementation units }
  925. symtablestack:=unitst.next;
  926. { we don't want implementation units symbols in unitsymtable !! PM }
  927. refsymtable:=st;
  928. { Read the implementation units }
  929. parse_implementation_uses;
  930. if current_module.state=ms_compiled then
  931. exit;
  932. { reset ranges/stabs in exported definitions }
  933. reset_all_defs;
  934. { All units are read, now give them a number }
  935. current_module.numberunits;
  936. { now we can change refsymtable }
  937. refsymtable:=st;
  938. { but reinsert the global symtable as lasts }
  939. unitst.next:=symtablestack;
  940. symtablestack:=unitst;
  941. {$ifdef DEBUG}
  942. test_symtablestack;
  943. {$endif DEBUG}
  944. constsymtable:=symtablestack;
  945. {$ifdef Splitheap}
  946. if testsplit then
  947. begin
  948. Split_Heap;
  949. allow_special:=true;
  950. Switch_to_temp_heap;
  951. end;
  952. { it will report all crossings }
  953. allow_special:=false;
  954. {$endif Splitheap}
  955. Message1(parser_u_parsing_implementation,current_module.modulename^);
  956. if current_module.in_interface then
  957. internalerror(200212285);
  958. { Compile the unit }
  959. pd:=create_main_proc(make_mangledname('',current_module.localsymtable,'init'),potype_unitinit,st);
  960. pd.aliasnames.insert(make_mangledname('INIT$',current_module.localsymtable,''));
  961. tcgprocinfo(current_procinfo).parse_body;
  962. tcgprocinfo(current_procinfo).generate_code;
  963. tcgprocinfo(current_procinfo).resetprocdef;
  964. release_main_proc(pd);
  965. { if the unit contains ansi/widestrings, initialization and
  966. finalization code must be forced }
  967. force_init_final:=tglobalsymtable(current_module.globalsymtable).needs_init_final or
  968. tstaticsymtable(current_module.localsymtable).needs_init_final;
  969. { should we force unit initialization? }
  970. { this is a hack, but how can it be done better ? }
  971. if force_init_final and ((current_module.flags and uf_init)=0) then
  972. gen_implicit_initfinal(uf_init,st);
  973. { finalize? }
  974. if token=_FINALIZATION then
  975. begin
  976. { set module options }
  977. current_module.flags:=current_module.flags or uf_finalize;
  978. { Compile the finalize }
  979. pd:=create_main_proc(make_mangledname('',current_module.localsymtable,'finalize'),potype_unitfinalize,st);
  980. pd.aliasnames.insert(make_mangledname('FINALIZE$',current_module.localsymtable,''));
  981. tcgprocinfo(current_procinfo).parse_body;
  982. tcgprocinfo(current_procinfo).generate_code;
  983. tcgprocinfo(current_procinfo).resetprocdef;
  984. release_main_proc(pd);
  985. end
  986. else if force_init_final then
  987. gen_implicit_initfinal(uf_finalize,st);
  988. { the last char should always be a point }
  989. consume(_POINT);
  990. { generate a list of threadvars }
  991. InsertThreadvars;
  992. { Generate resoucestrings }
  993. If ResourceStrings.ResStrCount>0 then
  994. begin
  995. ResourceStrings.CreateResourceStringList;
  996. current_module.flags:=current_module.flags or uf_has_resources;
  997. { only write if no errors found }
  998. if (Errorcount=0) then
  999. ResourceStrings.WriteResourceFile(ForceExtension(current_module.ppufilename^,'.rst'));
  1000. end;
  1001. if (Errorcount=0) then
  1002. begin
  1003. { test static symtable }
  1004. tstoredsymtable(st).allsymbolsused;
  1005. tstoredsymtable(st).allprivatesused;
  1006. current_module.allunitsused;
  1007. end;
  1008. {$ifdef GDB}
  1009. write_gdb_info;
  1010. {$endif GDB}
  1011. if (Errorcount=0) then
  1012. begin
  1013. { tests, if all (interface) forwards are resolved }
  1014. tstoredsymtable(symtablestack).check_forwards;
  1015. { check if all private fields are used }
  1016. tstoredsymtable(symtablestack).allprivatesused;
  1017. { remove cross unit overloads }
  1018. tstoredsymtable(symtablestack).unchain_overloaded;
  1019. end;
  1020. { leave when we got an error }
  1021. if (Errorcount>0) and not status.skip_error then
  1022. begin
  1023. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  1024. status.skip_error:=true;
  1025. exit;
  1026. end;
  1027. { generate imports }
  1028. if current_module.uses_imports then
  1029. importlib.generatelib;
  1030. { insert own objectfile, or say that it's in a library
  1031. (no check for an .o when loading) }
  1032. if is_assembler_generated then
  1033. insertobjectfile
  1034. else
  1035. current_module.flags:=current_module.flags or uf_no_link;
  1036. if cs_local_browser in aktmoduleswitches then
  1037. current_module.localsymtable:=refsymtable;
  1038. if is_assembler_generated then
  1039. begin
  1040. { finish asmlist by adding segment starts }
  1041. insertsegment;
  1042. { assemble }
  1043. create_objectfile;
  1044. end;
  1045. { Write out the ppufile after the object file has been created }
  1046. store_interface_crc:=current_module.interface_crc;
  1047. store_crc:=current_module.crc;
  1048. if (Errorcount=0) then
  1049. tppumodule(current_module).writeppu;
  1050. if not(cs_compilesystem in aktmoduleswitches) then
  1051. if store_interface_crc<>current_module.interface_crc then
  1052. Message1(unit_u_interface_crc_changed,current_module.ppufilename^);
  1053. {$ifdef EXTDEBUG}
  1054. if not(cs_compilesystem in aktmoduleswitches) then
  1055. if (store_crc<>current_module.crc) and simplify_ppu then
  1056. Message1(unit_u_implementation_crc_changed,current_module.ppufilename^);
  1057. {$endif EXTDEBUG}
  1058. { remove static symtable (=refsymtable) here to save some mem }
  1059. if not (cs_local_browser in aktmoduleswitches) then
  1060. begin
  1061. st.free;
  1062. current_module.localsymtable:=nil;
  1063. end;
  1064. { leave when we got an error }
  1065. if (Errorcount>0) and not status.skip_error then
  1066. begin
  1067. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  1068. status.skip_error:=true;
  1069. exit;
  1070. end;
  1071. Message1(unit_u_finished_compiling,current_module.modulename^);
  1072. end;
  1073. procedure proc_program(islibrary : boolean);
  1074. var
  1075. main_file: tinputfile;
  1076. st : tsymtable;
  1077. hp : tmodule;
  1078. pd : tprocdef;
  1079. begin
  1080. DLLsource:=islibrary;
  1081. Status.IsLibrary:=IsLibrary;
  1082. Status.IsExe:=true;
  1083. parse_only:=false;
  1084. { relocation works only without stabs under win32 !! PM }
  1085. { internal assembler uses rva for stabs info
  1086. so it should work with relocated DLLs }
  1087. if RelocSection and
  1088. (target_info.system in [system_i386_win32,system_i386_wdosx]) and
  1089. (target_info.assem<>as_i386_pecoff) then
  1090. begin
  1091. include(aktglobalswitches,cs_link_strip);
  1092. { Warning stabs info does not work with reloc section !! }
  1093. if cs_debuginfo in aktmoduleswitches then
  1094. begin
  1095. Message1(parser_w_parser_reloc_no_debug,current_module.mainsource^);
  1096. Message(parser_w_parser_win32_debug_needs_WN);
  1097. exclude(aktmoduleswitches,cs_debuginfo);
  1098. end;
  1099. end;
  1100. { get correct output names }
  1101. main_file := current_scanner.inputfile;
  1102. while assigned(main_file.next) do
  1103. main_file := main_file.next;
  1104. current_module.SetFileName(main_file.path^+main_file.name^,true);
  1105. if islibrary then
  1106. begin
  1107. consume(_LIBRARY);
  1108. stringdispose(current_module.modulename);
  1109. current_module.modulename:=stringdup(pattern);
  1110. current_module.islibrary:=true;
  1111. exportlib.preparelib(pattern);
  1112. consume(_ID);
  1113. consume(_SEMICOLON);
  1114. end
  1115. else
  1116. { is there an program head ? }
  1117. if token=_PROGRAM then
  1118. begin
  1119. consume(_PROGRAM);
  1120. stringdispose(current_module.modulename);
  1121. stringdispose(current_module.realmodulename);
  1122. current_module.modulename:=stringdup(pattern);
  1123. current_module.realmodulename:=stringdup(orgpattern);
  1124. if (target_info.system in [system_i386_WIN32,system_i386_wdosx]) then
  1125. exportlib.preparelib(pattern);
  1126. consume(_ID);
  1127. if token=_LKLAMMER then
  1128. begin
  1129. consume(_LKLAMMER);
  1130. repeat
  1131. consume(_ID);
  1132. until not try_to_consume(_COMMA);
  1133. consume(_RKLAMMER);
  1134. end;
  1135. consume(_SEMICOLON);
  1136. end
  1137. else if (target_info.system in [system_i386_WIN32,system_i386_wdosx]) then
  1138. exportlib.preparelib(current_module.modulename^);
  1139. { global switches are read, so further changes aren't allowed }
  1140. current_module.in_global:=false;
  1141. { setup things using the global switches }
  1142. setupglobalswitches;
  1143. { set implementation flag }
  1144. current_module.in_interface:=false;
  1145. current_module.interface_compiled:=true;
  1146. { insert after the unit symbol tables the static symbol table }
  1147. { of the program }
  1148. st:=tstaticsymtable.create(current_module.modulename^);;
  1149. current_module.localsymtable:=st;
  1150. refsymtable:=st;
  1151. { load standard units (system,objpas,profile unit) }
  1152. loaddefaultunits;
  1153. {Load the units used by the program we compile.}
  1154. if token=_USES then
  1155. loadunits;
  1156. { reset ranges/stabs in exported definitions }
  1157. reset_all_defs;
  1158. { All units are read, now give them a number }
  1159. current_module.numberunits;
  1160. {Insert the name of the main program into the symbol table.}
  1161. if current_module.realmodulename^<>'' then
  1162. st.insert(tunitsym.create(current_module.realmodulename^,st));
  1163. { ...is also constsymtable, this is the symtable where }
  1164. { the elements of enumeration types are inserted }
  1165. constsymtable:=st;
  1166. Message1(parser_u_parsing_implementation,current_module.mainsource^);
  1167. { The program intialization needs an alias, so it can be called
  1168. from the bootstrap code.}
  1169. if islibrary or
  1170. (target_info.system in [system_powerpc_macos,system_powerpc_darwin]) then
  1171. begin
  1172. pd:=create_main_proc(make_mangledname('',current_module.localsymtable,'main'),potype_proginit,st);
  1173. { Win32 startup code needs a single name }
  1174. // if (target_info.system in [system_i386_win32,system_i386_wdosx]) then
  1175. pd.aliasnames.insert('PASCALMAIN');
  1176. end
  1177. else
  1178. begin
  1179. pd:=create_main_proc('main',potype_proginit,st);
  1180. pd.aliasnames.insert('PASCALMAIN');
  1181. end;
  1182. tcgprocinfo(current_procinfo).parse_body;
  1183. tcgprocinfo(current_procinfo).generate_code;
  1184. tcgprocinfo(current_procinfo).resetprocdef;
  1185. release_main_proc(pd);
  1186. { should we force unit initialization? }
  1187. if tstaticsymtable(current_module.localsymtable).needs_init_final then
  1188. begin
  1189. { initialize section }
  1190. gen_implicit_initfinal(uf_init,st);
  1191. { finalize section }
  1192. gen_implicit_initfinal(uf_finalize,st);
  1193. end;
  1194. { Add symbol to the exports section for win32 so smartlinking a
  1195. DLL will include the edata section }
  1196. if assigned(exportlib) and
  1197. (target_info.system in [system_i386_win32,system_i386_wdosx]) and
  1198. assigned(current_module._exports.first) then
  1199. codesegment.concat(tai_const_symbol.create(exportlib.edatalabel));
  1200. If ResourceStrings.ResStrCount>0 then
  1201. begin
  1202. ResourceStrings.CreateResourceStringList;
  1203. { only write if no errors found }
  1204. if (Errorcount=0) then
  1205. ResourceStrings.WriteResourceFile(ForceExtension(current_module.ppufilename^,'.rst'));
  1206. end;
  1207. { finalize? }
  1208. if token=_FINALIZATION then
  1209. begin
  1210. { set module options }
  1211. current_module.flags:=current_module.flags or uf_finalize;
  1212. { Compile the finalize }
  1213. pd:=create_main_proc(make_mangledname('',current_module.localsymtable,'finalize'),potype_unitfinalize,st);
  1214. pd.aliasnames.insert(make_mangledname('FINALIZE$',current_module.localsymtable,''));
  1215. tcgprocinfo(current_procinfo).parse_body;
  1216. tcgprocinfo(current_procinfo).generate_code;
  1217. tcgprocinfo(current_procinfo).resetprocdef;
  1218. release_main_proc(pd);
  1219. end;
  1220. { consume the last point }
  1221. consume(_POINT);
  1222. {$ifdef GDB}
  1223. write_gdb_info;
  1224. {$endif GDB}
  1225. { leave when we got an error }
  1226. if (Errorcount>0) and not status.skip_error then
  1227. begin
  1228. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  1229. status.skip_error:=true;
  1230. exit;
  1231. end;
  1232. if (Errorcount=0) then
  1233. begin
  1234. { test static symtable }
  1235. tstoredsymtable(st).allsymbolsused;
  1236. tstoredsymtable(st).allprivatesused;
  1237. current_module.allunitsused;
  1238. end;
  1239. { generate a list of threadvars }
  1240. InsertThreadvars;
  1241. { generate imports }
  1242. if current_module.uses_imports then
  1243. importlib.generatelib;
  1244. if islibrary or
  1245. (target_info.system in [system_i386_WIN32,system_i386_wdosx]) or
  1246. (target_info.system=system_i386_NETWARE) then
  1247. exportlib.generatelib;
  1248. { insert Tables and Heap }
  1249. insertThreadVarTablesTable;
  1250. insertResourceTablesTable;
  1251. insertinitfinaltable;
  1252. insertheap;
  1253. insertstacklength;
  1254. // datasize:=symtablestack.datasize;
  1255. { finish asmlist by adding segment starts }
  1256. insertsegment;
  1257. { insert own objectfile }
  1258. insertobjectfile;
  1259. { assemble and link }
  1260. create_objectfile;
  1261. { leave when we got an error }
  1262. if (Errorcount>0) and not status.skip_error then
  1263. begin
  1264. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  1265. status.skip_error:=true;
  1266. exit;
  1267. end;
  1268. { create the executable when we are at level 1 }
  1269. if (compile_level=1) then
  1270. begin
  1271. { insert all .o files from all loaded units }
  1272. hp:=tmodule(loaded_units.first);
  1273. while assigned(hp) do
  1274. begin
  1275. linker.AddModuleFiles(hp);
  1276. hp:=tmodule(hp.next);
  1277. end;
  1278. { write .def file }
  1279. if (cs_link_deffile in aktglobalswitches) then
  1280. deffile.writefile;
  1281. { finally we can create a executable }
  1282. if (not current_module.is_unit) then
  1283. begin
  1284. if DLLSource then
  1285. linker.MakeSharedLibrary
  1286. else
  1287. linker.MakeExecutable;
  1288. end;
  1289. end;
  1290. end;
  1291. end.
  1292. {
  1293. $Log$
  1294. Revision 1.148 2004-03-24 20:24:25 hajny
  1295. * OS/2 heap management modified to be able to grow heap as needed
  1296. Revision 1.147 2004/03/18 11:43:57 olle
  1297. * change AT_FUNCTION to AT_DATA where appropriate
  1298. Revision 1.146 2004/03/14 20:10:14 peter
  1299. * fix stabs lineno for fpc_compiled
  1300. Revision 1.145 2004/03/10 22:52:57 peter
  1301. * more stabs fixes
  1302. * special mode -gv for valgrind compatible stabs
  1303. Revision 1.144 2004/03/09 20:45:04 peter
  1304. * more stabs updates
  1305. Revision 1.143 2004/03/08 22:07:47 peter
  1306. * stabs updates to write stabs for def for all implictly used
  1307. units
  1308. Revision 1.142 2004/03/02 17:32:12 florian
  1309. * make cycle fixed
  1310. + pic support for darwin
  1311. + support of importing vars from shared libs on darwin implemented
  1312. Revision 1.141 2004/03/02 00:36:33 olle
  1313. * big transformation of Tai_[const_]Symbol.Create[data]name*
  1314. Revision 1.140 2004/02/26 16:16:38 peter
  1315. * tai_const.create_ptr added
  1316. Revision 1.139 2004/02/06 22:37:00 daniel
  1317. * Removed not very usefull nextglobal & previousglobal fields from
  1318. Tstoreddef, saving 78 kb of memory
  1319. Revision 1.138 2004/02/04 22:15:15 daniel
  1320. * Rtti generation moved to ncgutil
  1321. * Assmtai usage of symsym removed
  1322. * operator overloading cleanup up
  1323. Revision 1.137 2004/01/28 16:48:24 peter
  1324. use local string of 8 chars
  1325. Revision 1.136 2004/01/04 21:08:09 jonas
  1326. * Never generate a "main" symbol for PASCALMAIN for Darwin and classic
  1327. Mac OS, they use a C-main in their system unit
  1328. Revision 1.135 2003/12/12 19:42:21 peter
  1329. * check unit name when expected unitname > 8 chars
  1330. Revision 1.134 2003/12/08 22:33:43 peter
  1331. * don't allow duplicate uses
  1332. * fix wrong circular dependency
  1333. Revision 1.133 2003/11/29 20:13:25 florian
  1334. * fixed several pi_do_call problems
  1335. Revision 1.132 2003/10/29 19:48:51 peter
  1336. * renamed mangeldname_prefix to make_mangledname and made it more
  1337. generic
  1338. * make_mangledname is now also used for internal threadvar/resstring
  1339. lists
  1340. * Add P$ in front of program modulename to prevent duplicated symbols
  1341. at assembler level, because the main program can have the same name
  1342. as a unit, see webtbs/tw1251b
  1343. Revision 1.131 2003/10/24 17:40:23 peter
  1344. * cleanup of the entry and exit code insertion
  1345. Revision 1.130 2003/10/22 15:22:33 peter
  1346. * fixed unitsym-globalsymtable relation so the uses of a unit
  1347. is counted correctly
  1348. Revision 1.129 2003/10/21 15:14:33 peter
  1349. * fixed memleak for initfinalcode
  1350. * exit from generatecode when there are already errors
  1351. Revision 1.128 2003/10/01 20:34:49 peter
  1352. * procinfo unit contains tprocinfo
  1353. * cginfo renamed to cgbase
  1354. * moved cgmessage to verbose
  1355. * fixed ppc and sparc compiles
  1356. Revision 1.127 2003/09/30 08:39:50 michael
  1357. + Patch from Wiktor Sywula for watcom support
  1358. Revision 1.126 2003/09/23 18:03:08 peter
  1359. * add missing release of main_proc
  1360. Revision 1.125 2003/09/23 17:56:05 peter
  1361. * locals and paras are allocated in the code generation
  1362. * tvarsym.localloc contains the location of para/local when
  1363. generating code for the current procedure
  1364. Revision 1.124 2003/09/09 20:59:27 daniel
  1365. * Adding register allocation order
  1366. Revision 1.123 2003/09/09 15:55:44 peter
  1367. * use register with least interferences in spillregister
  1368. Revision 1.122 2003/09/07 22:09:35 peter
  1369. * preparations for different default calling conventions
  1370. * various RA fixes
  1371. Revision 1.121 2003/09/05 17:41:12 florian
  1372. * merged Wiktor's Watcom patches in 1.1
  1373. Revision 1.120 2003/08/23 22:29:24 peter
  1374. * reload flagged units when interface is loaded
  1375. Revision 1.119 2003/08/21 14:47:41 peter
  1376. * remove convert_registers
  1377. Revision 1.118 2003/08/20 17:48:49 peter
  1378. * fixed stackalloc to not allocate localst.datasize twice
  1379. * order of stackalloc code fixed for implicit init/final
  1380. Revision 1.117 2003/08/20 09:07:00 daniel
  1381. * New register coding now mandatory, some more convert_registers calls
  1382. removed.
  1383. Revision 1.116 2003/07/23 11:04:15 jonas
  1384. * split en_exit_code into a part that may allocate a register and a part
  1385. that doesn't, so the former can be done before the register colouring
  1386. has been performed
  1387. Revision 1.115 2003/07/06 17:58:22 peter
  1388. * framepointer fixes for sparc
  1389. * parent framepointer code more generic
  1390. Revision 1.114 2003/06/13 21:19:31 peter
  1391. * current_procdef removed, use current_procinfo.procdef instead
  1392. Revision 1.113 2003/06/09 12:23:30 peter
  1393. * init/final of procedure data splitted from genentrycode
  1394. * use asmnode getposition to insert final at the correct position
  1395. als for the implicit try...finally
  1396. Revision 1.112 2003/06/07 20:26:32 peter
  1397. * re-resolving added instead of reloading from ppu
  1398. * tderef object added to store deref info for resolving
  1399. Revision 1.111 2003/06/03 20:21:45 mazen
  1400. - removed unneeded ifdefs
  1401. - removed unneeded cases for sparc and x86_64
  1402. Revision 1.110 2003/06/03 13:01:59 daniel
  1403. * Register allocator finished
  1404. Revision 1.109 2003/05/26 21:17:17 peter
  1405. * procinlinenode removed
  1406. * aktexit2label removed, fast exit removed
  1407. + tcallnode.inlined_pass_2 added
  1408. Revision 1.108 2003/05/25 10:27:12 peter
  1409. * moved Comment calls to messge file
  1410. Revision 1.107 2003/05/22 21:31:35 peter
  1411. * defer codegeneration for nested procedures
  1412. Revision 1.106 2003/05/15 18:58:53 peter
  1413. * removed selfpointer_offset, vmtpointer_offset
  1414. * tvarsym.adjusted_address
  1415. * address in localsymtable is now in the real direction
  1416. * removed some obsolete globals
  1417. Revision 1.105 2003/05/11 19:31:28 florian
  1418. * fixed implicit init/final code for units, stack frame was wrong for ppc
  1419. Revision 1.104 2003/04/28 21:19:02 peter
  1420. * fix stabs generation for implicit initfinal
  1421. Revision 1.103 2003/04/27 11:21:34 peter
  1422. * aktprocdef renamed to current_procinfo.procdef
  1423. * procinfo renamed to current_procinfo
  1424. * procinfo will now be stored in current_module so it can be
  1425. cleaned up properly
  1426. * gen_main_procsym changed to create_main_proc and release_main_proc
  1427. to also generate a tprocinfo structure
  1428. * fixed unit implicit initfinal
  1429. Revision 1.102 2003/04/27 07:29:50 peter
  1430. * current_procinfo.procdef cleanup, current_procdef is now always nil when parsing
  1431. a new procdef declaration
  1432. * aktprocsym removed
  1433. * lexlevel removed, use symtable.symtablelevel instead
  1434. * implicit init/final code uses the normal genentry/genexit
  1435. * funcret state checking updated for new funcret handling
  1436. Revision 1.101 2003/04/23 12:35:34 florian
  1437. * fixed several issues with powerpc
  1438. + applied a patch from Jonas for nested function calls (PowerPC only)
  1439. * ...
  1440. Revision 1.100 2003/04/12 15:13:03 peter
  1441. * Use the original unitname when defining a unitsym
  1442. Revision 1.99 2003/03/23 23:21:42 hajny
  1443. + emx target added
  1444. Revision 1.98 2003/03/17 22:20:08 peter
  1445. *** empty log message ***
  1446. Revision 1.97 2003/03/17 13:36:39 peter
  1447. * fix import linking under linux
  1448. Revision 1.96 2003/02/19 22:00:14 daniel
  1449. * Code generator converted to new register notation
  1450. - Horribily outdated todo.txt removed
  1451. Revision 1.95 2003/02/06 22:36:55 mazen
  1452. * fixing bug related to errornous program main entry stack frame
  1453. Revision 1.94 2003/01/30 21:46:20 peter
  1454. * tai_const_symbol.createdataname added
  1455. Revision 1.93 2003/01/11 11:19:54 hajny
  1456. * correction from rev. 1.88 put back
  1457. Revision 1.92 2003/01/08 18:43:56 daniel
  1458. * Tregister changed into a record
  1459. Revision 1.91 2003/01/05 13:36:53 florian
  1460. * x86-64 compiles
  1461. + very basic support for float128 type (x86-64 only)
  1462. Revision 1.90 2002/12/29 18:17:23 peter
  1463. * insert unitsym with the name as specified in the uses list
  1464. Revision 1.89 2002/12/29 14:57:50 peter
  1465. * unit loading changed to first register units and load them
  1466. afterwards. This is needed to support uses xxx in yyy correctly
  1467. * unit dependency check fixed
  1468. Revision 1.88 2002/12/27 19:09:33 hajny
  1469. * another (hopefully final ;-) ) fix for not linked import libraries for units with no code
  1470. Revision 1.87 2002/12/24 23:32:56 peter
  1471. * Use FixFilename for specified unit sourcefile in uses
  1472. Revision 1.86 2002/12/06 16:56:58 peter
  1473. * only compile cs_fp_emulation support when cpufpuemu is defined
  1474. * define cpufpuemu for m68k only
  1475. Revision 1.85 2002/11/30 21:32:24 carl
  1476. + Add loading of softfpu in emulation mode
  1477. + Correct routine call for softfpu
  1478. * Extended type must also be defined even with softfpu
  1479. Revision 1.84 2002/11/15 01:58:53 peter
  1480. * merged changes from 1.0.7 up to 04-11
  1481. - -V option for generating bug report tracing
  1482. - more tracing for option parsing
  1483. - errors for cdecl and high()
  1484. - win32 import stabs
  1485. - win32 records<=8 are returned in eax:edx (turned off by default)
  1486. - heaptrc update
  1487. - more info for temp management in .s file with EXTDEBUG
  1488. Revision 1.83 2002/11/09 15:33:26 carl
  1489. * major alignment updates
  1490. Revision 1.82 2002/10/16 06:32:52 michael
  1491. + Renamed thread unit to systhrds
  1492. Revision 1.81 2002/10/14 19:42:34 peter
  1493. * only use init tables for threadvars
  1494. Revision 1.80 2002/10/06 19:41:30 peter
  1495. * Add finalization of typed consts
  1496. * Finalization of globals in the main program
  1497. Revision 1.79 2002/09/09 17:34:15 peter
  1498. * tdicationary.replace added to replace and item in a dictionary. This
  1499. is only allowed for the same name
  1500. * varsyms are inserted in symtable before the types are parsed. This
  1501. fixes the long standing "var longint : longint" bug
  1502. - consume_idlist and idstringlist removed. The loops are inserted
  1503. at the callers place and uses the symtable for duplicate id checking
  1504. Revision 1.78 2002/09/07 15:25:07 peter
  1505. * old logs removed and tabs fixed
  1506. Revision 1.77 2002/09/03 16:26:27 daniel
  1507. * Make Tprocdef.defs protected
  1508. Revision 1.76 2002/09/02 18:46:26 peter
  1509. * insert PASCALMAIN in library for Win32 only
  1510. Revision 1.75 2002/08/31 15:59:30 florian
  1511. + HEAP* stuff must be generated for Linux/PPC as well
  1512. + direct assembler reader searches now global and static symtables as well
  1513. Revision 1.74 2002/08/25 19:25:20 peter
  1514. * sym.insert_in_data removed
  1515. * symtable.insertvardata/insertconstdata added
  1516. * removed insert_in_data call from symtable.insert, it needs to be
  1517. called separatly. This allows to deref the address calculation
  1518. * procedures now calculate the parast addresses after the procedure
  1519. directives are parsed. This fixes the cdecl parast problem
  1520. * push_addr_param has an extra argument that specifies if cdecl is used
  1521. or not
  1522. Revision 1.73 2002/08/18 20:06:25 peter
  1523. * inlining is now also allowed in interface
  1524. * renamed write/load to ppuwrite/ppuload
  1525. * tnode storing in ppu
  1526. * nld,ncon,nbas are already updated for storing in ppu
  1527. Revision 1.72 2002/08/17 09:23:39 florian
  1528. * first part of procinfo rewrite
  1529. Revision 1.71 2002/08/11 13:24:12 peter
  1530. * saving of asmsymbols in ppu supported
  1531. * asmsymbollist global is removed and moved into a new class
  1532. tasmlibrarydata that will hold the info of a .a file which
  1533. corresponds with a single module. Added librarydata to tmodule
  1534. to keep the library info stored for the module. In the future the
  1535. objectfiles will also be stored to the tasmlibrarydata class
  1536. * all getlabel/newasmsymbol and friends are moved to the new class
  1537. Revision 1.70 2002/08/10 14:46:29 carl
  1538. + moved target_cpu_string to cpuinfo
  1539. * renamed asmmode enum.
  1540. * assembler reader has now less ifdef's
  1541. * move from nppcmem.pas -> ncgmem.pas vec. node.
  1542. Revision 1.69 2002/07/26 21:15:41 florian
  1543. * rewrote the system handling
  1544. Revision 1.68 2002/07/04 20:43:01 florian
  1545. * first x86-64 patches
  1546. Revision 1.67 2002/07/01 18:46:25 peter
  1547. * internal linker
  1548. * reorganized aasm layer
  1549. Revision 1.66 2002/05/16 19:46:43 carl
  1550. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1551. + try to fix temp allocation (still in ifdef)
  1552. + generic constructor calls
  1553. + start of tassembler / tmodulebase class cleanup
  1554. Revision 1.65 2002/05/14 19:34:49 peter
  1555. * removed old logs and updated copyright year
  1556. Revision 1.64 2002/05/12 16:53:09 peter
  1557. * moved entry and exitcode to ncgutil and cgobj
  1558. * foreach gets extra argument for passing local data to the
  1559. iterator function
  1560. * -CR checks also class typecasts at runtime by changing them
  1561. into as
  1562. * fixed compiler to cycle with the -CR option
  1563. * fixed stabs with elf writer, finally the global variables can
  1564. be watched
  1565. * removed a lot of routines from cga unit and replaced them by
  1566. calls to cgobj
  1567. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1568. u32bit then the other is typecasted also to u32bit without giving
  1569. a rangecheck warning/error.
  1570. * fixed pascal calling method with reversing also the high tree in
  1571. the parast, detected by tcalcst3 test
  1572. Revision 1.63 2002/05/06 19:54:50 carl
  1573. + added more patches from Mazen for SPARC port
  1574. Revision 1.62 2002/04/20 21:32:24 carl
  1575. + generic FPC_CHECKPOINTER
  1576. + first parameter offset in stack now portable
  1577. * rename some constants
  1578. + move some cpu stuff to other units
  1579. - remove unused constents
  1580. * fix stacksize for some targets
  1581. * fix generic size problems which depend now on EXTEND_SIZE constant
  1582. Revision 1.61 2002/04/19 15:46:02 peter
  1583. * mangledname rewrite, tprocdef.mangledname is now created dynamicly
  1584. in most cases and not written to the ppu
  1585. * add mangeledname_prefix() routine to generate the prefix of
  1586. manglednames depending on the current procedure, object and module
  1587. * removed static procprefix since the mangledname is now build only
  1588. on demand from tprocdef.mangledname
  1589. Revision 1.60 2002/04/14 16:53:10 carl
  1590. + align code section and data section according to alignment rules
  1591. Revision 1.59 2002/04/07 17:58:38 carl
  1592. + generic stack checking
  1593. Revision 1.58 2002/04/04 19:06:03 peter
  1594. * removed unused units
  1595. * use tlocation.size in cg.a_*loc*() routines
  1596. }