Beispiel #1
0
        private static LLVMAbi PickLLVMAbi(ITypeMember Member, LLVMAssembly DeclaringAssembly)
        {
            var abiName = LLVMAttributes.GetAbiName(Member);

            if (abiName != null)
            {
                switch (abiName.ToLowerInvariant())
                {
                case "c":
                    return(DeclaringAssembly.ExternalAbi);

                case "c++":
                case "c#":
                    return(DeclaringAssembly.Abi);

                default:
                    throw new InvalidDataException(
                              LLVMAttributes.AbiAttributeName + " specified unknown ABI '" + abiName + "'");
                }
            }
            else if (Member.IsStatic && IsImportedMember(Member))
            {
                return(DeclaringAssembly.ExternalAbi);
            }
            else
            {
                return(DeclaringAssembly.Abi);
            }
        }
 public LLVMNamespace(
     UnqualifiedName Name,
     QualifiedName FullName,
     LLVMAssembly Assembly)
 {
     this.Name               = Name;
     this.FullName           = FullName;
     this.Assembly           = Assembly;
     this.declaredTypes      = new List <LLVMType>();
     this.declaredNamespaces = new List <LLVMNamespace>();
 }
Beispiel #3
0
 /// <summary>
 /// Gets the ABI for the given member.
 /// </summary>
 /// <param name="Member">The member for which an ABI is to be found.</param>
 /// <param name="DeclaringAssembly">The assembly that is examined for candidate ABIs.</param>
 /// <returns>The right ABI for the given member.</returns>
 public static LLVMAbi GetLLVMAbi(ITypeMember Member, LLVMAssembly DeclaringAssembly)
 {
     if (Member is LLVMMethod)
     {
         return(((LLVMMethod)Member).Abi);
     }
     else if (Member is LLVMField)
     {
         return(((LLVMField)Member).Abi);
     }
     else
     {
         return(PickLLVMAbi(Member, DeclaringAssembly));
     }
 }
Beispiel #4
0
 /// <summary>
 /// Creates a module builder from the given assembly and module.
 /// </summary>
 public LLVMModuleBuilder(LLVMAssembly Assembly, LLVMModuleRef Module)
 {
     this.assembly               = Assembly;
     this.module                 = Module;
     this.declaredMethods        = new Dictionary <IMethod, LLVMValueRef>();
     this.declaredVirtMethods    = new Dictionary <IMethod, LLVMValueRef>();
     this.declaredPrototypes     = new Dictionary <IMethod, LLVMTypeRef>();
     this.declaredTypes          = new Dictionary <IType, LLVMTypeRef>();
     this.declaredDataLayouts    = new Dictionary <LLVMType, LLVMTypeRef>();
     this.declaredGlobals        = new Dictionary <IField, LLVMValueRef>();
     this.declaredTypeIds        = new Dictionary <IType, ulong>();
     this.declaredTypePrimes     = new Dictionary <IType, ulong>();
     this.declaredTypeIndices    = new Dictionary <IType, ulong>();
     this.declaredVTables        = new Dictionary <IType, VTableInstance>();
     this.declaredIntrinsics     = new Dictionary <IntrinsicValue, LLVMValueRef>();
     this.interfaceStubs         = new Dictionary <LLVMMethod, InterfaceStub>();
     this.primeGen               = new PrimeNumberGenerator();
     this.staticConstructorLocks = new Dictionary <
         LLVMType,
         Tuple <LLVMValueRef, LLVMValueRef, LLVMValueRef, LLVMValueRef> >();
     this.declaredStringChars = new Dictionary <string, LLVMValueRef>();
 }
