njvminl.pas 29 KB

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