Esempio n. 1
0
        public TypeRef(LLVMTypeRef* handle)
        {
            if(handle == null)
                throw new ArgumentNullException("handle");

            m_handle = handle;
        }
Esempio n. 2
0
        public TypeRef(LLVMTypeRef* handle, LLVMTypeRef* pointed = null)
        {
            if(handle == null)
                throw new ArgumentNullException("handle");

            m_handle = handle;
            m_pointedType = pointed;
        }
        private LLVMValueRef CreateLLVMFunction(string mangledName)
        {
            LLVMTypeRef universalSignature = LLVM.FunctionType(LLVM.VoidType(), new LLVMTypeRef[] { LLVM.PointerType(LLVM.Int8Type(), 0), LLVM.PointerType(LLVM.Int8Type(), 0) }, false);

            return(LLVM.AddFunction(Module, mangledName, universalSignature));
        }
 public static extern LLVMTypeRef* PointerType(LLVMTypeRef* ElementType, uint AddressSpace);
Esempio n. 5
0
 public static LLVMValueRef AsLLVMValue(this ulong intValue)
 {
     return(LLVMSharp.LLVM.ConstInt(LLVMTypeRef.Int64Type(), intValue, false));
 }
 public static extern void StructSetBody(LLVMTypeRef* StructTy, System.IntPtr[] ElementTypes, uint ElementCount, int Packed);
 public static extern int IsOpaqueStruct(LLVMTypeRef* StructTy);
 public static extern LLVMContextRef* GetTypeContext(LLVMTypeRef* Ty);
 public static extern LLVMTypeRef* GetReturnType(LLVMTypeRef* FunctionTy);
Esempio n. 10
0
 public BuilderStackItem(TypeReference type, LLVMTypeRef typeref)
 {
     Type    = type;
     ValRef  = null;
     TypeRef = typeref;
 }
Esempio n. 11
0
 internal FunctionType(LLVMTypeRef typeRef)
     : base(typeRef)
 {
 }
Esempio n. 12
0
 public static uint AlignmentOfType(this LLVMTargetDataRef self, LLVMTypeRef type)
 {
     return(LLVM.ABIAlignmentOfType(self, type));
 }
Esempio n. 13
0
 public static LLVMTypeRef GetPointerTo(this LLVMTypeRef self)
 {
     return(LLVM.PointerType(self, 0));
 }
Esempio n. 14
0
 public static ulong SizeOfTypeInBits(this LLVMTargetDataRef self, LLVMTypeRef type)
 {
     return(LLVM.SizeOfTypeInBits(self, type));
 }
 protected override LLVMValueRef ValueAsTypeInternal(LLVMTypeRef type, LLVMBuilderRef builder, bool signExtend)
 {
     return(_importer.LoadTemp(LocalIndex, type));
 }
Esempio n. 16
0
 internal StructType(LLVMTypeRef typeRef)
     : base(typeRef)
 {
 }
Esempio n. 17
0
 public static extern ulong OffsetOfElement(LLVMTargetDataRef* LLVMTargetDataRef, LLVMTypeRef* StructTy, uint Element);
