protected override void RunTest(Program program, string outputFileName)
        {
            ExpressionNormalizer aen = new ExpressionNormalizer(program.Architecture.PointerType);
            aen.Transform(program);
            EquivalenceClassBuilder eq = new EquivalenceClassBuilder(factory, store);
            eq.Build(program);
#if OLD
            			DataTypeBuilder dtb = new DataTypeBuilder(factory, store, program.Architecture);
			TraitCollector coll = new TraitCollector(factory, store, dtb, program);
			coll.CollectProgramTraits(program);
			dtb.BuildEquivalenceClassDataTypes();
#else
            TypeCollector coll = new TypeCollector(factory, store, program);
            coll.CollectTypes();
            store.BuildEquivalenceClassDataTypes(factory);
#endif

            TypeVariableReplacer tvr = new TypeVariableReplacer(store);
            tvr.ReplaceTypeVariables();

            TypeTransformer trans = new TypeTransformer(factory, store, program);
            trans.Transform();
            using (FileUnitTester fut = new FileUnitTester(outputFileName))
            {
                foreach (Procedure proc in program.Procedures.Values)
                {
                    proc.Write(false, fut.TextWriter);
                    fut.TextWriter.WriteLine();
                }
                store.Write(fut.TextWriter);
                fut.AssertFilesEqual();
            }
        }
		public void Setup()
		{
			factory = new TypeFactory();
			store = new TypeStore();
			eqb = new EquivalenceClassBuilder(factory, store);
            var platform = new DefaultPlatform(null, new FakeArchitecture());
			dtb = new DataTypeBuilder(factory, store, platform);
		}
		public void TvrReplaceInStruct()
		{
			TypeFactory factory = new TypeFactory();
			TypeStore store = new TypeStore();
			EquivalenceClassBuilder eqb = new EquivalenceClassBuilder(factory, store);

			Identifier pptr = new Identifier("pptr", PrimitiveType.Word32, null);
			Identifier ptr = new Identifier("ptr", PrimitiveType.Word32, null);
		}
 public void SetUp()
 {
     store = new TypeStore();
     factory = new TypeFactory();
     aen = new ExpressionNormalizer(PrimitiveType.Pointer32);
     eqb = new EquivalenceClassBuilder(factory, store);
     arch = new FakeArchitecture();
     prog = new Program();
     prog.Architecture = arch;
     prog.Platform = new DefaultPlatform(null, arch);
     dtb = new DataTypeBuilder(factory, store, prog.Platform);
 }
        private void RunTest(Expression e)
        {
            var globals = new Identifier("globals", PrimitiveType.Pointer32, TemporaryStorage.None);
            store.EnsureExpressionTypeVariable(factory, globals, "globals_t");
            var eq = new EquivalenceClassBuilder(factory, store);
            e.Accept(eq);

            e.Accept(exa);

            var outputFileName = string.Format("Typing/{0}.txt", new StackTrace().GetFrame(1).GetMethod().Name);
            Verify(outputFileName);
        }
        private void RunTest(Expression e, DataType dt)
        {
            var eq = new EquivalenceClassBuilder(factory, store);
            e.Accept(eq);

            var result = e.Accept(exa);
            Debug.Print("After exa: {0}", result);
            exd.MeetDataType(e, dt);
            e.Accept(exd, e.TypeVariable);

            var outputFileName = string.Format("Typing/{0}.txt", new StackTrace().GetFrame(1).GetMethod().Name);
            Verify(outputFileName);
        }
		public void SimpleEquivalence()
		{
			TypeFactory factory = new TypeFactory();
			TypeStore store = new TypeStore();
			EquivalenceClassBuilder eqb = new EquivalenceClassBuilder(factory, store);
			Identifier id1 = new Identifier("id2", PrimitiveType.Word32, null);
			Identifier id2 = new Identifier("id2", PrimitiveType.Word32, null);
			Assignment ass = new Assignment(id1, id2);
			ass.Accept(eqb);

			Assert.IsNotNull(id1);
			Assert.IsNotNull(id2);
			Assert.AreEqual(2, id1.TypeVariable.Number, "id1 type number");
			Assert.AreEqual(2, id1.TypeVariable.Number, "id2 type number");
			Assert.AreEqual(id1.TypeVariable.Class, id2.TypeVariable.Class);
		}
        private void RunTest(Program prog, string outputFile)
        {
            EquivalenceClassBuilder eqb = new EquivalenceClassBuilder(factory, store);
            DataTypeBuilder dtb = new DataTypeBuilder(factory, store, prog.Platform);
            eqb.Build(prog);
            TraitCollector trco = new TraitCollector(factory, store, dtb, prog);
            trco.CollectProgramTraits(prog);
            dtb.BuildEquivalenceClassDataTypes();
            var tv = new TypeVariableReplacer(store);
            tv.ReplaceTypeVariables();
            store.CopyClassDataTypesToTypeVariables();
            var ppr = new PtrPrimitiveReplacer(factory, store, prog);
            ppr.ReplaceAll();

            var dpa = new DerivedPointerAnalysis(factory, store, prog);
            dpa.FollowDerivedPointers();

            Verify(null, outputFile);
        }
