nppccal.pas 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. {
  2. $Id$
  3. Copyright (c) 2002 by Florian Klaempfl
  4. Implements the PowerPC specific part of call nodes
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published bymethodpointer
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit nppccal;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. symdef,node,ncal,ncgcal;
  23. type
  24. tppccallnode = class(tcgcallnode)
  25. function pass_1 : tnode;override;
  26. procedure push_framepointer;override;
  27. end;
  28. implementation
  29. uses
  30. globtype,systems,
  31. cutils,verbose,globals,
  32. symconst,symbase,symsym,symtable,defutil,paramgr,
  33. {$ifdef GDB}
  34. {$ifdef delphi}
  35. sysutils,
  36. {$else}
  37. strings,
  38. {$endif}
  39. gdb,
  40. {$endif GDB}
  41. cginfo,cgbase,pass_2,
  42. cpuinfo,cpubase,aasmbase,aasmtai,aasmcpu,
  43. nmem,nld,ncnv,
  44. ncgutil,cgobj,tgobj,regvars,rgobj,rgcpu,cg64f32,cgcpu,cpupi;
  45. function tppccallnode.pass_1 : tnode;
  46. begin
  47. result:=inherited pass_1;
  48. if assigned(result) then
  49. exit;
  50. if procdefinition is tprocdef then
  51. begin
  52. if tprocdef(procdefinition).parast.datasize>tppcprocinfo(current_procinfo).maxpushedparasize then
  53. tppcprocinfo(current_procinfo).maxpushedparasize:=tprocdef(procdefinition).parast.datasize
  54. end
  55. else
  56. begin
  57. {!!!!}
  58. end;
  59. end;
  60. procedure tppccallnode.push_framepointer;
  61. var
  62. href : treference;
  63. hregister1,hregister2 : tregister;
  64. i : longint;
  65. begin
  66. if current_procdef.parast.symtablelevel=(tprocdef(procdefinition).parast.symtablelevel) then
  67. begin
  68. { pass the same framepointer as the current procedure got }
  69. hregister2.enum:=R_INTREGISTER;
  70. hregister2.number:=NR_R11;
  71. reference_reset_base(href,current_procinfo.framepointer,current_procinfo.framepointer_offset);
  72. cg.a_load_ref_reg(exprasmlist,OS_ADDR,href,hregister2);
  73. { it must be adjusted! }
  74. end
  75. { this is only true if the difference is one !!
  76. but it cannot be more !! }
  77. else if (current_procdef.parast.symtablelevel=(tprocdef(procdefinition).parast.symtablelevel)-1) then
  78. begin
  79. { pass the same framepointer as the current procedure got }
  80. hregister1.enum:=R_INTREGISTER;
  81. hregister1.number:=NR_R1;
  82. hregister2.enum:=R_INTREGISTER;
  83. hregister2.number:=NR_R11;
  84. exprasmlist.concat(taicpu.op_reg_reg_const(A_ADDI,hregister2,hregister1,current_procinfo.procdef.parast.address_fixup));
  85. end
  86. else if (current_procdef.parast.symtablelevel>(tprocdef(procdefinition).parast.symtablelevel)) then
  87. begin
  88. hregister1:=rg.getregisterint(exprasmlist,OS_ADDR);
  89. reference_reset_base(href,current_procinfo.framepointer,current_procinfo.framepointer_offset);
  90. cg.a_load_ref_reg(exprasmlist,OS_ADDR,href,hregister1);
  91. { the previous frame pointer is always saved at }
  92. { previous_framepointer-sizeof(pointer) }
  93. reference_reset_base(href,hregister1,-POINTER_SIZE);
  94. i:=current_procdef.parast.symtablelevel-1;
  95. while (i>tprocdef(procdefinition).parast.symtablelevel) do
  96. begin
  97. {we should get the correct frame_pointer_offset at each level
  98. how can we do this !!! }
  99. cg.a_load_ref_reg(exprasmlist,OS_ADDR,href,hregister1);
  100. dec(i);
  101. end;
  102. hregister2.enum:=R_11;
  103. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,hregister1,hregister2);
  104. rg.ungetregisterint(exprasmlist,hregister1);
  105. end
  106. else
  107. internalerror(2002081303);
  108. end;
  109. begin
  110. ccallnode:=tppccallnode;
  111. end.
  112. {
  113. $Log$
  114. Revision 1.11 2003-05-16 20:00:39 jonas
  115. * powerpc nested procedure fixes, should work completely now if all
  116. local variables of the parent procedure are declared before the
  117. nested procedures are declared
  118. Revision 1.10 2003/04/27 11:21:36 peter
  119. * aktprocdef renamed to current_procdef
  120. * procinfo renamed to current_procinfo
  121. * procinfo will now be stored in current_module so it can be
  122. cleaned up properly
  123. * gen_main_procsym changed to create_main_proc and release_main_proc
  124. to also generate a tprocinfo structure
  125. * fixed unit implicit initfinal
  126. Revision 1.9 2003/04/27 10:41:47 florian
  127. * fixed nested procedures to get them working as before
  128. Revision 1.8 2003/04/27 07:48:05 peter
  129. * updated for removed lexlevel
  130. Revision 1.7 2003/04/24 11:24:00 florian
  131. * fixed several issues with nested procedures
  132. Revision 1.6 2003/04/23 12:35:35 florian
  133. * fixed several issues with powerpc
  134. + applied a patch from Jonas for nested function calls (PowerPC only)
  135. * ...
  136. Revision 1.5 2003/04/04 15:38:56 peter
  137. * moved generic code from n386cal to ncgcal, i386 now also
  138. uses the generic ncgcal
  139. Revision 1.4 2002/12/05 14:28:12 florian
  140. * some variant <-> dyn. array stuff
  141. Revision 1.3 2002/11/25 17:43:28 peter
  142. * splitted defbase in defutil,symutil,defcmp
  143. * merged isconvertable and is_equal into compare_defs(_ext)
  144. * made operator search faster by walking the list only once
  145. Revision 1.2 2002/08/17 09:23:49 florian
  146. * first part of procinfo rewrite
  147. Revision 1.1 2002/08/13 21:40:59 florian
  148. * more fixes for ppc calling conventions
  149. }