cg68kinl.pas 38 KB

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