示例#1
0
        private void CreateInternalBindings(AsmSegments segments, List <int> jumpFrom, List <int> jumpTo)
        {
            for (int s = 0; s < segments.Count - 1; s++)
            {
                AsmSegment   source = segments[s];
                AsmSegment   target = segments[s + 1];
                JsmOperation last   = source[source.Length - 1];
                if (last.Command == JsmCommand.JPF)
                {
                    AsmConditionBinding binding = new AsmConditionBinding(source, target, AsmValueSource.Create(source, source.Length - 2), true);
                    source.OutputBindings.Add(binding);
                    target.InputBindings.Add(binding);
                }
                else if (last.Command != JsmCommand.JMP)
                {
                    AsmHardlinkBinding binding = new AsmHardlinkBinding(source, target);
                    source.OutputBindings.Add(binding);
                    target.InputBindings.Add(binding);
                }
            }

            for (int i = 0; i < jumpFrom.Count; i++)
            {
                int fromIndex = jumpFrom[i];
                int toIndex   = jumpTo[i];

                AsmSegment source = segments.GetSegmentByOffset(fromIndex);
                AsmSegment target = segments.GetSegmentByOffset(toIndex);

                JsmOperation last = source[source.Length - 1];
                if (last.Command == JsmCommand.JMP)
                {
                    AsmHardlinkBinding binding = new AsmHardlinkBinding(source, target);
                    source.OutputBindings.Add(binding);
                    target.InputBindings.Add(binding);
                }
                else if (last.Command == JsmCommand.JPF)
                {
                    AsmConditionBinding binding = new AsmConditionBinding(source, target, AsmValueSource.Create(source, source.Length - 2), false);
                    source.OutputBindings.Add(binding);
                    target.InputBindings.Add(binding);
                }
            }
        }
示例#2
0
        private void CreateSegmentsByJumps(AsmEvent evt, List <int> jumpFrom, List <int> jumpTo)
        {
            jumpFrom = jumpFrom.Order().ToList();
            jumpTo   = jumpTo.Order().ToList();

            AsmSegments segments = new AsmSegments(jumpFrom.Count);

            if (segments.Capacity == 0)
            {
                segments.Add(new AsmSegment(evt, 0, evt.Count));
                evt.Segments = segments;
                return;
            }

            int left      = 0;
            int fromIndex = 0;
            int toIndex   = 0;

            while (true)
            {
                int right;
                if (fromIndex < jumpFrom.Count)
                {
                    if (toIndex < jumpTo.Count)
                    {
                        int fromValue = jumpFrom[fromIndex];
                        int toValue   = jumpTo[toIndex];
                        if (fromValue < toValue)
                        {
                            right = fromValue;
                            fromIndex++;
                        }
                        else if (toValue < fromValue)
                        {
                            right = toValue - 1;
                            toIndex++;
                        }
                        else
                        {
                            right = toValue - 1;
                            toIndex++;
                        }
                    }
                    else
                    {
                        right = jumpFrom[fromIndex++];
                    }
                }
                else if (toIndex < jumpTo.Count)
                {
                    right = jumpTo[toIndex++];
                    if (left == right)
                    {
                        continue;
                    }
                }
                else
                {
                    if (left < evt.Count)
                    {
                        segments.Add(new AsmSegment(evt, left, evt.Count - left));
                    }
                    break;
                }

                int length = right - left + 1;
                if (length != 0)
                {
                    segments.Add(new AsmSegment(evt, left, length));
                }
                left = right + 1;
            }

            evt.Segments = segments;
        }