ncginl.pas 31 KB

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