Esempio n. 18
0
        public override bool VisitTopLevelExternDef([NotNull] GamaParser.TopLevelExternDefContext context)
        {
            var name = context.Symbol().GetText();
            var list = NamespaceContext.FindFunctionRefGlobal(name);

            if (list == null)
            {
                list = new GamaFunctionList(name);
                NamespaceContext.This.Functions.Add(list);
            }

            var retty = InstanceTypes.Void;

            var rettyfqtn = context.typeName();

            if (rettyfqtn != null)
            {
                retty = NamespaceContext.FindTypeRefGlobal(rettyfqtn);
                if (retty == null)
                {
                    GlobalContext.AddError(new ErrorTypeNotFound(context.typeName()));
                    return(false);
                }
            }

            var ellipsis       = context.ellipsis() != null;
            var parmslist      = new GamaParamList();
            var argtypes       = new GamaTypeRef[0];
            var argtypesnative = new LLVMTypeRef[0];
            var fqtnlist       = context.typeList();

            if (fqtnlist != null)
            {
                var types = fqtnlist.typeName();
                argtypesnative = new LLVMTypeRef[types.Length];
                argtypes       = new GamaTypeRef[types.Length];
                for (int i = 0; i < types.Length; i++)
                {
                    var ty = NamespaceContext.FindTypeRefGlobal(types[i]);
                    if (ty == null)
                    {
                        GlobalContext.AddError(new ErrorTypeNotFound(types[i]));
                        return(false);
                    }
                    parmslist.Add(i.ToString(), ty); // Adding parameter with a numeric name, doesn't matter since this is a extern.
                    argtypes[i]       = ty;
                    argtypesnative[i] = ty.UnderlyingType;
                }
            }

            if (list.FindFunction(parmslist) != null)
            {
                GlobalContext.AddError(new ErrorDuplicateFunction(context));
                return(false);
            }

            var fnty  = new GamaFunction(retty, argtypes, LLVMTypeRef.CreateFunction(retty.UnderlyingType, argtypesnative, ellipsis), ellipsis);
            var modfn = GlobalContext.Module.AddFunction(name, fnty.UnderlyingType);

            var fnref = new GamaFunctionRef(retty, parmslist, fnty, modfn, false);

            list.AddFunction(fnref);

            return(true);
        }
Esempio n. 19
0
 public static extern LLVMTypeKind GetTypeKind(LLVMTypeRef* Ty);
