示例#1
0
        public void OperandsAreAccessibleTest()
        {
            const int CompositeTypeOperandCount = 9;
            var       targetMachine             = TargetTests.GetTargetMachine( );

            using (var ctx = new Context( ))
                using (var module = ctx.CreateBitcodeModule("test.bc", SourceLanguage.C99, "test.c", "unit-tests"))
                {
                    module.Layout = targetMachine.TargetData;
                    var intType   = new DebugBasicType(module.Context.Int32Type, module, "int", DiTypeKind.Signed);
                    var arrayType = new DebugArrayType(intType, module, 3u);
                    Assert.IsNotNull(arrayType);

                    var mdnode = arrayType.DIType;
                    Assert.IsNotNull(mdnode.Operands);
                    Assert.AreEqual(CompositeTypeOperandCount, mdnode.Operands.Count);

                    Assert.IsNull(mdnode.File);
                    Assert.IsNull(mdnode.Operands[0]);

                    Assert.IsNull(mdnode.Scope);
                    Assert.IsNull(mdnode.Operands[1]);

                    Assert.IsTrue(string.IsNullOrEmpty(mdnode.Name));
                    Assert.IsNull(mdnode.Operands[2]);

                    Assert.IsNotNull(mdnode.BaseType);
                    Assert.IsNotNull(mdnode.Operands[3]);

                    Assert.IsNotNull(mdnode.Elements);
                    Assert.IsNotNull(mdnode.Operands[4]);
                    Assert.AreEqual(1, mdnode.Elements.Count);
                    Assert.AreEqual(1, mdnode.Elements.Count);
                    var subRange = mdnode.Elements[0] as DISubRange;
                    Assert.IsNotNull(subRange);

                    /* TODO: Test non-operand properties when available
                     * // Assert.AreEqual( 0, subRange.LowerBound );
                     * // Assert.AreEqual( 3, subRange.Length );
                     */

                    Assert.IsNull(mdnode.VTableHolder);
                    Assert.IsNull(mdnode.Operands[5]);

                    Assert.IsNull(mdnode.TemplateParameters);
                    Assert.IsNull(mdnode.Operands[6]);

                    Assert.IsTrue(string.IsNullOrEmpty(mdnode.Identifier));
                    Assert.IsNull(mdnode.Operands[7]);

                    Assert.IsNull(mdnode.Discriminator);
                    Assert.IsNull(mdnode.Operands[8]);

                    Assert.AreSame(intType.DIType, mdnode.BaseType);
                }
        }
