hlcgppc.pas 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. {
  2. Copyright (c) 1998-2010 by Florian Klaempfl and Jonas Maebe
  3. Member of the Free Pascal development team
  4. This unit contains routines high-level code generator support shared by
  5. ppc32 and ppc64
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ****************************************************************************
  18. }
  19. unit hlcgppc;
  20. {$mode objfpc}
  21. interface
  22. uses
  23. aasmdata,
  24. symtype,
  25. cgbase,cgutils,hlcgobj,hlcg2ll;
  26. type
  27. thlcgppcgen = class(thlcg2ll)
  28. protected
  29. procedure a_load_subsetref_regs_noindex(list: TAsmList; subsetsize: tdef; loadbitsize: byte; const sref: tsubsetreference; valuereg, extra_value_reg: tregister); override;
  30. public
  31. procedure gen_load_para_value(list: TAsmList); override;
  32. end;
  33. implementation
  34. uses
  35. cpubase,globtype,
  36. procinfo,cpupi,
  37. symdef,defutil;
  38. { thlcgppc }
  39. procedure thlcgppcgen.a_load_subsetref_regs_noindex(list: TAsmList; subsetsize: tdef; loadbitsize: byte; const sref: tsubsetreference; valuereg, extra_value_reg: tregister);
  40. var
  41. fromsreg, tosreg: tsubsetregister;
  42. restbits: byte;
  43. begin
  44. restbits:=(sref.bitlen-(loadbitsize-sref.startbit));
  45. if is_signed(subsetsize) then
  46. begin
  47. { sign extend }
  48. a_op_const_reg(list,OP_SHL,osuinttype,AIntBits-loadbitsize+sref.startbit,valuereg);
  49. a_op_const_reg(list,OP_SAR,osuinttype,AIntBits-sref.bitlen,valuereg);
  50. end
  51. else
  52. begin
  53. a_op_const_reg(list,OP_SHL,osuinttype,restbits,valuereg);
  54. { mask other bits }
  55. if (sref.bitlen<>AIntBits) then
  56. a_op_const_reg(list,OP_AND,osuinttype,(aword(1) shl sref.bitlen)-1,valuereg);
  57. end;
  58. { use subsetreg routine, it may have been overridden with an optimized version }
  59. fromsreg.subsetreg:=extra_value_reg;
  60. fromsreg.subsetregsize:=OS_INT;
  61. { subsetregs always count bits from right to left }
  62. fromsreg.startbit:=loadbitsize-restbits;
  63. fromsreg.bitlen:=restbits;
  64. tosreg.subsetreg:=valuereg;
  65. tosreg.subsetregsize:=OS_INT;
  66. tosreg.startbit:=0;
  67. tosreg.bitlen:=restbits;
  68. a_load_subsetreg_subsetreg(list,subsetsize,subsetsize,fromsreg,tosreg);
  69. end;
  70. procedure thlcgppcgen.gen_load_para_value(list: TAsmList);
  71. begin
  72. { get the register that contains the stack pointer before the procedure
  73. entry, which is used to access the parameters in their original
  74. callee-side location }
  75. if (tppcprocinfo(current_procinfo).needs_frame_pointer) then
  76. getcpuregister(list,NR_OLD_STACK_POINTER_REG);
  77. inherited;
  78. { free it again }
  79. if (tppcprocinfo(current_procinfo).needs_frame_pointer) then
  80. ungetcpuregister(list,NR_OLD_STACK_POINTER_REG);
  81. end;
  82. end.