cgcpu.pas 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. {
  2. Copyright (c) 2010 by Jonas Maebe
  3. This unit implements the code generator for the Java VM
  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 cgcpu;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,parabase,
  22. cgbase,cgutils,cgobj,cghlcpu,
  23. aasmbase,aasmtai,aasmdata,aasmcpu,
  24. cpubase,cpuinfo,
  25. node,symconst,SymType,symdef,
  26. rgcpu;
  27. type
  28. TCgJvm=class(thlbasecgcpu)
  29. public
  30. procedure init_register_allocators;override;
  31. procedure done_register_allocators;override;
  32. function getintregister(list:TAsmList;size:Tcgsize):Tregister;override;
  33. function getfpuregister(list:TAsmList;size:Tcgsize):Tregister;override;
  34. function getaddressregister(list:TAsmList):Tregister;override;
  35. procedure do_register_allocation(list:TAsmList;headertai:tai);override;
  36. end;
  37. procedure create_codegen;
  38. implementation
  39. uses
  40. globals,verbose,systems,cutils,
  41. paramgr,fmodule,
  42. tgobj,
  43. procinfo,cpupi;
  44. {****************************************************************************
  45. Assembler code
  46. ****************************************************************************}
  47. procedure tcgjvm.init_register_allocators;
  48. begin
  49. inherited init_register_allocators;
  50. {$ifndef cpu64bitaddr}
  51. rg[R_INTREGISTER]:=Trgcpu.create(R_INTREGISTER,R_SUBD,
  52. [RS_R0],first_int_imreg,[]);
  53. {$else not cpu64bitaddr}
  54. rg[R_INTREGISTER]:=Trgcpu.create(R_INTREGISTER,R_SUBQ,
  55. [RS_R0],first_int_imreg,[]);
  56. {$endif not cpu64bitaddr}
  57. rg[R_FPUREGISTER]:=trgcpu.create(R_FPUREGISTER,R_SUBFS,
  58. [RS_R0],first_fpu_imreg,[]);
  59. rg[R_MMREGISTER]:=trgcpu.create(R_MMREGISTER,R_SUBNONE,
  60. [RS_R0],first_mm_imreg,[]);
  61. end;
  62. procedure tcgjvm.done_register_allocators;
  63. begin
  64. rg[R_INTREGISTER].free;
  65. rg[R_FPUREGISTER].free;
  66. rg[R_MMREGISTER].free;
  67. inherited done_register_allocators;
  68. end;
  69. function tcgjvm.getintregister(list:TAsmList;size:Tcgsize):Tregister;
  70. begin
  71. if not(size in [OS_64,OS_S64]) then
  72. result:=rg[R_INTREGISTER].getregister(list,R_SUBD)
  73. else
  74. result:=rg[R_INTREGISTER].getregister(list,R_SUBQ);
  75. end;
  76. function tcgjvm.getfpuregister(list:TAsmList;size:Tcgsize):Tregister;
  77. begin
  78. if size=OS_F64 then
  79. result:=rg[R_FPUREGISTER].getregister(list,R_SUBFD)
  80. else
  81. result:=rg[R_FPUREGISTER].getregister(list,R_SUBFS);
  82. end;
  83. function tcgjvm.getaddressregister(list:TAsmList):Tregister;
  84. begin
  85. { avoid problems in the compiler where int and addr registers are
  86. mixed for now; we currently don't have to differentiate between the
  87. two as far as the jvm backend is concerned }
  88. result:=rg[R_INTREGISTER].getregister(list,R_SUBD)
  89. end;
  90. procedure tcgjvm.do_register_allocation(list:TAsmList;headertai:tai);
  91. begin
  92. { We only run the "register allocation" once for an arbitrary allocator,
  93. which will perform the register->temp mapping for all register types.
  94. This allows us to easily reuse temps. }
  95. trgcpu(rg[R_INTREGISTER]).do_all_register_allocation(list,headertai);
  96. end;
  97. procedure create_codegen;
  98. begin
  99. cg:=tcgjvm.Create;
  100. end;
  101. end.