ncgcnv.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. {
  2. Copyright (c) 2000-2002 by Florian Klaempfl
  3. Generate assembler for nodes that handle type conversions which are
  4. the same for all (most) processors
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit ncgcnv;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,ncnv,defutil,defcmp;
  23. type
  24. tcgtypeconvnode = class(ttypeconvnode)
  25. procedure second_int_to_int;override;
  26. procedure second_cstring_to_pchar;override;
  27. procedure second_cstring_to_int;override;
  28. procedure second_string_to_chararray;override;
  29. procedure second_array_to_pointer;override;
  30. procedure second_pointer_to_array;override;
  31. procedure second_char_to_string;override;
  32. procedure second_real_to_real;override;
  33. procedure second_cord_to_pointer;override;
  34. procedure second_proc_to_procvar;override;
  35. procedure second_nil_to_methodprocvar;override;
  36. procedure second_bool_to_int;override;
  37. procedure second_bool_to_bool;override;
  38. procedure second_ansistring_to_pchar;override;
  39. procedure second_class_to_intf;override;
  40. procedure second_char_to_char;override;
  41. procedure second_nothing;override;
  42. procedure pass_generate_code;override;
  43. end;
  44. tcgasnode = class(tasnode)
  45. procedure pass_generate_code;override;
  46. end;
  47. implementation
  48. uses
  49. cutils,verbose,globtype,globals,
  50. aasmbase,aasmtai,aasmdata,aasmcpu,symconst,symdef,paramgr,
  51. nutils,ncon,ncal,
  52. cpubase,systems,
  53. procinfo,pass_2,
  54. cgbase,
  55. cgutils,cgobj,
  56. ncgutil,
  57. tgobj
  58. ;
  59. procedure tcgtypeconvnode.second_int_to_int;
  60. var
  61. orgsize,
  62. newsize : tcgsize;
  63. ressize,
  64. leftsize : longint;
  65. begin
  66. newsize:=def_cgsize(resultdef);
  67. { insert range check if not explicit conversion }
  68. if not(nf_explicit in flags) then
  69. cg.g_rangecheck(current_asmdata.CurrAsmList,left.location,left.resultdef,resultdef);
  70. { is the result size smaller? when typecasting from void
  71. we always reuse the current location, because there is
  72. nothing that we can load in a register }
  73. ressize := resultdef.size;
  74. leftsize := left.resultdef.size;
  75. if ((ressize<>leftsize) or
  76. is_bitpacked_access(left)) and
  77. not is_void(left.resultdef) then
  78. begin
  79. location_copy(location,left.location);
  80. { reuse a loc_reference when the newsize is smaller than
  81. than the original, else load it to a register }
  82. if (location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) and
  83. (ressize<leftsize) then
  84. begin
  85. location.size:=newsize;
  86. if (target_info.endian = ENDIAN_BIG) then
  87. begin
  88. inc(location.reference.offset,leftsize-ressize);
  89. location.reference.alignment:=newalignment(location.reference.alignment,leftsize-ressize);
  90. end;
  91. end
  92. else
  93. location_force_reg(current_asmdata.CurrAsmList,location,newsize,false);
  94. end
  95. else
  96. begin
  97. { no special loading is required, reuse current location }
  98. { that's not true, if you go from signed to unsiged or }
  99. { vice versa, you need sign extension/removal if the }
  100. { value is already in a register (at least for archs }
  101. { which don't have 8bit register components etc) (JM) }
  102. location_copy(location,left.location);
  103. location.size:=newsize;
  104. orgsize := def_cgsize(left.resultdef);
  105. if (ressize < sizeof(aint)) and
  106. (location.loc in [LOC_REGISTER,LOC_CREGISTER]) and
  107. (orgsize <> newsize) then
  108. begin
  109. location.register := cg.getintregister(current_asmdata.CurrAsmList,newsize);
  110. location.loc := LOC_REGISTER;
  111. cg.a_load_reg_reg(current_asmdata.CurrAsmList,orgsize,newsize,left.location.register,location.register);
  112. end;
  113. end;
  114. end;
  115. procedure tcgtypeconvnode.second_cstring_to_pchar;
  116. var
  117. hr : treference;
  118. begin
  119. if left.nodetype<>stringconstn then
  120. internalerror(200601131);
  121. location_reset(location,LOC_REGISTER,OS_ADDR);
  122. case tstringconstnode(left).cst_type of
  123. cst_conststring :
  124. begin
  125. location.register:=cg.getaddressregister(current_asmdata.CurrAsmList);
  126. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.location.reference,location.register);
  127. end;
  128. cst_shortstring :
  129. begin
  130. inc(left.location.reference.offset);
  131. location.reference.alignment:=1;
  132. location.register:=cg.getaddressregister(current_asmdata.CurrAsmList);
  133. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.location.reference,location.register);
  134. end;
  135. cst_widestring,
  136. cst_unicodestring,
  137. cst_ansistring :
  138. begin
  139. if tstringconstnode(left).len=0 then
  140. begin
  141. { FPC_EMPTYCHAR is a widechar -> 2 bytes }
  142. reference_reset(hr,2);
  143. hr.symbol:=current_asmdata.RefAsmSymbol('FPC_EMPTYCHAR');
  144. location.register:=cg.getaddressregister(current_asmdata.CurrAsmList);
  145. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,hr,location.register);
  146. end
  147. else
  148. begin
  149. location_copy(location,left.location);
  150. end;
  151. end;
  152. cst_longstring:
  153. begin
  154. {!!!!!!!}
  155. internalerror(8888);
  156. end;
  157. else
  158. internalerror(200808241);
  159. end;
  160. end;
  161. procedure tcgtypeconvnode.second_cstring_to_int;
  162. begin
  163. { this can't happen because constants are already processed in
  164. pass 1 }
  165. internalerror(200510013);
  166. end;
  167. procedure tcgtypeconvnode.second_string_to_chararray;
  168. begin
  169. if is_chararray(left.resultdef) then
  170. begin
  171. location_copy(location,left.location);
  172. exit;
  173. end;
  174. { should be handled already in resultdef pass (JM) }
  175. internalerror(200108292);
  176. end;
  177. procedure tcgtypeconvnode.second_array_to_pointer;
  178. begin
  179. location_reset(location,LOC_REGISTER,OS_ADDR);
  180. location.register:=cg.getaddressregister(current_asmdata.CurrAsmList);
  181. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.location.reference,location.register);
  182. end;
  183. procedure tcgtypeconvnode.second_pointer_to_array;
  184. begin
  185. { assume natural alignment }
  186. location_reset_ref(location,LOC_REFERENCE,OS_NO,resultdef.alignment);
  187. case left.location.loc of
  188. LOC_CREGISTER,
  189. LOC_REGISTER :
  190. begin
  191. {$ifdef cpu_uses_separate_address_registers}
  192. if getregtype(left.location.register)<>R_ADDRESSREGISTER then
  193. begin
  194. location.reference.base:=rg.getaddressregister(current_asmdata.CurrAsmList);
  195. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,
  196. left.location.register,location.reference.base);
  197. end
  198. else
  199. {$endif}
  200. location.reference.base := left.location.register;
  201. end;
  202. LOC_REFERENCE,
  203. LOC_CREFERENCE :
  204. begin
  205. location.reference.base:=cg.getaddressregister(current_asmdata.CurrAsmList);
  206. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,left.location.reference,
  207. location.reference.base);
  208. location_freetemp(current_asmdata.CurrAsmList,left.location);
  209. end;
  210. else
  211. internalerror(2002032216);
  212. end;
  213. end;
  214. procedure tcgtypeconvnode.second_char_to_string;
  215. begin
  216. location_reset_ref(location,LOC_REFERENCE,OS_NO,2);
  217. case tstringdef(resultdef).stringtype of
  218. st_shortstring :
  219. begin
  220. tg.GetTemp(current_asmdata.CurrAsmList,256,2,tt_normal,location.reference);
  221. cg.a_load_loc_ref(current_asmdata.CurrAsmList,left.location.size,left.location,
  222. location.reference);
  223. location_freetemp(current_asmdata.CurrAsmList,left.location);
  224. end;
  225. { the rest is removed in the resultdef pass and converted to compilerprocs }
  226. else
  227. internalerror(4179);
  228. end;
  229. end;
  230. procedure tcgtypeconvnode.second_real_to_real;
  231. {$ifdef x86}
  232. var
  233. tr: treference;
  234. {$endif x86}
  235. begin
  236. location_reset(location,expectloc,def_cgsize(resultdef));
  237. {$ifdef x86}
  238. { extended types in memory which should be loaded into the sse unit
  239. must be converted by the fpu first, so force them to be loaded into
  240. the fpu }
  241. if (expectloc=LOC_MMREGISTER) and
  242. (left.location.size in [OS_F80,OS_C64]) then
  243. begin
  244. if (left.location.loc in [LOC_CREFERENCE,LOC_REFERENCE]) then
  245. location_force_fpureg(current_asmdata.CurrAsmList,left.location,false);
  246. { round them down to the proper precision }
  247. tg.gettemp(current_asmdata.currasmlist,resultdef.size,resultdef.alignment,tt_normal,tr);
  248. cg.a_loadfpu_reg_ref(current_asmdata.CurrAsmList,left.location.size,location.size,left.location.register,tr);
  249. location_reset_ref(left.location,LOC_REFERENCE,location.size,tr.alignment);
  250. left.location.reference:=tr;
  251. end;
  252. {$endif x86}
  253. { ARM VFP values are in integer registers when they are function results }
  254. if (left.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  255. location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,false);
  256. case left.location.loc of
  257. LOC_FPUREGISTER,
  258. LOC_CFPUREGISTER:
  259. begin
  260. case expectloc of
  261. LOC_FPUREGISTER:
  262. begin
  263. { on sparc a move from double -> single means from two to one register. }
  264. { On all other platforms it also needs rounding to avoid that }
  265. { single(double_regvar) = double_regvar is true in all cases }
  266. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  267. cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmList,left.location.size,location.size,left.location.register,location.register);
  268. end;
  269. LOC_MMREGISTER:
  270. begin
  271. location_force_mmregscalar(current_asmdata.CurrAsmList,left.location,false);
  272. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  273. cg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,left.location.size,location.size,left.location.register,location.register,mms_movescalar);
  274. end
  275. else
  276. internalerror(2003012262);
  277. end;
  278. exit
  279. end;
  280. LOC_CREFERENCE,
  281. LOC_REFERENCE:
  282. begin
  283. if expectloc=LOC_MMREGISTER then
  284. begin
  285. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  286. cg.a_loadmm_loc_reg(current_asmdata.CurrAsmList,location.size,left.location,location.register,mms_movescalar)
  287. end
  288. else
  289. begin
  290. location_force_fpureg(current_asmdata.CurrAsmList,left.location,false);
  291. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  292. cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmList,left.location.size,location.size,left.location.register,location.register);
  293. end;
  294. location_freetemp(current_asmdata.CurrAsmList,left.location);
  295. end;
  296. LOC_MMREGISTER,
  297. LOC_CMMREGISTER:
  298. begin
  299. case expectloc of
  300. LOC_FPUREGISTER:
  301. begin
  302. location_force_fpureg(current_asmdata.CurrAsmList,left.location,false);
  303. location.register:=cg.getfpuregister(current_asmdata.CurrAsmList,location.size);
  304. cg.a_loadfpu_reg_reg(current_asmdata.CurrAsmList,left.location.size,location.size,left.location.register,location.register);
  305. end;
  306. LOC_MMREGISTER:
  307. begin
  308. location.register:=cg.getmmregister(current_asmdata.CurrAsmList,location.size);
  309. cg.a_loadmm_reg_reg(current_asmdata.CurrAsmList,left.location.size,location.size,left.location.register,location.register,mms_movescalar);
  310. end;
  311. else
  312. internalerror(2003012261);
  313. end;
  314. end;
  315. else
  316. internalerror(2002032215);
  317. end;
  318. end;
  319. procedure tcgtypeconvnode.second_cord_to_pointer;
  320. begin
  321. { this can't happen because constants are already processed in
  322. pass 1 }
  323. internalerror(47423985);
  324. end;
  325. procedure tcgtypeconvnode.second_proc_to_procvar;
  326. var
  327. tmpreg: tregister;
  328. begin
  329. if tabstractprocdef(resultdef).is_addressonly then
  330. begin
  331. location_reset(location,LOC_REGISTER,OS_ADDR);
  332. location.register:=cg.getaddressregister(current_asmdata.CurrAsmList);
  333. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.location.reference,location.register);
  334. end
  335. else
  336. begin
  337. if not tabstractprocdef(left.resultdef).is_addressonly then
  338. location_copy(location,left.location)
  339. else
  340. begin
  341. { assigning a global function to a nested procvar -> create
  342. tmethodpointer record and set the "frame pointer" to nil }
  343. location_reset_ref(location,LOC_REFERENCE,int_cgsize(sizeof(pint)*2),sizeof(pint));
  344. tg.gettemp(current_asmdata.CurrAsmList,resultdef.size,sizeof(pint),tt_normal,location.reference);
  345. tmpreg:=cg.getaddressregister(current_asmdata.CurrAsmList);
  346. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,left.location.reference,tmpreg);
  347. cg.a_load_reg_ref(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,tmpreg,location.reference);
  348. { setting the frame pointer to nil is not strictly necessary
  349. since the global procedure won't use it, but it can help with
  350. debugging }
  351. inc(location.reference.offset,sizeof(pint));
  352. cg.a_load_const_ref(current_asmdata.CurrAsmList,OS_ADDR,0,location.reference);
  353. dec(location.reference.offset,sizeof(pint));
  354. end;
  355. end;
  356. end;
  357. procedure Tcgtypeconvnode.second_nil_to_methodprocvar;
  358. var r:Treference;
  359. begin
  360. tg.gettemp(current_asmdata.currasmlist,2*sizeof(puint),sizeof(puint),tt_normal,r);
  361. location_reset_ref(location,LOC_REFERENCE,def_cgsize(resultdef),0);
  362. location.reference:=r;
  363. cg.a_load_const_ref(current_asmdata.currasmlist,OS_ADDR,0,r);
  364. inc(r.offset,sizeof(puint));
  365. cg.a_load_const_ref(current_asmdata.currasmlist,OS_ADDR,0,r);
  366. end;
  367. procedure tcgtypeconvnode.second_bool_to_int;
  368. var
  369. newsize: tcgsize;
  370. oldTrueLabel,oldFalseLabel : tasmlabel;
  371. begin
  372. oldTrueLabel:=current_procinfo.CurrTrueLabel;
  373. oldFalseLabel:=current_procinfo.CurrFalseLabel;
  374. current_asmdata.getjumplabel(current_procinfo.CurrTrueLabel);
  375. current_asmdata.getjumplabel(current_procinfo.CurrFalseLabel);
  376. secondpass(left);
  377. location_copy(location,left.location);
  378. newsize:=def_cgsize(resultdef);
  379. { byte(bytebool) or word(wordbool) or longint(longbool) must be }
  380. { accepted for var parameters and assignments, and must not }
  381. { change the ordinal value or value location. }
  382. { htypechk.valid_for_assign ensures that such locations with a }
  383. { size<sizeof(register) cannot be LOC_CREGISTER (they otherwise }
  384. { could be in case of a plain assignment), and LOC_REGISTER can }
  385. { never be an assignment target. The remaining LOC_REGISTER/ }
  386. { LOC_CREGISTER locations do have to be sign/zero-extended. }
  387. if not(nf_explicit in flags) or
  388. (location.loc in [LOC_FLAGS,LOC_JUMP]) or
  389. { change of size/signedness? Then we have to sign/ }
  390. { zero-extend in case of a loc_(c)register }
  391. ((newsize<>left.location.size) and
  392. ((left.resultdef.size<>resultdef.size) or
  393. not(location.loc in [LOC_REFERENCE,LOC_CREFERENCE]))) then
  394. location_force_reg(current_asmdata.CurrAsmList,location,newsize,true)
  395. else
  396. { may differ in sign, e.g. bytebool -> byte }
  397. location.size:=newsize;
  398. current_procinfo.CurrTrueLabel:=oldTrueLabel;
  399. current_procinfo.CurrFalseLabel:=oldFalseLabel;
  400. end;
  401. procedure tcgtypeconvnode.second_bool_to_bool;
  402. begin
  403. { we can reuse the conversion already available
  404. in bool_to_int to resize the value. But when the
  405. size of the new boolean is smaller we need to calculate
  406. the value as is done in int_to_bool. This is needed because
  407. the bits that define the true status can be outside the limits
  408. of the new size and truncating the register can result in a 0
  409. value }
  410. if (left.expectloc in [LOC_FLAGS,LOC_JUMP]) and
  411. { a cbool must be converted to -1/0 }
  412. not is_cbool(resultdef) then
  413. begin
  414. secondpass(left);
  415. if (left.location.loc <> left.expectloc) then
  416. internalerror(2010081601);
  417. location_copy(location,left.location);
  418. end
  419. else if (resultdef.size=left.resultdef.size) and
  420. (is_cbool(resultdef)=is_cbool(left.resultdef)) then
  421. second_bool_to_int
  422. else
  423. begin
  424. if (resultdef.size<>left.resultdef.size) then
  425. { remove nf_explicit to perform full conversion if boolean sizes are different }
  426. exclude(flags, nf_explicit);
  427. second_int_to_bool;
  428. end;
  429. end;
  430. procedure tcgtypeconvnode.second_ansistring_to_pchar;
  431. var
  432. l1 : tasmlabel;
  433. hr : treference;
  434. begin
  435. location_reset(location,LOC_REGISTER,OS_ADDR);
  436. current_asmdata.getjumplabel(l1);
  437. case left.location.loc of
  438. LOC_CREGISTER,LOC_REGISTER:
  439. begin
  440. {$ifdef cpu_uses_separate_address_registers}
  441. if getregtype(left.location.register)<>R_ADDRESSREGISTER then
  442. begin
  443. location.register:=cg.getaddressregister(current_asmdata.CurrAsmList);
  444. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,
  445. left.location.register,location.register);
  446. end
  447. else
  448. {$endif}
  449. location.register := left.location.register;
  450. end;
  451. LOC_CREFERENCE,LOC_REFERENCE:
  452. begin
  453. location.register:=cg.getaddressregister(current_asmdata.CurrAsmList);
  454. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,left.location.reference,location.register);
  455. end;
  456. else
  457. internalerror(2002032214);
  458. end;
  459. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_ADDR,OC_NE,0,location.register,l1);
  460. { FPC_EMPTYCHAR is a widechar -> 2 bytes }
  461. reference_reset(hr,2);
  462. hr.symbol:=current_asmdata.RefAsmSymbol('FPC_EMPTYCHAR');
  463. cg.a_loadaddr_ref_reg(current_asmdata.CurrAsmList,hr,location.register);
  464. cg.a_label(current_asmdata.CurrAsmList,l1);
  465. end;
  466. procedure tcgtypeconvnode.second_class_to_intf;
  467. var
  468. l1 : tasmlabel;
  469. hd : tobjectdef;
  470. ImplIntf : TImplementedInterface;
  471. begin
  472. location_reset(location,LOC_REGISTER,OS_ADDR);
  473. case left.location.loc of
  474. LOC_CREFERENCE,
  475. LOC_REFERENCE:
  476. begin
  477. location.register:=cg.getaddressregister(current_asmdata.CurrAsmList);
  478. cg.a_load_ref_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,left.location.reference,location.register);
  479. location_freetemp(current_asmdata.CurrAsmList,left.location);
  480. end;
  481. LOC_CREGISTER:
  482. begin
  483. location.register:=cg.getaddressregister(current_asmdata.CurrAsmList);
  484. cg.a_load_reg_reg(current_asmdata.CurrAsmList,OS_ADDR,OS_ADDR,left.location.register,location.register);
  485. end;
  486. LOC_REGISTER:
  487. location.register:=left.location.register;
  488. else
  489. internalerror(121120001);
  490. end;
  491. hd:=tobjectdef(left.resultdef);
  492. while assigned(hd) do
  493. begin
  494. ImplIntf:=hd.find_implemented_interface(tobjectdef(resultdef));
  495. if assigned(ImplIntf) then
  496. begin
  497. case ImplIntf.IType of
  498. etStandard:
  499. begin
  500. current_asmdata.getjumplabel(l1);
  501. cg.a_cmp_const_reg_label(current_asmdata.CurrAsmList,OS_ADDR,OC_EQ,0,location.register,l1);
  502. cg.a_op_const_reg(current_asmdata.CurrAsmList,OP_ADD,OS_ADDR,ImplIntf.ioffset,location.register);
  503. break;
  504. end;
  505. else
  506. internalerror(200802163);
  507. end;
  508. end;
  509. hd:=hd.childof;
  510. end;
  511. if hd=nil then
  512. internalerror(2002081301);
  513. cg.a_label(current_asmdata.CurrAsmList,l1);
  514. end;
  515. procedure tcgtypeconvnode.second_char_to_char;
  516. begin
  517. internalerror(2007081202);
  518. end;
  519. procedure tcgtypeconvnode.second_nothing;
  520. var
  521. newsize : tcgsize;
  522. begin
  523. { we reuse the old value }
  524. location_copy(location,left.location);
  525. { Floats should never be returned as LOC_CONSTANT, do the
  526. moving to memory before the new size is set.
  527. Also when converting from a float to a non-float
  528. or the other way round, move to memory first to prevent
  529. invalid LOC_FPUREGISTER locations }
  530. if (
  531. (resultdef.typ=floatdef) and
  532. (location.loc=LOC_CONSTANT)
  533. ) or
  534. (
  535. (left.resultdef.typ=floatdef) xor
  536. (resultdef.typ=floatdef)
  537. ) then
  538. location_force_mem(current_asmdata.CurrAsmList,location);
  539. { but use the new size, but we don't know the size of all arrays }
  540. newsize:=def_cgsize(resultdef);
  541. location.size:=newsize;
  542. end;
  543. {$ifdef TESTOBJEXT2}
  544. procedure tcgtypeconvnode.checkobject;
  545. begin
  546. { no checking by default }
  547. end;
  548. {$endif TESTOBJEXT2}
  549. procedure tcgtypeconvnode.pass_generate_code;
  550. begin
  551. { the boolean routines can be called with LOC_JUMP and
  552. call secondpass themselves in the helper }
  553. if not(convtype in [tc_bool_2_int,tc_bool_2_bool,tc_int_2_bool]) then
  554. begin
  555. secondpass(left);
  556. if codegenerror then
  557. exit;
  558. end;
  559. second_call_helper(convtype);
  560. {$ifdef TESTOBJEXT2}
  561. { Check explicit conversions to objects pointers !! }
  562. if p^.explizit and
  563. (p^.resultdef.typ=pointerdef) and
  564. (tpointerdef(p^.resultdef).definition.typ=objectdef) and not
  565. (tobjectdef(tpointerdef(p^.resultdef).definition).isclass) and
  566. ((tobjectdef(tpointerdef(p^.resultdef).definition).options and oo_hasvmt)<>0) and
  567. (cs_check_range in current_settings.localswitches) then
  568. checkobject;
  569. {$endif TESTOBJEXT2}
  570. end;
  571. procedure tcgasnode.pass_generate_code;
  572. begin
  573. secondpass(call);
  574. location_copy(location,call.location);
  575. end;
  576. begin
  577. ctypeconvnode := tcgtypeconvnode;
  578. casnode := tcgasnode;
  579. end.