njvminl.pas 30 KB

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