cg386flw.pas 26 KB

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