Ejemplo n.º 1
0
 public Field(FieldDefinition fieldDefinition, Type declaringType, Type type, int structIndex)
 {
     FieldDefinition = fieldDefinition;
     DeclaringType = declaringType;
     Type = type;
     StructIndex = structIndex;
 }
Ejemplo n.º 2
0
 public Field(FieldDefinition fieldDefinition, Class declaringClass, Type type, int structIndex)
 {
     FieldDefinition = fieldDefinition;
     DeclaringClass = declaringClass;
     Type = type;
     StructIndex = structIndex;
 }
Ejemplo n.º 3
0
        public Function(Type declaringType, MethodReference methodReference, TypeRef functionType, ValueRef generatedValue, FunctionSignature signature)
        {
            Signature = signature;
            DeclaringType = declaringType;
            MethodReference = methodReference;
            FunctionType = functionType;
            GeneratedValue = generatedValue;
            VirtualSlot = -1;

            MethodDefinition = methodReference.Resolve();

            ParameterTypes = signature.ParameterTypes.Select(x => x.Type).ToArray();

            // Generate function type when being called from vtable/IMT (if it applies)
            // If declaring type is a value type, needs to unbox "this" for virtual method
            if (DeclaringType.TypeDefinitionCecil.IsValueType
                && (MethodDefinition.Attributes & MethodAttributes.Virtual) != 0)
            {
                bool hasStructValueReturn = signature.ReturnType.ABIParameterInfo.Kind == ABIParameterInfoKind.Indirect;

                // Create function type with boxed "this"
                var argumentCount = LLVM.CountParamTypes(FunctionType);
                var argumentTypes = new TypeRef[argumentCount];
                LLVM.GetParamTypes(FunctionType, argumentTypes);
                // Change first type to boxed "this"
                var thisIndex = hasStructValueReturn ? 1 : 0;
                argumentTypes[thisIndex] = LLVM.PointerType(DeclaringType.ObjectTypeLLVM, 0);
                VirtualFunctionType = LLVM.FunctionType(LLVM.GetReturnType(FunctionType), argumentTypes, LLVM.IsFunctionVarArg(FunctionType));
            }
            else
            {
                VirtualFunctionType = FunctionType;
            }
        }
Ejemplo n.º 4
0
 public Function(Type declaringType, MethodReference methodReference, TypeRef functionType, ValueRef generatedValue, Type returnType, Type[] parameterTypes)
 {
     Signature = new FunctionSignature(returnType, parameterTypes);
     DeclaringType = declaringType;
     MethodReference = methodReference;
     FunctionType = functionType;
     GeneratedValue = generatedValue;
     VirtualSlot = -1;
 }
Ejemplo n.º 5
0
        public FunctionSignature(IABI abi, Type returnType, Type[] parameterTypes, MethodCallingConvention callingConvention, PInvokeInfo pinvoke)
        {
            ReturnType = new FunctionParameterType(abi, returnType);
            ParameterTypes = new FunctionParameterType[parameterTypes.Length];
            for (int index = 0; index < parameterTypes.Length; index++)
                ParameterTypes[index] = new FunctionParameterType(abi, parameterTypes[index]);

            CallingConvention = callingConvention;
            PInvokeInfo = pinvoke;
        }
Ejemplo n.º 6
0
        public ABIParameterInfo GetParameterInfo(Type type)
        {
            if (type.StackType == StackValueType.Value)
            {
                // Types smaller than register size will be coerced to integer register type
                var structSize = LLVM.ABISizeOfType(targetData, type.DefaultTypeLLVM);
                if (structSize <= (ulong)intPtrSize)
                {
                    return new ABIParameterInfo(ABIParameterInfoKind.Coerced, LLVM.IntTypeInContext(context, (uint)structSize * 8));
                }

                // Otherwise, fallback to passing by pointer + byval (x86) or direct (x64)
                if (intPtrSize == 8)
                    return new ABIParameterInfo(ABIParameterInfoKind.Direct);
                return new ABIParameterInfo(ABIParameterInfoKind.Indirect);
            }

            // Other types are passed by value (pointers, int32, int64, float, etc...)
            return new ABIParameterInfo(ABIParameterInfoKind.Direct);
        }