cg68kinl.pas 38 KB

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