njvmcon.pas 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. {
  2. Copyright (c) 1998-2011 by Florian Klaempfl and Jonas Maebe
  3. Generate assembler for constant nodes for the JVM
  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 njvmcon;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. symtype,
  22. node,ncon,ncgcon;
  23. type
  24. tjvmrealconstnode = class(tcgrealconstnode)
  25. procedure pass_generate_code;override;
  26. end;
  27. tjvmstringconstnode = class(tstringconstnode)
  28. procedure pass_generate_code;override;
  29. end;
  30. implementation
  31. uses
  32. globtype,widestr,
  33. symdef,symtable,symconst,
  34. aasmdata,aasmcpu,defutil,
  35. cgbase,hlcgobj,hlcgcpu,cgutils,cpubase
  36. ;
  37. {*****************************************************************************
  38. TJVMREALCONSTNODE
  39. *****************************************************************************}
  40. procedure tjvmrealconstnode.pass_generate_code;
  41. begin
  42. location_reset(location,LOC_FPUREGISTER,def_cgsize(resultdef));
  43. location.register:=hlcg.getfpuregister(current_asmdata.CurrAsmList,resultdef);
  44. thlcgjvm(hlcg).a_loadfpu_const_stack(current_asmdata.CurrAsmList,resultdef,value_real);
  45. thlcgjvm(hlcg).a_load_stack_reg(current_asmdata.CurrAsmList,resultdef,location.register);
  46. end;
  47. { tcgstringconstnode }
  48. procedure tjvmstringconstnode.pass_generate_code;
  49. begin
  50. location_reset(location,LOC_REGISTER,def_cgsize(resultdef));
  51. location.register:=hlcg.getaddressregister(current_asmdata.CurrAsmList,resultdef);
  52. case cst_type of
  53. cst_ansistring,
  54. cst_shortstring,
  55. cst_conststring:
  56. current_asmdata.CurrAsmList.concat(taicpu.op_string(a_ldc,len,value_str));
  57. cst_unicodestring,
  58. cst_widestring:
  59. current_asmdata.CurrAsmList.concat(taicpu.op_wstring(a_ldc,pcompilerwidestring(value_str)));
  60. end;
  61. thlcgjvm(hlcg).incstack(current_asmdata.CurrAsmList,1);
  62. thlcgjvm(hlcg).a_load_stack_reg(current_asmdata.CurrAsmList,resultdef,location.register);
  63. end;
  64. begin
  65. crealconstnode:=tjvmrealconstnode;
  66. cstringconstnode:=tjvmstringconstnode;
  67. end.