Esempio n. 20
0
        public override bool VisitTopLevelFuncDef([NotNull] GamaParser.TopLevelFuncDefContext context)
        {
            var name   = context.Symbol().GetText();
            var fnlist = NamespaceContext.FindFunctionRef(name);
            var attrs  = context.funcAttr();

            // New function
            if (fnlist == null)
            {
                fnlist = new GamaFunctionList(name);
                var stplist         = context.symbolTypePairList();
                var parms           = new GamaParamList();
                var parmTypes       = new GamaTypeRef[0];
                var parmTypesNative = new LLVMTypeRef[0];

                if (stplist != null)
                {
                    var list = stplist.symbolTypePair();

                    parmTypes       = new GamaTypeRef[list.Length];
                    parmTypesNative = new LLVMTypeRef[list.Length];

                    for (int i = 0; i < list.Length; i++)
                    {
                        var stp  = list[i];
                        var sym  = stp.Symbol();
                        var type = NamespaceContext.FindTypeRefGlobal(stp.typeName());
                        if (type == null)
                        {
                            GlobalContext.AddError(new ErrorTypeNotFound(stp.typeName()));
                            return(false);
                        }
                        /* Since functions are not first-class types, we need to wrap them around with a pointer */
                        if (type is GamaFunction)
                        {
                            type = new GamaPointer(type);
                        }
                        if (!parms.Add(sym.GetText(), type))
                        {
                            GlobalContext.AddError(new ErrorDuplicateParameter(stp));
                            return(false); // TODO: fix error library.
                        }
                        parmTypesNative[i] = type.UnderlyingType;
                        parmTypes[i]       = type;
                    }
                }

                /* Determine type */
                var rettypefqtn = context.typeName();
                var retty       = InstanceTypes.Void;

                // If function has a non-void type
                if (rettypefqtn != null)
                {
                    // Find it
                    retty = NamespaceContext.FindTypeRefGlobal(rettypefqtn);
                    if (retty == null)
                    {
                        GlobalContext.AddError(new ErrorTypeNotFound(rettypefqtn));
                        return(false);
                    }
                }

                /* LLVM */
                var modty = new GamaFunction(retty, parmTypes, LLVMTypeRef.CreateFunction(retty.UnderlyingType, parmTypesNative));
                var modfn = NamespaceContext.This.Context.Module.AddFunction(name, modty.UnderlyingType);

                var fn   = new GamaFunctionRef(retty, parms, modty, modfn, false);
                var unit = new GamaFunctionCompiler(NamespaceContext, fn);

                /* Parameters are added to top frame of the target function, but they are not treated as conventional variables */
                foreach (var p in parms.Parameters)
                {
                    unit.Top.AddValue(p.Name, new GamaValueRef(p.Type, modfn.GetParam(p.Index), false));
                }

                unit.Visit(context.block());
                if (unit.Finish() == 0)
                {
                    // First add ident, if it fails you fail too.
                    if (attrs != null)
                    {
                        var attributes = new GamaAttributeCompiler(this).Visit(attrs);
                        if (attributes != null)
                        {
                            fn.Attributes = attributes;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    fnlist.AddFunction(fn);
                    NamespaceContext.This.Functions.Add(fnlist);
                }
                else
                {
                    ; // ?gnihtemos oD :ODOT (TODO:)
                }
                return(true);
            }
            // An override function
            else
            {
                var stplist = context.symbolTypePairList();
                var parms   = new GamaParamList();
                if (stplist != null)
                {
                    var list = stplist.symbolTypePair();
                    for (int i = 0; i < list.Length; i++)
                    {
                        var stp  = list[i];
                        var sym  = stp.Symbol();
                        var type = NamespaceContext.FindTypeRefGlobal(stp.typeName());
                        if (type == null)
                        {
                            GlobalContext.AddError(new ErrorTypeNotFound(stp.typeName()));
                            return(false);
                        }
                        if (type is GamaFunction)
                        {
                            if (!parms.Add(sym.GetText(), new GamaPointer(type)))
                            {
                                GlobalContext.AddError(new ErrorDuplicateParameter(stp));
                                return(false); // TODO: fix error library.
                            }
                            continue;
                        }
                        if (!parms.Add(sym.GetText(), type))
                        {
                            GlobalContext.AddError(new ErrorDuplicateParameter(stp));
                            return(false);
                        }
                    }
                }

                // Duplicate function if two functions have same type of parameters
                if (fnlist.FindFunction(parms) != null)
                {
                    GlobalContext.AddError(new ErrorDuplicateFunction(context));
                    return(false);
                }

                /* Determine type */
                var rettypefqtn = context.typeName();
                var retty       = InstanceTypes.Void;

                // If function has a non-void type
                if (rettypefqtn != null)
                {
                    // Find it
                    retty = NamespaceContext.FindTypeRefGlobal(rettypefqtn);
                    if (retty == null)
                    {
                        GlobalContext.AddError(new ErrorTypeNotFound(rettypefqtn));
                        return(false);
                    }
                }

                var modty = new GamaFunction(retty, parms.Parameters.Select(p => p.Type).ToArray(), LLVMTypeRef.CreateFunction(retty.UnderlyingType, parms.Parameters.Select(p => p.Type.UnderlyingType).ToArray()));
                var modfn = GlobalContext.Module.AddFunction(name, modty.UnderlyingType);

                var fn   = new GamaFunctionRef(retty, parms, modty, modfn, false);
                var unit = new GamaFunctionCompiler(NamespaceContext, fn);
                unit.Visit(context.block());
                if (unit.Finish() == 0)
                {
                    if (attrs != null)
                    {
                        var attributes = new GamaAttributeCompiler(this).Visit(attrs);
                        if (attributes != null)
                        {
                            fn.Attributes = attributes;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    fnlist.AddFunction(fn);
                }
                else
                {
                    ; // TODO:
                }
                return(true);
            }
        }
Esempio n. 21
0
 public static extern LLVMTypeRef* FunctionType(LLVMTypeRef* ReturnType, System.IntPtr[] ParamTypes, uint ParamCount, int IsVarArg);
Esempio n. 22
0
 public LLVMValueRef ValueAsType(LLVMTypeRef type, LLVMBuilderRef builder)
 {
     return(ValueAsTypeInternal(type, builder, false));
 }
Esempio n. 23
0
 public static extern void GetParamTypes(LLVMTypeRef* FunctionTy, System.IntPtr[] Dest);
Esempio n. 24
0
 protected override LLVMValueRef ValueAsTypeInternal(LLVMTypeRef type, LLVMBuilderRef builder, bool signExtend)
 {
     //TODO: deal with sign extension here
     return(ILImporter.CastIfNecessary(builder, RawLLVMValue, type, Name));
 }
Esempio n. 25
0
 public static extern void GetStructElementTypes(LLVMTypeRef* StructTy, System.IntPtr[] Dest);
Esempio n. 26
0
 public GamaArray(GamaTypeRef elemtype, int size) : base($"{ elemtype.Name }[{ size }]", LLVMTypeRef.CreateArray(elemtype.UnderlyingType, (uint)size))
 {
     ElementType = elemtype;
 }
Esempio n. 27
0
 public static extern LLVMTypeRef* ArrayType(LLVMTypeRef* ElementType, uint ElementCount);
Esempio n. 28
0
 public static extern ulong ABISizeOfType(LLVMTargetDataRef* LLVMTargetDataRef, LLVMTypeRef* LLVMTypeRef);
Esempio n. 29
0
 public static extern LLVMTypeRef* VectorType(LLVMTypeRef* ElementType, uint ElementCount);
Esempio n. 30
0
 public static extern uint CallFrameAlignmentOfType(LLVMTargetDataRef* LLVMTargetDataRef, LLVMTypeRef* LLVMTypeRef);
Esempio n. 31
0
 internal TokenType(LLVMTypeRef typeRef)
     : base(typeRef)
 {
 }
        private void ImportStoreField(int token, bool isStatic)
        {
            if (isStatic)
            {
                throw new NotImplementedException("static stfld");
            }

            FieldDesc field = (FieldDesc)_methodIL.GetObject(token);

            StackEntry valueEntry  = _stack.Pop();
            StackEntry objectEntry = _stack.Pop();

            var untypedObjectPointer = LLVM.BuildPointerCast(_builder, objectEntry.LLVMValue, LLVM.PointerType(LLVMTypeRef.Int8Type(), 0), "stfld");
            var storeLocation        = LLVM.BuildGEP(_builder, untypedObjectPointer,
                                                     new LLVMValueRef[] { LLVM.ConstInt(LLVM.Int32Type(), (ulong)field.Offset.AsInt, LLVMMisc.False) }, "stfld");
            var typedStoreLocation = LLVM.BuildPointerCast(_builder, storeLocation, LLVM.PointerType(GetLLVMTypeForTypeDesc(valueEntry.Type), 0), "stfld");

            LLVM.BuildStore(_builder, valueEntry.LLVMValue, typedStoreLocation);
        }
Esempio n. 33
0
 public static extern uint ABIAlignmentOfType(LLVMTargetDataRef* LLVMTargetDataRef, LLVMTypeRef* LLVMTypeRef);
Esempio n. 34
0
        private LLVMValueRef OutputCodeForDictionaryLookup(LLVMBuilderRef builder, NodeFactory factory,
                                                           ReadyToRunGenericHelperNode node, GenericLookupResult lookup, LLVMValueRef ctx, string gepName)
        {
            // Find the generic dictionary slot
            int dictionarySlot = factory.GenericDictionaryLayout(node.DictionaryOwner).GetSlotForEntry(lookup);
            int offset         = dictionarySlot * factory.Target.PointerSize;

            // Load the generic dictionary cell
            LLVMValueRef retGep  = builder.BuildGEP(ctx, new[] { LLVMValueRef.CreateConstInt(LLVMTypeRef.Int32, (ulong)offset, false) }, "retGep");
            LLVMValueRef castGep = builder.BuildBitCast(retGep, LLVMTypeRef.CreatePointer(LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0), 0), "ptrPtr");
            LLVMValueRef retRef  = builder.BuildLoad(castGep, gepName);

            switch (lookup.LookupResultReferenceType(factory))
            {
            case GenericLookupResultReferenceType.Indirect:
                var ptrPtr = builder.BuildBitCast(retRef, LLVMTypeRef.CreatePointer(LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0), 0), "ptrPtr");
                retRef = builder.BuildLoad(ptrPtr, "indLoad");
                break;

            case GenericLookupResultReferenceType.ConditionalIndirect:
                throw new NotImplementedException();

            default:
                break;
            }

            return(retRef);
        }
Esempio n. 35
0
 public static extern uint PreferredAlignmentOfType(LLVMTargetDataRef* LLVMTargetDataRef, LLVMTypeRef* LLVMTypeRef);
Esempio n. 36
0
        public void OutputCodeForDelegateCtorInit(LLVMBuilderRef builder, LLVMValueRef helperFunc,
                                                  MethodDesc constructor,
                                                  LLVMValueRef fatFunction)
        {
            StackEntry[] argValues   = new StackEntry [constructor.Signature.Length + 1]; // for delegate this
            var          shadowStack = helperFunc.GetParam(0);

            argValues[0] = new LoadExpressionEntry(StackValueKind.ObjRef, "this", shadowStack, GetWellKnownType(WellKnownType.Object));
            for (var i = 0; i < constructor.Signature.Length; i++)
            {
                if (i == 1)
                {
                    argValues[i + 1] = new ExpressionEntry(StackValueKind.Int32, "arg" + (i + 1),
                                                           builder.BuildIntToPtr(fatFunction, LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0), "toPtr"),
                                                           GetWellKnownType(WellKnownType.IntPtr));
                }
                else
                {
                    var argRef = LoadVarAddress(i + 1, LocalVarKind.Argument, out TypeDesc type);
                    var ptrPtr = builder.BuildPointerCast(argRef,
                                                          LLVMTypeRef.CreatePointer(LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0), 0), "ptrPtr");
                    var loadArg = builder.BuildLoad(ptrPtr, "arg" + (i + 1));
                    argValues[i + 1] = new ExpressionEntry(GetStackValueKind(constructor.Signature[i]), "arg" + i + 1, loadArg,
                                                           constructor.Signature[i]);
                }
            }
            HandleCall(constructor, constructor.Signature, constructor, argValues, null);
        }
