예제 #1
0
        public T Run <T>(TestCompilerSettings settings, string ns, string type, string method, params object[] parameters)
        {
            CompileTestCode(settings);

            // Find the test method to execute
            RuntimeMethod runtimeMethod = FindMethod(
                ns,
                type,
                method
                );

            Debug.Assert(runtimeMethod != null, runtimeMethod.ToString());
            //Debug.Assert(runtimeMethod.Address != null, runtimeMethod.ToString());
            //Debug.Assert(runtimeMethod.Address != IntPtr.Zero, runtimeMethod.ToString());

            // Get delegate name
            string delegateName;

            if (default(T) is System.ValueType)
            {
                delegateName = "Mosa.Test.Prebuilt.Delegates+" + DelegateUtility.GetDelegteName(default(T), parameters);
            }
            else
            {
                delegateName = "Mosa.Test.Prebuilt.Delegates+" + DelegateUtility.GetDelegteName(null, parameters);
            }

            // Get the prebuilt delegate type
            Type delegateType = Prebuilt.GetType(delegateName);

            Debug.Assert(delegateType != null, delegateName);

            IntPtr address = linker.GetSymbol(runtimeMethod.ToString()).VirtualAddress;

            // Create a delegate for the test method
            Delegate fn = Marshal.GetDelegateForFunctionPointer(
                address,
                delegateType
                );

            // Execute the test method
            object tempResult = fn.DynamicInvoke(parameters);

            try
            {
                if (default(T) is System.ValueType)
                {
                    return((T)tempResult);
                }
                else
                {
                    return(default(T));
                }
            }
            catch (InvalidCastException e)
            {
                Assert.Fail(@"Failed to convert result {0} of type {1} to type {2}.", tempResult, tempResult.GetType(), typeof(T));
                throw e;
            }
        }
예제 #2
0
        protected string FormatRuntimeMember(RuntimeMethod method)
        {
            if (!showTokenValues.Checked)
            {
                return(method.Name);
            }

            return("[" + TokenToString(method.Token) + "] " + method.ToString());
        }
        private void CompileMethod(RuntimeMethod method)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write(@"[Compiling]  ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine(method.ToString());
            Debug.WriteLine(@"Compiling " + method.ToString());
            using (IMethodCompiler mc = compiler.CreateMethodCompiler(this, method.DeclaringType, method))
            {
                mc.Compile();

                //try
                //{
                //    mc.Compile();
                //}
                //catch (Exception e)
                //{
                //    HandleCompilationException(e);
                //    throw;
                //}
            }
        }
        /// <summary>
        /// Performs stage specific processing on the compiler context.
        /// </summary>
        void IAssemblyCompilerStage.Run()
        {
            CheckImplementation();

            ITypeModule mainModule = typeSystem.MainTypeModule;

            if (mainModule.MetadataModule.EntryPoint.RID != 0)
            {
                RuntimeMethod entrypoint = mainModule.GetMethod(mainModule.MetadataModule.EntryPoint);

                implementation.EntryPoint = GetSymbol(entrypoint.ToString());
            }

            // Run the real linker
            IAssemblyCompilerStage assemblyCompilerStage = implementation as IAssemblyCompilerStage;

            Debug.Assert(assemblyCompilerStage != null, @"Linker doesn't implement IAssemblyCompilerStage.");
            if (assemblyCompilerStage != null)
            {
                assemblyCompilerStage.Run();
            }
        }
        /// <summary>
        /// Issues a linker request for the given runtime method.
        /// </summary>
        /// <param name="linkType">The type of link required.</param>
        /// <param name="method">The method the patched code belongs to.</param>
        /// <param name="methodOffset">The offset inside the method where the patch is placed.</param>
        /// <param name="methodRelativeBase">The base virtualAddress, if a relative link is required.</param>
        /// <param name="targetSymbolName">The linker symbol to link against.</param>
        /// <param name="offset">The offset to apply to the symbol to link against.</param>
        /// <returns>
        /// The return value is the preliminary virtualAddress to place in the generated machine
        /// code. On 32-bit systems, only the lower 32 bits are valid. The above are not used. An implementation of
        /// IAssemblyLinker may not rely on 64-bits being stored in the memory defined by position.
        /// </returns>
        public virtual long Link(LinkType linkType, RuntimeMethod method, int methodOffset, int methodRelativeBase, string targetSymbolName, IntPtr offset)
        {
            Debug.Assert(null != targetSymbolName, @"Symbol can't be null.");
            if (null == targetSymbolName)
                throw new ArgumentNullException(@"symbol");

            string symbolName = method.ToString();
            return this.Link(linkType, symbolName, methodOffset, methodRelativeBase, targetSymbolName, offset);
        }
예제 #6
0
        /// <summary>
        /// Creates a symbol operand for the given method.
        /// </summary>
        /// <param name="method">The method to create a symbol operand for.</param>
        /// <returns>The created symbol operand.</returns>
        public static SymbolOperand FromMethod(RuntimeMethod method)
        {
            string symbolName = method.ToString();

            return new SymbolOperand(BuiltInSigType.IntPtr, symbolName);
        }
        private void CompileMethod(RuntimeMethod method)
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write(@"[Compiling]  ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine(method.ToString());
            Debug.WriteLine(@"Compiling " + method.ToString());
            using (IMethodCompiler mc = compiler.CreateMethodCompiler(this, method.DeclaringType, method))
            {
                mc.Compile();

                //try
                //{
                //    mc.Compile();
                //}
                //catch (Exception e)
                //{
                //    HandleCompilationException(e);
                //    throw;
                //}
            }
        }
예제 #8
0
 /// <summary>
 /// Requests a stream to emit native instructions to.
 /// </summary>
 /// <returns>A stream object, which can be used to store emitted instructions.</returns>
 public virtual Stream RequestCodeStream()
 {
     return(linker.Allocate(method.ToString(), SectionKind.Text, 0, 0));
 }
예제 #9
0
        private string CreateSymbolName(RuntimeMethod symbol)
        {
            //if (symbol == null)
            //    throw new ArgumentNullException("symbol");

            //// TODO: If it is a generic method instance, then the symbol name needs to be carefully constructed. ~BMarkham,2/18/09
            //if (symbol.IsGeneric)
            //    throw new NotImplementedException();

            //StringBuilder sb = new StringBuilder();
            //sb.Append(CreateSymbolName(symbol.DeclaringType));
            //sb.Append('.');
            //sb.Append(symbol.Name);
            //sb.Append('(');
            //bool hasEmittedSignaturePart = false;
            //foreach (SigType parameterSignatureType in symbol.Signature.Parameters) {
            //    if (hasEmittedSignaturePart)
            //        sb.Append(',');
            //    sb.Append(parameterSignatureType.ToSymbolPart()); // FIXME : This obviously doesn't work! We need to emit class names.
            //    hasEmittedSignaturePart = true;
            //}
            //sb.Append(')');
            //return sb.ToString();

            string symbolName = symbol.ToString();
            return symbolName;
        }
예제 #10
0
        /// <summary>
        /// Creates a symbol operand for the given method.
        /// </summary>
        /// <param name="method">The method to create a symbol operand for.</param>
        /// <returns>The created symbol operand.</returns>
        public static SymbolOperand FromMethod(RuntimeMethod method)
        {
            string symbolName = method.ToString();

            return(new SymbolOperand(BuiltInSigType.IntPtr, symbolName));
        }