cg386flw.pas 26 KB

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