示例#1
0
        public override int GetByteSizeFromCBasicType(CBasicType cb)
        {
            switch (cb)
            {
            case CBasicType.Char: return(1);

            case CBasicType.Short: return(2);

            case CBasicType.Int: return(2);

            case CBasicType.Long: return(4);

            case CBasicType.LongLong: return(8);

            case CBasicType.Float: return(4);

            case CBasicType.Double: return(8);

            case CBasicType.LongDouble: return(8);

            case CBasicType.Int64: return(8);

            default: throw new NotImplementedException(string.Format("C basic type {0} not supported.", cb));
            }
        }
示例#2
0
        void TestArithmetic(MachineInfo mi, string type1, string type2, CBasicType result)
        {
            var report = new Report(new TestPrinter());

            var compiler = new Compiler.CCompiler(mi, report);

            compiler.AddCode("test.c", type1 + " v1; " + type2 + " v2;");
            var exe     = compiler.Compile();
            var context = new ExecutableContext(new Executable(mi), report);

            var ty1 = exe.Globals.First(x => x.Name == "v1").VariableType;

            Assert.IsInstanceOfType(ty1, typeof(CBasicType));
            var ty2 = exe.Globals.First(x => x.Name == "v2").VariableType;

            Assert.IsInstanceOfType(ty2, typeof(CBasicType));

            var bty1 = (CBasicType)ty1;
            var bty2 = (CBasicType)ty2;

            Assert.IsTrue(bty1.IsIntegral);
            Assert.IsTrue(bty2.IsIntegral);

            var aty1 = bty1.ArithmeticConvert(bty2, context);
            var aty2 = bty2.ArithmeticConvert(bty1, context);

            Assert.AreEqual(aty1.Signedness, result.Signedness);
            Assert.AreEqual(aty1.GetByteSize(context), result.GetByteSize(context));
            Assert.AreEqual(aty2.Signedness, result.Signedness);
            Assert.AreEqual(aty2.GetByteSize(context), result.GetByteSize(context));
        }
示例#3
0
        public override int GetBitSizeFromCBasicType(CBasicType cb)
        {
            switch (cb)
            {
            case CBasicType.Bool: return(8);

            case CBasicType.Char: return(8);

            case CBasicType.WChar_t: return(16);  //$REVIEW: Does RiscOS support wchar_t?

            case CBasicType.Short: return(16);

            case CBasicType.Int: return(32);

            case CBasicType.Long: return(32);

            case CBasicType.LongLong: return(64);

            case CBasicType.Float: return(32);

            case CBasicType.Double: return(64);

            case CBasicType.LongDouble: return(64);

            case CBasicType.Int64: return(64);

            default: throw new NotImplementedException(string.Format("C basic type {0} not supported.", cb));
            }
        }
示例#4
0
        public override int GetBitSizeFromCBasicType(CBasicType cb)
        {
            switch (cb)
            {
            case CBasicType.Bool: return(8);

            case CBasicType.Char: return(8);

            case CBasicType.Short: return(16);

            case CBasicType.Int: return(16);

            case CBasicType.Long: return(32);

            case CBasicType.Float: return(32);

            case CBasicType.Double: return(64);

            // Seen in Watcom
            case CBasicType.Int64: return(64);

            // Seen in OpenWatcom as an alias to __int64
            case CBasicType.LongLong: return(64);

            // Used for EBCDIC, Shift-JIS and Unicode
            case CBasicType.WChar_t: return(16);
            }
            throw new NotImplementedException();
        }
 public NamedDataTypeExtractor(IPlatform platform, IEnumerable <DeclSpec> specs, SymbolTable converter)
 {
     this.platform          = platform ?? throw new ArgumentNullException("platform");
     this.specs             = specs;
     this.symbolTable       = converter;
     this.callingConvention = CTokenType.None;
     this.eval      = new CConstantEvaluator(platform, converter.Constants);
     this.basicType = CBasicType.None;
     foreach (var declspec in specs)
     {
         dt = declspec.Accept(this);
     }
 }
