ncgflw.pas 68 KB

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