cg68kinl.pas 40 KB

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