ncgflw.pas 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Generate assembler for nodes that influence the flow which are
  4. the same for all (most?) processors
  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 ncgflw;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. aasmbase,node,nflw,ncgutil;
  23. type
  24. tcgwhilerepeatnode = class(twhilerepeatnode)
  25. usedregvars: tusedregvars;
  26. procedure pass_generate_code;override;
  27. procedure sync_regvars(checkusedregvars: boolean);
  28. end;
  29. tcgifnode = class(tifnode)
  30. procedure pass_generate_code;override;
  31. end;
  32. tcgfornode = class(tfornode)
  33. usedregvars: tusedregvars;
  34. procedure pass_generate_code;override;
  35. procedure sync_regvars(checkusedregvars: boolean);
  36. end;
  37. tcgexitnode = class(texitnode)
  38. procedure pass_generate_code;override;
  39. end;
  40. tcgbreaknode = class(tbreaknode)
  41. procedure pass_generate_code;override;
  42. end;
  43. tcgcontinuenode = class(tcontinuenode)
  44. procedure pass_generate_code;override;
  45. end;
  46. tcggotonode = class(tgotonode)
  47. procedure pass_generate_code;override;
  48. end;
  49. tcglabelnode = class(tlabelnode)
  50. private
  51. asmlabel : tasmlabel;
  52. public
  53. function getasmlabel : tasmlabel;
  54. procedure pass_generate_code;override;
  55. end;
  56. tcgraisenode = class(traisenode)
  57. procedure pass_generate_code;override;
  58. end;
  59. tcgtryexceptnode = class(ttryexceptnode)
  60. procedure pass_generate_code;override;
  61. end;
  62. tcgtryfinallynode = class(ttryfinallynode)
  63. procedure pass_generate_code;override;
  64. end;
  65. tcgonnode = class(tonnode)
  66. procedure pass_generate_code;override;
  67. end;
  68. implementation
  69. uses
  70. verbose,globals,systems,globtype,constexp,
  71. symconst,symdef,symsym,aasmtai,aasmdata,aasmcpu,defutil,
  72. procinfo,cgbase,pass_2,parabase,
  73. cpubase,cpuinfo,
  74. nld,ncon,
  75. tgobj,paramgr,
  76. regvars,
  77. cgutils,cgobj
  78. ;
  79. {*****************************************************************************
  80. Second_While_RepeatN
  81. *****************************************************************************}
  82. procedure tcgwhilerepeatnode.sync_regvars(checkusedregvars: boolean);
  83. begin
  84. if (cs_opt_regvar in current_settings.optimizerswitches) and
  85. not(pi_has_label in current_procinfo.flags) then
  86. begin
  87. if checkusedregvars then
  88. begin
  89. usedregvars.intregvars.init;
  90. usedregvars.fpuregvars.init;
  91. usedregvars.mmregvars.init;
  92. { we have to synchronise both the regvars used in the loop }
  93. { and the ones in the while/until condition }
  94. get_used_regvars(self,usedregvars);
  95. gen_sync_regvars(current_asmdata.CurrAsmList,usedregvars);
  96. end
  97. else
  98. begin
  99. gen_sync_regvars(current_asmdata.CurrAsmList,usedregvars);
  100. usedregvars.intregvars.done;
  101. usedregvars.fpuregvars.done;
  102. usedregvars.mmregvars.done;
  103. end;
  104. end;
  105. end;
  106. procedure tcgwhilerepeatnode.pass_generate_code;
  107. var
  108. lcont,lbreak,lloop,
  109. oldclabel,oldblabel : tasmlabel;
  110. otlabel,oflabel : tasmlabel;
  111. oldflowcontrol : tflowcontrol;
  112. oldexecutionweight : longint;
  113. begin
  114. location_reset(location,LOC_VOID,OS_NO);
  115. current_asmdata.getjumplabel(lloop);
  116. current_asmdata.getjumplabel(lcont);
  117. current_asmdata.getjumplabel(lbreak);
  118. { arrange continue and breaklabels: }
  119. oldflowcontrol:=flowcontrol;
  120. oldclabel:=current_procinfo.CurrContinueLabel;
  121. oldblabel:=current_procinfo.CurrBreakLabel;
  122. include(flowcontrol,fc_inflowcontrol);
  123. sync_regvars(true);
  124. {$ifdef OLDREGVARS}
  125. load_all_regvars(current_asmdata.CurrAsmList);
  126. {$endif OLDREGVARS}
  127. { handling code at the end as it is much more efficient, and makes
  128. while equal to repeat loop, only the end true/false is swapped (PFV) }
  129. if lnf_testatbegin in loopflags then
  130. cg.a_jmp_always(current_asmdata.CurrAsmList,lcont);
  131. if not(cs_opt_size in current_settings.optimizerswitches) then
  132. { align loop target }
  133. current_asmdata.CurrAsmList.concat(Tai_align.Create(current_settings.alignment.loopalign));
  134. cg.a_label(current_asmdata.CurrAsmList,lloop);
  135. current_procinfo.CurrContinueLabel:=lcont;
  136. current_procinfo.CurrBreakLabel:=lbreak;
  137. if assigned(right) then
  138. begin
  139. { calc register weight }
  140. oldexecutionweight:=cg.executionweight;
  141. cg.executionweight:=cg.executionweight*8;
  142. secondpass(right);
  143. cg.executionweight:=oldexecutionweight;
  144. end;
  145. {$ifdef OLDREGVARS}
  146. load_all_regvars(current_asmdata.CurrAsmList);
  147. {$endif OLDREGVARS}
  148. cg.a_label(current_asmdata.CurrAsmList,lcont);
  149. otlabel:=current_procinfo.CurrTrueLabel;
  150. oflabel:=current_procinfo.CurrFalseLabel;
  151. if lnf_checknegate in loopflags then
  152. begin
  153. current_procinfo.CurrTrueLabel:=lbreak;
  154. current_procinfo.CurrFalseLabel:=lloop;
  155. end
  156. else
  157. begin
  158. current_procinfo.CurrTrueLabel:=lloop;
  159. current_procinfo.CurrFalseLabel:=lbreak;
  160. end;
  161. secondpass(left);
  162. maketojumpbool(current_asmdata.CurrAsmList,left,lr_load_regvars);
  163. cg.a_label(current_asmdata.CurrAsmList,lbreak);
  164. sync_regvars(false);
  165. current_procinfo.CurrTrueLabel:=otlabel;
  166. current_procinfo.CurrFalseLabel:=oflabel;
  167. current_procinfo.CurrContinueLabel:=oldclabel;
  168. current_procinfo.CurrBreakLabel:=oldblabel;
  169. { a break/continue in a while/repeat block can't be seen outside }
  170. flowcontrol:=oldflowcontrol+(flowcontrol-[fc_break,fc_continue,fc_inflowcontrol]);
  171. end;
  172. {*****************************************************************************
  173. tcgIFNODE
  174. *****************************************************************************}
  175. procedure tcgifnode.pass_generate_code;
  176. var
  177. hl,otlabel,oflabel : tasmlabel;
  178. oldflowcontrol: tflowcontrol;
  179. oldexecutionweight : longint;
  180. (*
  181. org_regvar_loaded_other,
  182. then_regvar_loaded_other,
  183. else_regvar_loaded_other : regvarother_booleanarray;
  184. org_regvar_loaded_int,
  185. then_regvar_loaded_int,
  186. else_regvar_loaded_int : Tsuperregisterset;
  187. org_list,
  188. then_list,
  189. else_list : TAsmList;
  190. *)
  191. begin
  192. location_reset(location,LOC_VOID,OS_NO);
  193. oldflowcontrol := flowcontrol;
  194. include(flowcontrol,fc_inflowcontrol);
  195. otlabel:=current_procinfo.CurrTrueLabel;
  196. oflabel:=current_procinfo.CurrFalseLabel;
  197. current_asmdata.getjumplabel(current_procinfo.CurrTrueLabel);
  198. current_asmdata.getjumplabel(current_procinfo.CurrFalseLabel);
  199. secondpass(left);
  200. (*
  201. { save regvars loaded in the beginning so that we can restore them }
  202. { when processing the else-block }
  203. if cs_opt_regvar in current_settings.optimizerswitches then
  204. begin
  205. org_list := current_asmdata.CurrAsmList;
  206. current_asmdata.CurrAsmList := TAsmList.create;
  207. end;
  208. *)
  209. maketojumpbool(current_asmdata.CurrAsmList,left,lr_dont_load_regvars);
  210. (*
  211. if cs_opt_regvar in current_settings.optimizerswitches then
  212. begin
  213. org_regvar_loaded_int := rg.regvar_loaded_int;
  214. org_regvar_loaded_other := rg.regvar_loaded_other;
  215. end;
  216. *)
  217. { determines registers weigths }
  218. oldexecutionweight:=cg.executionweight;
  219. cg.executionweight:=cg.executionweight div 2;
  220. if cg.executionweight<1 then
  221. cg.executionweight:=1;
  222. if assigned(right) then
  223. begin
  224. cg.a_label(current_asmdata.CurrAsmList,current_procinfo.CurrTrueLabel);
  225. secondpass(right);
  226. end;
  227. { save current asmlist (previous instructions + then-block) and }
  228. { loaded regvar state and create new clean ones }
  229. {
  230. if cs_opt_regvar in current_settings.optimizerswitches then
  231. begin
  232. then_regvar_loaded_int := rg.regvar_loaded_int;
  233. then_regvar_loaded_other := rg.regvar_loaded_other;
  234. rg.regvar_loaded_int := org_regvar_loaded_int;
  235. rg.regvar_loaded_other := org_regvar_loaded_other;
  236. then_list := current_asmdata.CurrAsmList;
  237. current_asmdata.CurrAsmList := TAsmList.create;
  238. end;
  239. }
  240. if assigned(t1) then
  241. begin
  242. if assigned(right) then
  243. begin
  244. current_asmdata.getjumplabel(hl);
  245. { do go back to if line !! }
  246. (*
  247. if not(cs_opt_regvar in current_settings.optimizerswitches) then
  248. *)
  249. current_filepos:=current_asmdata.CurrAsmList.getlasttaifilepos^
  250. (*
  251. else
  252. current_filepos:=then_list.getlasttaifilepos^
  253. *)
  254. ;
  255. cg.a_jmp_always(current_asmdata.CurrAsmList,hl);
  256. end;
  257. cg.a_label(current_asmdata.CurrAsmList,current_procinfo.CurrFalseLabel);
  258. secondpass(t1);
  259. (*
  260. { save current asmlist (previous instructions + else-block) }
  261. { and loaded regvar state and create a new clean list }
  262. if cs_opt_regvar in current_settings.optimizerswitches then
  263. begin
  264. { else_regvar_loaded_int := rg.regvar_loaded_int;
  265. else_regvar_loaded_other := rg.regvar_loaded_other;}
  266. else_list := current_asmdata.CurrAsmList;
  267. current_asmdata.CurrAsmList := TAsmList.create;
  268. end;
  269. *)
  270. if assigned(right) then
  271. cg.a_label(current_asmdata.CurrAsmList,hl);
  272. end
  273. else
  274. begin
  275. (*
  276. if cs_opt_regvar in current_settings.optimizerswitches then
  277. begin
  278. { else_regvar_loaded_int := rg.regvar_loaded_int;
  279. else_regvar_loaded_other := rg.regvar_loaded_other;}
  280. else_list := current_asmdata.CurrAsmList;
  281. current_asmdata.CurrAsmList := TAsmList.create;
  282. end;
  283. *)
  284. cg.a_label(current_asmdata.CurrAsmList,current_procinfo.CurrFalseLabel);
  285. end;
  286. if not(assigned(right)) then
  287. begin
  288. cg.a_label(current_asmdata.CurrAsmList,current_procinfo.CurrTrueLabel);
  289. end;
  290. (*
  291. if cs_opt_regvar in current_settings.optimizerswitches then
  292. begin
  293. { add loads of regvars at the end of the then- and else-blocks }
  294. { so that at the end of both blocks the same regvars are loaded }
  295. { no else block? }
  296. if not assigned(t1) then
  297. begin
  298. sync_regvars_int(org_list,then_list,org_regvar_loaded_int,then_regvar_loaded_int);
  299. sync_regvars_other(org_list,then_list,org_regvar_loaded_other,then_regvar_loaded_other);
  300. end
  301. { no then block? }
  302. else if not assigned(right) then
  303. begin
  304. sync_regvars_int(org_list,else_list,org_regvar_loaded_int,else_regvar_loaded_int);
  305. sync_regvars_other(org_list,else_list,org_regvar_loaded_other,else_regvar_loaded_other);
  306. end
  307. { both else and then blocks }
  308. else
  309. begin
  310. sync_regvars_int(then_list,else_list,then_regvar_loaded_int,else_regvar_loaded_int);
  311. sync_regvars_other(then_list,else_list,then_regvar_loaded_other,else_regvar_loaded_other);
  312. end;
  313. { add all lists together }
  314. org_list.concatlist(then_list);
  315. then_list.free;
  316. org_list.concatlist(else_list);
  317. else_list.free;
  318. org_list.concatlist(current_asmdata.CurrAsmList);
  319. current_asmdata.CurrAsmList.free;
  320. current_asmdata.CurrAsmList := org_list;
  321. end;
  322. *)
  323. cg.executionweight:=oldexecutionweight;
  324. current_procinfo.CurrTrueLabel:=otlabel;
  325. current_procinfo.CurrFalseLabel:=oflabel;
  326. flowcontrol := oldflowcontrol + (flowcontrol - [fc_inflowcontrol]);
  327. end;
  328. {*****************************************************************************
  329. SecondFor
  330. *****************************************************************************}
  331. procedure tcgfornode.sync_regvars(checkusedregvars: boolean);
  332. begin
  333. if (cs_opt_regvar in current_settings.optimizerswitches) and
  334. not(pi_has_label in current_procinfo.flags) then
  335. begin
  336. if checkusedregvars then
  337. begin
  338. usedregvars.intregvars.init;
  339. usedregvars.fpuregvars.init;
  340. usedregvars.mmregvars.init;
  341. { We have to synchronise the loop variable and loop body. }
  342. { The loop end is not necessary, unless it's a register }
  343. { variable. The start value also doesn't matter. }
  344. { loop var }
  345. get_used_regvars(right,usedregvars);
  346. { loop body }
  347. get_used_regvars(t2,usedregvars);
  348. { end value (t1) is not necessary (it cannot be a regvar, }
  349. { see webtbs/tw8883) }
  350. gen_sync_regvars(current_asmdata.CurrAsmList,usedregvars);
  351. end
  352. else
  353. begin
  354. gen_sync_regvars(current_asmdata.CurrAsmList,usedregvars);
  355. usedregvars.intregvars.done;
  356. usedregvars.fpuregvars.done;
  357. usedregvars.mmregvars.done;
  358. end;
  359. end;
  360. end;
  361. procedure tcgfornode.pass_generate_code;
  362. var
  363. l3,oldclabel,oldblabel,
  364. otl, ofl : tasmlabel;
  365. temptovalue : boolean;
  366. hop : topcg;
  367. hcond : topcmp;
  368. opsize : tcgsize;
  369. count_var_is_signed,do_loopvar_at_end : boolean;
  370. cmp_const:Tconstexprint;
  371. oldflowcontrol : tflowcontrol;
  372. oldexecutionweight : longint;
  373. isjump: boolean;
  374. begin
  375. location_reset(location,LOC_VOID,OS_NO);
  376. oldclabel:=current_procinfo.CurrContinueLabel;
  377. oldblabel:=current_procinfo.CurrBreakLabel;
  378. current_asmdata.getjumplabel(current_procinfo.CurrContinueLabel);
  379. current_asmdata.getjumplabel(current_procinfo.CurrBreakLabel);
  380. current_asmdata.getjumplabel(l3);
  381. { only calculate reference }
  382. opsize := def_cgsize(left.resultdef);
  383. count_var_is_signed:=is_signed(left.resultdef);
  384. { first set the to value
  385. because the count var can be in the expression ! }
  386. do_loopvar_at_end:=(lnf_dont_mind_loopvar_on_exit in loopflags)
  387. { if the loop is unrolled and there is a jump into the loop,
  388. then we can't do the trick with incrementing the loop var only at the
  389. end
  390. }
  391. and not(assigned(entrylabel));
  392. isjump:=(t1.expectloc=LOC_JUMP);
  393. if isjump then
  394. begin
  395. otl:=current_procinfo.CurrTrueLabel;
  396. current_asmdata.getjumplabel(current_procinfo.CurrTrueLabel);
  397. ofl:=current_procinfo.CurrFalseLabel;
  398. current_asmdata.getjumplabel(current_procinfo.CurrFalseLabel);
  399. end;
  400. secondpass(t1);
  401. if t1.location.loc in [LOC_FLAGS,LOC_JUMP] then
  402. location_force_reg(current_asmdata.CurrAsmList,t1.location,def_cgsize(t1.resultdef),false);
  403. if isjump then
  404. begin
  405. current_procinfo.CurrTrueLabel:=otl;
  406. current_procinfo.CurrFalseLabel:=ofl;
  407. end;
  408. { calculate pointer value and check if changeable and if so }
  409. { load into temporary variable }
  410. if t1.nodetype<>ordconstn then
  411. begin
  412. do_loopvar_at_end:=false;
  413. location_force_reg(current_asmdata.CurrAsmList,t1.location,t1.location.size,false);
  414. temptovalue:=true;
  415. end
  416. else
  417. temptovalue:=false;
  418. { load loopvar, prefer loopvar being a register variable }
  419. oldexecutionweight:=cg.executionweight;
  420. inc(cg.executionweight,8);
  421. secondpass(left);
  422. cg.executionweight:=oldexecutionweight;
  423. { load from value }
  424. isjump:=(right.expectloc=LOC_JUMP);
  425. if isjump then
  426. begin
  427. otl:=current_procinfo.CurrTrueLabel;
  428. current_asmdata.getjumplabel(current_procinfo.CurrTrueLabel);
  429. ofl:=current_procinfo.CurrFalseLabel;
  430. current_asmdata.getjumplabel(current_procinfo.CurrFalseLabel);
  431. end;
  432. secondpass(right);
  433. if right.location.loc in [LOC_FLAGS,LOC_JUMP] then
  434. location_force_reg(current_asmdata.CurrAsmList,right.location,def_cgsize(right.resultdef),false);
  435. if isjump then
  436. begin
  437. current_procinfo.CurrTrueLabel:=otl;
  438. current_procinfo.CurrFalseLabel:=ofl;
  439. end;
  440. maybechangeloadnodereg(current_asmdata.CurrAsmList,left,false);
  441. oldflowcontrol:=flowcontrol;
  442. include(flowcontrol,fc_inflowcontrol);
  443. { produce start assignment }
  444. case left.location.loc of
  445. LOC_REFERENCE,
  446. LOC_CREFERENCE :
  447. cg.a_load_loc_ref(current_asmdata.CurrAsmList,left.location.size,right.location,left.location.reference);
  448. LOC_REGISTER,
  449. LOC_CREGISTER:
  450. cg.a_load_loc_reg(current_asmdata.CurrAsmList,left.location.size,right.location,left.location.register);
  451. LOC_SUBSETREG,
  452. LOC_CSUBSETREG :
  453. cg.a_load_loc_subsetreg(current_asmdata.CurrAsmList,left.location.size,right.location,left.location.sreg);
  454. else
  455. internalerror(200501311);
  456. end;
  457. if lnf_backward in loopflags then
  458. if count_var_is_signed then
  459. hcond:=OC_LT
  460. else
  461. hcond:=OC_B
  462. else
  463. if count_var_is_signed then
  464. hcond:=OC_GT
  465. else
  466. hcond:=OC_A;
  467. sync_regvars(true);
  468. {$ifdef OLDREGVARS}
  469. load_all_regvars(current_asmdata.CurrAsmList);
  470. {$endif OLDREGVARS}
  471. if temptovalue then
  472. begin
  473. cg.a_cmp_reg_loc_label(current_asmdata.CurrAsmList,opsize,hcond,
  474. t1.location.register,left.location,current_procinfo.CurrBreakLabel);
  475. end
  476. else
  477. begin
  478. if lnf_testatbegin in loopflags then
  479. begin
  480. cg.a_cmp_const_loc_label(current_asmdata.CurrAsmList,opsize,hcond,
  481. tordconstnode(t1).value.svalue,
  482. left.location,current_procinfo.CurrBreakLabel);
  483. end;
  484. end;
  485. {If the loopvar doesn't mind on exit, we avoid this ugly
  486. dec instruction and do the loopvar inc/dec after the loop
  487. body.}
  488. if not do_loopvar_at_end then
  489. begin
  490. if lnf_backward in loopflags then
  491. hop:=OP_ADD
  492. else
  493. hop:=OP_SUB;
  494. cg.a_op_const_loc(current_asmdata.CurrAsmList,hop,1,left.location);
  495. end;
  496. if assigned(entrylabel) then
  497. cg.a_jmp_always(current_asmdata.CurrAsmList,tcglabelnode(entrylabel).getasmlabel);
  498. { align loop target }
  499. if not(cs_opt_size in current_settings.optimizerswitches) then
  500. current_asmdata.CurrAsmList.concat(Tai_align.Create(current_settings.alignment.loopalign));
  501. cg.a_label(current_asmdata.CurrAsmList,l3);
  502. {If the loopvar doesn't mind on exit, we avoid the loopvar inc/dec
  503. after the loop body instead of here.}
  504. if not do_loopvar_at_end then
  505. begin
  506. { according to count direction DEC or INC... }
  507. if lnf_backward in loopflags then
  508. hop:=OP_SUB
  509. else
  510. hop:=OP_ADD;
  511. cg.a_op_const_loc(current_asmdata.CurrAsmList,hop,1,left.location);
  512. end;
  513. if assigned(t2) then
  514. begin
  515. { Calc register weight }
  516. oldexecutionweight:=cg.executionweight;
  517. cg.executionweight:=cg.executionweight*8;
  518. secondpass(t2);
  519. cg.executionweight:=oldexecutionweight;
  520. {$ifdef OLDREGVARS}
  521. load_all_regvars(current_asmdata.CurrAsmList);
  522. {$endif OLDREGVARS}
  523. end;
  524. {If the loopvar doesn't mind on exit, we do the loopvar inc/dec
  525. after the loop body instead of here.}
  526. if do_loopvar_at_end then
  527. begin
  528. { according to count direction DEC or INC... }
  529. if lnf_backward in loopflags then
  530. hop:=OP_SUB
  531. else
  532. hop:=OP_ADD;
  533. cg.a_op_const_loc(current_asmdata.CurrAsmList,hop,1,left.location);
  534. end;
  535. cg.a_label(current_asmdata.CurrAsmList,current_procinfo.CurrContinueLabel);
  536. if do_loopvar_at_end then
  537. if lnf_backward in loopflags then
  538. if count_var_is_signed then
  539. hcond:=OC_GTE
  540. else
  541. hcond:=OC_AE
  542. else
  543. if count_var_is_signed then
  544. hcond:=OC_LTE
  545. else
  546. hcond:=OC_BE
  547. else
  548. if lnf_backward in loopflags then
  549. if count_var_is_signed then
  550. hcond:=OC_GT
  551. else
  552. hcond:=OC_A
  553. else
  554. if count_var_is_signed then
  555. hcond:=OC_LT
  556. else
  557. hcond:=OC_B;
  558. {$ifdef OLDREGVARS}
  559. load_all_regvars(current_asmdata.CurrAsmList);
  560. {$endif OLDREGVARS}
  561. { produce comparison and the corresponding }
  562. { jump }
  563. if temptovalue then
  564. begin
  565. cg.a_cmp_reg_loc_label(current_asmdata.CurrAsmList,opsize,hcond,t1.location.register,
  566. left.location,l3);
  567. end
  568. else
  569. begin
  570. cmp_const:=Tordconstnode(t1).value;
  571. if do_loopvar_at_end then
  572. begin
  573. {Watch out for wrap around 255 -> 0.}
  574. {Ugly: This code is way to long... Use tables?}
  575. case opsize of
  576. OS_8:
  577. begin
  578. if lnf_backward in loopflags then
  579. begin
  580. if byte(cmp_const.svalue)=low(byte) then
  581. begin
  582. hcond:=OC_NE;
  583. cmp_const:=high(byte);
  584. end
  585. end
  586. else
  587. begin
  588. if byte(cmp_const.svalue)=high(byte) then
  589. begin
  590. hcond:=OC_NE;
  591. cmp_const:=low(byte);
  592. end
  593. end
  594. end;
  595. OS_16:
  596. begin
  597. if lnf_backward in loopflags then
  598. begin
  599. if word(cmp_const.svalue)=high(word) then
  600. begin
  601. hcond:=OC_NE;
  602. cmp_const:=low(word);
  603. end
  604. end
  605. else
  606. begin
  607. if word(cmp_const.svalue)=low(word) then
  608. begin
  609. hcond:=OC_NE;
  610. cmp_const:=high(word);
  611. end
  612. end
  613. end;
  614. OS_32:
  615. begin
  616. if lnf_backward in loopflags then
  617. begin
  618. if cardinal(cmp_const.svalue)=high(cardinal) then
  619. begin
  620. hcond:=OC_NE;
  621. cmp_const:=low(cardinal);
  622. end
  623. end
  624. else
  625. begin
  626. if cardinal(cmp_const.svalue)=low(cardinal) then
  627. begin
  628. hcond:=OC_NE;
  629. cmp_const:=high(cardinal);
  630. end
  631. end
  632. end;
  633. OS_64:
  634. begin
  635. if lnf_backward in loopflags then
  636. begin
  637. if qword(cmp_const.uvalue)=high(qword) then
  638. begin
  639. hcond:=OC_NE;
  640. cmp_const:=low(qword);
  641. end
  642. end
  643. else
  644. begin
  645. if qword(cmp_const.uvalue)=low(qword) then
  646. begin
  647. hcond:=OC_NE;
  648. cmp_const:=high(qword);
  649. end
  650. end
  651. end;
  652. OS_S8:
  653. begin
  654. if lnf_backward in loopflags then
  655. begin
  656. if shortint(cmp_const.svalue)=low(shortint) then
  657. begin
  658. hcond:=OC_NE;
  659. cmp_const:=high(shortint);
  660. end
  661. end
  662. else
  663. begin
  664. if shortint(cmp_const.svalue)=high(shortint) then
  665. begin
  666. hcond:=OC_NE;
  667. cmp_const:=int64(low(shortint));
  668. end
  669. end
  670. end;
  671. OS_S16:
  672. begin
  673. if lnf_backward in loopflags then
  674. begin
  675. if integer(cmp_const.svalue)=high(smallint) then
  676. begin
  677. hcond:=OC_NE;
  678. cmp_const:=int64(low(smallint));
  679. end
  680. end
  681. else
  682. begin
  683. if integer(cmp_const.svalue)=low(smallint) then
  684. begin
  685. hcond:=OC_NE;
  686. cmp_const:=int64(high(smallint));
  687. end
  688. end
  689. end;
  690. OS_S32:
  691. begin
  692. if lnf_backward in loopflags then
  693. begin
  694. if longint(cmp_const.svalue)=high(longint) then
  695. begin
  696. hcond:=OC_NE;
  697. cmp_const:=int64(low(longint));
  698. end
  699. end
  700. else
  701. begin
  702. if longint(cmp_const.svalue)=low(longint) then
  703. begin
  704. hcond:=OC_NE;
  705. cmp_const:=int64(high(longint));
  706. end
  707. end
  708. end;
  709. OS_S64:
  710. begin
  711. if lnf_backward in loopflags then
  712. begin
  713. if int64(cmp_const.svalue)=high(int64) then
  714. begin
  715. hcond:=OC_NE;
  716. cmp_const:=low(int64);
  717. end
  718. end
  719. else
  720. begin
  721. if int64(cmp_const.svalue)=low(int64) then
  722. begin
  723. hcond:=OC_NE;
  724. cmp_const:=high(int64);
  725. end
  726. end
  727. end;
  728. else
  729. internalerror(200201021);
  730. end;
  731. end;
  732. cg.a_cmp_const_loc_label(current_asmdata.CurrAsmList,opsize,hcond,
  733. aint(cmp_const.svalue),left.location,l3);
  734. end;
  735. { this is the break label: }
  736. cg.a_label(current_asmdata.CurrAsmList,current_procinfo.CurrBreakLabel);
  737. sync_regvars(false);
  738. current_procinfo.CurrContinueLabel:=oldclabel;
  739. current_procinfo.CurrBreakLabel:=oldblabel;
  740. { a break/continue in a while/repeat block can't be seen outside }
  741. flowcontrol:=oldflowcontrol+(flowcontrol-[fc_break,fc_continue,fc_inflowcontrol]);
  742. end;
  743. {*****************************************************************************
  744. SecondExitN
  745. *****************************************************************************}
  746. procedure tcgexitnode.pass_generate_code;
  747. begin
  748. location_reset(location,LOC_VOID,OS_NO);
  749. include(flowcontrol,fc_exit);
  750. if assigned(left) then
  751. secondpass(left);
  752. cg.a_jmp_always(current_asmdata.CurrAsmList,current_procinfo.CurrExitLabel);
  753. end;
  754. {*****************************************************************************
  755. SecondBreakN
  756. *****************************************************************************}
  757. procedure tcgbreaknode.pass_generate_code;
  758. begin
  759. location_reset(location,LOC_VOID,OS_NO);
  760. include(flowcontrol,fc_break);
  761. if current_procinfo.CurrBreakLabel<>nil then
  762. begin
  763. {$ifdef OLDREGVARS}
  764. load_all_regvars(current_asmdata.CurrAsmList);
  765. {$endif OLDREGVARS}
  766. cg.a_jmp_always(current_asmdata.CurrAsmList,current_procinfo.CurrBreakLabel)
  767. end
  768. else
  769. CGMessage(cg_e_break_not_allowed);
  770. end;
  771. {*****************************************************************************
  772. SecondContinueN
  773. *****************************************************************************}
  774. procedure tcgcontinuenode.pass_generate_code;
  775. begin
  776. location_reset(location,LOC_VOID,OS_NO);
  777. include(flowcontrol,fc_continue);
  778. if current_procinfo.CurrContinueLabel<>nil then
  779. begin
  780. {$ifdef OLDREGVARS}
  781. load_all_regvars(current_asmdata.CurrAsmList);
  782. {$endif OLDREGVARS}
  783. cg.a_jmp_always(current_asmdata.CurrAsmList,current_procinfo.CurrContinueLabel)
  784. end
  785. else
  786. CGMessage(cg_e_continue_not_allowed);
  787. end;
  788. {*****************************************************************************
  789. SecondGoto
  790. *****************************************************************************}
  791. procedure tcggotonode.pass_generate_code;
  792. begin
  793. location_reset(location,LOC_VOID,OS_NO);
  794. include(flowcontrol,fc_gotolabel);
  795. {$ifdef OLDREGVARS}
  796. load_all_regvars(current_asmdata.CurrAsmList);
  797. {$endif OLDREGVARS}
  798. cg.a_jmp_always(current_asmdata.CurrAsmList,tcglabelnode(labelnode).getasmlabel)
  799. end;
  800. {*****************************************************************************
  801. SecondLabel
  802. *****************************************************************************}
  803. function tcglabelnode.getasmlabel : tasmlabel;
  804. begin
  805. if not(assigned(asmlabel)) then
  806. { labsym is not set in inlined procedures, but since assembler }
  807. { routines can't be inlined, that shouldn't matter }
  808. if assigned(labsym) and
  809. labsym.nonlocal then
  810. current_asmdata.getglobaljumplabel(asmlabel)
  811. else
  812. current_asmdata.getjumplabel(asmlabel);
  813. result:=asmlabel
  814. end;
  815. procedure tcglabelnode.pass_generate_code;
  816. begin
  817. location_reset(location,LOC_VOID,OS_NO);
  818. include(flowcontrol,fc_gotolabel);
  819. {$ifdef OLDREGVARS}
  820. load_all_regvars(current_asmdata.CurrAsmList);
  821. {$endif OLDREGVARS}
  822. cg.a_label(current_asmdata.CurrAsmList,getasmlabel);
  823. { Write also extra label if this label was referenced from
  824. assembler block }
  825. if assigned(labsym) and
  826. assigned(labsym.asmblocklabel) then
  827. cg.a_label(current_asmdata.CurrAsmList,labsym.asmblocklabel);
  828. secondpass(left);
  829. end;
  830. {*****************************************************************************
  831. SecondRaise
  832. *****************************************************************************}
  833. procedure tcgraisenode.pass_generate_code;
  834. var
  835. a : tasmlabel;
  836. href2: treference;
  837. paraloc1,paraloc2,paraloc3 : tcgpara;
  838. begin
  839. paraloc1.init;
  840. paraloc2.init;
  841. paraloc3.init;
  842. paramanager.getintparaloc(pocall_default,1,paraloc1);
  843. paramanager.getintparaloc(pocall_default,2,paraloc2);
  844. paramanager.getintparaloc(pocall_default,3,paraloc3);
  845. location_reset(location,LOC_VOID,OS_NO);
  846. if assigned(left) then
  847. begin
  848. { multiple parameters? }
  849. if assigned(right) then
  850. begin
  851. { frame tree }
  852. if assigned(third) then
  853. secondpass(third);
  854. secondpass(right);
  855. end;
  856. secondpass(left);
  857. if codegenerror then
  858. exit;
  859. { Push parameters }
  860. if assigned(right) then
  861. begin
  862. { frame tree }
  863. if assigned(third) then
  864. cg.a_load_loc_cgpara(current_asmdata.CurrAsmList,third.location,paraloc3)
  865. else
  866. cg.a_load_const_cgpara(current_asmdata.CurrAsmList,OS_INT,0,paraloc3);
  867. { push address }
  868. cg.a_load_loc_cgpara(current_asmdata.CurrAsmList,right.location,paraloc2);
  869. end
  870. else
  871. begin
  872. { get current address }
  873. current_asmdata.getaddrlabel(a);
  874. cg.a_label(current_asmdata.CurrAsmList,a);
  875. reference_reset_symbol(href2,a,0,1);
  876. { push current frame }
  877. cg.a_load_reg_cgpara(current_asmdata.CurrAsmList,OS_ADDR,NR_FRAME_POINTER_REG,paraloc3);
  878. { push current address }
  879. if target_info.system <> system_powerpc_macos then
  880. cg.a_loadaddr_ref_cgpara(current_asmdata.CurrAsmList,href2,paraloc2)
  881. else
  882. cg.a_load_const_cgpara(current_asmdata.CurrAsmList,OS_INT,0,paraloc2);
  883. end;
  884. cg.a_load_loc_cgpara(current_asmdata.CurrAsmList,left.location,paraloc1);
  885. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  886. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc2);
  887. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc3);
  888. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  889. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_RAISEEXCEPTION',false);
  890. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  891. end
  892. else
  893. begin
  894. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  895. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPADDRSTACK',false);
  896. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_RERAISE',false);
  897. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  898. end;
  899. paraloc1.done;
  900. paraloc2.done;
  901. paraloc3.done;
  902. end;
  903. {*****************************************************************************
  904. SecondTryExcept
  905. *****************************************************************************}
  906. var
  907. endexceptlabel : tasmlabel;
  908. { does the necessary things to clean up the object stack }
  909. { in the except block }
  910. procedure cleanupobjectstack;
  911. var
  912. paraloc1 : tcgpara;
  913. begin
  914. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  915. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPOBJECTSTACK',false);
  916. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  917. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  918. paraloc1.init;
  919. paramanager.getintparaloc(pocall_default,1,paraloc1);
  920. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  921. cg.a_load_reg_cgpara(current_asmdata.CurrAsmList,OS_ADDR,NR_FUNCTION_RESULT_REG,paraloc1);
  922. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  923. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  924. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_DESTROYEXCEPTION',false);
  925. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  926. paraloc1.done;
  927. end;
  928. procedure tcgtryexceptnode.pass_generate_code;
  929. var
  930. exceptlabel,doexceptlabel,oldendexceptlabel,
  931. lastonlabel,
  932. exitexceptlabel,
  933. continueexceptlabel,
  934. breakexceptlabel,
  935. exittrylabel,
  936. continuetrylabel,
  937. breaktrylabel,
  938. doobjectdestroy,
  939. doobjectdestroyandreraise,
  940. oldCurrExitLabel,
  941. oldContinueLabel,
  942. oldBreakLabel : tasmlabel;
  943. oldflowcontrol,tryflowcontrol,
  944. exceptflowcontrol : tflowcontrol;
  945. destroytemps,
  946. excepttemps : texceptiontemps;
  947. paraloc1 : tcgpara;
  948. label
  949. errorexit;
  950. begin
  951. location_reset(location,LOC_VOID,OS_NO);
  952. oldflowcontrol:=flowcontrol;
  953. flowcontrol:=[fc_inflowcontrol];
  954. { this can be called recursivly }
  955. oldBreakLabel:=nil;
  956. oldContinueLabel:=nil;
  957. oldendexceptlabel:=endexceptlabel;
  958. { save the old labels for control flow statements }
  959. oldCurrExitLabel:=current_procinfo.CurrExitLabel;
  960. if assigned(current_procinfo.CurrBreakLabel) then
  961. begin
  962. oldContinueLabel:=current_procinfo.CurrContinueLabel;
  963. oldBreakLabel:=current_procinfo.CurrBreakLabel;
  964. end;
  965. { get new labels for the control flow statements }
  966. current_asmdata.getjumplabel(exittrylabel);
  967. current_asmdata.getjumplabel(exitexceptlabel);
  968. if assigned(current_procinfo.CurrBreakLabel) then
  969. begin
  970. current_asmdata.getjumplabel(breaktrylabel);
  971. current_asmdata.getjumplabel(continuetrylabel);
  972. current_asmdata.getjumplabel(breakexceptlabel);
  973. current_asmdata.getjumplabel(continueexceptlabel);
  974. end;
  975. current_asmdata.getjumplabel(exceptlabel);
  976. current_asmdata.getjumplabel(doexceptlabel);
  977. current_asmdata.getjumplabel(endexceptlabel);
  978. current_asmdata.getjumplabel(lastonlabel);
  979. get_exception_temps(current_asmdata.CurrAsmList,excepttemps);
  980. new_exception(current_asmdata.CurrAsmList,excepttemps,exceptlabel);
  981. { try block }
  982. { set control flow labels for the try block }
  983. current_procinfo.CurrExitLabel:=exittrylabel;
  984. if assigned(oldBreakLabel) then
  985. begin
  986. current_procinfo.CurrContinueLabel:=continuetrylabel;
  987. current_procinfo.CurrBreakLabel:=breaktrylabel;
  988. end;
  989. flowcontrol:=[fc_inflowcontrol];
  990. secondpass(left);
  991. tryflowcontrol:=flowcontrol;
  992. if codegenerror then
  993. goto errorexit;
  994. { don't generate line info for internal cleanup }
  995. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoStart));
  996. cg.a_label(current_asmdata.CurrAsmList,exceptlabel);
  997. free_exception(current_asmdata.CurrAsmList, excepttemps, 0, endexceptlabel, false);
  998. cg.a_label(current_asmdata.CurrAsmList,doexceptlabel);
  999. { end cleanup }
  1000. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoEnd));
  1001. { set control flow labels for the except block }
  1002. { and the on statements }
  1003. current_procinfo.CurrExitLabel:=exitexceptlabel;
  1004. if assigned(oldBreakLabel) then
  1005. begin
  1006. current_procinfo.CurrContinueLabel:=continueexceptlabel;
  1007. current_procinfo.CurrBreakLabel:=breakexceptlabel;
  1008. end;
  1009. flowcontrol:=[fc_inflowcontrol];
  1010. { on statements }
  1011. if assigned(right) then
  1012. secondpass(right);
  1013. { don't generate line info for internal cleanup }
  1014. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoStart));
  1015. cg.a_label(current_asmdata.CurrAsmList,lastonlabel);
  1016. { default handling except handling }
  1017. if assigned(t1) then
  1018. begin
  1019. { FPC_CATCHES must be called with
  1020. 'default handler' flag (=-1)
  1021. }
  1022. paraloc1.init;
  1023. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1024. cg.a_load_const_cgpara(current_asmdata.CurrAsmList,OS_ADDR,-1,paraloc1);
  1025. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  1026. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1027. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_CATCHES',false);
  1028. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1029. paraloc1.done;
  1030. { the destruction of the exception object must be also }
  1031. { guarded by an exception frame }
  1032. current_asmdata.getjumplabel(doobjectdestroy);
  1033. current_asmdata.getjumplabel(doobjectdestroyandreraise);
  1034. get_exception_temps(current_asmdata.CurrAsmList,destroytemps);
  1035. new_exception(current_asmdata.CurrAsmList,destroytemps,doobjectdestroyandreraise);
  1036. { except block needs line info }
  1037. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoEnd));
  1038. { here we don't have to reset flowcontrol }
  1039. { the default and on flowcontrols are handled equal }
  1040. secondpass(t1);
  1041. exceptflowcontrol:=flowcontrol;
  1042. { don't generate line info for internal cleanup }
  1043. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoStart));
  1044. cg.a_label(current_asmdata.CurrAsmList,doobjectdestroyandreraise);
  1045. free_exception(current_asmdata.CurrAsmList,destroytemps,0,doobjectdestroy,false);
  1046. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1047. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPSECONDOBJECTSTACK',false);
  1048. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1049. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1050. paraloc1.init;
  1051. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1052. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1053. cg.a_load_reg_cgpara(current_asmdata.CurrAsmList, OS_ADDR, NR_FUNCTION_RESULT_REG, paraloc1);
  1054. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  1055. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1056. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_DESTROYEXCEPTION',false);
  1057. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1058. paraloc1.done;
  1059. { we don't need to restore esi here because reraise never }
  1060. { returns }
  1061. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_RERAISE',false);
  1062. cg.a_label(current_asmdata.CurrAsmList,doobjectdestroy);
  1063. cleanupobjectstack;
  1064. unget_exception_temps(current_asmdata.CurrAsmList,destroytemps);
  1065. cg.a_jmp_always(current_asmdata.CurrAsmList,endexceptlabel);
  1066. end
  1067. else
  1068. begin
  1069. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_RERAISE',false);
  1070. exceptflowcontrol:=flowcontrol;
  1071. end;
  1072. if fc_exit in exceptflowcontrol then
  1073. begin
  1074. { do some magic for exit in the try block }
  1075. cg.a_label(current_asmdata.CurrAsmList,exitexceptlabel);
  1076. { we must also destroy the address frame which guards }
  1077. { exception object }
  1078. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1079. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPADDRSTACK',false);
  1080. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1081. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1082. cleanupobjectstack;
  1083. cg.a_jmp_always(current_asmdata.CurrAsmList,oldCurrExitLabel);
  1084. { from g_exception_reason_load }
  1085. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1086. end;
  1087. if fc_break in exceptflowcontrol then
  1088. begin
  1089. cg.a_label(current_asmdata.CurrAsmList,breakexceptlabel);
  1090. { we must also destroy the address frame which guards }
  1091. { exception object }
  1092. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1093. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPADDRSTACK',false);
  1094. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1095. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1096. cleanupobjectstack;
  1097. cg.a_jmp_always(current_asmdata.CurrAsmList,oldBreakLabel);
  1098. { from g_exception_reason_load }
  1099. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1100. end;
  1101. if fc_continue in exceptflowcontrol then
  1102. begin
  1103. cg.a_label(current_asmdata.CurrAsmList,continueexceptlabel);
  1104. { we must also destroy the address frame which guards }
  1105. { exception object }
  1106. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1107. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPADDRSTACK',false);
  1108. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1109. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1110. cleanupobjectstack;
  1111. cg.a_jmp_always(current_asmdata.CurrAsmList,oldContinueLabel);
  1112. { from g_exception_reason_load }
  1113. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1114. end;
  1115. if fc_exit in tryflowcontrol then
  1116. begin
  1117. { do some magic for exit in the try block }
  1118. cg.a_label(current_asmdata.CurrAsmList,exittrylabel);
  1119. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1120. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPADDRSTACK',false);
  1121. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1122. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1123. cg.a_jmp_always(current_asmdata.CurrAsmList,oldCurrExitLabel);
  1124. { from g_exception_reason_load }
  1125. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1126. end;
  1127. if fc_break in tryflowcontrol then
  1128. begin
  1129. cg.a_label(current_asmdata.CurrAsmList,breaktrylabel);
  1130. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1131. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPADDRSTACK',false);
  1132. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1133. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1134. cg.a_jmp_always(current_asmdata.CurrAsmList,oldBreakLabel);
  1135. { from g_exception_reason_load }
  1136. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1137. end;
  1138. if fc_continue in tryflowcontrol then
  1139. begin
  1140. cg.a_label(current_asmdata.CurrAsmList,continuetrylabel);
  1141. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1142. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPADDRSTACK',false);
  1143. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1144. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1145. cg.a_jmp_always(current_asmdata.CurrAsmList,oldContinueLabel);
  1146. { from g_exception_reason_load }
  1147. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1148. end;
  1149. unget_exception_temps(current_asmdata.CurrAsmList,excepttemps);
  1150. cg.a_label(current_asmdata.CurrAsmList,endexceptlabel);
  1151. { end cleanup }
  1152. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoEnd));
  1153. errorexit:
  1154. { restore all saved labels }
  1155. endexceptlabel:=oldendexceptlabel;
  1156. { restore the control flow labels }
  1157. current_procinfo.CurrExitLabel:=oldCurrExitLabel;
  1158. if assigned(oldBreakLabel) then
  1159. begin
  1160. current_procinfo.CurrContinueLabel:=oldContinueLabel;
  1161. current_procinfo.CurrBreakLabel:=oldBreakLabel;
  1162. end;
  1163. { return all used control flow statements }
  1164. flowcontrol:=oldflowcontrol+(exceptflowcontrol +
  1165. tryflowcontrol - [fc_inflowcontrol]);
  1166. end;
  1167. procedure tcgonnode.pass_generate_code;
  1168. var
  1169. nextonlabel,
  1170. exitonlabel,
  1171. continueonlabel,
  1172. breakonlabel,
  1173. oldCurrExitLabel,
  1174. oldContinueLabel,
  1175. doobjectdestroyandreraise,
  1176. doobjectdestroy,
  1177. oldBreakLabel : tasmlabel;
  1178. oldflowcontrol : tflowcontrol;
  1179. excepttemps : texceptiontemps;
  1180. exceptref,
  1181. href2: treference;
  1182. paraloc1 : tcgpara;
  1183. exceptvarsym : tlocalvarsym;
  1184. begin
  1185. paraloc1.init;
  1186. location_reset(location,LOC_VOID,OS_NO);
  1187. oldflowcontrol:=flowcontrol;
  1188. flowcontrol:=[fc_inflowcontrol];
  1189. current_asmdata.getjumplabel(nextonlabel);
  1190. { send the vmt parameter }
  1191. reference_reset_symbol(href2,current_asmdata.RefAsmSymbol(excepttype.vmt_mangledname),0,sizeof(pint));
  1192. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1193. cg.a_loadaddr_ref_cgpara(current_asmdata.CurrAsmList,href2,paraloc1);
  1194. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  1195. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1196. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_CATCHES',false);
  1197. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1198. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1199. { is it this catch? No. go to next onlabel }
  1200. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_ADDR,OC_EQ,0,NR_FUNCTION_RESULT_REG,nextonlabel);
  1201. { Retrieve exception variable }
  1202. if assigned(excepTSymtable) then
  1203. exceptvarsym:=tlocalvarsym(excepTSymtable.SymList[0])
  1204. else
  1205. exceptvarsym:=nil;
  1206. if assigned(exceptvarsym) then
  1207. begin
  1208. exceptvarsym.localloc.loc:=LOC_REFERENCE;
  1209. exceptvarsym.localloc.size:=OS_ADDR;
  1210. tg.GetLocal(current_asmdata.CurrAsmList,sizeof(pint),voidpointertype,exceptvarsym.localloc.reference);
  1211. cg.a_load_reg_ref(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,exceptvarsym.localloc.reference);
  1212. end
  1213. else
  1214. begin
  1215. tg.GetTemp(current_asmdata.CurrAsmList,sizeof(pint),sizeof(pint),tt_normal,exceptref);
  1216. cg.a_load_reg_ref(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,exceptref);
  1217. end;
  1218. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1219. { in the case that another exception is risen
  1220. we've to destroy the old one }
  1221. current_asmdata.getjumplabel(doobjectdestroyandreraise);
  1222. { call setjmp, and jump to finally label on non-zero result }
  1223. get_exception_temps(current_asmdata.CurrAsmList,excepttemps);
  1224. new_exception(current_asmdata.CurrAsmList,excepttemps,doobjectdestroyandreraise);
  1225. oldBreakLabel:=nil;
  1226. oldContinueLabel:=nil;
  1227. if assigned(right) then
  1228. begin
  1229. oldCurrExitLabel:=current_procinfo.CurrExitLabel;
  1230. current_asmdata.getjumplabel(exitonlabel);
  1231. current_procinfo.CurrExitLabel:=exitonlabel;
  1232. if assigned(current_procinfo.CurrBreakLabel) then
  1233. begin
  1234. oldContinueLabel:=current_procinfo.CurrContinueLabel;
  1235. oldBreakLabel:=current_procinfo.CurrBreakLabel;
  1236. current_asmdata.getjumplabel(breakonlabel);
  1237. current_asmdata.getjumplabel(continueonlabel);
  1238. current_procinfo.CurrContinueLabel:=continueonlabel;
  1239. current_procinfo.CurrBreakLabel:=breakonlabel;
  1240. end;
  1241. secondpass(right);
  1242. end;
  1243. { don't generate lineinfo for internal cleanup }
  1244. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoStart));
  1245. current_asmdata.getjumplabel(doobjectdestroy);
  1246. cg.a_label(current_asmdata.CurrAsmList,doobjectdestroyandreraise);
  1247. free_exception(current_asmdata.CurrAsmList,excepttemps,0,doobjectdestroy,false);
  1248. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1249. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPSECONDOBJECTSTACK',false);
  1250. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1251. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1252. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1253. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1254. cg.a_load_reg_cgpara(current_asmdata.CurrAsmList, OS_ADDR, NR_FUNCTION_RESULT_REG, paraloc1);
  1255. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  1256. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1257. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_DESTROYEXCEPTION',false);
  1258. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1259. { we don't need to store/restore registers here because reraise never
  1260. returns }
  1261. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_RERAISE',false);
  1262. cg.a_label(current_asmdata.CurrAsmList,doobjectdestroy);
  1263. cleanupobjectstack;
  1264. { clear some stuff }
  1265. if assigned(exceptvarsym) then
  1266. begin
  1267. tg.UngetLocal(current_asmdata.CurrAsmList,exceptvarsym.localloc.reference);
  1268. exceptvarsym.localloc.loc:=LOC_INVALID;
  1269. end
  1270. else
  1271. tg.Ungettemp(current_asmdata.CurrAsmList,exceptref);
  1272. cg.a_jmp_always(current_asmdata.CurrAsmList,endexceptlabel);
  1273. if assigned(right) then
  1274. begin
  1275. { special handling for control flow instructions }
  1276. if fc_exit in flowcontrol then
  1277. begin
  1278. { the address and object pop does secondtryexcept }
  1279. cg.a_label(current_asmdata.CurrAsmList,exitonlabel);
  1280. cg.a_jmp_always(current_asmdata.CurrAsmList,oldCurrExitLabel);
  1281. end;
  1282. if fc_break in flowcontrol then
  1283. begin
  1284. { the address and object pop does secondtryexcept }
  1285. cg.a_label(current_asmdata.CurrAsmList,breakonlabel);
  1286. cg.a_jmp_always(current_asmdata.CurrAsmList,oldBreakLabel);
  1287. end;
  1288. if fc_continue in flowcontrol then
  1289. begin
  1290. { the address and object pop does secondtryexcept }
  1291. cg.a_label(current_asmdata.CurrAsmList,continueonlabel);
  1292. cg.a_jmp_always(current_asmdata.CurrAsmList,oldContinueLabel);
  1293. end;
  1294. current_procinfo.CurrExitLabel:=oldCurrExitLabel;
  1295. if assigned(oldBreakLabel) then
  1296. begin
  1297. current_procinfo.CurrContinueLabel:=oldContinueLabel;
  1298. current_procinfo.CurrBreakLabel:=oldBreakLabel;
  1299. end;
  1300. end;
  1301. unget_exception_temps(current_asmdata.CurrAsmList,excepttemps);
  1302. cg.a_label(current_asmdata.CurrAsmList,nextonlabel);
  1303. flowcontrol:=oldflowcontrol+(flowcontrol-[fc_inflowcontrol]);
  1304. paraloc1.done;
  1305. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoEnd));
  1306. { next on node }
  1307. if assigned(left) then
  1308. secondpass(left);
  1309. end;
  1310. {*****************************************************************************
  1311. SecondTryFinally
  1312. *****************************************************************************}
  1313. procedure tcgtryfinallynode.pass_generate_code;
  1314. var
  1315. reraiselabel,
  1316. finallylabel,
  1317. endfinallylabel,
  1318. exitfinallylabel,
  1319. continuefinallylabel,
  1320. breakfinallylabel,
  1321. oldCurrExitLabel,
  1322. oldContinueLabel,
  1323. oldBreakLabel : tasmlabel;
  1324. oldflowcontrol,tryflowcontrol : tflowcontrol;
  1325. decconst : longint;
  1326. excepttemps : texceptiontemps;
  1327. retsym: tlocalvarsym;
  1328. begin
  1329. location_reset(location,LOC_VOID,OS_NO);
  1330. { check if child nodes do a break/continue/exit }
  1331. oldflowcontrol:=flowcontrol;
  1332. flowcontrol:=[fc_inflowcontrol];
  1333. current_asmdata.getjumplabel(finallylabel);
  1334. current_asmdata.getjumplabel(endfinallylabel);
  1335. current_asmdata.getjumplabel(reraiselabel);
  1336. { the finally block must catch break, continue and exit }
  1337. { statements }
  1338. oldCurrExitLabel:=current_procinfo.CurrExitLabel;
  1339. if implicitframe then
  1340. exitfinallylabel:=finallylabel
  1341. else
  1342. current_asmdata.getjumplabel(exitfinallylabel);
  1343. current_procinfo.CurrExitLabel:=exitfinallylabel;
  1344. if assigned(current_procinfo.CurrBreakLabel) then
  1345. begin
  1346. oldContinueLabel:=current_procinfo.CurrContinueLabel;
  1347. oldBreakLabel:=current_procinfo.CurrBreakLabel;
  1348. if implicitframe then
  1349. begin
  1350. breakfinallylabel:=finallylabel;
  1351. continuefinallylabel:=finallylabel;
  1352. end
  1353. else
  1354. begin
  1355. current_asmdata.getjumplabel(breakfinallylabel);
  1356. current_asmdata.getjumplabel(continuefinallylabel);
  1357. end;
  1358. current_procinfo.CurrContinueLabel:=continuefinallylabel;
  1359. current_procinfo.CurrBreakLabel:=breakfinallylabel;
  1360. end;
  1361. { call setjmp, and jump to finally label on non-zero result }
  1362. get_exception_temps(current_asmdata.CurrAsmList,excepttemps);
  1363. new_exception(current_asmdata.CurrAsmList,excepttemps,finallylabel);
  1364. { try code }
  1365. if assigned(left) then
  1366. begin
  1367. secondpass(left);
  1368. tryflowcontrol:=flowcontrol;
  1369. if codegenerror then
  1370. exit;
  1371. end;
  1372. { don't generate line info for internal cleanup }
  1373. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoStart));
  1374. cg.a_label(current_asmdata.CurrAsmList,finallylabel);
  1375. { just free the frame information }
  1376. free_exception(current_asmdata.CurrAsmList,excepttemps,1,finallylabel,true);
  1377. { end cleanup }
  1378. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoEnd));
  1379. { finally code }
  1380. flowcontrol:=[fc_inflowcontrol];
  1381. secondpass(right);
  1382. { goto is allowed if it stays inside the finally block,
  1383. this is checked using the exception block number }
  1384. if (flowcontrol-[fc_gotolabel])<>[fc_inflowcontrol] then
  1385. CGMessage(cg_e_control_flow_outside_finally);
  1386. if codegenerror then
  1387. exit;
  1388. { don't generate line info for internal cleanup }
  1389. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoStart));
  1390. { the value should now be in the exception handler }
  1391. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1392. if implicitframe then
  1393. begin
  1394. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_INT,OC_EQ,0,NR_FUNCTION_RESULT_REG,endfinallylabel);
  1395. { from g_exception_reason_load }
  1396. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1397. { finally code only needed to be executed on exception }
  1398. flowcontrol:=[fc_inflowcontrol];
  1399. secondpass(t1);
  1400. if flowcontrol<>[fc_inflowcontrol] then
  1401. CGMessage(cg_e_control_flow_outside_finally);
  1402. if codegenerror then
  1403. exit;
  1404. {$if defined(x86) or defined(arm)}
  1405. if (tf_safecall_exceptions in target_info.flags) and
  1406. (current_procinfo.procdef.proccalloption=pocall_safecall) then
  1407. begin
  1408. { find safe_result variable we created in the generate_except_block }
  1409. retsym:=tlocalvarsym(current_procinfo.procdef.localst.Find('safe_result'));
  1410. { Set return value of safecall procedure to indicate exception. }
  1411. { Exception will be raised after procedure exit based on return value }
  1412. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1413. cg.a_load_loc_reg(current_asmdata.CurrAsmList,OS_INT,retsym.localloc,NR_FUNCTION_RESULT_REG);
  1414. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1415. end
  1416. else
  1417. {$endif}
  1418. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_RERAISE',false);
  1419. end
  1420. else
  1421. begin
  1422. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_INT,OC_EQ,0,NR_FUNCTION_RESULT_REG,endfinallylabel);
  1423. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SUB,OS_INT,1,NR_FUNCTION_RESULT_REG);
  1424. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_INT,OC_EQ,0,NR_FUNCTION_RESULT_REG,reraiselabel);
  1425. if fc_exit in tryflowcontrol then
  1426. begin
  1427. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SUB,OS_INT,1,NR_FUNCTION_RESULT_REG);
  1428. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_INT,OC_EQ,0,NR_FUNCTION_RESULT_REG,oldCurrExitLabel);
  1429. decconst:=1;
  1430. end
  1431. else
  1432. decconst:=2;
  1433. if fc_break in tryflowcontrol then
  1434. begin
  1435. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SUB,OS_INT,decconst,NR_FUNCTION_RESULT_REG);
  1436. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_INT,OC_EQ,0,NR_FUNCTION_RESULT_REG,oldBreakLabel);
  1437. decconst:=1;
  1438. end
  1439. else
  1440. inc(decconst);
  1441. if fc_continue in tryflowcontrol then
  1442. begin
  1443. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SUB,OS_INT,decconst,NR_FUNCTION_RESULT_REG);
  1444. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_INT,OC_EQ,0,NR_FUNCTION_RESULT_REG,oldContinueLabel);
  1445. end;
  1446. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1447. cg.a_label(current_asmdata.CurrAsmList,reraiselabel);
  1448. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_RERAISE',false);
  1449. { do some magic for exit,break,continue in the try block }
  1450. if fc_exit in tryflowcontrol then
  1451. begin
  1452. cg.a_label(current_asmdata.CurrAsmList,exitfinallylabel);
  1453. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1454. cg.g_exception_reason_save_const(current_asmdata.CurrAsmList,excepttemps.reasonbuf,2);
  1455. cg.a_jmp_always(current_asmdata.CurrAsmList,finallylabel);
  1456. { from g_exception_reason_load }
  1457. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1458. end;
  1459. if fc_break in tryflowcontrol then
  1460. begin
  1461. cg.a_label(current_asmdata.CurrAsmList,breakfinallylabel);
  1462. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1463. cg.g_exception_reason_save_const(current_asmdata.CurrAsmList,excepttemps.reasonbuf,3);
  1464. cg.a_jmp_always(current_asmdata.CurrAsmList,finallylabel);
  1465. { from g_exception_reason_load }
  1466. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1467. end;
  1468. if fc_continue in tryflowcontrol then
  1469. begin
  1470. cg.a_label(current_asmdata.CurrAsmList,continuefinallylabel);
  1471. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1472. cg.g_exception_reason_save_const(current_asmdata.CurrAsmList,excepttemps.reasonbuf,4);
  1473. cg.a_jmp_always(current_asmdata.CurrAsmList,finallylabel);
  1474. { from g_exception_reason_load }
  1475. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1476. end;
  1477. end;
  1478. unget_exception_temps(current_asmdata.CurrAsmList,excepttemps);
  1479. cg.a_label(current_asmdata.CurrAsmList,endfinallylabel);
  1480. { end cleanup }
  1481. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoEnd));
  1482. current_procinfo.CurrExitLabel:=oldCurrExitLabel;
  1483. if assigned(current_procinfo.CurrBreakLabel) then
  1484. begin
  1485. current_procinfo.CurrContinueLabel:=oldContinueLabel;
  1486. current_procinfo.CurrBreakLabel:=oldBreakLabel;
  1487. end;
  1488. flowcontrol:=oldflowcontrol+(tryflowcontrol-[fc_inflowcontrol]);
  1489. end;
  1490. begin
  1491. cwhilerepeatnode:=tcgwhilerepeatnode;
  1492. cifnode:=tcgifnode;
  1493. cfornode:=tcgfornode;
  1494. cexitnode:=tcgexitnode;
  1495. cbreaknode:=tcgbreaknode;
  1496. ccontinuenode:=tcgcontinuenode;
  1497. cgotonode:=tcggotonode;
  1498. clabelnode:=tcglabelnode;
  1499. craisenode:=tcgraisenode;
  1500. ctryexceptnode:=tcgtryexceptnode;
  1501. ctryfinallynode:=tcgtryfinallynode;
  1502. connode:=tcgonnode;
  1503. end.