Esempio n. 37
0
 public static extern LLVMValueRef* AddFunction(LLVMModuleRef* M, [In][MarshalAs(UnmanagedType.LPStr)] string Name, LLVMTypeRef* FunctionTy);
Esempio n. 38
0
        private void EmitNativeMain(LLVMContextRef context)
        {
            LLVMValueRef shadowStackTop = Module.GetNamedGlobal("t_pShadowStackTop");

            LLVMBuilderRef builder        = context.CreateBuilder();
            var            mainSignature  = LLVMTypeRef.CreateFunction(LLVMTypeRef.Int32, new LLVMTypeRef[] { LLVMTypeRef.Int32, LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0) }, false);
            var            mainFunc       = Module.AddFunction("__managed__Main", mainSignature);
            var            mainEntryBlock = mainFunc.AppendBasicBlock("entry");

            builder.PositionAtEnd(mainEntryBlock);
            LLVMValueRef managedMain = Module.GetNamedFunction("StartupCodeMain");

            if (managedMain.Handle == IntPtr.Zero)
            {
                throw new Exception("Main not found");
            }

            LLVMTypeRef  reversePInvokeFrameType = LLVMTypeRef.CreateStruct(new LLVMTypeRef[] { LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0), LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0) }, false);
            LLVMValueRef reversePinvokeFrame     = builder.BuildAlloca(reversePInvokeFrameType, "ReversePInvokeFrame");
            LLVMValueRef RhpReversePInvoke2      = Module.GetNamedFunction("RhpReversePInvoke2");

            if (RhpReversePInvoke2.Handle == IntPtr.Zero)
            {
                RhpReversePInvoke2 = Module.AddFunction("RhpReversePInvoke2", LLVMTypeRef.CreateFunction(LLVMTypeRef.Void, new LLVMTypeRef[] { LLVMTypeRef.CreatePointer(reversePInvokeFrameType, 0) }, false));
            }

            builder.BuildCall(RhpReversePInvoke2, new LLVMValueRef[] { reversePinvokeFrame }, "");

            var shadowStack     = builder.BuildMalloc(LLVMTypeRef.CreateArray(LLVMTypeRef.Int8, 1000000), String.Empty);
            var castShadowStack = builder.BuildPointerCast(shadowStack, LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0), String.Empty);

            builder.BuildStore(castShadowStack, shadowStackTop);

            var shadowStackBottom = Module.AddGlobal(LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0), "t_pShadowStackBottom");

            shadowStackBottom.Linkage         = LLVMLinkage.LLVMExternalLinkage;
            shadowStackBottom.Initializer     = LLVMValueRef.CreateConstPointerNull(LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0));
            shadowStackBottom.ThreadLocalMode = LLVMThreadLocalMode.LLVMLocalDynamicTLSModel;
            builder.BuildStore(castShadowStack, shadowStackBottom);

            // Pass on main arguments
            LLVMValueRef argc = mainFunc.GetParam(0);
            LLVMValueRef argv = mainFunc.GetParam(1);

            LLVMValueRef mainReturn = builder.BuildCall(managedMain, new LLVMValueRef[]
            {
                castShadowStack,
                argc,
                argv,
            },
                                                        "returnValue");

            builder.BuildRet(mainReturn);
            mainFunc.Linkage = LLVMLinkage.LLVMExternalLinkage;
        }
