Exemplo n.º 1
0
        public void NamedDataTypeExtractor_GetArgumentKindFromAttributes_OtherAttrs()
        {
            var ndte = new NamedDataTypeExtractor(platform, new DeclSpec[0], symbolTable);
            var kind = ndte.GetArgumentKindFromAttributes("arg", null);

            Assert.IsNull(kind);
        }
Exemplo n.º 2
0
 public void ProcessDeclaration(Decl declaration, IPlatform platform, TypeLibraryDeserializer tldser, SymbolTable symbolTable)
 {
     var types = symbolTable.AddDeclaration(declaration);
     var type = types[0];
     int? vectorOffset = GetVectorOffset(declaration);
     if (vectorOffset.HasValue)
     {
         var ntde = new NamedDataTypeExtractor(platform, declaration.decl_specs, symbolTable);
         foreach (var declarator in declaration.init_declarator_list)
         {
             var nt = ntde.GetNameAndType(declarator.Declarator);
             var ssig = (SerializedSignature)nt.DataType;
             if (ssig.ReturnValue != null)
             {
                 ssig.ReturnValue.Kind = ntde.GetArgumentKindFromAttributes(
                     "returns", declaration.attribute_list);
             }
             var sser = platform.CreateProcedureSerializer(tldser, platform.DefaultCallingConvention);
             var sig = sser.Deserialize(ssig, platform.Architecture.CreateFrame());
             SystemServices.Add(
                 vectorOffset.Value,
                 new SystemService
                 {
                     Name = nt.Name,
                     SyscallInfo = new SyscallInfo
                     {
                         Vector = vectorOffset.Value,
                     },
                     Signature = sig,
                 });
         }
     }
 }
Exemplo n.º 3
0
        public void ProcessDeclaration(Decl declaration, IPlatform platform, TypeLibraryDeserializer tldser, SymbolTable symbolTable)
        {
            var types        = symbolTable.AddDeclaration(declaration);
            var type         = types[0];
            int?vectorOffset = GetVectorOffset(declaration);

            if (vectorOffset.HasValue)
            {
                var ntde = new NamedDataTypeExtractor(platform, declaration.decl_specs, symbolTable, 4);
                foreach (var declarator in declaration.init_declarator_list)
                {
                    var nt   = ntde.GetNameAndType(declarator.Declarator);
                    var ssig = (SerializedSignature?)nt.DataType;
                    if (ssig != null && ssig.ReturnValue != null)
                    {
                        ssig.ReturnValue.Kind = ntde.GetArgumentKindFromAttributes(
                            "returns", declaration.attribute_list);
                    }
                    var sser = new ProcedureSerializer(platform, tldser, platform.DefaultCallingConvention);
                    var sig  = sser.Deserialize(ssig, platform.Architecture.CreateFrame());
                    SystemServices.Add(
                        vectorOffset.Value,
                        new SystemService
                    {
                        Name        = nt.Name,
                        SyscallInfo = new SyscallInfo
                        {
                            Vector = vectorOffset.Value,
                        },
                        Signature = sig,
                    });
                }
            }
        }
Exemplo n.º 4
0
        public List<SerializedType> AddDeclaration(Decl decl)
        {
            var types = new List<SerializedType>();
            var fndec = decl as FunctionDecl;
            if (fndec != null)
            {
                return types; 
            }

            IEnumerable<DeclSpec> declspecs = decl.decl_specs;
            var isTypedef = false;
            var scspec = decl.decl_specs[0] as StorageClassSpec;
            if (scspec != null && scspec.Type == CTokenType.Typedef)
            {
                declspecs = decl.decl_specs.Skip(1);
                isTypedef = true;
            }

            var ntde = new NamedDataTypeExtractor(platform, declspecs, this);
            foreach (var declarator in decl.init_declarator_list)
            {
                var nt = ntde.GetNameAndType(declarator.Declarator);
                var serType = nt.DataType;

                var sSig = nt.DataType as SerializedSignature;
                if (sSig != null)
                {
                    if (sSig.ReturnValue != null)
                    {
                        sSig.ReturnValue.Kind = ntde.GetArgumentKindFromAttributes(decl.attribute_list);
                    }
                    Procedures.Add(new Procedure_v1
                    {
                        Name = nt.Name,
                        Signature = sSig,
                    });
                    types.Add(sSig);
                }
                if (isTypedef)
                {
                    //$REVIEW: should make sure that if the typedef already exists, 
                    // then the types match but a real compiler would have validated that.
                    var typedef = new SerializedTypedef
                    {
                        Name = nt.Name,
                        DataType = serType
                    };
                    Types.Add(typedef);
                    //$REVIEW: do we really need to check for consistence?
                    NamedTypes[typedef.Name] = serType;
                    types.Add(serType);
                }
            }
            return types;
        }
Exemplo n.º 5
0
 public void NamedDataTypeExtractor_GetArgumentKindFromAttributes_null()
 {
     var ndte = new NamedDataTypeExtractor(new DeclSpec[0], parserState);
     var kind = ndte.GetArgumentKindFromAttributes(new List<CAttribute>
     {
         new CAttribute {
              Name = new QualifiedName { Components = new[] { "foo", "bar"} }
         }
     });
     Assert.IsNull(kind);
 }
