njvminl.pas 29 KB

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