ncginl.pas 31 KB

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