cg68kinl.pas 41 KB

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