procinfo.pas 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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
  30. ;
  31. const
  32. inherited_inlining_flags : tprocinfoflags = [pi_do_call];
  33. type
  34. {# This object gives information on the current routine being
  35. compiled.
  36. }
  37. tprocinfo = class(tlinkedlistitem)
  38. { pointer to parent in nested procedures }
  39. parent : tprocinfo;
  40. {# the definition of the routine itself }
  41. procdef : tprocdef;
  42. { procinfo of the main procedure that is inlining
  43. the current function, only used in tcgcallnode.inlined_pass2 }
  44. inlining_procinfo : tprocinfo;
  45. { file location of begin of procedure }
  46. entrypos : tfileposinfo;
  47. { file location of end of procedure }
  48. exitpos : tfileposinfo;
  49. { local switches at begin of procedure }
  50. entryswitches : tlocalswitches;
  51. { local switches at end of procedure }
  52. exitswitches : tlocalswitches;
  53. { Size of the parameters on the stack }
  54. para_stack_size : longint;
  55. { Offset of temp after para/local are allocated }
  56. tempstart : longint;
  57. {# some collected informations about the procedure
  58. see pi_xxxx constants above
  59. }
  60. flags : tprocinfoflags;
  61. { register used as frame pointer }
  62. framepointer : tregister;
  63. { register containing currently the got }
  64. got : tregister;
  65. gotlabel : tasmlabel;
  66. { Holds the reference used to store all saved registers. }
  67. save_regs_ref : treference;
  68. { label to leave the sub routine }
  69. aktexitlabel : tasmlabel;
  70. {# The code for the routine itself, excluding entry and
  71. exit code. This is a linked list of tai classes.
  72. }
  73. aktproccode : taasmoutput;
  74. { Data (like jump tables) that belongs to this routine }
  75. aktlocaldata : taasmoutput;
  76. { max. of space need for parameters }
  77. maxpushedparasize : aint;
  78. constructor create(aparent:tprocinfo);virtual;
  79. destructor destroy;override;
  80. procedure allocate_push_parasize(size:longint);virtual;
  81. function calc_stackframe_size:longint;virtual;
  82. { Set the address of the first temp, can be used to allocate
  83. space for pushing parameters }
  84. procedure set_first_temp_offset;virtual;
  85. { Generate parameter information }
  86. procedure generate_parameter_info;virtual;
  87. end;
  88. tcprocinfo = class of tprocinfo;
  89. var
  90. cprocinfo : tcprocinfo;
  91. { information about the current sub routine being parsed (@var(pprocinfo))}
  92. current_procinfo : tprocinfo;
  93. implementation
  94. uses
  95. cutils,systems,
  96. tgobj,cgobj,
  97. paramgr
  98. ;
  99. {****************************************************************************
  100. TProcInfo
  101. ****************************************************************************}
  102. constructor tprocinfo.create(aparent:tprocinfo);
  103. begin
  104. parent:=aparent;
  105. procdef:=nil;
  106. para_stack_size:=0;
  107. flags:=[];
  108. framepointer:=NR_FRAME_POINTER_REG;
  109. maxpushedparasize:=0;
  110. { asmlists }
  111. aktproccode:=Taasmoutput.Create;
  112. aktlocaldata:=Taasmoutput.Create;
  113. reference_reset(save_regs_ref);
  114. { labels }
  115. objectlibrary.getjumplabel(aktexitlabel);
  116. objectlibrary.getjumplabel(gotlabel);
  117. end;
  118. destructor tprocinfo.destroy;
  119. begin
  120. aktproccode.free;
  121. aktlocaldata.free;
  122. end;
  123. procedure tprocinfo.allocate_push_parasize(size:longint);
  124. begin
  125. end;
  126. function tprocinfo.calc_stackframe_size:longint;
  127. begin
  128. result:=Align(tg.direction*tg.lasttemp,aktalignment.localalignmin);
  129. end;
  130. procedure tprocinfo.set_first_temp_offset;
  131. begin
  132. end;
  133. procedure tprocinfo.generate_parameter_info;
  134. begin
  135. { generate callee paraloc register info, it returns the size that
  136. is allocated on the stack }
  137. para_stack_size:=paramanager.create_paraloc_info(procdef,calleeside);
  138. end;
  139. end.