ncgflw.pas 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Generate assembler for nodes that influence the flow which are
  5. the same for all (most?) processors
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. unit ncgflw;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. node,nflw;
  24. type
  25. tcgwhilerepeatnode = class(twhilerepeatnode)
  26. procedure pass_2;override;
  27. end;
  28. tcgifnode = class(tifnode)
  29. procedure pass_2;override;
  30. end;
  31. tcgfornode = class(tfornode)
  32. procedure pass_2;override;
  33. end;
  34. tcgexitnode = class(texitnode)
  35. procedure pass_2;override;
  36. end;
  37. tcgbreaknode = class(tbreaknode)
  38. procedure pass_2;override;
  39. end;
  40. tcgcontinuenode = class(tcontinuenode)
  41. procedure pass_2;override;
  42. end;
  43. tcggotonode = class(tgotonode)
  44. procedure pass_2;override;
  45. end;
  46. tcglabelnode = class(tlabelnode)
  47. procedure pass_2;override;
  48. end;
  49. tcgraisenode = class(traisenode)
  50. procedure pass_2;override;
  51. end;
  52. tcgtryexceptnode = class(ttryexceptnode)
  53. procedure pass_2;override;
  54. end;
  55. tcgtryfinallynode = class(ttryfinallynode)
  56. procedure pass_2;override;
  57. end;
  58. tcgonnode = class(tonnode)
  59. procedure pass_2;override;
  60. end;
  61. implementation
  62. uses
  63. verbose,globals,systems,globtype,
  64. symconst,symsym,aasmbase,aasmtai,aasmcpu,defutil,
  65. cginfo,cgbase,pass_2,
  66. cpubase,cpuinfo,
  67. nld,ncon,
  68. ncgutil,
  69. tgobj,rgobj,paramgr,
  70. regvars,cgobj
  71. {$ifndef cpu64bit}
  72. ,cg64f32
  73. {$endif cpu64bit}
  74. ;
  75. const
  76. EXCEPT_BUF_SIZE = 12;
  77. {*****************************************************************************
  78. Second_While_RepeatN
  79. *****************************************************************************}
  80. procedure tcgwhilerepeatnode.pass_2;
  81. var
  82. lcont,lbreak,lloop,
  83. oldclabel,oldblabel : tasmlabel;
  84. otlabel,oflabel : tasmlabel;
  85. begin
  86. location_reset(location,LOC_VOID,OS_NO);
  87. objectlibrary.getlabel(lloop);
  88. objectlibrary.getlabel(lcont);
  89. objectlibrary.getlabel(lbreak);
  90. { arrange continue and breaklabels: }
  91. oldclabel:=aktcontinuelabel;
  92. oldblabel:=aktbreaklabel;
  93. load_all_regvars(exprasmlist);
  94. { handling code at the end as it is much more efficient, and makes
  95. while equal to repeat loop, only the end true/false is swapped (PFV) }
  96. if lnf_testatbegin in loopflags then
  97. cg.a_jmp_always(exprasmlist,lcont);
  98. if not(cs_littlesize in aktglobalswitches) then
  99. { align loop target }
  100. exprasmList.concat(Tai_align.Create(aktalignment.loopalign));
  101. cg.a_label(exprasmlist,lloop);
  102. aktcontinuelabel:=lcont;
  103. aktbreaklabel:=lbreak;
  104. {$ifndef newra}
  105. rg.cleartempgen;
  106. {$endif}
  107. if assigned(right) then
  108. secondpass(right);
  109. load_all_regvars(exprasmlist);
  110. cg.a_label(exprasmlist,lcont);
  111. otlabel:=truelabel;
  112. oflabel:=falselabel;
  113. if lnf_checknegate in loopflags then
  114. begin
  115. truelabel:=lbreak;
  116. falselabel:=lloop;
  117. end
  118. else
  119. begin
  120. truelabel:=lloop;
  121. falselabel:=lbreak;
  122. end;
  123. {$ifndef newra}
  124. rg.cleartempgen;
  125. {$endif}
  126. secondpass(left);
  127. maketojumpbool(exprasmlist,left,lr_load_regvars);
  128. cg.a_label(exprasmlist,lbreak);
  129. truelabel:=otlabel;
  130. falselabel:=oflabel;
  131. aktcontinuelabel:=oldclabel;
  132. aktbreaklabel:=oldblabel;
  133. { a break/continue in a while/repeat block can't be seen outside }
  134. flowcontrol:=flowcontrol-[fc_break,fc_continue];
  135. end;
  136. {*****************************************************************************
  137. tcgIFNODE
  138. *****************************************************************************}
  139. procedure tcgifnode.pass_2;
  140. var
  141. hl,otlabel,oflabel : tasmlabel;
  142. org_regvar_loaded_other,
  143. then_regvar_loaded_other,
  144. else_regvar_loaded_other : regvarother_booleanarray;
  145. org_regvar_loaded_int,
  146. then_regvar_loaded_int,
  147. else_regvar_loaded_int : Tsupregset;
  148. org_list,
  149. then_list,
  150. else_list : taasmoutput;
  151. begin
  152. location_reset(location,LOC_VOID,OS_NO);
  153. otlabel:=truelabel;
  154. oflabel:=falselabel;
  155. objectlibrary.getlabel(truelabel);
  156. objectlibrary.getlabel(falselabel);
  157. {$ifndef newra}
  158. rg.cleartempgen;
  159. {$endif}
  160. secondpass(left);
  161. { save regvars loaded in the beginning so that we can restore them }
  162. { when processing the else-block }
  163. if cs_regalloc in aktglobalswitches then
  164. begin
  165. org_list := exprasmlist;
  166. exprasmlist := taasmoutput.create;
  167. end;
  168. maketojumpbool(exprasmlist,left,lr_dont_load_regvars);
  169. if cs_regalloc in aktglobalswitches then
  170. begin
  171. org_regvar_loaded_int := rg.regvar_loaded_int;
  172. org_regvar_loaded_other := rg.regvar_loaded_other;
  173. end;
  174. if assigned(right) then
  175. begin
  176. cg.a_label(exprasmlist,truelabel);
  177. {$ifndef newra}
  178. rg.cleartempgen;
  179. {$endif}
  180. secondpass(right);
  181. end;
  182. { save current asmlist (previous instructions + then-block) and }
  183. { loaded regvar state and create new clean ones }
  184. if cs_regalloc in aktglobalswitches then
  185. begin
  186. then_regvar_loaded_int := rg.regvar_loaded_int;
  187. then_regvar_loaded_other := rg.regvar_loaded_other;
  188. rg.regvar_loaded_int := org_regvar_loaded_int;
  189. rg.regvar_loaded_other := org_regvar_loaded_other;
  190. then_list := exprasmlist;
  191. exprasmlist := taasmoutput.create;
  192. end;
  193. if assigned(t1) then
  194. begin
  195. if assigned(right) then
  196. begin
  197. objectlibrary.getlabel(hl);
  198. { do go back to if line !! }
  199. if not(cs_regalloc in aktglobalswitches) then
  200. aktfilepos:=exprasmList.getlasttaifilepos^
  201. else
  202. aktfilepos:=then_list.getlasttaifilepos^;
  203. cg.a_jmp_always(exprasmlist,hl);
  204. end;
  205. cg.a_label(exprasmlist,falselabel);
  206. {$ifndef newra}
  207. rg.cleartempgen;
  208. {$endif}
  209. secondpass(t1);
  210. { save current asmlist (previous instructions + else-block) }
  211. { and loaded regvar state and create a new clean list }
  212. if cs_regalloc in aktglobalswitches then
  213. begin
  214. else_regvar_loaded_int := rg.regvar_loaded_int;
  215. else_regvar_loaded_other := rg.regvar_loaded_other;
  216. else_list := exprasmlist;
  217. exprasmlist := taasmoutput.create;
  218. end;
  219. if assigned(right) then
  220. cg.a_label(exprasmlist,hl);
  221. end
  222. else
  223. begin
  224. if cs_regalloc in aktglobalswitches then
  225. begin
  226. else_regvar_loaded_int := rg.regvar_loaded_int;
  227. else_regvar_loaded_other := rg.regvar_loaded_other;
  228. else_list := exprasmlist;
  229. exprasmlist := taasmoutput.create;
  230. end;
  231. cg.a_label(exprasmlist,falselabel);
  232. end;
  233. if not(assigned(right)) then
  234. begin
  235. cg.a_label(exprasmlist,truelabel);
  236. end;
  237. if cs_regalloc in aktglobalswitches then
  238. begin
  239. { add loads of regvars at the end of the then- and else-blocks }
  240. { so that at the end of both blocks the same regvars are loaded }
  241. { no else block? }
  242. if not assigned(t1) then
  243. begin
  244. sync_regvars_int(org_list,then_list,org_regvar_loaded_int,then_regvar_loaded_int);
  245. sync_regvars_other(org_list,then_list,org_regvar_loaded_other,then_regvar_loaded_other);
  246. end
  247. { no then block? }
  248. else if not assigned(right) then
  249. begin
  250. sync_regvars_int(org_list,else_list,org_regvar_loaded_int,else_regvar_loaded_int);
  251. sync_regvars_other(org_list,else_list,org_regvar_loaded_other,else_regvar_loaded_other);
  252. end
  253. { both else and then blocks }
  254. else
  255. begin
  256. sync_regvars_int(then_list,else_list,then_regvar_loaded_int,else_regvar_loaded_int);
  257. sync_regvars_other(then_list,else_list,then_regvar_loaded_other,else_regvar_loaded_other);
  258. end;
  259. { add all lists together }
  260. org_list.concatlist(then_list);
  261. then_list.free;
  262. org_list.concatlist(else_list);
  263. else_list.free;
  264. org_list.concatlist(exprasmlist);
  265. exprasmlist.free;
  266. exprasmlist := org_list;
  267. end;
  268. truelabel:=otlabel;
  269. falselabel:=oflabel;
  270. end;
  271. {*****************************************************************************
  272. SecondFor
  273. *****************************************************************************}
  274. procedure tcgfornode.pass_2;
  275. var
  276. l3,oldclabel,oldblabel : tasmlabel;
  277. temptovalue : boolean;
  278. hs : byte;
  279. temp1 : treference;
  280. hop : topcg;
  281. hcond : topcmp;
  282. opsize : tcgsize;
  283. count_var_is_signed,do_loopvar_at_end : boolean;
  284. cmp_const:Tconstexprint;
  285. begin
  286. location_reset(location,LOC_VOID,OS_NO);
  287. oldclabel:=aktcontinuelabel;
  288. oldblabel:=aktbreaklabel;
  289. objectlibrary.getlabel(aktcontinuelabel);
  290. objectlibrary.getlabel(aktbreaklabel);
  291. objectlibrary.getlabel(l3);
  292. { only calculate reference }
  293. {$ifndef newra}
  294. rg.cleartempgen;
  295. {$endif}
  296. secondpass(t2);
  297. hs := t2.resulttype.def.size;
  298. opsize := def_cgsize(t2.resulttype.def);
  299. { first set the to value
  300. because the count var can be in the expression !! }
  301. {$ifndef newra}
  302. rg.cleartempgen;
  303. {$endif}
  304. do_loopvar_at_end:=lnf_dont_mind_loopvar_on_exit in loopflags;
  305. secondpass(right);
  306. { calculate pointer value and check if changeable and if so }
  307. { load into temporary variable }
  308. if right.nodetype<>ordconstn then
  309. begin
  310. do_loopvar_at_end:=false;
  311. tg.GetTemp(exprasmlist,hs,tt_normal,temp1);
  312. temptovalue:=true;
  313. if (right.location.loc=LOC_REGISTER) or
  314. (right.location.loc=LOC_CREGISTER) then
  315. begin
  316. cg.a_load_reg_ref(exprasmlist,opsize,
  317. right.location.register,temp1);
  318. rg.ungetregisterint(exprasmlist,right.location.register);
  319. end
  320. else
  321. cg.g_concatcopy(exprasmlist,right.location.reference,temp1,
  322. hs,true,false);
  323. end
  324. else
  325. temptovalue:=false;
  326. { produce start assignment }
  327. {$ifndef newra}
  328. rg.cleartempgen;
  329. {$endif}
  330. secondpass(left);
  331. count_var_is_signed:=is_signed(t2.resulttype.def);
  332. if lnf_backward in loopflags then
  333. if count_var_is_signed then
  334. hcond:=OC_LT
  335. else
  336. hcond:=OC_B
  337. else
  338. if count_var_is_signed then
  339. hcond:=OC_GT
  340. else
  341. hcond:=OC_A;
  342. load_all_regvars(exprasmlist);
  343. if temptovalue then
  344. begin
  345. cg.a_cmp_ref_loc_label(exprasmlist,opsize,hcond,
  346. temp1,t2.location,aktbreaklabel);
  347. end
  348. else
  349. begin
  350. if lnf_testatbegin in loopflags then
  351. begin
  352. cg.a_cmp_const_loc_label(exprasmlist,opsize,hcond,
  353. aword(tordconstnode(right).value),
  354. t2.location,aktbreaklabel);
  355. end;
  356. end;
  357. {If the loopvar doesn't mind on exit, we avoid this ugly
  358. dec instruction and do the loopvar inc/dec after the loop
  359. body.}
  360. if not do_loopvar_at_end then
  361. begin
  362. if lnf_backward in loopflags then
  363. hop:=OP_ADD
  364. else
  365. hop:=OP_SUB;
  366. cg.a_op_const_loc(exprasmlist,hop,1,t2.location);
  367. end;
  368. if not(cs_littlesize in aktglobalswitches) then
  369. { align loop target }
  370. exprasmList.concat(Tai_align.Create(aktalignment.loopalign));
  371. cg.a_label(exprasmlist,l3);
  372. {If the loopvar doesn't mind on exit, we avoid the loopvar inc/dec
  373. after the loop body instead of here.}
  374. if not do_loopvar_at_end then
  375. begin
  376. { according to count direction DEC or INC... }
  377. if lnf_backward in loopflags then
  378. hop:=OP_SUB
  379. else
  380. hop:=OP_ADD;
  381. cg.a_op_const_loc(exprasmlist,hop,1,t2.location);
  382. end;
  383. { help register must not be in instruction block }
  384. {$ifndef newra}
  385. rg.cleartempgen;
  386. {$endif}
  387. if assigned(t1) then
  388. begin
  389. secondpass(t1);
  390. load_all_regvars(exprasmlist);
  391. end;
  392. {If the loopvar doesn't mind on exit, we do the loopvar inc/dec
  393. after the loop body instead of here.}
  394. if do_loopvar_at_end then
  395. begin
  396. { according to count direction DEC or INC... }
  397. if lnf_backward in loopflags then
  398. hop:=OP_SUB
  399. else
  400. hop:=OP_ADD;
  401. cg.a_op_const_loc(exprasmlist,hop,1,t2.location);
  402. end;
  403. cg.a_label(exprasmlist,aktcontinuelabel);
  404. { makes no problems there }
  405. {$ifndef newra}
  406. rg.cleartempgen;
  407. {$endif}
  408. if do_loopvar_at_end then
  409. if lnf_backward in loopflags then
  410. if count_var_is_signed then
  411. hcond:=OC_GTE
  412. else
  413. hcond:=OC_AE
  414. else
  415. if count_var_is_signed then
  416. hcond:=OC_LTE
  417. else
  418. hcond:=OC_BE
  419. else
  420. if lnf_backward in loopflags then
  421. if count_var_is_signed then
  422. hcond:=OC_GT
  423. else
  424. hcond:=OC_A
  425. else
  426. if count_var_is_signed then
  427. hcond:=OC_LT
  428. else
  429. hcond:=OC_B;
  430. load_all_regvars(exprasmlist);
  431. cmp_const:=aword(Tordconstnode(right).value);
  432. if do_loopvar_at_end then
  433. begin
  434. {Watch out for wrap around 255 -> 0.}
  435. {Ugly: This code is way to long... Use tables?}
  436. case opsize of
  437. OS_8:
  438. begin
  439. if lnf_backward in loopflags then
  440. begin
  441. if byte(cmp_const)=low(byte) then
  442. begin
  443. hcond:=OC_NE;
  444. cmp_const:=high(byte);
  445. end
  446. end
  447. else
  448. begin
  449. if byte(cmp_const)=high(byte) then
  450. begin
  451. hcond:=OC_NE;
  452. cmp_const:=low(byte);
  453. end
  454. end
  455. end;
  456. OS_16:
  457. begin
  458. if lnf_backward in loopflags then
  459. begin
  460. if word(cmp_const)=high(word) then
  461. begin
  462. hcond:=OC_NE;
  463. cmp_const:=low(word);
  464. end
  465. end
  466. else
  467. begin
  468. if word(cmp_const)=low(word) then
  469. begin
  470. hcond:=OC_NE;
  471. cmp_const:=high(word);
  472. end
  473. end
  474. end;
  475. OS_32:
  476. begin
  477. if lnf_backward in loopflags then
  478. begin
  479. if cardinal(cmp_const)=high(cardinal) then
  480. begin
  481. hcond:=OC_NE;
  482. cmp_const:=low(cardinal);
  483. end
  484. end
  485. else
  486. begin
  487. if cardinal(cmp_const)=low(cardinal) then
  488. begin
  489. hcond:=OC_NE;
  490. cmp_const:=high(cardinal);
  491. end
  492. end
  493. end;
  494. OS_64:
  495. begin
  496. if lnf_backward in loopflags then
  497. begin
  498. if qword(cmp_const)=high(qword) then
  499. begin
  500. hcond:=OC_NE;
  501. cmp_const:=low(qword);
  502. end
  503. end
  504. else
  505. begin
  506. if qword(cmp_const)=low(qword) then
  507. begin
  508. hcond:=OC_NE;
  509. cmp_const:=high(qword);
  510. end
  511. end
  512. end;
  513. OS_S8:
  514. begin
  515. if lnf_backward in loopflags then
  516. begin
  517. if shortint(cmp_const)=low(shortint) then
  518. begin
  519. hcond:=OC_NE;
  520. cmp_const:=high(shortint);
  521. end
  522. end
  523. else
  524. begin
  525. if shortint(cmp_const)=high(shortint) then
  526. begin
  527. hcond:=OC_NE;
  528. cmp_const:=low(shortint);
  529. end
  530. end
  531. end;
  532. OS_S16:
  533. begin
  534. if lnf_backward in loopflags then
  535. begin
  536. if integer(cmp_const)=high(integer) then
  537. begin
  538. hcond:=OC_NE;
  539. cmp_const:=low(integer);
  540. end
  541. end
  542. else
  543. begin
  544. if integer(cmp_const)=low(integer) then
  545. begin
  546. hcond:=OC_NE;
  547. cmp_const:=high(integer);
  548. end
  549. end
  550. end;
  551. OS_S32:
  552. begin
  553. if lnf_backward in loopflags then
  554. begin
  555. if longint(cmp_const)=high(longint) then
  556. begin
  557. hcond:=OC_NE;
  558. cmp_const:=low(longint);
  559. end
  560. end
  561. else
  562. begin
  563. if longint(cmp_const)=low(longint) then
  564. begin
  565. hcond:=OC_NE;
  566. cmp_const:=high(longint);
  567. end
  568. end
  569. end;
  570. OS_S64:
  571. begin
  572. if lnf_backward in loopflags then
  573. begin
  574. if int64(cmp_const)=high(int64) then
  575. begin
  576. hcond:=OC_NE;
  577. cmp_const:=low(int64);
  578. end
  579. end
  580. else
  581. begin
  582. if int64(cmp_const)=low(int64) then
  583. begin
  584. hcond:=OC_NE;
  585. cmp_const:=high(int64);
  586. end
  587. end
  588. end;
  589. else
  590. internalerror(200201021);
  591. end;
  592. end;
  593. { produce comparison and the corresponding }
  594. { jump }
  595. if temptovalue then
  596. begin
  597. cg.a_cmp_ref_loc_label(exprasmlist,opsize,hcond,temp1,
  598. t2.location,l3);
  599. end
  600. else
  601. begin
  602. cg.a_cmp_const_loc_label(exprasmlist,opsize,hcond,
  603. cmp_const,t2.location,l3);
  604. end;
  605. if temptovalue then
  606. tg.ungetiftemp(exprasmlist,temp1);
  607. { this is the break label: }
  608. cg.a_label(exprasmlist,aktbreaklabel);
  609. aktcontinuelabel:=oldclabel;
  610. aktbreaklabel:=oldblabel;
  611. { a break/continue in a for block can't be seen outside }
  612. flowcontrol:=flowcontrol-[fc_break,fc_continue];
  613. end;
  614. {*****************************************************************************
  615. SecondExitN
  616. *****************************************************************************}
  617. procedure tcgexitnode.pass_2;
  618. begin
  619. location_reset(location,LOC_VOID,OS_NO);
  620. include(flowcontrol,fc_exit);
  621. if assigned(left) then
  622. secondpass(left);
  623. cg.a_jmp_always(exprasmlist,aktexitlabel);
  624. end;
  625. {*****************************************************************************
  626. SecondBreakN
  627. *****************************************************************************}
  628. procedure tcgbreaknode.pass_2;
  629. begin
  630. location_reset(location,LOC_VOID,OS_NO);
  631. include(flowcontrol,fc_break);
  632. if aktbreaklabel<>nil then
  633. begin
  634. load_all_regvars(exprasmlist);
  635. cg.a_jmp_always(exprasmlist,aktbreaklabel)
  636. end
  637. else
  638. CGMessage(cg_e_break_not_allowed);
  639. end;
  640. {*****************************************************************************
  641. SecondContinueN
  642. *****************************************************************************}
  643. procedure tcgcontinuenode.pass_2;
  644. begin
  645. location_reset(location,LOC_VOID,OS_NO);
  646. include(flowcontrol,fc_continue);
  647. if aktcontinuelabel<>nil then
  648. begin
  649. load_all_regvars(exprasmlist);
  650. cg.a_jmp_always(exprasmlist,aktcontinuelabel)
  651. end
  652. else
  653. CGMessage(cg_e_continue_not_allowed);
  654. end;
  655. {*****************************************************************************
  656. SecondGoto
  657. *****************************************************************************}
  658. procedure tcggotonode.pass_2;
  659. begin
  660. location_reset(location,LOC_VOID,OS_NO);
  661. load_all_regvars(exprasmlist);
  662. cg.a_jmp_always(exprasmlist,labsym.lab)
  663. end;
  664. {*****************************************************************************
  665. SecondLabel
  666. *****************************************************************************}
  667. procedure tcglabelnode.pass_2;
  668. begin
  669. location_reset(location,LOC_VOID,OS_NO);
  670. load_all_regvars(exprasmlist);
  671. cg.a_label(exprasmlist,labelnr);
  672. {$ifndef newra}
  673. rg.cleartempgen;
  674. {$endif newra}
  675. secondpass(left);
  676. end;
  677. {*****************************************************************************
  678. SecondRaise
  679. *****************************************************************************}
  680. procedure tcgraisenode.pass_2;
  681. var
  682. a : tasmlabel;
  683. href2: treference;
  684. r:Tregister;
  685. begin
  686. location_reset(location,LOC_VOID,OS_NO);
  687. if assigned(left) then
  688. begin
  689. { multiple parameters? }
  690. if assigned(right) then
  691. begin
  692. { push frame }
  693. if assigned(frametree) then
  694. begin
  695. secondpass(frametree);
  696. if codegenerror then
  697. exit;
  698. cg.a_param_loc(exprasmlist,frametree.location,paramanager.getintparaloc(2));
  699. end
  700. else
  701. cg.a_param_const(exprasmlist,OS_INT,0,paramanager.getintparaloc(2));
  702. { push address }
  703. secondpass(right);
  704. if codegenerror then
  705. exit;
  706. cg.a_param_loc(exprasmlist,right.location,paramanager.getintparaloc(1));
  707. end
  708. else
  709. begin
  710. { get current address }
  711. objectlibrary.getaddrlabel(a);
  712. cg.a_label(exprasmlist,a);
  713. reference_reset_symbol(href2,a,0);
  714. { push current frame }
  715. r.enum:=R_INTREGISTER;
  716. r.number:=NR_FRAME_POINTER_REG;
  717. cg.a_param_reg(exprasmlist,OS_ADDR,r,paramanager.getintparaloc(2));
  718. { push current address }
  719. cg.a_paramaddr_ref(exprasmlist,href2,paramanager.getintparaloc(1));
  720. end;
  721. { push object }
  722. secondpass(left);
  723. if codegenerror then
  724. exit;
  725. cg.a_param_loc(exprasmlist,left.location,paramanager.getintparaloc(1));
  726. cg.a_call_name(exprasmlist,'FPC_RAISEEXCEPTION');
  727. end
  728. else
  729. begin
  730. cg.a_call_name(exprasmlist,'FPC_POPADDRSTACK');
  731. cg.a_call_name(exprasmlist,'FPC_RERAISE');
  732. end;
  733. end;
  734. {*****************************************************************************
  735. SecondTryExcept
  736. *****************************************************************************}
  737. var
  738. endexceptlabel : tasmlabel;
  739. procedure try_new_exception(list : taasmoutput;var jmpbuf,envbuf, href : treference;
  740. a : aword; exceptlabel : tasmlabel);
  741. begin
  742. tg.GetTemp(list,EXCEPT_BUF_SIZE,tt_persistent,envbuf);
  743. tg.GetTemp(list,JMP_BUF_SIZE,tt_persistent,jmpbuf);
  744. tg.GetTemp(list,sizeof(aword),tt_persistent,href);
  745. new_exception(list, jmpbuf,envbuf, href, a, exceptlabel);
  746. end;
  747. procedure try_free_exception(list : taasmoutput;var jmpbuf, envbuf, href : treference;
  748. a : aword ; endexceptlabel : tasmlabel; onlyfree : boolean);
  749. begin
  750. free_exception(list, jmpbuf, envbuf, href, a, endexceptlabel, onlyfree);
  751. tg.ungettemp(list,href);
  752. tg.Ungettemp(list,jmpbuf);
  753. tg.ungettemp(list,envbuf);
  754. end;
  755. { does the necessary things to clean up the object stack }
  756. { in the except block }
  757. procedure cleanupobjectstack;
  758. var r:Tregister;
  759. begin
  760. cg.a_call_name(exprasmlist,'FPC_POPOBJECTSTACK');
  761. r.enum:=R_INTREGISTER;
  762. r.number:=NR_ACCUMULATOR;
  763. cg.a_param_reg(exprasmlist,OS_ADDR,r,paramanager.getintparaloc(1));
  764. cg.a_call_name(exprasmlist,'FPC_DESTROYEXCEPTION');
  765. end;
  766. procedure tcgtryexceptnode.pass_2;
  767. var
  768. exceptlabel,doexceptlabel,oldendexceptlabel,
  769. lastonlabel,
  770. exitexceptlabel,
  771. continueexceptlabel,
  772. breakexceptlabel,
  773. exittrylabel,
  774. continuetrylabel,
  775. breaktrylabel,
  776. doobjectdestroy,
  777. doobjectdestroyandreraise,
  778. oldaktexitlabel,
  779. oldaktcontinuelabel,
  780. oldaktbreaklabel : tasmlabel;
  781. oldflowcontrol,tryflowcontrol,
  782. exceptflowcontrol : tflowcontrol;
  783. tempbuf,tempaddr : treference;
  784. href : treference;
  785. r:Tregister;
  786. label
  787. errorexit;
  788. begin
  789. location_reset(location,LOC_VOID,OS_NO);
  790. oldflowcontrol:=flowcontrol;
  791. flowcontrol:=[];
  792. { this can be called recursivly }
  793. oldendexceptlabel:=endexceptlabel;
  794. { save the old labels for control flow statements }
  795. oldaktexitlabel:=aktexitlabel;
  796. if assigned(aktbreaklabel) then
  797. begin
  798. oldaktcontinuelabel:=aktcontinuelabel;
  799. oldaktbreaklabel:=aktbreaklabel;
  800. end;
  801. { get new labels for the control flow statements }
  802. objectlibrary.getlabel(exittrylabel);
  803. objectlibrary.getlabel(exitexceptlabel);
  804. if assigned(aktbreaklabel) then
  805. begin
  806. objectlibrary.getlabel(breaktrylabel);
  807. objectlibrary.getlabel(continuetrylabel);
  808. objectlibrary.getlabel(breakexceptlabel);
  809. objectlibrary.getlabel(continueexceptlabel);
  810. end;
  811. objectlibrary.getlabel(exceptlabel);
  812. objectlibrary.getlabel(doexceptlabel);
  813. objectlibrary.getlabel(endexceptlabel);
  814. objectlibrary.getlabel(lastonlabel);
  815. try_new_exception(exprasmlist,tempbuf,tempaddr,href,1,exceptlabel);
  816. { try block }
  817. { set control flow labels for the try block }
  818. aktexitlabel:=exittrylabel;
  819. if assigned(oldaktbreaklabel) then
  820. begin
  821. aktcontinuelabel:=continuetrylabel;
  822. aktbreaklabel:=breaktrylabel;
  823. end;
  824. flowcontrol:=[];
  825. secondpass(left);
  826. tryflowcontrol:=flowcontrol;
  827. if codegenerror then
  828. goto errorexit;
  829. cg.a_label(exprasmlist,exceptlabel);
  830. try_free_exception(exprasmlist,tempbuf,tempaddr,href,0,endexceptlabel,false);
  831. cg.a_label(exprasmlist,doexceptlabel);
  832. { set control flow labels for the except block }
  833. { and the on statements }
  834. aktexitlabel:=exitexceptlabel;
  835. if assigned(oldaktbreaklabel) then
  836. begin
  837. aktcontinuelabel:=continueexceptlabel;
  838. aktbreaklabel:=breakexceptlabel;
  839. end;
  840. flowcontrol:=[];
  841. { on statements }
  842. if assigned(right) then
  843. secondpass(right);
  844. cg.a_label(exprasmlist,lastonlabel);
  845. { default handling except handling }
  846. if assigned(t1) then
  847. begin
  848. { FPC_CATCHES must be called with
  849. 'default handler' flag (=-1)
  850. }
  851. cg.a_param_const(exprasmlist,OS_ADDR,aword(-1),paramanager.getintparaloc(1));
  852. cg.a_call_name(exprasmlist,'FPC_CATCHES');
  853. { the destruction of the exception object must be also }
  854. { guarded by an exception frame }
  855. objectlibrary.getlabel(doobjectdestroy);
  856. objectlibrary.getlabel(doobjectdestroyandreraise);
  857. try_new_exception(exprasmlist,tempbuf,tempaddr,href,1,doobjectdestroyandreraise);
  858. { here we don't have to reset flowcontrol }
  859. { the default and on flowcontrols are handled equal }
  860. secondpass(t1);
  861. exceptflowcontrol:=flowcontrol;
  862. cg.a_label(exprasmlist,doobjectdestroyandreraise);
  863. try_free_exception(exprasmlist,tempbuf,tempaddr,href,0,doobjectdestroy,false);
  864. cg.a_call_name(exprasmlist,'FPC_POPSECONDOBJECTSTACK');
  865. r.enum:=R_INTREGISTER;
  866. r.number:=NR_ACCUMULATOR;
  867. cg.a_param_reg(exprasmlist, OS_ADDR, r, paramanager.getintparaloc(1));
  868. cg.a_call_name(exprasmlist,'FPC_DESTROYEXCEPTION');
  869. { we don't need to restore esi here because reraise never }
  870. { returns }
  871. cg.a_call_name(exprasmlist,'FPC_RERAISE');
  872. cg.a_label(exprasmlist,doobjectdestroy);
  873. cleanupobjectstack;
  874. cg.a_jmp_always(exprasmlist,endexceptlabel);
  875. end
  876. else
  877. begin
  878. cg.a_call_name(exprasmlist,'FPC_RERAISE');
  879. exceptflowcontrol:=flowcontrol;
  880. end;
  881. if fc_exit in exceptflowcontrol then
  882. begin
  883. { do some magic for exit in the try block }
  884. cg.a_label(exprasmlist,exitexceptlabel);
  885. { we must also destroy the address frame which guards }
  886. { exception object }
  887. cg.a_call_name(exprasmlist,'FPC_POPADDRSTACK');
  888. cg.g_exception_reason_load(exprasmlist,href);
  889. cleanupobjectstack;
  890. cg.a_jmp_always(exprasmlist,oldaktexitlabel);
  891. end;
  892. if fc_break in exceptflowcontrol then
  893. begin
  894. cg.a_label(exprasmlist,breakexceptlabel);
  895. { we must also destroy the address frame which guards }
  896. { exception object }
  897. cg.a_call_name(exprasmlist,'FPC_POPADDRSTACK');
  898. cg.g_exception_reason_load(exprasmlist,href);
  899. cleanupobjectstack;
  900. cg.a_jmp_always(exprasmlist,oldaktbreaklabel);
  901. end;
  902. if fc_continue in exceptflowcontrol then
  903. begin
  904. cg.a_label(exprasmlist,continueexceptlabel);
  905. { we must also destroy the address frame which guards }
  906. { exception object }
  907. cg.a_call_name(exprasmlist,'FPC_POPADDRSTACK');
  908. cg.g_exception_reason_load(exprasmlist,href);
  909. cleanupobjectstack;
  910. cg.a_jmp_always(exprasmlist,oldaktcontinuelabel);
  911. end;
  912. if fc_exit in tryflowcontrol then
  913. begin
  914. { do some magic for exit in the try block }
  915. cg.a_label(exprasmlist,exittrylabel);
  916. cg.a_call_name(exprasmlist,'FPC_POPADDRSTACK');
  917. cg.g_exception_reason_load(exprasmlist,href);
  918. cg.a_jmp_always(exprasmlist,oldaktexitlabel);
  919. end;
  920. if fc_break in tryflowcontrol then
  921. begin
  922. cg.a_label(exprasmlist,breaktrylabel);
  923. cg.a_call_name(exprasmlist,'FPC_POPADDRSTACK');
  924. cg.g_exception_reason_load(exprasmlist,href);
  925. cg.a_jmp_always(exprasmlist,oldaktbreaklabel);
  926. end;
  927. if fc_continue in tryflowcontrol then
  928. begin
  929. cg.a_label(exprasmlist,continuetrylabel);
  930. cg.a_call_name(exprasmlist,'FPC_POPADDRSTACK');
  931. cg.g_exception_reason_load(exprasmlist,href);
  932. cg.a_jmp_always(exprasmlist,oldaktcontinuelabel);
  933. end;
  934. cg.a_label(exprasmlist,endexceptlabel);
  935. errorexit:
  936. { restore all saved labels }
  937. endexceptlabel:=oldendexceptlabel;
  938. { restore the control flow labels }
  939. aktexitlabel:=oldaktexitlabel;
  940. if assigned(oldaktbreaklabel) then
  941. begin
  942. aktcontinuelabel:=oldaktcontinuelabel;
  943. aktbreaklabel:=oldaktbreaklabel;
  944. end;
  945. { return all used control flow statements }
  946. flowcontrol:=oldflowcontrol+exceptflowcontrol+
  947. tryflowcontrol;
  948. end;
  949. procedure tcgonnode.pass_2;
  950. var
  951. nextonlabel,
  952. exitonlabel,
  953. continueonlabel,
  954. breakonlabel,
  955. oldaktexitlabel,
  956. oldaktcontinuelabel,
  957. doobjectdestroyandreraise,
  958. doobjectdestroy,
  959. oldaktbreaklabel : tasmlabel;
  960. ref : treference;
  961. oldflowcontrol : tflowcontrol;
  962. tempbuf,tempaddr : treference;
  963. href : treference;
  964. href2: treference;
  965. r:Tregister;
  966. begin
  967. location_reset(location,LOC_VOID,OS_NO);
  968. r.enum:=R_INTREGISTER;
  969. r.number:=NR_ACCUMULATOR;
  970. oldflowcontrol:=flowcontrol;
  971. flowcontrol:=[];
  972. objectlibrary.getlabel(nextonlabel);
  973. { send the vmt parameter }
  974. reference_reset_symbol(href2,objectlibrary.newasmsymboldata(excepttype.vmt_mangledname),0);
  975. cg.a_paramaddr_ref(exprasmlist,href2,paramanager.getintparaloc(1));
  976. cg.a_call_name(exprasmlist,'FPC_CATCHES');
  977. { is it this catch? No. go to next onlabel }
  978. cg.a_cmp_const_reg_label(exprasmlist,OS_ADDR,OC_EQ,0,r,nextonlabel);
  979. ref.symbol:=nil;
  980. tg.GetTemp(exprasmlist,pointer_size,tt_normal,ref);
  981. { what a hack ! }
  982. if assigned(exceptsymtable) then
  983. tvarsym(exceptsymtable.symindex.first).address:=ref.offset;
  984. cg.a_load_reg_ref(exprasmlist, OS_ADDR, r, ref);
  985. { in the case that another exception is risen }
  986. { we've to destroy the old one }
  987. objectlibrary.getlabel(doobjectdestroyandreraise);
  988. { call setjmp, and jump to finally label on non-zero result }
  989. try_new_exception(exprasmlist,tempbuf,tempaddr,href,1,doobjectdestroyandreraise);
  990. if assigned(right) then
  991. begin
  992. oldaktexitlabel:=aktexitlabel;
  993. objectlibrary.getlabel(exitonlabel);
  994. aktexitlabel:=exitonlabel;
  995. if assigned(aktbreaklabel) then
  996. begin
  997. oldaktcontinuelabel:=aktcontinuelabel;
  998. oldaktbreaklabel:=aktbreaklabel;
  999. objectlibrary.getlabel(breakonlabel);
  1000. objectlibrary.getlabel(continueonlabel);
  1001. aktcontinuelabel:=continueonlabel;
  1002. aktbreaklabel:=breakonlabel;
  1003. end;
  1004. secondpass(right);
  1005. end;
  1006. objectlibrary.getlabel(doobjectdestroy);
  1007. cg.a_label(exprasmlist,doobjectdestroyandreraise);
  1008. try_free_exception(exprasmlist,tempbuf,tempaddr,href,0,doobjectdestroy,false);
  1009. cg.a_call_name(exprasmlist,'FPC_POPSECONDOBJECTSTACK');
  1010. cg.a_param_reg(exprasmlist, OS_ADDR, r, paramanager.getintparaloc(1));
  1011. cg.a_call_name(exprasmlist,'FPC_DESTROYEXCEPTION');
  1012. { we don't need to restore esi here because reraise never }
  1013. { returns }
  1014. cg.a_call_name(exprasmlist,'FPC_RERAISE');
  1015. cg.a_label(exprasmlist,doobjectdestroy);
  1016. cleanupobjectstack;
  1017. { clear some stuff }
  1018. tg.ungetiftemp(exprasmlist,ref);
  1019. cg.a_jmp_always(exprasmlist,endexceptlabel);
  1020. if assigned(right) then
  1021. begin
  1022. { special handling for control flow instructions }
  1023. if fc_exit in flowcontrol then
  1024. begin
  1025. { the address and object pop does secondtryexcept }
  1026. cg.a_label(exprasmlist,exitonlabel);
  1027. cg.a_jmp_always(exprasmlist,oldaktexitlabel);
  1028. end;
  1029. if fc_break in flowcontrol then
  1030. begin
  1031. { the address and object pop does secondtryexcept }
  1032. cg.a_label(exprasmlist,breakonlabel);
  1033. cg.a_jmp_always(exprasmlist,oldaktbreaklabel);
  1034. end;
  1035. if fc_continue in flowcontrol then
  1036. begin
  1037. { the address and object pop does secondtryexcept }
  1038. cg.a_label(exprasmlist,continueonlabel);
  1039. cg.a_jmp_always(exprasmlist,oldaktcontinuelabel);
  1040. end;
  1041. aktexitlabel:=oldaktexitlabel;
  1042. if assigned(oldaktbreaklabel) then
  1043. begin
  1044. aktcontinuelabel:=oldaktcontinuelabel;
  1045. aktbreaklabel:=oldaktbreaklabel;
  1046. end;
  1047. end;
  1048. cg.a_label(exprasmlist,nextonlabel);
  1049. flowcontrol:=oldflowcontrol+flowcontrol;
  1050. { next on node }
  1051. if assigned(left) then
  1052. begin
  1053. {$ifndef newra}
  1054. rg.cleartempgen;
  1055. {$endif newra}
  1056. secondpass(left);
  1057. end;
  1058. end;
  1059. {*****************************************************************************
  1060. SecondTryFinally
  1061. *****************************************************************************}
  1062. procedure tcgtryfinallynode.pass_2;
  1063. var
  1064. reraiselabel,
  1065. finallylabel,
  1066. endfinallylabel,
  1067. exitfinallylabel,
  1068. continuefinallylabel,
  1069. breakfinallylabel,
  1070. oldaktexitlabel,
  1071. oldaktcontinuelabel,
  1072. oldaktbreaklabel : tasmlabel;
  1073. oldflowcontrol,tryflowcontrol : tflowcontrol;
  1074. decconst : longint;
  1075. tempbuf,tempaddr : treference;
  1076. href : treference;
  1077. r:Tregister;
  1078. begin
  1079. location_reset(location,LOC_VOID,OS_NO);
  1080. { check if child nodes do a break/continue/exit }
  1081. oldflowcontrol:=flowcontrol;
  1082. flowcontrol:=[];
  1083. objectlibrary.getlabel(finallylabel);
  1084. objectlibrary.getlabel(endfinallylabel);
  1085. objectlibrary.getlabel(reraiselabel);
  1086. { the finally block must catch break, continue and exit }
  1087. { statements }
  1088. oldaktexitlabel:=aktexitlabel;
  1089. if implicitframe then
  1090. exitfinallylabel:=finallylabel
  1091. else
  1092. objectlibrary.getlabel(exitfinallylabel);
  1093. aktexitlabel:=exitfinallylabel;
  1094. if assigned(aktbreaklabel) then
  1095. begin
  1096. oldaktcontinuelabel:=aktcontinuelabel;
  1097. oldaktbreaklabel:=aktbreaklabel;
  1098. if implicitframe then
  1099. begin
  1100. breakfinallylabel:=finallylabel;
  1101. continuefinallylabel:=finallylabel;
  1102. end
  1103. else
  1104. begin
  1105. objectlibrary.getlabel(breakfinallylabel);
  1106. objectlibrary.getlabel(continuefinallylabel);
  1107. end;
  1108. aktcontinuelabel:=continuefinallylabel;
  1109. aktbreaklabel:=breakfinallylabel;
  1110. end;
  1111. { call setjmp, and jump to finally label on non-zero result }
  1112. try_new_exception(exprasmlist,tempbuf,tempaddr,href,1,finallylabel);
  1113. { try code }
  1114. if assigned(left) then
  1115. begin
  1116. secondpass(left);
  1117. tryflowcontrol:=flowcontrol;
  1118. if codegenerror then
  1119. exit;
  1120. end;
  1121. cg.a_label(exprasmlist,finallylabel);
  1122. { just free the frame information }
  1123. try_free_exception(exprasmlist,tempbuf,tempaddr,href,1,finallylabel,true);
  1124. { finally code }
  1125. flowcontrol:=[];
  1126. secondpass(right);
  1127. if flowcontrol<>[] then
  1128. CGMessage(cg_e_control_flow_outside_finally);
  1129. if codegenerror then
  1130. exit;
  1131. { the value should now be in the exception handler }
  1132. cg.g_exception_reason_load(exprasmlist,href);
  1133. r.enum:=R_INTREGISTER;
  1134. r.number:=NR_ACCUMULATOR;
  1135. if implicitframe then
  1136. begin
  1137. cg.a_cmp_const_reg_label(exprasmlist,OS_S32,OC_EQ,0,r,endfinallylabel);
  1138. { finally code only needed to be executed on exception }
  1139. flowcontrol:=[];
  1140. secondpass(t1);
  1141. if flowcontrol<>[] then
  1142. CGMessage(cg_e_control_flow_outside_finally);
  1143. if codegenerror then
  1144. exit;
  1145. cg.a_call_name(exprasmlist,'FPC_RERAISE');
  1146. end
  1147. else
  1148. begin
  1149. cg.a_cmp_const_reg_label(exprasmlist,OS_S32,OC_EQ,0,r,endfinallylabel);
  1150. cg.a_op_const_reg(exprasmlist,OP_SUB,1,r);
  1151. cg.a_cmp_const_reg_label(exprasmlist,OS_S32,OC_EQ,0,r,reraiselabel);
  1152. if fc_exit in tryflowcontrol then
  1153. begin
  1154. cg.a_op_const_reg(exprasmlist,OP_SUB,1,r);
  1155. cg.a_cmp_const_reg_label(exprasmlist,OS_S32,OC_EQ,0,r,oldaktexitlabel);
  1156. decconst:=1;
  1157. end
  1158. else
  1159. decconst:=2;
  1160. if fc_break in tryflowcontrol then
  1161. begin
  1162. cg.a_op_const_reg(exprasmlist,OP_SUB,decconst,r);
  1163. cg.a_cmp_const_reg_label(exprasmlist,OS_S32,OC_EQ,0,r,oldaktbreaklabel);
  1164. decconst:=1;
  1165. end
  1166. else
  1167. inc(decconst);
  1168. if fc_continue in tryflowcontrol then
  1169. begin
  1170. cg.a_op_const_reg(exprasmlist,OP_SUB,decconst,r);
  1171. cg.a_cmp_const_reg_label(exprasmlist,OS_S32,OC_EQ,0,r,oldaktcontinuelabel);
  1172. end;
  1173. cg.a_label(exprasmlist,reraiselabel);
  1174. cg.a_call_name(exprasmlist,'FPC_RERAISE');
  1175. { do some magic for exit,break,continue in the try block }
  1176. if fc_exit in tryflowcontrol then
  1177. begin
  1178. cg.a_label(exprasmlist,exitfinallylabel);
  1179. cg.g_exception_reason_load(exprasmlist,href);
  1180. cg.g_exception_reason_save_const(exprasmlist,href,2);
  1181. cg.a_jmp_always(exprasmlist,finallylabel);
  1182. end;
  1183. if fc_break in tryflowcontrol then
  1184. begin
  1185. cg.a_label(exprasmlist,breakfinallylabel);
  1186. cg.g_exception_reason_load(exprasmlist,href);
  1187. cg.g_exception_reason_save_const(exprasmlist,href,3);
  1188. cg.a_jmp_always(exprasmlist,finallylabel);
  1189. end;
  1190. if fc_continue in tryflowcontrol then
  1191. begin
  1192. cg.a_label(exprasmlist,continuefinallylabel);
  1193. cg.g_exception_reason_load(exprasmlist,href);
  1194. cg.g_exception_reason_save_const(exprasmlist,href,4);
  1195. cg.a_jmp_always(exprasmlist,finallylabel);
  1196. end;
  1197. end;
  1198. cg.a_label(exprasmlist,endfinallylabel);
  1199. aktexitlabel:=oldaktexitlabel;
  1200. if assigned(aktbreaklabel) then
  1201. begin
  1202. aktcontinuelabel:=oldaktcontinuelabel;
  1203. aktbreaklabel:=oldaktbreaklabel;
  1204. end;
  1205. flowcontrol:=oldflowcontrol+tryflowcontrol;
  1206. end;
  1207. begin
  1208. cwhilerepeatnode:=tcgwhilerepeatnode;
  1209. cifnode:=tcgifnode;
  1210. cfornode:=tcgfornode;
  1211. cexitnode:=tcgexitnode;
  1212. cbreaknode:=tcgbreaknode;
  1213. ccontinuenode:=tcgcontinuenode;
  1214. cgotonode:=tcggotonode;
  1215. clabelnode:=tcglabelnode;
  1216. craisenode:=tcgraisenode;
  1217. ctryexceptnode:=tcgtryexceptnode;
  1218. ctryfinallynode:=tcgtryfinallynode;
  1219. connode:=tcgonnode;
  1220. end.
  1221. {
  1222. $Log$
  1223. Revision 1.64 2003-05-26 21:17:17 peter
  1224. * procinlinenode removed
  1225. * aktexit2label removed, fast exit removed
  1226. + tcallnode.inlined_pass_2 added
  1227. Revision 1.63 2003/05/23 14:27:35 peter
  1228. * remove some unit dependencies
  1229. * current_procinfo changes to store more info
  1230. Revision 1.62 2003/05/17 13:30:08 jonas
  1231. * changed tt_persistant to tt_persistent :)
  1232. * tempcreatenode now doesn't accept a boolean anymore for persistent
  1233. temps, but a ttemptype, so you can also create ansistring temps etc
  1234. Revision 1.61 2003/05/16 14:33:31 peter
  1235. * regvar fixes
  1236. Revision 1.60 2003/05/13 19:14:41 peter
  1237. * failn removed
  1238. * inherited result code check moven to pexpr
  1239. Revision 1.59 2003/05/11 21:37:03 peter
  1240. * moved implicit exception frame from ncgutil to psub
  1241. * constructor/destructor helpers moved from cobj/ncgutil to psub
  1242. Revision 1.58 2003/04/30 15:45:35 florian
  1243. * merged more x86-64/i386 code
  1244. Revision 1.57 2003/04/29 07:29:14 michael
  1245. + Patch from peter to fix wrong pushing of ansistring function results in open array
  1246. Revision 1.56 2003/04/27 11:21:33 peter
  1247. * aktprocdef renamed to current_procdef
  1248. * procinfo renamed to current_procinfo
  1249. * procinfo will now be stored in current_module so it can be
  1250. cleaned up properly
  1251. * gen_main_procsym changed to create_main_proc and release_main_proc
  1252. to also generate a tprocinfo structure
  1253. * fixed unit implicit initfinal
  1254. Revision 1.55 2003/04/22 23:50:22 peter
  1255. * firstpass uses expectloc
  1256. * checks if there are differences between the expectloc and
  1257. location.loc from secondpass in EXTDEBUG
  1258. Revision 1.54 2003/04/17 07:50:24 daniel
  1259. * Some work on interference graph construction
  1260. Revision 1.53 2003/04/06 21:11:23 olle
  1261. * changed newasmsymbol to newasmsymboldata for data symbols
  1262. Revision 1.52 2003/03/28 19:16:56 peter
  1263. * generic constructor working for i386
  1264. * remove fixed self register
  1265. * esi added as address register for i386
  1266. Revision 1.51 2003/02/19 22:00:14 daniel
  1267. * Code generator converted to new register notation
  1268. - Horribily outdated todo.txt removed
  1269. Revision 1.50 2003/02/15 22:17:38 carl
  1270. * bugfix of FPU emulation code
  1271. Revision 1.49 2003/01/08 18:43:56 daniel
  1272. * Tregister changed into a record
  1273. Revision 1.48 2003/01/03 09:51:58 daniel
  1274. * Compiler now cycles with var_notification
  1275. Revision 1.47 2003/01/02 15:29:25 daniel
  1276. * Some debugging on for loop optimization
  1277. Revision 1.46 2002/12/31 09:55:58 daniel
  1278. + Notification implementation complete
  1279. + Add for loop code optimization using notifications
  1280. results in 1.5-1.9% speed improvement in nestloop benchmark
  1281. Optimization incomplete, compiler does not cycle yet with
  1282. notifications enabled.
  1283. Revision 1.45 2002/11/28 11:17:01 florian
  1284. * loop node flags from node flags splitted
  1285. Revision 1.44 2002/11/25 17:43:17 peter
  1286. * splitted defbase in defutil,symutil,defcmp
  1287. * merged isconvertable and is_equal into compare_defs(_ext)
  1288. * made operator search faster by walking the list only once
  1289. Revision 1.43 2002/09/30 07:00:45 florian
  1290. * fixes to common code to get the alpha compiler compiled applied
  1291. Revision 1.42 2002/09/07 15:25:02 peter
  1292. * old logs removed and tabs fixed
  1293. Revision 1.41 2002/09/01 18:47:00 peter
  1294. * assignn check in exitnode changed to use a separate boolean as the
  1295. assignn can be changed to a calln
  1296. Revision 1.40 2002/09/01 14:41:47 peter
  1297. * increase refcount in exit(arg) for arg
  1298. Revision 1.39 2002/08/24 18:41:52 peter
  1299. * fixed wrong label in jump of except block (was also in n386flw wrong)
  1300. * fixed wrong pushing of raise parameters
  1301. * fixed wrong compare in finally
  1302. Revision 1.38 2002/08/23 16:14:48 peter
  1303. * tempgen cleanup
  1304. * tt_noreuse temp type added that will be used in genentrycode
  1305. Revision 1.37 2002/08/19 19:36:43 peter
  1306. * More fixes for cross unit inlining, all tnodes are now implemented
  1307. * Moved pocall_internconst to po_internconst because it is not a
  1308. calling type at all and it conflicted when inlining of these small
  1309. functions was requested
  1310. Revision 1.36 2002/08/15 15:15:55 carl
  1311. * jmpbuf size allocation for exceptions is now cpu specific (as it should)
  1312. * more generic nodes for maths
  1313. * several fixes for better m68k support
  1314. Revision 1.35 2002/08/13 18:01:52 carl
  1315. * rename swatoperands to swapoperands
  1316. + m68k first compilable version (still needs a lot of testing):
  1317. assembler generator, system information , inline
  1318. assembler reader.
  1319. Revision 1.34 2002/08/11 14:32:26 peter
  1320. * renamed current_library to objectlibrary
  1321. Revision 1.33 2002/08/11 13:24:11 peter
  1322. * saving of asmsymbols in ppu supported
  1323. * asmsymbollist global is removed and moved into a new class
  1324. tasmlibrarydata that will hold the info of a .a file which
  1325. corresponds with a single module. Added librarydata to tmodule
  1326. to keep the library info stored for the module. In the future the
  1327. objectfiles will also be stored to the tasmlibrarydata class
  1328. * all getlabel/newasmsymbol and friends are moved to the new class
  1329. Revision 1.32 2002/08/09 19:10:59 carl
  1330. * fixed generic exception management
  1331. Revision 1.31 2002/08/04 19:06:41 carl
  1332. + added generic exception support (still does not work!)
  1333. + more documentation
  1334. Revision 1.30 2002/07/27 19:53:51 jonas
  1335. + generic implementation of tcg.g_flags2ref()
  1336. * tcg.flags2xxx() now also needs a size parameter
  1337. Revision 1.29 2002/07/25 17:56:29 carl
  1338. + FPURESULTREG -> FPU_RESULT_REG
  1339. Revision 1.28 2002/07/21 06:58:49 daniel
  1340. * Changed booleans into flags
  1341. Revision 1.27 2002/07/20 12:54:53 daniel
  1342. * Optimized the code generated for for nodes. The shootout/nestloop benchmark
  1343. now runs 5% faster on my computer.
  1344. Revision 1.26 2002/07/20 11:57:54 florian
  1345. * types.pas renamed to defbase.pas because D6 contains a types
  1346. unit so this would conflicts if D6 programms are compiled
  1347. + Willamette/SSE2 instructions to assembler added
  1348. Revision 1.25 2002/07/20 11:15:51 daniel
  1349. * The for node does a check if the first comparision can be skipped. I moved
  1350. the check from the second pass to the resulttype pass. The advantage is
  1351. that the state tracker can now decide to skip the first comparision too.
  1352. Revision 1.24 2002/07/20 08:14:24 daniel
  1353. * Loops should not be aligned when optimizing for size
  1354. Revision 1.23 2002/07/19 11:41:35 daniel
  1355. * State tracker work
  1356. * The whilen and repeatn are now completely unified into whilerepeatn. This
  1357. allows the state tracker to change while nodes automatically into
  1358. repeat nodes.
  1359. * Resulttypepass improvements to the notn. 'not not a' is optimized away and
  1360. 'not(a>b)' is optimized into 'a<=b'.
  1361. * Resulttypepass improvements to the whilerepeatn. 'while not a' is optimized
  1362. by removing the notn and later switchting the true and falselabels. The
  1363. same is done with 'repeat until not a'.
  1364. Revision 1.22 2002/07/04 20:43:01 florian
  1365. * first x86-64 patches
  1366. }