ncginl.pas 27 KB

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