nppccal.pas 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. procedure free_pushed_framepointer;override;
  28. end;
  29. implementation
  30. uses
  31. globtype,systems,
  32. cutils,verbose,globals,
  33. symconst,symbase,symsym,symtable,defutil,paramgr,
  34. {$ifdef GDB}
  35. {$ifdef delphi}
  36. sysutils,
  37. {$else}
  38. strings,
  39. {$endif}
  40. gdb,
  41. {$endif GDB}
  42. cginfo,cgbase,pass_2,
  43. cpuinfo,cpubase,aasmbase,aasmtai,aasmcpu,
  44. nmem,nld,ncnv,
  45. ncgutil,cgobj,tgobj,regvars,rgobj,rgcpu,cg64f32,cgcpu,cpupi;
  46. function tppccallnode.pass_1 : tnode;
  47. begin
  48. result:=inherited pass_1;
  49. if assigned(result) then
  50. exit;
  51. if procdefinition is tprocdef then
  52. begin
  53. if tprocdef(procdefinition).parast.datasize>tppcprocinfo(current_procinfo).maxpushedparasize then
  54. tppcprocinfo(current_procinfo).maxpushedparasize:=tprocdef(procdefinition).parast.datasize;
  55. end
  56. else
  57. begin
  58. {!!!!}
  59. end;
  60. end;
  61. procedure tppccallnode.push_framepointer;
  62. var
  63. href : treference;
  64. hregister1,hregister2 : tregister;
  65. i : longint;
  66. begin
  67. if current_procinfo.procdef.parast.symtablelevel=(tprocdef(procdefinition).parast.symtablelevel) then
  68. begin
  69. { pass the same framepointer as the current procedure got }
  70. hregister2.enum:=R_INTREGISTER;
  71. hregister2.number:=NR_R11;
  72. reference_reset_base(href,current_procinfo.framepointer,PARENT_FRAMEPOINTER_OFFSET);
  73. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,href,hregister2);
  74. { it must be adjusted! }
  75. end
  76. { this is only true if the difference is one !!
  77. but it cannot be more !! }
  78. else if (current_procinfo.procdef.parast.symtablelevel=(tprocdef(procdefinition).parast.symtablelevel)-1) then
  79. begin
  80. { pass the same framepointer as the current procedure got }
  81. hregister1.enum:=R_INTREGISTER;
  82. hregister1.number:=NR_R1;
  83. hregister2.enum:=R_INTREGISTER;
  84. hregister2.number:=NR_R11;
  85. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,hregister1,hregister2);
  86. end
  87. else if (current_procinfo.procdef.parast.symtablelevel>(tprocdef(procdefinition).parast.symtablelevel)) then
  88. begin
  89. hregister1:=rg.getregisterint(exprasmlist,OS_ADDR);
  90. reference_reset_base(href,current_procinfo.framepointer,PARENT_FRAMEPOINTER_OFFSET);
  91. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,href,hregister1);
  92. { the previous frame pointer is always saved at }
  93. { previous_framepointer+12 (in the link area) }
  94. reference_reset_base(href,hregister1,12);
  95. i:=current_procinfo.procdef.parast.symtablelevel-1;
  96. while (i>tprocdef(procdefinition).parast.symtablelevel) do
  97. begin
  98. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,href,hregister1);
  99. dec(i);
  100. end;
  101. hregister2.enum:=R_INTREGISTER;
  102. hregister2.number:=NR_R11;
  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. procedure tppccallnode.free_pushed_framepointer;
  110. begin
  111. end;
  112. begin
  113. ccallnode:=tppccallnode;
  114. end.
  115. {
  116. $Log$
  117. Revision 1.20 2003-07-08 21:24:59 peter
  118. * sparc fixes
  119. Revision 1.19 2003/07/06 20:25:03 jonas
  120. * fixed ppc compiler
  121. Revision 1.18 2003/06/13 21:19:32 peter
  122. * current_procdef removed, use current_procinfo.procdef instead
  123. Revision 1.17 2003/06/04 11:58:58 jonas
  124. * calculate localsize also in g_return_from_proc since it's now called
  125. before g_stackframe_entry (still have to fix macos)
  126. * compilation fixes (cycle doesn't work yet though)
  127. Revision 1.16 2003/05/25 14:32:42 jonas
  128. * fixed register numbering bug
  129. Revision 1.15 2003/05/24 11:47:27 jonas
  130. * fixed framepointer storage: it's now always stored at r1+12, which is
  131. a place in the link area reserved for compiler use.
  132. Revision 1.14 2003/05/23 18:51:26 jonas
  133. * fixed support for nested procedures and more parameters than those
  134. which fit in registers (untested/probably not working: calling a
  135. nested procedure from a deeper nested procedure)
  136. Revision 1.13 2003/05/18 15:15:59 florian
  137. + added abi field to tsysteminfo
  138. Revision 1.12 2003/05/16 23:15:51 jonas
  139. * workaround for nested procedures until Peter fixes it properly :)
  140. Revision 1.11 2003/05/16 20:00:39 jonas
  141. * powerpc nested procedure fixes, should work completely now if all
  142. local variables of the parent procedure are declared before the
  143. nested procedures are declared
  144. Revision 1.10 2003/04/27 11:21:36 peter
  145. * aktprocdef renamed to current_procinfo.procdef
  146. * procinfo renamed to current_procinfo
  147. * procinfo will now be stored in current_module so it can be
  148. cleaned up properly
  149. * gen_main_procsym changed to create_main_proc and release_main_proc
  150. to also generate a tprocinfo structure
  151. * fixed unit implicit initfinal
  152. Revision 1.9 2003/04/27 10:41:47 florian
  153. * fixed nested procedures to get them working as before
  154. Revision 1.8 2003/04/27 07:48:05 peter
  155. * updated for removed lexlevel
  156. Revision 1.7 2003/04/24 11:24:00 florian
  157. * fixed several issues with nested procedures
  158. Revision 1.6 2003/04/23 12:35:35 florian
  159. * fixed several issues with powerpc
  160. + applied a patch from Jonas for nested function calls (PowerPC only)
  161. * ...
  162. Revision 1.5 2003/04/04 15:38:56 peter
  163. * moved generic code from n386cal to ncgcal, i386 now also
  164. uses the generic ncgcal
  165. Revision 1.4 2002/12/05 14:28:12 florian
  166. * some variant <-> dyn. array stuff
  167. Revision 1.3 2002/11/25 17:43:28 peter
  168. * splitted defbase in defutil,symutil,defcmp
  169. * merged isconvertable and is_equal into compare_defs(_ext)
  170. * made operator search faster by walking the list only once
  171. Revision 1.2 2002/08/17 09:23:49 florian
  172. * first part of procinfo rewrite
  173. Revision 1.1 2002/08/13 21:40:59 florian
  174. * more fixes for ppc calling conventions
  175. }