cg386flw.pas 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  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,LOC_REFERENCE : is_mem:=true;
  342. LOC_CREGISTER,
  343. LOC_REGISTER : is_mem:=false;
  344. LOC_FLAGS : begin
  345. exprasmlist^.concat(new(pai386,op_reg(flag_2_set[p^.right^.location.resflags],S_B,R_AL)));
  346. goto do_jmp;
  347. end;
  348. LOC_JUMP : begin
  349. emitl(A_LABEL,truelabel);
  350. exprasmlist^.concat(new(pai386,op_const_reg(A_MOV,S_B,1,R_AL)));
  351. emitl(A_JMP,aktexit2label);
  352. exprasmlist^.concat(new(pai386,op_reg_reg(A_XOR,S_B,R_AL,R_AL)));
  353. goto do_jmp;
  354. end;
  355. else internalerror(2001);
  356. end;
  357. if (procinfo.retdef^.deftype=orddef) then
  358. begin
  359. case porddef(procinfo.retdef)^.typ of
  360. s32bit,u32bit,bool32bit : if is_mem then
  361. exprasmlist^.concat(new(pai386,op_ref_reg(A_MOV,S_L,
  362. newreference(p^.left^.location.reference),R_EAX)))
  363. else
  364. emit_reg_reg(A_MOV,S_L,p^.left^.location.register,R_EAX);
  365. u8bit,s8bit,uchar,bool8bit : if is_mem then
  366. exprasmlist^.concat(new(pai386,op_ref_reg(A_MOV,S_B,
  367. newreference(p^.left^.location.reference),R_AL)))
  368. else
  369. emit_reg_reg(A_MOV,S_B,p^.left^.location.register,R_AL);
  370. s16bit,u16bit,bool16bit : if is_mem then
  371. exprasmlist^.concat(new(pai386,op_ref_reg(A_MOV,S_W,
  372. newreference(p^.left^.location.reference),R_AX)))
  373. else
  374. emit_reg_reg(A_MOV,S_W,p^.left^.location.register,R_AX);
  375. end;
  376. end
  377. else
  378. if (procinfo.retdef^.deftype in [pointerdef,enumdef,procvardef]) then
  379. begin
  380. if is_mem then
  381. exprasmlist^.concat(new(pai386,op_ref_reg(A_MOV,S_L,
  382. newreference(p^.left^.location.reference),R_EAX)))
  383. else
  384. exprasmlist^.concat(new(pai386,op_reg_reg(A_MOV,S_L,
  385. p^.left^.location.register,R_EAX)));
  386. end
  387. else
  388. if (procinfo.retdef^.deftype=floatdef) then
  389. 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. do_jmp:
  403. truelabel:=otlabel;
  404. falselabel:=oflabel;
  405. emitl(A_JMP,aktexit2label);
  406. end
  407. else
  408. begin
  409. emitl(A_JMP,aktexitlabel);
  410. end;
  411. end;
  412. {*****************************************************************************
  413. SecondBreakN
  414. *****************************************************************************}
  415. procedure secondbreakn(var p : ptree);
  416. begin
  417. if aktbreaklabel<>nil then
  418. emitl(A_JMP,aktbreaklabel)
  419. else
  420. Message(cg_e_break_not_allowed);
  421. end;
  422. {*****************************************************************************
  423. SecondContinueN
  424. *****************************************************************************}
  425. procedure secondcontinuen(var p : ptree);
  426. begin
  427. if aktcontinuelabel<>nil then
  428. emitl(A_JMP,aktcontinuelabel)
  429. else
  430. Message(cg_e_continue_not_allowed);
  431. end;
  432. {*****************************************************************************
  433. SecondGoto
  434. *****************************************************************************}
  435. procedure secondgoto(var p : ptree);
  436. begin
  437. emitl(A_JMP,p^.labelnr);
  438. end;
  439. {*****************************************************************************
  440. SecondLabel
  441. *****************************************************************************}
  442. procedure secondlabel(var p : ptree);
  443. begin
  444. emitl(A_LABEL,p^.labelnr);
  445. cleartempgen;
  446. secondpass(p^.left);
  447. end;
  448. {*****************************************************************************
  449. SecondRaise
  450. *****************************************************************************}
  451. procedure secondraise(var p : ptree);
  452. var
  453. a : plabel;
  454. begin
  455. if assigned(p^.left) then
  456. begin
  457. { generate the address }
  458. if assigned(p^.right) then
  459. begin
  460. secondpass(p^.right);
  461. if codegenerror then
  462. exit;
  463. end
  464. else
  465. begin
  466. getlabel(a);
  467. emitl(A_LABEL,a);
  468. exprasmlist^.concat(new(pai386,
  469. op_csymbol(A_PUSH,S_L,newcsymbol(lab2str(a),0))));
  470. end;
  471. secondpass(p^.left);
  472. if codegenerror then
  473. exit;
  474. case p^.left^.location.loc of
  475. LOC_MEM,LOC_REFERENCE:
  476. emitpushreferenceaddr(exprasmlist,p^.left^.location.reference);
  477. LOC_CREGISTER,LOC_REGISTER : exprasmlist^.concat(new(pai386,op_reg(A_PUSH,S_L,
  478. p^.left^.location.register)));
  479. else Message(sym_e_type_mismatch);
  480. end;
  481. emitcall('FPC_RAISEEXCEPTION',true);
  482. end
  483. else
  484. begin
  485. emitcall('FPC_RERAISE',true);
  486. end;
  487. end;
  488. {*****************************************************************************
  489. SecondTryExcept
  490. *****************************************************************************}
  491. var
  492. endexceptlabel : plabel;
  493. procedure secondtryexcept(var p : ptree);
  494. var
  495. exceptlabel,doexceptlabel,oldendexceptlabel,
  496. lastonlabel : plabel;
  497. begin
  498. { this can be called recursivly }
  499. oldendexceptlabel:=endexceptlabel;
  500. { we modify EAX }
  501. usedinproc:=usedinproc or ($80 shr byte(R_EAX));
  502. getlabel(exceptlabel);
  503. getlabel(doexceptlabel);
  504. getlabel(endexceptlabel);
  505. getlabel(lastonlabel);
  506. push_int (1); { push type of exceptionframe }
  507. emitcall('FPC_PUSHEXCEPTADDR',true);
  508. exprasmlist^.concat(new(pai386,
  509. op_reg(A_PUSH,S_L,R_EAX)));
  510. emitcall('FPC_SETJMP',true);
  511. exprasmlist^.concat(new(pai386,
  512. op_reg(A_PUSH,S_L,R_EAX)));
  513. exprasmlist^.concat(new(pai386,
  514. op_reg_reg(A_TEST,S_L,R_EAX,R_EAX)));
  515. emitl(A_JNE,exceptlabel);
  516. { try code }
  517. secondpass(p^.left);
  518. if codegenerror then
  519. exit;
  520. emitl(A_LABEL,exceptlabel);
  521. exprasmlist^.concat(new(pai386,
  522. op_reg(A_POP,S_L,R_EAX)));
  523. exprasmlist^.concat(new(pai386,
  524. op_reg_reg(A_TEST,S_L,R_EAX,R_EAX)));
  525. emitl(A_JNE,doexceptlabel);
  526. emitcall('FPC_POPADDRSTACK',true);
  527. emitl(A_JMP,endexceptlabel);
  528. emitl(A_LABEL,doexceptlabel);
  529. if assigned(p^.right) then
  530. secondpass(p^.right);
  531. emitl(A_LABEL,lastonlabel);
  532. { default handling }
  533. if assigned(p^.t1) then
  534. begin
  535. { FPC_CATCHES must be called with
  536. 'default handler' flag (=-1)
  537. }
  538. push_int (-1);
  539. emitcall('FPC_CATCHES',true);
  540. secondpass(p^.t1);
  541. end
  542. else
  543. emitcall('FPC_RERAISE',true);
  544. emitl(A_LABEL,endexceptlabel);
  545. endexceptlabel:=oldendexceptlabel;
  546. end;
  547. procedure secondon(var p : ptree);
  548. var
  549. nextonlabel : plabel;
  550. ref : treference;
  551. begin
  552. getlabel(nextonlabel);
  553. { push the vmt }
  554. exprasmlist^.concat(new(pai386,op_csymbol(A_PUSH,S_L,
  555. newcsymbol(p^.excepttype^.vmt_mangledname,0))));
  556. maybe_concat_external(p^.excepttype^.owner,
  557. p^.excepttype^.vmt_mangledname);
  558. emitcall('FPC_CATCHES',true);
  559. exprasmlist^.concat(new(pai386,
  560. op_reg_reg(A_TEST,S_L,R_EAX,R_EAX)));
  561. emitl(A_JE,nextonlabel);
  562. ref.symbol:=nil;
  563. gettempofsizereference(4,ref);
  564. { what a hack ! }
  565. if assigned(p^.exceptsymtable) then
  566. pvarsym(p^.exceptsymtable^.root)^.address:=ref.offset;
  567. exprasmlist^.concat(new(pai386,op_reg_ref(A_MOV,S_L,
  568. R_EAX,newreference(ref))));
  569. if assigned(p^.right) then
  570. secondpass(p^.right);
  571. { clear some stuff }
  572. ungetiftemp(ref);
  573. emitl(A_JMP,endexceptlabel);
  574. emitl(A_LABEL,nextonlabel);
  575. { next on node }
  576. if assigned(p^.left) then
  577. secondpass(p^.left);
  578. end;
  579. {*****************************************************************************
  580. SecondTryFinally
  581. *****************************************************************************}
  582. procedure secondtryfinally(var p : ptree);
  583. var
  584. finallylabel,noreraiselabel,endfinallylabel : plabel;
  585. begin
  586. { we modify EAX }
  587. usedinproc:=usedinproc or ($80 shr byte(R_EAX));
  588. getlabel(finallylabel);
  589. getlabel(noreraiselabel);
  590. getlabel(endfinallylabel);
  591. push_int(1); { Type of stack-frame must be pushed}
  592. emitcall('FPC_PUSHEXCEPTADDR',true);
  593. exprasmlist^.concat(new(pai386,
  594. op_reg(A_PUSH,S_L,R_EAX)));
  595. emitcall('FPC_SETJMP',true);
  596. exprasmlist^.concat(new(pai386,
  597. op_reg(A_PUSH,S_L,R_EAX)));
  598. exprasmlist^.concat(new(pai386,
  599. op_reg_reg(A_TEST,S_L,R_EAX,R_EAX)));
  600. emitl(A_JNE,finallylabel);
  601. { try code }
  602. secondpass(p^.left);
  603. if codegenerror then
  604. exit;
  605. emitl(A_LABEL,finallylabel);
  606. { finally code }
  607. secondpass(p^.right);
  608. if codegenerror then
  609. exit;
  610. exprasmlist^.concat(new(pai386,
  611. op_reg(A_POP,S_L,R_EAX)));
  612. exprasmlist^.concat(new(pai386,
  613. op_reg_reg(A_TEST,S_L,R_EAX,R_EAX)));
  614. emitl(A_JE,noreraiselabel);
  615. emitcall('FPC_RERAISE',true);
  616. emitl(A_LABEL,noreraiselabel);
  617. emitcall('FPC_POPADDRSTACK',true);
  618. emitl(A_LABEL,endfinallylabel);
  619. end;
  620. {*****************************************************************************
  621. SecondFail
  622. *****************************************************************************}
  623. procedure secondfail(var p : ptree);
  624. var
  625. hp : preference;
  626. begin
  627. {if procinfo.exceptions then
  628. aktproccode.concat(gennasmrec(CALL,S_NO,'HELP_DESTRUCTOR_E'))
  629. else }
  630. { we should know if the constructor is called with a new or not,
  631. how can we do that ???
  632. exprasmlist^.concat(new(pai386,op_csymbol(A_CALL,S_NO,newcsymbol('HELP_DESTRUCTOR',0))));
  633. }
  634. exprasmlist^.concat(new(pai386,op_reg_reg(A_XOR,S_L,R_ESI,R_ESI)));
  635. { also reset to zero in the stack }
  636. new(hp);
  637. reset_reference(hp^);
  638. hp^.offset:=procinfo.ESI_offset;
  639. hp^.base:=procinfo.framepointer;
  640. exprasmlist^.concat(new(pai386,op_reg_ref(A_MOV,S_L,R_ESI,hp)));
  641. exprasmlist^.concat(new(pai_labeled,init(A_JMP,quickexitlabel)));
  642. end;
  643. end.
  644. {
  645. $Log$
  646. Revision 1.12 1998-08-28 10:56:58 peter
  647. * removed warnings
  648. Revision 1.11 1998/08/05 16:00:10 florian
  649. * some fixes for ansi strings
  650. * $log$ to $Log$
  651. * $log$ to Revision 1.12 1998-08-28 10:56:58 peter
  652. * $log$ to * removed warnings
  653. * $log$ to changed
  654. Revision 1.10 1998/08/04 16:26:26 jonas
  655. * converted // comment to TP comment
  656. Revision 1.9 1998/07/31 11:36:34 michael
  657. Default exception handler also needs to call FPC_CATCHES
  658. Revision 1.8 1998/07/30 13:30:32 florian
  659. * final implemenation of exception support, maybe it needs
  660. some fixes :)
  661. Revision 1.7 1998/07/30 11:18:13 florian
  662. + first implementation of try ... except on .. do end;
  663. * limitiation of 65535 bytes parameters for cdecl removed
  664. Revision 1.6 1998/07/29 13:29:11 michael
  665. + Corrected try.. code. Type of exception fram is pushed
  666. Revision 1.5 1998/07/28 21:52:49 florian
  667. + implementation of raise and try..finally
  668. + some misc. exception stuff
  669. Revision 1.4 1998/07/24 22:16:53 florian
  670. * internal error 10 together with array access fixed. I hope
  671. that's the final fix.
  672. Revision 1.3 1998/06/25 08:48:08 florian
  673. * first version of rtti support
  674. Revision 1.2 1998/06/08 13:13:33 pierre
  675. + temporary variables now in temp_gen.pas unit
  676. because it is processor independent
  677. * mppc68k.bat modified to undefine i386 and support_mmx
  678. (which are defaults for i386)
  679. Revision 1.1 1998/06/05 17:44:12 peter
  680. * splitted cgi386
  681. }