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(); } }
/// <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); }