Exemple #1
0
        public void Emit(BaseOpcodeEncoder opcode, Operand symbolOperand, int patchOffset, int referenceOffset = 0)
        {
            int pos = (int)codeStream.Position + patchOffset;

            Emit(opcode);

            if (symbolOperand.IsLabel)
            {
                linker.Link(LinkType.AbsoluteAddress, PatchType.I4, SectionKind.Text, MethodName, pos, SectionKind.ROData, symbolOperand.Name, referenceOffset);
            }
            else if (symbolOperand.IsStaticField)
            {
                var section = symbolOperand.Field.Data != null ? SectionKind.ROData : SectionKind.BSS;

                linker.Link(LinkType.AbsoluteAddress, PatchType.I4, SectionKind.Text, MethodName, pos, section, symbolOperand.Field.FullName, referenceOffset);
            }
            else if (symbolOperand.IsSymbol)
            {
                var section = symbolOperand.Method != null ? SectionKind.Text : SectionKind.ROData;

                // First try finding the symbol in the expected section
                // If no symbol found, look in all sections
                // Otherwise create the symbol in the expected section
                var symbol = (linker.FindSymbol(symbolOperand.Name, section) ?? linker.FindSymbol(symbolOperand.Name)) ?? linker.GetSymbol(symbolOperand.Name, section);

                linker.Link(LinkType.AbsoluteAddress, PatchType.I4, SectionKind.Text, MethodName, pos, symbol, referenceOffset);
            }
        }
Exemple #2
0
        public void Emit(OpcodeEncoder opcode, Operand symbolOperand, int symbolOffset)
        {
            int pos = (int)codeStream.Position + symbolOffset;

            Emit(opcode);

            if (symbolOperand.IsLabel)
            {
                linker.Link(LinkType.AbsoluteAddress, PatchType.I4, MethodName, SectionKind.Text, pos, 0, symbolOperand.Name, SectionKind.ROData, 0);
            }
            else if (symbolOperand.IsField)
            {
                var section = symbolOperand.Field.Data != null ? SectionKind.ROData : SectionKind.BSS;

                linker.Link(LinkType.AbsoluteAddress, PatchType.I4, MethodName, SectionKind.Text, pos, 0, symbolOperand.Field.FullName, section, (int)symbolOperand.Displacement);
            }
            else if (symbolOperand.IsSymbol)
            {
                var section = symbolOperand.Method != null ? SectionKind.Text : SectionKind.ROData;

                var symbol = linker.GetSymbol(symbolOperand.Name, section);

                if (symbol == null)
                {
                    symbol = linker.FindSymbol(symbolOperand.Name);
                }

                linker.Link(LinkType.AbsoluteAddress, PatchType.I4, MethodName, SectionKind.Text, pos, 0, symbol, 0);
            }
        }