Esempio n. 39
0
 public static extern int TypeIsSized(LLVMTypeRef* Ty);
Esempio n. 40
0
        private void GetCodeForReadyToRunGenericHelper(WebAssemblyCodegenCompilation compilation, ReadyToRunGenericHelperNode node, NodeFactory factory)
        {
            LLVMBuilderRef builder      = compilation.Module.Context.CreateBuilder();
            var            args         = new List <LLVMTypeRef>();
            MethodDesc     delegateCtor = null;

            if (node.Id == ReadyToRunHelperId.DelegateCtor)
            {
                DelegateCreationInfo target = (DelegateCreationInfo)node.Target;
                delegateCtor = target.Constructor.Method;
                bool isStatic = delegateCtor.Signature.IsStatic;
                int  argCount = delegateCtor.Signature.Length;
                if (!isStatic)
                {
                    argCount++;
                }
                for (int i = 0; i < argCount; i++)
                {
                    TypeDesc argType;
                    if (i == 0 && !isStatic)
                    {
                        argType = delegateCtor.OwningType;
                    }
                    else
                    {
                        argType = delegateCtor.Signature[i - (isStatic ? 0 : 1)];
                    }
                    args.Add(ILImporter.GetLLVMTypeForTypeDesc(argType));
                }
            }

            LLVMValueRef helperFunc = Module.GetNamedFunction(node.GetMangledName(factory.NameMangler));

            if (helperFunc.Handle == IntPtr.Zero)
            {
                throw new Exception("if the function is requested here, it should have been created earlier");
            }
            var helperBlock = helperFunc.AppendBasicBlock("genericHelper");

            builder.PositionAtEnd(helperBlock);
            var          importer = new ILImporter(builder, compilation, Module, helperFunc, delegateCtor);
            LLVMValueRef ctx;
            string       gepName;

            if (node is ReadyToRunGenericLookupFromTypeNode)
            {
                // Locate the VTable slot that points to the dictionary
                int vtableSlot = VirtualMethodSlotHelper.GetGenericDictionarySlot(factory, (TypeDesc)node.DictionaryOwner);

                int pointerSize = factory.Target.PointerSize;
                // Load the dictionary pointer from the VTable
                int slotOffset    = EETypeNode.GetVTableOffset(pointerSize) + (vtableSlot * pointerSize);
                var slotGep       = builder.BuildGEP(helperFunc.GetParam(1), new[] { LLVMValueRef.CreateConstInt(LLVMTypeRef.Int32, (ulong)slotOffset, false) }, "slotGep");
                var slotGepPtrPtr = builder.BuildPointerCast(slotGep,
                                                             LLVMTypeRef.CreatePointer(LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0), 0), "slotGepPtrPtr");
                ctx     = builder.BuildLoad(slotGepPtrPtr, "dictGep");
                gepName = "typeNodeGep";
            }
            else
            {
                ctx     = helperFunc.GetParam(1);
                gepName = "paramGep";
            }

            LLVMValueRef resVar = OutputCodeForDictionaryLookup(builder, factory, node, node.LookupSignature, ctx, gepName);

            switch (node.Id)
            {
            case ReadyToRunHelperId.GetNonGCStaticBase:
            {
                MetadataType target = (MetadataType)node.Target;

                if (compilation.HasLazyStaticConstructor(target))
                {
                    importer.OutputCodeForTriggerCctor(target, resVar);
                }
            }
            break;

            case ReadyToRunHelperId.GetGCStaticBase:
            {
                MetadataType target = (MetadataType)node.Target;

                var ptrPtrPtr = builder.BuildBitCast(resVar, LLVMTypeRef.CreatePointer(LLVMTypeRef.CreatePointer(LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0), 0), 0), "ptrPtrPtr");

                resVar = builder.BuildLoad(builder.BuildLoad(ptrPtrPtr, "ind1"), "ind2");

                if (compilation.HasLazyStaticConstructor(target))
                {
                    GenericLookupResult nonGcRegionLookup = factory.GenericLookup.TypeNonGCStaticBase(target);
                    var nonGcStaticsBase = OutputCodeForDictionaryLookup(builder, factory, node, nonGcRegionLookup, ctx, "lazyGep");
                    importer.OutputCodeForTriggerCctor(target, nonGcStaticsBase);
                }
            }
            break;

            case ReadyToRunHelperId.GetThreadStaticBase:
            {
                MetadataType target = (MetadataType)node.Target;

                if (compilation.HasLazyStaticConstructor(target))
                {
                    GenericLookupResult nonGcRegionLookup = factory.GenericLookup.TypeNonGCStaticBase(target);
                    var threadStaticBase = OutputCodeForDictionaryLookup(builder, factory, node, nonGcRegionLookup, ctx, "tsGep");
                    importer.OutputCodeForTriggerCctor(target, threadStaticBase);
                }
                resVar = importer.OutputCodeForGetThreadStaticBaseForType(resVar).ValueAsType(LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0), builder);
            }
            break;

            case ReadyToRunHelperId.DelegateCtor:
            {
                DelegateCreationInfo target      = (DelegateCreationInfo)node.Target;
                MethodDesc           constructor = target.Constructor.Method;
                var fatPtr = ILImporter.MakeFatPointer(builder, resVar, compilation);
                importer.OutputCodeForDelegateCtorInit(builder, helperFunc, constructor, fatPtr);
            }
            break;

            // These are all simple: just get the thing from the dictionary and we're done
            case ReadyToRunHelperId.TypeHandle:
            case ReadyToRunHelperId.TypeHandleForCasting:
            case ReadyToRunHelperId.MethodHandle:
            case ReadyToRunHelperId.FieldHandle:
            case ReadyToRunHelperId.MethodDictionary:
            case ReadyToRunHelperId.MethodEntry:
            case ReadyToRunHelperId.VirtualDispatchCell:
            case ReadyToRunHelperId.DefaultConstructor:
                break;

            default:
                throw new NotImplementedException();
            }

            if (node.Id != ReadyToRunHelperId.DelegateCtor)
            {
                builder.BuildRet(resVar);
            }
            else
            {
                builder.BuildRetVoid();
            }
        }
