ncginl.pas 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  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_2;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,
  55. tgobj,ncgutil,
  56. cgutils,cgobj
  57. {$ifndef cpu64bit}
  58. ,cg64f32
  59. {$endif cpu64bit}
  60. ;
  61. {*****************************************************************************
  62. TCGINLINENODE
  63. *****************************************************************************}
  64. procedure tcginlinenode.pass_2;
  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 aktlocalswitches) 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:=cstringconstnode.createstr(current_module.sourcefiles.get_file_name(aktfilepos.fileindex));
  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,aktfilepos.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.resulttype.def).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.resulttype.def.deftype=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.resulttype.def).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.resulttype.def) 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.resulttype.def).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.resulttype.def.deftype=objectdef) then
  270. inc(left.location.reference.offset,tobjectdef(left.resulttype.def).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.resulttype.def) 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.resulttype.def) 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.resulttype.def) 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(resulttype.def);
  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,resulttype.def,resulttype.def);
  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. { load first parameter, must be a reference }
  370. secondpass(tcallparanode(left).left);
  371. cgsize:=def_cgsize(tcallparanode(left).left.resulttype.def);
  372. { get addvalue }
  373. case tcallparanode(left).left.resulttype.def.deftype of
  374. orddef,
  375. enumdef :
  376. addvalue:=1;
  377. pointerdef :
  378. begin
  379. if is_void(tpointerdef(tcallparanode(left).left.resulttype.def).pointertype.def) then
  380. addvalue:=1
  381. else
  382. addvalue:=tpointerdef(tcallparanode(left).left.resulttype.def).pointertype.def.size;
  383. end;
  384. else
  385. internalerror(10081);
  386. end;
  387. { second_ argument specified?, must be a s32bit in register }
  388. if assigned(tcallparanode(left).right) then
  389. begin
  390. secondpass(tcallparanode(tcallparanode(left).right).left);
  391. { when constant, just multiply the addvalue }
  392. if is_constintnode(tcallparanode(tcallparanode(left).right).left) then
  393. addvalue:=addvalue*get_ordinal_value(tcallparanode(tcallparanode(left).right).left)
  394. else
  395. begin
  396. location_force_reg(current_asmdata.CurrAsmList,tcallparanode(tcallparanode(left).right).left.location,cgsize,addvalue<=1);
  397. hregister:=tcallparanode(tcallparanode(left).right).left.location.register;
  398. {$ifndef cpu64bit}
  399. hregisterhi:=tcallparanode(tcallparanode(left).right).left.location.register64.reghi;
  400. {$endif cpu64bit}
  401. { insert multiply with addvalue if its >1 }
  402. if addvalue>1 then
  403. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_IMUL,cgsize,addvalue,hregister);
  404. addconstant:=false;
  405. end;
  406. end;
  407. { write the add instruction }
  408. if addconstant then
  409. begin
  410. {$ifndef cpu64bit}
  411. if cgsize in [OS_64,OS_S64] then
  412. cg64.a_op64_const_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],cgsize,addvalue,tcallparanode(left).left.location)
  413. else
  414. {$endif cpu64bit}
  415. cg.a_op_const_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],
  416. aint(addvalue),tcallparanode(left).left.location);
  417. end
  418. else
  419. begin
  420. {$ifndef cpu64bit}
  421. if cgsize in [OS_64,OS_S64] then
  422. cg64.a_op64_reg_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],cgsize,
  423. joinreg64(hregister,hregisterhi),tcallparanode(left).left.location)
  424. else
  425. {$endif cpu64bit}
  426. cg.a_op_reg_loc(current_asmdata.CurrAsmList,addsubop[inlinenumber],
  427. hregister,tcallparanode(left).left.location);
  428. end;
  429. cg.g_overflowcheck(current_asmdata.CurrAsmList,tcallparanode(left).left.location,tcallparanode(left).resulttype.def);
  430. cg.g_rangecheck(current_asmdata.CurrAsmList,tcallparanode(left).left.location,tcallparanode(left).left.resulttype.def,
  431. tcallparanode(left).left.resulttype.def);
  432. end;
  433. {*****************************************************************************
  434. TYPEINFO GENERIC HANDLING
  435. *****************************************************************************}
  436. procedure tcginlinenode.second_typeinfo;
  437. var
  438. href : treference;
  439. begin
  440. location_reset(location,LOC_REGISTER,OS_ADDR);
  441. location.register:=cg.getaddressregister(current_asmdata.CurrAsmList);
  442. reference_reset_symbol(href,tstoreddef(left.resulttype.def).get_rtti_label(fullrtti),0);
  443. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,href,location.register);
  444. end;
  445. {*****************************************************************************
  446. INCLUDE/EXCLUDE GENERIC HANDLING
  447. *****************************************************************************}
  448. procedure tcginlinenode.second_IncludeExclude;
  449. var
  450. bitsperop,l : longint;
  451. opsize : tcgsize;
  452. cgop : topcg;
  453. addrreg2,addrreg,
  454. hregister,hregister2: tregister;
  455. use_small : boolean;
  456. href : treference;
  457. begin
  458. opsize:=OS_32;
  459. bitsperop:=(8*tcgsize2size[opsize]);
  460. secondpass(tcallparanode(left).left);
  461. if tcallparanode(tcallparanode(left).right).left.nodetype=ordconstn then
  462. begin
  463. { calculate bit position }
  464. l:=1 shl (tordconstnode(tcallparanode(tcallparanode(left).right).left).value mod bitsperop);
  465. { determine operator }
  466. if inlinenumber=in_include_x_y then
  467. cgop:=OP_OR
  468. else
  469. begin
  470. cgop:=OP_AND;
  471. l:=not(l);
  472. end;
  473. case tcallparanode(left).left.location.loc of
  474. LOC_REFERENCE :
  475. begin
  476. inc(tcallparanode(left).left.location.reference.offset,
  477. (tordconstnode(tcallparanode(tcallparanode(left).right).left).value div bitsperop)*tcgsize2size[opsize]);
  478. cg.a_op_const_ref(current_asmdata.CurrAsmList,cgop,opsize,l,tcallparanode(left).left.location.reference);
  479. end;
  480. LOC_CREGISTER :
  481. cg.a_op_const_reg(current_asmdata.CurrAsmList,cgop,tcallparanode(left).left.location.size,l,tcallparanode(left).left.location.register);
  482. else
  483. internalerror(200405021);
  484. end;
  485. end
  486. else
  487. begin
  488. use_small:=
  489. { set type }
  490. (tsetdef(tcallparanode(left).left.resulttype.def).settype=smallset)
  491. and
  492. { elemenut number between 1 and 32 }
  493. ((tcallparanode(tcallparanode(left).right).left.resulttype.def.deftype=orddef) and
  494. (torddef(tcallparanode(tcallparanode(left).right).left.resulttype.def).high<=32) or
  495. (tcallparanode(tcallparanode(left).right).left.resulttype.def.deftype=enumdef) and
  496. (tenumdef(tcallparanode(tcallparanode(left).right).left.resulttype.def).max<=32));
  497. { generate code for the element to set }
  498. secondpass(tcallparanode(tcallparanode(left).right).left);
  499. { bitnumber - which must be loaded into register }
  500. hregister:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
  501. hregister2:=cg.getintregister(current_asmdata.CurrAsmList,opsize);
  502. cg.a_load_loc_reg(current_asmdata.CurrAsmList,opsize,
  503. tcallparanode(tcallparanode(left).right).left.location,hregister);
  504. if use_small then
  505. begin
  506. { hregister contains the bitnumber to add }
  507. cg.a_load_const_reg(current_asmdata.CurrAsmList, opsize, 1, hregister2);
  508. cg.a_op_reg_reg(current_asmdata.CurrAsmList, OP_SHL, opsize, hregister, hregister2);
  509. { possiblities :
  510. bitnumber : LOC_REFERENCE, LOC_REGISTER, LOC_CREGISTER
  511. set value : LOC_REFERENCE, LOC_REGISTER
  512. }
  513. { location of set }
  514. if inlinenumber=in_include_x_y then
  515. begin
  516. cg.a_op_reg_loc(current_asmdata.CurrAsmList, OP_OR, hregister2,
  517. tcallparanode(left).left.location);
  518. end
  519. else
  520. begin
  521. cg.a_op_reg_reg(current_asmdata.CurrAsmList, OP_NOT, opsize, hregister2,hregister2);
  522. cg.a_op_reg_loc(current_asmdata.CurrAsmList, OP_AND, hregister2,
  523. tcallparanode(left).left.location);
  524. end;
  525. end
  526. else
  527. begin
  528. { possiblities :
  529. bitnumber : LOC_REFERENCE, LOC_REGISTER, LOC_CREGISTER
  530. set value : LOC_REFERENCE
  531. }
  532. { hregister contains the bitnumber (div 32 to get the correct offset) }
  533. { hregister contains the bitnumber to add }
  534. cg.a_op_const_reg_reg(current_asmdata.CurrAsmList, OP_SHR, opsize, 5, hregister,hregister2);
  535. cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_SHL, opsize, 2, hregister2);
  536. addrreg:=cg.getaddressregister(current_asmdata.CurrAsmList);
  537. { we need an extra address register to be able to do an ADD operation }
  538. addrreg2:=cg.getaddressregister(current_asmdata.CurrAsmList);
  539. cg.a_load_reg_reg(current_asmdata.CurrAsmList,opsize,OS_ADDR,hregister2,addrreg2);
  540. { calculate the correct address of the operand }
  541. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList, tcallparanode(left).left.location.reference,addrreg);
  542. cg.a_op_reg_reg(current_asmdata.CurrAsmList, OP_ADD, OS_ADDR, addrreg2, addrreg);
  543. { hregister contains the bitnumber to add }
  544. cg.a_load_const_reg(current_asmdata.CurrAsmList, opsize, 1, hregister2);
  545. cg.a_op_const_reg(current_asmdata.CurrAsmList, OP_AND, opsize, 31, hregister);
  546. cg.a_op_reg_reg(current_asmdata.CurrAsmList, OP_SHL, opsize, hregister, hregister2);
  547. reference_reset_base(href,addrreg,0);
  548. if inlinenumber=in_include_x_y then
  549. cg.a_op_reg_ref(current_asmdata.CurrAsmList, OP_OR, opsize, hregister2, href)
  550. else
  551. begin
  552. cg.a_op_reg_reg(current_asmdata.CurrAsmList, OP_NOT, opsize, hregister2, hregister2);
  553. cg.a_op_reg_ref(current_asmdata.CurrAsmList, OP_AND, opsize, hregister2, href);
  554. end;
  555. end;
  556. end;
  557. end;
  558. {*****************************************************************************
  559. FLOAT GENERIC HANDLING
  560. *****************************************************************************}
  561. {
  562. These routines all call internal RTL routines, so if they are
  563. called here, they give an internal error
  564. }
  565. procedure tcginlinenode.second_pi;
  566. begin
  567. internalerror(20020718);
  568. end;
  569. procedure tcginlinenode.second_arctan_real;
  570. begin
  571. internalerror(20020718);
  572. end;
  573. procedure tcginlinenode.second_abs_real;
  574. begin
  575. internalerror(20020718);
  576. end;
  577. procedure tcginlinenode.second_sqr_real;
  578. begin
  579. internalerror(20020718);
  580. end;
  581. procedure tcginlinenode.second_sqrt_real;
  582. begin
  583. internalerror(20020718);
  584. end;
  585. procedure tcginlinenode.second_ln_real;
  586. begin
  587. internalerror(20020718);
  588. end;
  589. procedure tcginlinenode.second_cos_real;
  590. begin
  591. internalerror(20020718);
  592. end;
  593. procedure tcginlinenode.second_sin_real;
  594. begin
  595. internalerror(20020718);
  596. end;
  597. procedure tcginlinenode.second_prefetch;
  598. begin
  599. end;
  600. {*****************************************************************************
  601. ASSIGNED GENERIC HANDLING
  602. *****************************************************************************}
  603. procedure tcginlinenode.second_assigned;
  604. begin
  605. secondpass(tcallparanode(left).left);
  606. { force left to be an OS_ADDR, since in case of method procvars }
  607. { the size is 2*OS_ADDR (JM) }
  608. cg.a_cmp_const_loc_label(current_asmdata.CurrAsmList,OS_ADDR,OC_NE,0,tcallparanode(left).left.location,current_procinfo.CurrTrueLabel);
  609. cg.a_jmp_always(current_asmdata.CurrAsmList,current_procinfo.CurrFalseLabel);
  610. location_reset(location,LOC_JUMP,OS_NO);
  611. end;
  612. procedure Tcginlinenode.second_get_frame;
  613. begin
  614. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  615. begin
  616. location_reset(location,LOC_CONSTANT,OS_ADDR);
  617. location.value:=0;
  618. end
  619. else
  620. begin
  621. location_reset(location,LOC_CREGISTER,OS_ADDR);
  622. location.register:=current_procinfo.framepointer;
  623. end;
  624. end;
  625. procedure Tcginlinenode.second_get_caller_frame;
  626. var frame_ref:Treference;
  627. begin
  628. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  629. begin
  630. location_reset(location,LOC_CREGISTER,OS_ADDR);
  631. location.register:=NR_FRAME_POINTER_REG;
  632. { location_reset(location,LOC_REGISTER,OS_ADDR);
  633. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  634. cg.a_load_reg_reg(current_asmdata.currasmlist,OS_ADDR,OS_ADDR,NR_FRAME_POINTER_REG,location.register);}
  635. end
  636. else
  637. begin
  638. location_reset(location,LOC_REGISTER,OS_ADDR);
  639. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  640. reference_reset_base(frame_ref,current_procinfo.framepointer,0);
  641. cg.a_load_ref_reg(current_asmdata.currasmlist,OS_ADDR,OS_ADDR,frame_ref,location.register);
  642. end;
  643. end;
  644. procedure Tcginlinenode.second_get_caller_addr;
  645. var frame_ref:Treference;
  646. begin
  647. if current_procinfo.framepointer=NR_STACK_POINTER_REG then
  648. begin
  649. location_reset(location,LOC_REGISTER,OS_ADDR);
  650. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  651. reference_reset_base(frame_ref,NR_STACK_POINTER_REG,0);
  652. cg.a_load_ref_reg(current_asmdata.currasmlist,OS_ADDR,OS_ADDR,frame_ref,location.register);
  653. end
  654. else
  655. begin
  656. location_reset(location,LOC_REGISTER,OS_ADDR);
  657. location.register:=cg.getaddressregister(current_asmdata.currasmlist);
  658. {$ifdef cpu64bit}
  659. reference_reset_base(frame_ref,current_procinfo.framepointer,8);
  660. {$else}
  661. reference_reset_base(frame_ref,current_procinfo.framepointer,4);
  662. {$endif}
  663. cg.a_load_ref_reg(current_asmdata.currasmlist,OS_ADDR,OS_ADDR,frame_ref,location.register);
  664. end;
  665. end;
  666. begin
  667. cinlinenode:=tcginlinenode;
  668. end.