Esempio n. 1
0
        /// <summary>
        /// Link time code generator used to compile dynamically created methods during link time.
        /// </summary>
        /// <param name="compiler">The assembly compiler used to compile this method.</param>
        /// <param name="methodName">The name of the created method.</param>
        /// <param name="instructionSet">The instruction set.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="compiler"/>, <paramref name="methodName"/> or <paramref name="instructionSet"/> is null.</exception>
        /// <exception cref="System.ArgumentException"><paramref name="methodName"/> is invalid.</exception>
        public static CompilerGeneratedMethod Compile(AssemblyCompiler compiler, string methodName, InstructionSet instructionSet)
        {
            if (compiler == null)
            {
                throw new ArgumentNullException(@"compiler");
            }
            if (methodName == null)
            {
                throw new ArgumentNullException(@"methodName");
            }
            if (methodName.Length == 0)
            {
                throw new ArgumentException(@"Invalid method name.");
            }

            // Create the type if we need to.
            CompilerGeneratedType type = compilerGeneratedType;

            if (type == null)
            {
                type = compilerGeneratedType = new CompilerGeneratedType(compiler.Assembly, @"Mosa.Tools.Compiler", @"LinkerGenerated");
            }

            // Create the method
            // HACK: <$> prevents the method from being called from CIL
            CompilerGeneratedMethod method = new CompilerGeneratedMethod(compiler.Assembly, "<$>" + methodName, type);

            type.Methods.Add(method);

            LinkerMethodCompiler methodCompiler = new LinkerMethodCompiler(compiler, method, instructionSet);

            methodCompiler.Compile();
            return(method);
        }
        /// <summary>
        /// Link time code generator used to compile dynamically created methods during link time.
        /// </summary>
        /// <param name="compiler">The assembly compiler used to compile this method.</param>
        /// <param name="methodName">The name of the created method.</param>
        /// <param name="instructionSet">The instruction set.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="compiler"/>, <paramref name="methodName"/> or <paramref name="instructionSet"/> is null.</exception>
        /// <exception cref="System.ArgumentException"><paramref name="methodName"/> is invalid.</exception>
        public static LinkerGeneratedMethod Compile(AssemblyCompiler compiler, string methodName, InstructionSet instructionSet, ITypeSystem typeSystem)
        {
            if (compiler == null)
                throw new ArgumentNullException(@"compiler");
            if (methodName == null)
                throw new ArgumentNullException(@"methodName");
            if (methodName.Length == 0)
                throw new ArgumentException(@"Invalid method name.");

            LinkerGeneratedType compilerGeneratedType = typeSystem.InternalTypeModule.GetType(@"Mosa.Tools.Compiler", @"LinkerGenerated") as LinkerGeneratedType;

            // Create the type if we need to.
            if (compilerGeneratedType == null)
            {
                compilerGeneratedType = new LinkerGeneratedType(typeSystem.InternalTypeModule, @"Mosa.Tools.Compiler", @"LinkerGenerated", null);
                typeSystem.AddInternalType(compilerGeneratedType);
            }

            MethodSignature signature = new MethodSignature(new SigType(CilElementType.Void), new SigType[0]);

            // Create the method
            // HACK: <$> prevents the method from being called from CIL
            LinkerGeneratedMethod method = new LinkerGeneratedMethod(typeSystem.InternalTypeModule, "<$>" + methodName, compilerGeneratedType, signature);
            compilerGeneratedType.AddMethod(method);

            LinkerMethodCompiler methodCompiler = new LinkerMethodCompiler(compiler, compiler.Pipeline.FindFirst<ICompilationSchedulerStage>(), method, instructionSet);
            methodCompiler.Compile();
            return method;
        }
        /// <summary>
        /// Link time code generator used to compile dynamically created methods during link time.
        /// </summary>
        /// <param name="compiler">The assembly compiler used to compile this method.</param>
        /// <param name="methodName">The name of the created method.</param>
        /// <param name="instructionSet">The instruction set.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="compiler"/>, <paramref name="methodName"/> or <paramref name="instructionSet"/> is null.</exception>
        /// <exception cref="System.ArgumentException"><paramref name="methodName"/> is invalid.</exception>
        public static CompilerGeneratedMethod Compile(AssemblyCompiler compiler, string methodName, InstructionSet instructionSet)
        {
            if (compiler == null)
                throw new ArgumentNullException(@"compiler");
            if (methodName == null)
                throw new ArgumentNullException(@"methodName");
            if (methodName.Length == 0)
                throw new ArgumentException(@"Invalid method name.");

            // Create the type if we need to.
            if (compilerGeneratedType == null)
                compilerGeneratedType = new CompilerGeneratedType(compiler.Assembly, @"Mosa.Tools.Compiler", @"LinkerGenerated");

            // Create the method
            // HACK: <$> prevents the method from being called from CIL
            CompilerGeneratedMethod method = new CompilerGeneratedMethod(compiler.Assembly, "<$>" + methodName, compilerGeneratedType);
            compilerGeneratedType.AddMethod(method);

            LinkerMethodCompiler methodCompiler = new LinkerMethodCompiler(compiler, compiler.Pipeline.FindFirst<ICompilationSchedulerStage>(), method, instructionSet);
            methodCompiler.Compile();
            return method;
        }
