cg68kflw.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  1. {
  2. $Id$
  3. Copyright (c) 1998-2000 by Florian Klaempfl
  4. Generate m68k 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. {$ifdef FPC}
  19. {$goto on}
  20. {$endif FPC}
  21. unit cg68kflw;
  22. interface
  23. uses
  24. tree;
  25. procedure second_while_repeatn(var p : ptree);
  26. procedure secondifn(var p : ptree);
  27. procedure secondfor(var p : ptree);
  28. procedure secondexitn(var p : ptree);
  29. procedure secondbreakn(var p : ptree);
  30. procedure secondcontinuen(var p : ptree);
  31. procedure secondgoto(var p : ptree);
  32. procedure secondlabel(var p : ptree);
  33. procedure secondraise(var p : ptree);
  34. procedure secondtryexcept(var p : ptree);
  35. procedure secondtryfinally(var p : ptree);
  36. procedure secondon(var p : ptree);
  37. procedure secondfail(var p : ptree);
  38. implementation
  39. uses
  40. globtype,systems,symconst,
  41. cobjects,verbose,globals,
  42. symtable,aasm,types,
  43. hcodegen,temp_gen,pass_2,
  44. cpubase,cga68k,tgen68k;
  45. {*****************************************************************************
  46. Second_While_RepeatN
  47. *****************************************************************************}
  48. procedure second_while_repeatn(var p : ptree);
  49. var
  50. l1,l2,l3,oldclabel,oldblabel : pasmlabel;
  51. otlabel,oflabel : pasmlabel;
  52. begin
  53. getlabel(l1);
  54. getlabel(l2);
  55. { arrange continue and breaklabels: }
  56. oldclabel:=aktcontinuelabel;
  57. oldblabel:=aktbreaklabel;
  58. if p^.treetype=repeatn then
  59. begin
  60. emitl(A_LABEL,l1);
  61. aktcontinuelabel:=l1;
  62. aktbreaklabel:=l2;
  63. cleartempgen;
  64. if assigned(p^.right) then
  65. secondpass(p^.right);
  66. otlabel:=truelabel;
  67. oflabel:=falselabel;
  68. truelabel:=l2;
  69. falselabel:=l1;
  70. cleartempgen;
  71. secondpass(p^.left);
  72. maketojumpbool(p^.left);
  73. emitl(A_LABEL,l2);
  74. truelabel:=otlabel;
  75. falselabel:=oflabel;
  76. end
  77. else { //// NOT a small set //// }
  78. begin
  79. { handling code at the end as it is much more efficient }
  80. emitl(A_JMP,l2);
  81. emitl(A_LABEL,l1);
  82. cleartempgen;
  83. getlabel(l3);
  84. aktcontinuelabel:=l2;
  85. aktbreaklabel:=l3;
  86. if assigned(p^.right) then
  87. secondpass(p^.right);
  88. emitl(A_LABEL,l2);
  89. otlabel:=truelabel;
  90. oflabel:=falselabel;
  91. truelabel:=l1;
  92. falselabel:=l3;
  93. cleartempgen;
  94. secondpass(p^.left);
  95. maketojumpbool(p^.left);
  96. emitl(A_LABEL,l3);
  97. truelabel:=otlabel;
  98. falselabel:=oflabel;
  99. end;
  100. aktcontinuelabel:=oldclabel;
  101. aktbreaklabel:=oldblabel;
  102. end;
  103. {*****************************************************************************
  104. SecondIfN
  105. *****************************************************************************}
  106. procedure secondifn(var p : ptree);
  107. var
  108. hl,otlabel,oflabel : pasmlabel;
  109. begin
  110. otlabel:=truelabel;
  111. oflabel:=falselabel;
  112. getlabel(truelabel);
  113. getlabel(falselabel);
  114. cleartempgen;
  115. secondpass(p^.left);
  116. maketojumpbool(p^.left);
  117. if assigned(p^.right) then
  118. begin
  119. emitl(A_LABEL,truelabel);
  120. cleartempgen;
  121. secondpass(p^.right);
  122. end;
  123. if assigned(p^.t1) then
  124. begin
  125. if assigned(p^.right) then
  126. begin
  127. getlabel(hl);
  128. emitl(A_JMP,hl);
  129. end;
  130. emitl(A_LABEL,falselabel);
  131. cleartempgen;
  132. secondpass(p^.t1);
  133. if assigned(p^.right) then
  134. emitl(A_LABEL,hl);
  135. end
  136. else
  137. emitl(A_LABEL,falselabel);
  138. if not(assigned(p^.right)) then
  139. emitl(A_LABEL,truelabel);
  140. truelabel:=otlabel;
  141. falselabel:=oflabel;
  142. end;
  143. {*****************************************************************************
  144. SecondFor
  145. *****************************************************************************}
  146. procedure secondfor(var p : ptree);
  147. var
  148. l1,l3,oldclabel,oldblabel : pasmlabel;
  149. omitfirstcomp,temptovalue : boolean;
  150. hs : byte;
  151. temp1 : treference;
  152. hop : tasmop;
  153. cmpreg,cmp32 : tregister;
  154. opsize : topsize;
  155. count_var_is_signed : boolean;
  156. begin
  157. oldclabel:=aktcontinuelabel;
  158. oldblabel:=aktbreaklabel;
  159. getlabel(aktcontinuelabel);
  160. getlabel(aktbreaklabel);
  161. getlabel(l3);
  162. { could we spare the first comparison ? }
  163. omitfirstcomp:=false;
  164. if p^.right^.treetype=ordconstn then
  165. if p^.left^.right^.treetype=ordconstn then
  166. omitfirstcomp:=(p^.backward and (p^.left^.right^.value>=p^.right^.value))
  167. or (not(p^.backward) and (p^.left^.right^.value<=p^.right^.value));
  168. { only calculate reference }
  169. cleartempgen;
  170. secondpass(p^.t2);
  171. if not(simple_loadn) then
  172. CGMessage(cg_e_illegal_count_var);
  173. { produce start assignment }
  174. cleartempgen;
  175. secondpass(p^.left);
  176. count_var_is_signed:=is_signed(porddef(p^.t2^.resulttype));
  177. hs:=p^.t2^.resulttype^.size;
  178. cmp32:=getregister32;
  179. cmpreg:=cmp32;
  180. case hs of
  181. 1 : begin
  182. opsize:=S_B;
  183. end;
  184. 2 : begin
  185. opsize:=S_W;
  186. end;
  187. 4 : begin
  188. opsize:=S_L;
  189. end;
  190. end;
  191. cleartempgen;
  192. secondpass(p^.right);
  193. { calculate pointer value and check if changeable and if so }
  194. { load into temporary variable }
  195. if p^.right^.treetype<>ordconstn then
  196. begin
  197. temp1.symbol:=nil;
  198. gettempofsizereference(hs,temp1);
  199. temptovalue:=true;
  200. if (p^.right^.location.loc=LOC_REGISTER) or
  201. (p^.right^.location.loc=LOC_CREGISTER) then
  202. begin
  203. exprasmlist^.concat(new(paicpu,op_reg_ref(A_MOVE,opsize,p^.right^.location.register,
  204. newreference(temp1))));
  205. end
  206. else
  207. concatcopy(p^.right^.location.reference,temp1,hs,false);
  208. end
  209. else temptovalue:=false;
  210. if temptovalue then
  211. begin
  212. if p^.t2^.location.loc=LOC_CREGISTER then
  213. begin
  214. exprasmlist^.concat(new(paicpu,op_ref_reg(A_CMP,opsize,newreference(temp1),
  215. p^.t2^.location.register)));
  216. end
  217. else
  218. begin
  219. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,opsize,newreference(p^.t2^.location.reference),
  220. cmpreg)));
  221. exprasmlist^.concat(new(paicpu,op_ref_reg(A_CMP,opsize,newreference(temp1),
  222. cmpreg)));
  223. end;
  224. end
  225. else
  226. begin
  227. if not(omitfirstcomp) then
  228. begin
  229. if p^.t2^.location.loc=LOC_CREGISTER then
  230. exprasmlist^.concat(new(paicpu,op_const_reg(A_CMP,opsize,p^.right^.value,
  231. p^.t2^.location.register)))
  232. else
  233. exprasmlist^.concat(new(paicpu,op_const_ref(A_CMP,opsize,p^.right^.value,
  234. newreference(p^.t2^.location.reference))));
  235. end;
  236. end;
  237. if p^.backward then
  238. begin
  239. if count_var_is_signed then
  240. hop:=A_BLT
  241. else
  242. hop:=A_BCS;
  243. end
  244. else
  245. if count_var_is_signed then
  246. hop:=A_BGT
  247. else hop:=A_BHI;
  248. if not(omitfirstcomp) or temptovalue then
  249. emitl(hop,aktbreaklabel);
  250. emitl(A_LABEL,l3);
  251. { help register must not be in instruction block }
  252. cleartempgen;
  253. if assigned(p^.t1) then
  254. secondpass(p^.t1);
  255. emitl(A_LABEL,aktcontinuelabel);
  256. { makes no problems there }
  257. cleartempgen;
  258. { demand help register again }
  259. cmp32:=getregister32;
  260. case hs of
  261. 1 : begin
  262. opsize:=S_B;
  263. end;
  264. 2 : begin
  265. opsize:=S_W;
  266. end;
  267. 4 : opsize:=S_L;
  268. end;
  269. { produce comparison and the corresponding }
  270. { jump }
  271. if temptovalue then
  272. begin
  273. if p^.t2^.location.loc=LOC_CREGISTER then
  274. begin
  275. exprasmlist^.concat(new(paicpu,op_ref_reg(A_CMP,opsize,newreference(temp1),
  276. p^.t2^.location.register)));
  277. end
  278. else
  279. begin
  280. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,opsize,newreference(p^.t2^.location.reference),
  281. cmpreg)));
  282. exprasmlist^.concat(new(paicpu,op_ref_reg(A_CMP,opsize,newreference(temp1),
  283. cmpreg)));
  284. end;
  285. end
  286. else
  287. begin
  288. if p^.t2^.location.loc=LOC_CREGISTER then
  289. exprasmlist^.concat(new(paicpu,op_const_reg(A_CMP,opsize,p^.right^.value,
  290. p^.t2^.location.register)))
  291. else
  292. exprasmlist^.concat(new(paicpu,op_const_ref(A_CMP,opsize,p^.right^.value,
  293. newreference(p^.t2^.location.reference))));
  294. end;
  295. if p^.backward then
  296. if count_var_is_signed then
  297. hop:=A_BLE
  298. else
  299. hop :=A_BLS
  300. else
  301. if count_var_is_signed then
  302. hop:=A_BGE
  303. else
  304. hop:=A_BCC;
  305. emitl(hop,aktbreaklabel);
  306. { according to count direction DEC or INC... }
  307. { must be after the test because of 0to 255 for bytes !! }
  308. if p^.backward then
  309. hop:=A_SUB
  310. else hop:=A_ADD;
  311. if p^.t2^.location.loc=LOC_CREGISTER then
  312. exprasmlist^.concat(new(paicpu,op_const_reg(hop,opsize,1,p^.t2^.location.register)))
  313. else
  314. exprasmlist^.concat(new(paicpu,op_const_ref(hop,opsize,1,newreference(p^.t2^.location.reference))));
  315. emitl(A_JMP,l3);
  316. { this is the break label: }
  317. emitl(A_LABEL,aktbreaklabel);
  318. ungetregister32(cmp32);
  319. if temptovalue then
  320. ungetiftemp(temp1);
  321. aktcontinuelabel:=oldclabel;
  322. aktbreaklabel:=oldblabel;
  323. end;
  324. {*****************************************************************************
  325. SecondExitN
  326. *****************************************************************************}
  327. procedure secondexitn(var p : ptree);
  328. var
  329. is_mem : boolean;
  330. {op : tasmop;
  331. s : topsize;}
  332. otlabel,oflabel : pasmlabel;
  333. label
  334. do_jmp;
  335. begin
  336. if assigned(p^.left) then
  337. begin
  338. otlabel:=truelabel;
  339. oflabel:=falselabel;
  340. getlabel(truelabel);
  341. getlabel(falselabel);
  342. secondpass(p^.left);
  343. case p^.left^.location.loc of
  344. LOC_FPU : goto do_jmp;
  345. LOC_MEM,LOC_REFERENCE : is_mem:=true;
  346. LOC_CREGISTER,
  347. LOC_REGISTER : is_mem:=false;
  348. LOC_FLAGS : begin
  349. exprasmlist^.concat(new(paicpu,op_reg(flag_2_set[p^.right^.location.resflags],S_B,R_D0)));
  350. exprasmlist^.concat(new(paicpu,op_reg(A_NEG, S_B, R_D0)));
  351. goto do_jmp;
  352. end;
  353. LOC_JUMP : begin
  354. emitl(A_LABEL,truelabel);
  355. exprasmlist^.concat(new(paicpu,op_const_reg(A_MOVE,S_B,1,R_D0)));
  356. emitl(A_JMP,aktexit2label);
  357. exprasmlist^.concat(new(paicpu,op_reg(A_CLR,S_B,R_D0)));
  358. goto do_jmp;
  359. end;
  360. else internalerror(2001);
  361. end;
  362. case procinfo^.retdef^.deftype of
  363. orddef,
  364. enumdef : begin
  365. case procinfo^.retdef^.size of
  366. 4 : if is_mem then
  367. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_L,
  368. newreference(p^.left^.location.reference),R_D0)))
  369. else
  370. emit_reg_reg(A_MOVE,S_L,p^.left^.location.register,R_D0);
  371. 2 : if is_mem then
  372. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_W,
  373. newreference(p^.left^.location.reference),R_D0)))
  374. else
  375. emit_reg_reg(A_MOVE,S_W,p^.left^.location.register,R_D0);
  376. 1 : if is_mem then
  377. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_B,
  378. newreference(p^.left^.location.reference),R_D0)))
  379. else
  380. emit_reg_reg(A_MOVE,S_B,p^.left^.location.register,R_D0);
  381. end;
  382. end;
  383. pointerdef,
  384. procvardef : begin
  385. if is_mem then
  386. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_L,
  387. newreference(p^.left^.location.reference),R_D0)))
  388. else
  389. exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_L,p^.left^.location.register,R_D0)));
  390. end;
  391. floatdef : begin
  392. { floating point return values .... }
  393. { single are returned in d0 }
  394. if (pfloatdef(procinfo^.retdef)^.typ=f32bit) or
  395. (pfloatdef(procinfo^.retdef)^.typ=s32real) then
  396. begin
  397. if is_mem then
  398. exprasmlist^.concat(new(paicpu,op_ref_reg(A_MOVE,S_L,
  399. newreference(p^.left^.location.reference),R_D0)))
  400. else
  401. begin
  402. if pfloatdef(procinfo^.retdef)^.typ=f32bit then
  403. emit_reg_reg(A_MOVE,S_L,p^.left^.location.register,R_D0)
  404. else
  405. begin
  406. { single values are in the floating point registers }
  407. if cs_fp_emulation in aktmoduleswitches then
  408. emit_reg_reg(A_MOVE,S_L,p^.left^.location.fpureg,R_D0)
  409. else
  410. exprasmlist^.concat(new(paicpu,op_reg_reg(A_FMOVE,S_FS,
  411. p^.left^.location.fpureg,R_D0)));
  412. end;
  413. end;
  414. end
  415. else
  416. Begin
  417. { this is only possible in real non emulation mode }
  418. { LOC_MEM,LOC_REFERENCE }
  419. if is_mem then
  420. begin
  421. exprasmlist^.concat(new(paicpu,op_ref_reg(A_FMOVE,
  422. getfloatsize(pfloatdef(procinfo^.retdef)^.typ),
  423. newreference(p^.left^.location.reference),R_FP0)));
  424. end
  425. else
  426. { LOC_FPU }
  427. begin
  428. { convert from extended to correct type }
  429. { when storing }
  430. exprasmlist^.concat(new(paicpu,op_reg_reg(A_FMOVE,
  431. getfloatsize(pfloatdef(procinfo^.retdef)^.typ),p^.left^.location.fpureg,R_FP0)));
  432. end;
  433. end;
  434. end;
  435. end;
  436. do_jmp:
  437. truelabel:=otlabel;
  438. falselabel:=oflabel;
  439. emitl(A_JMP,aktexit2label);
  440. end
  441. else
  442. begin
  443. emitl(A_JMP,aktexitlabel);
  444. end;
  445. end;
  446. {*****************************************************************************
  447. SecondBreakN
  448. *****************************************************************************}
  449. procedure secondbreakn(var p : ptree);
  450. begin
  451. if aktbreaklabel<>nil then
  452. emitl(A_JMP,aktbreaklabel)
  453. else
  454. CGMessage(cg_e_break_not_allowed);
  455. end;
  456. {*****************************************************************************
  457. SecondContinueN
  458. *****************************************************************************}
  459. procedure secondcontinuen(var p : ptree);
  460. begin
  461. if aktcontinuelabel<>nil then
  462. emitl(A_JMP,aktcontinuelabel)
  463. else
  464. CGMessage(cg_e_continue_not_allowed);
  465. end;
  466. {*****************************************************************************
  467. SecondGoto
  468. *****************************************************************************}
  469. procedure secondgoto(var p : ptree);
  470. begin
  471. emitl(A_JMP,p^.labelnr);
  472. end;
  473. {*****************************************************************************
  474. SecondLabel
  475. *****************************************************************************}
  476. procedure secondlabel(var p : ptree);
  477. begin
  478. emitl(A_LABEL,p^.labelnr);
  479. cleartempgen;
  480. secondpass(p^.left);
  481. end;
  482. {*****************************************************************************
  483. SecondRaise
  484. *****************************************************************************}
  485. { generates the code for a raise statement }
  486. procedure secondraise(var p : ptree);
  487. var
  488. a : pasmlabel;
  489. begin
  490. if assigned(p^.left) then
  491. begin
  492. { generate the address }
  493. if assigned(p^.right) then
  494. begin
  495. secondpass(p^.right);
  496. if codegenerror then
  497. exit;
  498. end
  499. else
  500. begin
  501. getlabel(a);
  502. emitl(A_LABEL,a);
  503. exprasmlist^.concat(new(paicpu,
  504. op_csymbol_reg(A_MOVE,S_L,newcsymbol(a^.name,0),R_SPPUSH)));
  505. end;
  506. secondpass(p^.left);
  507. if codegenerror then
  508. exit;
  509. case p^.left^.location.loc of
  510. LOC_MEM,LOC_REFERENCE : emitpushreferenceaddr(exprasmlist,p^.left^.location.reference);
  511. LOC_CREGISTER,LOC_REGISTER : exprasmlist^.concat(new(paicpu,op_reg_reg(A_MOVE,S_L,
  512. p^.left^.location.register,R_SPPUSH)));
  513. else CGMessage(type_e_mismatch);
  514. end;
  515. emitcall('FPC_RAISEEXCEPTION',true);
  516. end
  517. else
  518. emitcall('FPC_RERAISE',true);
  519. end;
  520. {*****************************************************************************
  521. SecondTryExcept
  522. *****************************************************************************}
  523. var
  524. endexceptlabel : pasmlabel;
  525. procedure secondtryexcept(var p : ptree);
  526. var
  527. exceptlabel,doexceptlabel,oldendexceptlabel,
  528. lastonlabel : pasmlabel;
  529. begin
  530. InternalError(3431243);
  531. (*
  532. { this can be called recursivly }
  533. oldendexceptlabel:=endexceptlabel;
  534. { we modify EAX }
  535. usedinproc:=usedinproc or ($80 shr byte(R_EAX));
  536. getlabel(exceptlabel);
  537. getlabel(doexceptlabel);
  538. getlabel(endexceptlabel);
  539. getlabel(lastonlabel);
  540. push_int (1); { push type of exceptionframe }
  541. emitcall('FPC_PUSHEXCEPTADDR',true);
  542. exprasmlist^.concat(new(paicpu,
  543. op_reg(A_PUSH,S_L,R_EAX)));
  544. emitcall('FPC_SETJMP',true);
  545. exprasmlist^.concat(new(paicpu,
  546. op_reg(A_PUSH,S_L,R_EAX)));
  547. exprasmlist^.concat(new(paicpu,
  548. op_reg_reg(A_TEST,S_L,R_EAX,R_EAX)));
  549. emitl(A_JNE,exceptlabel);
  550. { try code }
  551. secondpass(p^.left);
  552. if codegenerror then
  553. exit;
  554. emitl(A_LABEL,exceptlabel);
  555. exprasmlist^.concat(new(paicpu,
  556. op_reg(A_POP,S_L,R_EAX)));
  557. exprasmlist^.concat(new(paicpu,
  558. op_reg_reg(A_TEST,S_L,R_EAX,R_EAX)));
  559. emitl(A_JNE,doexceptlabel);
  560. emitcall('FPC_POPADDRSTACK',true);
  561. emitl(A_JMP,endexceptlabel);
  562. emitl(A_LABEL,doexceptlabel);
  563. if assigned(p^.right) then
  564. secondpass(p^.right);
  565. emitl(A_LABEL,lastonlabel);
  566. { default handling }
  567. if assigned(p^.t1) then
  568. begin
  569. { FPC_CATCHES must be called with
  570. 'default handler' flag (=-1)
  571. }
  572. push_int (-1);
  573. emitcall('FPC_CATCHES',true);
  574. secondpass(p^.t1);
  575. end
  576. else
  577. emitcall('FPC_RERAISE',true);
  578. emitl(A_LABEL,endexceptlabel);
  579. endexceptlabel:=oldendexceptlabel; *)
  580. end;
  581. {*****************************************************************************
  582. SecondOn
  583. *****************************************************************************}
  584. procedure secondon(var p : ptree);
  585. var
  586. nextonlabel,myendexceptlabel : pasmlabel;
  587. ref : treference;
  588. begin
  589. { !!!!!!!!!!!!!!! }
  590. (* getlabel(nextonlabel);
  591. { push the vmt }
  592. exprasmlist^.concat(new(paicpu,op_csymbol(A_PUSH,S_L,
  593. newcsymbol(p^.excepttype^.vmt_mangledname,0))));
  594. maybe_concat_external(p^.excepttype^.owner,
  595. p^.excepttype^.vmt_mangledname);
  596. emitcall('FPC_CATCHES',true);
  597. exprasmlist^.concat(new(paicpu,
  598. op_reg_reg(A_TEST,S_L,R_EAX,R_EAX)));
  599. emitl(A_JE,nextonlabel);
  600. ref.symbol:=nil;
  601. gettempofsizereference(4,ref);
  602. { what a hack ! }
  603. if assigned(p^.exceptsymtable) then
  604. pvarsym(p^.exceptsymtable^.root)^.address:=ref.offset;
  605. exprasmlist^.concat(new(paicpu,op_reg_ref(A_MOV,S_L,
  606. R_EAX,newreference(ref))));
  607. if assigned(p^.right) then
  608. secondpass(p^.right);
  609. { clear some stuff }
  610. ungetiftemp(ref);
  611. emitl(A_JMP,endexceptlabel);
  612. emitl(A_LABEL,nextonlabel);
  613. { next on node }
  614. if assigned(p^.left) then
  615. secondpass(p^.left); *)
  616. end;
  617. {*****************************************************************************
  618. SecondTryFinally
  619. *****************************************************************************}
  620. procedure secondtryfinally(var p : ptree);
  621. var
  622. finallylabel,noreraiselabel,endfinallylabel : pasmlabel;
  623. begin
  624. (* { we modify EAX }
  625. usedinproc:=usedinproc or ($80 shr byte(R_EAX));
  626. getlabel(finallylabel);
  627. getlabel(noreraiselabel);
  628. getlabel(endfinallylabel);
  629. push_int(1); { Type of stack-frame must be pushed}
  630. emitcall('FPC_PUSHEXCEPTADDR',true);
  631. exprasmlist^.concat(new(paicpu,
  632. op_reg(A_PUSH,S_L,R_EAX)));
  633. emitcall('FPC_SETJMP',true);
  634. exprasmlist^.concat(new(paicpu,
  635. op_reg(A_PUSH,S_L,R_EAX)));
  636. exprasmlist^.concat(new(paicpu,
  637. op_reg_reg(A_TEST,S_L,R_EAX,R_EAX)));
  638. emitl(A_JNE,finallylabel);
  639. { try code }
  640. secondpass(p^.left);
  641. if codegenerror then
  642. exit;
  643. emitl(A_LABEL,finallylabel);
  644. { finally code }
  645. secondpass(p^.right);
  646. if codegenerror then
  647. exit;
  648. exprasmlist^.concat(new(paicpu,
  649. op_reg(A_POP,S_L,R_EAX)));
  650. exprasmlist^.concat(new(paicpu,
  651. op_reg_reg(A_TEST,S_L,R_EAX,R_EAX)));
  652. emitl(A_JE,noreraiselabel);
  653. emitcall('FPC_RERAISE',true);
  654. emitl(A_LABEL,noreraiselabel);
  655. emitcall('FPC_POPADDRSTACK',true);
  656. emitl(A_LABEL,endfinallylabel); *)
  657. end;
  658. {*****************************************************************************
  659. SecondFail
  660. *****************************************************************************}
  661. procedure secondfail(var p : ptree);
  662. var
  663. hp : preference;
  664. begin
  665. exprasmlist^.concat(new(paicpu,op_reg(A_CLR,S_L,R_A5)));
  666. { also reset to zero in the stack }
  667. new(hp);
  668. reset_reference(hp^);
  669. hp^.offset:=procinfo^.selfpointer_offset;
  670. hp^.base:=procinfo^.framepointer;
  671. exprasmlist^.concat(new(paicpu,op_reg_ref(A_MOVE,S_L,R_A5,hp)));
  672. exprasmlist^.concat(new(pai_labeled,init(A_JMP,quickexitlabel)));
  673. end;
  674. end.
  675. {
  676. $Log$
  677. Revision 1.2 2000-07-13 11:32:36 michael
  678. + removed logs
  679. }