Exemple #1
0
        public static bool IsFloatType(FrontendType t)
        {
            bool result = false;

            result |= t.Equals(f32);
            result |= t.Equals(f64);
            return(result);
        }
Exemple #2
0
        public static bool IsIntegerType(FrontendType t)
        {
            bool result = false;

            result |= t.Equals(i8);
            result |= t.Equals(i16);
            result |= t.Equals(i32);
            result |= t.Equals(i64);
            result |= t.Equals(mm);
            return(result);
        }
Exemple #3
0
        int GetAlignmentOfFrontendType(FrontendType t)
        {
            switch (t)
            {
            case var _ when t.Equals(FrontendType.i8):
                return(1);

            case var _ when t.Equals(FrontendType.i16):
                return(2);

            case var _ when t.Equals(FrontendType.i32):
                return(4);

            case var _ when t.Equals(FrontendType.i64):
                return(8);

            case var _ when t.Equals(FrontendFunctionType.f32):
                return(4);

            case var _ when t.Equals(FrontendFunctionType.f64):
                return(8);

            case var _ when t.Equals(FrontendType.bool_):
                return(1);    // TODO(pragma): switch to b8 b16 b32?

            case var _ when t.Equals(FrontendType.mm):
                return(8);

            case FrontendPointerType _:
                return(8);

            case FrontendFunctionType _:
                return(8);

            case FrontendStructType fst:
                return(GetAlignmentOfStruct(fst));

            case FrontendArrayType fat:
                return(SizeOfArrayType(fat));

            case FrontendEnumType fet:
                return(GetAlignmentOfFrontendType(fet.integerType));

            case FrontendVectorType fvt:
                return(16);
                // return GetSizeOfFrontendType(fvt.elementType) * fvt.length;
            }
            Debug.Assert(false);
            return(-1);
        }
Exemple #4
0
 public static bool IsVoidType(FrontendType t)
 {
     return(t.Equals(void_));
 }
Exemple #5
0
 public static bool IsBoolType(FrontendType t)
 {
     return(t.Equals(bool_));
 }
Exemple #6
0
        public static bool CompatibleAndLateBind(FrontendType a, FrontendType b)
        {
            var a_is_number = a is FrontendNumberType;
            var b_is_number = b is FrontendNumberType;

            if (a_is_number || b_is_number)
            {
                if (a_is_number && b_is_number)
                {
                    var an = a as FrontendNumberType;
                    var bn = b as FrontendNumberType;
                    an.others.Add(bn);
                    bn.others.Add(an);
                    if (an.floatType || bn.floatType)
                    {
                        an.floatType = true;
                        bn.floatType = true;
                    }

                    return(true);
                }

                if (a_is_number)
                {
                    if (IsIntegerType(b))
                    {
                        var an = a as FrontendNumberType;
                        if (an.floatType)
                        {
                            return(false);
                        }
                        else
                        {
                            an.Bind(b);
                            return(true);
                        }
                    }
                    else if (IsFloatType(b))
                    {
                        (a as FrontendNumberType).Bind(b);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
                if (b_is_number)
                {
                    if (IsIntegerType(a))
                    {
                        var bn = b as FrontendNumberType;
                        if (bn.floatType)
                        {
                            return(false);
                        }
                        else
                        {
                            bn.Bind(a);
                            return(true);
                        }
                    }
                    else if (IsFloatType(a))
                    {
                        (b as FrontendNumberType).Bind(a);
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            if (a.Equals(b))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }