ncginl.pas 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl and Carl Eric Codere
  3. Generate generic inline nodes
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit ncginl;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. node,ninl;
  22. type
  23. tcginlinenode = class(tinlinenode)
  24. procedure pass_generate_code;override;
  25. procedure second_assert;virtual;
  26. procedure second_sizeoftypeof;virtual;
  27. procedure second_length;virtual;
  28. procedure second_predsucc;virtual;
  29. procedure second_incdec;virtual;
  30. procedure second_typeinfo;virtual;
  31. procedure second_includeexclude;virtual;
  32. procedure second_pi; virtual;
  33. procedure second_arctan_real; virtual;
  34. procedure second_abs_real; virtual;
  35. procedure second_sqr_real; virtual;
  36. procedure second_sqrt_real; virtual;
  37. procedure second_ln_real; virtual;
  38. procedure second_cos_real; virtual;
  39. procedure second_sin_real; virtual;
  40. procedure second_assigned; virtual;
  41. procedure second_get_frame;virtual;
  42. procedure second_get_caller_frame;virtual;
  43. procedure second_get_caller_addr;virtual;
  44. procedure second_prefetch; virtual;
  45. procedure second_round_real; virtual;
  46. procedure second_trunc_real; virtual;
  47. procedure second_abs_long; virtual;
  48. procedure second_rox; virtual;
  49. procedure second_sar; virtual;
  50. end;
  51. implementation
  52. uses
  53. globtype,systems,constexp,
  54. cutils,verbose,globals,fmodule,
  55. symconst,symdef,defutil,symsym,
  56. aasmbase,aasmtai,aasmdata,aasmcpu,parabase,
  57. cgbase,pass_1,pass_2,
  58. cpuinfo,cpubase,paramgr,procinfo,
  59. nbas,ncon,ncal,ncnv,nld,ncgrtti,
  60. tgobj,ncgutil,
  61. cgutils,cgobj
  62. {$ifndef cpu64bitalu}
  63. ,cg64f32
  64. {$endif not cpu64bitalu}
  65. ;
  66. {*****************************************************************************
  67. TCGINLINENODE
  68. *****************************************************************************}
  69. procedure tcginlinenode.pass_generate_code;
  70. begin
  71. location_reset(location,LOC_VOID,OS_NO);
  72. case inlinenumber of
  73. in_assert_x_y:
  74. second_Assert;
  75. in_sizeof_x,
  76. in_typeof_x :
  77. second_SizeofTypeOf;
  78. in_length_x :
  79. second_Length;
  80. in_pred_x,
  81. in_succ_x:
  82. second_PredSucc;
  83. in_dec_x,
  84. in_inc_x :
  85. second_IncDec;
  86. in_typeinfo_x:
  87. second_TypeInfo;
  88. in_include_x_y,
  89. in_exclude_x_y:
  90. second_IncludeExclude;
  91. in_pi_real:
  92. second_pi;
  93. in_sin_real:
  94. second_sin_real;
  95. in_arctan_real:
  96. second_arctan_real;
  97. in_abs_real:
  98. second_abs_real;
  99. in_abs_long:
  100. second_abs_long;
  101. in_round_real:
  102. second_round_real;
  103. in_trunc_real:
  104. second_trunc_real;
  105. in_sqr_real:
  106. second_sqr_real;
  107. in_sqrt_real:
  108. second_sqrt_real;
  109. in_ln_real:
  110. second_ln_real;
  111. in_cos_real:
  112. second_cos_real;
  113. in_prefetch_var:
  114. second_prefetch;
  115. in_assigned_x:
  116. second_assigned;
  117. in_get_frame:
  118. second_get_frame;
  119. in_get_caller_frame:
  120. second_get_caller_frame;
  121. in_get_caller_addr:
  122. second_get_caller_addr;
  123. in_unaligned_x:
  124. begin
  125. secondpass(tcallparanode(left).left);
  126. location:=tcallparanode(left).left.location;
  127. if location.loc in [LOC_CREFERENCE,LOC_REFERENCE] then
  128. location.reference.alignment:=1;
  129. end;
  130. {$ifdef SUPPORT_MMX}
  131. in_mmx_pcmpeqb..in_mmx_pcmpgtw:
  132. begin
  133. location_reset(location,LOC_MMXREGISTER,OS_NO);
  134. if left.location.loc=LOC_REGISTER then
  135. begin
  136. {!!!!!!!}
  137. end
  138. else if tcallparanode(left).left.location.loc=LOC_REGISTER then
  139. begin
  140. {!!!!!!!}
  141. end
  142. else
  143. begin
  144. {!!!!!!!}
  145. end;
  146. end;
  147. {$endif SUPPORT_MMX}
  148. in_rol_x,
  149. in_rol_x_x,
  150. in_ror_x,
  151. in_ror_x_x:
  152. second_rox;
  153. in_sar_x,
  154. in_sar_x_y:
  155. second_sar;
  156. else internalerror(9);
  157. end;
  158. end;
  159. {*****************************************************************************
  160. ASSERT GENERIC HANDLING
  161. *****************************************************************************}
  162. procedure tcginlinenode.second_Assert;
  163. var
  164. hp2,hp3 : tnode;
  165. otlabel,oflabel : tasmlabel;
  166. paraloc1,paraloc2,
  167. paraloc3,paraloc4 : tcgpara;
  168. begin
  169. { the node should be removed in the firstpass }
  170. if not (cs_do_assertion in current_settings.localswitches) then
  171. internalerror(7123458);
  172. paraloc1.init;
  173. paraloc2.init;
  174. paraloc3.init;
  175. paraloc4.init;
  176. paramanager.getintparaloc(pocall_default,1,paraloc1);
  177. paramanager.getintparaloc(pocall_default,2,paraloc2);
  178. paramanager.getintparaloc(pocall_default,3,paraloc3);
  179. paramanager.getintparaloc(pocall_default,4,paraloc4);
  180. otlabel:=current_procinfo.CurrTrueLabel;
  181. oflabel:=current_procinfo.CurrFalseLabel;
  182. current_asmdata.getjumplabel(current_procinfo.CurrTrueLabel);
  183. current_asmdata.getjumplabel(current_procinfo.CurrFalseLabel);
  184. secondpass(tcallparanode(left).left);
  185. maketojumpbool(current_asmdata.CurrAsmList,tcallparanode(left).left,lr_load_regvars);
  186. cg.a_label(current_asmdata.CurrAsmList,current_procinfo.CurrFalseLabel);
  187. { First call secondpass() before we can push the parameters, otherwise
  188. parameters allocated in the registers can be destroyed }
  189. { generate filename string parameter }
  190. hp2:=ctypeconvnode.create(cstringconstnode.createstr(current_module.sourcefiles.get_file_name(current_filepos.fileindex)),cshortstringtype);
  191. firstpass(hp2);
  192. secondpass(hp2);
  193. if codegenerror then
  194. exit;
  195. { message parameter }
  196. hp3:=tcallparanode(tcallparanode(left).right).left;
  197. secondpass(hp3);
  198. if codegenerror then
  199. exit;
  200. { push erroraddr }
  201. cg.a_load_reg_cgpara(current_asmdata.CurrAsmList,OS_ADDR,NR_FRAME_POINTER_REG,paraloc4);
  202. { push lineno }
  203. cg.a_load_const_cgpara(current_asmdata.CurrAsmList,OS_INT,current_filepos.line,paraloc3);
  204. { push filename }
  205. cg.a_loadaddr_ref_cgpara(current_asmdata.CurrAsmList,hp2.location.reference,paraloc2);
  206. { push msg }
  207. cg.a_loadaddr_ref_cgpara(current_asmdata.CurrAsmList,hp3.location.reference,paraloc1);
  208. { call }
  209. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc1);
  210. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc2);
  211. paramanager.freecgpara(current_asmdata.CurrAsmList,paraloc3);
  212. paramanager.freecgpara(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. 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 if is_constpointernode(tcallparanode(tcallparanode(left).right).left) then
  414. addvalue:=addvalue*tpointerconstnode(tcallparanode(tcallparanode(left).right).left).value
  415. else
  416. begin
  417. location_force_reg(current_asmdata.CurrAsmList,tcallparanode(tcallparanode(left).right).left.location,cgsize,addvalue<=1);
  418. hregister:=tcallparanode(tcallparanode(left).right).left.location.register;
  419. {$ifndef cpu64bitalu}
  420. hregisterhi:=tcallparanode(tcallparanode(left).right).left.location.register64.reghi;
  421. {$endif not cpu64bitalu}
  422. { insert multiply with addvalue if its >1 }
  423. if addvalue>1 then
  424. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_IMUL,cgsize,addvalue.svalue,hregister);
  425. addconstant:=false;
  426. end;
  427. end;
  428. { write the add instruction }
  429. if addconstant then
  430. begin
  431. {$ifndef cpu64bitalu}
  432. if cgsize in [OS_64,OS_S64] then
  433. cg64.a_op64_const_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],cgsize,addvalue,tcallparanode(left).left.location)
  434. else
  435. {$endif not cpu64bitalu}
  436. cg.a_op_const_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],
  437. aint(addvalue.svalue),tcallparanode(left).left.location);
  438. end
  439. else
  440. begin
  441. {$ifndef cpu64bitalu}
  442. if cgsize in [OS_64,OS_S64] then
  443. cg64.a_op64_reg_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],cgsize,
  444. joinreg64(hregister,hregisterhi),tcallparanode(left).left.location)
  445. else
  446. {$endif not cpu64bitalu}
  447. cg.a_op_reg_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],
  448. hregister,tcallparanode(left).left.location);
  449. end;
  450. { no overflow checking for pointers (see ninl), and range checking }
  451. { is not applicable for them }
  452. if (tcallparanode(left).left.resultdef.typ <> pointerdef) then
  453. begin
  454. { things which can overflow must NOT pass via here, but have to be }
  455. { handled via a regular add node (conversion in tinlinenode.pass_1) }
  456. { Or someone has to rewrite the above to use a_op_const_reg_reg_ov }
  457. { and friends in case of overflow checking, and ask everyone to }
  458. { implement these methods since they don't exist for all cpus (JM) }
  459. { Similarly, range checking also has to be handled separately, }
  460. { see mantis #14841 (JM) }
  461. if ([cs_check_overflow,cs_check_range] * current_settings.localswitches <> []) then
  462. internalerror(2006111010);
  463. // cg.g_overflowcheck(current_asmdata.CurrAsmList,tcallparanode(left).left.location,tcallparanode(left).resultdef);
  464. // cg.g_rangecheck(current_asmdata.CurrAsmList,tcallparanode(left).left.location,tcallparanode(left).left.resultdef,
  465. // tcallparanode(left).left.resultdef);
  466. end;
  467. end;
  468. {*****************************************************************************
  469. TYPEINFO GENERIC HANDLING
  470. *****************************************************************************}
  471. procedure tcginlinenode.second_typeinfo;
  472. var
  473. href : treference;
  474. begin
  475. location_reset(location,LOC_REGISTER,OS_ADDR);
  476. location.register:=cg.getaddressregister(current_asmdata.CurrAsmList);
  477. reference_reset_symbol(href,RTTIWriter.get_rtti_label(left.resultdef,fullrtti),0,sizeof(pint));
  478. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,href,location.register);
  479. end;
  480. {*****************************************************************************
  481. INCLUDE/EXCLUDE GENERIC HANDLING
  482. *****************************************************************************}
  483. procedure tcginlinenode.second_IncludeExclude;
  484. var
  485. setpara, elepara: tnode;
  486. begin
  487. { the set }
  488. secondpass(tcallparanode(left).left);
  489. { the element to set }
  490. secondpass(tcallparanode(tcallparanode(left).right).left);
  491. setpara:=tcallparanode(left).left;
  492. elepara:=tcallparanode(tcallparanode(left).right).left;
  493. if elepara.location.loc=LOC_CONSTANT then
  494. begin
  495. cg.a_bit_set_const_loc(current_asmdata.CurrAsmList,(inlinenumber=in_include_x_y),
  496. elepara.location.value-tsetdef(setpara.resultdef).setbase,setpara.location);
  497. end
  498. else
  499. begin
  500. location_force_reg(current_asmdata.CurrAsmList,elepara.location,OS_INT,true);
  501. register_maybe_adjust_setbase(current_asmdata.CurrAsmList,elepara.location,tsetdef(setpara.resultdef).setbase);
  502. cg.a_bit_set_reg_loc(current_asmdata.CurrAsmList,(inlinenumber=in_include_x_y),
  503. elepara.location.size,elepara.location.register,setpara.location);
  504. end;
  505. end;
  506. {*****************************************************************************
  507. FLOAT GENERIC HANDLING
  508. *****************************************************************************}
  509. {
  510. These routines all call internal RTL routines, so if they are
  511. called here, they give an internal error
  512. }
  513. procedure tcginlinenode.second_pi;
  514. begin
  515. internalerror(20020718);
  516. end;
  517. procedure tcginlinenode.second_arctan_real;
  518. begin
  519. internalerror(20020718);
  520. end;
  521. procedure tcginlinenode.second_abs_real;
  522. begin
  523. internalerror(20020718);
  524. end;
  525. procedure tcginlinenode.second_round_real;
  526. begin
  527. internalerror(20020718);
  528. end;
  529. procedure tcginlinenode.second_trunc_real;
  530. begin
  531. internalerror(20020718);
  532. end;
  533. procedure tcginlinenode.second_sqr_real;
  534. begin
  535. internalerror(20020718);
  536. end;
  537. procedure tcginlinenode.second_sqrt_real;
  538. begin
  539. internalerror(20020718);
  540. end;
  541. procedure tcginlinenode.second_ln_real;
  542. begin
  543. internalerror(20020718);
  544. end;
  545. procedure tcginlinenode.second_cos_real;
  546. begin
  547. internalerror(20020718);
  548. end;
  549. procedure tcginlinenode.second_sin_real;
  550. begin
  551. internalerror(20020718);
  552. end;
  553. procedure tcginlinenode.second_prefetch;
  554. begin
  555. end;
  556. procedure tcginlinenode.second_abs_long;
  557. var
  558. opsize : tcgsize;
  559. tempreg1, tempreg2 : tregister;
  560. begin
  561. opsize := def_cgsize(left.resultdef);
  562. secondpass(left);
  563. location_force_reg(current_asmdata.CurrAsmList, left.location, opsize, false);
  564. location := left.location;
  565. location.register := cg.getintregister(current_asmdata.CurrAsmList, opsize);
  566. tempreg1 := cg.getintregister(current_asmdata.CurrAsmList, opsize);
  567. tempreg2 := cg.getintregister(current_asmdata.CurrAsmList, opsize);
  568. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_SAR, OS_INT, tcgsize2size[opsize]*8-1, left.location.register, tempreg1);
  569. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmList, OP_XOR, OS_INT, left.location.register, tempreg1, tempreg2);
  570. cg.a_op_reg_reg_reg(current_asmdata.CurrAsmlist, OP_SUB, OS_INT, tempreg1, tempreg2, location.register);
  571. end;
  572. {*****************************************************************************
  573. ASSIGNED GENERIC HANDLING
  574. *****************************************************************************}
  575. procedure tcginlinenode.second_assigned;
  576. begin
  577. secondpass(tcallparanode(left).left);
  578. { force left to be an OS_ADDR, since in case of method procvars }
  579. { the size is 2*OS_ADDR (JM) }
  580. cg.a_cmp_const_loc_label(current_asmdata.CurrAsmList,OS_ADDR,OC_NE,0,tcallparanode(left).left.location,current_procinfo.CurrTrueLabel);
  581. cg.a_jmp_always(current_asmdata.CurrAsmList,current_procinfo.CurrFalseLabel);
  582. location_reset(location,LOC_JUMP,OS_NO);
  583. end;
  584. procedure Tcginlinenode.second_get_frame;
  585. begin
  586. {$if defined(x86) or defined(arm)}
  587. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  588. begin
  589. location_reset(location,LOC_CONSTANT,OS_ADDR);
  590. location.value:=0;
  591. end
  592. else
  593. {$endif defined(x86) or defined(arm)}
  594. begin
  595. location_reset(location,LOC_CREGISTER,OS_ADDR);
  596. location.register:=current_procinfo.framepointer;
  597. end;
  598. end;
  599. procedure Tcginlinenode.second_get_caller_frame;
  600. var
  601. frame_reg:Tregister;
  602. use_frame_pointer:boolean;
  603. begin
  604. if left<>nil then
  605. begin
  606. secondpass(left);
  607. if left.location.loc=LOC_CONSTANT then
  608. use_frame_pointer:=true
  609. else
  610. begin
  611. location_force_reg(current_asmdata.currasmlist,left.location,OS_ADDR,false);
  612. frame_reg:=left.location.register;
  613. use_frame_pointer:=false;
  614. end
  615. end
  616. else
  617. begin
  618. use_frame_pointer:=current_procinfo.framepointer=NR_STACK_POINTER_REG;
  619. frame_reg:=current_procinfo.framepointer;
  620. end;
  621. if use_frame_pointer then
  622. begin
  623. location_reset(location,LOC_CREGISTER,OS_ADDR);
  624. location.register:=NR_FRAME_POINTER_REG;
  625. end
  626. else
  627. begin
  628. location_reset_ref(location,LOC_REFERENCE,OS_ADDR,sizeof(pint));
  629. location.reference.base:=frame_reg;
  630. end;
  631. end;
  632. procedure Tcginlinenode.second_get_caller_addr;
  633. var
  634. frame_ref:Treference;
  635. begin
  636. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  637. begin
  638. location_reset(location,LOC_REGISTER,OS_ADDR);
  639. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  640. reference_reset_base(frame_ref,NR_STACK_POINTER_REG,{current_procinfo.calc_stackframe_size}tg.lasttemp,sizeof(pint));
  641. cg.a_load_ref_reg(current_asmdata.currasmlist,OS_ADDR,OS_ADDR,frame_ref,location.register);
  642. end
  643. else
  644. begin
  645. location_reset(location,LOC_REGISTER,OS_ADDR);
  646. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  647. reference_reset_base(frame_ref,current_procinfo.framepointer,sizeof(pint),sizeof(pint));
  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 (left.nodetype=callparan) and
  659. assigned(tcallparanode(left).right) then
  660. begin
  661. op1:=tcallparanode(tcallparanode(left).right).left;
  662. op2:=tcallparanode(left).left;
  663. end
  664. else
  665. op1:=left;
  666. secondpass(op1);
  667. { load left operator in a register }
  668. location_copy(location,op1.location);
  669. case inlinenumber of
  670. in_ror_x,
  671. in_ror_x_x:
  672. op:=OP_ROR;
  673. in_rol_x,
  674. in_rol_x_x:
  675. op:=OP_ROL;
  676. end;
  677. location_force_reg(current_asmdata.CurrAsmList,location,location.size,false);
  678. if (left.nodetype=callparan) and
  679. assigned(tcallparanode(left).right) then
  680. begin
  681. secondpass(op2);
  682. { rotating by a constant directly coded: }
  683. if op2.nodetype=ordconstn then
  684. cg.a_op_const_reg(current_asmdata.CurrAsmList,op,location.size,
  685. tordconstnode(op2).value.uvalue and (resultdef.size*8-1),location.register)
  686. else
  687. begin
  688. location_force_reg(current_asmdata.CurrAsmList,op2.location,location.size,false);
  689. { do modulo 2 operation }
  690. cg.a_op_reg_reg(current_asmdata.CurrAsmList,op,location.size,op2.location.register,location.register);
  691. end;
  692. end
  693. else
  694. cg.a_op_const_reg(current_asmdata.CurrAsmList,op,location.size,1,location.register);
  695. end;
  696. procedure tcginlinenode.second_sar;
  697. var
  698. {hcountreg : tregister;}
  699. op1,op2 : tnode;
  700. begin
  701. if (left.nodetype=callparan) and
  702. assigned(tcallparanode(left).right) then
  703. begin
  704. op1:=tcallparanode(tcallparanode(left).right).left;
  705. op2:=tcallparanode(left).left;
  706. end
  707. else
  708. begin
  709. op1:=left;
  710. op2:=nil;
  711. end;
  712. secondpass(op1);
  713. { load left operator in a register }
  714. location_copy(location,op1.location);
  715. location_force_reg(current_asmdata.CurrAsmList,location,location.size,false);
  716. if not(assigned(op2)) then
  717. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SAR,location.size,1,location.register)
  718. else
  719. begin
  720. secondpass(op2);
  721. { shifting by a constant directly coded: }
  722. if op2.nodetype=ordconstn then
  723. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_SAR,location.size,
  724. tordconstnode(op2).value.uvalue and (resultdef.size*8-1),location.register)
  725. else
  726. begin
  727. location_force_reg(current_asmdata.CurrAsmList,op2.location,location.size,false);
  728. cg.a_op_reg_reg(current_asmdata.CurrAsmList,OP_SAR,location.size,op2.location.register,location.register);
  729. end;
  730. end;
  731. end;
  732. begin
  733. cinlinenode:=tcginlinenode;
  734. end.