njvminl.pas 26 KB

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