示例#6
0
 public override int GetByteSizeFromCBasicType(CBasicType cb)
 {
     switch (cb)
     {
     case CBasicType.Char: return 1;
     case CBasicType.Short: return 2;
     case CBasicType.Int: return 4;
     case CBasicType.Long: return 4;
     case CBasicType.LongLong: return 8;
     case CBasicType.Float: return 4;
     case CBasicType.Double: return 8;
     case CBasicType.LongDouble: return 8;
     case CBasicType.Int64: return 8;
     default: throw new NotImplementedException(string.Format("C basic type {0} not supported.", cb));
     }
 }
示例#7
0
 public override int GetBitSizeFromCBasicType(CBasicType cb)
 {
     switch (cb)
     {
     case CBasicType.Bool: return 8;
     case CBasicType.Char: return 8;
     case CBasicType.WChar_t: return 16;
     case CBasicType.Short: return 16;
     case CBasicType.Int: return 32;
     case CBasicType.Long: return 32;
     case CBasicType.LongLong: return 64;
     case CBasicType.Float: return 32;
     case CBasicType.Double: return 64;
     case CBasicType.LongDouble: return 64;
     case CBasicType.Int64: return 64;
     default: throw new NotImplementedException(string.Format("C basic type {0} not supported.", cb));
     }
 }
        private PrimitiveType_v1 CreatePrimitive()
        {
            if (domain != Domain.None && basicType == CBasicType.None)
            {
                basicType = CBasicType.Int;
            }
            byteSize = platform.GetByteSizeFromCBasicType(basicType);
            var d = domain;

            if (d == Domain.None)
            {
                d = Domain.SignedInt;
            }
            return(new PrimitiveType_v1
            {
                Domain = d,
                ByteSize = byteSize
            });
        }
示例#9
0
        public override int GetBitSizeFromCBasicType(CBasicType cb)
        {
            //$REVIEW: it seems this sort of data should be in the reko.config file.
            switch (cb)
            {
            case CBasicType.Bool: return(8);

            case CBasicType.Char: return(8);

            case CBasicType.WChar_t: return(16);

            case CBasicType.Short: return(16);

            case CBasicType.Int: return(32);

            case CBasicType.Long: return(64);

            case CBasicType.LongLong: return(64);

            case CBasicType.Float: return(32);

            case CBasicType.Double: return(64);

            case CBasicType.LongDouble:
                if (Architecture.Name.StartsWith("x86") &&
                    Architecture.WordWidth.BitSize == 32)
                {
                    return(80);
                }
                else
                {
                    return(64);      //$REVIEW: should this be 128?
                }

            case CBasicType.Int64: return(64);

            default: throw new NotImplementedException(string.Format("C basic type {0} not supported.", cb));
            }
        }
示例#10
0
        private PrimitiveType_v1 CreatePrimitive()
        {
            if (domain != Domain.None && basicType == CBasicType.None)
            {
                basicType = CBasicType.Int;
            }
            var bitSize           = platform.GetBitSizeFromCBasicType(basicType);
            var memoryUnitBitSize = platform.Architecture.MemoryGranularity;

            this.byteSize = (bitSize + (memoryUnitBitSize - 1)) / memoryUnitBitSize;
            var d = domain;

            if (d == Domain.None)
            {
                d = Domain.SignedInt;
            }
            return(new PrimitiveType_v1
            {
                Domain = d,
                ByteSize = byteSize
            });
        }
