ncginl.pas 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  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',false);
  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,sizeof(pint));
  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,sizeof(pint));
  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,sizeof(pint));
  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. begin
  286. inc(left.location.reference.offset,tobjectdef(left.resultdef).vmt_offset);
  287. left.location.reference.alignment:=newalignment(left.location.reference.alignment,tobjectdef(left.resultdef).vmt_offset);
  288. end;
  289. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,left.location.reference,hregister);
  290. end;
  291. end;
  292. else
  293. internalerror(200301301);
  294. end;
  295. end;
  296. { in sizeof load size }
  297. if inlinenumber=in_sizeof_x then
  298. begin
  299. reference_reset_base(href,hregister,0,sizeof(pint));
  300. hregister:=cg.getintregister(current_asmdata.CurrAsmList,OS_INT);
  301. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_INT,OS_INT,href,hregister);
  302. end;
  303. location.register:=hregister;
  304. end;
  305. {*****************************************************************************
  306. LENGTH GENERIC HANDLING
  307. *****************************************************************************}
  308. procedure tcginlinenode.second_Length;
  309. var
  310. lengthlab : tasmlabel;
  311. hregister : tregister;
  312. href : treference;
  313. begin
  314. secondpass(left);
  315. if is_shortstring(left.resultdef) then
  316. begin
  317. location_copy(location,left.location);
  318. location.size:=OS_8;
  319. end
  320. else
  321. begin
  322. { length in ansi/wide strings is at offset -sizeof(pint) }
  323. location_force_reg(current_asmdata.CurrAsmList,left.location,OS_ADDR,false);
  324. current_asmdata.getjumplabel(lengthlab);
  325. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_ADDR,OC_EQ,0,left.location.register,lengthlab);
  326. if is_widestring(left.resultdef) and (tf_winlikewidestring in target_info.flags) then
  327. begin
  328. reference_reset_base(href,left.location.register,-sizeof(dword),sizeof(dword));
  329. hregister:=cg.makeregsize(current_asmdata.CurrAsmList,left.location.register,OS_INT);
  330. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_32,OS_INT,href,hregister);
  331. end
  332. else
  333. begin
  334. reference_reset_base(href,left.location.register,-sizeof(pint),sizeof(pint));
  335. hregister:=cg.makeregsize(current_asmdata.CurrAsmList,left.location.register,OS_INT);
  336. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_INT,OS_INT,href,hregister);
  337. end;
  338. if is_widestring(left.resultdef) or is_unicodestring(left.resultdef) then
  339. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SHR,OS_INT,1,hregister);
  340. cg.a_label(current_asmdata.CurrAsmList,lengthlab);
  341. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  342. location.register:=hregister;
  343. end;
  344. end;
  345. {*****************************************************************************
  346. PRED/SUCC GENERIC HANDLING
  347. *****************************************************************************}
  348. procedure tcginlinenode.second_PredSucc;
  349. var
  350. cgsize : TCGSize;
  351. cgop : topcg;
  352. begin
  353. secondpass(left);
  354. if inlinenumber=in_pred_x then
  355. cgop:=OP_SUB
  356. else
  357. cgop:=OP_ADD;
  358. cgsize:=def_cgsize(resultdef);
  359. { we need a value in a register }
  360. location_copy(location,left.location);
  361. location_force_reg(current_asmdata.CurrAsmList,location,cgsize,false);
  362. {$ifndef cpu64bitalu}
  363. if cgsize in [OS_64,OS_S64] then
  364. cg64.a_op64_const_reg(current_asmdata.CurrAsmList,cgop,cgsize,1,location.register64)
  365. else
  366. {$endif not cpu64bitalu}
  367. cg.a_op_const_reg(current_asmdata.CurrAsmList,cgop,location.size,1,location.register);
  368. cg.g_rangecheck(current_asmdata.CurrAsmList,location,resultdef,resultdef);
  369. end;
  370. {*****************************************************************************
  371. INC/DEC GENERIC HANDLING
  372. *****************************************************************************}
  373. procedure tcginlinenode.second_IncDec;
  374. const
  375. addsubop:array[in_inc_x..in_dec_x] of TOpCG=(OP_ADD,OP_SUB);
  376. var
  377. addvalue : TConstExprInt;
  378. addconstant : boolean;
  379. {$ifndef cpu64bitalu}
  380. hregisterhi,
  381. {$endif not cpu64bitalu}
  382. hregister : tregister;
  383. cgsize : tcgsize;
  384. begin
  385. { set defaults }
  386. addconstant:=true;
  387. { first secondpass second argument, because if the first arg }
  388. { is used in that expression then SSL may move it to another }
  389. { register }
  390. if assigned(tcallparanode(left).right) then
  391. secondpass(tcallparanode(tcallparanode(left).right).left);
  392. { load first parameter, must be a reference }
  393. secondpass(tcallparanode(left).left);
  394. cgsize:=def_cgsize(tcallparanode(left).left.resultdef);
  395. { get addvalue }
  396. case tcallparanode(left).left.resultdef.typ of
  397. orddef,
  398. enumdef :
  399. addvalue:=1;
  400. pointerdef :
  401. begin
  402. if is_void(tpointerdef(tcallparanode(left).left.resultdef).pointeddef) then
  403. addvalue:=1
  404. else
  405. addvalue:=tpointerdef(tcallparanode(left).left.resultdef).pointeddef.size;
  406. end;
  407. else
  408. internalerror(10081);
  409. end;
  410. { second_ argument specified?, must be a s32bit in register }
  411. if assigned(tcallparanode(left).right) then
  412. begin
  413. { when constant, just multiply the addvalue }
  414. if is_constintnode(tcallparanode(tcallparanode(left).right).left) then
  415. addvalue:=addvalue*get_ordinal_value(tcallparanode(tcallparanode(left).right).left)
  416. else if is_constpointernode(tcallparanode(tcallparanode(left).right).left) then
  417. addvalue:=addvalue*tpointerconstnode(tcallparanode(tcallparanode(left).right).left).value
  418. else
  419. begin
  420. location_force_reg(current_asmdata.CurrAsmList,tcallparanode(tcallparanode(left).right).left.location,cgsize,addvalue<=1);
  421. hregister:=tcallparanode(tcallparanode(left).right).left.location.register;
  422. {$ifndef cpu64bitalu}
  423. hregisterhi:=tcallparanode(tcallparanode(left).right).left.location.register64.reghi;
  424. {$endif not cpu64bitalu}
  425. { insert multiply with addvalue if its >1 }
  426. if addvalue>1 then
  427. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_IMUL,cgsize,addvalue.svalue,hregister);
  428. addconstant:=false;
  429. end;
  430. end;
  431. { write the add instruction }
  432. if addconstant then
  433. begin
  434. {$ifndef cpu64bitalu}
  435. if cgsize in [OS_64,OS_S64] then
  436. cg64.a_op64_const_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],cgsize,addvalue,tcallparanode(left).left.location)
  437. else
  438. {$endif not cpu64bitalu}
  439. cg.a_op_const_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],
  440. aint(addvalue.svalue),tcallparanode(left).left.location);
  441. end
  442. else
  443. begin
  444. {$ifndef cpu64bitalu}
  445. if cgsize in [OS_64,OS_S64] then
  446. cg64.a_op64_reg_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],cgsize,
  447. joinreg64(hregister,hregisterhi),tcallparanode(left).left.location)
  448. else
  449. {$endif not cpu64bitalu}
  450. cg.a_op_reg_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],
  451. hregister,tcallparanode(left).left.location);
  452. end;
  453. { no overflow checking for pointers (see ninl), and range checking }
  454. { is not applicable for them }
  455. if (tcallparanode(left).left.resultdef.typ <> pointerdef) then
  456. begin
  457. { things which can overflow must NOT pass via here, but have to be }
  458. { handled via a regular add node (conversion in tinlinenode.pass_1) }
  459. { Or someone has to rewrite the above to use a_op_const_reg_reg_ov }
  460. { and friends in case of overflow checking, and ask everyone to }
  461. { implement these methods since they don't exist for all cpus (JM) }
  462. if (cs_check_overflow in current_settings.localswitches) then
  463. internalerror(2006111010);
  464. // cg.g_overflowcheck(current_asmdata.CurrAsmList,tcallparanode(left).left.location,tcallparanode(left).resultdef);
  465. cg.g_rangecheck(current_asmdata.CurrAsmList,tcallparanode(left).left.location,tcallparanode(left).left.resultdef,
  466. tcallparanode(left).left.resultdef);
  467. end;
  468. end;
  469. {*****************************************************************************
  470. TYPEINFO GENERIC HANDLING
  471. *****************************************************************************}
  472. procedure tcginlinenode.second_typeinfo;
  473. var
  474. href : treference;
  475. begin
  476. location_reset(location,LOC_REGISTER,OS_ADDR);
  477. location.register:=cg.getaddressregister(current_asmdata.CurrAsmList);
  478. reference_reset_symbol(href,RTTIWriter.get_rtti_label(left.resultdef,fullrtti),0,sizeof(pint));
  479. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,href,location.register);
  480. end;
  481. {*****************************************************************************
  482. INCLUDE/EXCLUDE GENERIC HANDLING
  483. *****************************************************************************}
  484. procedure tcginlinenode.second_IncludeExclude;
  485. var
  486. setpara, elepara: tnode;
  487. begin
  488. { the set }
  489. secondpass(tcallparanode(left).left);
  490. { the element to set }
  491. secondpass(tcallparanode(tcallparanode(left).right).left);
  492. setpara:=tcallparanode(left).left;
  493. elepara:=tcallparanode(tcallparanode(left).right).left;
  494. if elepara.location.loc=LOC_CONSTANT then
  495. begin
  496. cg.a_bit_set_const_loc(current_asmdata.CurrAsmList,(inlinenumber=in_include_x_y),
  497. elepara.location.value-tsetdef(setpara.resultdef).setbase,setpara.location);
  498. end
  499. else
  500. begin
  501. location_force_reg(current_asmdata.CurrAsmList,elepara.location,OS_INT,true);
  502. register_maybe_adjust_setbase(current_asmdata.CurrAsmList,elepara.location,tsetdef(setpara.resultdef).setbase);
  503. cg.a_bit_set_reg_loc(current_asmdata.CurrAsmList,(inlinenumber=in_include_x_y),
  504. elepara.location.size,elepara.location.register,setpara.location);
  505. end;
  506. end;
  507. {*****************************************************************************
  508. FLOAT GENERIC HANDLING
  509. *****************************************************************************}
  510. {
  511. These routines all call internal RTL routines, so if they are
  512. called here, they give an internal error
  513. }
  514. procedure tcginlinenode.second_pi;
  515. begin
  516. internalerror(20020718);
  517. end;
  518. procedure tcginlinenode.second_arctan_real;
  519. begin
  520. internalerror(20020718);
  521. end;
  522. procedure tcginlinenode.second_abs_real;
  523. begin
  524. internalerror(20020718);
  525. end;
  526. procedure tcginlinenode.second_round_real;
  527. begin
  528. internalerror(20020718);
  529. end;
  530. procedure tcginlinenode.second_trunc_real;
  531. begin
  532. internalerror(20020718);
  533. end;
  534. procedure tcginlinenode.second_sqr_real;
  535. begin
  536. internalerror(20020718);
  537. end;
  538. procedure tcginlinenode.second_sqrt_real;
  539. begin
  540. internalerror(20020718);
  541. end;
  542. procedure tcginlinenode.second_ln_real;
  543. begin
  544. internalerror(20020718);
  545. end;
  546. procedure tcginlinenode.second_cos_real;
  547. begin
  548. internalerror(20020718);
  549. end;
  550. procedure tcginlinenode.second_sin_real;
  551. begin
  552. internalerror(20020718);
  553. end;
  554. procedure tcginlinenode.second_prefetch;
  555. begin
  556. end;
  557. procedure tcginlinenode.second_abs_long;
  558. var
  559. opsize : tcgsize;
  560. tempreg1, tempreg2 : tregister;
  561. begin
  562. opsize := def_cgsize(left.resultdef);
  563. secondpass(left);
  564. location_force_reg(current_asmdata.CurrAsmList, left.location, opsize, false);
  565. location := left.location;
  566. location.register := cg.getintregister(current_asmdata.CurrAsmList, opsize);
  567. tempreg1 := cg.getintregister(current_asmdata.CurrAsmList, opsize);
  568. tempreg2 := cg.getintregister(current_asmdata.CurrAsmList, opsize);
  569. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_SAR, OS_INT, tcgsize2size[opsize]*8-1, left.location.register, tempreg1);
  570. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList, OP_XOR, OS_INT, left.location.register, tempreg1, tempreg2);
  571. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmlist, OP_SUB, OS_INT, tempreg1, tempreg2, location.register);
  572. end;
  573. {*****************************************************************************
  574. ASSIGNED GENERIC HANDLING
  575. *****************************************************************************}
  576. procedure tcginlinenode.second_assigned;
  577. begin
  578. secondpass(tcallparanode(left).left);
  579. { force left to be an OS_ADDR, since in case of method procvars }
  580. { the size is 2*OS_ADDR (JM) }
  581. cg.a_cmp_const_loc_label(current_asmdata.CurrAsmList,OS_ADDR,OC_NE,0,tcallparanode(left).left.location,current_procinfo.CurrTrueLabel);
  582. cg.a_jmp_always(current_asmdata.CurrAsmList,current_procinfo.CurrFalseLabel);
  583. location_reset(location,LOC_JUMP,OS_NO);
  584. end;
  585. procedure Tcginlinenode.second_get_frame;
  586. begin
  587. {$if defined(x86) or defined(arm)}
  588. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  589. begin
  590. location_reset(location,LOC_CONSTANT,OS_ADDR);
  591. location.value:=0;
  592. end
  593. else
  594. {$endif defined(x86) or defined(arm)}
  595. begin
  596. location_reset(location,LOC_CREGISTER,OS_ADDR);
  597. location.register:=current_procinfo.framepointer;
  598. end;
  599. end;
  600. procedure Tcginlinenode.second_get_caller_frame;
  601. var
  602. frame_reg:Tregister;
  603. use_frame_pointer:boolean;
  604. begin
  605. if left<>nil then
  606. begin
  607. secondpass(left);
  608. if left.location.loc=LOC_CONSTANT then
  609. use_frame_pointer:=true
  610. else
  611. begin
  612. location_force_reg(current_asmdata.currasmlist,left.location,OS_ADDR,false);
  613. frame_reg:=left.location.register;
  614. use_frame_pointer:=false;
  615. end
  616. end
  617. else
  618. begin
  619. use_frame_pointer:=current_procinfo.framepointer=NR_STACK_POINTER_REG;
  620. frame_reg:=current_procinfo.framepointer;
  621. end;
  622. if use_frame_pointer then
  623. begin
  624. location_reset(location,LOC_CREGISTER,OS_ADDR);
  625. location.register:=NR_FRAME_POINTER_REG;
  626. end
  627. else
  628. begin
  629. location_reset_ref(location,LOC_REFERENCE,OS_ADDR,sizeof(pint));
  630. location.reference.base:=frame_reg;
  631. end;
  632. end;
  633. procedure Tcginlinenode.second_get_caller_addr;
  634. var
  635. frame_ref:Treference;
  636. begin
  637. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  638. begin
  639. location_reset(location,LOC_REGISTER,OS_ADDR);
  640. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  641. reference_reset_base(frame_ref,NR_STACK_POINTER_REG,{current_procinfo.calc_stackframe_size}tg.lasttemp,sizeof(pint));
  642. cg.a_load_ref_reg(current_asmdata.currasmlist,OS_ADDR,OS_ADDR,frame_ref,location.register);
  643. end
  644. else
  645. begin
  646. location_reset(location,LOC_REGISTER,OS_ADDR);
  647. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  648. reference_reset_base(frame_ref,current_procinfo.framepointer,sizeof(pint),sizeof(pint));
  649. cg.a_load_ref_reg(current_asmdata.currasmlist,OS_ADDR,OS_ADDR,frame_ref,location.register);
  650. end;
  651. end;
  652. procedure tcginlinenode.second_rox;
  653. var
  654. op : topcg;
  655. {hcountreg : tregister;}
  656. op1,op2 : tnode;
  657. begin
  658. { one or two parameters? }
  659. if (left.nodetype=callparan) and
  660. assigned(tcallparanode(left).right) then
  661. begin
  662. op1:=tcallparanode(tcallparanode(left).right).left;
  663. op2:=tcallparanode(left).left;
  664. end
  665. else
  666. op1:=left;
  667. secondpass(op1);
  668. { load left operator in a register }
  669. location_copy(location,op1.location);
  670. case inlinenumber of
  671. in_ror_x,
  672. in_ror_x_x:
  673. op:=OP_ROR;
  674. in_rol_x,
  675. in_rol_x_x:
  676. op:=OP_ROL;
  677. end;
  678. location_force_reg(current_asmdata.CurrAsmList,location,location.size,false);
  679. if (left.nodetype=callparan) and
  680. assigned(tcallparanode(left).right) then
  681. begin
  682. secondpass(op2);
  683. { rotating by a constant directly coded: }
  684. if op2.nodetype=ordconstn then
  685. cg.a_op_const_reg(current_asmdata.CurrAsmList,op,location.size,
  686. tordconstnode(op2).value.uvalue and (resultdef.size*8-1),location.register)
  687. else
  688. begin
  689. location_force_reg(current_asmdata.CurrAsmList,op2.location,location.size,false);
  690. { do modulo 2 operation }
  691. cg.a_op_reg_reg(current_asmdata.CurrAsmList,op,location.size,op2.location.register,location.register);
  692. end;
  693. end
  694. else
  695. cg.a_op_const_reg(current_asmdata.CurrAsmList,op,location.size,1,location.register);
  696. end;
  697. begin
  698. cinlinenode:=tcginlinenode;
  699. end.