pmodules.pas 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847
  1. {
  2. $Id$
  3. Copyright (c) 1998 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. {$define New_GDB}
  20. interface
  21. procedure proc_unit;
  22. procedure proc_program(islibrary : boolean);
  23. implementation
  24. uses
  25. globtype,version,systems,tokens,
  26. cobjects,comphook,globals,verbose,files,
  27. symtable,aasm,hcodegen,
  28. link,assemble,import,export,gendef,ppu,comprsrc
  29. {$ifdef i386}
  30. ,i386base,i386asm
  31. {$endif}
  32. {$ifdef m68k}
  33. ,m68k
  34. {$endif}
  35. ,scanner,pbase,psystem,pdecl,psub,parser;
  36. procedure create_objectfile;
  37. begin
  38. { create the .s file and assemble it }
  39. GenerateAsm(false);
  40. { Also create a smartlinked version ? }
  41. if (cs_smartlink in aktmoduleswitches) then
  42. begin
  43. GenerateAsm(true);
  44. if target_asm.needar then
  45. Linker.MakeStaticLibrary(SmartLinkFilesCnt);
  46. end;
  47. { resource files }
  48. CompileResourceFiles;
  49. end;
  50. procedure insertobjectfile;
  51. { Insert the used object file for this unit in the used list for this unit }
  52. begin
  53. current_module^.linkunitofiles.insert(current_module^.objfilename^,link_static);
  54. current_module^.flags:=current_module^.flags or uf_static_linked;
  55. if (cs_smartlink in aktmoduleswitches) then
  56. begin
  57. current_module^.linkunitstaticlibs.insert(current_module^.staticlibfilename^,link_smart);
  58. current_module^.flags:=current_module^.flags or uf_smart_linked;
  59. end;
  60. end;
  61. procedure insertsegment;
  62. procedure fixseg(p:paasmoutput;sec:tsection);
  63. begin
  64. p^.insert(new(pai_section,init(sec)));
  65. if (cs_smartlink in aktmoduleswitches) then
  66. p^.insert(new(pai_cut,init));
  67. p^.concat(new(pai_section,init(sec_none)));
  68. end;
  69. begin
  70. {Insert Ident of the compiler}
  71. if (not (cs_smartlink in aktmoduleswitches))
  72. {$ifndef EXTDEBUG}
  73. and (not current_module^.is_unit)
  74. {$endif}
  75. then
  76. begin
  77. datasegment^.insert(new(pai_align,init(4)));
  78. datasegment^.insert(new(pai_string,init('FPC '+version_string+
  79. ' for '+target_cpu_string+' - '+target_info.short_name)));
  80. end;
  81. { Insert start and end of sections }
  82. fixseg(codesegment,sec_code);
  83. fixseg(datasegment,sec_data);
  84. fixseg(bsssegment,sec_bss);
  85. { we should use .rdata section for these two no ? }
  86. { .rdata is a read only data section (PM) }
  87. fixseg(rttilist,sec_data);
  88. fixseg(consts,sec_data);
  89. {$ifdef GDB}
  90. if assigned(debuglist) then
  91. fixseg(debuglist,sec_code);
  92. {$endif GDB}
  93. end;
  94. procedure InsertInitFinalTable;
  95. var
  96. hp : pused_unit;
  97. unitinits : taasmoutput;
  98. count : longint;
  99. begin
  100. unitinits.init;
  101. count:=0;
  102. hp:=pused_unit(usedunits.first);
  103. while assigned(hp) do
  104. begin
  105. { call the unit init code and make it external }
  106. if (hp^.u^.flags and (uf_init or uf_finalize))<>0 then
  107. begin
  108. if (hp^.u^.flags and uf_init)<>0 then
  109. begin
  110. unitinits.concat(new(pai_const_symbol,initname('INIT$$'+hp^.u^.modulename^)));
  111. end
  112. else
  113. unitinits.concat(new(pai_const,init_32bit(0)));
  114. if (hp^.u^.flags and uf_finalize)<>0 then
  115. begin
  116. unitinits.concat(new(pai_const_symbol,initname('FINALIZE$$'+hp^.u^.modulename^)));
  117. end
  118. else
  119. unitinits.concat(new(pai_const,init_32bit(0)));
  120. inc(count);
  121. end;
  122. hp:=Pused_unit(hp^.next);
  123. end;
  124. { TableCount,InitCount }
  125. unitinits.insert(new(pai_const,init_32bit(0)));
  126. unitinits.insert(new(pai_const,init_32bit(count)));
  127. unitinits.insert(new(pai_symbol,initname_global('INITFINAL')));
  128. { insert in data segment }
  129. if (cs_smartlink in aktmoduleswitches) then
  130. datasegment^.concat(new(pai_cut,init));
  131. datasegment^.concatlist(@unitinits);
  132. unitinits.done;
  133. end;
  134. procedure insertheap;
  135. begin
  136. if (cs_smartlink in aktmoduleswitches) then
  137. begin
  138. bsssegment^.concat(new(pai_cut,init));
  139. datasegment^.concat(new(pai_cut,init));
  140. end;
  141. { On the Macintosh Classic M68k Architecture
  142. The Heap variable is simply a POINTER to the
  143. real HEAP. The HEAP must be set up by the RTL
  144. and must store the pointer in this value.
  145. On OS/2 the heap is also intialized by the RTL. We do
  146. not output a pointer }
  147. case target_info.target of
  148. {$ifdef i386}
  149. target_i386_OS2:
  150. ;
  151. {$endif i386}
  152. {$ifdef m68k}
  153. target_m68k_Mac:
  154. bsssegment^.concat(new(pai_datablock,init_global('HEAP',4)));
  155. target_m68k_PalmOS:
  156. ;
  157. {$endif m68k}
  158. else
  159. bsssegment^.concat(new(pai_datablock,init_global('HEAP',heapsize)));
  160. end;
  161. {$ifdef i386}
  162. datasegment^.concat(new(pai_symbol,initname_global('HEAPSIZE')));
  163. datasegment^.concat(new(pai_const,init_32bit(heapsize)));
  164. {$endif i386}
  165. {$ifdef m68k}
  166. if target_info.target<>target_m68k_PalmOS then
  167. begin
  168. datasegment^.concat(new(pai_symbol,init_global('HEAP_SIZE')));
  169. datasegment^.concat(new(pai_const,init_32bit(heapsize)));
  170. end;
  171. {$endif m68k}
  172. end;
  173. procedure inserttargetspecific;
  174. begin
  175. case target_info.target of
  176. {$ifdef i386}
  177. target_i386_GO32V2 :
  178. begin
  179. { stacksize can be specified }
  180. datasegment^.concat(new(pai_symbol,initname_global('__stklen')));
  181. datasegment^.concat(new(pai_const,init_32bit(stacksize)));
  182. end;
  183. target_i386_WIN32 :
  184. begin
  185. { Generate an external entry to be sure that _mainCRTStarup will be
  186. linked, can't use concat_external because those aren't written for
  187. asw (PFV) }
  188. target_link.bindcmd[1]:=target_link.bindcmd[1]+' -d '+deffile.fname;
  189. if DLLsource then
  190. target_link.binders:=2;
  191. if RelocSection then
  192. begin
  193. target_link.linkcmd:=target_link.linkcmd+' --base-file base.$$$';
  194. target_link.bindcmd[1]:=target_link.bindcmd[1]+' --base-file base.$$$';
  195. target_link.binders:=2;
  196. end;
  197. if apptype=at_gui then
  198. begin
  199. target_link.linkcmd:='--subsystem windows '+target_link.linkcmd;
  200. target_link.bindcmd[2]:='--subsystem windows '+target_link.bindcmd[2];
  201. end;
  202. if DLLsource then
  203. begin
  204. target_link.linkcmd:='--dll '+target_link.linkcmd;
  205. target_link.bindcmd[2]:='--dll '+target_link.bindcmd[2];
  206. end;
  207. end;
  208. {$endif i386}
  209. {$ifdef m68k}
  210. target_m68k_Atari :
  211. begin
  212. { stacksize can be specified }
  213. datasegment^.concat(new(pai_symbol,init_global('__stklen')));
  214. datasegment^.concat(new(pai_const,init_32bit(stacksize)));
  215. end;
  216. {$endif m68k}
  217. end;
  218. end;
  219. function loadunit(const s : string;compile_system:boolean) : pmodule;forward;
  220. procedure load_usedunits(compile_system:boolean);
  221. var
  222. pu : pused_unit;
  223. loaded_unit : pmodule;
  224. load_refs : boolean;
  225. nextmapentry : longint;
  226. begin
  227. load_refs:=true;
  228. { init the map }
  229. new(current_module^.map);
  230. fillchar(current_module^.map^,sizeof(tunitmap),#0);
  231. {$ifdef NEWMAP}
  232. current_module^.map^[0]:=current_module;
  233. {$endif NEWMAP}
  234. nextmapentry:=1;
  235. { load the used units from interface }
  236. current_module^.in_implementation:=false;
  237. pu:=pused_unit(current_module^.used_units.first);
  238. while assigned(pu) do
  239. begin
  240. if (not pu^.loaded) and (pu^.in_interface) then
  241. begin
  242. loaded_unit:=loadunit(pu^.name^,false);
  243. if current_module^.compiled then
  244. exit;
  245. { register unit in used units }
  246. pu^.u:=loaded_unit;
  247. pu^.loaded:=true;
  248. { doubles are not important for that list PM }
  249. pu^.u^.dependent_units.concat(new(pdependent_unit,init(current_module)));
  250. { need to recompile the current unit ? }
  251. if loaded_unit^.crc<>pu^.checksum then
  252. begin
  253. Message2(unit_u_recompile_crc_change,current_module^.modulename^,pu^.name^);
  254. current_module^.do_compile:=true;
  255. dispose(current_module^.map);
  256. current_module^.map:=nil;
  257. exit;
  258. end;
  259. { setup the map entry for deref }
  260. {$ifndef NEWMAP}
  261. current_module^.map^[nextmapentry]:=loaded_unit^.globalsymtable;
  262. {$else NEWMAP}
  263. current_module^.map^[nextmapentry]:=loaded_unit;
  264. {$endif NEWMAP}
  265. inc(nextmapentry);
  266. if nextmapentry>maxunits then
  267. Message(unit_f_too_much_units);
  268. end;
  269. pu:=pused_unit(pu^.next);
  270. end;
  271. { ok, now load the unit }
  272. current_module^.globalsymtable:=new(punitsymtable,loadasunit);
  273. { now only read the implementation part }
  274. current_module^.in_implementation:=true;
  275. { load the used units from implementation }
  276. pu:=pused_unit(current_module^.used_units.first);
  277. while assigned(pu) do
  278. begin
  279. if (not pu^.loaded) and (not pu^.in_interface) then
  280. begin
  281. loaded_unit:=loadunit(pu^.name^,false);
  282. if current_module^.compiled then
  283. exit;
  284. { register unit in used units }
  285. pu^.u:=loaded_unit;
  286. pu^.loaded:=true;
  287. { need to recompile the current unit ? }
  288. if loaded_unit^.crc<>pu^.checksum then
  289. begin
  290. Message2(unit_u_recompile_crc_change,current_module^.modulename^,pu^.name^);
  291. current_module^.do_compile:=true;
  292. dispose(current_module^.map);
  293. current_module^.map:=nil;
  294. exit;
  295. end;
  296. { setup the map entry for deref }
  297. {$ifndef NEWMAP}
  298. current_module^.map^[nextmapentry]:=loaded_unit^.globalsymtable;
  299. {$else NEWMAP}
  300. current_module^.map^[nextmapentry]:=loaded_unit;
  301. {$endif NEWMAP}
  302. inc(nextmapentry);
  303. if nextmapentry>maxunits then
  304. Message(unit_f_too_much_units);
  305. end;
  306. pu:=pused_unit(pu^.next);
  307. end;
  308. { load browser info if stored }
  309. if ((current_module^.flags and uf_has_browser)<>0) and load_refs then
  310. punitsymtable(current_module^.globalsymtable)^.load_symtable_refs;
  311. { remove the map, it's not needed anymore }
  312. dispose(current_module^.map);
  313. current_module^.map:=nil;
  314. end;
  315. function loadunit(const s : string;compile_system:boolean) : pmodule;
  316. const
  317. ImplIntf : array[boolean] of string[15]=('interface','implementation');
  318. var
  319. st : punitsymtable;
  320. second_time : boolean;
  321. old_current_ppu : pppufile;
  322. old_current_module,hp,hp2,hp3 : pmodule;
  323. name : string;{ necessary because
  324. current_module^.mainsource^ is reset in compile !! }
  325. scanner : pscannerfile;
  326. procedure loadppufile;
  327. begin
  328. { load interface section }
  329. if not current_module^.do_compile then
  330. load_interface;
  331. { only load units when we don't recompile }
  332. if not current_module^.do_compile then
  333. load_usedunits(compile_system);
  334. { recompile if set }
  335. if current_module^.do_compile then
  336. begin
  337. { we don't need the ppufile anymore }
  338. if assigned(current_module^.ppufile) then
  339. begin
  340. dispose(current_module^.ppufile,done);
  341. current_module^.ppufile:=nil;
  342. current_ppu:=nil;
  343. end;
  344. { recompile the unit or give a fatal error if sources not available }
  345. if not(current_module^.sources_avail) then
  346. if (not current_module^.search_unit(current_module^.modulename^,true))
  347. and (length(current_module^.modulename^)>8) then
  348. current_module^.search_unit(copy(current_module^.modulename^,1,8),true);
  349. if not(current_module^.sources_avail) then
  350. Message1(unit_f_cant_compile_unit,current_module^.modulename^)
  351. else
  352. begin
  353. if current_module^.in_second_compile then
  354. Message1(parser_d_compiling_second_time,current_module^.modulename^);
  355. current_scanner^.tempcloseinputfile;
  356. name:=current_module^.mainsource^;
  357. if assigned(scanner) then
  358. scanner^.invalid:=true;
  359. compile(name,compile_system);
  360. if (not current_scanner^.invalid) then
  361. current_scanner^.tempopeninputfile;
  362. end;
  363. end
  364. else
  365. begin
  366. { only reassemble ? }
  367. if (current_module^.do_assemble) then
  368. OnlyAsm;
  369. end;
  370. if assigned(current_module^.ppufile) then
  371. begin
  372. dispose(current_module^.ppufile,done);
  373. current_module^.ppufile:=nil;
  374. current_ppu:=nil;
  375. end;
  376. end;
  377. begin
  378. old_current_module:=current_module;
  379. old_current_ppu:=current_ppu;
  380. { Info }
  381. Message3(unit_u_load_unit,current_module^.modulename^,ImplIntf[current_module^.in_implementation],s);
  382. { unit not found }
  383. st:=nil;
  384. { search all loaded units }
  385. hp:=pmodule(loaded_units.first);
  386. while assigned(hp) do
  387. begin
  388. if hp^.modulename^=s then
  389. begin
  390. { forced to reload ? }
  391. if hp^.do_reload then
  392. break;
  393. { the unit is already registered }
  394. { and this means that the unit }
  395. { is already compiled }
  396. { else there is a cyclic unit use }
  397. if assigned(hp^.globalsymtable) then
  398. st:=punitsymtable(hp^.globalsymtable)
  399. else
  400. begin
  401. { both units in interface ? }
  402. if (not current_module^.in_implementation) and (not hp^.in_implementation) then
  403. begin
  404. { check for a cycle }
  405. hp2:=current_module^.loaded_from;
  406. while assigned(hp2) and (hp2<>hp) do
  407. begin
  408. if hp2^.in_implementation then
  409. hp2:=nil
  410. else
  411. hp2:=hp2^.loaded_from;
  412. end;
  413. if assigned(hp2) then
  414. Message2(unit_f_circular_unit_reference,current_module^.modulename^,hp^.modulename^);
  415. end;
  416. end;
  417. break;
  418. end;
  419. { the next unit }
  420. hp:=pmodule(hp^.next);
  421. end;
  422. { the unit is not in the symtable stack }
  423. if (not assigned(st)) then
  424. begin
  425. if assigned(hp) then
  426. begin
  427. { remove the old unit }
  428. loaded_units.remove(hp);
  429. scanner:=hp^.scanner;
  430. hp^.reset;
  431. { now reload all dependent units }
  432. hp2:=pmodule(loaded_units.first);
  433. while assigned(hp2) do
  434. begin
  435. if hp2^.do_reload then
  436. begin
  437. hp2^.do_reload:=false;
  438. hp3:=loadunit(hp^.modulename^,false);
  439. end;
  440. hp2:=pmodule(hp2^.next);
  441. end;
  442. hp^.scanner:=scanner;
  443. { try to reopen ppu }
  444. hp^.search_unit(s,false);
  445. { try to load the unit a second time first }
  446. current_module:=hp;
  447. current_module^.in_second_compile:=true;
  448. Message1(unit_u_second_load_unit,current_module^.modulename^);
  449. second_time:=true;
  450. end
  451. else
  452. { generates a new unit info record }
  453. begin
  454. current_module:=new(pmodule,init(s,true));
  455. scanner:=nil;
  456. second_time:=false;
  457. end;
  458. current_ppu:=current_module^.ppufile;
  459. { now we can register the unit }
  460. current_module^.loaded_from:=old_current_module;
  461. loaded_units.insert(current_module);
  462. { now realy load the ppu }
  463. loadppufile;
  464. { set compiled flag }
  465. current_module^.compiled:=true;
  466. { register the unit _once_ }
  467. { this is buggy PM }
  468. if not second_time then
  469. usedunits.concat(new(pused_unit,init(current_module,true)));
  470. { load return pointer }
  471. hp:=current_module;
  472. end;
  473. { set the old module }
  474. current_ppu:=old_current_ppu;
  475. current_module:=old_current_module;
  476. loadunit:=hp;
  477. end;
  478. procedure loaddefaultunits;
  479. var
  480. hp : pmodule;
  481. begin
  482. { are we compiling the system unit? }
  483. if (cs_compilesystem in aktmoduleswitches) then
  484. begin
  485. { create system defines }
  486. createconstdefs;
  487. { we don't need to reset anything, it's already done in parser.pas }
  488. exit;
  489. end;
  490. { insert the system unit, it is allways the first }
  491. hp:=loadunit(upper(target_info.system_unit),true);
  492. systemunit:=hp^.globalsymtable;
  493. { it's always the first unit }
  494. systemunit^.next:=nil;
  495. symtablestack:=systemunit;
  496. { add to the used units }
  497. current_module^.used_units.concat(new(pused_unit,init(hp,true)));
  498. refsymtable^.insert(new(punitsym,init('SYSTEM',systemunit)));
  499. { read default constant definitions }
  500. make_ref:=false;
  501. readconstdefs;
  502. make_ref:=true;
  503. { if POWER is defined in the RTL then use it for starstar overloading }
  504. getsym('POWER',false);
  505. if assigned(srsym) and (srsym^.typ=procsym) and (overloaded_operators[STARSTAR]=nil) then
  506. overloaded_operators[STARSTAR]:=pprocsym(srsym);
  507. { Objpas unit? }
  508. if m_objpas in aktmodeswitches then
  509. begin
  510. hp:=loadunit('OBJPAS',false);
  511. objpasunit:=hp^.globalsymtable;
  512. { insert in stack }
  513. objpasunit^.next:=symtablestack;
  514. symtablestack:=objpasunit;
  515. { add to the used units }
  516. current_module^.used_units.concat(new(pused_unit,init(hp,true)));
  517. refsymtable^.insert(new(punitsym,init('OBJPAS',objpasunit)));
  518. end
  519. else
  520. objpasunit:=nil;
  521. { Profile unit? Needed for go32v2 only }
  522. if (cs_profile in aktmoduleswitches) and (target_info.target=target_i386_go32v2) then
  523. begin
  524. hp:=loadunit('PROFILE',false);
  525. psymtable(hp^.globalsymtable)^.next:=symtablestack;
  526. symtablestack:=hp^.globalsymtable;
  527. { add to the used units }
  528. current_module^.used_units.concat(new(pused_unit,init(hp,true)));
  529. refsymtable^.insert(new(punitsym,init('PROFILE',hp^.globalsymtable)));
  530. end;
  531. { Heaptrc unit? (not needed for units), this is here to be sure that it is really
  532. loaded as first unit }
  533. if (cs_gdb_heaptrc in aktglobalswitches) and not(current_module^.is_unit)then
  534. begin
  535. hp:=loadunit('HEAPTRC',false);
  536. psymtable(hp^.globalsymtable)^.next:=symtablestack;
  537. symtablestack:=hp^.globalsymtable;
  538. { add to the used units }
  539. current_module^.used_units.concat(new(pused_unit,init(hp,true)));
  540. refsymtable^.insert(new(punitsym,init('HEAPTRC',hp^.globalsymtable)));
  541. end;
  542. { save default symtablestack }
  543. defaultsymtablestack:=symtablestack;
  544. end;
  545. procedure loadunits;
  546. var
  547. s : stringid;
  548. pu,
  549. hp : pused_unit;
  550. hp2 : pmodule;
  551. hp3 : psymtable;
  552. oldprocsym:Pprocsym;
  553. begin
  554. oldprocsym:=aktprocsym;
  555. consume(_USES);
  556. {$ifdef DEBUG}
  557. test_symtablestack;
  558. {$endif DEBUG}
  559. repeat
  560. s:=pattern;
  561. consume(ID);
  562. { Give a warning if objpas is loaded }
  563. if s='OBJPAS' then
  564. Message(parser_w_no_objpas_use_mode);
  565. { check if the unit is already used }
  566. pu:=pused_unit(current_module^.used_units.first);
  567. while assigned(pu) do
  568. begin
  569. if (pu^.name^=s) then
  570. break;
  571. pu:=pused_unit(pu^.next);
  572. end;
  573. { avoid uses of itself }
  574. if not assigned(pu) and (s<>current_module^.modulename^) then
  575. begin
  576. { load the unit }
  577. hp2:=loadunit(s,false);
  578. { the current module uses the unit hp2 }
  579. current_module^.used_units.concat(new(pused_unit,init(hp2,not current_module^.in_implementation)));
  580. pused_unit(current_module^.used_units.last)^.in_uses:=true;
  581. if current_module^.compiled then
  582. exit;
  583. refsymtable^.insert(new(punitsym,init(s,hp2^.globalsymtable)));
  584. end
  585. else
  586. Message1(sym_e_duplicate_id,s);
  587. if token=COMMA then
  588. begin
  589. pattern:='';
  590. consume(COMMA);
  591. end
  592. else
  593. break;
  594. until false;
  595. consume(SEMICOLON);
  596. { set the symtable to systemunit so it gets reorderd correctly }
  597. symtablestack:=defaultsymtablestack;
  598. { now insert the units in the symtablestack }
  599. hp:=pused_unit(current_module^.used_units.first);
  600. while assigned(hp) do
  601. begin
  602. {$IfDef GDB}
  603. {$IfnDef New_GDB}
  604. if (cs_debuginfo in aktmoduleswitches) and
  605. not hp^.is_stab_written then
  606. begin
  607. punitsymtable(hp^.u^.globalsymtable)^.concattypestabto(debuglist);
  608. hp^.is_stab_written:=true;
  609. hp^.unitid:=psymtable(hp^.u^.globalsymtable)^.unitid;
  610. end;
  611. {$endIf nDef New_GDB}
  612. {$EndIf GDB}
  613. if hp^.in_uses then
  614. begin
  615. hp3:=symtablestack;
  616. while assigned(hp3) do
  617. begin
  618. { insert units only once ! }
  619. if hp^.u^.globalsymtable=hp3 then
  620. break;
  621. hp3:=hp3^.next;
  622. { unit isn't inserted }
  623. if hp3=nil then
  624. begin
  625. psymtable(hp^.u^.globalsymtable)^.next:=symtablestack;
  626. symtablestack:=psymtable(hp^.u^.globalsymtable);
  627. {$ifdef CHAINPROCSYMS}
  628. symtablestack^.chainprocsyms;
  629. {$endif CHAINPROCSYMS}
  630. {$ifdef DEBUG}
  631. test_symtablestack;
  632. {$endif DEBUG}
  633. end;
  634. end;
  635. end;
  636. hp:=pused_unit(hp^.next);
  637. end;
  638. aktprocsym:=oldprocsym;
  639. end;
  640. procedure write_gdb_info;
  641. {$IfDef GDB}
  642. var
  643. hp : pused_unit;
  644. begin
  645. if not (cs_debuginfo in aktmoduleswitches) then
  646. exit;
  647. { now insert the units in the symtablestack }
  648. hp:=pused_unit(current_module^.used_units.first);
  649. while assigned(hp) do
  650. begin
  651. if (cs_debuginfo in aktmoduleswitches) and
  652. not hp^.is_stab_written then
  653. begin
  654. punitsymtable(hp^.u^.globalsymtable)^.concattypestabto(debuglist);
  655. hp^.is_stab_written:=true;
  656. hp^.unitid:=psymtable(hp^.u^.globalsymtable)^.unitid;
  657. end;
  658. hp:=pused_unit(hp^.next);
  659. end;
  660. if current_module^.in_implementation then
  661. begin
  662. if assigned(current_module^.localsymtable) then
  663. begin
  664. { all types }
  665. punitsymtable(current_module^.localsymtable)^.concattypestabto(debuglist);
  666. { and all local symbols}
  667. punitsymtable(current_module^.localsymtable)^.concatstabto(debuglist);
  668. end;
  669. end
  670. else
  671. begin
  672. if assigned(current_module^.globalsymtable) then
  673. begin
  674. { all types }
  675. punitsymtable(current_module^.globalsymtable)^.concattypestabto(debuglist);
  676. { and all local symbols}
  677. punitsymtable(current_module^.globalsymtable)^.concatstabto(debuglist);
  678. end;
  679. end;
  680. end;
  681. {$Else GDB}
  682. begin
  683. end;
  684. {$EndIf GDB}
  685. procedure parse_implementation_uses(symt:Psymtable);
  686. begin
  687. if token=_USES then
  688. begin
  689. symt^.symtabletype:=unitsymtable;
  690. loadunits;
  691. symt^.symtabletype:=globalsymtable;
  692. {$ifdef DEBUG}
  693. test_symtablestack;
  694. {$endif DEBUG}
  695. end;
  696. end;
  697. procedure gen_main_procsym(const name:string;options:longint;st:psymtable);
  698. var
  699. stt : psymtable;
  700. begin
  701. {Generate a procsym for main}
  702. make_ref:=false;
  703. aktprocsym:=new(Pprocsym,init(name));
  704. {Try to insert in in static symtable ! }
  705. stt:=symtablestack;
  706. symtablestack:=st;
  707. aktprocsym^.definition:=new(Pprocdef,init);
  708. symtablestack:=stt;
  709. aktprocsym^.definition^.options:=aktprocsym^.definition^.options or options;
  710. aktprocsym^.definition^.setmangledname(target_os.cprefix+name);
  711. aktprocsym^.definition^.forwarddef:=false;
  712. make_ref:=true;
  713. { The localst is a local symtable. Change it into the static
  714. symtable }
  715. dispose(aktprocsym^.definition^.localst,done);
  716. aktprocsym^.definition^.localst:=st;
  717. { and insert the procsym in symtable }
  718. st^.insert(aktprocsym);
  719. { set some informations about the main program }
  720. with procinfo do
  721. begin
  722. retdef:=voiddef;
  723. _class:=nil;
  724. call_offset:=8;
  725. framepointer:=frame_pointer;
  726. flags:=0;
  727. end;
  728. end;
  729. procedure proc_unit;
  730. function is_assembler_generated:boolean;
  731. begin
  732. is_assembler_generated:=(Errorcount=0) and
  733. not(
  734. codesegment^.empty and
  735. datasegment^.empty and
  736. bsssegment^.empty and
  737. ((importssection=nil) or importssection^.empty) and
  738. ((resourcesection=nil) or resourcesection^.empty)
  739. );
  740. end;
  741. var
  742. names : Tstringcontainer;
  743. st : psymtable;
  744. unitst : punitsymtable;
  745. {$ifdef GDB}
  746. pu : pused_unit;
  747. {$endif GDB}
  748. {$ifdef Test_Double_checksum}
  749. store_crc : longint;
  750. {$endif}
  751. s1,s2 : ^string; {Saves stack space}
  752. begin
  753. consume(_UNIT);
  754. if token=ID then
  755. begin
  756. { create filenames and unit name }
  757. current_module^.SetFileName(current_scanner^.inputfile^.path^+current_scanner^.inputfile^.name^,true);
  758. stringdispose(current_module^.modulename);
  759. current_module^.modulename:=stringdup(upper(pattern));
  760. { check for system unit }
  761. new(s1);
  762. new(s2);
  763. s1^:=upper(target_info.system_unit);
  764. s2^:=upper(SplitName(current_scanner^.inputfile^.name^));
  765. if (cs_compilesystem in aktmoduleswitches) then
  766. begin
  767. if ((length(current_module^.modulename^)>8) or
  768. (current_module^.modulename^<>s1^) or
  769. (current_module^.modulename^<>s2^)) then
  770. Message1(unit_e_illegal_unit_name,current_module^.modulename^);
  771. end
  772. else
  773. begin
  774. if (cs_check_unit_name in aktglobalswitches) and
  775. not((current_module^.modulename^=s2^) or
  776. ((length(current_module^.modulename^)>8) and
  777. (copy(current_module^.modulename^,1,8)=s2^))) then
  778. Message1(unit_e_illegal_unit_name,current_module^.modulename^);
  779. if (current_module^.modulename^=s1^) then
  780. Message(unit_w_switch_us_missed);
  781. end;
  782. dispose(s2);
  783. dispose(s1);
  784. end;
  785. consume(ID);
  786. consume(SEMICOLON);
  787. consume(_INTERFACE);
  788. { global switches are read, so further changes aren't allowed }
  789. current_module^.in_global:=false;
  790. { can't have local browser when no global browser }
  791. if (cs_local_browser in aktmoduleswitches) and
  792. not(cs_browser in aktmoduleswitches) then
  793. aktmoduleswitches:=aktmoduleswitches-[cs_local_browser];
  794. Message1(unit_u_start_parse_interface,current_module^.modulename^);
  795. { update status }
  796. status.currentmodule:=current_module^.modulename^;
  797. { maybe turn off m_objpas if we are compiling objpas }
  798. if (current_module^.modulename^='OBJPAS') then
  799. aktmodeswitches:=aktmodeswitches-[m_objpas];
  800. { this should be placed after uses !!}
  801. {$ifndef UseNiceNames}
  802. procprefix:='_'+current_module^.modulename^+'$$';
  803. {$else UseNiceNames}
  804. procprefix:='_'+tostr(length(current_module^.modulename^))+lowercase(current_module^.modulename^)+'_';
  805. {$endif UseNiceNames}
  806. parse_only:=true;
  807. { generate now the global symboltable }
  808. st:=new(punitsymtable,init(globalsymtable,current_module^.modulename^));
  809. refsymtable:=st;
  810. unitst:=punitsymtable(st);
  811. { define first as local to overcome dependency conflicts }
  812. current_module^.localsymtable:=st;
  813. { the unit name must be usable as a unit specifier }
  814. { inside the unit itself (PM) }
  815. { this also forbids to have another symbol }
  816. { with the same name as the unit }
  817. refsymtable^.insert(new(punitsym,init(current_module^.modulename^,unitst)));
  818. { a unit compiled at command line must be inside the loaded_unit list }
  819. if (compile_level=1) then
  820. loaded_units.insert(current_module);
  821. { load default units, like the system unit }
  822. loaddefaultunits;
  823. { reset }
  824. make_ref:=true;
  825. lexlevel:=0;
  826. { insert qualifier for the system unit (allows system.writeln) }
  827. if not(cs_compilesystem in aktmoduleswitches) then
  828. begin
  829. if token=_USES then
  830. begin
  831. unitst^.symtabletype:=unitsymtable;
  832. loadunits;
  833. { has it been compiled at a higher level ?}
  834. if current_module^.compiled then
  835. begin
  836. { this unit symtable is obsolete }
  837. { dispose(unitst,done);
  838. disposed as localsymtable !! }
  839. exit;
  840. end;
  841. unitst^.symtabletype:=globalsymtable;
  842. end;
  843. { ... but insert the symbol table later }
  844. st^.next:=symtablestack;
  845. symtablestack:=st;
  846. end
  847. else
  848. { while compiling a system unit, some types are directly inserted }
  849. begin
  850. st^.next:=symtablestack;
  851. symtablestack:=st;
  852. insert_intern_types(st);
  853. end;
  854. { now we know the place to insert the constants }
  855. constsymtable:=symtablestack;
  856. { move the global symtab from the temporary local to global }
  857. current_module^.globalsymtable:=current_module^.localsymtable;
  858. current_module^.localsymtable:=nil;
  859. reset_global_defs;
  860. { ... parse the declarations }
  861. read_interface_declarations;
  862. { leave when we got an error }
  863. if (Errorcount>0) and not status.skip_error then
  864. begin
  865. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  866. status.skip_error:=true;
  867. exit;
  868. end;
  869. {$ifdef New_GDB}
  870. write_gdb_info;
  871. {$endIf Def New_GDB}
  872. {$ifdef Test_Double_checksum}
  873. if (Errorcount=0) then
  874. writeunitas(current_module^.ppufilename^,punitsymtable(symtablestack),true);
  875. {$endif Test_Double_checksum}
  876. { Parse the implementation section }
  877. consume(_IMPLEMENTATION);
  878. current_module^.in_implementation:=true;
  879. Message1(unit_u_start_parse_implementation,current_module^.modulename^);
  880. parse_only:=false;
  881. { generates static symbol table }
  882. st:=new(punitsymtable,init(staticsymtable,current_module^.modulename^));
  883. current_module^.localsymtable:=st;
  884. { remove the globalsymtable from the symtable stack }
  885. { to reinsert it after loading the implementation units }
  886. symtablestack:=unitst^.next;
  887. { we don't want implementation units symbols in unitsymtable !! PM }
  888. refsymtable:=st;
  889. { Read the implementation units }
  890. parse_implementation_uses(unitst);
  891. if current_module^.compiled then
  892. begin
  893. exit;
  894. end;
  895. { reset ranges/stabs in exported definitions }
  896. reset_global_defs;
  897. { All units are read, now give them a number }
  898. numberunits;
  899. { now we can change refsymtable }
  900. refsymtable:=st;
  901. { but reinsert the global symtable as lasts }
  902. unitst^.next:=symtablestack;
  903. symtablestack:=unitst;
  904. {$ifdef DEBUG}
  905. test_symtablestack;
  906. {$endif DEBUG}
  907. constsymtable:=symtablestack;
  908. {$ifdef Splitheap}
  909. if testsplit then
  910. begin
  911. Split_Heap;
  912. allow_special:=true;
  913. Switch_to_temp_heap;
  914. end;
  915. { it will report all crossings }
  916. allow_special:=false;
  917. {$endif Splitheap}
  918. { Generate a procsym }
  919. gen_main_procsym(current_module^.modulename^+'_init',pounitinit,st);
  920. { Compile the unit }
  921. codegen_newprocedure;
  922. names.init;
  923. names.insert('INIT$$'+current_module^.modulename^);
  924. names.insert(target_os.cprefix+current_module^.modulename^+'_init');
  925. compile_proc_body(names,true,false);
  926. names.done;
  927. codegen_doneprocedure;
  928. { avoid self recursive destructor call !! PM }
  929. aktprocsym^.definition^.localst:=nil;
  930. { finalize? }
  931. if token=_FINALIZATION then
  932. begin
  933. { set module options }
  934. current_module^.flags:=current_module^.flags or uf_finalize;
  935. { Generate a procsym }
  936. gen_main_procsym(current_module^.modulename^+'_finalize',pounitfinalize,st);
  937. { Compile the finalize }
  938. codegen_newprocedure;
  939. names.init;
  940. names.insert('FINALIZE$$'+current_module^.modulename^);
  941. names.insert(target_os.cprefix+current_module^.modulename^+'_finalize');
  942. compile_proc_body(names,true,false);
  943. names.done;
  944. codegen_doneprocedure;
  945. end;
  946. { the last char should always be a point }
  947. consume(POINT);
  948. { avoid self recursive destructor call !! PM }
  949. aktprocsym^.definition^.localst:=nil;
  950. { absence does not matter here !! }
  951. aktprocsym^.definition^.forwarddef:=false;
  952. { test static symtable }
  953. if (Errorcount=0) then
  954. st^.allsymbolsused;
  955. { size of the static data }
  956. datasize:=st^.datasize;
  957. {$ifdef GDB}
  958. { add all used definitions even for implementation}
  959. if (cs_debuginfo in aktmoduleswitches) then
  960. begin
  961. {$IfnDef New_GDB}
  962. if assigned(current_module^.globalsymtable) then
  963. begin
  964. { all types }
  965. punitsymtable(current_module^.globalsymtable)^.concattypestabto(debuglist);
  966. { and all local symbols}
  967. punitsymtable(current_module^.globalsymtable)^.concatstabto(debuglist);
  968. end;
  969. { all local types }
  970. punitsymtable(st)^.concattypestabto(debuglist);
  971. { and all local symbols}
  972. st^.concatstabto(debuglist);
  973. {$else New_GDB}
  974. write_gdb_info;
  975. {$endIf Def New_GDB}
  976. end;
  977. {$endif GDB}
  978. reset_global_defs;
  979. { tests, if all (interface) forwards are resolved }
  980. if (Errorcount=0) then
  981. symtablestack^.check_forwards;
  982. { now we have a correct unit, change the symtable type }
  983. current_module^.in_implementation:=false;
  984. symtablestack^.symtabletype:=unitsymtable;
  985. {$ifdef GDB}
  986. punitsymtable(symtablestack)^.is_stab_written:=false;
  987. {$endif GDB}
  988. { leave when we got an error }
  989. if (Errorcount>0) and not status.skip_error then
  990. begin
  991. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  992. status.skip_error:=true;
  993. exit;
  994. end;
  995. { generate imports }
  996. if current_module^.uses_imports then
  997. importlib^.generatelib;
  998. { insert own objectfile, or say that it's in a library
  999. (no check for an .o when loading) }
  1000. if is_assembler_generated then
  1001. insertobjectfile
  1002. else
  1003. current_module^.flags:=current_module^.flags or uf_no_link;
  1004. if cs_local_browser in aktmoduleswitches then
  1005. current_module^.localsymtable:=refsymtable;
  1006. { Write out the ppufile }
  1007. {$ifdef Test_Double_checksum}
  1008. store_crc:=current_module^.interface_crc;
  1009. {$endif Test_Double_checksum}
  1010. if (Errorcount=0) then
  1011. writeunitas(current_module^.ppufilename^,punitsymtable(symtablestack),false);
  1012. {$ifdef Test_Double_checksum}
  1013. if store_crc<>current_module^.interface_crc then
  1014. Def_comment(V_Warning,current_module^.ppufilename^+' CRC changed '+
  1015. tostr(store_crc)+'<>'+tostr(current_module^.interface_crc));
  1016. {$endif def Test_Double_checksum}
  1017. { must be done only after local symtable ref stores !! }
  1018. closecurrentppu;
  1019. {$ifdef GDB}
  1020. pu:=pused_unit(usedunits.first);
  1021. while assigned(pu) do
  1022. begin
  1023. punitsymtable(pu^.u^.globalsymtable)^.is_stab_written:=false;
  1024. pu:=pused_unit(pu^.next);
  1025. end;
  1026. {$endif GDB}
  1027. { remove static symtable (=refsymtable) here to save some mem }
  1028. if not (cs_local_browser in aktmoduleswitches) then
  1029. begin
  1030. dispose(st,done);
  1031. current_module^.localsymtable:=nil;
  1032. end;
  1033. if is_assembler_generated then
  1034. begin
  1035. { finish asmlist by adding segment starts }
  1036. insertsegment;
  1037. { assemble }
  1038. create_objectfile;
  1039. end;
  1040. { leave when we got an error }
  1041. if (Errorcount>0) and not status.skip_error then
  1042. begin
  1043. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  1044. status.skip_error:=true;
  1045. exit;
  1046. end;
  1047. end;
  1048. procedure proc_program(islibrary : boolean);
  1049. var
  1050. st : psymtable;
  1051. hp : pmodule;
  1052. names : Tstringcontainer;
  1053. begin
  1054. DLLsource:=islibrary;
  1055. parse_only:=false;
  1056. if islibrary then
  1057. begin
  1058. consume(_LIBRARY);
  1059. stringdispose(current_module^.modulename);
  1060. current_module^.modulename:=stringdup(pattern);
  1061. current_module^.islibrary:=true;
  1062. exportlib^.preparelib(pattern);
  1063. consume(ID);
  1064. consume(SEMICOLON);
  1065. end
  1066. else
  1067. { is there an program head ? }
  1068. if token=_PROGRAM then
  1069. begin
  1070. consume(_PROGRAM);
  1071. stringdispose(current_module^.modulename);
  1072. current_module^.modulename:=stringdup(pattern);
  1073. consume(ID);
  1074. if token=LKLAMMER then
  1075. begin
  1076. consume(LKLAMMER);
  1077. idlist;
  1078. consume(RKLAMMER);
  1079. end;
  1080. consume(SEMICOLON);
  1081. end;
  1082. { global switches are read, so further changes aren't allowed }
  1083. current_module^.in_global:=false;
  1084. { can't have local browser when no global browser }
  1085. if (cs_local_browser in aktmoduleswitches) and
  1086. not(cs_browser in aktmoduleswitches) then
  1087. aktmoduleswitches:=aktmoduleswitches-[cs_local_browser];
  1088. { set implementation flag }
  1089. current_module^.in_implementation:=true;
  1090. { insert after the unit symbol tables the static symbol table }
  1091. { of the program }
  1092. st:=new(punitsymtable,init(staticsymtable,current_module^.modulename^));
  1093. current_module^.localsymtable:=st;
  1094. symtablestack:=st;
  1095. refsymtable:=st;
  1096. { necessary for browser }
  1097. loaded_units.insert(current_module);
  1098. { load standard units (system,objpas,profile unit) }
  1099. loaddefaultunits;
  1100. { reset }
  1101. lexlevel:=0;
  1102. {Load the units used by the program we compile.}
  1103. if token=_USES then
  1104. loadunits;
  1105. reset_global_defs;
  1106. {Insert the name of the main program into the symbol table.}
  1107. if current_module^.modulename^<>'' then
  1108. {st^.insert(new(pprogramsym,init(current_module^.modulename^)));}
  1109. st^.insert(new(punitsym,init(current_module^.modulename^,punitsymtable(st))));
  1110. { ...is also constsymtable, this is the symtable where }
  1111. { the elements of enumeration types are inserted }
  1112. constsymtable:=st;
  1113. { Generate a procsym for main }
  1114. gen_main_procsym('main',poproginit,st);
  1115. { reset }
  1116. procprefix:='';
  1117. in_except_block:=false;
  1118. {The program intialization needs an alias, so it can be called
  1119. from the bootstrap code.}
  1120. codegen_newprocedure;
  1121. names.init;
  1122. names.insert('program_init');
  1123. names.insert('PASCALMAIN');
  1124. names.insert(target_os.cprefix+'main');
  1125. {$ifdef m68k}
  1126. if target_info.target=target_m68k_PalmOS then
  1127. names.insert('PilotMain');
  1128. {$endif}
  1129. compile_proc_body(names,true,false);
  1130. names.done;
  1131. { avoid self recursive destructor call !! PM }
  1132. aktprocsym^.definition^.localst:=nil;
  1133. { consider these symbols as global ones }
  1134. { for browser }
  1135. current_module^.globalsymtable:=current_module^.localsymtable;
  1136. current_module^.localsymtable:=nil;
  1137. codegen_doneprocedure;
  1138. { consume the last point }
  1139. consume(POINT);
  1140. {$ifdef New_GDB}
  1141. write_gdb_info;
  1142. {$endIf Def New_GDB}
  1143. { leave when we got an error }
  1144. if (Errorcount>0) and not status.skip_error then
  1145. begin
  1146. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  1147. status.skip_error:=true;
  1148. exit;
  1149. end;
  1150. { generate imports }
  1151. if current_module^.uses_imports then
  1152. importlib^.generatelib;
  1153. if islibrary then
  1154. exportlib^.generatelib;
  1155. { insert heap }
  1156. insertinitfinaltable;
  1157. insertheap;
  1158. inserttargetspecific;
  1159. datasize:=symtablestack^.datasize;
  1160. { finish asmlist by adding segment starts }
  1161. insertsegment;
  1162. { insert own objectfile }
  1163. insertobjectfile;
  1164. { assemble and link }
  1165. create_objectfile;
  1166. { leave when we got an error }
  1167. if (Errorcount>0) and not status.skip_error then
  1168. begin
  1169. Message1(unit_f_errors_in_unit,tostr(Errorcount));
  1170. status.skip_error:=true;
  1171. exit;
  1172. end;
  1173. { create the executable when we are at level 1 }
  1174. if (compile_level=1) then
  1175. begin
  1176. { insert all .o files from all loaded units }
  1177. hp:=pmodule(loaded_units.first);
  1178. while assigned(hp) do
  1179. begin
  1180. Linker.AddModuleFiles(hp);
  1181. hp:=pmodule(hp^.next);
  1182. end;
  1183. { write .def file }
  1184. if (cs_link_deffile in aktglobalswitches) then
  1185. deffile.writefile;
  1186. { finally we can create a executable }
  1187. if (not current_module^.is_unit) then
  1188. Linker.MakeExecutable;
  1189. end;
  1190. end;
  1191. end.
  1192. {
  1193. $Log$
  1194. Revision 1.127 1999-07-05 16:21:27 peter
  1195. * fixed linking for units without linking necessary
  1196. Revision 1.126 1999/07/03 00:29:56 peter
  1197. * new link writing to the ppu, one .ppu is needed for all link types,
  1198. static (.o) is now always created also when smartlinking is used
  1199. Revision 1.125 1999/06/15 13:57:32 peter
  1200. * merged
  1201. Revision 1.124.2.1 1999/06/15 13:54:26 peter
  1202. * don't run ar anymore for binary writer, also not with -CS
  1203. Revision 1.124 1999/05/27 19:44:48 peter
  1204. * removed oldasm
  1205. * plabel -> pasmlabel
  1206. * -a switches to source writing automaticly
  1207. * assembler readers OOPed
  1208. * asmsymbol automaticly external
  1209. * jumptables and other label fixes for asm readers
  1210. Revision 1.123 1999/05/21 13:55:06 peter
  1211. * NEWLAB for label as symbol
  1212. Revision 1.122 1999/05/18 22:36:29 pierre
  1213. * little redondant code removed
  1214. Revision 1.121 1999/05/17 14:43:54 pierre
  1215. * reset current_ppu to nil when appropriate
  1216. Revision 1.120 1999/05/13 21:59:35 peter
  1217. * removed oldppu code
  1218. * warning if objpas is loaded from uses
  1219. * first things for new deref writing
  1220. Revision 1.119 1999/05/09 11:38:08 peter
  1221. * don't write .o and link if errors occure during assembling
  1222. Revision 1.118 1999/05/03 18:03:28 peter
  1223. * no ar.exe running field in target_asm
  1224. Revision 1.117 1999/05/01 13:24:32 peter
  1225. * merged nasm compiler
  1226. * old asm moved to oldasm/
  1227. Revision 1.116 1999/04/26 23:22:42 peter
  1228. * fixed double .o file insertion
  1229. Revision 1.115 1999/04/26 18:29:58 peter
  1230. * farpointerdef moved into pointerdef.is_far
  1231. Revision 1.114 1999/04/26 13:31:39 peter
  1232. * release storenumber,double_checksum
  1233. Revision 1.113 1999/04/25 17:32:14 peter
  1234. * fixed double_checksum
  1235. Revision 1.112 1999/04/25 15:08:38 peter
  1236. * small fixes for double_checksum
  1237. Revision 1.111 1999/04/21 09:43:46 peter
  1238. * storenumber works
  1239. * fixed some typos in double_checksum
  1240. + incompatible types type1 and type2 message (with storenumber)
  1241. Revision 1.110 1999/04/17 13:14:52 peter
  1242. * concat_external added for new init/final
  1243. Revision 1.109 1999/04/15 12:19:59 peter
  1244. + finalization support
  1245. Revision 1.108 1999/04/14 09:14:52 peter
  1246. * first things to store the symbol/def number in the ppu
  1247. Revision 1.107 1999/04/08 10:53:54 michael
  1248. * Fixed forgotten ;
  1249. Revision 1.106 1999/04/07 15:39:30 pierre
  1250. + double_checksum code added
  1251. Revision 1.105 1999/03/26 00:05:38 peter
  1252. * released valintern
  1253. + deffile is now removed when compiling is finished
  1254. * ^( compiles now correct
  1255. + static directive
  1256. * shrd fixed
  1257. Revision 1.104 1999/03/24 23:17:17 peter
  1258. * fixed bugs 212,222,225,227,229,231,233
  1259. Revision 1.103 1999/03/18 20:30:46 peter
  1260. + .a writer
  1261. Revision 1.102 1999/03/16 21:07:25 peter
  1262. * check for dup uses
  1263. Revision 1.101 1999/02/25 21:02:43 peter
  1264. * ag386bin updates
  1265. + coff writer
  1266. Revision 1.100 1999/02/23 18:29:20 pierre
  1267. * win32 compilation error fix
  1268. + some work for local browser (not cl=omplete yet)
  1269. Revision 1.99 1999/02/22 13:06:58 pierre
  1270. + -b and -bl options work !
  1271. + cs_local_browser ($L+) is disabled if cs_browser ($Y+)
  1272. is not enabled when quitting global section
  1273. * local vars and procedures are not yet stored into PPU
  1274. Revision 1.98 1999/02/22 02:15:29 peter
  1275. * updates for ag386bin
  1276. Revision 1.97 1999/02/16 00:45:31 peter
  1277. * fixed crashes by forgotten strpnew() for init_symbol
  1278. Revision 1.96 1999/02/05 08:54:27 pierre
  1279. + linkofiles splitted inot linkofiles and linkunitfiles
  1280. because linkofiles must be stored with directory
  1281. to enabled linking of different objects with same name
  1282. in a different directory
  1283. Revision 1.95 1999/02/03 09:44:36 pierre
  1284. * symbol nubering begins with 1 in number_symbols
  1285. * program tmodule has globalsymtable for its staticsymtable
  1286. (to get it displayed in IDE globals list)
  1287. + list of symbol (browcol) greatly improved for IDE
  1288. Revision 1.94 1999/01/12 14:25:31 peter
  1289. + BrowserLog for browser.log generation
  1290. + BrowserCol for browser info in TCollections
  1291. * released all other UseBrowser
  1292. Revision 1.93 1999/01/06 12:39:46 peter
  1293. * renamed resource -> comprsrc (conflicted with FV)
  1294. Revision 1.92 1998/12/28 23:26:23 peter
  1295. + resource file handling ($R directive) for Win32
  1296. Revision 1.91 1998/12/15 17:14:17 peter
  1297. * fix for tp7
  1298. Revision 1.90 1998/12/15 10:23:26 peter
  1299. + -iSO, -iSP, -iTO, -iTP
  1300. Revision 1.89 1998/12/11 00:03:34 peter
  1301. + globtype,tokens,version unit splitted from globals
  1302. Revision 1.88 1998/12/08 10:18:11 peter
  1303. + -gh for heaptrc unit
  1304. Revision 1.87 1998/12/01 23:40:53 pierre
  1305. * new try for correct debug info generation
  1306. Revision 1.86 1998/11/30 09:43:22 pierre
  1307. * some range check bugs fixed (still not working !)
  1308. + added DLL writing support for win32 (also accepts variables)
  1309. + TempAnsi for code that could be used for Temporary ansi strings
  1310. handling
  1311. Revision 1.85 1998/11/28 16:20:54 peter
  1312. + support for dll variables
  1313. Revision 1.84 1998/11/18 09:18:03 pierre
  1314. + automatic loading of profile unit with -pg option
  1315. in go32v2 mode (also defines FPC_PROFILE)
  1316. * some memory leaks removed
  1317. * unreleased temp problem with sets solved
  1318. Revision 1.83 1998/11/16 11:29:00 pierre
  1319. * stackcheck removed for i386_win32
  1320. * exportlist does not crash at least !!
  1321. (was need for tests dir !)z
  1322. Revision 1.82 1998/11/12 12:55:16 pierre
  1323. * fix for bug0176 and bug0177
  1324. Revision 1.81 1998/11/12 11:34:58 peter
  1325. * fix for empty .o files and linking of libs
  1326. Revision 1.80 1998/11/06 09:48:14 pierre
  1327. * double initialization code calling bug fixed
  1328. Revision 1.79 1998/11/03 11:33:11 peter
  1329. + search_unit arg to only search for sources
  1330. Revision 1.78 1998/10/30 12:23:41 peter
  1331. * fix for lognunitname and longunit.pas
  1332. Revision 1.77 1998/10/29 11:35:52 florian
  1333. * some dll support for win32
  1334. * fixed assembler writing for PalmOS
  1335. Revision 1.76 1998/10/28 18:26:15 pierre
  1336. * removed some erros after other errors (introduced by useexcept)
  1337. * stabs works again correctly (for how long !)
  1338. Revision 1.75 1998/10/27 13:45:35 pierre
  1339. * classes get a vmt allways
  1340. * better error info (tried to remove
  1341. several error strings introduced by the tpexcept handling)
  1342. Revision 1.74 1998/10/26 09:34:50 peter
  1343. * unit check name works now for all units, not only systemunit
  1344. Revision 1.73 1998/10/22 23:53:27 peter
  1345. * leave when an error has been in the interface (else other units could
  1346. be compiled with the implementation uses!)
  1347. * don't always compile when not in implementation with a second_load
  1348. Revision 1.72 1998/10/22 11:36:34 peter
  1349. * fixed imports generation at the wrong place
  1350. Revision 1.71 1998/10/21 20:13:10 peter
  1351. * check for importsection for empty asm file
  1352. Revision 1.70 1998/10/20 09:30:05 peter
  1353. * set also in_library flag when no .o is generated
  1354. Revision 1.68 1998/10/19 08:54:59 pierre
  1355. * wrong stabs info corrected once again !!
  1356. + variable vmt offset with vmt field only if required
  1357. implemented now !!!
  1358. Revision 1.67 1998/10/13 13:10:25 peter
  1359. * new style for m68k/i386 infos and enums
  1360. Revision 1.66 1998/10/09 16:36:05 pierre
  1361. * some memory leaks specific to usebrowser define fixed
  1362. * removed tmodule.implsymtable (was like tmodule.localsymtable)
  1363. Revision 1.65 1998/10/09 14:38:55 pierre
  1364. * add a second load for PPU file
  1365. Revision 1.64 1998/10/09 08:56:28 pierre
  1366. * several memory leaks fixed
  1367. Revision 1.63 1998/10/08 23:29:01 peter
  1368. * -vu shows unit info, -vt shows tried/used files
  1369. Revision 1.62 1998/10/08 17:17:25 pierre
  1370. * current_module old scanner tagged as invalid if unit is recompiled
  1371. + added ppheap for better info on tracegetmem of heaptrc
  1372. (adds line column and file index)
  1373. * several memory leaks removed ith help of heaptrc !!
  1374. Revision 1.61 1998/10/08 13:48:47 peter
  1375. * fixed memory leaks for do nothing source
  1376. * fixed unit interdependency
  1377. Revision 1.60 1998/10/06 17:16:54 pierre
  1378. * some memory leaks fixed (thanks to Peter for heaptrc !)
  1379. Revision 1.59 1998/10/05 21:33:26 peter
  1380. * fixed 161,165,166,167,168
  1381. Revision 1.58 1998/09/30 16:43:37 peter
  1382. * fixed unit interdependency with circular uses
  1383. Revision 1.57 1998/09/30 12:11:52 peter
  1384. * fixed circular uses which looped forever
  1385. Revision 1.56 1998/09/28 11:22:15 pierre
  1386. * did not compile for browser
  1387. * merge from fixes
  1388. Revision 1.48.2.1 1998/09/28 10:55:16 pierre
  1389. fix for current_module dispose bug
  1390. Revision 1.55 1998/09/28 11:04:03 peter
  1391. * fixed loaddefaultunits which was at the wrong place for programs, so
  1392. the default defs were not loaded when main was initialized
  1393. Revision 1.54 1998/09/24 23:49:12 peter
  1394. + aktmodeswitches
  1395. Revision 1.53 1998/09/23 12:20:50 pierre
  1396. * main program tmodule had no symtable (crashed browser)
  1397. * unit symbols problem fixed !!
  1398. Revision 1.52 1998/09/22 17:13:49 pierre
  1399. + browsing updated and developed
  1400. records and objects fields are also stored
  1401. Revision 1.51 1998/09/22 15:40:55 peter
  1402. * some extra ifdef GDB
  1403. Revision 1.50 1998/09/21 08:45:17 pierre
  1404. + added vmt_offset in tobjectdef.write for fututre use
  1405. (first steps to have objects without vmt if no virtual !!)
  1406. + added fpu_used field for tabstractprocdef :
  1407. sets this level to 2 if the functions return with value in FPU
  1408. (is then set to correct value at parsing of implementation)
  1409. THIS MIGHT refuse some code with FPU expression too complex
  1410. that were accepted before and even in some cases
  1411. that don't overflow in fact
  1412. ( like if f : float; is a forward that finally in implementation
  1413. only uses one fpu register !!)
  1414. Nevertheless I think that it will improve security on
  1415. FPU operations !!
  1416. * most other changes only for UseBrowser code
  1417. (added symtable references for record and objects)
  1418. local switch for refs to args and local of each function
  1419. (static symtable still missing)
  1420. UseBrowser still not stable and probably broken by
  1421. the definition hash array !!
  1422. Revision 1.49 1998/09/18 08:01:36 pierre
  1423. + improvement on the usebrowser part
  1424. (does not work correctly for now)
  1425. Revision 1.48 1998/09/09 15:33:07 peter
  1426. * fixed in_global to allow directives also after interface token
  1427. Revision 1.47 1998/09/09 11:50:55 pierre
  1428. * forward def are not put in record or objects
  1429. + added check for forwards also in record and objects
  1430. * dummy parasymtable for unit initialization removed from
  1431. symtable stack
  1432. Revision 1.46 1998/09/03 11:24:01 peter
  1433. * moved more inputfile things from tscannerfile to tinputfile
  1434. * changed ifdef Sourceline to cs_asm_source
  1435. Revision 1.45 1998/08/31 12:26:28 peter
  1436. * m68k and palmos updates from surebugfixes
  1437. Revision 1.44 1998/08/26 15:35:33 peter
  1438. * fixed scannerfiles for macros
  1439. + $I %<environment>%
  1440. Revision 1.43 1998/08/26 10:08:47 peter
  1441. * fixed problem with libprefix at the wrong place
  1442. * fixed lib generation with smartlinking and no -CS used
  1443. Revision 1.42 1998/08/19 18:04:54 peter
  1444. * fixed current_module^.in_implementation flag
  1445. Revision 1.41 1998/08/17 10:10:08 peter
  1446. - removed OLDPPU
  1447. Revision 1.40 1998/08/17 09:17:50 peter
  1448. * static/shared linking updates
  1449. Revision 1.39 1998/08/14 21:56:37 peter
  1450. * setting the outputfile using -o works now to create static libs
  1451. Revision 1.38 1998/08/10 14:50:13 peter
  1452. + localswitches, moduleswitches, globalswitches splitting
  1453. Revision 1.37 1998/08/10 10:18:31 peter
  1454. + Compiler,Comphook unit which are the new interface units to the
  1455. compiler
  1456. Revision 1.36 1998/07/14 14:46:54 peter
  1457. * released NEWINPUT
  1458. Revision 1.35 1998/07/08 12:39:38 peter
  1459. * heap_size for m68k
  1460. Revision 1.34 1998/07/07 11:20:03 peter
  1461. + NEWINPUT for a better inputfile and scanner object
  1462. Revision 1.33 1998/06/25 11:15:34 pierre
  1463. * ppu files where not closed in newppu !!
  1464. second compilation was impossible due to too many opened files
  1465. (not visible in 'make cycle' as we remove all the ppu files)
  1466. Revision 1.32 1998/06/25 08:48:16 florian
  1467. * first version of rtti support
  1468. Revision 1.31 1998/06/24 14:48:35 peter
  1469. * ifdef newppu -> ifndef oldppu
  1470. Revision 1.30 1998/06/17 14:10:16 peter
  1471. * small os2 fixes
  1472. * fixed interdependent units with newppu (remake3 under linux works now)
  1473. Revision 1.29 1998/06/16 08:56:25 peter
  1474. + targetcpu
  1475. * cleaner pmodules for newppu
  1476. Revision 1.28 1998/06/13 00:10:10 peter
  1477. * working browser and newppu
  1478. * some small fixes against crashes which occured in bp7 (but not in
  1479. fpc?!)
  1480. Revision 1.27 1998/06/11 13:58:08 peter
  1481. * small fix to let newppu compile
  1482. Revision 1.26 1998/06/09 16:01:47 pierre
  1483. + added procedure directive parsing for procvars
  1484. (accepted are popstack cdecl and pascal)
  1485. + added C vars with the following syntax
  1486. var C calias 'true_c_name';(can be followed by external)
  1487. reason is that you must add the Cprefix
  1488. which is target dependent
  1489. Revision 1.25 1998/06/08 22:59:49 peter
  1490. * smartlinking works for win32
  1491. * some defines to exclude some compiler parts
  1492. Revision 1.24 1998/06/08 13:13:44 pierre
  1493. + temporary variables now in temp_gen.pas unit
  1494. because it is processor independent
  1495. * mppc68k.bat modified to undefine i386 and support_mmx
  1496. (which are defaults for i386)
  1497. Revision 1.23 1998/06/05 17:47:29 peter
  1498. * some better uses clauses
  1499. Revision 1.22 1998/06/05 14:37:34 pierre
  1500. * fixes for inline for operators
  1501. * inline procedure more correctly restricted
  1502. Revision 1.21 1998/06/04 23:51:53 peter
  1503. * m68k compiles
  1504. + .def file creation moved to gendef.pas so it could also be used
  1505. for win32
  1506. Revision 1.20 1998/06/04 09:55:42 pierre
  1507. * demangled name of procsym reworked to become independant of the mangling scheme
  1508. Revision 1.19 1998/06/03 23:40:38 peter
  1509. + unlimited file support, release tempclose
  1510. Revision 1.18 1998/06/03 22:49:00 peter
  1511. + wordbool,longbool
  1512. * rename bis,von -> high,low
  1513. * moved some systemunit loading/creating to psystem.pas
  1514. Revision 1.17 1998/05/28 14:40:25 peter
  1515. * fixes for newppu, remake3 works now with it
  1516. Revision 1.16 1998/05/27 19:45:06 peter
  1517. * symtable.pas splitted into includefiles
  1518. * symtable adapted for $ifdef NEWPPU
  1519. Revision 1.15 1998/05/23 01:21:22 peter
  1520. + aktasmmode, aktoptprocessor, aktoutputformat
  1521. + smartlink per module $SMARTLINK-/+ (like MMX) and moved to aktswitches
  1522. + $LIBNAME to set the library name where the unit will be put in
  1523. * splitted cgi386 a bit (codeseg to large for bp7)
  1524. * nasm, tasm works again. nasm moved to ag386nsm.pas
  1525. Revision 1.14 1998/05/20 09:42:35 pierre
  1526. + UseTokenInfo now default
  1527. * unit in interface uses and implementation uses gives error now
  1528. * only one error for unknown symbol (uses lastsymknown boolean)
  1529. the problem came from the label code !
  1530. + first inlined procedures and function work
  1531. (warning there might be allowed cases were the result is still wrong !!)
  1532. * UseBrower updated gives a global list of all position of all used symbols
  1533. with switch -gb
  1534. Revision 1.13 1998/05/12 10:47:00 peter
  1535. * moved printstatus to verb_def
  1536. + V_Normal which is between V_Error and V_Warning and doesn't have a
  1537. prefix like error: warning: and is included in V_Default
  1538. * fixed some messages
  1539. * first time parameter scan is only for -v and -T
  1540. - removed old style messages
  1541. Revision 1.12 1998/05/11 13:07:56 peter
  1542. + $ifdef NEWPPU for the new ppuformat
  1543. + $define GDB not longer required
  1544. * removed all warnings and stripped some log comments
  1545. * no findfirst/findnext anymore to remove smartlink *.o files
  1546. Revision 1.11 1998/05/06 18:36:53 peter
  1547. * tai_section extended with code,data,bss sections and enumerated type
  1548. * ident 'compiled by FPC' moved to pmodules
  1549. * small fix for smartlink
  1550. Revision 1.10 1998/05/04 17:54:28 peter
  1551. + smartlinking works (only case jumptable left todo)
  1552. * redesign of systems.pas to support assemblers and linkers
  1553. + Unitname is now also in the PPU-file, increased version to 14
  1554. Revision 1.9 1998/05/01 16:38:45 florian
  1555. * handling of private and protected fixed
  1556. + change_keywords_to_tp implemented to remove
  1557. keywords which aren't supported by tp
  1558. * break and continue are now symbols of the system unit
  1559. + widestring, longstring and ansistring type released
  1560. Revision 1.8 1998/04/30 15:59:41 pierre
  1561. * GDB works again better :
  1562. correct type info in one pass
  1563. + UseTokenInfo for better source position
  1564. * fixed one remaining bug in scanner for line counts
  1565. * several little fixes
  1566. Revision 1.7 1998/04/29 10:33:59 pierre
  1567. + added some code for ansistring (not complete nor working yet)
  1568. * corrected operator overloading
  1569. * corrected nasm output
  1570. + started inline procedures
  1571. + added starstarn : use ** for exponentiation (^ gave problems)
  1572. + started UseTokenInfo cond to get accurate positions
  1573. Revision 1.6 1998/04/27 23:10:28 peter
  1574. + new scanner
  1575. * $makelib -> if smartlink
  1576. * small filename fixes pmodule.setfilename
  1577. * moved import from files.pas -> import.pas
  1578. Revision 1.5 1998/04/14 23:27:03 florian
  1579. + exclude/include with constant second parameter added
  1580. Revision 1.4 1998/04/10 14:41:43 peter
  1581. * removed some Hints
  1582. * small speed optimization for AsmLn
  1583. Revision 1.3 1998/04/03 09:51:00 daniel
  1584. * Fixed heap allocation for OS/2.
  1585. }