cg68kinl.pas 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931
  1. {
  2. $Id$
  3. Copyright (c) 1993-98 by Florian Klaempfl
  4. Generate m68k inline nodes
  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 cg68kinl;
  19. interface
  20. uses
  21. tree;
  22. procedure secondinline(var p : ptree);
  23. implementation
  24. uses
  25. cobjects,verbose,globals,systems,
  26. aasm,types,symtable,
  27. hcodegen,temp_gen,pass_2,
  28. m68k,cga68k,tgen68k,cg68kld,cg68kcal;
  29. {*****************************************************************************
  30. Helpers
  31. *****************************************************************************}
  32. { reverts the parameter list }
  33. var nb_para : integer;
  34. function reversparameter(p : ptree) : ptree;
  35. var
  36. hp1,hp2 : ptree;
  37. begin
  38. hp1:=nil;
  39. nb_para := 0;
  40. while assigned(p) do
  41. begin
  42. { pull out }
  43. hp2:=p;
  44. p:=p^.right;
  45. inc(nb_para);
  46. { pull in }
  47. hp2^.right:=hp1;
  48. hp1:=hp2;
  49. end;
  50. reversparameter:=hp1;
  51. end;
  52. {*****************************************************************************
  53. SecondInLine
  54. *****************************************************************************}
  55. procedure secondinline(var p : ptree);
  56. const
  57. { tfloattype = (f32bit,s32real,s64real,s80real,s64bit); }
  58. float_name: array[tfloattype] of string[8]=
  59. ('FIXED','SINGLE','REAL','EXTENDED','COMP','FIXED16');
  60. addconstsubop:array[in_inc_x..in_dec_x] of tasmop=(A_ADDQ,A_SUBQ);
  61. addsubop:array[in_inc_x..in_dec_x] of tasmop=(A_ADD,A_SUB);
  62. var
  63. aktfile : treference;
  64. ft : tfiletype;
  65. opsize : topsize;
  66. asmop : tasmop;
  67. pushed : tpushed;
  68. {inc/dec}
  69. addconstant : boolean;
  70. addvalue : longint;
  71. procedure handlereadwrite(doread,doln : boolean);
  72. { produces code for READ(LN) and WRITE(LN) }
  73. procedure loadstream;
  74. const
  75. io:array[0..1] of string[7]=('_OUTPUT','_INPUT');
  76. var
  77. r : preference;
  78. begin
  79. new(r);
  80. reset_reference(r^);
  81. r^.symbol:=stringdup('U_'+upper(target_info.system_unit)+io[byte(doread)]);
  82. concat_external(r^.symbol^,EXT_NEAR);
  83. exprasmlist^.concat(new(pai68k,op_ref_reg(A_LEA,S_L,r,R_A0)))
  84. end;
  85. var
  86. node,hp : ptree;
  87. typedtyp,
  88. pararesult : pdef;
  89. has_length : boolean;
  90. dummycoll : tdefcoll;
  91. iolabel : plabel;
  92. npara : longint;
  93. begin
  94. { I/O check }
  95. if cs_check_io in aktlocalswitches then
  96. begin
  97. getlabel(iolabel);
  98. emitl(A_LABEL,iolabel);
  99. end
  100. else
  101. iolabel:=nil;
  102. { for write of real with the length specified }
  103. has_length:=false;
  104. hp:=nil;
  105. { reserve temporary pointer to data variable }
  106. aktfile.symbol:=nil;
  107. gettempofsizereference(4,aktfile);
  108. { first state text data }
  109. ft:=ft_text;
  110. { and state a parameter ? }
  111. if p^.left=nil then
  112. begin
  113. { the following instructions are for "writeln;" }
  114. loadstream;
  115. { save @aktfile in temporary variable }
  116. exprasmlist^.concat(new(pai68k,op_reg_ref(A_MOVE,S_L,R_A0,newreference(aktfile))));
  117. end
  118. else
  119. begin
  120. { revers paramters }
  121. node:=reversparameter(p^.left);
  122. p^.left := node;
  123. npara := nb_para;
  124. { calculate data variable }
  125. { is first parameter a file type ? }
  126. if node^.left^.resulttype^.deftype=filedef then
  127. begin
  128. ft:=pfiledef(node^.left^.resulttype)^.filetype;
  129. if ft=ft_typed then
  130. typedtyp:=pfiledef(node^.left^.resulttype)^.typed_as;
  131. secondpass(node^.left);
  132. if codegenerror then
  133. exit;
  134. { save reference in temporary variables }
  135. if node^.left^.location.loc<>LOC_REFERENCE then
  136. begin
  137. CGMessage(cg_e_illegal_expression);
  138. exit;
  139. end;
  140. exprasmlist^.concat(new(pai68k,op_ref_reg(A_LEA,S_L,newreference(node^.left^.location.reference),R_A0)));
  141. { skip to the next parameter }
  142. node:=node^.right;
  143. end
  144. else
  145. begin
  146. { load stdin/stdout stream }
  147. loadstream;
  148. end;
  149. { save @aktfile in temporary variable }
  150. exprasmlist^.concat(new(pai68k,op_reg_ref(A_MOVE,S_L,R_A0,newreference(aktfile))));
  151. if doread then
  152. { parameter by READ gives call by reference }
  153. dummycoll.paratyp:=vs_var
  154. { an WRITE Call by "Const" }
  155. else
  156. dummycoll.paratyp:=vs_const;
  157. { because of secondcallparan, which otherwise attaches }
  158. if ft=ft_typed then
  159. { this is to avoid copy of simple const parameters }
  160. dummycoll.data:=new(pformaldef,init)
  161. else
  162. { I think, this isn't a good solution (FK) }
  163. dummycoll.data:=nil;
  164. while assigned(node) do
  165. begin
  166. pushusedregisters(pushed,$ff);
  167. hp:=node;
  168. node:=node^.right;
  169. hp^.right:=nil;
  170. if hp^.is_colon_para then
  171. CGMessage(parser_e_illegal_colon_qualifier);
  172. if ft=ft_typed then
  173. never_copy_const_param:=true;
  174. secondcallparan(hp,@dummycoll,false);
  175. if ft=ft_typed then
  176. never_copy_const_param:=false;
  177. hp^.right:=node;
  178. if codegenerror then
  179. exit;
  180. emit_push_mem(aktfile);
  181. if (ft=ft_typed) then
  182. begin
  183. { OK let's try this }
  184. { first we must only allow the right type }
  185. { we have to call blockread or blockwrite }
  186. { but the real problem is that }
  187. { reset and rewrite should have set }
  188. { the type size }
  189. { as recordsize for that file !!!! }
  190. { how can we make that }
  191. { I think that is only possible by adding }
  192. { reset and rewrite to the inline list a call }
  193. { allways read only one record by element }
  194. push_int(typedtyp^.size);
  195. if doread then
  196. emitcall('FPC_TYPED_READ',true)
  197. else
  198. emitcall('FPC_TYPED_WRITE',true);
  199. end
  200. else
  201. begin
  202. { save current position }
  203. pararesult:=hp^.left^.resulttype;
  204. { handle possible field width }
  205. { of course only for write(ln) }
  206. if not doread then
  207. begin
  208. { handle total width parameter }
  209. if assigned(node) and node^.is_colon_para then
  210. begin
  211. hp:=node;
  212. node:=node^.right;
  213. hp^.right:=nil;
  214. secondcallparan(hp,@dummycoll,false);
  215. hp^.right:=node;
  216. if codegenerror then
  217. exit;
  218. has_length:=true;
  219. end
  220. else
  221. if pararesult^.deftype<>floatdef then
  222. push_int(0)
  223. else
  224. push_int(-32767);
  225. { a second colon para for a float ? }
  226. if assigned(node) and node^.is_colon_para then
  227. begin
  228. hp:=node;
  229. node:=node^.right;
  230. hp^.right:=nil;
  231. secondcallparan(hp,@dummycoll,false);
  232. hp^.right:=node;
  233. if pararesult^.deftype<>floatdef then
  234. CGMessage(parser_e_illegal_colon_qualifier);
  235. if codegenerror then
  236. exit;
  237. end
  238. else
  239. begin
  240. if pararesult^.deftype=floatdef then
  241. push_int(-1);
  242. end
  243. end;
  244. case pararesult^.deftype of
  245. stringdef : begin
  246. if doread then
  247. begin
  248. { push maximum string length }
  249. push_int(pstringdef(pararesult)^.len);
  250. case pstringdef(pararesult)^.string_typ of
  251. st_shortstring:
  252. emitcall ('FPC_READ_TEXT_STRING',true);
  253. st_ansistring:
  254. emitcall ('FPC_READ_TEXT_ANSISTRING',true);
  255. st_longstring:
  256. emitcall ('FPC_READ_TEXT_LONGSTRING',true);
  257. st_widestring:
  258. emitcall ('FPC_READ_TEXT_ANSISTRING',true);
  259. end
  260. end
  261. else
  262. Case pstringdef(Pararesult)^.string_typ of
  263. st_shortstring:
  264. emitcall ('FPC_WRITE_TEXT_STRING',true);
  265. st_ansistring:
  266. emitcall ('FPC_WRITE_TEXT_ANSISTRING',true);
  267. st_longstring:
  268. emitcall ('FPC_WRITE_TEXT_LONGSTRING',true);
  269. st_widestring:
  270. emitcall ('FPC_WRITE_TEXT_ANSISTRING',true);
  271. end;
  272. end;
  273. pointerdef : begin
  274. if is_equal(ppointerdef(pararesult)^.definition,cchardef) then
  275. begin
  276. if doread then
  277. emitcall('FPC_READ_TEXT_PCHAR_AS_POINTER',true)
  278. else
  279. emitcall('FPC_WRITE_TEXT_PCHAR_AS_POINTER',true);
  280. end;
  281. end;
  282. arraydef : begin
  283. if (parraydef(pararesult)^.lowrange=0) and
  284. is_equal(parraydef(pararesult)^.definition,cchardef) then
  285. begin
  286. if doread then
  287. emitcall('FPC_READ_TEXT_PCHAR_AS_ARRAY',true)
  288. else
  289. emitcall('FPC_WRITE_TEXT_PCHAR_AS_ARRAY',true);
  290. end;
  291. end;
  292. floatdef : begin
  293. if doread then
  294. emitcall('FPC_READ_TEXT_'+float_name[pfloatdef(pararesult)^.typ],true)
  295. else
  296. emitcall('FPC_WRITE_TEXT_'+float_name[pfloatdef(pararesult)^.typ],true);
  297. end;
  298. orddef : begin
  299. case porddef(pararesult)^.typ of
  300. u8bit : if doread then
  301. emitcall('FPC_READ_TEXT_BYTE',true);
  302. s8bit : if doread then
  303. emitcall('FPC_READ_TEXT_SHORTINT',true);
  304. u16bit : if doread then
  305. emitcall('FPC_READ_TEXT_WORD',true);
  306. s16bit : if doread then
  307. emitcall('FPC_READ_TEXT_INTEGER',true);
  308. s32bit : if doread then
  309. emitcall('FPC_READ_TEXT_LONGINT',true)
  310. else
  311. emitcall('FPC_WRITE_TEXT_LONGINT',true);
  312. u32bit : if doread then
  313. emitcall('FPC_READ_TEXT_CARDINAL',true)
  314. else
  315. emitcall('FPC_WRITE_TEXT_CARDINAL',true);
  316. uchar : if doread then
  317. emitcall('FPC_READ_TEXT_CHAR',true)
  318. else
  319. emitcall('FPC_WRITE_TEXT_CHAR',true);
  320. bool8bit,
  321. bool16bit,
  322. bool32bit : if doread then
  323. CGMessage(parser_e_illegal_parameter_list)
  324. else
  325. emitcall('FPC_WRITE_TEXT_BOOLEAN',true);
  326. end;
  327. end;
  328. end;
  329. end;
  330. { load ESI in methods again }
  331. popusedregisters(pushed);
  332. maybe_loada5;
  333. end;
  334. end;
  335. { Insert end of writing for textfiles }
  336. if ft=ft_text then
  337. begin
  338. pushusedregisters(pushed,$ff);
  339. emit_push_mem(aktfile);
  340. if doread then
  341. begin
  342. if doln then
  343. emitcall('FPC_READLN_END',true)
  344. else
  345. emitcall('FPC_READ_END',true);
  346. end
  347. else
  348. begin
  349. if doln then
  350. emitcall('FPC_WRITELN_END',true)
  351. else
  352. emitcall('FPC_WRITE_END',true);
  353. end;
  354. popusedregisters(pushed);
  355. maybe_loada5;
  356. end;
  357. { Insert IOCheck if set }
  358. if assigned(iolabel) then
  359. begin
  360. { registers are saved in the procedure }
  361. exprasmlist^.concat(new(pai68k,op_csymbol(A_PEA,S_L,newcsymbol(lab2str(iolabel),0))));
  362. emitcall('FPC_IOCHECK',true);
  363. end;
  364. { Freeup all used temps }
  365. ungetiftemp(aktfile);
  366. if assigned(p^.left) then
  367. begin
  368. p^.left:=reversparameter(p^.left);
  369. if npara<>nb_para then
  370. CGMessage(cg_f_internal_error_in_secondinline);
  371. hp:=p^.left;
  372. while assigned(hp) do
  373. begin
  374. if assigned(hp^.left) then
  375. if (hp^.left^.location.loc in [LOC_MEM,LOC_REFERENCE]) then
  376. ungetiftemp(hp^.left^.location.reference);
  377. hp:=hp^.right;
  378. end;
  379. end;
  380. end;
  381. procedure handle_str;
  382. var
  383. hp,node : ptree;
  384. dummycoll : tdefcoll;
  385. is_real,has_length : boolean;
  386. begin
  387. pushusedregisters(pushed,$ff);
  388. node:=p^.left;
  389. is_real:=false;
  390. has_length:=false;
  391. while assigned(node^.right) do node:=node^.right;
  392. { if a real parameter somewhere then call REALSTR }
  393. if (node^.left^.resulttype^.deftype=floatdef) then
  394. is_real:=true;
  395. node:=p^.left;
  396. { we have at least two args }
  397. { with at max 2 colon_para in between }
  398. { first arg longint or float }
  399. hp:=node;
  400. node:=node^.right;
  401. hp^.right:=nil;
  402. dummycoll.data:=hp^.resulttype;
  403. { string arg }
  404. dummycoll.paratyp:=vs_var;
  405. secondcallparan(hp,@dummycoll,false);
  406. if codegenerror then
  407. exit;
  408. dummycoll.paratyp:=vs_const;
  409. disposetree(hp);
  410. p^.left:=nil;
  411. { second arg }
  412. hp:=node;
  413. node:=node^.right;
  414. hp^.right:=nil;
  415. { frac para }
  416. if hp^.is_colon_para and assigned(node) and
  417. node^.is_colon_para then
  418. begin
  419. dummycoll.data:=hp^.resulttype;
  420. secondcallparan(hp,@dummycoll,false);
  421. if codegenerror then
  422. exit;
  423. disposetree(hp);
  424. hp:=node;
  425. node:=node^.right;
  426. hp^.right:=nil;
  427. has_length:=true;
  428. end
  429. else
  430. if is_real then
  431. push_int(-1);
  432. { third arg, length only if is_real }
  433. if hp^.is_colon_para then
  434. begin
  435. dummycoll.data:=hp^.resulttype;
  436. secondcallparan(hp,@dummycoll,false);
  437. if codegenerror then
  438. exit;
  439. disposetree(hp);
  440. hp:=node;
  441. node:=node^.right;
  442. hp^.right:=nil;
  443. end
  444. else
  445. if is_real then
  446. push_int(-32767)
  447. else
  448. push_int(-1);
  449. { last arg longint or real }
  450. secondcallparan(hp,@dummycoll,false);
  451. if codegenerror then
  452. exit;
  453. disposetree(hp);
  454. if is_real then
  455. emitcall('FPC_STR_'+float_name[pfloatdef(hp^.resulttype)^.typ],true)
  456. else if porddef(hp^.resulttype)^.typ=u32bit then
  457. emitcall('FPC_STR_CARDINAL',true)
  458. else
  459. emitcall('FPC_STR_LONGINT',true);
  460. popusedregisters(pushed);
  461. end;
  462. var
  463. r : preference;
  464. l : longint;
  465. ispushed : boolean;
  466. hregister : tregister;
  467. otlabel,oflabel,filenamestring : plabel;
  468. oldpushedparasize : longint;
  469. begin
  470. { save & reset pushedparasize }
  471. oldpushedparasize:=pushedparasize;
  472. pushedparasize:=0;
  473. case p^.inlinenumber of
  474. in_assert_x_y:
  475. begin
  476. { !!!!!!!!! }
  477. end;
  478. in_lo_word,
  479. in_hi_word :
  480. begin
  481. secondpass(p^.left);
  482. p^.location.loc:=LOC_REGISTER;
  483. if p^.left^.location.loc<>LOC_REGISTER then
  484. begin
  485. if p^.left^.location.loc=LOC_CREGISTER then
  486. begin
  487. p^.location.register:=getregister32;
  488. emit_reg_reg(A_MOVE,S_W,p^.left^.location.register,
  489. p^.location.register);
  490. end
  491. else
  492. begin
  493. del_reference(p^.left^.location.reference);
  494. p^.location.register:=getregister32;
  495. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_W,
  496. newreference(p^.left^.location.reference),
  497. p^.location.register)));
  498. end;
  499. end
  500. else p^.location.register:=p^.left^.location.register;
  501. if p^.inlinenumber=in_hi_word then
  502. exprasmlist^.concat(new(pai68k,op_const_reg(A_LSR,S_W,8,p^.location.register)));
  503. p^.location.register:=p^.location.register;
  504. end;
  505. in_high_x :
  506. begin
  507. if is_open_array(p^.left^.resulttype) then
  508. begin
  509. secondpass(p^.left);
  510. del_reference(p^.left^.location.reference);
  511. p^.location.register:=getregister32;
  512. new(r);
  513. reset_reference(r^);
  514. r^.base:=highframepointer;
  515. r^.offset:=highoffset+4;
  516. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,
  517. r,p^.location.register)));
  518. end
  519. end;
  520. in_sizeof_x,
  521. in_typeof_x :
  522. begin
  523. { sizeof(openarray) handling }
  524. if (p^.inlinenumber=in_sizeof_x) and
  525. is_open_array(p^.left^.resulttype) then
  526. begin
  527. { sizeof(openarray)=high(openarray)+1 }
  528. secondpass(p^.left);
  529. del_reference(p^.left^.location.reference);
  530. p^.location.register:=getregister32;
  531. new(r);
  532. reset_reference(r^);
  533. r^.base:=highframepointer;
  534. r^.offset:=highoffset+4;
  535. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,
  536. r,p^.location.register)));
  537. exprasmlist^.concat(new(pai68k,op_const_reg(A_ADD,S_L,
  538. 1,p^.location.register)));
  539. if parraydef(p^.left^.resulttype)^.elesize<>1 then
  540. exprasmlist^.concat(new(pai68k,op_const_reg(A_MULS,S_L,
  541. parraydef(p^.left^.resulttype)^.elesize,p^.location.register)));
  542. end
  543. else
  544. begin
  545. { for both cases load vmt }
  546. if p^.left^.treetype=typen then
  547. begin
  548. exprasmlist^.concat(new(pai68k,op_csymbol_reg(A_LEA,
  549. S_L,newcsymbol(pobjectdef(p^.left^.resulttype)^.vmt_mangledname,0),
  550. R_A0)));
  551. p^.location.register:=getregister32;
  552. emit_reg_reg(A_MOVE,S_L,R_A0,p^.location.register);
  553. end
  554. else
  555. begin
  556. secondpass(p^.left);
  557. del_reference(p^.left^.location.reference);
  558. p^.location.loc:=LOC_REGISTER;
  559. p^.location.register:=getregister32;
  560. { load VMT pointer }
  561. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,
  562. newreference(p^.left^.location.reference),
  563. p^.location.register)));
  564. end;
  565. { in sizeof load size }
  566. if p^.inlinenumber=in_sizeof_x then
  567. begin
  568. new(r);
  569. reset_reference(r^);
  570. { load the address in A0 }
  571. { because now supposedly p^.location.register is an }
  572. { address. }
  573. emit_reg_reg(A_MOVE, S_L, p^.location.register, R_A0);
  574. r^.base:=R_A0;
  575. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,r,
  576. p^.location.register)));
  577. end;
  578. end;
  579. end;
  580. in_lo_long,
  581. in_hi_long : begin
  582. secondpass(p^.left);
  583. p^.location.loc:=LOC_REGISTER;
  584. if p^.left^.location.loc<>LOC_REGISTER then
  585. begin
  586. if p^.left^.location.loc=LOC_CREGISTER then
  587. begin
  588. p^.location.register:=getregister32;
  589. emit_reg_reg(A_MOVE,S_L,p^.left^.location.register,
  590. p^.location.register);
  591. end
  592. else
  593. begin
  594. del_reference(p^.left^.location.reference);
  595. p^.location.register:=getregister32;
  596. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,
  597. newreference(p^.left^.location.reference),
  598. p^.location.register)));
  599. end;
  600. end
  601. else p^.location.register:=p^.left^.location.register;
  602. if p^.inlinenumber=in_hi_long then
  603. begin
  604. exprasmlist^.concat(new(pai68k,op_const_reg(A_MOVEQ, S_L, 16, R_D1)));
  605. exprasmlist^.concat(new(pai68k,op_reg_reg(A_LSR,S_L,R_D1,p^.location.register)));
  606. end;
  607. p^.location.register:=p^.location.register;
  608. end;
  609. in_length_string :
  610. begin
  611. secondpass(p^.left);
  612. set_location(p^.location,p^.left^.location);
  613. { length in ansi strings is at offset -8 }
  614. {$ifdef UseAnsiString}
  615. if is_ansistring(p^.left^.resulttype) then
  616. dec(p^.location.reference.offset,8);
  617. {$endif UseAnsiString}
  618. end;
  619. in_pred_x,
  620. in_succ_x:
  621. begin
  622. secondpass(p^.left);
  623. if p^.inlinenumber=in_pred_x then
  624. asmop:=A_SUB
  625. else
  626. asmop:=A_ADD;
  627. case p^.resulttype^.size of
  628. 4 : opsize:=S_L;
  629. 2 : opsize:=S_W;
  630. 1 : opsize:=S_B;
  631. else
  632. internalerror(10080);
  633. end;
  634. p^.location.loc:=LOC_REGISTER;
  635. if p^.left^.location.loc<>LOC_REGISTER then
  636. begin
  637. p^.location.register:=getregister32;
  638. if p^.left^.location.loc=LOC_CREGISTER then
  639. emit_reg_reg(A_MOVE,opsize,p^.left^.location.register,
  640. p^.location.register)
  641. else
  642. if p^.left^.location.loc=LOC_FLAGS then
  643. exprasmlist^.concat(new(pai68k,op_reg(flag_2_set[p^.left^.location.resflags],S_NO,
  644. p^.location.register)))
  645. else
  646. begin
  647. del_reference(p^.left^.location.reference);
  648. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,opsize,newreference(p^.left^.location.reference),
  649. p^.location.register)));
  650. end;
  651. end
  652. else p^.location.register:=p^.left^.location.register;
  653. exprasmlist^.concat(new(pai68k,op_const_reg(asmop,opsize,1,
  654. p^.location.register)))
  655. { here we should insert bounds check ? }
  656. { and direct call to bounds will crash the program }
  657. { if we are at the limit }
  658. { we could also simply say that pred(first)=first and succ(last)=last }
  659. { could this be usefull I don't think so (PM)
  660. emitoverflowcheck;}
  661. end;
  662. in_dec_x,
  663. in_inc_x :
  664. begin
  665. { set defaults }
  666. addvalue:=1;
  667. addconstant:=true;
  668. { load first parameter, must be a reference }
  669. secondpass(p^.left^.left);
  670. case p^.left^.left^.resulttype^.deftype of
  671. orddef,
  672. enumdef : begin
  673. case p^.left^.left^.resulttype^.size of
  674. 1 : opsize:=S_B;
  675. 2 : opsize:=S_W;
  676. 4 : opsize:=S_L;
  677. end;
  678. end;
  679. pointerdef : begin
  680. opsize:=S_L;
  681. addvalue:=ppointerdef(p^.left^.left^.resulttype)^.definition^.savesize;
  682. end;
  683. else
  684. internalerror(10081);
  685. end;
  686. { second argument specified?, must be a s32bit in register }
  687. if assigned(p^.left^.right) then
  688. begin
  689. secondpass(p^.left^.right^.left);
  690. { when constant, just multiply the addvalue }
  691. if is_constintnode(p^.left^.right^.left) then
  692. addvalue:=addvalue*get_ordinal_value(p^.left^.right^.left)
  693. else
  694. begin
  695. case p^.left^.right^.left^.location.loc of
  696. LOC_REGISTER,
  697. LOC_CREGISTER : hregister:=p^.left^.right^.left^.location.register;
  698. LOC_MEM,
  699. LOC_REFERENCE : begin
  700. hregister:=getregister32;
  701. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,
  702. newreference(p^.left^.right^.left^.location.reference),hregister)));
  703. end;
  704. else
  705. internalerror(10082);
  706. end;
  707. { insert multiply with addvalue if its >1 }
  708. if addvalue>1 then
  709. exprasmlist^.concat(new(pai68k,op_const_reg(A_MULS,opsize,
  710. addvalue,hregister)));
  711. addconstant:=false;
  712. end;
  713. end;
  714. { write the add instruction }
  715. if addconstant then
  716. begin
  717. exprasmlist^.concat(new(pai68k,op_const_ref(addconstsubop[p^.inlinenumber],opsize,
  718. addvalue,newreference(p^.left^.left^.location.reference))));
  719. end
  720. else
  721. begin
  722. exprasmlist^.concat(new(pai68k,op_reg_ref(addsubop[p^.inlinenumber],opsize,
  723. hregister,newreference(p^.left^.left^.location.reference))));
  724. ungetregister32(hregister);
  725. end;
  726. emitoverflowcheck(p^.left^.left);
  727. end;
  728. in_assigned_x :
  729. begin
  730. secondpass(p^.left^.left);
  731. p^.location.loc:=LOC_FLAGS;
  732. if (p^.left^.left^.location.loc=LOC_REGISTER) or
  733. (p^.left^.left^.location.loc=LOC_CREGISTER) then
  734. begin
  735. exprasmlist^.concat(new(pai68k,op_reg(A_TST,S_L,
  736. p^.left^.left^.location.register)));
  737. ungetregister32(p^.left^.left^.location.register);
  738. end
  739. else
  740. begin
  741. exprasmlist^.concat(new(pai68k,op_ref(A_TST,S_L,
  742. newreference(p^.left^.left^.location.reference))));
  743. del_reference(p^.left^.left^.location.reference);
  744. end;
  745. p^.location.resflags:=F_NE;
  746. end;
  747. in_reset_typedfile,in_rewrite_typedfile :
  748. begin
  749. pushusedregisters(pushed,$ffff);
  750. exprasmlist^.concat(new(pai68k,op_const_reg(A_MOVE,S_L,
  751. pfiledef(p^.left^.resulttype)^.typed_as^.size,R_SPPUSH)));
  752. secondload(p^.left);
  753. emitpushreferenceaddr(p^.left^.location.reference);
  754. if p^.inlinenumber=in_reset_typedfile then
  755. emitcall('FPC_RESET_TYPED',true)
  756. else
  757. emitcall('FPC_REWRITE_TYPED',true);
  758. popusedregisters(pushed);
  759. end;
  760. in_write_x :
  761. handlereadwrite(false,false);
  762. in_writeln_x :
  763. handlereadwrite(false,true);
  764. in_read_x :
  765. handlereadwrite(true,false);
  766. in_readln_x :
  767. handlereadwrite(true,true);
  768. in_str_x_string :
  769. begin
  770. handle_str;
  771. maybe_loada5;
  772. end;
  773. in_include_x_y,
  774. in_exclude_x_y:
  775. begin
  776. { !!!!!!! }
  777. (* secondpass(p^.left^.left);
  778. if p^.left^.right^.left^.treetype=ordconstn then
  779. begin
  780. { calculate bit position }
  781. l:=1 shl (p^.left^.right^.left^.value mod 32);
  782. { determine operator }
  783. if p^.inlinenumber=in_include_x_y then
  784. asmop:=A_OR
  785. else
  786. begin
  787. asmop:=A_AND;
  788. l:=not(l);
  789. end;
  790. if (p^.left^.left^.location.loc=LOC_REFERENCE) then
  791. begin
  792. inc(p^.left^.left^.location.reference.offset,(p^.left^.right^.left^.value div 32)*4);
  793. exprasmlist^.concat(new(pai68k,op_const_ref(asmop,S_L,
  794. l,newreference(p^.left^.left^.location.reference))));
  795. del_reference(p^.left^.left^.location.reference);
  796. end
  797. else
  798. { LOC_CREGISTER }
  799. exprasmlist^.concat(new(pai68k,op_const_reg(asmop,S_L,
  800. l,p^.left^.left^.location.register)));
  801. end
  802. else
  803. begin
  804. { generate code for the element to set }
  805. ispushed:=maybe_push(p^.left^.right^.left^.registers32,p^.left^.left);
  806. secondpass(p^.left^.right^.left);
  807. if ispushed then
  808. restore(p^.left^.left);
  809. { determine asm operator }
  810. if p^.inlinenumber=in_include_x_y then
  811. asmop:=A_BTS
  812. else
  813. asmop:=A_BTR;
  814. if psetdef(p^.left^.resulttype)^.settype=smallset then
  815. begin
  816. if p^.left^.right^.left^.location.loc in [LOC_CREGISTER,LOC_REGISTER] then
  817. hregister:=p^.left^.right^.left^.location.register
  818. else
  819. begin
  820. hregister:=R_EDI;
  821. exprasmlist^.concat(new(pai386,op_ref_reg(A_MOV,S_L,
  822. newreference(p^.left^.right^.left^.location.reference),R_EDI)));
  823. end;
  824. if (p^.left^.left^.location.loc=LOC_REFERENCE) then
  825. exprasmlist^.concat(new(pai386,op_reg_ref(asmop,S_L,R_EDI,
  826. newreference(p^.left^.right^.left^.location.reference))))
  827. else
  828. exprasmlist^.concat(new(pai386,op_reg_reg(asmop,S_L,R_EDI,
  829. p^.left^.right^.left^.location.register)));
  830. end
  831. else
  832. begin
  833. end;
  834. end;
  835. *)
  836. end;
  837. else
  838. internalerror(9);
  839. end;
  840. pushedparasize:=oldpushedparasize;
  841. end;
  842. end.
  843. {
  844. $Log$
  845. Revision 1.8 1998-10-14 08:08:52 pierre
  846. * following Peters remark, removed all ifdef in
  847. the systems unit enums
  848. * last bugs of cg68k removed for sysamiga
  849. (sysamiga assembles with as68k !!)
  850. Revision 1.7 1998/10/13 16:50:08 pierre
  851. * undid some changes of Peter that made the compiler wrong
  852. for m68k (I had to reinsert some ifdefs)
  853. * removed several memory leaks under m68k
  854. * removed the meory leaks for assembler readers
  855. * cross compiling shoud work again better
  856. ( crosscompiling sysamiga works
  857. but as68k still complain about some code !)
  858. Revision 1.6 1998/10/06 20:48:58 peter
  859. * m68k compiler compiles again
  860. Revision 1.5 1998/09/20 12:26:39 peter
  861. * merged fixes
  862. Revision 1.4 1998/09/17 09:42:26 peter
  863. + pass_2 for cg386
  864. * Message() -> CGMessage() for pass_1/pass_2
  865. Revision 1.3 1998/09/14 10:43:59 peter
  866. * all internal RTL functions start with FPC_
  867. Revision 1.2.2.1 1998/09/20 12:20:10 peter
  868. * Fixed stack not on 4 byte boundary when doing a call
  869. Revision 1.2 1998/09/04 08:41:48 peter
  870. * updated some error CGMessages
  871. Revision 1.1 1998/09/01 09:07:09 peter
  872. * m68k fixes, splitted cg68k like cgi386
  873. }