ncginl.pas 30 KB

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