Exemplo n.º 6
0
        public void NamedDataTypeExtractor_GetArgumentKindFromAttributes_null()
        {
            var ndte = new NamedDataTypeExtractor(platform, new DeclSpec[0], symbolTable);
            var kind = ndte.GetArgumentKindFromAttributes(new List <CAttribute>
            {
                new CAttribute {
                    Name = new QualifiedName {
                        Components = new[] { "foo", "bar" }
                    }
                }
            });

            Assert.IsNull(kind);
        }
Exemplo n.º 7
0
 public void NamedDataTypeExtractor_GetArgumentKindFromAttributes_reko_reg()
 {
     var ndte = new NamedDataTypeExtractor(new DeclSpec[0], parserState);
     var kind = ndte.GetArgumentKindFromAttributes(new List<CAttribute>
     {
         new CAttribute {
              Name = new QualifiedName("reko", "reg"),
              Tokens = new List<CToken> {
                  new CToken(CTokenType.StringLiteral, "D0")
              }
         }
     });
     Assert.IsNotNull(kind);
     var sReg = (Register_v1)kind;
     Assert.AreEqual("D0", sReg.Name);
 }
Exemplo n.º 8
0
        public void NamedDataTypeExtractor_GetArgumentKindFromAttributes_reko_x87_fpu()
        {
            var ndte = new NamedDataTypeExtractor(platform, new DeclSpec[0], symbolTable);
            var kind = ndte.GetArgumentKindFromAttributes(
                "arg",
                new List <CAttribute>
            {
                new CAttribute {
                    Name   = new QualifiedName("reko", "arg"),
                    Tokens = new List <CToken> {
                        new CToken(CTokenType.Id, "fpu")
                    }
                }
            });

            Assert.IsNotNull(kind);
            Assert.IsInstanceOf <FpuStackVariable_v1>(kind);
        }
Exemplo n.º 9
0
        public void NamedDataTypeExtractor_GetArgumentKindFromAttributes_reko_reg()
        {
            var ndte = new NamedDataTypeExtractor(platform, new DeclSpec[0], symbolTable);
            var kind = ndte.GetArgumentKindFromAttributes(new List <CAttribute>
            {
                new CAttribute {
                    Name   = new QualifiedName("reko", "reg"),
                    Tokens = new List <CToken> {
                        new CToken(CTokenType.StringLiteral, "D0")
                    }
                }
            });

            Assert.IsNotNull(kind);
            var sReg = (Register_v1)kind;

            Assert.AreEqual("D0", sReg.Name);
        }
Exemplo n.º 10
0
        private void Run(DeclSpec[] declSpecs, Declarator decl)
        {
            var ndte = new NamedDataTypeExtractor(platform, declSpecs, symbolTable);

            this.nt = ndte.GetNameAndType(decl);
        }
Exemplo n.º 11
0
 public void NamedDataTypeExtractor_GetArgumentKindFromAttributes_OtherAttrs()
 {
     var ndte = new NamedDataTypeExtractor(new DeclSpec[0], parserState);
     var kind = ndte.GetArgumentKindFromAttributes(null);
     Assert.IsNull(kind);
 }
Exemplo n.º 12
0
 private void Run(DeclSpec[] declSpecs, Declarator decl)
 {
     var ndte = new NamedDataTypeExtractor(declSpecs, parserState);
     this.nt = ndte.GetNameAndType(decl);
 }
Exemplo n.º 13
0
        private void Run(DeclSpec[] declSpecs, Declarator decl)
        {
            var ndte = new NamedDataTypeExtractor(declSpecs, parserState);

            this.nt = ndte.GetNameAndType(decl);
        }
Exemplo n.º 14
0
 private void Run(DeclSpec[] declSpecs, Declarator decl)
 {
     var ndte = new NamedDataTypeExtractor(platform, declSpecs, symbolTable);
     this.nt = ndte.GetNameAndType(decl);
 }
Exemplo n.º 15
0
 public void NamedDataTypeExtractor_GetArgumentKindFromAttributes_reko_x87_fpu()
 {
     var ndte = new NamedDataTypeExtractor(platform, new DeclSpec[0], symbolTable);
     var kind = ndte.GetArgumentKindFromAttributes(
         "arg",
         new List<CAttribute>
         {
             new CAttribute {
                  Name = new QualifiedName("reko", "arg"),
                  Tokens = new List<CToken> {
                      new CToken(CTokenType.Id, "fpu")
                  }
             }
         });
     Assert.IsNotNull(kind);
     Assert.IsInstanceOf<FpuStackVariable_v1>(kind);
 }
Exemplo n.º 16
0
 public void NamedDataTypeExtractor_GetArgumentKindFromAttributes_OtherAttrs()
 {
     var ndte = new NamedDataTypeExtractor(platform, new DeclSpec[0], symbolTable);
     var kind = ndte.GetArgumentKindFromAttributes("arg", null);
     Assert.IsNull(kind);
 }