procinfo.pas 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Information about the current procedure that is being compiled
  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 by
  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 procinfo;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. { common }
  23. cclasses,
  24. { global }
  25. globtype,globals,verbose,
  26. { symtable }
  27. symconst,symtype,symdef,symsym,
  28. { aasm }
  29. cpubase,cpuinfo,cgbase,
  30. aasmbase,aasmtai
  31. ;
  32. type
  33. tprocinfoflag=(
  34. {# procedure uses asm }
  35. pi_uses_asm,
  36. {# procedure does a call }
  37. pi_do_call,
  38. {# procedure has a try statement = no register optimization }
  39. pi_uses_exceptions,
  40. {# procedure is declared as @var(assembler), don't optimize}
  41. pi_is_assembler,
  42. {# procedure contains data which needs to be finalized }
  43. pi_needs_implicit_finally
  44. );
  45. tprocinfoflags=set of tprocinfoflag;
  46. type
  47. {# This object gives information on the current routine being
  48. compiled.
  49. }
  50. tprocinfo = class(tlinkedlistitem)
  51. { pointer to parent in nested procedures }
  52. parent : tprocinfo;
  53. {# the definition of the routine itself }
  54. procdef : tprocdef;
  55. { procinfo of the main procedure that is inlining
  56. the current function, only used in tcgcallnode.inlined_pass2 }
  57. inlining_procinfo : tprocinfo;
  58. { file location of begin of procedure }
  59. entrypos : tfileposinfo;
  60. { file location of end of procedure }
  61. exitpos : tfileposinfo;
  62. { local switches at begin of procedure }
  63. entryswitches : tlocalswitches;
  64. { local switches at end of procedure }
  65. exitswitches : tlocalswitches;
  66. { Size of the parameters on the stack }
  67. para_stack_size : longint;
  68. { Offset of temp after para/local are allocated }
  69. tempstart : longint;
  70. {# some collected informations about the procedure
  71. see pi_xxxx constants above
  72. }
  73. flags : tprocinfoflags;
  74. { register used as frame pointer }
  75. framepointer : tregister;
  76. { register containing currently the got }
  77. got : tregister;
  78. { Holds the reference used to store alll saved registers. }
  79. save_regs_ref : treference;
  80. { label to leave the sub routine }
  81. aktexitlabel : tasmlabel;
  82. {# The code for the routine itself, excluding entry and
  83. exit code. This is a linked list of tai classes.
  84. }
  85. aktproccode : taasmoutput;
  86. { Data (like jump tables) that belongs to this routine }
  87. aktlocaldata : taasmoutput;
  88. constructor create(aparent:tprocinfo);virtual;
  89. destructor destroy;override;
  90. { Allocate framepointer so it can not be used by the
  91. register allocator }
  92. { procedure allocate_framepointer_reg;virtual;}
  93. procedure allocate_push_parasize(size:longint);virtual;
  94. function calc_stackframe_size:longint;virtual;
  95. { Set the address of the first temp, can be used to allocate
  96. space for pushing parameters }
  97. procedure set_first_temp_offset;virtual;
  98. { Generate parameter information }
  99. procedure generate_parameter_info;virtual;
  100. { This procedure is called after the pass 1 of the subroutine body is done.
  101. Here the address fix ups to generate code for the body must be done.
  102. }
  103. {procedure after_pass1;virtual;}
  104. end;
  105. tcprocinfo = class of tprocinfo;
  106. var
  107. cprocinfo : tcprocinfo;
  108. { information about the current sub routine being parsed (@var(pprocinfo))}
  109. current_procinfo : tprocinfo;
  110. implementation
  111. uses
  112. cutils,systems,
  113. tgobj,cgobj,
  114. paramgr
  115. ;
  116. {****************************************************************************
  117. TProcInfo
  118. ****************************************************************************}
  119. constructor tprocinfo.create(aparent:tprocinfo);
  120. begin
  121. parent:=aparent;
  122. procdef:=nil;
  123. para_stack_size:=0;
  124. flags:=[];
  125. framepointer:=NR_FRAME_POINTER_REG;
  126. { asmlists }
  127. aktproccode:=Taasmoutput.Create;
  128. aktlocaldata:=Taasmoutput.Create;
  129. reference_reset(save_regs_ref);
  130. { labels }
  131. objectlibrary.getlabel(aktexitlabel);
  132. end;
  133. destructor tprocinfo.destroy;
  134. begin
  135. aktproccode.free;
  136. aktlocaldata.free;
  137. end;
  138. (*
  139. procedure tprocinfo.allocate_framepointer_reg;
  140. begin
  141. if framepointer=NR_FRAME_POINTER_REG then
  142. begin
  143. { Make sure the register allocator won't allocate registers
  144. into ebp }
  145. include(rg.used_in_proc_int,RS_FRAME_POINTER_REG);
  146. exclude(rg.unusedregsint,RS_FRAME_POINTER_REG);
  147. end;
  148. end;
  149. *)
  150. procedure tprocinfo.allocate_push_parasize(size:longint);
  151. begin
  152. end;
  153. function tprocinfo.calc_stackframe_size:longint;
  154. begin
  155. result:=Align(tg.direction*tg.lasttemp,aktalignment.localalignmin);
  156. end;
  157. procedure tprocinfo.set_first_temp_offset;
  158. begin
  159. end;
  160. procedure tprocinfo.generate_parameter_info;
  161. begin
  162. { generate callee paraloc register info, it returns the size that
  163. is allocated on the stack }
  164. para_stack_size:=paramanager.create_paraloc_info(procdef,calleeside);
  165. end;
  166. end.
  167. {
  168. $Log$
  169. Revision 1.9 2003-12-03 23:13:20 peter
  170. * delayed paraloc allocation, a_param_*() gets extra parameter
  171. if it needs to allocate temp or real paralocation
  172. * optimized/simplified int-real loading
  173. Revision 1.8 2003/11/10 22:02:52 peter
  174. * cross unit inlining fixed
  175. Revision 1.7 2003/10/17 14:38:32 peter
  176. * 64k registers supported
  177. * fixed some memory leaks
  178. Revision 1.6 2003/10/14 00:30:48 florian
  179. + some code for PIC support added
  180. Revision 1.5 2003/10/10 17:48:13 peter
  181. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  182. * tregisteralloctor renamed to trgobj
  183. * removed rgobj from a lot of units
  184. * moved location_* and reference_* to cgobj
  185. * first things for mmx register allocation
  186. Revision 1.4 2003/10/09 21:31:37 daniel
  187. * Register allocator splitted, ans abstract now
  188. Revision 1.3 2003/10/05 21:21:52 peter
  189. * c style array of const generates callparanodes
  190. * varargs paraloc fixes
  191. Revision 1.2 2003/10/03 22:00:33 peter
  192. * parameter alignment fixes
  193. Revision 1.1 2003/10/01 20:34:49 peter
  194. * procinfo unit contains tprocinfo
  195. * cginfo renamed to cgbase
  196. * moved cgmessage to verbose
  197. * fixed ppc and sparc compiles
  198. }