cgutils.pas 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. {
  2. $Id$
  3. Copyright (c) 1998-2004 by Florian Klaempfl
  4. Some basic types and constants for the code generation
  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. { This unit exports some helper routines which are used across the code generator }
  19. unit cgutils;
  20. {$i fpcdefs.inc}
  21. interface
  22. uses
  23. globtype,
  24. cclasses,
  25. aasmbase,
  26. cpubase,cgbase;
  27. type
  28. { reference record, reordered for best alignment }
  29. preference = ^treference;
  30. treference = record
  31. offset : aint;
  32. symbol,
  33. relsymbol : tasmsymbol;
  34. segment,
  35. base,
  36. index : tregister;
  37. refaddr : trefaddr;
  38. scalefactor : byte;
  39. {$ifdef arm}
  40. symboldata : tlinkedlistitem;
  41. signindex : shortint;
  42. shiftimm : byte;
  43. addressmode : taddressmode;
  44. shiftmode : tshiftmode;
  45. {$endif arm}
  46. end;
  47. tlocation = record
  48. loc : TCGLoc;
  49. size : TCGSize;
  50. case TCGLoc of
  51. LOC_FLAGS : (resflags : tresflags);
  52. LOC_CONSTANT : (
  53. case longint of
  54. {$ifdef FPC_BIG_ENDIAN}
  55. 1 : (_valuedummy,value : aint);
  56. {$else FPC_BIG_ENDIAN}
  57. 1 : (value : aint);
  58. {$endif FPC_BIG_ENDIAN}
  59. 2 : (value64 : Int64);
  60. );
  61. LOC_CREFERENCE,
  62. LOC_REFERENCE : (reference : treference);
  63. { segment in reference at the same place as in loc_register }
  64. LOC_REGISTER,
  65. LOC_CREGISTER : (
  66. case longint of
  67. 1 : (register : tregister);
  68. {$ifndef cpu64bit}
  69. { overlay a 64 Bit register type }
  70. 2 : (register64 : tregister64);
  71. {$endif cpu64bit}
  72. );
  73. end;
  74. { trerefence handling }
  75. {# Clear to zero a treference }
  76. procedure reference_reset(var ref : treference);
  77. {# Clear to zero a treference, and set is base address
  78. to base register.
  79. }
  80. procedure reference_reset_base(var ref : treference;base : tregister;offset : longint);
  81. procedure reference_reset_symbol(var ref : treference;sym : tasmsymbol;offset : longint);
  82. { This routine verifies if two references are the same, and
  83. if so, returns TRUE, otherwise returns false.
  84. }
  85. function references_equal(sref : treference;dref : treference) : boolean;
  86. { tlocation handling }
  87. procedure location_reset(var l : tlocation;lt:TCGLoc;lsize:TCGSize);
  88. procedure location_copy(var destloc:tlocation; const sourceloc : tlocation);
  89. procedure location_swap(var destloc,sourceloc : tlocation);
  90. implementation
  91. {****************************************************************************
  92. TReference
  93. ****************************************************************************}
  94. procedure reference_reset(var ref : treference);
  95. begin
  96. FillChar(ref,sizeof(treference),0);
  97. {$ifdef arm}
  98. ref.signindex:=1;
  99. {$endif arm}
  100. end;
  101. procedure reference_reset_base(var ref : treference;base : tregister;offset : longint);
  102. begin
  103. reference_reset(ref);
  104. ref.base:=base;
  105. ref.offset:=offset;
  106. end;
  107. procedure reference_reset_symbol(var ref : treference;sym : tasmsymbol;offset : longint);
  108. begin
  109. reference_reset(ref);
  110. ref.symbol:=sym;
  111. ref.offset:=offset;
  112. end;
  113. function references_equal(sref : treference;dref : treference):boolean;
  114. begin
  115. references_equal:=CompareByte(sref,dref,sizeof(treference))=0;
  116. end;
  117. {****************************************************************************
  118. TLocation
  119. ****************************************************************************}
  120. procedure location_reset(var l : tlocation;lt:TCGLoc;lsize:TCGSize);
  121. begin
  122. FillChar(l,sizeof(tlocation),0);
  123. l.loc:=lt;
  124. l.size:=lsize;
  125. {$ifdef arm}
  126. if l.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
  127. l.reference.signindex:=1;
  128. {$endif arm}
  129. end;
  130. procedure location_copy(var destloc:tlocation; const sourceloc : tlocation);
  131. begin
  132. destloc:=sourceloc;
  133. end;
  134. procedure location_swap(var destloc,sourceloc : tlocation);
  135. var
  136. swapl : tlocation;
  137. begin
  138. swapl := destloc;
  139. destloc := sourceloc;
  140. sourceloc := swapl;
  141. end;
  142. end.
  143. {
  144. $Log$
  145. Revision 1.3 2004-11-01 17:41:28 florian
  146. * fixed arm compilation with cgutils
  147. * ...
  148. Revision 1.2 2004/10/31 21:45:02 peter
  149. * generic tlocation
  150. * move tlocation to cgutils
  151. Revision 1.1 2004/02/27 10:21:05 florian
  152. * top_symbol killed
  153. + refaddr to treference added
  154. + refsymbol to treference added
  155. * top_local stuff moved to an extra record to save memory
  156. + aint introduced
  157. * tppufile.get/putint64/aint implemented
  158. }