ncginl.pas 31 KB

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