Exemple #1
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);
            }
        }
Exemple #2
0
        /// <summary>
        /// Initializes a new instance of <see cref="BaseCodeEmitter" />.
        /// </summary>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="linker">The linker.</param>
        /// <param name="codeStream">The stream the machine code is written to.</param>
        public void Initialize(string methodName, BaseLinker linker, Stream codeStream)
        {
            Debug.Assert(codeStream != null);
            Debug.Assert(linker != null);

            MethodName      = methodName;
            this.linker     = linker;
            this.codeStream = codeStream;

            // only necessary if method is being recompiled (due to inline optimization, for example)
            var symbol = linker.GetSymbol(MethodName, SectionKind.Text);

            symbol.RemovePatches();
        }
Exemple #3
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
                var symbol = linker.FindSymbol(symbolOperand.Name, section);

                // If no symbol found, look in all sections
                if (symbol == null)
                {
                    symbol = linker.FindSymbol(symbolOperand.Name);
                }

                // Otherwise create the symbol in the expected section
                if (symbol == null)
                {
                    symbol = linker.GetSymbol(symbolOperand.Name, section);
                }

                linker.Link(LinkType.AbsoluteAddress, PatchType.I4, SectionKind.Text, MethodName, pos, symbol, referenceOffset);
            }
        }
Exemple #4
0
        public static IntPtr GetMethodAddress(MosaMethod method, BaseLinker linker)
        {
            var symbol = linker.GetSymbol(method.FullName, SectionKind.Text);

            return(new IntPtr((long)symbol.VirtualAddress));
        }
Exemple #5
0
		public static ulong GetMethodAddress(MosaMethod method, BaseLinker linker)
		{
			var symbol = linker.GetSymbol(method.FullName, SectionKind.Text);

			return symbol.VirtualAddress;
		}
		protected void EmitLink(int position, Operand symbolOperand, int patchOffset, int referenceOffset = 0)
		{
			position += patchOffset;

			if (symbolOperand.IsLabel)
			{
				linker.Link(LinkType.AbsoluteAddress, PatchType.I4, SectionKind.Text, MethodName, position, 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, position, 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, position, symbol, referenceOffset);
			}
		}