Esempio n. 4
0
        /// <summary>
        /// Link time code generator used to compile dynamically created methods during link time.
        /// </summary>
        /// <param name="compiler">The assembly compiler used to compile this method.</param>
        /// <param name="methodName">The name of the created method.</param>
        /// <param name="instructionSet">The instruction set.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException"><paramref name="compiler"/>, <paramref name="methodName"/> or <paramref name="instructionSet"/> is null.</exception>
        /// <exception cref="System.ArgumentException"><paramref name="methodName"/> is invalid.</exception>
        public static LinkerGeneratedMethod Compile(AssemblyCompiler compiler, string methodName, InstructionSet instructionSet, ITypeSystem typeSystem)
        {
            if (compiler == null)
            {
                throw new ArgumentNullException(@"compiler");
            }
            if (methodName == null)
            {
                throw new ArgumentNullException(@"methodName");
            }
            if (methodName.Length == 0)
            {
                throw new ArgumentException(@"Invalid method name.");
            }

            LinkerGeneratedType compilerGeneratedType = typeSystem.InternalTypeModule.GetType(@"Mosa.Tools.Compiler", @"LinkerGenerated") as LinkerGeneratedType;

            // Create the type if we need to.
            if (compilerGeneratedType == null)
            {
                compilerGeneratedType = new LinkerGeneratedType(typeSystem.InternalTypeModule, @"Mosa.Tools.Compiler", @"LinkerGenerated", null);
                typeSystem.AddInternalType(compilerGeneratedType);
            }

            MethodSignature signature = new MethodSignature(new SigType(CilElementType.Void), new SigType[0]);

            // Create the method
            // HACK: <$> prevents the method from being called from CIL
            LinkerGeneratedMethod method = new LinkerGeneratedMethod(typeSystem.InternalTypeModule, "<$>" + methodName, compilerGeneratedType, signature);

            compilerGeneratedType.AddMethod(method);

            LinkerMethodCompiler methodCompiler = new LinkerMethodCompiler(compiler, compiler.Pipeline.FindFirst <ICompilationSchedulerStage>(), method, instructionSet);

            methodCompiler.Compile();
            return(method);
        }
 private void Compile(RuntimeMethod method)
 {
     LinkerMethodCompiler methodCompiler = new LinkerMethodCompiler(this.compiler, this.compiler.Pipeline.FindFirst<ICompilationSchedulerStage>(), method, this.InstructionSet);
     methodCompiler.Compile();
 }