Esempio n. 41
0
 public static extern uint GetIntTypeWidth(LLVMTypeRef* IntegerTy);
Esempio n. 42
0
 public void SetLLVMType(string pType, LLVMTypeRef pLLVMType)
 {
     _types.SetLLVMType(pType, pLLVMType);
 }
Esempio n. 43
0
 public static extern int IsFunctionVarArg(LLVMTypeRef* FunctionTy);
Esempio n. 44
0
 internal SequentialType(LLVMTypeRef typeRef)
     : base(typeRef)
 {
 }
Esempio n. 45
0
 public static extern uint CountParamTypes(LLVMTypeRef* FunctionTy);
        static void BuildFinallyFunclet(LLVMModuleRef module)
        {
            LlvmFinallyFunclet = module.AddFunction("LlvmFinallyFunclet", LLVMTypeRef.CreateFunction(LLVMTypeRef.Void,
                                                                                                     new LLVMTypeRef[]
            {
                LLVMTypeRef.CreatePointer(LLVMTypeRef.CreateFunction(LLVMTypeRef.Void, new LLVMTypeRef[] { LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0) }, false), 0), // finallyHandler
                LLVMTypeRef.CreatePointer(LLVMTypeRef.Int8, 0),                                                                                                          // shadow stack
            }, false));
            var            block          = LlvmFinallyFunclet.AppendBasicBlock("Finally");
            LLVMBuilderRef funcletBuilder = Context.CreateBuilder();

            funcletBuilder.PositionAtEnd(block);

            var finallyFunclet  = LlvmFinallyFunclet.GetParam(0);
            var castShadowStack = LlvmFinallyFunclet.GetParam(1);

            List <LLVMValueRef> llvmArgs = new List <LLVMValueRef>();

            llvmArgs.Add(castShadowStack);

            funcletBuilder.BuildCall(finallyFunclet, llvmArgs.ToArray(), string.Empty);
            funcletBuilder.BuildRetVoid();
            funcletBuilder.Dispose();
        }
