ncginl.pas 30 KB

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