示例#2
0
        public void OperandsAreAccessibleTest()
        {
            using (var ctx = new Context( ))
                using (var module = new BitcodeModule(ctx, "test.bc", SourceLanguage.CSharp, "test.cs", "unittests"))
                    using (var targetMachine = TargetTests.GetTargetMachine( ))
                    {
                        module.Layout = targetMachine.TargetData;
                        var intType   = new DebugBasicType(module.Context.Int32Type, module, "int", DiTypeKind.Signed);
                        var arrayType = new DebugArrayType(intType, module, 3u);
                        Assert.IsNotNull(arrayType);

                        var mdnode = arrayType.DIType as DICompositeType;
                        Assert.IsNotNull(mdnode.Operands);
                        Assert.AreEqual(8, mdnode.Operands.Count);

                        Assert.IsNotNull(mdnode.Operands[0]); // File
                        Assert.AreSame(mdnode, mdnode.Operands[0].OwningNode);
                        Assert.IsNull(mdnode.Operands[0].Metadata);

                        Assert.IsNotNull(mdnode.Operands[1]); // Scope
                        Assert.AreSame(mdnode, mdnode.Operands[1].OwningNode);
                        Assert.IsNull(mdnode.Operands[1].Metadata);

                        Assert.IsNotNull(mdnode.Operands[2]); // Name
                        Assert.AreSame(mdnode, mdnode.Operands[2].OwningNode);
                        Assert.IsNull(mdnode.Operands[2].Metadata);

                        Assert.IsNotNull(mdnode.Operands[3]); // BaseType
                        Assert.AreSame(mdnode, mdnode.Operands[3].OwningNode);
                        Assert.IsNotNull(mdnode.Operands[3].Metadata);

                        Assert.IsNotNull(mdnode.Operands[4]); // Elements
                        Assert.AreSame(mdnode, mdnode.Operands[4].OwningNode);
                        Assert.IsNotNull(mdnode.Operands[4].Metadata);

                        Assert.IsNotNull(mdnode.Operands[5]); // VTableHolder
                        Assert.AreSame(mdnode, mdnode.Operands[5].OwningNode);
                        Assert.IsNull(mdnode.Operands[5].Metadata);

                        Assert.IsNotNull(mdnode.Operands[6]); // TemplateParams
                        Assert.AreSame(mdnode, mdnode.Operands[6].OwningNode);
                        Assert.IsNull(mdnode.Operands[6].Metadata);

                        Assert.IsNotNull(mdnode.Operands[7]); // Identifier
                        Assert.AreSame(mdnode, mdnode.Operands[7].OwningNode);
                        Assert.IsNull(mdnode.Operands[7].Metadata);

                        Assert.AreSame(intType.DIType, mdnode.BaseType);
                        Assert.AreEqual(1, mdnode.Elements.Count);
                        var subRange = mdnode.Elements[0] as DISubRange;
                        Assert.IsNotNull(subRange);
                    }
        }
        public void CreateFunctionTypeTest( )
        {
            var targetMachine = TargetTests.GetTargetMachine( );

            using (var context = new Context( ))
            {
                var module = context.CreateBitcodeModule("test.bc", SourceLanguage.C99, "test.c", "unit-tests");
                Assert.IsNotNull(module);
                module.Layout = targetMachine.TargetData;

                var i16 = new DebugBasicType(context.Int16Type, module, "int16", DiTypeKind.Signed);
                var i32 = new DebugBasicType(context.Int32Type, module, "int32", DiTypeKind.Signed);
                var f32 = new DebugBasicType(context.FloatType, module, "float", DiTypeKind.Float);

                // i16 ( i32, float )
                var funcSig = context.CreateFunctionType(module.DIBuilder, i16, i32, f32);

                Assert.IsNotNull(funcSig);
                Assert.AreSame(context, funcSig.Context);

                Assert.AreEqual(TypeKind.Function, funcSig.Kind);
                Assert.AreSame(context.Int16Type, funcSig.ReturnType);
                Assert.AreEqual(2, funcSig.ParameterTypes.Count);

                // verify additional properties created properly
                Assert.AreEqual(0U, funcSig.IntegerBitWidth);
                Assert.IsFalse(funcSig.IsDouble);
                Assert.IsFalse(funcSig.IsFloat);
                Assert.IsFalse(funcSig.IsFloatingPoint);
                Assert.IsFalse(funcSig.IsInteger);
                Assert.IsFalse(funcSig.IsPointer);
                Assert.IsFalse(funcSig.IsPointerPointer);
                Assert.IsFalse(funcSig.IsSequence);
                Assert.IsFalse(funcSig.IsSized);
                Assert.IsFalse(funcSig.IsStruct);
                Assert.IsFalse(funcSig.IsVarArg);
                Assert.IsFalse(funcSig.IsVoid);

                Assert.IsNotNull(funcSig.DIType);
                var subroutineType = funcSig.DIType;
                Assert.IsNotNull(subroutineType);
                Assert.AreSame(context, subroutineType.Context);
                Assert.AreEqual(DebugInfoFlags.None, subroutineType.DebugInfoFlags);

                // signatures, have no scope or file
                Assert.IsNull(subroutineType.Scope);
                Assert.IsNull(subroutineType.File);
            }
        }
示例#4
0
        public void VerifyCreateFunctionTypeWithSameSigIsSameInstanceTest( )
        {
            using (var context = new Context( ))
                using (var targetMachine = TargetTests.GetTargetMachine( ))
                {
                    var module = new BitcodeModule(context, "test.bc", SourceLanguage.CSharp, "test.cs", "unittests");
                    Assert.IsNotNull(module);
                    module.Layout = targetMachine.TargetData;

                    var i16 = new DebugBasicType(context.Int16Type, module, "int16", DiTypeKind.Signed);
                    var i32 = new DebugBasicType(context.Int32Type, module, "int32", DiTypeKind.Signed);
                    var f32 = new DebugBasicType(context.FloatType, module, "float", DiTypeKind.Float);

                    // i16 ( i32, float )
                    var funcSig  = context.CreateFunctionType(module.DIBuilder, i16, i32, f32);
                    var funcSig2 = context.CreateFunctionType(module.DIBuilder, i16, i32, f32);
                    Assert.AreSame(funcSig.NativeType, funcSig2.NativeType);
                    Assert.AreSame(funcSig.DIType, funcSig2.DIType);
                }
        }