ncgflw.pas 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691
  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,hlcgobj
  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. hlcg.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. hlcg.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. hlcg.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. hlcg.maketojumpbool(current_asmdata.CurrAsmList,left);
  163. hlcg.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. hlcg.maketojumpbool(current_asmdata.CurrAsmList,left);
  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. hlcg.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. hlcg.a_jmp_always(current_asmdata.CurrAsmList,hl);
  256. end;
  257. hlcg.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. hlcg.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. hlcg.a_label(current_asmdata.CurrAsmList,current_procinfo.CurrFalseLabel);
  285. end;
  286. if not(assigned(right)) then
  287. begin
  288. hlcg.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. hlcg.location_force_reg(current_asmdata.CurrAsmList,t1.location,t1.resultdef,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. hlcg.location_force_reg(current_asmdata.CurrAsmList,t1.location,t1.resultdef,t1.resultdef,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. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,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. hlcg.a_load_loc_ref(current_asmdata.CurrAsmList,right.resultdef,left.resultdef,right.location,left.location.reference);
  448. LOC_REGISTER,
  449. LOC_CREGISTER:
  450. hlcg.a_load_loc_reg(current_asmdata.CurrAsmList,right.resultdef,left.resultdef,right.location,left.location.register);
  451. {$ifndef cpuhighleveltarget}
  452. { still have to figure out how to handle the subset sizes }
  453. LOC_SUBSETREG,
  454. LOC_CSUBSETREG :
  455. cg.a_load_loc_subsetreg(current_asmdata.CurrAsmList,left.location.size,right.location,left.location.sreg);
  456. {$endif}
  457. else
  458. internalerror(200501311);
  459. end;
  460. if lnf_backward in loopflags then
  461. if count_var_is_signed then
  462. hcond:=OC_LT
  463. else
  464. hcond:=OC_B
  465. else
  466. if count_var_is_signed then
  467. hcond:=OC_GT
  468. else
  469. hcond:=OC_A;
  470. sync_regvars(true);
  471. {$ifdef OLDREGVARS}
  472. load_all_regvars(current_asmdata.CurrAsmList);
  473. {$endif OLDREGVARS}
  474. if temptovalue then
  475. begin
  476. hlcg.a_cmp_reg_loc_label(current_asmdata.CurrAsmList,left.resultdef,hcond,
  477. t1.location.register,left.location,current_procinfo.CurrBreakLabel);
  478. end
  479. else
  480. begin
  481. if lnf_testatbegin in loopflags then
  482. begin
  483. hlcg.a_cmp_const_loc_label(current_asmdata.CurrAsmList,left.resultdef,hcond,
  484. tordconstnode(t1).value.svalue,
  485. left.location,current_procinfo.CurrBreakLabel);
  486. end;
  487. end;
  488. {If the loopvar doesn't mind on exit, we avoid this ugly
  489. dec instruction and do the loopvar inc/dec after the loop
  490. body.}
  491. if not do_loopvar_at_end then
  492. begin
  493. if lnf_backward in loopflags then
  494. hop:=OP_ADD
  495. else
  496. hop:=OP_SUB;
  497. hlcg.a_op_const_loc(current_asmdata.CurrAsmList,hop,left.resultdef,1,left.location);
  498. end;
  499. if assigned(entrylabel) then
  500. hlcg.a_jmp_always(current_asmdata.CurrAsmList,tcglabelnode(entrylabel).getasmlabel);
  501. { align loop target }
  502. if not(cs_opt_size in current_settings.optimizerswitches) then
  503. current_asmdata.CurrAsmList.concat(Tai_align.Create(current_settings.alignment.loopalign));
  504. hlcg.a_label(current_asmdata.CurrAsmList,l3);
  505. {If the loopvar doesn't mind on exit, we avoid the loopvar inc/dec
  506. after the loop body instead of here.}
  507. if not do_loopvar_at_end then
  508. begin
  509. { according to count direction DEC or INC... }
  510. if lnf_backward in loopflags then
  511. hop:=OP_SUB
  512. else
  513. hop:=OP_ADD;
  514. hlcg.a_op_const_loc(current_asmdata.CurrAsmList,hop,left.resultdef,1,left.location);
  515. end;
  516. if assigned(t2) then
  517. begin
  518. { Calc register weight }
  519. oldexecutionweight:=cg.executionweight;
  520. cg.executionweight:=cg.executionweight*8;
  521. secondpass(t2);
  522. cg.executionweight:=oldexecutionweight;
  523. {$ifdef OLDREGVARS}
  524. load_all_regvars(current_asmdata.CurrAsmList);
  525. {$endif OLDREGVARS}
  526. end;
  527. {If the loopvar doesn't mind on exit, we do the loopvar inc/dec
  528. after the loop body instead of here.}
  529. if do_loopvar_at_end then
  530. begin
  531. { according to count direction DEC or INC... }
  532. if lnf_backward in loopflags then
  533. hop:=OP_SUB
  534. else
  535. hop:=OP_ADD;
  536. hlcg.a_op_const_loc(current_asmdata.CurrAsmList,hop,left.resultdef,1,left.location);
  537. end;
  538. hlcg.a_label(current_asmdata.CurrAsmList,current_procinfo.CurrContinueLabel);
  539. if do_loopvar_at_end then
  540. if lnf_backward in loopflags then
  541. if count_var_is_signed then
  542. hcond:=OC_GTE
  543. else
  544. hcond:=OC_AE
  545. else
  546. if count_var_is_signed then
  547. hcond:=OC_LTE
  548. else
  549. hcond:=OC_BE
  550. else
  551. if lnf_backward in loopflags then
  552. if count_var_is_signed then
  553. hcond:=OC_GT
  554. else
  555. hcond:=OC_A
  556. else
  557. if count_var_is_signed then
  558. hcond:=OC_LT
  559. else
  560. hcond:=OC_B;
  561. {$ifdef OLDREGVARS}
  562. load_all_regvars(current_asmdata.CurrAsmList);
  563. {$endif OLDREGVARS}
  564. { produce comparison and the corresponding }
  565. { jump }
  566. if temptovalue then
  567. begin
  568. hlcg.a_cmp_reg_loc_label(current_asmdata.CurrAsmList,left.resultdef,hcond,t1.location.register,
  569. left.location,l3);
  570. end
  571. else
  572. begin
  573. cmp_const:=Tordconstnode(t1).value;
  574. if do_loopvar_at_end then
  575. begin
  576. {Watch out for wrap around 255 -> 0.}
  577. {Ugly: This code is way to long... Use tables?}
  578. case opsize of
  579. OS_8:
  580. begin
  581. if lnf_backward in loopflags then
  582. begin
  583. if byte(cmp_const.svalue)=low(byte) then
  584. begin
  585. hcond:=OC_NE;
  586. cmp_const:=high(byte);
  587. end
  588. end
  589. else
  590. begin
  591. if byte(cmp_const.svalue)=high(byte) then
  592. begin
  593. hcond:=OC_NE;
  594. cmp_const:=low(byte);
  595. end
  596. end
  597. end;
  598. OS_16:
  599. begin
  600. if lnf_backward in loopflags then
  601. begin
  602. if word(cmp_const.svalue)=high(word) then
  603. begin
  604. hcond:=OC_NE;
  605. cmp_const:=low(word);
  606. end
  607. end
  608. else
  609. begin
  610. if word(cmp_const.svalue)=low(word) then
  611. begin
  612. hcond:=OC_NE;
  613. cmp_const:=high(word);
  614. end
  615. end
  616. end;
  617. OS_32:
  618. begin
  619. if lnf_backward in loopflags then
  620. begin
  621. if cardinal(cmp_const.svalue)=high(cardinal) then
  622. begin
  623. hcond:=OC_NE;
  624. cmp_const:=low(cardinal);
  625. end
  626. end
  627. else
  628. begin
  629. if cardinal(cmp_const.svalue)=low(cardinal) then
  630. begin
  631. hcond:=OC_NE;
  632. cmp_const:=high(cardinal);
  633. end
  634. end
  635. end;
  636. OS_64:
  637. begin
  638. if lnf_backward in loopflags then
  639. begin
  640. if qword(cmp_const.uvalue)=high(qword) then
  641. begin
  642. hcond:=OC_NE;
  643. cmp_const:=low(qword);
  644. end
  645. end
  646. else
  647. begin
  648. if qword(cmp_const.uvalue)=low(qword) then
  649. begin
  650. hcond:=OC_NE;
  651. cmp_const:=high(qword);
  652. end
  653. end
  654. end;
  655. OS_S8:
  656. begin
  657. if lnf_backward in loopflags then
  658. begin
  659. if shortint(cmp_const.svalue)=low(shortint) then
  660. begin
  661. hcond:=OC_NE;
  662. cmp_const:=high(shortint);
  663. end
  664. end
  665. else
  666. begin
  667. if shortint(cmp_const.svalue)=high(shortint) then
  668. begin
  669. hcond:=OC_NE;
  670. cmp_const:=int64(low(shortint));
  671. end
  672. end
  673. end;
  674. OS_S16:
  675. begin
  676. if lnf_backward in loopflags then
  677. begin
  678. if integer(cmp_const.svalue)=high(smallint) then
  679. begin
  680. hcond:=OC_NE;
  681. cmp_const:=int64(low(smallint));
  682. end
  683. end
  684. else
  685. begin
  686. if integer(cmp_const.svalue)=low(smallint) then
  687. begin
  688. hcond:=OC_NE;
  689. cmp_const:=int64(high(smallint));
  690. end
  691. end
  692. end;
  693. OS_S32:
  694. begin
  695. if lnf_backward in loopflags then
  696. begin
  697. if longint(cmp_const.svalue)=high(longint) then
  698. begin
  699. hcond:=OC_NE;
  700. cmp_const:=int64(low(longint));
  701. end
  702. end
  703. else
  704. begin
  705. if longint(cmp_const.svalue)=low(longint) then
  706. begin
  707. hcond:=OC_NE;
  708. cmp_const:=int64(high(longint));
  709. end
  710. end
  711. end;
  712. OS_S64:
  713. begin
  714. if lnf_backward in loopflags then
  715. begin
  716. if int64(cmp_const.svalue)=high(int64) then
  717. begin
  718. hcond:=OC_NE;
  719. cmp_const:=low(int64);
  720. end
  721. end
  722. else
  723. begin
  724. if int64(cmp_const.svalue)=low(int64) then
  725. begin
  726. hcond:=OC_NE;
  727. cmp_const:=high(int64);
  728. end
  729. end
  730. end;
  731. else
  732. internalerror(200201021);
  733. end;
  734. end;
  735. hlcg.a_cmp_const_loc_label(current_asmdata.CurrAsmList,left.resultdef,hcond,
  736. aint(cmp_const.svalue),left.location,l3);
  737. end;
  738. { this is the break label: }
  739. hlcg.a_label(current_asmdata.CurrAsmList,current_procinfo.CurrBreakLabel);
  740. sync_regvars(false);
  741. current_procinfo.CurrContinueLabel:=oldclabel;
  742. current_procinfo.CurrBreakLabel:=oldblabel;
  743. { a break/continue in a while/repeat block can't be seen outside }
  744. flowcontrol:=oldflowcontrol+(flowcontrol-[fc_break,fc_continue,fc_inflowcontrol]);
  745. end;
  746. {*****************************************************************************
  747. SecondExitN
  748. *****************************************************************************}
  749. procedure tcgexitnode.pass_generate_code;
  750. begin
  751. location_reset(location,LOC_VOID,OS_NO);
  752. include(flowcontrol,fc_exit);
  753. if assigned(left) then
  754. secondpass(left);
  755. hlcg.a_jmp_always(current_asmdata.CurrAsmList,current_procinfo.CurrExitLabel);
  756. end;
  757. {*****************************************************************************
  758. SecondBreakN
  759. *****************************************************************************}
  760. procedure tcgbreaknode.pass_generate_code;
  761. begin
  762. location_reset(location,LOC_VOID,OS_NO);
  763. include(flowcontrol,fc_break);
  764. if current_procinfo.CurrBreakLabel<>nil then
  765. begin
  766. {$ifdef OLDREGVARS}
  767. load_all_regvars(current_asmdata.CurrAsmList);
  768. {$endif OLDREGVARS}
  769. hlcg.a_jmp_always(current_asmdata.CurrAsmList,current_procinfo.CurrBreakLabel)
  770. end
  771. else
  772. CGMessage(cg_e_break_not_allowed);
  773. end;
  774. {*****************************************************************************
  775. SecondContinueN
  776. *****************************************************************************}
  777. procedure tcgcontinuenode.pass_generate_code;
  778. begin
  779. location_reset(location,LOC_VOID,OS_NO);
  780. include(flowcontrol,fc_continue);
  781. if current_procinfo.CurrContinueLabel<>nil then
  782. begin
  783. {$ifdef OLDREGVARS}
  784. load_all_regvars(current_asmdata.CurrAsmList);
  785. {$endif OLDREGVARS}
  786. hlcg.a_jmp_always(current_asmdata.CurrAsmList,current_procinfo.CurrContinueLabel)
  787. end
  788. else
  789. CGMessage(cg_e_continue_not_allowed);
  790. end;
  791. {*****************************************************************************
  792. SecondGoto
  793. *****************************************************************************}
  794. procedure tcggotonode.pass_generate_code;
  795. begin
  796. location_reset(location,LOC_VOID,OS_NO);
  797. include(flowcontrol,fc_gotolabel);
  798. {$ifdef OLDREGVARS}
  799. load_all_regvars(current_asmdata.CurrAsmList);
  800. {$endif OLDREGVARS}
  801. hlcg.a_jmp_always(current_asmdata.CurrAsmList,tcglabelnode(labelnode).getasmlabel)
  802. end;
  803. {*****************************************************************************
  804. SecondLabel
  805. *****************************************************************************}
  806. function tcglabelnode.getasmlabel : tasmlabel;
  807. begin
  808. if not(assigned(asmlabel)) then
  809. { labsym is not set in inlined procedures, but since assembler }
  810. { routines can't be inlined, that shouldn't matter }
  811. if assigned(labsym) and
  812. labsym.nonlocal then
  813. current_asmdata.getglobaljumplabel(asmlabel)
  814. else
  815. current_asmdata.getjumplabel(asmlabel);
  816. result:=asmlabel
  817. end;
  818. procedure tcglabelnode.pass_generate_code;
  819. begin
  820. location_reset(location,LOC_VOID,OS_NO);
  821. include(flowcontrol,fc_gotolabel);
  822. {$ifdef OLDREGVARS}
  823. load_all_regvars(current_asmdata.CurrAsmList);
  824. {$endif OLDREGVARS}
  825. hlcg.a_label(current_asmdata.CurrAsmList,getasmlabel);
  826. { Write also extra label if this label was referenced from
  827. assembler block }
  828. if assigned(labsym) and
  829. assigned(labsym.asmblocklabel) then
  830. hlcg.a_label(current_asmdata.CurrAsmList,labsym.asmblocklabel);
  831. secondpass(left);
  832. end;
  833. {*****************************************************************************
  834. SecondRaise
  835. *****************************************************************************}
  836. procedure tcgraisenode.pass_generate_code;
  837. var
  838. a : tasmlabel;
  839. href2: treference;
  840. paraloc1,paraloc2,paraloc3 : tcgpara;
  841. begin
  842. paraloc1.init;
  843. paraloc2.init;
  844. paraloc3.init;
  845. paramanager.getintparaloc(pocall_default,1,paraloc1);
  846. paramanager.getintparaloc(pocall_default,2,paraloc2);
  847. paramanager.getintparaloc(pocall_default,3,paraloc3);
  848. location_reset(location,LOC_VOID,OS_NO);
  849. if assigned(left) then
  850. begin
  851. { multiple parameters? }
  852. if assigned(right) then
  853. begin
  854. { frame tree }
  855. if assigned(third) then
  856. secondpass(third);
  857. secondpass(right);
  858. end;
  859. secondpass(left);
  860. if codegenerror then
  861. exit;
  862. { Push parameters }
  863. if assigned(right) then
  864. begin
  865. { frame tree }
  866. if assigned(third) then
  867. cg.a_load_loc_cgpara(current_asmdata.CurrAsmList,third.location,paraloc3)
  868. else
  869. cg.a_load_const_cgpara(current_asmdata.CurrAsmList,OS_INT,0,paraloc3);
  870. { push address }
  871. cg.a_load_loc_cgpara(current_asmdata.CurrAsmList,right.location,paraloc2);
  872. end
  873. else
  874. begin
  875. { get current address }
  876. current_asmdata.getaddrlabel(a);
  877. cg.a_label(current_asmdata.CurrAsmList,a);
  878. reference_reset_symbol(href2,a,0,1);
  879. { push current frame }
  880. cg.a_load_reg_cgpara(current_asmdata.CurrAsmList,OS_ADDR,NR_FRAME_POINTER_REG,paraloc3);
  881. { push current address }
  882. if target_info.system <> system_powerpc_macos then
  883. cg.a_loadaddr_ref_cgpara(current_asmdata.CurrAsmList,href2,paraloc2)
  884. else
  885. cg.a_load_const_cgpara(current_asmdata.CurrAsmList,OS_INT,0,paraloc2);
  886. end;
  887. cg.a_load_loc_cgpara(current_asmdata.CurrAsmList,left.location,paraloc1);
  888. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  889. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc2);
  890. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc3);
  891. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  892. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_RAISEEXCEPTION',false);
  893. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  894. end
  895. else
  896. begin
  897. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  898. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPADDRSTACK',false);
  899. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_RERAISE',false);
  900. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  901. end;
  902. paraloc1.done;
  903. paraloc2.done;
  904. paraloc3.done;
  905. end;
  906. {*****************************************************************************
  907. SecondTryExcept
  908. *****************************************************************************}
  909. var
  910. endexceptlabel : tasmlabel;
  911. { does the necessary things to clean up the object stack }
  912. { in the except block }
  913. procedure cleanupobjectstack;
  914. var
  915. paraloc1 : tcgpara;
  916. begin
  917. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  918. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPOBJECTSTACK',false);
  919. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  920. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  921. paraloc1.init;
  922. paramanager.getintparaloc(pocall_default,1,paraloc1);
  923. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  924. cg.a_load_reg_cgpara(current_asmdata.CurrAsmList,OS_ADDR,NR_FUNCTION_RESULT_REG,paraloc1);
  925. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  926. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  927. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_DESTROYEXCEPTION',false);
  928. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  929. paraloc1.done;
  930. end;
  931. procedure tcgtryexceptnode.pass_generate_code;
  932. var
  933. exceptlabel,doexceptlabel,oldendexceptlabel,
  934. lastonlabel,
  935. exitexceptlabel,
  936. continueexceptlabel,
  937. breakexceptlabel,
  938. exittrylabel,
  939. continuetrylabel,
  940. breaktrylabel,
  941. doobjectdestroy,
  942. doobjectdestroyandreraise,
  943. oldCurrExitLabel,
  944. oldContinueLabel,
  945. oldBreakLabel : tasmlabel;
  946. oldflowcontrol,tryflowcontrol,
  947. exceptflowcontrol : tflowcontrol;
  948. destroytemps,
  949. excepttemps : texceptiontemps;
  950. paraloc1 : tcgpara;
  951. label
  952. errorexit;
  953. begin
  954. location_reset(location,LOC_VOID,OS_NO);
  955. oldflowcontrol:=flowcontrol;
  956. flowcontrol:=[fc_inflowcontrol];
  957. { this can be called recursivly }
  958. oldBreakLabel:=nil;
  959. oldContinueLabel:=nil;
  960. oldendexceptlabel:=endexceptlabel;
  961. { save the old labels for control flow statements }
  962. oldCurrExitLabel:=current_procinfo.CurrExitLabel;
  963. if assigned(current_procinfo.CurrBreakLabel) then
  964. begin
  965. oldContinueLabel:=current_procinfo.CurrContinueLabel;
  966. oldBreakLabel:=current_procinfo.CurrBreakLabel;
  967. end;
  968. { get new labels for the control flow statements }
  969. current_asmdata.getjumplabel(exittrylabel);
  970. current_asmdata.getjumplabel(exitexceptlabel);
  971. if assigned(current_procinfo.CurrBreakLabel) then
  972. begin
  973. current_asmdata.getjumplabel(breaktrylabel);
  974. current_asmdata.getjumplabel(continuetrylabel);
  975. current_asmdata.getjumplabel(breakexceptlabel);
  976. current_asmdata.getjumplabel(continueexceptlabel);
  977. end;
  978. current_asmdata.getjumplabel(exceptlabel);
  979. current_asmdata.getjumplabel(doexceptlabel);
  980. current_asmdata.getjumplabel(endexceptlabel);
  981. current_asmdata.getjumplabel(lastonlabel);
  982. get_exception_temps(current_asmdata.CurrAsmList,excepttemps);
  983. new_exception(current_asmdata.CurrAsmList,excepttemps,exceptlabel);
  984. { try block }
  985. { set control flow labels for the try block }
  986. current_procinfo.CurrExitLabel:=exittrylabel;
  987. if assigned(oldBreakLabel) then
  988. begin
  989. current_procinfo.CurrContinueLabel:=continuetrylabel;
  990. current_procinfo.CurrBreakLabel:=breaktrylabel;
  991. end;
  992. flowcontrol:=[fc_inflowcontrol];
  993. secondpass(left);
  994. tryflowcontrol:=flowcontrol;
  995. if codegenerror then
  996. goto errorexit;
  997. { don't generate line info for internal cleanup }
  998. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoStart));
  999. cg.a_label(current_asmdata.CurrAsmList,exceptlabel);
  1000. free_exception(current_asmdata.CurrAsmList, excepttemps, 0, endexceptlabel, false);
  1001. cg.a_label(current_asmdata.CurrAsmList,doexceptlabel);
  1002. { end cleanup }
  1003. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoEnd));
  1004. { set control flow labels for the except block }
  1005. { and the on statements }
  1006. current_procinfo.CurrExitLabel:=exitexceptlabel;
  1007. if assigned(oldBreakLabel) then
  1008. begin
  1009. current_procinfo.CurrContinueLabel:=continueexceptlabel;
  1010. current_procinfo.CurrBreakLabel:=breakexceptlabel;
  1011. end;
  1012. flowcontrol:=[fc_inflowcontrol];
  1013. { on statements }
  1014. if assigned(right) then
  1015. secondpass(right);
  1016. { don't generate line info for internal cleanup }
  1017. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoStart));
  1018. cg.a_label(current_asmdata.CurrAsmList,lastonlabel);
  1019. { default handling except handling }
  1020. if assigned(t1) then
  1021. begin
  1022. { FPC_CATCHES must be called with
  1023. 'default handler' flag (=-1)
  1024. }
  1025. paraloc1.init;
  1026. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1027. cg.a_load_const_cgpara(current_asmdata.CurrAsmList,OS_ADDR,-1,paraloc1);
  1028. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  1029. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1030. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_CATCHES',false);
  1031. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1032. paraloc1.done;
  1033. { the destruction of the exception object must be also }
  1034. { guarded by an exception frame }
  1035. current_asmdata.getjumplabel(doobjectdestroy);
  1036. current_asmdata.getjumplabel(doobjectdestroyandreraise);
  1037. get_exception_temps(current_asmdata.CurrAsmList,destroytemps);
  1038. new_exception(current_asmdata.CurrAsmList,destroytemps,doobjectdestroyandreraise);
  1039. { except block needs line info }
  1040. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoEnd));
  1041. { here we don't have to reset flowcontrol }
  1042. { the default and on flowcontrols are handled equal }
  1043. secondpass(t1);
  1044. exceptflowcontrol:=flowcontrol;
  1045. { don't generate line info for internal cleanup }
  1046. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoStart));
  1047. cg.a_label(current_asmdata.CurrAsmList,doobjectdestroyandreraise);
  1048. free_exception(current_asmdata.CurrAsmList,destroytemps,0,doobjectdestroy,false);
  1049. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1050. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPSECONDOBJECTSTACK',false);
  1051. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1052. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1053. paraloc1.init;
  1054. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1055. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1056. cg.a_load_reg_cgpara(current_asmdata.CurrAsmList, OS_ADDR, NR_FUNCTION_RESULT_REG, paraloc1);
  1057. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  1058. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1059. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_DESTROYEXCEPTION',false);
  1060. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1061. paraloc1.done;
  1062. { we don't need to restore esi here because reraise never }
  1063. { returns }
  1064. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_RERAISE',false);
  1065. cg.a_label(current_asmdata.CurrAsmList,doobjectdestroy);
  1066. cleanupobjectstack;
  1067. unget_exception_temps(current_asmdata.CurrAsmList,destroytemps);
  1068. cg.a_jmp_always(current_asmdata.CurrAsmList,endexceptlabel);
  1069. end
  1070. else
  1071. begin
  1072. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_RERAISE',false);
  1073. exceptflowcontrol:=flowcontrol;
  1074. end;
  1075. if fc_exit in exceptflowcontrol then
  1076. begin
  1077. { do some magic for exit in the try block }
  1078. cg.a_label(current_asmdata.CurrAsmList,exitexceptlabel);
  1079. { we must also destroy the address frame which guards }
  1080. { exception object }
  1081. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1082. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPADDRSTACK',false);
  1083. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1084. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1085. cleanupobjectstack;
  1086. cg.a_jmp_always(current_asmdata.CurrAsmList,oldCurrExitLabel);
  1087. { from g_exception_reason_load }
  1088. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1089. end;
  1090. if fc_break in exceptflowcontrol then
  1091. begin
  1092. cg.a_label(current_asmdata.CurrAsmList,breakexceptlabel);
  1093. { we must also destroy the address frame which guards }
  1094. { exception object }
  1095. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1096. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPADDRSTACK',false);
  1097. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1098. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1099. cleanupobjectstack;
  1100. cg.a_jmp_always(current_asmdata.CurrAsmList,oldBreakLabel);
  1101. { from g_exception_reason_load }
  1102. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1103. end;
  1104. if fc_continue in exceptflowcontrol then
  1105. begin
  1106. cg.a_label(current_asmdata.CurrAsmList,continueexceptlabel);
  1107. { we must also destroy the address frame which guards }
  1108. { exception object }
  1109. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1110. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPADDRSTACK',false);
  1111. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1112. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1113. cleanupobjectstack;
  1114. cg.a_jmp_always(current_asmdata.CurrAsmList,oldContinueLabel);
  1115. { from g_exception_reason_load }
  1116. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1117. end;
  1118. if fc_exit in tryflowcontrol then
  1119. begin
  1120. { do some magic for exit in the try block }
  1121. cg.a_label(current_asmdata.CurrAsmList,exittrylabel);
  1122. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1123. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPADDRSTACK',false);
  1124. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1125. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1126. cg.a_jmp_always(current_asmdata.CurrAsmList,oldCurrExitLabel);
  1127. { from g_exception_reason_load }
  1128. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1129. end;
  1130. if fc_break in tryflowcontrol then
  1131. begin
  1132. cg.a_label(current_asmdata.CurrAsmList,breaktrylabel);
  1133. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1134. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPADDRSTACK',false);
  1135. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1136. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1137. cg.a_jmp_always(current_asmdata.CurrAsmList,oldBreakLabel);
  1138. { from g_exception_reason_load }
  1139. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1140. end;
  1141. if fc_continue in tryflowcontrol then
  1142. begin
  1143. cg.a_label(current_asmdata.CurrAsmList,continuetrylabel);
  1144. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1145. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPADDRSTACK',false);
  1146. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1147. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1148. cg.a_jmp_always(current_asmdata.CurrAsmList,oldContinueLabel);
  1149. { from g_exception_reason_load }
  1150. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1151. end;
  1152. unget_exception_temps(current_asmdata.CurrAsmList,excepttemps);
  1153. cg.a_label(current_asmdata.CurrAsmList,endexceptlabel);
  1154. { end cleanup }
  1155. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoEnd));
  1156. errorexit:
  1157. { restore all saved labels }
  1158. endexceptlabel:=oldendexceptlabel;
  1159. { restore the control flow labels }
  1160. current_procinfo.CurrExitLabel:=oldCurrExitLabel;
  1161. if assigned(oldBreakLabel) then
  1162. begin
  1163. current_procinfo.CurrContinueLabel:=oldContinueLabel;
  1164. current_procinfo.CurrBreakLabel:=oldBreakLabel;
  1165. end;
  1166. { return all used control flow statements }
  1167. flowcontrol:=oldflowcontrol+(exceptflowcontrol +
  1168. tryflowcontrol - [fc_inflowcontrol]);
  1169. end;
  1170. procedure tcgonnode.pass_generate_code;
  1171. var
  1172. nextonlabel,
  1173. exitonlabel,
  1174. continueonlabel,
  1175. breakonlabel,
  1176. oldCurrExitLabel,
  1177. oldContinueLabel,
  1178. doobjectdestroyandreraise,
  1179. doobjectdestroy,
  1180. oldBreakLabel : tasmlabel;
  1181. oldflowcontrol : tflowcontrol;
  1182. excepttemps : texceptiontemps;
  1183. href2: treference;
  1184. paraloc1 : tcgpara;
  1185. exceptvarsym : tlocalvarsym;
  1186. begin
  1187. paraloc1.init;
  1188. location_reset(location,LOC_VOID,OS_NO);
  1189. oldflowcontrol:=flowcontrol;
  1190. flowcontrol:=[fc_inflowcontrol];
  1191. current_asmdata.getjumplabel(nextonlabel);
  1192. { send the vmt parameter }
  1193. reference_reset_symbol(href2,current_asmdata.RefAsmSymbol(excepttype.vmt_mangledname),0,sizeof(pint));
  1194. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1195. cg.a_loadaddr_ref_cgpara(current_asmdata.CurrAsmList,href2,paraloc1);
  1196. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  1197. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1198. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_CATCHES',false);
  1199. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1200. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1201. { is it this catch? No. go to next onlabel }
  1202. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_ADDR,OC_EQ,0,NR_FUNCTION_RESULT_REG,nextonlabel);
  1203. { Retrieve exception variable }
  1204. if assigned(excepTSymtable) then
  1205. exceptvarsym:=tlocalvarsym(excepTSymtable.SymList[0])
  1206. else
  1207. internalerror(2011020401);
  1208. location_reset_ref(exceptvarsym.localloc,LOC_REFERENCE,OS_ADDR,sizeof(pint));
  1209. tg.GetLocal(current_asmdata.CurrAsmList,sizeof(pint),voidpointertype,exceptvarsym.localloc.reference);
  1210. cg.a_load_reg_ref(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,NR_FUNCTION_RESULT_REG,exceptvarsym.localloc.reference);
  1211. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1212. { in the case that another exception is risen
  1213. we've to destroy the old one }
  1214. current_asmdata.getjumplabel(doobjectdestroyandreraise);
  1215. { call setjmp, and jump to finally label on non-zero result }
  1216. get_exception_temps(current_asmdata.CurrAsmList,excepttemps);
  1217. new_exception(current_asmdata.CurrAsmList,excepttemps,doobjectdestroyandreraise);
  1218. oldBreakLabel:=nil;
  1219. oldContinueLabel:=nil;
  1220. if assigned(right) then
  1221. begin
  1222. oldCurrExitLabel:=current_procinfo.CurrExitLabel;
  1223. current_asmdata.getjumplabel(exitonlabel);
  1224. current_procinfo.CurrExitLabel:=exitonlabel;
  1225. if assigned(current_procinfo.CurrBreakLabel) then
  1226. begin
  1227. oldContinueLabel:=current_procinfo.CurrContinueLabel;
  1228. oldBreakLabel:=current_procinfo.CurrBreakLabel;
  1229. current_asmdata.getjumplabel(breakonlabel);
  1230. current_asmdata.getjumplabel(continueonlabel);
  1231. current_procinfo.CurrContinueLabel:=continueonlabel;
  1232. current_procinfo.CurrBreakLabel:=breakonlabel;
  1233. end;
  1234. secondpass(right);
  1235. end;
  1236. { don't generate lineinfo for internal cleanup }
  1237. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoStart));
  1238. current_asmdata.getjumplabel(doobjectdestroy);
  1239. cg.a_label(current_asmdata.CurrAsmList,doobjectdestroyandreraise);
  1240. free_exception(current_asmdata.CurrAsmList,excepttemps,0,doobjectdestroy,false);
  1241. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1242. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_POPSECONDOBJECTSTACK',false);
  1243. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1244. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1245. paramanager.getintparaloc(pocall_default,1,paraloc1);
  1246. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1247. cg.a_load_reg_cgpara(current_asmdata.CurrAsmList, OS_ADDR, NR_FUNCTION_RESULT_REG, paraloc1);
  1248. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  1249. cg.allocallcpuregisters(current_asmdata.CurrAsmList);
  1250. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_DESTROYEXCEPTION',false);
  1251. cg.deallocallcpuregisters(current_asmdata.CurrAsmList);
  1252. { we don't need to store/restore registers here because reraise never
  1253. returns }
  1254. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_RERAISE',false);
  1255. cg.a_label(current_asmdata.CurrAsmList,doobjectdestroy);
  1256. cleanupobjectstack;
  1257. { clear some stuff }
  1258. tg.UngetLocal(current_asmdata.CurrAsmList,exceptvarsym.localloc.reference);
  1259. exceptvarsym.localloc.loc:=LOC_INVALID;
  1260. cg.a_jmp_always(current_asmdata.CurrAsmList,endexceptlabel);
  1261. if assigned(right) then
  1262. begin
  1263. { special handling for control flow instructions }
  1264. if fc_exit in flowcontrol then
  1265. begin
  1266. { the address and object pop does secondtryexcept }
  1267. cg.a_label(current_asmdata.CurrAsmList,exitonlabel);
  1268. cg.a_jmp_always(current_asmdata.CurrAsmList,oldCurrExitLabel);
  1269. end;
  1270. if fc_break in flowcontrol then
  1271. begin
  1272. { the address and object pop does secondtryexcept }
  1273. cg.a_label(current_asmdata.CurrAsmList,breakonlabel);
  1274. cg.a_jmp_always(current_asmdata.CurrAsmList,oldBreakLabel);
  1275. end;
  1276. if fc_continue in flowcontrol then
  1277. begin
  1278. { the address and object pop does secondtryexcept }
  1279. cg.a_label(current_asmdata.CurrAsmList,continueonlabel);
  1280. cg.a_jmp_always(current_asmdata.CurrAsmList,oldContinueLabel);
  1281. end;
  1282. current_procinfo.CurrExitLabel:=oldCurrExitLabel;
  1283. if assigned(oldBreakLabel) then
  1284. begin
  1285. current_procinfo.CurrContinueLabel:=oldContinueLabel;
  1286. current_procinfo.CurrBreakLabel:=oldBreakLabel;
  1287. end;
  1288. end;
  1289. unget_exception_temps(current_asmdata.CurrAsmList,excepttemps);
  1290. cg.a_label(current_asmdata.CurrAsmList,nextonlabel);
  1291. flowcontrol:=oldflowcontrol+(flowcontrol-[fc_inflowcontrol]);
  1292. paraloc1.done;
  1293. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoEnd));
  1294. { next on node }
  1295. if assigned(left) then
  1296. secondpass(left);
  1297. end;
  1298. {*****************************************************************************
  1299. SecondTryFinally
  1300. *****************************************************************************}
  1301. procedure tcgtryfinallynode.pass_generate_code;
  1302. var
  1303. reraiselabel,
  1304. finallylabel,
  1305. endfinallylabel,
  1306. exitfinallylabel,
  1307. continuefinallylabel,
  1308. breakfinallylabel,
  1309. oldCurrExitLabel,
  1310. oldContinueLabel,
  1311. oldBreakLabel : tasmlabel;
  1312. oldflowcontrol,tryflowcontrol : tflowcontrol;
  1313. decconst : longint;
  1314. excepttemps : texceptiontemps;
  1315. retsym: tlocalvarsym;
  1316. begin
  1317. location_reset(location,LOC_VOID,OS_NO);
  1318. { check if child nodes do a break/continue/exit }
  1319. oldflowcontrol:=flowcontrol;
  1320. flowcontrol:=[fc_inflowcontrol];
  1321. current_asmdata.getjumplabel(finallylabel);
  1322. current_asmdata.getjumplabel(endfinallylabel);
  1323. current_asmdata.getjumplabel(reraiselabel);
  1324. { the finally block must catch break, continue and exit }
  1325. { statements }
  1326. oldCurrExitLabel:=current_procinfo.CurrExitLabel;
  1327. if implicitframe then
  1328. exitfinallylabel:=finallylabel
  1329. else
  1330. current_asmdata.getjumplabel(exitfinallylabel);
  1331. current_procinfo.CurrExitLabel:=exitfinallylabel;
  1332. if assigned(current_procinfo.CurrBreakLabel) then
  1333. begin
  1334. oldContinueLabel:=current_procinfo.CurrContinueLabel;
  1335. oldBreakLabel:=current_procinfo.CurrBreakLabel;
  1336. if implicitframe then
  1337. begin
  1338. breakfinallylabel:=finallylabel;
  1339. continuefinallylabel:=finallylabel;
  1340. end
  1341. else
  1342. begin
  1343. current_asmdata.getjumplabel(breakfinallylabel);
  1344. current_asmdata.getjumplabel(continuefinallylabel);
  1345. end;
  1346. current_procinfo.CurrContinueLabel:=continuefinallylabel;
  1347. current_procinfo.CurrBreakLabel:=breakfinallylabel;
  1348. end;
  1349. { call setjmp, and jump to finally label on non-zero result }
  1350. get_exception_temps(current_asmdata.CurrAsmList,excepttemps);
  1351. new_exception(current_asmdata.CurrAsmList,excepttemps,finallylabel);
  1352. { try code }
  1353. if assigned(left) then
  1354. begin
  1355. secondpass(left);
  1356. tryflowcontrol:=flowcontrol;
  1357. if codegenerror then
  1358. exit;
  1359. end;
  1360. { don't generate line info for internal cleanup }
  1361. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoStart));
  1362. cg.a_label(current_asmdata.CurrAsmList,finallylabel);
  1363. { just free the frame information }
  1364. free_exception(current_asmdata.CurrAsmList,excepttemps,1,finallylabel,true);
  1365. { end cleanup }
  1366. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoEnd));
  1367. { finally code }
  1368. flowcontrol:=[fc_inflowcontrol];
  1369. secondpass(right);
  1370. { goto is allowed if it stays inside the finally block,
  1371. this is checked using the exception block number }
  1372. if (flowcontrol-[fc_gotolabel])<>[fc_inflowcontrol] then
  1373. CGMessage(cg_e_control_flow_outside_finally);
  1374. if codegenerror then
  1375. exit;
  1376. { don't generate line info for internal cleanup }
  1377. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoStart));
  1378. { the value should now be in the exception handler }
  1379. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1380. if implicitframe then
  1381. begin
  1382. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_INT,OC_EQ,0,NR_FUNCTION_RESULT_REG,endfinallylabel);
  1383. { from g_exception_reason_load }
  1384. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1385. { finally code only needed to be executed on exception }
  1386. flowcontrol:=[fc_inflowcontrol];
  1387. secondpass(t1);
  1388. if flowcontrol<>[fc_inflowcontrol] then
  1389. CGMessage(cg_e_control_flow_outside_finally);
  1390. if codegenerror then
  1391. exit;
  1392. {$if defined(x86) or defined(arm)}
  1393. if (tf_safecall_exceptions in target_info.flags) and
  1394. (current_procinfo.procdef.proccalloption=pocall_safecall) then
  1395. begin
  1396. { find safe_result variable we created in the generate_except_block }
  1397. retsym:=tlocalvarsym(current_procinfo.procdef.localst.Find('safe_result'));
  1398. { Set return value of safecall procedure to indicate exception. }
  1399. { Exception will be raised after procedure exit based on return value }
  1400. cg.a_reg_alloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1401. cg.a_load_loc_reg(current_asmdata.CurrAsmList,OS_INT,retsym.localloc,NR_FUNCTION_RESULT_REG);
  1402. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1403. end
  1404. else
  1405. {$endif}
  1406. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_RERAISE',false);
  1407. end
  1408. else
  1409. begin
  1410. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_INT,OC_EQ,0,NR_FUNCTION_RESULT_REG,endfinallylabel);
  1411. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SUB,OS_INT,1,NR_FUNCTION_RESULT_REG);
  1412. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_INT,OC_EQ,0,NR_FUNCTION_RESULT_REG,reraiselabel);
  1413. if fc_exit in tryflowcontrol then
  1414. begin
  1415. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SUB,OS_INT,1,NR_FUNCTION_RESULT_REG);
  1416. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_INT,OC_EQ,0,NR_FUNCTION_RESULT_REG,oldCurrExitLabel);
  1417. decconst:=1;
  1418. end
  1419. else
  1420. decconst:=2;
  1421. if fc_break in tryflowcontrol then
  1422. begin
  1423. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SUB,OS_INT,decconst,NR_FUNCTION_RESULT_REG);
  1424. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_INT,OC_EQ,0,NR_FUNCTION_RESULT_REG,oldBreakLabel);
  1425. decconst:=1;
  1426. end
  1427. else
  1428. inc(decconst);
  1429. if fc_continue in tryflowcontrol then
  1430. begin
  1431. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SUB,OS_INT,decconst,NR_FUNCTION_RESULT_REG);
  1432. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_INT,OC_EQ,0,NR_FUNCTION_RESULT_REG,oldContinueLabel);
  1433. end;
  1434. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1435. cg.a_label(current_asmdata.CurrAsmList,reraiselabel);
  1436. cg.a_call_name(current_asmdata.CurrAsmList,'FPC_RERAISE',false);
  1437. { do some magic for exit,break,continue in the try block }
  1438. if fc_exit in tryflowcontrol then
  1439. begin
  1440. cg.a_label(current_asmdata.CurrAsmList,exitfinallylabel);
  1441. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1442. cg.g_exception_reason_save_const(current_asmdata.CurrAsmList,excepttemps.reasonbuf,2);
  1443. cg.a_jmp_always(current_asmdata.CurrAsmList,finallylabel);
  1444. { from g_exception_reason_load }
  1445. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1446. end;
  1447. if fc_break in tryflowcontrol then
  1448. begin
  1449. cg.a_label(current_asmdata.CurrAsmList,breakfinallylabel);
  1450. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1451. cg.g_exception_reason_save_const(current_asmdata.CurrAsmList,excepttemps.reasonbuf,3);
  1452. cg.a_jmp_always(current_asmdata.CurrAsmList,finallylabel);
  1453. { from g_exception_reason_load }
  1454. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1455. end;
  1456. if fc_continue in tryflowcontrol then
  1457. begin
  1458. cg.a_label(current_asmdata.CurrAsmList,continuefinallylabel);
  1459. cg.g_exception_reason_load(current_asmdata.CurrAsmList,excepttemps.reasonbuf);
  1460. cg.g_exception_reason_save_const(current_asmdata.CurrAsmList,excepttemps.reasonbuf,4);
  1461. cg.a_jmp_always(current_asmdata.CurrAsmList,finallylabel);
  1462. { from g_exception_reason_load }
  1463. cg.a_reg_dealloc(current_asmdata.CurrAsmList,NR_FUNCTION_RESULT_REG);
  1464. end;
  1465. end;
  1466. unget_exception_temps(current_asmdata.CurrAsmList,excepttemps);
  1467. cg.a_label(current_asmdata.CurrAsmList,endfinallylabel);
  1468. { end cleanup }
  1469. current_asmdata.CurrAsmList.concat(tai_marker.create(mark_NoLineInfoEnd));
  1470. current_procinfo.CurrExitLabel:=oldCurrExitLabel;
  1471. if assigned(current_procinfo.CurrBreakLabel) then
  1472. begin
  1473. current_procinfo.CurrContinueLabel:=oldContinueLabel;
  1474. current_procinfo.CurrBreakLabel:=oldBreakLabel;
  1475. end;
  1476. flowcontrol:=oldflowcontrol+(tryflowcontrol-[fc_inflowcontrol]);
  1477. end;
  1478. begin
  1479. cwhilerepeatnode:=tcgwhilerepeatnode;
  1480. cifnode:=tcgifnode;
  1481. cfornode:=tcgfornode;
  1482. cexitnode:=tcgexitnode;
  1483. cbreaknode:=tcgbreaknode;
  1484. ccontinuenode:=tcgcontinuenode;
  1485. cgotonode:=tcggotonode;
  1486. clabelnode:=tcglabelnode;
  1487. craisenode:=tcgraisenode;
  1488. ctryexceptnode:=tcgtryexceptnode;
  1489. ctryfinallynode:=tcgtryfinallynode;
  1490. connode:=tcgonnode;
  1491. end.