nppccal.pas 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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 : 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. reference_reset_base(href,current_procinfo.framepointer,PARENT_FRAMEPOINTER_OFFSET);
  71. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,href,NR_R11);
  72. { it must be adjusted! }
  73. end
  74. { this is only true if the difference is one !!
  75. but it cannot be more !! }
  76. else if (current_procinfo.procdef.parast.symtablelevel=(tprocdef(procdefinition).parast.symtablelevel)-1) then
  77. begin
  78. { pass the same framepointer as the current procedure got }
  79. cg.a_load_reg_reg(exprasmlist,OS_32,OS_32,NR_R1,NR_R11);
  80. end
  81. else if (current_procinfo.procdef.parast.symtablelevel>(tprocdef(procdefinition).parast.symtablelevel)) then
  82. begin
  83. hregister1:=rg.getregisterint(exprasmlist,OS_ADDR);
  84. reference_reset_base(href,current_procinfo.framepointer,PARENT_FRAMEPOINTER_OFFSET);
  85. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,href,hregister1);
  86. { the previous frame pointer is always saved at }
  87. { previous_framepointer+12 (in the link area) }
  88. reference_reset_base(href,hregister1,12);
  89. i:=current_procinfo.procdef.parast.symtablelevel-1;
  90. while (i>tprocdef(procdefinition).parast.symtablelevel) do
  91. begin
  92. cg.a_load_ref_reg(exprasmlist,OS_ADDR,OS_ADDR,href,hregister1);
  93. dec(i);
  94. end;
  95. cg.a_load_reg_reg(exprasmlist,OS_ADDR,OS_ADDR,hregister1,NR_R11);
  96. rg.ungetregisterint(exprasmlist,hregister1);
  97. end
  98. else
  99. internalerror(2002081303);
  100. end;
  101. procedure tppccallnode.free_pushed_framepointer;
  102. begin
  103. end;
  104. begin
  105. ccallnode:=tppccallnode;
  106. end.
  107. {
  108. $Log$
  109. Revision 1.21 2003-09-03 19:35:24 peter
  110. * powerpc compiles again
  111. Revision 1.20 2003/07/08 21:24:59 peter
  112. * sparc fixes
  113. Revision 1.19 2003/07/06 20:25:03 jonas
  114. * fixed ppc compiler
  115. Revision 1.18 2003/06/13 21:19:32 peter
  116. * current_procdef removed, use current_procinfo.procdef instead
  117. Revision 1.17 2003/06/04 11:58:58 jonas
  118. * calculate localsize also in g_return_from_proc since it's now called
  119. before g_stackframe_entry (still have to fix macos)
  120. * compilation fixes (cycle doesn't work yet though)
  121. Revision 1.16 2003/05/25 14:32:42 jonas
  122. * fixed register numbering bug
  123. Revision 1.15 2003/05/24 11:47:27 jonas
  124. * fixed framepointer storage: it's now always stored at r1+12, which is
  125. a place in the link area reserved for compiler use.
  126. Revision 1.14 2003/05/23 18:51:26 jonas
  127. * fixed support for nested procedures and more parameters than those
  128. which fit in registers (untested/probably not working: calling a
  129. nested procedure from a deeper nested procedure)
  130. Revision 1.13 2003/05/18 15:15:59 florian
  131. + added abi field to tsysteminfo
  132. Revision 1.12 2003/05/16 23:15:51 jonas
  133. * workaround for nested procedures until Peter fixes it properly :)
  134. Revision 1.11 2003/05/16 20:00:39 jonas
  135. * powerpc nested procedure fixes, should work completely now if all
  136. local variables of the parent procedure are declared before the
  137. nested procedures are declared
  138. Revision 1.10 2003/04/27 11:21:36 peter
  139. * aktprocdef renamed to current_procinfo.procdef
  140. * procinfo renamed to current_procinfo
  141. * procinfo will now be stored in current_module so it can be
  142. cleaned up properly
  143. * gen_main_procsym changed to create_main_proc and release_main_proc
  144. to also generate a tprocinfo structure
  145. * fixed unit implicit initfinal
  146. Revision 1.9 2003/04/27 10:41:47 florian
  147. * fixed nested procedures to get them working as before
  148. Revision 1.8 2003/04/27 07:48:05 peter
  149. * updated for removed lexlevel
  150. Revision 1.7 2003/04/24 11:24:00 florian
  151. * fixed several issues with nested procedures
  152. Revision 1.6 2003/04/23 12:35:35 florian
  153. * fixed several issues with powerpc
  154. + applied a patch from Jonas for nested function calls (PowerPC only)
  155. * ...
  156. Revision 1.5 2003/04/04 15:38:56 peter
  157. * moved generic code from n386cal to ncgcal, i386 now also
  158. uses the generic ncgcal
  159. Revision 1.4 2002/12/05 14:28:12 florian
  160. * some variant <-> dyn. array stuff
  161. Revision 1.3 2002/11/25 17:43:28 peter
  162. * splitted defbase in defutil,symutil,defcmp
  163. * merged isconvertable and is_equal into compare_defs(_ext)
  164. * made operator search faster by walking the list only once
  165. Revision 1.2 2002/08/17 09:23:49 florian
  166. * first part of procinfo rewrite
  167. Revision 1.1 2002/08/13 21:40:59 florian
  168. * more fixes for ppc calling conventions
  169. }