Beispiel #1
0
        /// <summary>
        /// Summarizes the net effect each procedure has on registers,
        /// then removes trashed registers that aren't live-out.
        /// </summary>
        public List <SsaTransform> UntangleProcedures()
        {
            eventListener.ShowProgress("Rewriting procedures.", 0, program.Procedures.Count);

            IntraBlockDeadRegisters.Apply(program, eventListener);

            AdjacentBranchCollector.Transform(program, eventListener);

            var ssts = RewriteProceduresToSsa();

            // Recreate user-defined signatures. It should prevent type
            // inference between user-defined parameters and other expressions
            var usb = new UserSignatureBuilder(program);

            usb.BuildSignatures(eventListener);

            // Discover ssaId's that are live out at each call site.
            // Delete all others.
            var uvr = new UnusedOutValuesRemover(
                program,
                ssts.Select(sst => sst.SsaState),
                this.flow,
                dynamicLinker,
                eventListener);

            uvr.Transform();

            // At this point, the exit blocks contain only live out registers.
            // We can create signatures from that.
            CallRewriter.Rewrite(program.Platform, ssts, this.flow, eventListener);
            return(ssts);
        }
Beispiel #2
0
        public static void Rewrite(
            IPlatform platform,
            List <SsaTransform> ssts,
            ProgramDataFlow summaries,
            DecompilerEventListener eventListener)
        {
            CallRewriter crw = new CallRewriter(platform, summaries, eventListener);

            foreach (SsaTransform sst in ssts)
            {
                if (eventListener.IsCanceled())
                {
                    return;
                }
                var           proc = sst.SsaState.Procedure;
                ProcedureFlow flow = crw.mpprocflow[proc];
                flow.Dump(proc.Architecture);
                crw.EnsureSignature(sst.SsaState, proc.Frame, flow);
            }

            foreach (SsaTransform sst in ssts)
            {
                if (eventListener.IsCanceled())
                {
                    return;
                }
                crw.RewriteCalls(sst.SsaState);
                crw.RewriteReturns(sst.SsaState);
                crw.RemoveStatementsFromExitBlock(sst.SsaState);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Finds all interprocedural register dependencies (in- and out-parameters) and
        /// abstracts them away by rewriting as calls.
        /// </summary>
        /// <returns>A RegisterLiveness object that summarizes the interprocedural register
        /// liveness analysis. This information can be used to generate SSA form.
        /// </returns>
        public void UntangleProcedures()
        {
            eventListener.ShowStatus("Eliminating intra-block dead registers.");
            var usb = new UserSignatureBuilder(program);

            usb.BuildSignatures(eventListener);
            CallRewriter.Rewrite(program, eventListener);
            IntraBlockDeadRegisters.Apply(program, eventListener);
            eventListener.ShowStatus("Finding terminating procedures.");
            var term = new TerminationAnalysis(flow, eventListener);

            term.Analyze(program);
            eventListener.ShowStatus("Finding trashed registers.");
            var trf = new TrashedRegisterFinder(program, program.Procedures.Values, flow, eventListener);

            trf.Compute();
            eventListener.ShowStatus("Rewriting affine expressions.");
            trf.RewriteBasicBlocks();
            eventListener.ShowStatus("Computing register liveness.");
            RegisterLiveness.Compute(program, flow, eventListener);
            eventListener.ShowStatus("Rewriting calls.");
            GlobalCallRewriter.Rewrite(program, flow, eventListener);
        }