pmodules.pas 62 KB

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