ncginl.pas 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl and Carl Eric Codere
  3. Generate generic inline nodes
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit ncginl;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ninl;
  22. type
  23. tcginlinenode = class(tinlinenode)
  24. procedure pass_generate_code;override;
  25. procedure second_sizeoftypeof;virtual;
  26. procedure second_length;virtual;
  27. procedure second_predsucc;virtual;
  28. procedure second_incdec;virtual;
  29. procedure second_typeinfo;virtual;
  30. procedure second_includeexclude;virtual;
  31. procedure second_pi; virtual;
  32. procedure second_arctan_real; virtual;
  33. procedure second_abs_real; virtual;
  34. procedure second_sqr_real; virtual;
  35. procedure second_sqrt_real; virtual;
  36. procedure second_ln_real; virtual;
  37. procedure second_cos_real; virtual;
  38. procedure second_sin_real; virtual;
  39. procedure second_assigned; virtual;
  40. procedure second_get_frame;virtual;
  41. procedure second_get_caller_frame;virtual;
  42. procedure second_get_caller_addr;virtual;
  43. procedure second_prefetch; virtual;
  44. procedure second_round_real; virtual;
  45. procedure second_trunc_real; virtual;
  46. procedure second_abs_long; virtual;
  47. procedure second_rox_sar; virtual;
  48. procedure second_bsfbsr; virtual;
  49. procedure second_new; virtual;
  50. procedure second_setlength; virtual; abstract;
  51. procedure second_box; virtual; abstract;
  52. procedure second_popcnt; virtual;
  53. procedure second_seg; virtual; abstract;
  54. end;
  55. implementation
  56. uses
  57. globtype,systems,constexp,
  58. cutils,verbose,globals,
  59. symconst,symdef,defutil,symsym,
  60. aasmbase,aasmtai,aasmdata,aasmcpu,parabase,
  61. cgbase,pass_1,pass_2,
  62. cpuinfo,cpubase,paramgr,procinfo,
  63. nbas,ncon,ncal,ncnv,nld,ncgrtti,
  64. tgobj,ncgutil,
  65. cgutils,cgobj,hlcgobj
  66. {$ifndef cpu64bitalu}
  67. ,cg64f32
  68. {$endif not cpu64bitalu}
  69. ;
  70. {*****************************************************************************
  71. TCGINLINENODE
  72. *****************************************************************************}
  73. procedure tcginlinenode.pass_generate_code;
  74. begin
  75. location_reset(location,LOC_VOID,OS_NO);
  76. case inlinenumber of
  77. in_sizeof_x,
  78. in_typeof_x :
  79. second_SizeofTypeOf;
  80. in_length_x :
  81. second_Length;
  82. in_pred_x,
  83. in_succ_x:
  84. second_PredSucc;
  85. in_dec_x,
  86. in_inc_x :
  87. second_IncDec;
  88. in_typeinfo_x:
  89. second_TypeInfo;
  90. in_include_x_y,
  91. in_exclude_x_y:
  92. second_IncludeExclude;
  93. in_pi_real:
  94. second_pi;
  95. in_sin_real:
  96. second_sin_real;
  97. in_arctan_real:
  98. second_arctan_real;
  99. in_abs_real:
  100. second_abs_real;
  101. in_abs_long:
  102. second_abs_long;
  103. in_round_real:
  104. second_round_real;
  105. in_trunc_real:
  106. second_trunc_real;
  107. in_sqr_real:
  108. second_sqr_real;
  109. in_sqrt_real:
  110. second_sqrt_real;
  111. in_ln_real:
  112. second_ln_real;
  113. in_cos_real:
  114. second_cos_real;
  115. in_prefetch_var:
  116. second_prefetch;
  117. in_assigned_x:
  118. second_assigned;
  119. in_get_frame:
  120. second_get_frame;
  121. in_get_caller_frame:
  122. second_get_caller_frame;
  123. in_get_caller_addr:
  124. second_get_caller_addr;
  125. in_unaligned_x:
  126. begin
  127. secondpass(tcallparanode(left).left);
  128. location:=tcallparanode(left).left.location;
  129. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  130. location.reference.alignment:=1;
  131. end;
  132. in_aligned_x:
  133. begin
  134. secondpass(tcallparanode(left).left);
  135. location:=tcallparanode(left).left.location;
  136. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  137. location.reference.alignment:=0;
  138. end;
  139. {$ifdef SUPPORT_MMX}
  140. in_mmx_pcmpeqb..in_mmx_pcmpgtw:
  141. begin
  142. location_reset(location,LOC_MMXREGISTER,OS_NO);
  143. if left.location.loc=LOC_REGISTER then
  144. begin
  145. {!!!!!!!}
  146. end
  147. else if tcallparanode(left).left.location.loc=LOC_REGISTER then
  148. begin
  149. {!!!!!!!}
  150. end
  151. else
  152. begin
  153. {!!!!!!!}
  154. end;
  155. end;
  156. {$endif SUPPORT_MMX}
  157. in_rol_x,
  158. in_rol_x_y,
  159. in_ror_x,
  160. in_ror_x_y,
  161. in_sar_x,
  162. in_sar_x_y:
  163. second_rox_sar;
  164. in_bsf_x,
  165. in_bsr_x:
  166. second_BsfBsr;
  167. in_new_x:
  168. second_new;
  169. in_setlength_x:
  170. second_setlength;
  171. in_box_x:
  172. second_box;
  173. in_popcnt_x:
  174. second_popcnt;
  175. in_seg_x:
  176. second_seg;
  177. else internalerror(9);
  178. end;
  179. end;
  180. {*****************************************************************************
  181. SIZEOF / TYPEOF GENERIC HANDLING
  182. *****************************************************************************}
  183. { second_handle_ the sizeof and typeof routines }
  184. procedure tcginlinenode.second_SizeOfTypeOf;
  185. var
  186. href,
  187. hrefvmt : treference;
  188. hregister : tregister;
  189. begin
  190. if inlinenumber=in_sizeof_x then
  191. location_reset(location,LOC_REGISTER,def_cgsize(resultdef))
  192. else
  193. location_reset(location,LOC_REGISTER,OS_ADDR);
  194. { for both cases load vmt }
  195. if left.nodetype=typen then
  196. begin
  197. hregister:=cg.getaddressregister(current_asmdata.CurrAsmList);
  198. reference_reset_symbol(href,current_asmdata.RefAsmSymbol(tobjectdef(left.resultdef).vmt_mangledname,AT_DATA),0,sizeof(pint));
  199. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,href,hregister);
  200. end
  201. else
  202. begin
  203. secondpass(left);
  204. hregister:=cg.getaddressregister(current_asmdata.CurrAsmList);
  205. { handle self inside a method of a class }
  206. case left.location.loc of
  207. LOC_CREGISTER,
  208. LOC_REGISTER :
  209. begin
  210. if (left.resultdef.typ=classrefdef) or
  211. (po_staticmethod in current_procinfo.procdef.procoptions) then
  212. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,left.location.register,hregister)
  213. else
  214. begin
  215. { load VMT pointer }
  216. reference_reset_base(hrefvmt,left.location.register,tobjectdef(left.resultdef).vmt_offset,sizeof(pint));
  217. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,hrefvmt,hregister);
  218. end
  219. end;
  220. LOC_REFERENCE,
  221. LOC_CREFERENCE :
  222. begin
  223. if is_class(left.resultdef) then
  224. begin
  225. { deref class }
  226. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,left.location.reference,hregister);
  227. hlcg.g_maybe_testself(current_asmdata.CurrAsmList,left.resultdef,hregister);
  228. { load VMT pointer }
  229. reference_reset_base(hrefvmt,hregister,tobjectdef(left.resultdef).vmt_offset,sizeof(pint));
  230. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,hrefvmt,hregister);
  231. end
  232. else
  233. begin
  234. { load VMT pointer, but not for classrefdefs }
  235. if (left.resultdef.typ=objectdef) then
  236. begin
  237. inc(left.location.reference.offset,tobjectdef(left.resultdef).vmt_offset);
  238. left.location.reference.alignment:=newalignment(left.location.reference.alignment,tobjectdef(left.resultdef).vmt_offset);
  239. end;
  240. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,left.location.reference,hregister);
  241. end;
  242. end;
  243. else
  244. internalerror(200301301);
  245. end;
  246. end;
  247. { in sizeof load size }
  248. if inlinenumber=in_sizeof_x then
  249. begin
  250. reference_reset_base(href,hregister,0,sizeof(pint));
  251. hregister:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  252. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_INT,OS_INT,href,hregister);
  253. end;
  254. location.register:=hregister;
  255. end;
  256. {*****************************************************************************
  257. LENGTH GENERIC HANDLING
  258. *****************************************************************************}
  259. procedure tcginlinenode.second_Length;
  260. var
  261. lengthlab : tasmlabel;
  262. hregister : tregister;
  263. href : treference;
  264. begin
  265. secondpass(left);
  266. if is_shortstring(left.resultdef) then
  267. begin
  268. location_copy(location,left.location);
  269. location.size:=OS_8;
  270. end
  271. else
  272. begin
  273. { length in ansi/wide strings and high in dynamic arrays is at offset -sizeof(pint) }
  274. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,false);
  275. current_asmdata.getjumplabel(lengthlab);
  276. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_ADDR,OC_EQ,0,left.location.register,lengthlab);
  277. if is_widestring(left.resultdef) and (tf_winlikewidestring in target_info.flags) then
  278. begin
  279. reference_reset_base(href,left.location.register,-sizeof(dword),sizeof(dword));
  280. hregister:=cg.makeregsize(current_asmdata.CurrAsmList,left.location.register,OS_INT);
  281. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_32,OS_INT,href,hregister);
  282. end
  283. else
  284. begin
  285. reference_reset_base(href,left.location.register,-sizeof(pint),sizeof(pint));
  286. hregister:=cg.makeregsize(current_asmdata.CurrAsmList,left.location.register,OS_INT);
  287. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_INT,OS_INT,href,hregister);
  288. end;
  289. if is_widestring(left.resultdef) then
  290. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SHR,OS_INT,1,hregister);
  291. { Dynamic arrays do not have their length attached but their maximum index }
  292. if is_dynamic_array(left.resultdef) then
  293. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_ADD,OS_INT,1,hregister);
  294. cg.a_label(current_asmdata.CurrAsmList,lengthlab);
  295. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  296. location.register:=hregister;
  297. end;
  298. end;
  299. {*****************************************************************************
  300. PRED/SUCC GENERIC HANDLING
  301. *****************************************************************************}
  302. procedure tcginlinenode.second_PredSucc;
  303. var
  304. cgop : topcg;
  305. begin
  306. secondpass(left);
  307. if inlinenumber=in_pred_x then
  308. cgop:=OP_SUB
  309. else
  310. cgop:=OP_ADD;
  311. { we need a value in a register }
  312. location_copy(location,left.location);
  313. hlcg.location_force_reg(current_asmdata.CurrAsmList,location,resultdef,resultdef,false);
  314. {$ifndef cpu64bitalu}
  315. if def_cgsize(resultdef) in [OS_64,OS_S64] then
  316. cg64.a_op64_const_reg(current_asmdata.CurrAsmList,cgop,def_cgsize(resultdef),1,location.register64)
  317. else
  318. {$endif not cpu64bitalu}
  319. hlcg.a_op_const_reg(current_asmdata.CurrAsmList,cgop,resultdef,1,location.register);
  320. end;
  321. {*****************************************************************************
  322. INC/DEC GENERIC HANDLING
  323. *****************************************************************************}
  324. procedure tcginlinenode.second_IncDec;
  325. const
  326. addsubop:array[in_inc_x..in_dec_x] of TOpCG=(OP_ADD,OP_SUB);
  327. var
  328. addvalue : TConstExprInt;
  329. addconstant : boolean;
  330. {$ifndef cpu64bitalu}
  331. hregisterhi,
  332. {$endif not cpu64bitalu}
  333. hregister : tregister;
  334. begin
  335. { set defaults }
  336. addconstant:=true;
  337. hregister:=NR_NO;
  338. {$ifndef cpu64bitalu}
  339. hregisterhi:=NR_NO;
  340. {$endif not cpu64bitalu}
  341. { first secondpass second argument, because if the first arg }
  342. { is used in that expression then SSL may move it to another }
  343. { register }
  344. if assigned(tcallparanode(left).right) then
  345. secondpass(tcallparanode(tcallparanode(left).right).left);
  346. { load first parameter, must be a reference }
  347. secondpass(tcallparanode(left).left);
  348. { get addvalue }
  349. case tcallparanode(left).left.resultdef.typ of
  350. orddef,
  351. enumdef :
  352. addvalue:=1;
  353. pointerdef :
  354. begin
  355. if is_void(tpointerdef(tcallparanode(left).left.resultdef).pointeddef) then
  356. addvalue:=1
  357. else
  358. addvalue:=tpointerdef(tcallparanode(left).left.resultdef).pointeddef.size;
  359. end;
  360. else
  361. internalerror(10081);
  362. end;
  363. { second_ argument specified?, must be a s32bit in register }
  364. if assigned(tcallparanode(left).right) then
  365. begin
  366. { when constant, just multiply the addvalue }
  367. if is_constintnode(tcallparanode(tcallparanode(left).right).left) then
  368. addvalue:=addvalue*get_ordinal_value(tcallparanode(tcallparanode(left).right).left)
  369. else if is_constpointernode(tcallparanode(tcallparanode(left).right).left) then
  370. addvalue:=addvalue*tpointerconstnode(tcallparanode(tcallparanode(left).right).left).value
  371. else
  372. begin
  373. hlcg.location_force_reg(current_asmdata.CurrAsmList,tcallparanode(tcallparanode(left).right).left.location,tcallparanode(tcallparanode(left).right).left.resultdef,left.resultdef,addvalue<=1);
  374. hregister:=tcallparanode(tcallparanode(left).right).left.location.register;
  375. {$ifndef cpu64bitalu}
  376. hregisterhi:=tcallparanode(tcallparanode(left).right).left.location.register64.reghi;
  377. {$endif not cpu64bitalu}
  378. { insert multiply with addvalue if its >1 }
  379. if addvalue>1 then
  380. hlcg.a_op_const_reg(current_asmdata.CurrAsmList,OP_IMUL,left.resultdef,addvalue.svalue,hregister);
  381. addconstant:=false;
  382. end;
  383. end;
  384. { write the add instruction }
  385. if addconstant then
  386. begin
  387. {$ifndef cpu64bitalu}
  388. if def_cgsize(left.resultdef) in [OS_64,OS_S64] then
  389. cg64.a_op64_const_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],def_cgsize(left.resultdef),addvalue,tcallparanode(left).left.location)
  390. else
  391. {$endif not cpu64bitalu}
  392. hlcg.a_op_const_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],left.resultdef,
  393. aint(addvalue.svalue),tcallparanode(left).left.location);
  394. end
  395. else
  396. begin
  397. {$ifndef cpu64bitalu}
  398. if def_cgsize(left.resultdef) in [OS_64,OS_S64] then
  399. cg64.a_op64_reg_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],def_cgsize(left.resultdef),
  400. joinreg64(hregister,hregisterhi),tcallparanode(left).left.location)
  401. else
  402. {$endif not cpu64bitalu}
  403. hlcg.a_op_reg_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],left.resultdef,
  404. hregister,tcallparanode(left).left.location);
  405. end;
  406. { no overflow checking for pointers (see ninl), and range checking }
  407. { is not applicable for them }
  408. if (tcallparanode(left).left.resultdef.typ <> pointerdef) then
  409. begin
  410. { things which can overflow must NOT pass via here, but have to be }
  411. { handled via a regular add node (conversion in tinlinenode.pass_1) }
  412. { Or someone has to rewrite the above to use a_op_const_reg_reg_ov }
  413. { and friends in case of overflow checking, and ask everyone to }
  414. { implement these methods since they don't exist for all cpus (JM) }
  415. { Similarly, range checking also has to be handled separately, }
  416. { see mantis #14841 (JM) }
  417. if ([cs_check_overflow,cs_check_range] * current_settings.localswitches <> []) then
  418. internalerror(2006111010);
  419. // cg.g_overflowcheck(current_asmdata.CurrAsmList,tcallparanode(left).left.location,tcallparanode(left).resultdef);
  420. // cg.g_rangecheck(current_asmdata.CurrAsmList,tcallparanode(left).left.location,tcallparanode(left).left.resultdef,
  421. // tcallparanode(left).left.resultdef);
  422. end;
  423. end;
  424. {*****************************************************************************
  425. TYPEINFO GENERIC HANDLING
  426. *****************************************************************************}
  427. procedure tcginlinenode.second_typeinfo;
  428. begin
  429. internalerror(2013060301);
  430. end;
  431. {*****************************************************************************
  432. INCLUDE/EXCLUDE GENERIC HANDLING
  433. *****************************************************************************}
  434. procedure tcginlinenode.second_IncludeExclude;
  435. var
  436. setpara, elepara: tnode;
  437. begin
  438. { the set }
  439. secondpass(tcallparanode(left).left);
  440. { the element to set }
  441. secondpass(tcallparanode(tcallparanode(left).right).left);
  442. setpara:=tcallparanode(left).left;
  443. elepara:=tcallparanode(tcallparanode(left).right).left;
  444. if elepara.location.loc=LOC_CONSTANT then
  445. begin
  446. hlcg.a_bit_set_const_loc(current_asmdata.CurrAsmList,(inlinenumber=in_include_x_y),
  447. setpara.resultdef,elepara.location.value-tsetdef(setpara.resultdef).setbase,setpara.location);
  448. end
  449. else
  450. begin
  451. hlcg.location_force_reg(current_asmdata.CurrAsmList,elepara.location,elepara.resultdef,u32inttype,true);
  452. register_maybe_adjust_setbase(current_asmdata.CurrAsmList,elepara.location,tsetdef(setpara.resultdef).setbase);
  453. hlcg.a_bit_set_reg_loc(current_asmdata.CurrAsmList,(inlinenumber=in_include_x_y),
  454. u32inttype,setpara.resultdef,elepara.location.register,setpara.location);
  455. end;
  456. end;
  457. {*****************************************************************************
  458. FLOAT GENERIC HANDLING
  459. *****************************************************************************}
  460. {
  461. These routines all call internal RTL routines, so if they are
  462. called here, they give an internal error
  463. }
  464. procedure tcginlinenode.second_pi;
  465. begin
  466. internalerror(20020718);
  467. end;
  468. procedure tcginlinenode.second_arctan_real;
  469. begin
  470. internalerror(20020718);
  471. end;
  472. procedure tcginlinenode.second_abs_real;
  473. begin
  474. internalerror(20020718);
  475. end;
  476. procedure tcginlinenode.second_round_real;
  477. begin
  478. internalerror(20020718);
  479. end;
  480. procedure tcginlinenode.second_trunc_real;
  481. begin
  482. internalerror(20020718);
  483. end;
  484. procedure tcginlinenode.second_sqr_real;
  485. begin
  486. internalerror(20020718);
  487. end;
  488. procedure tcginlinenode.second_sqrt_real;
  489. begin
  490. internalerror(20020718);
  491. end;
  492. procedure tcginlinenode.second_ln_real;
  493. begin
  494. internalerror(20020718);
  495. end;
  496. procedure tcginlinenode.second_cos_real;
  497. begin
  498. internalerror(20020718);
  499. end;
  500. procedure tcginlinenode.second_sin_real;
  501. begin
  502. internalerror(20020718);
  503. end;
  504. procedure tcginlinenode.second_prefetch;
  505. begin
  506. end;
  507. procedure tcginlinenode.second_abs_long;
  508. var
  509. tempreg1, tempreg2: tregister;
  510. begin
  511. secondpass(left);
  512. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  513. location:=left.location;
  514. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,left.resultdef);
  515. tempreg1:=hlcg.getintregister(current_asmdata.CurrAsmList,left.resultdef);
  516. tempreg2:=hlcg.getintregister(current_asmdata.CurrAsmList,left.resultdef);
  517. hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SAR,left.resultdef,left.resultdef.size*8-1,left.location.register,tempreg1);
  518. hlcg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_XOR,left.resultdef,left.location.register,tempreg1,tempreg2);
  519. hlcg.a_op_reg_reg_reg(current_asmdata.CurrAsmlist,OP_SUB,left.resultdef,tempreg1,tempreg2,location.register);
  520. end;
  521. {*****************************************************************************
  522. ASSIGNED GENERIC HANDLING
  523. *****************************************************************************}
  524. procedure tcginlinenode.second_assigned;
  525. begin
  526. internalerror(2013091602);
  527. end;
  528. procedure Tcginlinenode.second_get_frame;
  529. begin
  530. {$if defined(x86) or defined(arm)}
  531. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  532. begin
  533. location_reset(location,LOC_CONSTANT,OS_ADDR);
  534. location.value:=0;
  535. end
  536. else
  537. {$endif defined(x86) or defined(arm)}
  538. begin
  539. location_reset(location,LOC_CREGISTER,OS_ADDR);
  540. location.register:=current_procinfo.framepointer;
  541. end;
  542. end;
  543. procedure Tcginlinenode.second_get_caller_frame;
  544. var
  545. frame_reg:Tregister;
  546. use_frame_pointer:boolean;
  547. begin
  548. frame_reg:=NR_NO;
  549. if left<>nil then
  550. begin
  551. secondpass(left);
  552. if left.location.loc=LOC_CONSTANT then
  553. use_frame_pointer:=true
  554. else
  555. begin
  556. hlcg.location_force_reg(current_asmdata.currasmlist,left.location,left.resultdef,voidpointertype,false);
  557. frame_reg:=left.location.register;
  558. use_frame_pointer:=false;
  559. end
  560. end
  561. else
  562. begin
  563. use_frame_pointer:=current_procinfo.framepointer=NR_STACK_POINTER_REG;
  564. frame_reg:=current_procinfo.framepointer;
  565. end;
  566. if use_frame_pointer then
  567. begin
  568. location_reset(location,LOC_CREGISTER,OS_ADDR);
  569. location.register:=NR_FRAME_POINTER_REG;
  570. end
  571. else
  572. begin
  573. location_reset_ref(location,LOC_REFERENCE,OS_ADDR,sizeof(pint));
  574. location.reference.base:=frame_reg;
  575. end;
  576. end;
  577. procedure Tcginlinenode.second_get_caller_addr;
  578. var
  579. frame_ref:Treference;
  580. begin
  581. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  582. begin
  583. location_reset(location,LOC_REGISTER,OS_ADDR);
  584. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  585. reference_reset_base(frame_ref,NR_STACK_POINTER_REG,{current_procinfo.calc_stackframe_size}tg.lasttemp,sizeof(pint));
  586. cg.a_load_ref_reg(current_asmdata.currasmlist,OS_ADDR,OS_ADDR,frame_ref,location.register);
  587. end
  588. else
  589. begin
  590. location_reset(location,LOC_REGISTER,OS_ADDR);
  591. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  592. reference_reset_base(frame_ref,current_procinfo.framepointer,sizeof(pint),sizeof(pint));
  593. cg.a_load_ref_reg(current_asmdata.currasmlist,OS_ADDR,OS_ADDR,frame_ref,location.register);
  594. end;
  595. end;
  596. procedure tcginlinenode.second_rox_sar;
  597. var
  598. op : topcg;
  599. op1,op2 : tnode;
  600. begin
  601. { one or two parameters? }
  602. if (left.nodetype=callparan) and
  603. assigned(tcallparanode(left).right) then
  604. begin
  605. op1:=tcallparanode(tcallparanode(left).right).left;
  606. op2:=tcallparanode(left).left;
  607. secondpass(op2);
  608. end
  609. else
  610. begin
  611. op1:=left;
  612. op2:=nil;
  613. end;
  614. secondpass(op1);
  615. case inlinenumber of
  616. in_ror_x,
  617. in_ror_x_y:
  618. op:=OP_ROR;
  619. in_rol_x,
  620. in_rol_x_y:
  621. op:=OP_ROL;
  622. in_sar_x,
  623. in_sar_x_y:
  624. op:=OP_SAR;
  625. else
  626. internalerror(2013120110);
  627. end;
  628. hlcg.location_force_reg(current_asmdata.CurrAsmList,op1.location,op1.resultdef,resultdef,true);
  629. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  630. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,resultdef);
  631. if assigned(op2) then
  632. begin
  633. { rotating by a constant directly coded: }
  634. if op2.nodetype=ordconstn then
  635. hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList,op,resultdef,
  636. tordconstnode(op2).value.uvalue and (resultdef.size*8-1),
  637. op1.location.register, location.register)
  638. else
  639. begin
  640. hlcg.location_force_reg(current_asmdata.CurrAsmList,op2.location,
  641. op2.resultdef,resultdef,true);
  642. hlcg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,op,resultdef,
  643. op2.location.register,op1.location.register,
  644. location.register);
  645. end;
  646. end
  647. else
  648. hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList,op,resultdef,1,
  649. op1.location.register,location.register);
  650. end;
  651. procedure tcginlinenode.second_BsfBsr;
  652. var
  653. reverse: boolean;
  654. opsize: tcgsize;
  655. begin
  656. reverse:=(inlinenumber = in_bsr_x);
  657. secondpass(left);
  658. opsize:=tcgsize2unsigned[left.location.size];
  659. if opsize < OS_32 then
  660. opsize:=OS_32;
  661. if (left.location.loc <> LOC_REGISTER) or
  662. (left.location.size <> opsize) then
  663. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,cgsize_orddef(opsize),true);
  664. location_reset(location,LOC_REGISTER,opsize);
  665. location.register := cg.getintregister(current_asmdata.CurrAsmList,opsize);
  666. cg.a_bit_scan_reg_reg(current_asmdata.CurrAsmList,reverse,opsize,left.location.register,location.register);
  667. end;
  668. procedure tcginlinenode.second_new;
  669. begin
  670. internalerror(2011012202);
  671. end;
  672. procedure tcginlinenode.second_popcnt;
  673. begin
  674. internalerror(2012082601);
  675. end;
  676. begin
  677. cinlinenode:=tcginlinenode;
  678. end. s