Exemple #1
0
 /// <summary>
 /// Compiles an assembly content description to an LLVM module.
 /// </summary>
 /// <param name="contents">An assembly content description to compile.</param>
 /// <param name="typeSystem">A type system to use.</param>
 /// <param name="mangler">A name mangler to use.</param>
 /// <returns>An LLVM module builder.</returns>
 public static ModuleBuilder Compile(
     AssemblyContentDescription contents,
     TypeEnvironment typeSystem,
     NameMangler mangler)
 {
     return(Compile(contents, typeSystem, mangler, ClrInternalCallImplementor.Instance));
 }
Exemple #2
0
        private static Task <AssemblyContentDescription> CreateContentDescriptionAsync(ClrAssembly assembly)
        {
            var typeSystem = assembly.Resolver.TypeEnvironment;
            var pipeline   = new Optimization[]
            {
                new ConstantPropagation(),
                MemoryAccessElimination.Instance,
                DeadValueElimination.Instance,
                new JumpThreading(true),
                SwitchSimplification.Instance,
                DuplicateReturns.Instance,
                TailRecursionElimination.Instance,
                BlockFusion.Instance
            };

            var optimizer = new OnDemandOptimizer(
                pipeline,
                method => GetInitialMethodBody(method, typeSystem));

            return(AssemblyContentDescription.CreateTransitiveAsync(
                       assembly.FullName,
                       assembly.Attributes,
                       assembly.Resolve(assembly.Definition.EntryPoint),
                       optimizer));
        }
Exemple #3
0
        private static Task <AssemblyContentDescription> CreateContentDescriptionAsync(
            IMethod method,
            IEnumerable <ITypeMember> memberRoots,
            IEnumerable <IType> typeRoots,
            ClrAssembly assembly)
        {
            // TODO: deduplicate this logic (it also appears in IL2LLVM and ILOpt)

            var typeSystem = assembly.Resolver.TypeEnvironment;
            var pipeline   = new Optimization[]
            {
                new ConstantPropagation(),
                MemoryAccessElimination.Instance,
                DeadValueElimination.Instance,
                new JumpThreading(true),
                SwitchSimplification.Instance,
                DuplicateReturns.Instance,
                TailRecursionElimination.Instance,
                BlockFusion.Instance
            };

            var optimizer = new OnDemandOptimizer(
                pipeline,
                m => GetInitialMethodBody(m, typeSystem));

            return(AssemblyContentDescription.CreateTransitiveAsync(
                       new SimpleName("kernel").Qualify(),
                       assembly.Attributes,
                       null,
                       new ITypeMember[] { method }.Concat(memberRoots),
                       typeRoots,
                       optimizer));
        }
Exemple #4
0
        /// <summary>
        /// Compiles an assembly content description to an LLVM module.
        /// </summary>
        /// <param name="contents">An assembly content description to compile.</param>
        /// <param name="typeSystem">A type system to use.</param>
        /// <param name="mangler">A name mangler to use.</param>
        /// <param name="internalCallImplementor">An internal call implementor to use.</param>
        /// <returns>An LLVM module builder.</returns>
        public static ModuleBuilder Compile(
            AssemblyContentDescription contents,
            TypeEnvironment typeSystem,
            NameMangler mangler,
            InternalCallImplementor internalCallImplementor)
        {
            var module  = LLVM.ModuleCreateWithName(contents.FullName.FullyUnqualifiedName.ToString());
            var builder = new ModuleBuilder(
                module,
                typeSystem,
                mangler,
                MallocInterface.Instance,
                new ClosedMetadataFormat(contents.Types, contents.TypeMembers));

            var icalls = new Dictionary <IMethod, LLVMValueRef>();

            foreach (var method in contents.TypeMembers.OfType <IMethod>())
            {
                var fun = builder.DeclareMethod(method);
                if (method.IsInternalCall())
                {
                    icalls[method] = fun;
                }
            }

            foreach (var pair in contents.MethodBodies)
            {
                builder.DefineMethod(pair.Key, pair.Value);
                icalls.Remove(pair.Key);
            }

            foreach (var pair in icalls)
            {
                internalCallImplementor.Implement(pair.Key, pair.Value, builder);
            }

            if (contents.EntryPoint != null)
            {
                // If there is an entry point, then we will synthesize a 'main' function that calls
                // said entry point.
                builder.SynthesizeMain(contents.EntryPoint);
            }

            return(builder);
        }
Exemple #5
0
 /// <summary>
 /// Compiles an assembly content description to an LLVM module.
 /// </summary>
 /// <param name="contents">An assembly content description to compile.</param>
 /// <param name="typeSystem">A type system to use.</param>
 /// <returns>An LLVM module builder.</returns>
 public static ModuleBuilder Compile(
     AssemblyContentDescription contents,
     TypeEnvironment typeSystem)
 {
     return(Compile(contents, typeSystem, new ItaniumMangler(typeSystem)));
 }