ncginl.pas 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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. { Similarly, range checking also has to be handled separately, }
  463. { see mantis #14841 (JM) }
  464. if ([cs_check_overflow,cs_check_range] * current_settings.localswitches <> []) then
  465. internalerror(2006111010);
  466. // cg.g_overflowcheck(current_asmdata.CurrAsmList,tcallparanode(left).left.location,tcallparanode(left).resultdef);
  467. // cg.g_rangecheck(current_asmdata.CurrAsmList,tcallparanode(left).left.location,tcallparanode(left).left.resultdef,
  468. // tcallparanode(left).left.resultdef);
  469. end;
  470. end;
  471. {*****************************************************************************
  472. TYPEINFO GENERIC HANDLING
  473. *****************************************************************************}
  474. procedure tcginlinenode.second_typeinfo;
  475. var
  476. href : treference;
  477. begin
  478. location_reset(location,LOC_REGISTER,OS_ADDR);
  479. location.register:=cg.getaddressregister(current_asmdata.CurrAsmList);
  480. reference_reset_symbol(href,RTTIWriter.get_rtti_label(left.resultdef,fullrtti),0,sizeof(pint));
  481. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,href,location.register);
  482. end;
  483. {*****************************************************************************
  484. INCLUDE/EXCLUDE GENERIC HANDLING
  485. *****************************************************************************}
  486. procedure tcginlinenode.second_IncludeExclude;
  487. var
  488. setpara, elepara: tnode;
  489. begin
  490. { the set }
  491. secondpass(tcallparanode(left).left);
  492. { the element to set }
  493. secondpass(tcallparanode(tcallparanode(left).right).left);
  494. setpara:=tcallparanode(left).left;
  495. elepara:=tcallparanode(tcallparanode(left).right).left;
  496. if elepara.location.loc=LOC_CONSTANT then
  497. begin
  498. cg.a_bit_set_const_loc(current_asmdata.CurrAsmList,(inlinenumber=in_include_x_y),
  499. elepara.location.value-tsetdef(setpara.resultdef).setbase,setpara.location);
  500. end
  501. else
  502. begin
  503. location_force_reg(current_asmdata.CurrAsmList,elepara.location,OS_INT,true);
  504. register_maybe_adjust_setbase(current_asmdata.CurrAsmList,elepara.location,tsetdef(setpara.resultdef).setbase);
  505. cg.a_bit_set_reg_loc(current_asmdata.CurrAsmList,(inlinenumber=in_include_x_y),
  506. elepara.location.size,elepara.location.register,setpara.location);
  507. end;
  508. end;
  509. {*****************************************************************************
  510. FLOAT GENERIC HANDLING
  511. *****************************************************************************}
  512. {
  513. These routines all call internal RTL routines, so if they are
  514. called here, they give an internal error
  515. }
  516. procedure tcginlinenode.second_pi;
  517. begin
  518. internalerror(20020718);
  519. end;
  520. procedure tcginlinenode.second_arctan_real;
  521. begin
  522. internalerror(20020718);
  523. end;
  524. procedure tcginlinenode.second_abs_real;
  525. begin
  526. internalerror(20020718);
  527. end;
  528. procedure tcginlinenode.second_round_real;
  529. begin
  530. internalerror(20020718);
  531. end;
  532. procedure tcginlinenode.second_trunc_real;
  533. begin
  534. internalerror(20020718);
  535. end;
  536. procedure tcginlinenode.second_sqr_real;
  537. begin
  538. internalerror(20020718);
  539. end;
  540. procedure tcginlinenode.second_sqrt_real;
  541. begin
  542. internalerror(20020718);
  543. end;
  544. procedure tcginlinenode.second_ln_real;
  545. begin
  546. internalerror(20020718);
  547. end;
  548. procedure tcginlinenode.second_cos_real;
  549. begin
  550. internalerror(20020718);
  551. end;
  552. procedure tcginlinenode.second_sin_real;
  553. begin
  554. internalerror(20020718);
  555. end;
  556. procedure tcginlinenode.second_prefetch;
  557. begin
  558. end;
  559. procedure tcginlinenode.second_abs_long;
  560. var
  561. opsize : tcgsize;
  562. tempreg1, tempreg2 : tregister;
  563. begin
  564. opsize := def_cgsize(left.resultdef);
  565. secondpass(left);
  566. location_force_reg(current_asmdata.CurrAsmList, left.location, opsize, false);
  567. location := left.location;
  568. location.register := cg.getintregister(current_asmdata.CurrAsmList, opsize);
  569. tempreg1 := cg.getintregister(current_asmdata.CurrAsmList, opsize);
  570. tempreg2 := cg.getintregister(current_asmdata.CurrAsmList, opsize);
  571. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_SAR, OS_INT, tcgsize2size[opsize]*8-1, left.location.register, tempreg1);
  572. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList, OP_XOR, OS_INT, left.location.register, tempreg1, tempreg2);
  573. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmlist, OP_SUB, OS_INT, tempreg1, tempreg2, location.register);
  574. end;
  575. {*****************************************************************************
  576. ASSIGNED GENERIC HANDLING
  577. *****************************************************************************}
  578. procedure tcginlinenode.second_assigned;
  579. begin
  580. secondpass(tcallparanode(left).left);
  581. { force left to be an OS_ADDR, since in case of method procvars }
  582. { the size is 2*OS_ADDR (JM) }
  583. cg.a_cmp_const_loc_label(current_asmdata.CurrAsmList,OS_ADDR,OC_NE,0,tcallparanode(left).left.location,current_procinfo.CurrTrueLabel);
  584. cg.a_jmp_always(current_asmdata.CurrAsmList,current_procinfo.CurrFalseLabel);
  585. location_reset(location,LOC_JUMP,OS_NO);
  586. end;
  587. procedure Tcginlinenode.second_get_frame;
  588. begin
  589. {$if defined(x86) or defined(arm)}
  590. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  591. begin
  592. location_reset(location,LOC_CONSTANT,OS_ADDR);
  593. location.value:=0;
  594. end
  595. else
  596. {$endif defined(x86) or defined(arm)}
  597. begin
  598. location_reset(location,LOC_CREGISTER,OS_ADDR);
  599. location.register:=current_procinfo.framepointer;
  600. end;
  601. end;
  602. procedure Tcginlinenode.second_get_caller_frame;
  603. var
  604. frame_reg:Tregister;
  605. use_frame_pointer:boolean;
  606. begin
  607. if left<>nil then
  608. begin
  609. secondpass(left);
  610. if left.location.loc=LOC_CONSTANT then
  611. use_frame_pointer:=true
  612. else
  613. begin
  614. location_force_reg(current_asmdata.currasmlist,left.location,OS_ADDR,false);
  615. frame_reg:=left.location.register;
  616. use_frame_pointer:=false;
  617. end
  618. end
  619. else
  620. begin
  621. use_frame_pointer:=current_procinfo.framepointer=NR_STACK_POINTER_REG;
  622. frame_reg:=current_procinfo.framepointer;
  623. end;
  624. if use_frame_pointer then
  625. begin
  626. location_reset(location,LOC_CREGISTER,OS_ADDR);
  627. location.register:=NR_FRAME_POINTER_REG;
  628. end
  629. else
  630. begin
  631. location_reset_ref(location,LOC_REFERENCE,OS_ADDR,sizeof(pint));
  632. location.reference.base:=frame_reg;
  633. end;
  634. end;
  635. procedure Tcginlinenode.second_get_caller_addr;
  636. var
  637. frame_ref:Treference;
  638. begin
  639. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  640. begin
  641. location_reset(location,LOC_REGISTER,OS_ADDR);
  642. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  643. reference_reset_base(frame_ref,NR_STACK_POINTER_REG,{current_procinfo.calc_stackframe_size}tg.lasttemp,sizeof(pint));
  644. cg.a_load_ref_reg(current_asmdata.currasmlist,OS_ADDR,OS_ADDR,frame_ref,location.register);
  645. end
  646. else
  647. begin
  648. location_reset(location,LOC_REGISTER,OS_ADDR);
  649. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  650. reference_reset_base(frame_ref,current_procinfo.framepointer,sizeof(pint),sizeof(pint));
  651. cg.a_load_ref_reg(current_asmdata.currasmlist,OS_ADDR,OS_ADDR,frame_ref,location.register);
  652. end;
  653. end;
  654. procedure tcginlinenode.second_rox;
  655. var
  656. op : topcg;
  657. {hcountreg : tregister;}
  658. op1,op2 : tnode;
  659. begin
  660. { one or two parameters? }
  661. if (left.nodetype=callparan) and
  662. assigned(tcallparanode(left).right) then
  663. begin
  664. op1:=tcallparanode(tcallparanode(left).right).left;
  665. op2:=tcallparanode(left).left;
  666. end
  667. else
  668. op1:=left;
  669. secondpass(op1);
  670. { load left operator in a register }
  671. location_copy(location,op1.location);
  672. case inlinenumber of
  673. in_ror_x,
  674. in_ror_x_x:
  675. op:=OP_ROR;
  676. in_rol_x,
  677. in_rol_x_x:
  678. op:=OP_ROL;
  679. end;
  680. location_force_reg(current_asmdata.CurrAsmList,location,location.size,false);
  681. if (left.nodetype=callparan) and
  682. assigned(tcallparanode(left).right) then
  683. begin
  684. secondpass(op2);
  685. { rotating by a constant directly coded: }
  686. if op2.nodetype=ordconstn then
  687. cg.a_op_const_reg(current_asmdata.CurrAsmList,op,location.size,
  688. tordconstnode(op2).value.uvalue and (resultdef.size*8-1),location.register)
  689. else
  690. begin
  691. location_force_reg(current_asmdata.CurrAsmList,op2.location,location.size,false);
  692. { do modulo 2 operation }
  693. cg.a_op_reg_reg(current_asmdata.CurrAsmList,op,location.size,op2.location.register,location.register);
  694. end;
  695. end
  696. else
  697. cg.a_op_const_reg(current_asmdata.CurrAsmList,op,location.size,1,location.register);
  698. end;
  699. begin
  700. cinlinenode:=tcginlinenode;
  701. end.