cgutils.pas 5.2 KB

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