Example #1
0
        public string EmitRegisters(IProcessorArchitecture arch, string caption, BitSet regs)
        {
            StringWriter sw = new StringWriter();

            EmitRegisters(arch, caption, regs, sw);
            return(sw.ToString());
        }
Example #2
0
        public bool TerminatesProcess; // True if entering this block means the process/thread will be terminated.

        #endregion Fields

        #region Constructors

        public BlockFlow(Block block, BitSet dataOut, SymbolicEvaluationContext ctx)
        {
            this.Block = block;
            this.DataOut = dataOut;
            this.StackVarsOut = new Dictionary<Storage,int>();
            this.SymbolicIn = ctx;
        }
Example #3
0
        public bool TerminatesProcess;                  // True if entering this block means the process/thread will be terminated.

        public BlockFlow(Block block, BitSet dataOut, SymbolicEvaluationContext ctx)
        {
            this.Block        = block;
            this.DataOut      = dataOut;
            this.StackVarsOut = new Dictionary <Storage, int>();
            this.SymbolicIn   = ctx;
        }
Example #4
0
        /// <summary>
        /// Creates a signature for this procedure, and ensures that all registers accessed by the procedure are in the procedure
        /// Frame.
        /// </summary>
        public void EnsureSignature(Procedure proc, ProcedureFlow flow)
        {
            if (proc.Signature != null && proc.Signature.ParametersValid)
            {
                return;
            }

            SignatureBuilder sb    = new SignatureBuilder(proc, Program.Architecture);
            Frame            frame = proc.Frame;

            if (flow.grfLiveOut != 0)
            {
                sb.AddFlagGroupReturnValue(flow.grfLiveOut, frame);
            }

            var    implicitRegs = Program.Platform.CreateImplicitArgumentRegisters();
            BitSet mayUse       = flow.MayUse - implicitRegs;

            foreach (int r in mayUse)
            {
                if (!IsSubRegisterOfRegisters(r, mayUse))
                {
                    sb.AddRegisterArgument(r);
                }
            }

            foreach (KeyValuePair <int, Identifier> de in GetSortedStackArguments(proc.Frame))
            {
                AddStackArgument(de.Key, de.Value, flow, sb);
            }

            foreach (KeyValuePair <int, Identifier> de in GetSortedFpuStackArguments(proc.Frame, 0))
            {
                sb.AddFpuStackArgument(de.Key, de.Value);
            }

            BitSet liveOut = flow.LiveOut - implicitRegs;

            foreach (int r in liveOut)
            {
                if (!IsSubRegisterOfRegisters(r, liveOut))
                {
                    sb.AddArgument(frame.EnsureRegister(Program.Architecture.GetRegister(r)), true);
                }
            }

            foreach (KeyValuePair <int, Identifier> de in GetSortedFpuStackArguments(proc.Frame, -proc.Signature.FpuStackDelta))
            {
                int i = de.Key;
                if (i <= proc.Signature.FpuStackOutArgumentMax)
                {
                    sb.AddArgument(frame.EnsureFpuStackVariable(i, de.Value.DataType), true);
                }
            }

            var sig = sb.BuildSignature();

            flow.Signature = sig;
            proc.Signature = sig;
        }
Example #5
0
            public bool VisitRegisterStorage(RegisterStorage reg)
            {
                //$REFACTOR: make SetAliases be a bitset of Register.
                BitSet b = new BitSet(liveState.BitSet.Count);

                reg.SetAliases(b, true);
                return(!(liveState.BitSet & b).IsEmpty);
            }
Example #6
0
 private void Dump(bool enable, string s, BitSet a)
 {
     if (enable)
     {
         StringWriter sw = new StringWriter();
         sw.Write("{0}: ", s);
         ProcedureFlow.EmitRegisters(prog.Architecture, "", a, sw);
         Debug.WriteLine(sw.ToString());
     }
 }
