コード例 #1
0
        private void scanNativeCodeSequences(CompilerContext context)
        {
            NativeCodeManager nativeCodeManager = context.NativeCodeManager;

//JAVA TO C# CONVERTER WARNING: Unlike Java's ListIterator, enumerators in .NET do not allow altering the collection:
            for (IEnumerator <CodeInstruction> lit = codeInstructions.GetEnumerator(); lit.MoveNext();)
            {
                CodeInstruction    codeInstruction    = lit.Current;
                NativeCodeSequence nativeCodeSequence = nativeCodeManager.getNativeCodeSequence(codeInstruction, this);
                if (nativeCodeSequence != null)
                {
                    if (nativeCodeSequence.Hook)
                    {
                        HookCodeInstruction hookCodeInstruction = new HookCodeInstruction(nativeCodeSequence, codeInstruction);

                        // Replace the current code instruction by the hook code instruction
//JAVA TO C# CONVERTER TODO TASK: .NET enumerators are read-only:
                        lit.remove();
                        lit.add(hookCodeInstruction);
                    }
                    else
                    {
                        NativeCodeInstruction nativeCodeInstruction = new NativeCodeInstruction(codeInstruction.Address, nativeCodeSequence);

                        if (nativeCodeInstruction.Branching)
                        {
                            IsBranchTarget = nativeCodeInstruction.BranchingTo;
                        }

                        if (nativeCodeSequence.WholeCodeBlock)
                        {
                            codeInstructions.Clear();
                            codeInstructions.AddLast(nativeCodeInstruction);
                        }
                        else
                        {
                            // Remove the first opcode that started this native code sequence
//JAVA TO C# CONVERTER TODO TASK: .NET enumerators are read-only:
                            lit.remove();

                            // Add any code instructions that need to be inserted before
                            // the native code sequence
                            IList <CodeInstruction> beforeCodeInstructions = nativeCodeSequence.BeforeCodeInstructions;
                            if (beforeCodeInstructions != null)
                            {
                                foreach (CodeInstruction beforeCodeInstruction in beforeCodeInstructions)
                                {
                                    CodeInstruction newCodeInstruction = new CodeInstruction(beforeCodeInstruction);
                                    newCodeInstruction.Address = codeInstruction.Address;

                                    lit.add(newCodeInstruction);
                                }
                            }

                            // Add the native code sequence itself
                            lit.add(nativeCodeInstruction);

                            // Remove the further opcodes from the native code sequence
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                            for (int i = nativeCodeSequence.NumOpcodes - 1; i > 0 && lit.hasNext(); i--)
                            {
                                lit.Current;
//JAVA TO C# CONVERTER TODO TASK: .NET enumerators are read-only:
                                lit.remove();
                            }
                        }
                    }
                }
            }
        }