cg68kinl.pas 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  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. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,
  563. newreference(p^.left^.location.reference),
  564. p^.location.register)));
  565. end;
  566. { in sizeof load size }
  567. if p^.inlinenumber=in_sizeof_x then
  568. begin
  569. new(r);
  570. reset_reference(r^);
  571. { load the address in A0 }
  572. { because now supposedly p^.location.register is an }
  573. { address. }
  574. emit_reg_reg(A_MOVE, S_L, p^.location.register, R_A0);
  575. r^.base:=R_A0;
  576. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,r,
  577. p^.location.register)));
  578. end;
  579. end;
  580. end;
  581. in_lo_long,
  582. in_hi_long : begin
  583. secondpass(p^.left);
  584. p^.location.loc:=LOC_REGISTER;
  585. if p^.left^.location.loc<>LOC_REGISTER then
  586. begin
  587. if p^.left^.location.loc=LOC_CREGISTER then
  588. begin
  589. p^.location.register:=getregister32;
  590. emit_reg_reg(A_MOVE,S_L,p^.left^.location.register,
  591. p^.location.register);
  592. end
  593. else
  594. begin
  595. del_reference(p^.left^.location.reference);
  596. p^.location.register:=getregister32;
  597. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,
  598. newreference(p^.left^.location.reference),
  599. p^.location.register)));
  600. end;
  601. end
  602. else p^.location.register:=p^.left^.location.register;
  603. if p^.inlinenumber=in_hi_long then
  604. begin
  605. exprasmlist^.concat(new(pai68k,op_const_reg(A_MOVEQ, S_L, 16, R_D1)));
  606. exprasmlist^.concat(new(pai68k,op_reg_reg(A_LSR,S_L,R_D1,p^.location.register)));
  607. end;
  608. p^.location.register:=p^.location.register;
  609. end;
  610. in_length_string :
  611. begin
  612. secondpass(p^.left);
  613. set_location(p^.location,p^.left^.location);
  614. { length in ansi strings is at offset -8 }
  615. {$ifdef UseAnsiString}
  616. if is_ansistring(p^.left^.resulttype) then
  617. dec(p^.location.reference.offset,8);
  618. {$endif UseAnsiString}
  619. end;
  620. in_pred_x,
  621. in_succ_x:
  622. begin
  623. secondpass(p^.left);
  624. if p^.inlinenumber=in_pred_x then
  625. asmop:=A_SUB
  626. else
  627. asmop:=A_ADD;
  628. case p^.resulttype^.size of
  629. 4 : opsize:=S_L;
  630. 2 : opsize:=S_W;
  631. 1 : opsize:=S_B;
  632. else
  633. internalerror(10080);
  634. end;
  635. p^.location.loc:=LOC_REGISTER;
  636. if p^.left^.location.loc<>LOC_REGISTER then
  637. begin
  638. p^.location.register:=getregister32;
  639. if p^.left^.location.loc=LOC_CREGISTER then
  640. emit_reg_reg(A_MOVE,opsize,p^.left^.location.register,
  641. p^.location.register)
  642. else
  643. if p^.left^.location.loc=LOC_FLAGS then
  644. exprasmlist^.concat(new(pai68k,op_reg(flag_2_set[p^.left^.location.resflags],S_NO,
  645. p^.location.register)))
  646. else
  647. begin
  648. del_reference(p^.left^.location.reference);
  649. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,opsize,newreference(p^.left^.location.reference),
  650. p^.location.register)));
  651. end;
  652. end
  653. else p^.location.register:=p^.left^.location.register;
  654. exprasmlist^.concat(new(pai68k,op_const_reg(asmop,opsize,1,
  655. p^.location.register)))
  656. { here we should insert bounds check ? }
  657. { and direct call to bounds will crash the program }
  658. { if we are at the limit }
  659. { we could also simply say that pred(first)=first and succ(last)=last }
  660. { could this be usefull I don't think so (PM)
  661. emitoverflowcheck;}
  662. end;
  663. in_dec_x,
  664. in_inc_x :
  665. begin
  666. { set defaults }
  667. addvalue:=1;
  668. addconstant:=true;
  669. { load first parameter, must be a reference }
  670. secondpass(p^.left^.left);
  671. case p^.left^.left^.resulttype^.deftype of
  672. orddef,
  673. enumdef : begin
  674. case p^.left^.left^.resulttype^.size of
  675. 1 : opsize:=S_B;
  676. 2 : opsize:=S_W;
  677. 4 : opsize:=S_L;
  678. end;
  679. end;
  680. pointerdef : begin
  681. opsize:=S_L;
  682. addvalue:=ppointerdef(p^.left^.left^.resulttype)^.definition^.savesize;
  683. end;
  684. else
  685. internalerror(10081);
  686. end;
  687. { second argument specified?, must be a s32bit in register }
  688. if assigned(p^.left^.right) then
  689. begin
  690. secondpass(p^.left^.right^.left);
  691. { when constant, just multiply the addvalue }
  692. if is_constintnode(p^.left^.right^.left) then
  693. addvalue:=addvalue*get_ordinal_value(p^.left^.right^.left)
  694. else
  695. begin
  696. case p^.left^.right^.left^.location.loc of
  697. LOC_REGISTER,
  698. LOC_CREGISTER : hregister:=p^.left^.right^.left^.location.register;
  699. LOC_MEM,
  700. LOC_REFERENCE : begin
  701. hregister:=getregister32;
  702. exprasmlist^.concat(new(pai68k,op_ref_reg(A_MOVE,S_L,
  703. newreference(p^.left^.right^.left^.location.reference),hregister)));
  704. end;
  705. else
  706. internalerror(10082);
  707. end;
  708. { insert multiply with addvalue if its >1 }
  709. if addvalue>1 then
  710. exprasmlist^.concat(new(pai68k,op_const_reg(A_MULS,opsize,
  711. addvalue,hregister)));
  712. addconstant:=false;
  713. end;
  714. end;
  715. { write the add instruction }
  716. if addconstant then
  717. begin
  718. if (addvalue > 0) and (addvalue < 9) then
  719. exprasmlist^.concat(new(pai68k,op_const_ref(addqconstsubop[p^.inlinenumber],opsize,
  720. addvalue,newreference(p^.left^.left^.location.reference))))
  721. else
  722. exprasmlist^.concat(new(pai68k,op_const_ref(addconstsubop[p^.inlinenumber],opsize,
  723. addvalue,newreference(p^.left^.left^.location.reference))));
  724. end
  725. else
  726. begin
  727. exprasmlist^.concat(new(pai68k,op_reg_ref(addsubop[p^.inlinenumber],opsize,
  728. hregister,newreference(p^.left^.left^.location.reference))));
  729. ungetregister32(hregister);
  730. end;
  731. emitoverflowcheck(p^.left^.left);
  732. end;
  733. in_assigned_x :
  734. begin
  735. secondpass(p^.left^.left);
  736. p^.location.loc:=LOC_FLAGS;
  737. if (p^.left^.left^.location.loc=LOC_REGISTER) or
  738. (p^.left^.left^.location.loc=LOC_CREGISTER) then
  739. begin
  740. exprasmlist^.concat(new(pai68k,op_reg(A_TST,S_L,
  741. p^.left^.left^.location.register)));
  742. ungetregister32(p^.left^.left^.location.register);
  743. end
  744. else
  745. begin
  746. exprasmlist^.concat(new(pai68k,op_ref(A_TST,S_L,
  747. newreference(p^.left^.left^.location.reference))));
  748. del_reference(p^.left^.left^.location.reference);
  749. end;
  750. p^.location.resflags:=F_NE;
  751. end;
  752. in_reset_typedfile,in_rewrite_typedfile :
  753. begin
  754. pushusedregisters(pushed,$ffff);
  755. exprasmlist^.concat(new(pai68k,op_const_reg(A_MOVE,S_L,
  756. pfiledef(p^.left^.resulttype)^.typed_as^.size,R_SPPUSH)));
  757. secondload(p^.left);
  758. emitpushreferenceaddr(exprasmlist,p^.left^.location.reference);
  759. if p^.inlinenumber=in_reset_typedfile then
  760. emitcall('FPC_RESET_TYPED',true)
  761. else
  762. emitcall('FPC_REWRITE_TYPED',true);
  763. popusedregisters(pushed);
  764. end;
  765. in_write_x :
  766. handlereadwrite(false,false);
  767. in_writeln_x :
  768. handlereadwrite(false,true);
  769. in_read_x :
  770. handlereadwrite(true,false);
  771. in_readln_x :
  772. handlereadwrite(true,true);
  773. in_str_x_string :
  774. begin
  775. handle_str;
  776. maybe_loada5;
  777. end;
  778. in_include_x_y,
  779. in_exclude_x_y:
  780. begin
  781. { !!!!!!! }
  782. (* secondpass(p^.left^.left);
  783. if p^.left^.right^.left^.treetype=ordconstn then
  784. begin
  785. { calculate bit position }
  786. l:=1 shl (p^.left^.right^.left^.value mod 32);
  787. { determine operator }
  788. if p^.inlinenumber=in_include_x_y then
  789. asmop:=A_OR
  790. else
  791. begin
  792. asmop:=A_AND;
  793. l:=not(l);
  794. end;
  795. if (p^.left^.left^.location.loc=LOC_REFERENCE) then
  796. begin
  797. inc(p^.left^.left^.location.reference.offset,(p^.left^.right^.left^.value div 32)*4);
  798. exprasmlist^.concat(new(pai68k,op_const_ref(asmop,S_L,
  799. l,newreference(p^.left^.left^.location.reference))));
  800. del_reference(p^.left^.left^.location.reference);
  801. end
  802. else
  803. { LOC_CREGISTER }
  804. exprasmlist^.concat(new(pai68k,op_const_reg(asmop,S_L,
  805. l,p^.left^.left^.location.register)));
  806. end
  807. else
  808. begin
  809. { generate code for the element to set }
  810. ispushed:=maybe_push(p^.left^.right^.left^.registers32,p^.left^.left);
  811. secondpass(p^.left^.right^.left);
  812. if ispushed then
  813. restore(p^.left^.left);
  814. { determine asm operator }
  815. if p^.inlinenumber=in_include_x_y then
  816. asmop:=A_BTS
  817. else
  818. asmop:=A_BTR;
  819. if psetdef(p^.left^.resulttype)^.settype=smallset then
  820. begin
  821. if p^.left^.right^.left^.location.loc in [LOC_CREGISTER,LOC_REGISTER] then
  822. hregister:=p^.left^.right^.left^.location.register
  823. else
  824. begin
  825. hregister:=R_EDI;
  826. exprasmlist^.concat(new(pai386,op_ref_reg(A_MOV,S_L,
  827. newreference(p^.left^.right^.left^.location.reference),R_EDI)));
  828. end;
  829. if (p^.left^.left^.location.loc=LOC_REFERENCE) then
  830. exprasmlist^.concat(new(pai386,op_reg_ref(asmop,S_L,R_EDI,
  831. newreference(p^.left^.right^.left^.location.reference))))
  832. else
  833. exprasmlist^.concat(new(pai386,op_reg_reg(asmop,S_L,R_EDI,
  834. p^.left^.right^.left^.location.register)));
  835. end
  836. else
  837. begin
  838. end;
  839. end;
  840. *)
  841. end;
  842. else
  843. internalerror(9);
  844. end;
  845. pushedparasize:=oldpushedparasize;
  846. end;
  847. end.
  848. {
  849. $Log$
  850. Revision 1.10 1998-10-14 16:53:04 pierre
  851. * bug in in_inc_x for constants out of range for A_ADDQ fixed
  852. Revision 1.9 1998/10/14 11:28:20 florian
  853. * emitpushreferenceaddress gets now the asmlist as parameter
  854. * m68k version compiles with -duseansistrings
  855. Revision 1.8 1998/10/14 08:08:52 pierre
  856. * following Peters remark, removed all ifdef in
  857. the systems unit enums
  858. * last bugs of cg68k removed for sysamiga
  859. (sysamiga assembles with as68k !!)
  860. Revision 1.7 1998/10/13 16:50:08 pierre
  861. * undid some changes of Peter that made the compiler wrong
  862. for m68k (I had to reinsert some ifdefs)
  863. * removed several memory leaks under m68k
  864. * removed the meory leaks for assembler readers
  865. * cross compiling shoud work again better
  866. ( crosscompiling sysamiga works
  867. but as68k still complain about some code !)
  868. Revision 1.6 1998/10/06 20:48:58 peter
  869. * m68k compiler compiles again
  870. Revision 1.5 1998/09/20 12:26:39 peter
  871. * merged fixes
  872. Revision 1.4 1998/09/17 09:42:26 peter
  873. + pass_2 for cg386
  874. * Message() -> CGMessage() for pass_1/pass_2
  875. Revision 1.3 1998/09/14 10:43:59 peter
  876. * all internal RTL functions start with FPC_
  877. Revision 1.2.2.1 1998/09/20 12:20:10 peter
  878. * Fixed stack not on 4 byte boundary when doing a call
  879. Revision 1.2 1998/09/04 08:41:48 peter
  880. * updated some error CGMessages
  881. Revision 1.1 1998/09/01 09:07:09 peter
  882. * m68k fixes, splitted cg68k like cgi386
  883. }