ncginl.pas 32 KB

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