njvminl.pas 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. {
  2. Copyright (c) 1998-2011 by Florian Klaempfl and Jonas Maebe
  3. Generate JVM 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 njvminl;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cpubase,
  22. node,ninl,ncginl;
  23. type
  24. tjvminlinenode = class(tcginlinenode)
  25. protected
  26. function typecheck_length(var handled: boolean): tnode;
  27. function typecheck_high(var handled: boolean): tnode;
  28. function typecheck_new(var handled: boolean): tnode;
  29. function first_copy: tnode; override;
  30. function first_setlength_array: tnode;
  31. function first_setlength_string: tnode;
  32. public
  33. { typecheck override to intercept handling }
  34. function pass_typecheck: tnode; override;
  35. { first pass override
  36. so that the code generator will actually generate
  37. these nodes.
  38. }
  39. (*
  40. function first_sqrt_real: tnode; override;
  41. *)
  42. function first_sqr_real: tnode; override;
  43. function first_trunc_real: tnode; override;
  44. (*
  45. function first_round_real: tnode; override;
  46. *)
  47. function first_new: tnode; override;
  48. function first_setlength: tnode; override;
  49. function first_length: tnode; override;
  50. procedure second_length; override;
  51. (*
  52. procedure second_sqrt_real; override;
  53. procedure second_abs_real; override;
  54. *)
  55. procedure second_sqr_real; override;
  56. procedure second_trunc_real; override;
  57. (*
  58. procedure second_round_real; override;
  59. *)
  60. procedure second_new; override;
  61. procedure second_setlength; override;
  62. protected
  63. procedure load_fpu_location;
  64. end;
  65. implementation
  66. uses
  67. cutils,globals,verbose,globtype,constexp,
  68. aasmbase,aasmtai,aasmdata,aasmcpu,
  69. symtype,symconst,symdef,symsym,symtable,jvmdef,
  70. defutil,
  71. nbas,ncon,ncnv,ncal,nld,nflw,nutils,
  72. cgbase,pass_1,pass_2,
  73. cpuinfo,ncgutil,
  74. cgutils,hlcgobj,hlcgcpu;
  75. {*****************************************************************************
  76. tjvminlinenode
  77. *****************************************************************************}
  78. function tjvminlinenode.typecheck_length(var handled: boolean): tnode;
  79. begin
  80. typecheckpass(left);
  81. if is_dynamic_array(left.resultdef) or
  82. is_open_array(left.resultdef) or
  83. is_wide_or_unicode_string(left.resultdef) then
  84. begin
  85. resultdef:=s32inttype;
  86. result:=nil;
  87. handled:=true;
  88. end;
  89. end;
  90. function tjvminlinenode.typecheck_high(var handled: boolean): tnode;
  91. begin
  92. typecheckpass(left);
  93. if is_dynamic_array(left.resultdef) or
  94. is_open_array(left.resultdef) then
  95. begin
  96. { replace with pred(length(arr)) }
  97. result:=cinlinenode.create(in_pred_x,false,
  98. cinlinenode.create(in_length_x,false,left));
  99. left:=nil;
  100. handled:=true;
  101. end;
  102. end;
  103. function tjvminlinenode.typecheck_new(var handled: boolean): tnode;
  104. var
  105. para: tcallparanode;
  106. elemdef: tdef;
  107. begin
  108. { normally never exists; used by the JVM backend to create new
  109. arrays because it requires special opcodes }
  110. tcallparanode(left).get_paratype;
  111. if is_dynamic_array(left.resultdef) then
  112. begin
  113. para:=tcallparanode(left);
  114. { need at least one extra parameter in addition to the
  115. array }
  116. if not assigned(para.right) then
  117. internalerror(2011012206);
  118. elemdef:=tarraydef(left.resultdef).elementdef;
  119. while elemdef.typ=arraydef do
  120. begin
  121. { if we have less length specifiers than dimensions, make
  122. the last array an array of length 0 }
  123. if not assigned(para.right) then
  124. begin
  125. para.right:=ccallparanode.create(
  126. cordconstnode.create(0,s32inttype,false),nil);
  127. tcallparanode(para.right).get_paratype;
  128. break;
  129. end
  130. else
  131. begin
  132. inserttypeconv(tcallparanode(para.right).left,s32inttype);
  133. tcallparanode(para.right).get_paratype;
  134. end;
  135. para:=tcallparanode(para.right);
  136. elemdef:=tarraydef(elemdef).elementdef;
  137. end;
  138. result:=nil;
  139. resultdef:=left.resultdef;
  140. handled:=true;
  141. end;
  142. end;
  143. function tjvminlinenode.first_copy: tnode;
  144. var
  145. ppn: tcallparanode;
  146. arr, len, start, kind: tnode;
  147. eledef: tdef;
  148. counter, ndims: longint;
  149. finaltype: char;
  150. begin
  151. if is_dynamic_array(resultdef) then
  152. begin
  153. ppn:=tcallparanode(left);
  154. counter:=1;
  155. while assigned(ppn.right) do
  156. begin
  157. inc(counter);
  158. ppn:=tcallparanode(ppn.right);
  159. end;
  160. if (counter=3) then
  161. begin
  162. len:=tcallparanode(left).left;
  163. tcallparanode(left).left:=nil;
  164. start:=tcallparanode(tcallparanode(left).right).left;
  165. tcallparanode(tcallparanode(left).right).left:=nil;
  166. { free the original start/len paras and remove them }
  167. ppn:=tcallparanode(left);
  168. left:=tcallparanode(tcallparanode(left).right).right;
  169. tcallparanode(ppn.right).right:=nil;
  170. ppn.free;
  171. end
  172. else
  173. begin
  174. { use special -1,-1 argument to copy the whole array }
  175. len:=genintconstnode(-1);
  176. start:=genintconstnode(-1);
  177. end;
  178. { currently there is one parameter left: the array itself }
  179. arr:=tcallparanode(left).left;
  180. tcallparanode(left).left:=nil;
  181. { in case it's a dynamic array of static arrays, get the dimensions
  182. of the static array components }
  183. eledef:=tarraydef(resultdef).elementdef;
  184. ndims:=1;
  185. while (eledef.typ=arraydef) and
  186. not is_dynamic_array(eledef) do
  187. begin
  188. inc(ndims);
  189. eledef:=tarraydef(eledef).elementdef;
  190. end;
  191. { get the final element kind }
  192. finaltype:=jvmarrtype_setlength(eledef);
  193. { construct the call to
  194. fpc_dynarray_copy(src: JLObject; start, len: longint; ndim: longint; eletype: jchar) }
  195. result:=ccallnode.createintern('FPC_DYNARRAY_COPY',
  196. ccallparanode.create(cordconstnode.create(ord(finaltype),cwidechartype,false),
  197. ccallparanode.create(genintconstnode(ndims),
  198. ccallparanode.create(len,
  199. ccallparanode.create(start,
  200. ccallparanode.create(ctypeconvnode.create_explicit(arr,java_jlobject),nil)
  201. )
  202. )
  203. )
  204. )
  205. );
  206. inserttypeconv_explicit(result,resultdef);
  207. end
  208. else
  209. result:=inherited first_copy;
  210. end;
  211. function tjvminlinenode.pass_typecheck: tnode;
  212. var
  213. handled: boolean;
  214. begin
  215. handled:=false;
  216. case inlinenumber of
  217. in_length_x:
  218. begin
  219. result:=typecheck_length(handled);
  220. end;
  221. in_high_x:
  222. begin
  223. result:=typecheck_high(handled);
  224. end;
  225. in_new_x:
  226. begin
  227. result:=typecheck_new(handled);
  228. end;
  229. end;
  230. if not handled then
  231. result:=inherited pass_typecheck;
  232. end;
  233. (*
  234. function tjvminlinenode.first_sqrt_real : tnode;
  235. begin
  236. if (current_settings.cputype >= cpu_PPC970) then
  237. begin
  238. expectloc:=LOC_FPUREGISTER;
  239. first_sqrt_real := nil;
  240. end
  241. else
  242. result:=inherited first_sqrt_real;
  243. end;
  244. *)
  245. function tjvminlinenode.first_sqr_real : tnode;
  246. begin
  247. expectloc:=LOC_FPUREGISTER;
  248. first_sqr_real:=nil;
  249. end;
  250. function tjvminlinenode.first_trunc_real : tnode;
  251. begin
  252. expectloc:=LOC_REGISTER;
  253. first_trunc_real:=nil;
  254. end;
  255. function tjvminlinenode.first_new: tnode;
  256. begin
  257. { skip the array; it's a type node }
  258. tcallparanode(tcallparanode(left).right).firstcallparan;
  259. expectloc:=LOC_REGISTER;
  260. result:=nil;
  261. end;
  262. function tjvminlinenode.first_setlength_array: tnode;
  263. var
  264. assignmenttarget,
  265. ppn,
  266. newparas: tnode;
  267. newnode: tnode;
  268. eledef,
  269. objarraydef: tdef;
  270. ndims: longint;
  271. finaltype: char;
  272. setlenroutine: string;
  273. lefttemp: ttempcreatenode;
  274. newblock: tblocknode;
  275. newstatement: tstatementnode;
  276. primitive: boolean;
  277. begin
  278. { first parameter is the array, the rest are the dimensions }
  279. newparas:=tcallparanode(left).right;
  280. tcallparanode(left).right:=nil;
  281. { count the number of specified dimensions, and determine the type of
  282. the final one }
  283. ppn:=newparas;
  284. eledef:=tarraydef(left.resultdef).elementdef;
  285. { ppn already points to the first dimension }
  286. ndims:=1;
  287. while assigned(tcallparanode(ppn).right) do
  288. begin
  289. inc(ndims);
  290. eledef:=tarraydef(eledef).elementdef;
  291. ppn:=tcallparanode(ppn).right;
  292. end;
  293. { in case it's a dynamic array of static arrays, we must also allocate
  294. the static arrays! }
  295. while (eledef.typ=arraydef) and
  296. not is_dynamic_array(eledef) do
  297. begin
  298. inc(ndims);
  299. tcallparanode(ppn).right:=
  300. ccallparanode.create(
  301. genintconstnode(tarraydef(eledef).elecount),nil);
  302. ppn:=tcallparanode(ppn).right;
  303. eledef:=tarraydef(eledef).elementdef;
  304. end;
  305. { prepend type parameter for the array }
  306. newparas:=ccallparanode.create(ctypenode.create(left.resultdef),newparas);
  307. ttypenode(tcallparanode(newparas).left).allowed:=true;
  308. { node to create the new array }
  309. newnode:=cinlinenode.create(in_new_x,false,newparas);
  310. { Common parameters for setlength helper }
  311. { start with org (save assignmenttarget itself to assign the result back to) }
  312. { store left into a temp in case it may contain a function call
  313. (which must not be evaluated twice) }
  314. lefttemp:=maybereplacewithtempref(tcallparanode(left).left,tcallparanode(left).left.resultdef.size,false);
  315. if assigned(lefttemp) then
  316. begin
  317. newblock:=internalstatements(newstatement);
  318. addstatement(newstatement,lefttemp);
  319. assignmenttarget:=ctemprefnode.create(lefttemp);
  320. typecheckpass(tnode(assignmenttarget));
  321. end
  322. else
  323. assignmenttarget:=tcallparanode(left).left.getcopy;
  324. newparas:=left;
  325. left:=nil;
  326. finaltype:=jvmarrtype_setlength(eledef);
  327. { since the setlength prototypes require certain types, insert
  328. explicit type conversions where necessary }
  329. objarraydef:=nil;
  330. if (ndims>1) then
  331. begin
  332. { expects array of JLObject }
  333. setlenroutine:='FPC_SETLENGTH_DYNARR_MULTIDIM';
  334. objarraydef:=search_system_type('TJOBJECTARRAY').typedef
  335. end
  336. else
  337. begin
  338. if finaltype<>'R' then
  339. begin
  340. { expects JLObject }
  341. setlenroutine:='FPC_SETLENGTH_DYNARR_GENERIC';
  342. objarraydef:=java_jlobject;
  343. end
  344. else
  345. begin
  346. { expects array of FpcBaseRecord}
  347. setlenroutine:='FPC_SETLENGTH_DYNARR_JRECORD';
  348. objarraydef:=search_system_type('TJRECORDARRAY').typedef;
  349. end;
  350. end;
  351. tcallparanode(newparas).left:=ctypeconvnode.create_explicit(tcallparanode(newparas).left,objarraydef);
  352. newnode:=ctypeconvnode.create_explicit(newnode,objarraydef);
  353. { prepend new }
  354. newparas:=ccallparanode.create(newnode,newparas);
  355. { prepend deepcopy }
  356. newparas:=ccallparanode.create(cordconstnode.create(0,pasbool8type,false),newparas);
  357. { call the right setlenght helper }
  358. if ndims>1 then
  359. begin
  360. { create proper parameters, from right to left:
  361. eletype=finaltype, ndim=ndims, deepcopy=false, new=newnode,
  362. assignmenttarget=tcallparanode(left).left }
  363. { prepend ndim }
  364. newparas:=ccallparanode.create(cordconstnode.create(ndims,s32inttype,false),newparas);
  365. { prepend eletype }
  366. newparas:=ccallparanode.create(cordconstnode.create(ord(finaltype),cwidechartype,false),newparas);
  367. end
  368. else
  369. begin
  370. { create proper parameters, from right to left:
  371. deepcopy=false, new=newnode, assignmenttarget=tcallparnode(left).left
  372. -> already done in common part above }
  373. end;
  374. result:=ccallnode.createintern(setlenroutine,newparas);
  375. { assign result back to org (no call-by-reference for Java) }
  376. result:=cassignmentnode.create(assignmenttarget,
  377. ctypeconvnode.create_explicit(result,assignmenttarget.resultdef));
  378. if assigned(lefttemp) then
  379. begin
  380. addstatement(newstatement,result);
  381. addstatement(newstatement,ctempdeletenode.create(lefttemp));
  382. result:=newblock;
  383. end;
  384. end;
  385. function tjvminlinenode.first_setlength_string: tnode;
  386. var
  387. newblock: tblocknode;
  388. newstatement: tstatementnode;
  389. lefttemp: ttempcreatenode;
  390. assignmenttarget: tnode;
  391. begin
  392. if is_wide_or_unicode_string(left.resultdef) then
  393. begin
  394. { store left into a temp in case it may contain a function call
  395. (which must not be evaluated twice) }
  396. lefttemp:=maybereplacewithtempref(tcallparanode(left).left,tcallparanode(left).left.resultdef.size,false);
  397. if assigned(lefttemp) then
  398. begin
  399. newblock:=internalstatements(newstatement);
  400. addstatement(newstatement,lefttemp);
  401. assignmenttarget:=ctemprefnode.create(lefttemp);
  402. typecheckpass(tnode(assignmenttarget));
  403. end
  404. else
  405. assignmenttarget:=tcallparanode(left).left.getcopy;
  406. { back to original order for the call }
  407. left:=reverseparameters(tcallparanode(left));
  408. result:=cassignmentnode.create(assignmenttarget,
  409. ccallnode.createintern('fpc_unicodestr_setlength',left));
  410. if assigned(lefttemp) then
  411. begin
  412. addstatement(newstatement,result);
  413. addstatement(newstatement,ctempdeletenode.create(lefttemp));
  414. result:=newblock;
  415. end;
  416. left:=nil;
  417. end
  418. {$ifndef nounsupported}
  419. else if left.resultdef.typ=stringdef then
  420. begin
  421. result:=cnothingnode.create;
  422. end
  423. {$endif}
  424. else
  425. internalerror(2011031405);
  426. end;
  427. function tjvminlinenode.first_setlength: tnode;
  428. begin
  429. { reverse the parameter order so we can process them more easily }
  430. left:=reverseparameters(tcallparanode(left));
  431. { treat setlength(x,0) specially: used to init uninitialised locations }
  432. if not assigned(tcallparanode(tcallparanode(left).right).right) and
  433. is_constintnode(tcallparanode(tcallparanode(left).right).left) and
  434. (tordconstnode(tcallparanode(tcallparanode(left).right).left).value=0) then
  435. begin
  436. result:=nil;
  437. expectloc:=LOC_VOID;
  438. exit;
  439. end;
  440. case left.resultdef.typ of
  441. arraydef:
  442. result:=first_setlength_array;
  443. stringdef:
  444. result:=first_setlength_string;
  445. else
  446. internalerror(2011031204);
  447. end;
  448. end;
  449. function tjvminlinenode.first_length: tnode;
  450. var
  451. newblock: tblocknode;
  452. newstatement: tstatementnode;
  453. lentemp: ttempcreatenode;
  454. ifcond,
  455. stringnonnull,
  456. stringnull: tnode;
  457. psym: tsym;
  458. begin
  459. if is_wide_or_unicode_string(left.resultdef) then
  460. begin
  461. { if assigned(JLString(left)) then
  462. lentemp:=JLString(left).length()
  463. else
  464. lentemp:=0;
  465. --> return lentemp
  466. }
  467. newblock:=internalstatements(newstatement);
  468. lentemp:=ctempcreatenode.create(s32inttype,s32inttype.size,tt_persistent,true);
  469. addstatement(newstatement,lentemp);
  470. { if-condition }
  471. ifcond:=cinlinenode.create(in_assigned_x,false,
  472. ccallparanode.create(ctypeconvnode.create_explicit(left.getcopy,java_jlstring),nil));
  473. { then-path (reuse left, since last use) }
  474. psym:=search_struct_member(java_jlstring,'LENGTH');
  475. if not assigned(psym) or
  476. (psym.typ<>procsym) then
  477. internalerror(2011031403);
  478. stringnonnull:=cassignmentnode.create(
  479. ctemprefnode.create(lentemp),
  480. ccallnode.create(nil,tprocsym(psym),psym.owner,
  481. ctypeconvnode.create_explicit(left,java_jlstring),[]));
  482. left:=nil;
  483. { else-path}
  484. stringnull:=cassignmentnode.create(
  485. ctemprefnode.create(lentemp),
  486. genintconstnode(0));
  487. { complete if-statement }
  488. addstatement(newstatement,cifnode.create(ifcond,stringnonnull,stringnull));
  489. { return temp }
  490. addstatement(newstatement,ctempdeletenode.create_normal_temp(lentemp));
  491. addstatement(newstatement,ctemprefnode.create(lentemp));
  492. result:=newblock;
  493. end
  494. {$ifndef nounsupported}
  495. else if left.resultdef.typ=stringdef then
  496. begin
  497. end
  498. {$endif}
  499. else
  500. result:=inherited first_length;
  501. end;
  502. procedure tjvminlinenode.second_length;
  503. begin
  504. if is_dynamic_array(left.resultdef) or
  505. is_open_array(left.resultdef) then
  506. begin
  507. location_reset(location,LOC_REGISTER,OS_S32);
  508. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,s32inttype);
  509. secondpass(left);
  510. thlcgjvm(hlcg).g_getarraylen(current_asmdata.CurrAsmList,left.location);
  511. thlcgjvm(hlcg).a_load_stack_reg(current_asmdata.CurrAsmList,resultdef,location.register);
  512. end
  513. {$ifndef nounsupported}
  514. else if left.resultdef.typ=stringdef then
  515. begin
  516. thlcgjvm(hlcg).a_load_const_stack(current_asmdata.CurrAsmList,java_jlobject,0,R_ADDRESSREGISTER);
  517. end
  518. {$endif}
  519. else
  520. internalerror(2011012004);
  521. end;
  522. (*
  523. function tjvminlinenode.first_round_real : tnode;
  524. begin
  525. if (current_settings.cputype >= cpu_PPC970) then
  526. begin
  527. expectloc:=LOC_REFERENCE;
  528. first_round_real := nil;
  529. end
  530. else
  531. result:=inherited first_round_real;
  532. end;
  533. *)
  534. { load the FPU value on the evaluation stack }
  535. procedure tjvminlinenode.load_fpu_location;
  536. begin
  537. secondpass(left);
  538. thlcgjvm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,left.resultdef,left.location);
  539. end;
  540. (*
  541. procedure tjvminlinenode.second_sqrt_real;
  542. begin
  543. if (current_settings.cputype < cpu_PPC970) then
  544. internalerror(2007020910);
  545. location.loc:=LOC_FPUREGISTER;
  546. load_fpu_location;
  547. case left.location.size of
  548. OS_F32:
  549. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FSQRTS,location.register,
  550. left.location.register));
  551. OS_F64:
  552. current_asmdata.CurrAsmList.concat(taicpu.op_reg_reg(A_FSQRT,location.register,
  553. left.location.register));
  554. else
  555. inherited;
  556. end;
  557. end;
  558. *)
  559. procedure tjvminlinenode.second_sqr_real;
  560. begin
  561. load_fpu_location;
  562. location_reset(location,LOC_FPUREGISTER,location.size);
  563. location.register:=hlcg.getfpuregister(current_asmdata.CurrAsmList,resultdef);
  564. case left.location.size of
  565. OS_F32:
  566. begin
  567. current_asmdata.CurrAsmList.concat(taicpu.op_none(a_dup));
  568. thlcgjvm(hlcg).incstack(current_asmdata.CurrAsmList,1);
  569. current_asmdata.CurrAsmList.concat(taicpu.op_none(a_fmul));
  570. thlcgjvm(hlcg).decstack(current_asmdata.CurrAsmList,1);
  571. end;
  572. OS_F64:
  573. begin
  574. current_asmdata.CurrAsmList.concat(taicpu.op_none(a_dup2));
  575. thlcgjvm(hlcg).incstack(current_asmdata.CurrAsmList,2);
  576. current_asmdata.CurrAsmList.concat(taicpu.op_none(a_dmul));
  577. thlcgjvm(hlcg).decstack(current_asmdata.CurrAsmList,2);
  578. end;
  579. else
  580. internalerror(2011010804);
  581. end;
  582. thlcgjvm(hlcg).a_load_stack_reg(current_asmdata.CurrAsmList,resultdef,location.register);
  583. end;
  584. procedure tjvminlinenode.second_trunc_real;
  585. begin
  586. load_fpu_location;
  587. location_reset(location,LOC_REGISTER,left.location.size);
  588. location.register:=hlcg.getintregister(current_asmdata.CurrAsmList,resultdef);
  589. case left.location.size of
  590. OS_F32:
  591. begin
  592. current_asmdata.CurrAsmList.concat(taicpu.op_none(a_f2l));
  593. { 32 bit float -> 64 bit int: +1 stack slot }
  594. thlcgjvm(hlcg).incstack(current_asmdata.CurrAsmList,1);
  595. end;
  596. OS_F64:
  597. begin
  598. { 64 bit float -> 64 bit int: same number of stack slots }
  599. current_asmdata.CurrAsmList.concat(taicpu.op_none(a_d2l));
  600. end;
  601. else
  602. internalerror(2011010805);
  603. end;
  604. thlcgjvm(hlcg).a_load_stack_reg(current_asmdata.CurrAsmList,resultdef,location.register);
  605. end;
  606. procedure tjvminlinenode.second_new;
  607. var
  608. arr: tnode;
  609. hp: tcallparanode;
  610. paracount: longint;
  611. begin
  612. hp:=tcallparanode(left);
  613. { we don't second pass this one, it's only a type node }
  614. arr:=hp.left;
  615. if not is_dynamic_array(arr.resultdef) then
  616. internalerror(2011012204);
  617. hp:=tcallparanode(hp.right);
  618. if not assigned(hp) then
  619. internalerror(2011012205);
  620. paracount:=0;
  621. { put all the dimensions on the stack }
  622. repeat
  623. inc(paracount);
  624. secondpass(hp.left);
  625. thlcgjvm(hlcg).a_load_loc_stack(current_asmdata.CurrAsmList,hp.left.resultdef,hp.left.location);
  626. hp:=tcallparanode(hp.right);
  627. until not assigned(hp);
  628. { create the array }
  629. thlcgjvm(hlcg).g_newarray(current_asmdata.CurrAsmList,arr.resultdef,paracount);
  630. location_reset(location,LOC_REGISTER,OS_ADDR);
  631. location.register:=hlcg.getaddressregister(current_asmdata.CurrAsmList,resultdef);
  632. thlcgjvm(hlcg).a_load_stack_reg(current_asmdata.CurrAsmList,arr.resultdef,location.register);
  633. end;
  634. procedure tjvminlinenode.second_setlength;
  635. var
  636. target: tnode;
  637. lenpara: tnode;
  638. emptystr: ansichar;
  639. begin
  640. target:=tcallparanode(left).left;
  641. lenpara:=tcallparanode(tcallparanode(left).right).left;
  642. if assigned(tcallparanode(tcallparanode(left).right).right) or
  643. not is_constintnode(lenpara) or
  644. (tordconstnode(lenpara).value<>0) then
  645. internalerror(2011031801);
  646. secondpass(target);
  647. if is_wide_or_unicode_string(target.resultdef) then
  648. begin
  649. emptystr:=#0;
  650. current_asmdata.CurrAsmList.concat(taicpu.op_string(a_ldc,0,@emptystr));
  651. thlcgjvm(hlcg).incstack(current_asmdata.CurrAsmList,1);
  652. end
  653. else if is_dynamic_array(target.resultdef) then
  654. begin
  655. thlcgjvm(hlcg).a_load_const_stack(current_asmdata.CurrAsmList,s32inttype,0,R_INTREGISTER);
  656. thlcgjvm(hlcg).g_newarray(current_asmdata.CurrAsmList,target.resultdef,1);
  657. end
  658. {$ifndef nounsupported}
  659. else if left.resultdef.typ=stringdef then
  660. begin
  661. thlcgjvm(hlcg).a_load_const_stack(current_asmdata.CurrAsmList,java_jlobject,0,R_ADDRESSREGISTER);
  662. end
  663. {$endif}
  664. else
  665. internalerror(2011031401);
  666. thlcgjvm(hlcg).a_load_stack_loc(current_asmdata.CurrAsmList,target.resultdef,target.location);
  667. end;
  668. begin
  669. cinlinenode:=tjvminlinenode;
  670. end.