ncginl.pas 32 KB

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