public void AddUseToExitBlock(Identifier id)
        {
            var use = new UseInstruction(id);
            var stm = Procedure.ExitBlock.Statements.Add(0, use);

            ProcessInstruction(use, stm);
        }
Exemple #2
0
 public BitRange VisitUseInstruction(UseInstruction use)
 {
     if (useLiveness)
     {
         var stg      = ((Identifier)use.Expression).Storage;
         var bitrange = procFlow.BitsLiveOut.Aggregate(
             BitRange.Empty,
             (br, entry) =>
         {
             if (entry.Key.OverlapsWith(stg))
             {
                 return(br | entry.Value);
             }
             else
             {
                 return(br);
             }
         });
         return(bitrange);
     }
     else
     {
         var br = use.Expression.Accept(this);
         return(br);
     }
 }
Exemple #3
0
        public void VisitUseInstruction(UseInstruction use)
        {
            var dt = use.Expression.Accept(asc);

            desc.MeetDataType(use.Expression, dt);
            use.Expression.Accept(desc, use.Expression.TypeVariable);
        }
		public void UseCreate()
		{
			var id1 = new Identifier("foo", PrimitiveType.Word32, new TemporaryStorage("foo", 1, PrimitiveType.Word32));
			var use = new UseInstruction(id1);
			Assert.AreSame(id1, use.Expression);
			Assert.IsNull(use.OutArgument);
		}
Exemple #5
0
        public void UseCreate()
        {
            var id1 = new Identifier("foo", PrimitiveType.Word32, new TemporaryStorage("foo", 1, PrimitiveType.Word32));
            var use = new UseInstruction(id1);

            Assert.AreSame(id1, use.Expression);
            Assert.IsNull(use.OutArgument);
        }
Exemple #6
0
 public override Instruction TransformUseInstruction(UseInstruction u)
 {
     if (u.OutArgument != null)
     {
         u.OutArgument = UsedBeforeDefined(u.OutArgument).Identifier;
     }
     return(base.TransformUseInstruction(u));
 }
		public void UseCreateWithArg()
		{
			var id2 = new Identifier("bar", PrimitiveType.Word32, new TemporaryStorage("bar", -1, PrimitiveType.Word32));
			var r = new Identifier(Registers.edx.Name, Registers.edx.DataType, Registers.edx);
			var arg = new Identifier("barOut", PrimitiveType.Pointer32, new OutArgumentStorage(r));
			var use2 = new UseInstruction(id2, arg);
			Assert.AreSame(id2, use2.Expression);
			Assert.AreEqual("barOut", use2.OutArgument.Name);
		}
Exemple #8
0
        public void UseCreateWithArg()
        {
            var id2  = new Identifier("bar", PrimitiveType.Word32, new TemporaryStorage("bar", -1, PrimitiveType.Word32));
            var r    = new Identifier(Registers.edx.Name, Registers.edx.DataType, Registers.edx);
            var arg  = new Identifier("barOut", PrimitiveType.Pointer32, new OutArgumentStorage(r));
            var use2 = new UseInstruction(id2, arg);

            Assert.AreSame(id2, use2.Expression);
            Assert.AreEqual("barOut", use2.OutArgument.Name);
        }
        public bool VisitUseInstruction(UseInstruction u)
        {
            var uPattern = pattern as UseInstruction;

            if (uPattern == null)
            {
                return(false);
            }
            matcher.Pattern = uPattern.Expression;
            return(matcher.Match(u.Expression));
        }
		public void UseToString()
		{
			var id1 = new Identifier("foo", PrimitiveType.Word32, null);
			var use = new UseInstruction(id1);
			Assert.AreEqual("use foo", use.ToString());

			var r = new Identifier(Registers.edx.Name, Registers.edx.DataType, Registers.edx);
			var arg = new Identifier("edxOut", PrimitiveType.Pointer32, new OutArgumentStorage(r));
			use = new UseInstruction(id1, arg);
			Assert.AreEqual("use foo (=> edxOut)" , use.ToString());
		}
Exemple #11
0
 public void VisitUseInstruction(UseInstruction u)
 {
     writer.Indent();
     writer.WriteKeyword("use");
     writer.Write(" ");
     WriteExpression(u.Expression);
     if (u.OutArgument != null)
     {
         writer.Write(" (=> {0})", u.OutArgument);
     }
     writer.Terminate();
 }
Exemple #12
0
        public void UseToString()
        {
            var id1 = new Identifier("foo", PrimitiveType.Word32, null);
            var use = new UseInstruction(id1);

            Assert.AreEqual("use foo", use.ToString());

            var r   = new Identifier(Registers.edx.Name, Registers.edx.DataType, Registers.edx);
            var arg = new Identifier("edxOut", PrimitiveType.Pointer32, new OutArgumentStorage(r));

            use = new UseInstruction(id1, arg);
            Assert.AreEqual("use foo (=> edxOut)", use.ToString());
        }
Exemple #13
0
 public void Transform()
 {
     for (int i = proc.ExitBlock.Statements.Count - 1; i >= 0; --i)
     {
         Statement      stm = proc.ExitBlock.Statements[i];
         UseInstruction use = stm.Instruction as UseInstruction;
         if (use != null)
         {
             Identifier id = (Identifier)use.Expression;
             ssaIds[id].Uses.Remove(stm);
             ReplaceDefinitionsWithOutParameter(id, use.OutArgument);
             proc.ExitBlock.Statements.RemoveAt(i);
         }
     }
 }
