njvminl.pas 29 KB

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