Exemple #9
0
		/// <summary>
		/// Performs type analysis and rewrites program based on the inferred information.
		/// </summary>
		/// <remarks>
		/// For instance, all MemoryAccesses will be converted to structure field
		/// accesses or array accesses as appropriate.
		/// </remarks>
		/// <param name="prog"></param>
		public void RewriteProgram(Program prog)
		{
            factory = prog.TypeFactory;
            store = prog.TypeStore;

            aen = new ExpressionNormalizer(prog.Platform.PointerType);
            eqb = new EquivalenceClassBuilder(factory, store);
            dtb = new DataTypeBuilder(factory, store, prog.Platform);
            trco = new TraitCollector(factory, store, dtb, prog);
            //dpa = new DerivedPointerAnalysis(factory, store, prog.Architecture);
            tvr = new TypeVariableReplacer(store);
            trans = new TypeTransformer(factory, store,prog, eventListener);
            ctn = new ComplexTypeNamer();
            ter = new TypedExpressionRewriter(prog);

            // RestrictProcedures(prog, 0, 1, true); //$DEBUG
            eventListener.ShowStatus("Gathering primitive datatypes from instructions.");
			aen.Transform(prog);
			eqb.Build(prog);
            eventListener.ShowStatus("Collecting datatype usage traits.");
			trco.CollectProgramTraits(prog);
            eventListener.ShowStatus("Building equivalence classes.");
			dtb.BuildEquivalenceClassDataTypes();
            //dpa.FollowConstantPointers(prog);
			tvr.ReplaceTypeVariables();

            eventListener.ShowStatus("Transforming datatypes.");
			var ppr = new PtrPrimitiveReplacer(factory, store, prog);
			ppr.ReplaceAll();

			trans.Transform();
			ctn.RenameAllTypes(store);
			store.Dump();
            eventListener.ShowStatus("Rewriting expressions.");
			ter.RewriteProgram(prog);
		}
        private void RunTest(params Tuple<Expression,DataType> [] tests)
        {
            foreach (var t in tests)
            {
                var eq = new EquivalenceClassBuilder(factory, store);
                t.Item1.Accept(eq);
            }

            foreach (var t in tests)
            {
                var result = t.Item1.Accept(exa);
                Debug.Print("After exa: {0}", result);
                exd.MeetDataType(t.Item1, t.Item2);
                t.Item1.Accept(exd, t.Item1.TypeVariable);
            }
            var outputFileName = string.Format("Typing/{0}.txt", new StackTrace().GetFrame(1).GetMethod().Name);
            Verify(outputFileName);
        }
		public void Setup()
		{
			factory = new TypeFactory();
			store = new TypeStore();
			eqb = new EquivalenceClassBuilder(factory, store);
		}
 public void SetupPreStages(Program prog)
 {
     aen = new ExpressionNormalizer(prog.Platform.PointerType);
     eqb = new EquivalenceClassBuilder(prog.TypeFactory, prog.TypeStore);
     dtb = new DataTypeBuilder(prog.TypeFactory, prog.TypeStore, prog.Platform);
     tvr = new TypeVariableReplacer(prog.TypeStore);
     trans = new TypeTransformer(prog.TypeFactory, prog.TypeStore, prog);
     ctn = new ComplexTypeNamer();
 }
		public void Setup()
		{
            prog = new Program();
            prog.Architecture = new FakeArchitecture();
            prog.Platform = new DefaultPlatform(null, prog.Architecture);
			factory = prog.TypeFactory;
			store = prog.TypeStore;
			handler = new TestTraitHandler(store);
			eqb = new EquivalenceClassBuilder(factory, store);
			store.EnsureExpressionTypeVariable(factory, prog.Globals);
			
			atrco = new AddressTraitCollector(factory, store, handler, prog);
			m = new ProcedureBuilder();
		}
 private TraitCollector CreateCollector(Program prog)
 {
     en = new ExpressionNormalizer(prog.Architecture.PointerType);
     eqb = new EquivalenceClassBuilder(prog.TypeFactory, prog.TypeStore);
     handler = new TestTraitHandler(prog.TypeStore);
     return new TraitCollector(prog.TypeFactory, prog.TypeStore, handler, prog);
 }
		protected override void RunTest(Program prog, string outputFilename)
		{
			TypeFactory factory = new TypeFactory();
			store = new TypeStore();
			EquivalenceClassBuilder eqb = new EquivalenceClassBuilder(factory, store);
			eqb.Build(prog);
			DataTypeBuilder dtb = new DataTypeBuilder(factory, store, prog.Platform);
			TraitCollector trco = new TraitCollector(factory, store, dtb, prog);
			trco.CollectProgramTraits(prog);
			dtb.BuildEquivalenceClassDataTypes();

			store.CopyClassDataTypesToTypeVariables();
			TypeVariableReplacer tvr = new TypeVariableReplacer(store);
			tvr.ReplaceTypeVariables();

			PtrPrimitiveReplacer ppr = new PtrPrimitiveReplacer(factory, store, prog);
			ppr.ReplaceAll();

			Verify(prog, outputFilename);
		}