ncginl.pas 31 KB

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