Esempio n. 47
0
 public static extern System.IntPtr GetStructName(LLVMTypeRef* Ty);
Esempio n. 48
0
 public LLVMValueRef ValueAsType(LLVMTypeRef type, LLVMBuilderRef builder)
 {
     return(ValueAsTypeInternal(type, builder, Type != null && (Type.IsWellKnownType(WellKnownType.SByte) || Type.IsWellKnownType(WellKnownType.Int16))));
 }
Esempio n. 49
0
 public static extern uint CountStructElementTypes(LLVMTypeRef* StructTy);
Esempio n. 50
0
 protected abstract LLVMValueRef ValueAsTypeInternal(LLVMTypeRef type, LLVMBuilderRef builder, bool signExtend);
Esempio n. 51
0
 public static extern int IsPackedStruct(LLVMTypeRef* StructTy);
Esempio n. 52
0
 protected override LLVMValueRef ValueAsTypeInternal(LLVMTypeRef type, LLVMBuilderRef builder, bool signExtend)
 {
     return(LLVMValueRef.CreateConstReal(type, Value));
 }
Esempio n. 53
0
 public static extern LLVMTypeRef* GetElementType(LLVMTypeRef* Ty);
Esempio n. 54
0
 protected override LLVMValueRef ValueAsTypeInternal(LLVMTypeRef type, LLVMBuilderRef builder, bool signExtend)
 {
     return(ILImporter.LoadValue(builder, RawLLVMValue, Type, type, signExtend, $"Load{Name}"));
 }
Esempio n. 55
0
 public static extern uint GetArrayLength(LLVMTypeRef* ArrayTy);
Esempio n. 56
0
 protected override LLVMValueRef ValueAsTypeInternal(LLVMTypeRef type, LLVMBuilderRef builder, bool signExtend)
 {
     throw new InvalidOperationException();
 }
Esempio n. 57
0
 public static extern uint GetPointerAddressSpace(LLVMTypeRef* PointerTy);
Esempio n. 58
0
 protected override LLVMValueRef ValueAsTypeInternal(LLVMTypeRef type, LLVMBuilderRef builder, bool signExtend)
 {
     return ILImporter.CastIfNecessary(builder, RawLLVMValue, type, Name, !signExtend);
 }
Esempio n. 59
0
 public static extern uint GetVectorSize(LLVMTypeRef* VectorTy);
Esempio n. 60
0
 public static LLVMValueRef AsLLVMValue(this int intValue)
 {
     return(LLVMSharp.LLVM.ConstInt(LLVMTypeRef.Int32Type(), (ulong)intValue, true));
 }