public void InsertResolvingMoves(BaseArchitecture architecture, Operand stackFrame) { if (Moves.Count == 0) { return; } var moves = GetResolveMoves(); var context = new Context(Index); if (Before) { // TODO: Generalize XXXX context.GotoPrevious(); // Note: This won't work for expanded switch statements... but we can't insert into the end of those blocks anyway while (context.IsEmpty || context.Instruction.FlowControl == FlowControl.UnconditionalBranch || context.Instruction.FlowControl == FlowControl.ConditionalBranch || context.Instruction.FlowControl == FlowControl.Return) { context.GotoPrevious(); } } foreach (var move in moves) { Debug.Assert(move.Destination.IsCPURegister); switch (move.Value) { case ResolvedMoveType.Move: architecture.InsertMoveInstruction(context, move.Destination, move.Source); break; case ResolvedMoveType.Exchange: architecture.InsertExchangeInstruction(context, move.Destination, move.Source); break; case ResolvedMoveType.Load: architecture.InsertLoadInstruction(context, move.Destination, stackFrame, move.Source); break; } context.Marked = true; } Debug.Assert(Moves.Count == 0); }
public void InsertResolvingMoves(BaseArchitecture architecture) { if (Moves.Count == 0) { return; } var moves = GetResolveMoves(); var context = new Context(Index); if (Before) { context.GotoPrevious(); // Note: This won't work for expanded switch statements... but we can't insert into the end of those blocks anyway while (context.IsEmpty || context.Instruction.FlowControl == FlowControl.UnconditionalBranch || context.Instruction.FlowControl == FlowControl.ConditionalBranch || context.Instruction.FlowControl == FlowControl.Return) { context.GotoPrevious(); } } foreach (var move in moves) { if (move.Value == ResolvedMoveType.Move) { architecture.InsertMoveInstruction(context, move.Destination, move.Source); } else { architecture.InsertExchangeInstruction(context, move.Destination, move.Source); } context.Marked = true; } Debug.Assert(Moves.Count == 0); }
protected void TryExchange(BaseArchitecture architecture, Context context) { bool loop = true; while (loop) { loop = false; for (int i = 0; i < moves.Count; i++) { var move = moves[i]; if (!(move.Source.IsCPURegister || move.Destination.IsCPURegister)) continue; int other = FindIndex(move.Destination.Register, true); if (other == -1) continue; architecture.InsertExchangeInstruction(context, moves[other].Source, move.Source); context.Marked = true; moves[other].Source = move.Source; moves.RemoveAt(i); if (other > i) other--; if (moves[other].Source.Register == moves[other].Destination.Register) moves.RemoveAt(other); loop = true; } } }