示例#11
0
        public SerializedType?VisitSimpleType(SimpleTypeSpec simpleType)
        {
            switch (simpleType.Type)
            {
            default:
                throw new NotImplementedException(string.Format("{0}", simpleType.Type));

            case CTokenType.Void:
                if (domain != Domain.None)
                {
                    throw new FormatException(string.Format("Can't have 'void' after '{0}'.", domain));
                }
                return(new VoidType_v1());

            case CTokenType.__W64:
                return(dt);      // Used by Microsoft compilers for 32->64 bit transition, deprecated.

            case CTokenType.Signed:
                if (domain != Domain.None)
                {
                    throw new FormatException(string.Format("Can't have 'signed' after '{0}'.", domain));
                }
                domain = Domain.SignedInt;
                return(CreatePrimitive());

            case CTokenType.Unsigned:
                if (domain != Domain.None)
                {
                    throw new FormatException(string.Format("Can't have 'unsigned' after '{0}'.", domain));
                }
                domain = Domain.UnsignedInt;
                return(CreatePrimitive());

            case CTokenType.Bool:
            case CTokenType._Bool:
                if (domain != Domain.None)
                {
                    throw new FormatException(string.Format("An '{0}' boolean doesn't make sense.", domain));
                }
                domain    = Domain.Boolean;
                basicType = CBasicType.Bool;
                return(CreatePrimitive());

            case CTokenType.Char:
                if (domain == Domain.None)
                {
                    domain = Domain.Character;
                }
                else if (domain != Domain.SignedInt && domain != Domain.UnsignedInt)
                {
                    throw new FormatException(string.Format("Unexpected domain {0}.", domain));
                }
                basicType = CBasicType.Char;
                return(CreatePrimitive());

            case CTokenType.Wchar_t:
                if (domain == Domain.None)
                {
                    domain = Domain.Character;
                }
                else if (domain != Domain.SignedInt && domain != Domain.UnsignedInt)
                {
                    throw new FormatException(string.Format("Unexpected domain {0}", domain));
                }
                basicType = CBasicType.WChar_t;
                return(CreatePrimitive());

            case CTokenType.Short:
                if (domain != Domain.None && domain != Domain.SignedInt && domain != Domain.UnsignedInt)
                {
                    throw new FormatException(string.Format("Unexpected domain {0}", domain));
                }
                basicType = CBasicType.Short;
                return(CreatePrimitive());

            case CTokenType.Int:
                if (domain == Domain.None)
                {
                    domain = Domain.SignedInt;
                }
                else if (domain != Domain.SignedInt && domain != Domain.UnsignedInt)
                {
                    throw new FormatException(string.Format("Unexpected domain {0}", domain));
                }
                if (basicType == CBasicType.None)
                {
                    basicType = CBasicType.Int;
                }
                return(CreatePrimitive());

            case CTokenType.Long:
                if (basicType == CBasicType.None)
                {
                    basicType = CBasicType.Long;
                }
                else if (basicType == CBasicType.Long)
                {
                    basicType = CBasicType.LongLong;
                }
                return(CreatePrimitive());

            case CTokenType.__Int64:
                if (domain == Domain.None)
                {
                    domain = Domain.SignedInt;
                }
                else if (domain != Domain.SignedInt && domain != Domain.UnsignedInt)
                {
                    throw new FormatException(string.Format("Unexpected domain {0}", domain));
                }
                basicType = CBasicType.Int64;
                return(CreatePrimitive());

            case CTokenType.Float:
                if (domain != Domain.None)
                {
                    throw new FormatException(string.Format("Unexpected domain {0} before float.", domain));
                }
                domain    = Domain.Real;
                basicType = CBasicType.Float;
                return(CreatePrimitive());

            case CTokenType.Double:
                if (domain != Domain.None && domain != Domain.SignedInt)  //$REVIEW: short double? long double? long long double?
                {
                    throw new FormatException(string.Format("Unexpected domain {0} before float.", domain));
                }
                domain = Domain.Real;
                if (basicType == CBasicType.None)
                {
                    basicType = CBasicType.Double;
                }
                else if (basicType == CBasicType.Long)
                {
                    basicType = CBasicType.LongDouble;
                }
                return(CreatePrimitive());
            }
        }
示例#12
0
 public override int GetBitSizeFromCBasicType(CBasicType cb)
 {
     throw new NotImplementedException();
 }
示例#13
0
 public int GetByteSizeFromCBasicType(CBasicType cb)
 {
     throw new NotImplementedException();
 }
示例#14
0
 public abstract int GetByteSizeFromCBasicType(CBasicType cb);
示例#15
0
 public override int GetByteSizeFromCBasicType(CBasicType cb)
 {
     throw new NotImplementedException();
 }
示例#16
0
 public abstract int GetByteSizeFromCBasicType(CBasicType cb);