n386flw.pas 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. Generate i386 assembler for nodes that influence the flow
  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 n386flw;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. node,nflw;
  23. type
  24. ti386whilerepeatnode = class(twhilerepeatnode)
  25. procedure pass_2;override;
  26. end;
  27. ti386ifnode = class(tifnode)
  28. procedure pass_2;override;
  29. end;
  30. ti386fornode = class(tfornode)
  31. procedure pass_2;override;
  32. end;
  33. ti386exitnode = class(texitnode)
  34. procedure pass_2;override;
  35. end;
  36. ti386breaknode = class(tbreaknode)
  37. procedure pass_2;override;
  38. end;
  39. ti386continuenode = class(tcontinuenode)
  40. procedure pass_2;override;
  41. end;
  42. ti386gotonode = class(tgotonode)
  43. procedure pass_2;override;
  44. end;
  45. ti386labelnode = class(tlabelnode)
  46. procedure pass_2;override;
  47. end;
  48. ti386raisenode = class(traisenode)
  49. procedure pass_2;override;
  50. end;
  51. ti386tryexceptnode = class(ttryexceptnode)
  52. procedure pass_2;override;
  53. end;
  54. ti386tryfinallynode = class(ttryfinallynode)
  55. procedure pass_2;override;
  56. end;
  57. ti386onnode = class(tonnode)
  58. procedure pass_2;override;
  59. end;
  60. ti386failnode = class(tfailnode)
  61. procedure pass_2;override;
  62. end;
  63. implementation
  64. uses
  65. verbose,globtype,globals,systems,
  66. symconst,symdef,symsym,aasm,types,
  67. hcodegen,temp_gen,pass_2,
  68. cpubase,cpuasm,
  69. pass_1,nld,ncon,
  70. cgai386,tgcpu,n386util,regvars;
  71. {*****************************************************************************
  72. Second_While_RepeatN
  73. *****************************************************************************}
  74. procedure ti386whilerepeatnode.pass_2;
  75. var
  76. lcont,lbreak,lloop,
  77. oldclabel,oldblabel : pasmlabel;
  78. otlabel,oflabel : pasmlabel;
  79. //start_regvars_loaded,
  80. //then_regvars_loaded: regvar_booleanarray;
  81. begin
  82. getlabel(lloop);
  83. getlabel(lcont);
  84. getlabel(lbreak);
  85. { arrange continue and breaklabels: }
  86. oldclabel:=aktcontinuelabel;
  87. oldblabel:=aktbreaklabel;
  88. load_all_regvars(exprasmlist);
  89. { handling code at the end as it is much more efficient, and makes
  90. while equal to repeat loop, only the end true/false is swapped (PFV) }
  91. if nodetype=whilen then
  92. emitjmp(C_None,lcont);
  93. emitlab(lloop);
  94. aktcontinuelabel:=lcont;
  95. aktbreaklabel:=lbreak;
  96. cleartempgen;
  97. if assigned(right) then
  98. secondpass(right);
  99. load_all_regvars(exprasmlist);
  100. emitlab(lcont);
  101. otlabel:=truelabel;
  102. oflabel:=falselabel;
  103. if nodetype=whilen then
  104. begin
  105. truelabel:=lloop;
  106. falselabel:=lbreak;
  107. end
  108. { repeatn }
  109. else
  110. begin
  111. truelabel:=lbreak;
  112. falselabel:=lloop;
  113. end;
  114. cleartempgen;
  115. secondpass(left);
  116. load_all_regvars(exprasmlist);
  117. maketojumpbool(left);
  118. emitlab(lbreak);
  119. truelabel:=otlabel;
  120. falselabel:=oflabel;
  121. aktcontinuelabel:=oldclabel;
  122. aktbreaklabel:=oldblabel;
  123. { a break/continue in a while/repeat block can't be seen outside }
  124. flowcontrol:=flowcontrol-[fc_break,fc_continue];
  125. end;
  126. {*****************************************************************************
  127. TI386IFNODE
  128. *****************************************************************************}
  129. procedure ti386ifnode.pass_2;
  130. var
  131. hl,otlabel,oflabel : pasmlabel;
  132. begin
  133. otlabel:=truelabel;
  134. oflabel:=falselabel;
  135. getlabel(truelabel);
  136. getlabel(falselabel);
  137. cleartempgen;
  138. secondpass(left);
  139. load_all_regvars(exprasmlist);
  140. maketojumpbool(left);
  141. if assigned(right) then
  142. begin
  143. emitlab(truelabel);
  144. cleartempgen;
  145. secondpass(right);
  146. { automatically done for blocks, but not for statements (JM) }
  147. load_all_regvars(exprasmlist);
  148. end;
  149. if assigned(t1) then
  150. begin
  151. if assigned(right) then
  152. begin
  153. getlabel(hl);
  154. { do go back to if line !! }
  155. aktfilepos:=exprasmList.getlasttaifilepos^;
  156. emitjmp(C_None,hl);
  157. end;
  158. emitlab(falselabel);
  159. cleartempgen;
  160. secondpass(t1);
  161. load_all_regvars(exprasmlist);
  162. if assigned(right) then
  163. emitlab(hl);
  164. end
  165. else
  166. begin
  167. emitlab(falselabel);
  168. end;
  169. if not(assigned(right)) then
  170. begin
  171. emitlab(truelabel);
  172. end;
  173. truelabel:=otlabel;
  174. falselabel:=oflabel;
  175. end;
  176. {*****************************************************************************
  177. SecondFor
  178. *****************************************************************************}
  179. procedure ti386fornode.pass_2;
  180. var
  181. l3,oldclabel,oldblabel : pasmlabel;
  182. omitfirstcomp,temptovalue : boolean;
  183. hs : byte;
  184. temp1 : treference;
  185. hop : tasmop;
  186. hcond : tasmcond;
  187. cmpreg,cmp32 : tregister;
  188. opsize : topsize;
  189. count_var_is_signed : boolean;
  190. begin
  191. oldclabel:=aktcontinuelabel;
  192. oldblabel:=aktbreaklabel;
  193. getlabel(aktcontinuelabel);
  194. getlabel(aktbreaklabel);
  195. getlabel(l3);
  196. { could we spare the first comparison ? }
  197. omitfirstcomp:=false;
  198. if right.nodetype=ordconstn then
  199. if tassignmentnode(left).right.nodetype=ordconstn then
  200. omitfirstcomp:=((nf_backward in flags) and
  201. (tordconstnode(tassignmentnode(left).right).value>=tordconstnode(right).value))
  202. or (not(nf_backward in flags) and
  203. (tordconstnode(tassignmentnode(left).right).value<=tordconstnode(right).value));
  204. { only calculate reference }
  205. cleartempgen;
  206. secondpass(t2);
  207. hs:=t2.resulttype^.size;
  208. if t2.location.loc <> LOC_CREGISTER then
  209. cmp32:=getregister32;
  210. case hs of
  211. 1 : begin
  212. opsize:=S_B;
  213. if t2.location.loc <> LOC_CREGISTER then
  214. cmpreg:=reg32toreg8(cmp32);
  215. end;
  216. 2 : begin
  217. opsize:=S_W;
  218. if t2.location.loc <> LOC_CREGISTER then
  219. cmpreg:=reg32toreg16(cmp32);
  220. end;
  221. 4 : begin
  222. opsize:=S_L;
  223. if t2.location.loc <> LOC_CREGISTER then
  224. cmpreg:=cmp32;
  225. end;
  226. end;
  227. { first set the to value
  228. because the count var can be in the expression !! }
  229. cleartempgen;
  230. secondpass(right);
  231. { calculate pointer value and check if changeable and if so }
  232. { load into temporary variable }
  233. if right.nodetype<>ordconstn then
  234. begin
  235. temp1.symbol:=nil;
  236. gettempofsizereference(hs,temp1);
  237. temptovalue:=true;
  238. if (right.location.loc=LOC_REGISTER) or
  239. (right.location.loc=LOC_CREGISTER) then
  240. begin
  241. emit_reg_ref(A_MOV,opsize,right.location.register,
  242. newreference(temp1));
  243. end
  244. else
  245. concatcopy(right.location.reference,temp1,hs,false,false);
  246. end
  247. else
  248. temptovalue:=false;
  249. { produce start assignment }
  250. cleartempgen;
  251. secondpass(left);
  252. count_var_is_signed:=is_signed(porddef(t2.resulttype));
  253. if temptovalue then
  254. begin
  255. if t2.location.loc=LOC_CREGISTER then
  256. begin
  257. emit_ref_reg(A_CMP,opsize,newreference(temp1),
  258. t2.location.register);
  259. end
  260. else
  261. begin
  262. emit_ref_reg(A_MOV,opsize,newreference(t2.location.reference),
  263. cmpreg);
  264. emit_ref_reg(A_CMP,opsize,newreference(temp1),
  265. cmpreg);
  266. { temp register not necessary anymore currently (JM) }
  267. ungetregister32(cmp32);
  268. end;
  269. end
  270. else
  271. begin
  272. if not(omitfirstcomp) then
  273. begin
  274. if t2.location.loc=LOC_CREGISTER then
  275. emit_const_reg(A_CMP,opsize,tordconstnode(right).value,
  276. t2.location.register)
  277. else
  278. emit_const_ref(A_CMP,opsize,tordconstnode(right).value,
  279. newreference(t2.location.reference));
  280. end;
  281. end;
  282. if nf_backward in flags then
  283. if count_var_is_signed then
  284. hcond:=C_L
  285. else
  286. hcond:=C_B
  287. else
  288. if count_var_is_signed then
  289. hcond:=C_G
  290. else
  291. hcond:=C_A;
  292. load_all_regvars(exprasmlist);
  293. if not(omitfirstcomp) or temptovalue then
  294. emitjmp(hcond,aktbreaklabel);
  295. { align loop target }
  296. if not(cs_littlesize in aktglobalswitches) then
  297. exprasmList.concat(Tai_align.Create_op(4,$90));
  298. emitlab(l3);
  299. { help register must not be in instruction block }
  300. cleartempgen;
  301. if assigned(t1) then
  302. begin
  303. secondpass(t1);
  304. load_all_regvars(exprasmlist);
  305. end;
  306. emitlab(aktcontinuelabel);
  307. { makes no problems there }
  308. cleartempgen;
  309. if (t2.location.loc <> LOC_CREGISTER) then
  310. begin
  311. { demand help register again }
  312. cmp32:=getregister32;
  313. case hs of
  314. 1 : cmpreg:=reg32toreg8(cmp32);
  315. 2 : cmpreg:=reg32toreg16(cmp32);
  316. 4 : cmpreg:=cmp32;
  317. end;
  318. end;
  319. { produce comparison and the corresponding }
  320. { jump }
  321. if temptovalue then
  322. begin
  323. if t2.location.loc=LOC_CREGISTER then
  324. begin
  325. emit_ref_reg(A_CMP,opsize,newreference(temp1),
  326. t2.location.register);
  327. end
  328. else
  329. begin
  330. emit_ref_reg(A_MOV,opsize,newreference(t2.location.reference),
  331. cmpreg);
  332. emit_ref_reg(A_CMP,opsize,newreference(temp1),
  333. cmpreg);
  334. end;
  335. end
  336. else
  337. begin
  338. if t2.location.loc=LOC_CREGISTER then
  339. emit_const_reg(A_CMP,opsize,tordconstnode(right).value,
  340. t2.location.register)
  341. else
  342. emit_const_ref(A_CMP,opsize,tordconstnode(right).value,
  343. newreference(t2.location.reference));
  344. end;
  345. if nf_backward in flags then
  346. if count_var_is_signed then
  347. hcond:=C_LE
  348. else
  349. hcond:=C_BE
  350. else
  351. if count_var_is_signed then
  352. hcond:=C_GE
  353. else
  354. hcond:=C_AE;
  355. load_all_regvars(exprasmlist);
  356. emitjmp(hcond,aktbreaklabel);
  357. { according to count direction DEC or INC... }
  358. { must be after the test because of 0 to 255 for bytes !! }
  359. if nf_backward in flags then
  360. hop:=A_DEC
  361. else
  362. hop:=A_INC;
  363. if t2.location.loc=LOC_CREGISTER then
  364. emit_reg(hop,opsize,t2.location.register)
  365. else
  366. emit_ref(hop,opsize,newreference(t2.location.reference));
  367. emitjmp(C_None,l3);
  368. if (t2.location.loc <> LOC_CREGISTER) then
  369. ungetregister32(cmp32);
  370. if temptovalue then
  371. ungetiftemp(temp1);
  372. { this is the break label: }
  373. emitlab(aktbreaklabel);
  374. aktcontinuelabel:=oldclabel;
  375. aktbreaklabel:=oldblabel;
  376. { a break/continue in a for block can't be seen outside }
  377. flowcontrol:=flowcontrol-[fc_break,fc_continue];
  378. end;
  379. {*****************************************************************************
  380. SecondExitN
  381. *****************************************************************************}
  382. procedure ti386exitnode.pass_2;
  383. var
  384. {op : tasmop;
  385. s : topsize;}
  386. otlabel,oflabel : pasmlabel;
  387. r : preference;
  388. is_mem,
  389. allocated_eax,
  390. allocated_edx: boolean;
  391. procedure cleanleft;
  392. begin
  393. if is_mem then
  394. begin
  395. del_reference(left.location.reference);
  396. ungetiftemp(left.location.reference);
  397. end
  398. else
  399. begin
  400. ungetregister(left.location.register);
  401. if left.location.registerhigh <> R_NO then
  402. ungetregister(left.location.registerhigh);
  403. end;
  404. end;
  405. label
  406. do_jmp;
  407. begin
  408. load_all_regvars(exprasmlist);
  409. include(flowcontrol,fc_exit);
  410. if assigned(left) then
  411. if left.nodetype=assignn then
  412. begin
  413. { just do a normal assignment followed by exit }
  414. secondpass(left);
  415. emitjmp(C_None,aktexitlabel);
  416. end
  417. else
  418. begin
  419. allocated_eax := false;
  420. allocated_edx := false;
  421. otlabel:=truelabel;
  422. oflabel:=falselabel;
  423. getlabel(truelabel);
  424. getlabel(falselabel);
  425. secondpass(left);
  426. case left.location.loc of
  427. LOC_FPU : goto do_jmp;
  428. LOC_MEM,
  429. LOC_REFERENCE : is_mem:=true;
  430. LOC_CREGISTER,
  431. LOC_REGISTER : is_mem:=false;
  432. LOC_FLAGS : begin
  433. exprasmlist.concat(tairegalloc.alloc(R_EAX));
  434. allocated_eax := true;
  435. emit_flag2reg(left.location.resflags,R_AL);
  436. goto do_jmp;
  437. end;
  438. LOC_JUMP : begin
  439. exprasmlist.concat(tairegalloc.alloc(R_EAX));
  440. allocated_eax := true;
  441. emitlab(truelabel);
  442. emit_const_reg(A_MOV,S_B,1,R_AL);
  443. emitjmp(C_None,aktexit2label);
  444. emitlab(falselabel);
  445. emit_reg_reg(A_XOR,S_B,R_AL,R_AL);
  446. goto do_jmp;
  447. end;
  448. else
  449. internalerror(2001);
  450. end;
  451. case procinfo^.returntype.def^.deftype of
  452. pointerdef,
  453. procvardef : begin
  454. cleanleft;
  455. exprasmlist.concat(tairegalloc.alloc(R_EAX));
  456. allocated_eax := true;
  457. if is_mem then
  458. emit_ref_reg(A_MOV,S_L,
  459. newreference(left.location.reference),R_EAX)
  460. else
  461. emit_reg_reg(A_MOV,S_L,
  462. left.location.register,R_EAX);
  463. end;
  464. floatdef : begin
  465. cleanleft;
  466. if pfloatdef(procinfo^.returntype.def)^.typ=f32bit then
  467. begin
  468. exprasmlist.concat(tairegalloc.alloc(R_EAX));
  469. allocated_eax := true;
  470. if is_mem then
  471. emit_ref_reg(A_MOV,S_L,
  472. newreference(left.location.reference),R_EAX)
  473. else
  474. emit_reg_reg(A_MOV,S_L,left.location.register,R_EAX);
  475. end
  476. else
  477. if is_mem then
  478. floatload(pfloatdef(procinfo^.returntype.def)^.typ,left.location.reference);
  479. end;
  480. { orddef,
  481. enumdef : }
  482. else
  483. { it can be anything shorter than 4 bytes PM
  484. this caused form bug 711 }
  485. begin
  486. cleanleft;
  487. exprasmlist.concat(tairegalloc.alloc(R_EAX));
  488. allocated_eax := true;
  489. case procinfo^.returntype.def^.size of
  490. { it can be a qword/int64 too ... }
  491. 8 : if is_mem then
  492. begin
  493. emit_ref_reg(A_MOV,S_L,
  494. newreference(left.location.reference),R_EAX);
  495. r:=newreference(left.location.reference);
  496. inc(r^.offset,4);
  497. exprasmlist.concat(tairegalloc.alloc(R_EDX));
  498. allocated_edx := true;
  499. emit_ref_reg(A_MOV,S_L,r,R_EDX);
  500. end
  501. else
  502. begin
  503. emit_reg_reg(A_MOV,S_L,left.location.registerlow,R_EAX);
  504. exprasmlist.concat(tairegalloc.alloc(R_EDX));
  505. allocated_edx := true;
  506. emit_reg_reg(A_MOV,S_L,left.location.registerhigh,R_EDX);
  507. end;
  508. { if its 3 bytes only we can still
  509. copy one of garbage ! PM }
  510. 4,3 : if is_mem then
  511. emit_ref_reg(A_MOV,S_L,
  512. newreference(left.location.reference),R_EAX)
  513. else
  514. emit_reg_reg(A_MOV,S_L,left.location.register,R_EAX);
  515. 2 : if is_mem then
  516. emit_ref_reg(A_MOV,S_W,
  517. newreference(left.location.reference),R_AX)
  518. else
  519. emit_reg_reg(A_MOV,S_W,makereg16(left.location.register),R_AX);
  520. 1 : if is_mem then
  521. emit_ref_reg(A_MOV,S_B,
  522. newreference(left.location.reference),R_AL)
  523. else
  524. emit_reg_reg(A_MOV,S_B,makereg8(left.location.register),R_AL);
  525. else internalerror(605001);
  526. end;
  527. end;
  528. end;
  529. do_jmp:
  530. truelabel:=otlabel;
  531. falselabel:=oflabel;
  532. emitjmp(C_None,aktexit2label);
  533. if allocated_eax then
  534. exprasmlist.concat(tairegalloc.dealloc(R_EAX));
  535. if allocated_edx then
  536. exprasmlist.concat(tairegalloc.dealloc(R_EDX));
  537. end
  538. else
  539. emitjmp(C_None,aktexitlabel);
  540. end;
  541. {*****************************************************************************
  542. SecondBreakN
  543. *****************************************************************************}
  544. procedure ti386breaknode.pass_2;
  545. begin
  546. include(flowcontrol,fc_break);
  547. if aktbreaklabel<>nil then
  548. begin
  549. load_all_regvars(exprasmlist);
  550. emitjmp(C_None,aktbreaklabel)
  551. end
  552. else
  553. CGMessage(cg_e_break_not_allowed);
  554. end;
  555. {*****************************************************************************
  556. SecondContinueN
  557. *****************************************************************************}
  558. procedure ti386continuenode.pass_2;
  559. begin
  560. include(flowcontrol,fc_continue);
  561. if aktcontinuelabel<>nil then
  562. begin
  563. load_all_regvars(exprasmlist);
  564. emitjmp(C_None,aktcontinuelabel)
  565. end
  566. else
  567. CGMessage(cg_e_continue_not_allowed);
  568. end;
  569. {*****************************************************************************
  570. SecondGoto
  571. *****************************************************************************}
  572. procedure ti386gotonode.pass_2;
  573. begin
  574. load_all_regvars(exprasmlist);
  575. emitjmp(C_None,labelnr);
  576. { the assigned avoids only crashes if the label isn't defined }
  577. if assigned(labsym) and
  578. assigned(labsym^.code) and
  579. (aktexceptblock<>tlabelnode(labsym^.code).exceptionblock) then
  580. CGMessage(cg_e_goto_inout_of_exception_block);
  581. end;
  582. {*****************************************************************************
  583. SecondLabel
  584. *****************************************************************************}
  585. procedure ti386labelnode.pass_2;
  586. begin
  587. load_all_regvars(exprasmlist);
  588. emitlab(labelnr);
  589. cleartempgen;
  590. secondpass(left);
  591. end;
  592. {*****************************************************************************
  593. SecondRaise
  594. *****************************************************************************}
  595. procedure ti386raisenode.pass_2;
  596. var
  597. a : pasmlabel;
  598. begin
  599. if assigned(left) then
  600. begin
  601. { multiple parameters? }
  602. if assigned(right) then
  603. begin
  604. { push frame }
  605. if assigned(frametree) then
  606. begin
  607. secondpass(frametree);
  608. if codegenerror then
  609. exit;
  610. emit_push_loc(frametree.location);
  611. end
  612. else
  613. emit_const(A_PUSH,S_L,0);
  614. { push address }
  615. secondpass(right);
  616. if codegenerror then
  617. exit;
  618. emit_push_loc(right.location);
  619. end
  620. else
  621. begin
  622. getaddrlabel(a);
  623. emitlab(a);
  624. emit_reg(A_PUSH,S_L,R_EBP);
  625. emit_sym(A_PUSH,S_L,a);
  626. end;
  627. { push object }
  628. secondpass(left);
  629. if codegenerror then
  630. exit;
  631. emit_push_loc(left.location);
  632. emitcall('FPC_RAISEEXCEPTION');
  633. end
  634. else
  635. begin
  636. emitcall('FPC_POPADDRSTACK');
  637. emitcall('FPC_RERAISE');
  638. end;
  639. end;
  640. {*****************************************************************************
  641. SecondTryExcept
  642. *****************************************************************************}
  643. var
  644. endexceptlabel : pasmlabel;
  645. { does the necessary things to clean up the object stack }
  646. { in the except block }
  647. procedure cleanupobjectstack;
  648. begin
  649. emitcall('FPC_POPOBJECTSTACK');
  650. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  651. emit_reg(A_PUSH,S_L,R_EAX);
  652. emitcall('FPC_DESTROYEXCEPTION');
  653. exprasmList.concat(Tairegalloc.DeAlloc(R_EAX));
  654. maybe_loadesi;
  655. end;
  656. { pops one element from the exception address stack }
  657. { and removes the flag }
  658. procedure cleanupaddrstack;
  659. begin
  660. emitcall('FPC_POPADDRSTACK');
  661. { allocate eax }
  662. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  663. emit_reg(A_POP,S_L,R_EAX);
  664. { deallocate eax }
  665. exprasmList.concat(Tairegalloc.DeAlloc(R_EAX));
  666. end;
  667. procedure ti386tryexceptnode.pass_2;
  668. var
  669. exceptlabel,doexceptlabel,oldendexceptlabel,
  670. lastonlabel,
  671. exitexceptlabel,
  672. continueexceptlabel,
  673. breakexceptlabel,
  674. exittrylabel,
  675. continuetrylabel,
  676. breaktrylabel,
  677. doobjectdestroy,
  678. doobjectdestroyandreraise,
  679. oldaktexitlabel,
  680. oldaktexit2label,
  681. oldaktcontinuelabel,
  682. oldaktbreaklabel : pasmlabel;
  683. oldexceptblock : tnode;
  684. oldflowcontrol,tryflowcontrol,
  685. exceptflowcontrol : tflowcontrol;
  686. tempbuf,tempaddr : treference;
  687. label
  688. errorexit;
  689. begin
  690. oldflowcontrol:=flowcontrol;
  691. flowcontrol:=[];
  692. { this can be called recursivly }
  693. oldendexceptlabel:=endexceptlabel;
  694. { we modify EAX }
  695. usedinproc:=usedinproc or ($80 shr byte(R_EAX));
  696. { save the old labels for control flow statements }
  697. oldaktexitlabel:=aktexitlabel;
  698. oldaktexit2label:=aktexit2label;
  699. if assigned(aktbreaklabel) then
  700. begin
  701. oldaktcontinuelabel:=aktcontinuelabel;
  702. oldaktbreaklabel:=aktbreaklabel;
  703. end;
  704. { get new labels for the control flow statements }
  705. getlabel(exittrylabel);
  706. getlabel(exitexceptlabel);
  707. if assigned(aktbreaklabel) then
  708. begin
  709. getlabel(breaktrylabel);
  710. getlabel(continuetrylabel);
  711. getlabel(breakexceptlabel);
  712. getlabel(continueexceptlabel);
  713. end;
  714. getlabel(exceptlabel);
  715. getlabel(doexceptlabel);
  716. getlabel(endexceptlabel);
  717. getlabel(lastonlabel);
  718. gettempofsizereferencepersistant(24,tempbuf);
  719. gettempofsizereferencepersistant(12,tempaddr);
  720. emitpushreferenceaddr(tempaddr);
  721. emitpushreferenceaddr(tempbuf);
  722. push_int (1); { push type of exceptionframe }
  723. emitcall('FPC_PUSHEXCEPTADDR');
  724. { allocate eax }
  725. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  726. emit_reg(A_PUSH,S_L,R_EAX);
  727. emitcall('FPC_SETJMP');
  728. emit_reg(A_PUSH,S_L,R_EAX);
  729. emit_reg_reg(A_TEST,S_L,R_EAX,R_EAX);
  730. { deallocate eax }
  731. exprasmList.concat(Tairegalloc.DeAlloc(R_EAX));
  732. emitjmp(C_NE,exceptlabel);
  733. { try block }
  734. { set control flow labels for the try block }
  735. aktexitlabel:=exittrylabel;
  736. aktexit2label:=exittrylabel;
  737. if assigned(oldaktbreaklabel) then
  738. begin
  739. aktcontinuelabel:=continuetrylabel;
  740. aktbreaklabel:=breaktrylabel;
  741. end;
  742. oldexceptblock:=aktexceptblock;
  743. aktexceptblock:=left;
  744. flowcontrol:=[];
  745. secondpass(left);
  746. tryflowcontrol:=flowcontrol;
  747. aktexceptblock:=oldexceptblock;
  748. if codegenerror then
  749. goto errorexit;
  750. emitlab(exceptlabel);
  751. emitcall('FPC_POPADDRSTACK');
  752. ungetpersistanttempreference(tempaddr);
  753. ungetpersistanttempreference(tempbuf);
  754. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  755. emit_reg(A_POP,S_L,R_EAX);
  756. emit_reg_reg(A_TEST,S_L,R_EAX,R_EAX);
  757. exprasmList.concat(Tairegalloc.DeAlloc(R_EAX));
  758. emitjmp(C_E,endexceptlabel);
  759. emitlab(doexceptlabel);
  760. { set control flow labels for the except block }
  761. { and the on statements }
  762. aktexitlabel:=exitexceptlabel;
  763. aktexit2label:=exitexceptlabel;
  764. if assigned(oldaktbreaklabel) then
  765. begin
  766. aktcontinuelabel:=continueexceptlabel;
  767. aktbreaklabel:=breakexceptlabel;
  768. end;
  769. flowcontrol:=[];
  770. { on statements }
  771. if assigned(right) then
  772. begin
  773. oldexceptblock:=aktexceptblock;
  774. aktexceptblock:=right;
  775. secondpass(right);
  776. aktexceptblock:=oldexceptblock;
  777. end;
  778. emitlab(lastonlabel);
  779. { default handling except handling }
  780. if assigned(t1) then
  781. begin
  782. { FPC_CATCHES must be called with
  783. 'default handler' flag (=-1)
  784. }
  785. push_int (-1);
  786. emitcall('FPC_CATCHES');
  787. maybe_loadesi;
  788. { the destruction of the exception object must be also }
  789. { guarded by an exception frame }
  790. getlabel(doobjectdestroy);
  791. getlabel(doobjectdestroyandreraise);
  792. gettempofsizereferencepersistant(12,tempaddr);
  793. gettempofsizereferencepersistant(24,tempbuf);
  794. emitpushreferenceaddr(tempaddr);
  795. emitpushreferenceaddr(tempbuf);
  796. exprasmList.concat(Taicpu.Op_const(A_PUSH,S_L,1));
  797. emitcall('FPC_PUSHEXCEPTADDR');
  798. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  799. exprasmList.concat(Taicpu.op_reg(A_PUSH,S_L,R_EAX));
  800. exprasmList.concat(Tairegalloc.DeAlloc(R_EAX));
  801. emitcall('FPC_SETJMP');
  802. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  803. exprasmList.concat(Taicpu.op_reg(A_PUSH,S_L,R_EAX));
  804. exprasmList.concat(Taicpu.op_reg_reg(A_TEST,S_L,R_EAX,R_EAX));
  805. exprasmList.concat(Tairegalloc.DeAlloc(R_EAX));
  806. emitjmp(C_NE,doobjectdestroyandreraise);
  807. oldexceptblock:=aktexceptblock;
  808. aktexceptblock:=t1;
  809. { here we don't have to reset flowcontrol }
  810. { the default and on flowcontrols are handled equal }
  811. secondpass(t1);
  812. exceptflowcontrol:=flowcontrol;
  813. aktexceptblock:=oldexceptblock;
  814. emitlab(doobjectdestroyandreraise);
  815. emitcall('FPC_POPADDRSTACK');
  816. ungetpersistanttempreference(tempaddr);
  817. ungetpersistanttempreference(tempbuf);
  818. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  819. exprasmList.concat(Taicpu.op_reg(A_POP,S_L,R_EAX));
  820. exprasmList.concat(Taicpu.op_reg_reg(A_TEST,S_L,R_EAX,R_EAX));
  821. exprasmList.concat(Tairegalloc.DeAlloc(R_EAX));
  822. emitjmp(C_E,doobjectdestroy);
  823. emitcall('FPC_POPSECONDOBJECTSTACK');
  824. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  825. emit_reg(A_PUSH,S_L,R_EAX);
  826. emitcall('FPC_DESTROYEXCEPTION');
  827. exprasmList.concat(Tairegalloc.DeAlloc(R_EAX));
  828. { we don't need to restore esi here because reraise never }
  829. { returns }
  830. emitcall('FPC_RERAISE');
  831. emitlab(doobjectdestroy);
  832. cleanupobjectstack;
  833. emitjmp(C_None,endexceptlabel);
  834. end
  835. else
  836. begin
  837. emitcall('FPC_RERAISE');
  838. exceptflowcontrol:=flowcontrol;
  839. end;
  840. if fc_exit in exceptflowcontrol then
  841. begin
  842. { do some magic for exit in the try block }
  843. emitlab(exitexceptlabel);
  844. { we must also destroy the address frame which guards }
  845. { exception object }
  846. cleanupaddrstack;
  847. cleanupobjectstack;
  848. emitjmp(C_None,oldaktexitlabel);
  849. end;
  850. if fc_break in exceptflowcontrol then
  851. begin
  852. emitlab(breakexceptlabel);
  853. { we must also destroy the address frame which guards }
  854. { exception object }
  855. cleanupaddrstack;
  856. cleanupobjectstack;
  857. emitjmp(C_None,oldaktbreaklabel);
  858. end;
  859. if fc_continue in exceptflowcontrol then
  860. begin
  861. emitlab(continueexceptlabel);
  862. { we must also destroy the address frame which guards }
  863. { exception object }
  864. cleanupaddrstack;
  865. cleanupobjectstack;
  866. emitjmp(C_None,oldaktcontinuelabel);
  867. end;
  868. if fc_exit in tryflowcontrol then
  869. begin
  870. { do some magic for exit in the try block }
  871. emitlab(exittrylabel);
  872. cleanupaddrstack;
  873. emitjmp(C_None,oldaktexitlabel);
  874. end;
  875. if fc_break in tryflowcontrol then
  876. begin
  877. emitlab(breaktrylabel);
  878. cleanupaddrstack;
  879. emitjmp(C_None,oldaktbreaklabel);
  880. end;
  881. if fc_continue in tryflowcontrol then
  882. begin
  883. emitlab(continuetrylabel);
  884. cleanupaddrstack;
  885. emitjmp(C_None,oldaktcontinuelabel);
  886. end;
  887. emitlab(endexceptlabel);
  888. errorexit:
  889. { restore all saved labels }
  890. endexceptlabel:=oldendexceptlabel;
  891. { restore the control flow labels }
  892. aktexitlabel:=oldaktexitlabel;
  893. aktexit2label:=oldaktexit2label;
  894. if assigned(oldaktbreaklabel) then
  895. begin
  896. aktcontinuelabel:=oldaktcontinuelabel;
  897. aktbreaklabel:=oldaktbreaklabel;
  898. end;
  899. { return all used control flow statements }
  900. flowcontrol:=oldflowcontrol+exceptflowcontrol+
  901. tryflowcontrol;
  902. end;
  903. procedure ti386onnode.pass_2;
  904. var
  905. nextonlabel,
  906. exitonlabel,
  907. continueonlabel,
  908. breakonlabel,
  909. oldaktexitlabel,
  910. oldaktexit2label,
  911. oldaktcontinuelabel,
  912. doobjectdestroyandreraise,
  913. doobjectdestroy,
  914. oldaktbreaklabel : pasmlabel;
  915. ref : treference;
  916. oldexceptblock : tnode;
  917. oldflowcontrol : tflowcontrol;
  918. tempbuf,tempaddr : treference;
  919. begin
  920. oldflowcontrol:=flowcontrol;
  921. flowcontrol:=[];
  922. getlabel(nextonlabel);
  923. { push the vmt }
  924. emit_sym(A_PUSH,S_L,
  925. newasmsymbol(excepttype^.vmt_mangledname));
  926. emitcall('FPC_CATCHES');
  927. { allocate eax }
  928. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  929. emit_reg_reg(A_TEST,S_L,R_EAX,R_EAX);
  930. emitjmp(C_E,nextonlabel);
  931. ref.symbol:=nil;
  932. gettempofsizereference(4,ref);
  933. { what a hack ! }
  934. if assigned(exceptsymtable) then
  935. pvarsym(exceptsymtable^.symindex^.first)^.address:=ref.offset;
  936. emit_reg_ref(A_MOV,S_L,
  937. R_EAX,newreference(ref));
  938. { deallocate eax }
  939. exprasmList.concat(Tairegalloc.DeAlloc(R_EAX));
  940. { in the case that another exception is risen }
  941. { we've to destroy the old one }
  942. getlabel(doobjectdestroyandreraise);
  943. gettempofsizereferencepersistant(12,tempaddr);
  944. gettempofsizereferencepersistant(24,tempbuf);
  945. emitpushreferenceaddr(tempaddr);
  946. emitpushreferenceaddr(tempbuf);
  947. exprasmList.concat(Taicpu.Op_const(A_PUSH,S_L,1));
  948. emitcall('FPC_PUSHEXCEPTADDR');
  949. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  950. exprasmList.concat(Taicpu.op_reg(A_PUSH,S_L,R_EAX));
  951. exprasmList.concat(Tairegalloc.DeAlloc(R_EAX));
  952. emitcall('FPC_SETJMP');
  953. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  954. exprasmList.concat(Taicpu.op_reg(A_PUSH,S_L,R_EAX));
  955. exprasmList.concat(Taicpu.op_reg_reg(A_TEST,S_L,R_EAX,R_EAX));
  956. exprasmList.concat(Tairegalloc.DeAlloc(R_EAX));
  957. emitjmp(C_NE,doobjectdestroyandreraise);
  958. if assigned(right) then
  959. begin
  960. oldaktexitlabel:=aktexitlabel;
  961. oldaktexit2label:=aktexit2label;
  962. getlabel(exitonlabel);
  963. aktexitlabel:=exitonlabel;
  964. aktexit2label:=exitonlabel;
  965. if assigned(aktbreaklabel) then
  966. begin
  967. oldaktcontinuelabel:=aktcontinuelabel;
  968. oldaktbreaklabel:=aktbreaklabel;
  969. getlabel(breakonlabel);
  970. getlabel(continueonlabel);
  971. aktcontinuelabel:=continueonlabel;
  972. aktbreaklabel:=breakonlabel;
  973. end;
  974. { esi is destroyed by FPC_CATCHES }
  975. maybe_loadesi;
  976. oldexceptblock:=aktexceptblock;
  977. aktexceptblock:=right;
  978. secondpass(right);
  979. aktexceptblock:=oldexceptblock;
  980. end;
  981. getlabel(doobjectdestroy);
  982. emitlab(doobjectdestroyandreraise);
  983. emitcall('FPC_POPADDRSTACK');
  984. ungetpersistanttempreference(tempaddr);
  985. ungetpersistanttempreference(tempbuf);
  986. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  987. exprasmList.concat(Taicpu.op_reg(A_POP,S_L,R_EAX));
  988. exprasmList.concat(Taicpu.op_reg_reg(A_TEST,S_L,R_EAX,R_EAX));
  989. exprasmList.concat(Tairegalloc.DeAlloc(R_EAX));
  990. emitjmp(C_E,doobjectdestroy);
  991. emitcall('FPC_POPSECONDOBJECTSTACK');
  992. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  993. emit_reg(A_PUSH,S_L,R_EAX);
  994. emitcall('FPC_DESTROYEXCEPTION');
  995. exprasmList.concat(Tairegalloc.DeAlloc(R_EAX));
  996. { we don't need to restore esi here because reraise never }
  997. { returns }
  998. emitcall('FPC_RERAISE');
  999. emitlab(doobjectdestroy);
  1000. cleanupobjectstack;
  1001. { clear some stuff }
  1002. ungetiftemp(ref);
  1003. emitjmp(C_None,endexceptlabel);
  1004. if assigned(right) then
  1005. begin
  1006. { special handling for control flow instructions }
  1007. if fc_exit in flowcontrol then
  1008. begin
  1009. { the address and object pop does secondtryexcept }
  1010. emitlab(exitonlabel);
  1011. emitjmp(C_None,oldaktexitlabel);
  1012. end;
  1013. if fc_break in flowcontrol then
  1014. begin
  1015. { the address and object pop does secondtryexcept }
  1016. emitlab(breakonlabel);
  1017. emitjmp(C_None,oldaktbreaklabel);
  1018. end;
  1019. if fc_continue in flowcontrol then
  1020. begin
  1021. { the address and object pop does secondtryexcept }
  1022. emitlab(continueonlabel);
  1023. emitjmp(C_None,oldaktcontinuelabel);
  1024. end;
  1025. aktexitlabel:=oldaktexitlabel;
  1026. aktexit2label:=oldaktexit2label;
  1027. if assigned(oldaktbreaklabel) then
  1028. begin
  1029. aktcontinuelabel:=oldaktcontinuelabel;
  1030. aktbreaklabel:=oldaktbreaklabel;
  1031. end;
  1032. end;
  1033. emitlab(nextonlabel);
  1034. flowcontrol:=oldflowcontrol+flowcontrol;
  1035. { next on node }
  1036. if assigned(left) then
  1037. begin
  1038. cleartempgen;
  1039. secondpass(left);
  1040. end;
  1041. end;
  1042. {*****************************************************************************
  1043. SecondTryFinally
  1044. *****************************************************************************}
  1045. procedure ti386tryfinallynode.pass_2;
  1046. var
  1047. reraiselabel,
  1048. finallylabel,
  1049. endfinallylabel,
  1050. exitfinallylabel,
  1051. continuefinallylabel,
  1052. breakfinallylabel,
  1053. oldaktexitlabel,
  1054. oldaktexit2label,
  1055. oldaktcontinuelabel,
  1056. oldaktbreaklabel : pasmlabel;
  1057. oldexceptblock : tnode;
  1058. oldflowcontrol,tryflowcontrol : tflowcontrol;
  1059. decconst : longint;
  1060. tempbuf,tempaddr : treference;
  1061. begin
  1062. { check if child nodes do a break/continue/exit }
  1063. oldflowcontrol:=flowcontrol;
  1064. flowcontrol:=[];
  1065. { we modify EAX }
  1066. usedinproc:=usedinproc or ($80 shr byte(R_EAX));
  1067. getlabel(finallylabel);
  1068. getlabel(endfinallylabel);
  1069. getlabel(reraiselabel);
  1070. { the finally block must catch break, continue and exit }
  1071. { statements }
  1072. oldaktexitlabel:=aktexitlabel;
  1073. oldaktexit2label:=aktexit2label;
  1074. getlabel(exitfinallylabel);
  1075. aktexitlabel:=exitfinallylabel;
  1076. aktexit2label:=exitfinallylabel;
  1077. if assigned(aktbreaklabel) then
  1078. begin
  1079. oldaktcontinuelabel:=aktcontinuelabel;
  1080. oldaktbreaklabel:=aktbreaklabel;
  1081. getlabel(breakfinallylabel);
  1082. getlabel(continuefinallylabel);
  1083. aktcontinuelabel:=continuefinallylabel;
  1084. aktbreaklabel:=breakfinallylabel;
  1085. end;
  1086. gettempofsizereferencepersistant(12,tempaddr);
  1087. gettempofsizereferencepersistant(24,tempbuf);
  1088. emitpushreferenceaddr(tempaddr);
  1089. emitpushreferenceaddr(tempbuf);
  1090. push_int(1); { Type of stack-frame must be pushed}
  1091. emitcall('FPC_PUSHEXCEPTADDR');
  1092. { allocate eax }
  1093. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  1094. emit_reg(A_PUSH,S_L,R_EAX);
  1095. emitcall('FPC_SETJMP');
  1096. emit_reg(A_PUSH,S_L,R_EAX);
  1097. emit_reg_reg(A_TEST,S_L,R_EAX,R_EAX);
  1098. { deallocate eax }
  1099. exprasmList.concat(Tairegalloc.DeAlloc(R_EAX));
  1100. emitjmp(C_NE,finallylabel);
  1101. { try code }
  1102. if assigned(left) then
  1103. begin
  1104. oldexceptblock:=aktexceptblock;
  1105. aktexceptblock:=left;
  1106. secondpass(left);
  1107. tryflowcontrol:=flowcontrol;
  1108. if codegenerror then
  1109. exit;
  1110. aktexceptblock:=oldexceptblock;
  1111. end;
  1112. emitlab(finallylabel);
  1113. emitcall('FPC_POPADDRSTACK');
  1114. ungetpersistanttempreference(tempaddr);
  1115. ungetpersistanttempreference(tempbuf);
  1116. { finally code }
  1117. oldexceptblock:=aktexceptblock;
  1118. aktexceptblock:=right;
  1119. flowcontrol:=[];
  1120. secondpass(right);
  1121. if flowcontrol<>[] then
  1122. CGMessage(cg_e_control_flow_outside_finally);
  1123. aktexceptblock:=oldexceptblock;
  1124. if codegenerror then
  1125. exit;
  1126. { allocate eax }
  1127. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  1128. emit_reg(A_POP,S_L,R_EAX);
  1129. emit_reg_reg(A_TEST,S_L,R_EAX,R_EAX);
  1130. emitjmp(C_E,endfinallylabel);
  1131. emit_reg(A_DEC,S_L,R_EAX);
  1132. emitjmp(C_Z,reraiselabel);
  1133. if fc_exit in tryflowcontrol then
  1134. begin
  1135. emit_reg(A_DEC,S_L,R_EAX);
  1136. emitjmp(C_Z,oldaktexitlabel);
  1137. decconst:=1;
  1138. end
  1139. else
  1140. decconst:=2;
  1141. if fc_break in tryflowcontrol then
  1142. begin
  1143. emit_const_reg(A_SUB,S_L,decconst,R_EAX);
  1144. emitjmp(C_Z,oldaktbreaklabel);
  1145. decconst:=1;
  1146. end
  1147. else
  1148. inc(decconst);
  1149. if fc_continue in tryflowcontrol then
  1150. begin
  1151. emit_const_reg(A_SUB,S_L,decconst,R_EAX);
  1152. emitjmp(C_Z,oldaktcontinuelabel);
  1153. end;
  1154. { deallocate eax }
  1155. exprasmList.concat(Tairegalloc.DeAlloc(R_EAX));
  1156. emitlab(reraiselabel);
  1157. emitcall('FPC_RERAISE');
  1158. { do some magic for exit,break,continue in the try block }
  1159. if fc_exit in tryflowcontrol then
  1160. begin
  1161. emitlab(exitfinallylabel);
  1162. { allocate eax }
  1163. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  1164. emit_reg(A_POP,S_L,R_EAX);
  1165. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  1166. emit_const(A_PUSH,S_L,2);
  1167. emitjmp(C_NONE,finallylabel);
  1168. end;
  1169. if fc_break in tryflowcontrol then
  1170. begin
  1171. emitlab(breakfinallylabel);
  1172. { allocate eax }
  1173. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  1174. emit_reg(A_POP,S_L,R_EAX);
  1175. { deallocate eax }
  1176. exprasmList.concat(Tairegalloc.DeAlloc(R_EAX));
  1177. emit_const(A_PUSH,S_L,3);
  1178. emitjmp(C_NONE,finallylabel);
  1179. end;
  1180. if fc_continue in tryflowcontrol then
  1181. begin
  1182. emitlab(continuefinallylabel);
  1183. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  1184. emit_reg(A_POP,S_L,R_EAX);
  1185. exprasmList.concat(Tairegalloc.Alloc(R_EAX));
  1186. emit_const(A_PUSH,S_L,4);
  1187. emitjmp(C_NONE,finallylabel);
  1188. end;
  1189. emitlab(endfinallylabel);
  1190. aktexitlabel:=oldaktexitlabel;
  1191. aktexit2label:=oldaktexit2label;
  1192. if assigned(aktbreaklabel) then
  1193. begin
  1194. aktcontinuelabel:=oldaktcontinuelabel;
  1195. aktbreaklabel:=oldaktbreaklabel;
  1196. end;
  1197. flowcontrol:=oldflowcontrol+tryflowcontrol;
  1198. end;
  1199. {*****************************************************************************
  1200. SecondFail
  1201. *****************************************************************************}
  1202. procedure ti386failnode.pass_2;
  1203. begin
  1204. emitjmp(C_None,faillabel);
  1205. end;
  1206. begin
  1207. cwhilerepeatnode:=ti386whilerepeatnode;
  1208. cifnode:=ti386ifnode;
  1209. cfornode:=ti386fornode;
  1210. cexitnode:=ti386exitnode;
  1211. cbreaknode:=ti386breaknode;
  1212. ccontinuenode:=ti386continuenode;
  1213. cgotonode:=ti386gotonode;
  1214. clabelnode:=ti386labelnode;
  1215. craisenode:=ti386raisenode;
  1216. ctryexceptnode:=ti386tryexceptnode;
  1217. ctryfinallynode:=ti386tryfinallynode;
  1218. connode:=ti386onnode;
  1219. cfailnode:=ti386failnode;
  1220. end.
  1221. {
  1222. $Log$
  1223. Revision 1.7 2001-01-06 23:35:05 jonas
  1224. * fixed webbug 1323
  1225. Revision 1.6 2001/01/05 17:36:58 florian
  1226. * the info about exception frames is stored now on the stack
  1227. instead on the heap
  1228. Revision 1.5 2000/12/25 00:07:32 peter
  1229. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1230. tlinkedlist objects)
  1231. Revision 1.4 2000/12/05 11:44:33 jonas
  1232. + new integer regvar handling, should be much more efficient
  1233. Revision 1.3 2000/11/29 00:30:47 florian
  1234. * unused units removed from uses clause
  1235. * some changes for widestrings
  1236. Revision 1.2 2000/10/31 22:02:56 peter
  1237. * symtable splitted, no real code changes
  1238. Revision 1.1 2000/10/15 09:33:31 peter
  1239. * moved n386*.pas to i386/ cpu_target dir
  1240. Revision 1.1 2000/10/14 10:14:48 peter
  1241. * moehrendorf oct 2000 rewrite
  1242. }