Пример #1
0
        public void BlockTerminates()
        {
            var m = new ProcedureBuilder();
            m.Call(exit, 4);
            var b = m.CurrentBlock;
            m.Return();

            var a = new TerminationAnalysis(flow);
            flow[b] = CreateBlockFlow(b, m.Frame);
            a.Analyze(b);
            Assert.IsTrue(flow[b].TerminatesProcess);
        }
Пример #2
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.");
            IntraBlockDeadRegisters.Apply(program);
            eventListener.ShowStatus("Finding terminating procedures.");
            var term = new TerminationAnalysis(flow);
            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.");
            var rl = RegisterLiveness.Compute(program, flow, eventListener);
            eventListener.ShowStatus("Rewriting calls.");
			GlobalCallRewriter.Rewrite(program, flow);
		}
Пример #3
0
        public void ProcedureTerminatesIfBlockTerminates()
        {
            var proc = CompileProcedure("proc", delegate(ProcedureBuilder m)
            {
                m.Call(exit, 4);
                m.Return();
            });
            var prog = progMock.BuildProgram();

            flow = new ProgramDataFlow(prog);
            var a = new TerminationAnalysis(flow);
            a.Analyze(proc);
            Assert.IsTrue(flow[proc].TerminatesProcess);
        }
Пример #4
0
 public void BlockDoesntTerminate()
 {
     var m = new ProcedureBuilder();
     m.Store(m.Word32(0x1231), m.Byte(0));
     var b = m.Block;
     m.Return();
     var a = new TerminationAnalysis(flow);
     prog = new Program
     {
         Architecture = new FakeArchitecture()
     };
     flow[b] = CreateBlockFlow(b, m.Frame);
     a.Analyze(b);
     Assert.IsFalse(flow[b].TerminatesProcess);
 }
Пример #5
0
 public void TerminatingApplication()
 {
     var test= CompileProcedure("test", m =>
     {
         m.SideEffect(m.Fn(new ProcedureConstant(PrimitiveType.Pointer32, exit)));
         m.FinishProcedure();
     });
     var prog = progMock.BuildProgram();
     flow = new ProgramDataFlow(prog);
     var a = new TerminationAnalysis(flow);
     a.Analyze(test);
     Assert.IsTrue(flow[test].TerminatesProcess);
 }
Пример #6
0
        public void TerminatingSubProcedure()
        {
            var sub = CompileProcedure("sub", m =>
            {
                m.Call(exit, 4);
                m.FinishProcedure();
            });

            Procedure caller = CompileProcedure("caller", m =>
            {
                m.Call(sub, 4);
                m.Return();
            });

            var prog = progMock.BuildProgram();
            flow = new ProgramDataFlow(prog);
            var a = new TerminationAnalysis(flow);
            a.Analyze(prog);
            Assert.IsTrue(flow[sub].TerminatesProcess);
            Assert.IsTrue(flow[caller].TerminatesProcess);
        }
Пример #7
0
 public void ProcedureTerminatesIfAllBranchesDo()
 {
     var proc = CompileProcedure("proc", m => 
     {
         m.BranchIf(m.Eq(m.Local32("foo"), m.Word32(0)), "whee");
         m.Call(exit, 4);
         m.FinishProcedure();
         m.Label("whee");
         m.Call(exit, 4);
         m.FinishProcedure();
     });
     var prog = progMock.BuildProgram();
     flow = new ProgramDataFlow(prog);
     var a = new TerminationAnalysis(flow);
     a.Analyze(proc);
     Assert.IsTrue(flow[proc].TerminatesProcess);
 }
Пример #8
0
        public void ProcedureDoesntTerminatesIfOneBranchDoesnt()
        {
            var proc = CompileProcedure("proc", delegate(ProcedureBuilder m)
            {
                m.BranchIf(m.Eq(m.Local32("foo"), m.Word32(0)), "bye");
                m.Call(exit, 4);
                m.Label("bye");
                m.Return();
            });
            var prog = progMock.BuildProgram();

            flow = new ProgramDataFlow(prog);
            var a = new TerminationAnalysis(flow);
            a.Analyze(proc);
            Assert.IsFalse(flow[proc].TerminatesProcess);
        }