cg386flw.pas 26 KB

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