cg68kinl.pas 41 KB

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