njvmmem.pas 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. {
  2. Copyright (c) 2011 by Jonas Maebe
  3. Generate JVM byetcode for in memory related 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 njvmmem;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,
  22. cgbase,cpubase,
  23. node,nmem,ncgmem;
  24. type
  25. tjvmvecnode = class(tcgvecnode)
  26. procedure pass_generate_code;override;
  27. end;
  28. implementation
  29. uses
  30. systems,
  31. cutils,verbose,
  32. symdef,defutil,
  33. aasmdata,pass_2,
  34. cgutils,hlcgobj;
  35. {*****************************************************************************
  36. TJVMVECNODE
  37. *****************************************************************************}
  38. procedure tjvmvecnode.pass_generate_code;
  39. var
  40. newsize: tcgsize;
  41. begin
  42. { This routine is not used for Strings, as they are a class type and
  43. you have to use charAt() there to load a character (and you cannot
  44. change characters; you have to create a new string in that case)
  45. As far as arrays are concerned: we have to create a trefererence
  46. with arrayreftype in [art_indexreg,art_indexref], and ref.base =
  47. pointer to the array (i.e., left.location.register) }
  48. secondpass(left);
  49. newsize:=def_cgsize(resultdef);
  50. if left.location.loc=LOC_CREFERENCE then
  51. location_reset_ref(location,LOC_CREFERENCE,newsize,left.location.reference.alignment)
  52. else
  53. location_reset_ref(location,LOC_REFERENCE,newsize,left.location.reference.alignment);
  54. hlcg.location_force_reg(current_asmdata.CurrAsmList,left.location,left.resultdef,left.resultdef,true);
  55. location.reference.base:=left.location.register;
  56. secondpass(right);
  57. { simplify index location if necessary, since array references support
  58. an index in memory, but not an another array index }
  59. if (right.location.loc in [LOC_REFERENCE,LOC_CREFERENCE]) and
  60. (right.location.reference.arrayreftype<>art_none) then
  61. hlcg.location_force_reg(current_asmdata.CurrAsmList,right.location,right.resultdef,right.resultdef,true);
  62. case right.location.loc of
  63. LOC_REGISTER,LOC_CREGISTER:
  64. begin
  65. location.reference.arrayreftype:=art_indexreg;
  66. location.reference.index:=right.location.register;
  67. end;
  68. LOC_REFERENCE,LOC_CREFERENCE:
  69. begin
  70. location.reference.arrayreftype:=art_indexref;
  71. location.reference.indexbase:=right.location.reference.base;
  72. location.reference.indexsymbol:=right.location.reference.symbol;
  73. location.reference.indexoffset:=right.location.reference.offset;
  74. end;
  75. LOC_CONSTANT:
  76. begin
  77. location.reference.arrayreftype:=art_indexconst;
  78. location.reference.indexoffset:=right.location.value;
  79. end
  80. else
  81. internalerror(2011012002);
  82. end;
  83. end;
  84. begin
  85. cvecnode:=tjvmvecnode;
  86. end.