/usr/share/fpcsrc/2.6.2/compiler/cgutils.pas is in fpc-source-2.6.2 2.6.2-8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 | {
Copyright (c) 1998-2004 by Florian Klaempfl
Some basic types and constants for the code generation
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
****************************************************************************
}
{ This unit exports some helper routines which are used across the code generator }
unit cgutils;
{$i fpcdefs.inc}
interface
uses
globtype,
cclasses,
aasmbase,
cpubase,cgbase;
type
{ reference record, reordered for best alignment }
preference = ^treference;
treference = record
offset : asizeint;
symbol,
relsymbol : tasmsymbol;
{$if defined(x86) or defined(m68k)}
segment,
{$endif defined(x86) or defined(m68k)}
base,
index : tregister;
refaddr : trefaddr;
scalefactor : byte;
{$ifdef arm}
symboldata : tlinkedlistitem;
signindex : shortint;
shiftimm : byte;
addressmode : taddressmode;
shiftmode : tshiftmode;
{$endif arm}
{$ifdef avr}
addressmode : taddressmode;
{$endif avr}
{$ifdef m68k}
{ indexed increment and decrement mode }
{ (An)+ and -(An) }
direction : tdirection;
{$endif m68k}
alignment : byte;
end;
tsubsetregister = record
subsetreg : tregister;
startbit, bitlen: byte;
subsetregsize: tcgsize;
end;
tsubsetreference = record
ref: treference;
bitindexreg: tregister;
startbit, bitlen: byte;
end;
tlocation = record
loc : TCGLoc;
size : TCGSize;
case TCGLoc of
{$ifdef cpuflags}
LOC_FLAGS : (resflags : tresflags);
{$endif cpuflags}
LOC_CONSTANT : (
case longint of
{$ifdef FPC_BIG_ENDIAN}
1 : (_valuedummy,value : aint);
{$else FPC_BIG_ENDIAN}
1 : (value : aint);
{$endif FPC_BIG_ENDIAN}
2 : (value64 : Int64);
);
LOC_CREFERENCE,
LOC_REFERENCE : (reference : treference);
{ segment in reference at the same place as in loc_register }
LOC_REGISTER,
LOC_CREGISTER : (
case longint of
1 : (register : tregister;
{ some x86_64 targets require two function result registers }
registerhi : tregister;
{$ifdef m68k}
{ some m68k OSes require that the result is returned in d0 and a0
the second location must be stored here }
registeralias : tregister;
{$endif m68k}
);
{$ifndef cpu64bitalu}
{ overlay a 64 Bit register type }
2 : (register64 : tregister64);
{$endif cpu64bitalu}
{$ifdef avr}
3 : (registers : array[0..3] of tregister);
{$endif avr}
);
LOC_SUBSETREG,
LOC_CSUBSETREG : (
sreg: tsubsetregister;
);
LOC_SUBSETREF : (
sref: tsubsetreference;
)
end;
{ trerefence handling }
{# Clear to zero a treference }
procedure reference_reset(var ref : treference; alignment: longint);
{# Clear to zero a treference, and set is base address
to base register.
}
procedure reference_reset_base(var ref : treference;base : tregister;offset, alignment : longint);
procedure reference_reset_symbol(var ref : treference;sym : tasmsymbol;offset, alignment : longint);
{ This routine verifies if two references are the same, and
if so, returns TRUE, otherwise returns false.
}
function references_equal(const sref,dref : treference) : boolean;
{ tlocation handling }
{ cannot be used for loc_(c)reference, because that one requires an alignment }
procedure location_reset(var l : tlocation;lt:TCGNonRefLoc;lsize:TCGSize);
{ for loc_(c)reference }
procedure location_reset_ref(var l : tlocation;lt:TCGRefLoc;lsize:TCGSize; alignment: longint);
procedure location_copy(var destloc:tlocation; const sourceloc : tlocation);
procedure location_swap(var destloc,sourceloc : tlocation);
{ returns r with the given alignment }
function setalignment(const r : treference;b : byte) : treference;
implementation
uses
systems,
verbose;
{****************************************************************************
TReference
****************************************************************************}
procedure reference_reset(var ref : treference; alignment: longint);
begin
FillChar(ref,sizeof(treference),0);
{$ifdef arm}
ref.signindex:=1;
{$endif arm}
ref.alignment:=alignment;
end;
procedure reference_reset_base(var ref : treference;base : tregister;offset, alignment : longint);
begin
reference_reset(ref,alignment);
ref.base:=base;
ref.offset:=offset;
end;
procedure reference_reset_symbol(var ref : treference;sym : tasmsymbol;offset, alignment : longint);
begin
reference_reset(ref,alignment);
ref.symbol:=sym;
ref.offset:=offset;
end;
function references_equal(const sref,dref : treference):boolean;
begin
references_equal:=CompareByte(sref,dref,sizeof(treference))=0;
end;
{ returns r with the given alignment }
function setalignment(const r : treference;b : byte) : treference;
begin
result:=r;
result.alignment:=b;
end;
{****************************************************************************
TLocation
****************************************************************************}
procedure location_reset(var l : tlocation;lt:TCGNonRefLoc;lsize:TCGSize);
begin
FillChar(l,sizeof(tlocation),0);
l.loc:=lt;
l.size:=lsize;
if l.loc in [LOC_REFERENCE,LOC_CREFERENCE] then
{ call location_reset_ref instead }
internalerror(2009020705);
end;
procedure location_reset_ref(var l: tlocation; lt: tcgrefloc; lsize: tcgsize;
alignment: longint);
begin
FillChar(l,sizeof(tlocation),0);
l.loc:=lt;
l.size:=lsize;
{$ifdef arm}
l.reference.signindex:=1;
{$endif arm}
l.reference.alignment:=alignment;
end;
procedure location_copy(var destloc:tlocation; const sourceloc : tlocation);
begin
destloc:=sourceloc;
end;
procedure location_swap(var destloc,sourceloc : tlocation);
var
swapl : tlocation;
begin
swapl := destloc;
destloc := sourceloc;
sourceloc := swapl;
end;
end.
|