Exemple #14
0
 public bool VisitUseInstruction(UseInstruction use)
 {
     return(false);
 }
Exemple #15
0
 void InstructionVisitor.VisitUseInstruction(UseInstruction u)
 {
     Method("Use");
     u.Expression.Accept(this);
     writer.Write(");");
 }
Exemple #16
0
 public override Instruction TransformUseInstruction(UseInstruction u)
 {
     if (u.OutArgument != null)
         u.OutArgument = UsedBeforeDefined(u.OutArgument).Identifier;
     return base.TransformUseInstruction(u);
 }
Exemple #17
0
 void InstructionVisitor.VisitUseInstruction(UseInstruction u)
 {
     throw new NotImplementedException();
 }
Exemple #18
0
 private void WriteUseInstruction(UseInstruction ui)
 {
 }
Exemple #19
0
 public override void VisitUseInstruction(UseInstruction u)
 {
     isCritical = true;
 }
Exemple #20
0
 public Instruction VisitUseInstruction(UseInstruction u)
 {
     throw new NotSupportedException("Use expressions shouldn't have been generated yet.");
 }
Exemple #21
0
		public override void VisitUseInstruction(UseInstruction u)
		{
			isCritical = true;
		}
Exemple #22
0
 public DataType VisitUseInstruction(UseInstruction u)
 {
     u.Expression.Accept(this);
     return(VoidType.Instance);
 }
Exemple #23
0
		public void VisitUseInstruction(UseInstruction u)
		{
			writer.Indent();
			writer.WriteKeyword("use");
            writer.Write(" ");
			WriteExpression(u.Expression);
			if (u.OutArgument != null)
			{
				writer.Write(" (=> {0})", u.OutArgument);
			}
			writer.Terminate();
		}
 public void VisitUseInstruction(UseInstruction u)
 {
     d.VisitUseInstruction(u);
 }
Exemple #25
0
        /// <summary>
        /// We're in the exit block now, so collect all identifiers
        /// that are registers into the procedureflow of the
        /// current procedure.
        /// </summary>
        public bool VisitUseInstruction(UseInstruction use)
        {
            if (!(use.Expression is Identifier id))
            {
                return(true);
            }
            var sid = ssas[block.Procedure].Identifiers[id];

            switch (id.Storage)
            {
            case RegisterStorage reg:
            {
                var value = ctx.GetValue(id);
                var range = ctx.GetBitRange(id);
                var stg   = arch.GetRegister(id.Storage.Domain, range) ?? id.Storage;
                if (value == Constant.Invalid)
                {
                    ctx.ProcFlow.Trashed.Add(stg);
                    ctx.ProcFlow.Preserved.Remove(stg);
                    ctx.ProcFlow.Constants.Remove(stg);
                    return(true);
                }
                if (value is Constant c)
                {
                    ctx.ProcFlow.Constants[stg] = c;
                    ctx.ProcFlow.Preserved.Remove(stg);
                    ctx.ProcFlow.Trashed.Add(stg);
                    return(true);
                }
                if (value is Identifier idV)
                {
                    if (id.Storage == arch.StackRegister)
                    {
                        if (idV == ctx.FramePointer)
                        {
                            // Special case: if we deduce that the CPU stack
                            // register is equal to the pseudo-register FP
                            // (frame pointer), we make note that the stack
                            // register is preserved.
                            ctx.ProcFlow.Preserved.Add(arch.StackRegister);
                            return(true);
                        }
                    }
                    else if (idV.Storage == id.Storage)
                    {
                        if (sid.OriginalIdentifier == idV &&
                            sid.OriginalIdentifier != id)
                        {
                            ctx.ProcFlow.Preserved.Add(stg);
                        }
                        return(true);
                    }
                }
                ctx.ProcFlow.Trashed.Add(stg);
                ctx.ProcFlow.Preserved.Remove(stg);
                ctx.ProcFlow.Constants.Remove(stg);
            }
            break;

            case FlagGroupStorage grfStorage:
            {
                var value = ctx.GetValue(id);
                if (value is Identifier idV && idV == sid.OriginalIdentifier)
                {
                    ctx.ProcFlow.grfPreserved[grfStorage.FlagRegister] =
                        ctx.ProcFlow.grfPreserved.Get(grfStorage.FlagRegister) | grfStorage.FlagGroupBits;
                    ctx.ProcFlow.grfTrashed[grfStorage.FlagRegister] =
                        ctx.ProcFlow.grfTrashed.Get(grfStorage.FlagRegister) & ~grfStorage.FlagGroupBits;
                }
 void InstructionVisitor.VisitUseInstruction(UseInstruction u)
 {
     throw new NotImplementedException();
 }
Exemple #27
0
 public Instruction VisitUseInstruction(UseInstruction u)
 {
     throw new NotSupportedException();
 }
Exemple #28
0
 public Instruction VisitUseInstruction(UseInstruction u)
 {
     return(u);
 }
Exemple #29
0
 public Instruction VisitUseInstruction(UseInstruction use)
 {
     throw new NotImplementedException();
 }
Exemple #30
0
 public AbsynStatement VisitUseInstruction(UseInstruction use)
 {
     throw new NotImplementedException();
 }
		public virtual void VisitUseInstruction(UseInstruction u)
		{
			u.Expression.Accept(this);
		}
Exemple #32
0
 public void VisitUseInstruction(UseInstruction use)
 {
     var dt = use.Expression.Accept(asc);
     desc.MeetDataType(use.Expression, dt);
     use.Expression.Accept(desc, use.Expression.TypeVariable);
 }