Mosa.Platform.x86.MachineCodeEmitter.ResolvePatches C# (CSharp) Method

ResolvePatches() public method

public ResolvePatches ( ) : void
return void
        public override void ResolvePatches()
        {
            // Save the current position
            long currentPosition = codeStream.Position;

            foreach (var p in patches)
            {
                int labelPosition;
                if (!TryGetLabel(p.Label, out labelPosition))
                {
                    throw new ArgumentException("Missing label while resolving patches.", "label=" + labelPosition.ToString());
                }

                codeStream.Position = p.Position;

                // Compute relative branch offset
                int relOffset = labelPosition - ((int)p.Position + 4);

                // Write relative offset to stream
                var bytes = BitConverter.GetBytes(relOffset);
                codeStream.Write(bytes, 0, bytes.Length);
            }

            // Reset the position
            codeStream.Position = currentPosition;
        }