@@ -30,7 +30,7 @@ public partial class CallFrame : IMemorySpace
3030 private readonly List < uint > _offsets = new ( ) ;
3131 private readonly List < ExceptionHandlerFrame > _exceptionHandlers = new ( ) ;
3232 private BitVector _localStorage ;
33- private long _baseAddress ;
33+ private AddressRange _addressRange ;
3434
3535 /// <summary>
3636 /// Constructs a new call stack frame.
@@ -89,7 +89,8 @@ internal CallFrame(IMethodDescriptor method, ValueFactory factory, bool isRoot)
8989
9090 // Actually reserve space for the entire frame.
9191 _localStorage = new BitVector ( ( int ) ( currentOffset * 8 ) , false ) ;
92-
92+ _addressRange = new AddressRange ( 0 , _localStorage . ByteCount ) ;
93+
9394 // Initialize locals to zero when method body says we should.
9495 if ( _initializeLocals )
9596 {
@@ -172,10 +173,10 @@ void AllocateFrameField(TypeSignature type)
172173 public ITypeDescriptor ? ConstrainedType { get ; set ; }
173174
174175 /// <inheritdoc />
175- public AddressRange AddressRange => new ( _baseAddress , _baseAddress + _localStorage . ByteCount ) ;
176+ public AddressRange AddressRange => _addressRange ;
176177
177178 /// <inheritdoc />
178- public bool IsValidAddress ( long address ) => AddressRange . Contains ( address ) ;
179+ public bool IsValidAddress ( long address ) => _addressRange . Contains ( address ) ;
179180
180181 /// <summary>
181182 /// Allocates local stack memory in the stack frame.
@@ -189,17 +190,21 @@ public long Allocate(int size)
189190 if ( size < 0 )
190191 throw new ArgumentOutOfRangeException ( nameof ( size ) ) ;
191192
192- long address = AddressRange . End ;
193+ long address = _addressRange . End ;
193194 int originalSize = _localStorage . Count ;
194195 _localStorage = _localStorage . Resize ( originalSize + size * 8 , false ) ;
195196 if ( ! _initializeLocals )
196197 _localStorage . AsSpan ( originalSize , _localStorage . Count - originalSize ) . MarkFullyUnknown ( ) ;
197-
198+
199+ _addressRange = new AddressRange ( _addressRange . Start , _addressRange . Start + _localStorage . ByteCount ) ;
198200 return address ;
199201 }
200202
201203 /// <inheritdoc />
202- public void Rebase ( long baseAddress ) => _baseAddress = baseAddress ;
204+ public void Rebase ( long baseAddress )
205+ {
206+ _addressRange = new AddressRange ( baseAddress , baseAddress + _localStorage . ByteCount ) ;
207+ }
203208
204209 /// <summary>
205210 /// Gets the address (relative to the start of the frame) to a local variable in the frame.
@@ -208,7 +213,7 @@ public long Allocate(int size)
208213 /// <returns>The address</returns>
209214 /// <exception cref="ArgumentOutOfRangeException">Occurs when the local index is invalid.</exception>
210215 public long GetLocalAddress ( int index ) => index < LocalsCount
211- ? _baseAddress + _offsets [ index ]
216+ ? _addressRange . Start + _offsets [ index ]
212217 : throw new ArgumentOutOfRangeException ( nameof ( index ) ) ;
213218
214219 /// <summary>
@@ -251,7 +256,7 @@ public BitVector ReadLocal(int index)
251256 /// <returns>The address</returns>
252257 /// <exception cref="ArgumentOutOfRangeException">Occurs when the argument index is invalid.</exception>
253258 public long GetArgumentAddress ( int index ) => index < Method . Signature ! . GetTotalParameterCount ( )
254- ? _baseAddress + _offsets [ LocalsCount + 1 + index ]
259+ ? _addressRange . Start + _offsets [ LocalsCount + 1 + index ]
255260 : throw new ArgumentOutOfRangeException ( nameof ( index ) ) ;
256261
257262 /// <summary>
@@ -290,19 +295,19 @@ public BitVector ReadArgument(int index)
290295 /// <inheritdoc />
291296 public void Read ( long address , BitVectorSpan buffer )
292297 {
293- _localStorage . AsSpan ( ( int ) ( address - _baseAddress ) * 8 , buffer . Count ) . CopyTo ( buffer ) ;
298+ _localStorage . AsSpan ( ( int ) ( address - _addressRange . Start ) * 8 , buffer . Count ) . CopyTo ( buffer ) ;
294299 }
295300
296301 /// <inheritdoc />
297302 public void Write ( long address , BitVectorSpan buffer )
298303 {
299- buffer . CopyTo ( _localStorage . AsSpan ( ( int ) ( address - _baseAddress ) * 8 , buffer . Count ) ) ;
304+ buffer . CopyTo ( _localStorage . AsSpan ( ( int ) ( address - _addressRange . Start ) * 8 , buffer . Count ) ) ;
300305 }
301306
302307 /// <inheritdoc />
303308 public void Write ( long address , ReadOnlySpan < byte > buffer )
304309 {
305- _localStorage . AsSpan ( ( int ) ( address - _baseAddress ) * 8 , buffer . Length ) . Write ( buffer ) ;
310+ _localStorage . AsSpan ( ( int ) ( address - _addressRange . Start ) * 8 , buffer . Length ) . Write ( buffer ) ;
306311 }
307312
308313 private void InitializeExceptionHandlerFrames ( )
0 commit comments