procinfo.pas 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Information about the current procedure that is being compiled
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit procinfo;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. { common }
  22. cclasses,
  23. { global }
  24. globtype,globals,verbose,
  25. { symtable }
  26. symconst,symtype,symdef,symsym,
  27. { aasm }
  28. cpubase,cpuinfo,cgbase,cgutils,
  29. aasmbase,aasmtai,aasmdata,
  30. optutils
  31. ;
  32. const
  33. inherited_inlining_flags : tprocinfoflags = [pi_do_call];
  34. type
  35. {# This object gives information on the current routine being
  36. compiled.
  37. }
  38. tprocinfo = class(tlinkedlistitem)
  39. { pointer to parent in nested procedures }
  40. parent : tprocinfo;
  41. {# the definition of the routine itself }
  42. procdef : tprocdef;
  43. { procinfo of the main procedure that is inlining
  44. the current function, only used in tcgcallnode.inlined_pass2 }
  45. inlining_procinfo : tprocinfo;
  46. { file location of begin of procedure }
  47. entrypos : tfileposinfo;
  48. { file location of end of procedure }
  49. exitpos : tfileposinfo;
  50. { local switches at begin of procedure }
  51. entryswitches : tlocalswitches;
  52. { local switches at end of procedure }
  53. exitswitches : tlocalswitches;
  54. { Size of the parameters on the stack }
  55. para_stack_size : longint;
  56. { Offset of temp after para/local are allocated }
  57. tempstart : longint;
  58. {# some collected informations about the procedure
  59. see pi_xxxx constants above
  60. }
  61. flags : tprocinfoflags;
  62. { register used as frame pointer }
  63. framepointer : tregister;
  64. { register containing currently the got }
  65. got : tregister;
  66. CurrGOTLabel : tasmlabel;
  67. { Holds the reference used to store all saved registers. }
  68. save_regs_ref : treference;
  69. { Labels for TRUE/FALSE condition, BREAK and CONTINUE }
  70. CurrBreakLabel,
  71. CurrContinueLabel,
  72. CurrTrueLabel,
  73. CurrFalseLabel : tasmlabel;
  74. { label to leave the sub routine }
  75. CurrExitLabel : tasmlabel;
  76. {# The code for the routine itself, excluding entry and
  77. exit code. This is a linked list of tai classes.
  78. }
  79. aktproccode : TAsmList;
  80. { Data (like jump tables) that belongs to this routine }
  81. aktlocaldata : TAsmList;
  82. { max. of space need for parameters }
  83. maxpushedparasize : aint;
  84. constructor create(aparent:tprocinfo);virtual;
  85. destructor destroy;override;
  86. procedure allocate_push_parasize(size:longint);
  87. function calc_stackframe_size:longint;virtual;
  88. { Set the address of the first temp, can be used to allocate
  89. space for pushing parameters }
  90. procedure set_first_temp_offset;virtual;
  91. { Generate parameter information }
  92. procedure generate_parameter_info;virtual;
  93. { Allocate got register }
  94. procedure allocate_got_register(list: TAsmList);virtual;
  95. end;
  96. tcprocinfo = class of tprocinfo;
  97. var
  98. cprocinfo : tcprocinfo;
  99. { information about the current sub routine being parsed (@var(pprocinfo))}
  100. current_procinfo : tprocinfo;
  101. implementation
  102. uses
  103. cutils,systems,
  104. tgobj,cgobj,
  105. paramgr
  106. ;
  107. {****************************************************************************
  108. TProcInfo
  109. ****************************************************************************}
  110. constructor tprocinfo.create(aparent:tprocinfo);
  111. begin
  112. parent:=aparent;
  113. procdef:=nil;
  114. para_stack_size:=0;
  115. flags:=[];
  116. framepointer:=NR_FRAME_POINTER_REG;
  117. maxpushedparasize:=0;
  118. { asmlists }
  119. aktproccode:=TAsmList.Create;
  120. aktlocaldata:=TAsmList.Create;
  121. reference_reset(save_regs_ref,sizeof(aint));
  122. { labels }
  123. current_asmdata.getjumplabel(CurrExitLabel);
  124. current_asmdata.getjumplabel(CurrGOTLabel);
  125. CurrBreakLabel:=nil;
  126. CurrContinueLabel:=nil;
  127. CurrTrueLabel:=nil;
  128. CurrFalseLabel:=nil;
  129. maxpushedparasize:=0;
  130. end;
  131. destructor tprocinfo.destroy;
  132. begin
  133. aktproccode.free;
  134. aktlocaldata.free;
  135. end;
  136. procedure tprocinfo.allocate_push_parasize(size:longint);
  137. begin
  138. if size>maxpushedparasize then
  139. maxpushedparasize:=size;
  140. end;
  141. function tprocinfo.calc_stackframe_size:longint;
  142. begin
  143. result:=Align(tg.direction*tg.lasttemp,current_settings.alignment.localalignmin);
  144. end;
  145. procedure tprocinfo.set_first_temp_offset;
  146. begin
  147. end;
  148. procedure tprocinfo.generate_parameter_info;
  149. begin
  150. { generate callee paraloc register info, it returns the size that
  151. is allocated on the stack }
  152. para_stack_size:=paramanager.create_paraloc_info(procdef,calleeside);
  153. end;
  154. procedure tprocinfo.allocate_got_register(list: TAsmList);
  155. begin
  156. { most os/cpu combo's don't use this yet, so not yet abstract }
  157. end;
  158. end.