Beispiel #5
0
        public BuildTarget CreateBuildTarget(string PlatformIdentifier, AssemblyCreationInfo Info, IDependencyBuilder DependencyBuilder)
        {
            var multiBinder = new MultiBinder(DependencyBuilder.Binder.Environment);

            multiBinder.AddBinder(DependencyBuilder.Binder);

            bool isWholeProgram = DependencyBuilder.Log.Options.GetFlag(
                Flags.WholeProgramFlagName,
                Info.IsExecutable);

            var targetAsm = new LLVMAssembly(
                new SimpleName(Info.Name),
                Info.Version,
                DependencyBuilder.Environment,
                new LLVMAbi(
                    ItaniumMangler.Instance,
                    new ExternalGCDescription(multiBinder, DependencyBuilder.Log),
                    ItaniumCxxEHDescription.Instance),
                AttributeMap.Empty,
                isWholeProgram);

            // -fintegrated-runtime will look in the compiled assembly for runtime types.
            // This flag facilitates building the runtime library.
            if (DependencyBuilder.Log.Options.GetFlag("integrated-runtime", false))
            {
                multiBinder.AddBinder(targetAsm.CreateBinder());
            }

            var extraPasses = new PassManager();

            // Always use -flower-box-unbox-types to lower box/unbox.
            extraPasses.RegisterMethodPass(
                new AtomicPassInfo <BodyPassArgument, IStatement>(
                    BoxUnboxTypePass.Instance,
                    BoxUnboxTypePass.BoxUnboxTypePassName));

            extraPasses.RegisterPassCondition(BoxUnboxTypePass.BoxUnboxTypePassName, UseAlways);

            // Always use -flower-string-concat to lower string concatenation to calls.
            extraPasses.RegisterMethodPass(
                new AtomicPassInfo <BodyPassArgument, IStatement>(
                    StringConcatPass.Instance,
                    StringConcatPass.StringConcatPassName));

            extraPasses.RegisterPassCondition(StringConcatPass.StringConcatPassName, UseAlways);

            // Always use -flower-string-literals to lower string literals to calls.
            extraPasses.RegisterMethodPass(
                new AtomicPassInfo <BodyPassArgument, IStatement>(
                    StringLiteralPass.Instance,
                    StringLiteralPass.StringLiteralPassName));

            extraPasses.RegisterPassCondition(StringLiteralPass.StringLiteralPassName, UseAlways);

            // Always use -fregister-finalizers to setup finalizers.
            extraPasses.RegisterMethodPass(
                new AtomicPassInfo <IStatement, IStatement>(
                    new FinalizerRegistrationPass(targetAsm.Abi.GarbageCollector),
                    FinalizerRegistrationPass.FinalizerRegistrationPassName));

            extraPasses.RegisterPassCondition(FinalizerRegistrationPass.FinalizerRegistrationPassName, UseAlways);

            // Always use -flower-new-struct, for correctness reasons.
            extraPasses.RegisterPassCondition(NewValueTypeLoweringPass.NewValueTypeLoweringPassName, UseAlways);

            // Always use -fexpand-generics-llvm to expand generic definitions.
            extraPasses.RegisterMemberLoweringPass(
                new AtomicPassInfo <MemberLoweringPassArgument, MemberConverter>(
                    new GenericsExpansionPass(NameExpandedType, NameExpandedMethod),
                    GenericsExpansionPass.GenericsExpansionPassName + "-llvm"));

            extraPasses.RegisterPassCondition(
                GenericsExpansionPass.GenericsExpansionPassName + "-llvm",
                UseAlways);

            // Use -finternalize-generics to keep generic definitions from creeping
            // into assemblies that are not compiled with -fwhole-program.
            extraPasses.RegisterSignaturePass(
                new AtomicPassInfo <MemberSignaturePassArgument <IMember>, MemberSignaturePassResult>(
                    GenericsInternalizingPass.Instance,
                    GenericsInternalizingPass.GenericsInternalizingPassName));

            extraPasses.RegisterPassCondition(
                GenericsInternalizingPass.GenericsInternalizingPassName,
                UseAlways);

            // Use -fdeconstruct-cfg-eh to deconstruct exception control-flow graphs
            // if -O2 or higher has been specified (we won't construct a flow graph
            // otherwise)
            extraPasses.RegisterPassCondition(
                new PassCondition(
                    DeconstructExceptionFlowPass.DeconstructExceptionFlowPassName,
                    UseOptimizeNormal));

            // Use -fdeconstruct-cfg to deconstruct control-flow graphs if -O2 or more
            // has been specified (we won't construct a flow graph otherwise)
            extraPasses.RegisterPassCondition(
                new PassCondition(
                    DeconstructFlowGraphPass.DeconstructFlowGraphPassName,
                    UseOptimizeNormal));

            return(new BuildTarget(targetAsm, DependencyBuilder, "ll", true, extraPasses.ToPreferences()));
        }