ncginl.pas 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844
  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. { 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. tempreg1, tempreg2: tregister;
  568. begin
  569. secondpass(left);
  570. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  571. location:=left.location;
  572. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,left.resultdef);
  573. tempreg1:=hlcg.getintregister(current_asmdata.CurrAsmList,left.resultdef);
  574. tempreg2:=hlcg.getintregister(current_asmdata.CurrAsmList,left.resultdef);
  575. hlcg.a_op_const_reg_reg(current_asmdata.CurrAsmList,OP_SAR,left.resultdef,left.resultdef.size*8-1,left.location.register,tempreg1);
  576. hlcg.a_op_reg_reg_reg(current_asmdata.CurrAsmList,OP_XOR,left.resultdef,left.location.register,tempreg1,tempreg2);
  577. hlcg.a_op_reg_reg_reg(current_asmdata.CurrAsmlist,OP_SUB,left.resultdef,tempreg1,tempreg2,location.register);
  578. end;
  579. {*****************************************************************************
  580. ASSIGNED GENERIC HANDLING
  581. *****************************************************************************}
  582. procedure tcginlinenode.second_assigned;
  583. begin
  584. secondpass(tcallparanode(left).left);
  585. hlcg.a_cmp_const_loc_label(current_asmdata.CurrAsmList,left.resultdef,OC_NE,0,tcallparanode(left).left.location,current_procinfo.CurrTrueLabel);
  586. hlcg.a_jmp_always(current_asmdata.CurrAsmList,current_procinfo.CurrFalseLabel);
  587. location_reset(location,LOC_JUMP,OS_NO);
  588. end;
  589. procedure Tcginlinenode.second_get_frame;
  590. begin
  591. {$if defined(x86) or defined(arm)}
  592. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  593. begin
  594. location_reset(location,LOC_CONSTANT,OS_ADDR);
  595. location.value:=0;
  596. end
  597. else
  598. {$endif defined(x86) or defined(arm)}
  599. begin
  600. location_reset(location,LOC_CREGISTER,OS_ADDR);
  601. location.register:=current_procinfo.framepointer;
  602. end;
  603. end;
  604. procedure Tcginlinenode.second_get_caller_frame;
  605. var
  606. frame_reg:Tregister;
  607. use_frame_pointer:boolean;
  608. begin
  609. if left<>nil then
  610. begin
  611. secondpass(left);
  612. if left.location.loc=LOC_CONSTANT then
  613. use_frame_pointer:=true
  614. else
  615. begin
  616. location_force_reg(current_asmdata.currasmlist,left.location,OS_ADDR,false);
  617. frame_reg:=left.location.register;
  618. use_frame_pointer:=false;
  619. end
  620. end
  621. else
  622. begin
  623. use_frame_pointer:=current_procinfo.framepointer=NR_STACK_POINTER_REG;
  624. frame_reg:=current_procinfo.framepointer;
  625. end;
  626. if use_frame_pointer then
  627. begin
  628. location_reset(location,LOC_CREGISTER,OS_ADDR);
  629. location.register:=NR_FRAME_POINTER_REG;
  630. end
  631. else
  632. begin
  633. location_reset_ref(location,LOC_REFERENCE,OS_ADDR,sizeof(pint));
  634. location.reference.base:=frame_reg;
  635. end;
  636. end;
  637. procedure Tcginlinenode.second_get_caller_addr;
  638. var
  639. frame_ref:Treference;
  640. begin
  641. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  642. begin
  643. location_reset(location,LOC_REGISTER,OS_ADDR);
  644. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  645. reference_reset_base(frame_ref,NR_STACK_POINTER_REG,{current_procinfo.calc_stackframe_size}tg.lasttemp,sizeof(pint));
  646. cg.a_load_ref_reg(current_asmdata.currasmlist,OS_ADDR,OS_ADDR,frame_ref,location.register);
  647. end
  648. else
  649. begin
  650. location_reset(location,LOC_REGISTER,OS_ADDR);
  651. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  652. reference_reset_base(frame_ref,current_procinfo.framepointer,sizeof(pint),sizeof(pint));
  653. cg.a_load_ref_reg(current_asmdata.currasmlist,OS_ADDR,OS_ADDR,frame_ref,location.register);
  654. end;
  655. end;
  656. procedure tcginlinenode.second_rox;
  657. var
  658. op : topcg;
  659. {hcountreg : tregister;}
  660. op1,op2 : tnode;
  661. begin
  662. { one or two parameters? }
  663. if (left.nodetype=callparan) and
  664. assigned(tcallparanode(left).right) then
  665. begin
  666. op1:=tcallparanode(tcallparanode(left).right).left;
  667. op2:=tcallparanode(left).left;
  668. end
  669. else
  670. op1:=left;
  671. secondpass(op1);
  672. { load left operator in a register }
  673. location_copy(location,op1.location);
  674. case inlinenumber of
  675. in_ror_x,
  676. in_ror_x_y:
  677. op:=OP_ROR;
  678. in_rol_x,
  679. in_rol_x_y:
  680. op:=OP_ROL;
  681. end;
  682. location_force_reg(current_asmdata.CurrAsmList,location,location.size,false);
  683. if (left.nodetype=callparan) and
  684. assigned(tcallparanode(left).right) then
  685. begin
  686. secondpass(op2);
  687. { rotating by a constant directly coded: }
  688. if op2.nodetype=ordconstn then
  689. cg.a_op_const_reg(current_asmdata.CurrAsmList,op,location.size,
  690. tordconstnode(op2).value.uvalue and (resultdef.size*8-1),location.register)
  691. else
  692. begin
  693. location_force_reg(current_asmdata.CurrAsmList,op2.location,location.size,false);
  694. { do modulo 2 operation }
  695. cg.a_op_reg_reg(current_asmdata.CurrAsmList,op,location.size,op2.location.register,location.register);
  696. end;
  697. end
  698. else
  699. cg.a_op_const_reg(current_asmdata.CurrAsmList,op,location.size,1,location.register);
  700. end;
  701. procedure tcginlinenode.second_sar;
  702. var
  703. {hcountreg : tregister;}
  704. op1,op2 : tnode;
  705. begin
  706. if (left.nodetype=callparan) and
  707. assigned(tcallparanode(left).right) then
  708. begin
  709. op1:=tcallparanode(tcallparanode(left).right).left;
  710. op2:=tcallparanode(left).left;
  711. end
  712. else
  713. begin
  714. op1:=left;
  715. op2:=nil;
  716. end;
  717. secondpass(op1);
  718. { load left operator in a register }
  719. location_copy(location,op1.location);
  720. hlcg.location_force_reg(current_asmdata.CurrAsmList,location,op1.resultdef,resultdef,false);
  721. if not(assigned(op2)) then
  722. hlcg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SAR,resultdef,1,location.register)
  723. else
  724. begin
  725. secondpass(op2);
  726. { shifting by a constant directly coded: }
  727. if op2.nodetype=ordconstn then
  728. hlcg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SAR,resultdef,
  729. tordconstnode(op2).value.uvalue and (resultdef.size*8-1),location.register)
  730. else
  731. begin
  732. hlcg.location_force_reg(current_asmdata.CurrAsmList,op2.location,op2.resultdef,resultdef,false);
  733. hlcg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_SAR,resultdef,op2.location.register,location.register);
  734. end;
  735. end;
  736. end;
  737. procedure tcginlinenode.second_BsfBsr;
  738. var
  739. reverse: boolean;
  740. opsize: tcgsize;
  741. begin
  742. reverse:=(inlinenumber = in_bsr_x);
  743. secondpass(left);
  744. opsize:=tcgsize2unsigned[left.location.size];
  745. if opsize < OS_32 then
  746. opsize:=OS_32;
  747. if (left.location.loc <> LOC_REGISTER) or
  748. (left.location.size <> opsize) then
  749. location_force_reg(current_asmdata.CurrAsmList,left.location,opsize,true);
  750. location_reset(location,LOC_REGISTER,opsize);
  751. location.register := cg.getintregister(current_asmdata.CurrAsmList,opsize);
  752. cg.a_bit_scan_reg_reg(current_asmdata.CurrAsmList,reverse,opsize,left.location.register,location.register);
  753. end;
  754. procedure tcginlinenode.second_new;
  755. begin
  756. internalerror(2011012202);
  757. end;
  758. begin
  759. cinlinenode:=tcginlinenode;
  760. end.