cg68kinl.pas 41 KB

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