Ejemplo n.º 1
0
		public void PprReplaceInts()
		{
            var arch = new FakeArchitecture(); 
            var program = new Program { Architecture = arch, Platform = new DefaultPlatform(null, arch) };

			TypeFactory factory = new TypeFactory();
			store = new TypeStore();
			TypeVariable tv1 = store.CreateTypeVariable(factory);
            TypeVariable tv2 = store.CreateTypeVariable(factory);
			Assert.IsNotNull(tv1.Class, "Expected store.EnsureTypeVariable to create equivalence class");
			Assert.IsNotNull(tv2.Class, "Expected store.EnsureTypeVariable to create equivalence class");
			tv1.Class.DataType = PrimitiveType.Word32;
			tv2.Class.DataType = PrimitiveType.Word16;
            program.Globals.TypeVariable = store.CreateTypeVariable(factory);
            program.Globals.DataType = factory.CreateStructureType();

            TypeVariable tv3 = store.CreateTypeVariable(factory);
			Assert.IsNotNull(tv3.Class, "Expected store.EnsureTypeVariable to create equivalence class");

			StructureType mem = factory.CreateStructureType(null, 0);
			mem.Fields.Add(0, tv1);
			mem.Fields.Add(4, tv2);
			tv3.Class.DataType = factory.CreatePointer(mem, 4);

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

            var ppr = new PtrPrimitiveReplacer(factory, store, program);

			ppr.ReplaceAll();

			Verify(null, "Typing/PprReplaceInts.txt");
		}
        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);
        }
Ejemplo n.º 3
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);
		}
Ejemplo n.º 4
0
		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);
		}