Example #7
0
        /// <summary>
        /// Returns true if the register is a strict subregister of one of the registers in the bitset.
        /// </summary>
        /// <param name="r"></param>
        /// <param name="regs"></param>
        /// <returns></returns>
        private bool IsSubRegisterOfRegisters(int r, BitSet regs)
        {
            var rr = Program.Architecture.GetRegister(r);

            if (rr == null)
            {
                return(false);
            }
            foreach (int r2 in regs)
            {
                if (rr.IsSubRegisterOf(Program.Architecture.GetRegister(r2)))
                {
                    return(true);
                }
            }
            return(false);
        }
Example #8
0
        /// <summary>
        /// Propagates the live-out from a call instruction to
        /// the exit block of the function the call statement invokes.
        /// </summary>
        /// <param name="stm"></param>
        private void PropagateToCalleeExitBlocks(Statement stm)
        {
            BitSet liveOrig  = new BitSet(varLive.BitSet);
            uint   grfOrig   = varLive.Grf;
            var    stackOrig = new Dictionary <Storage, int>(varLive.LiveStorages);

            foreach (Procedure p in prog.CallGraph.Callees(stm))
            {
                var flow = mpprocData[p];
                varLive.BitSet       = liveOrig - flow.PreservedRegisters;
                varLive.LiveStorages = new Dictionary <Storage, int>();
                MergeBlockInfo(p.ExitBlock);
                varLive.BitSet       = new BitSet(liveOrig);
                varLive.Grf          = grfOrig;
                varLive.LiveStorages = new Dictionary <Storage, int>(stackOrig);
            }
        }
Example #9
0
 private static void EmitRegistersCore(IProcessorArchitecture arch, BitSet regs, TextWriter sb)
 {
     if (regs != null && !regs.IsEmpty)
     {
         for (int i = 0; i < regs.Count; ++i)
         {
             if (regs[i])
             {
                 var r = arch.GetRegister(i);
                 if (r != null && r.IsAluRegister)
                 {
                     sb.Write(" ");
                     sb.Write(r.Name);
                 }
             }
         }
     }
 }
Example #10
0
        private string DumpRegisters(BitSet arr)
        {
            var sb   = new StringBuilder();
            var arch = prog.Architecture;

            for (int i = 0; i < arr.Count; ++i)
            {
                if (arr[i])
                {
                    var reg = arch.GetRegister(i);
                    if (reg != null && reg.IsAluRegister)
                    {
                        sb.Append(reg.Name);
                        sb.Append(" ");
                    }
                }
            }
            return(sb.ToString());
        }
Example #11
0
 public static void EmitRegisters(IProcessorArchitecture arch, string caption, BitSet regs, TextWriter sb)
 {
     sb.Write(caption);
     EmitRegistersCore(arch, regs, sb);
 }
Example #12
0
 public static void EmitRegisters(IProcessorArchitecture arch, string caption, uint grfFlags, BitSet regs, TextWriter sb)
 {
     sb.Write(caption);
     if (grfFlags != 0)
     {
         sb.Write(" {0}", arch.GrfToString(grfFlags));
     }
     EmitRegistersCore(arch, regs, sb);
 }
Example #13
0
		/// <summary>
		/// Returns true if the register is a strict subregister of one of the registers in the bitset.
		/// </summary>
		/// <param name="r"></param>
		/// <param name="regs"></param>
		/// <returns></returns>
		private bool IsSubRegisterOfRegisters(int r, BitSet regs)
		{
            var rr = Program.Architecture.GetRegister(r);
            if (rr == null)
                return false;
			foreach (int r2 in regs)
			{
				if (rr.IsSubRegisterOf(Program.Architecture.GetRegister(r2)))
					return true;
			}
			return false;
		}
Example #14
0
        public void RegisterBitset()
        {
            BitSet regs = arch.CreateRegisterBitset();

            Assert.IsTrue(regs.Count >= (int)Registers.Max);
        }