/// <summary>
		/// Encodes the displacement in the <see cref="EncodedInstruction"/>.
		/// </summary>
		/// <param name="context">The <see cref="Context"/> in which the operand is used.</param>
		/// <param name="instr">The <see cref="EncodedInstruction"/> encoding the operand.</param>
		/// <param name="addressSize">The address size used by the effective address.</param>
		private void EncodeDisplacement(Context context, EncodedInstruction instr, DataSize addressSize)
		{
			#region Contract
			Contract.Requires<ArgumentNullException>(context != null);
			Contract.Requires<ArgumentNullException>(instr != null);
			#endregion

			DataSize displacementSize = DataSize.None;
			SimpleExpression displacementExpression = null;

			if (displacement != null)
			{
				// Let's evaluate the displacement expression.
				displacementExpression = displacement(context);

				// Determine the size of the displacement.
				displacementSize = addressSize;
				if (displacementSize == DataSize.None)
				{
					// Does the result have a (resolved or not resolved) reference?
					if (displacementExpression.Reference != null && !displacementExpression.Reference.Resolved)
						// When the result has a reference, use the architecture's address size.
						displacementSize = context.Representation.Architecture.AddressSize;
					else
						// Otherwise, use the most efficient word size.
						displacementSize = MathExt.GetSizeOfValue(displacementExpression.Evaluate(context));	//.Constant);
				}
			}

			instr.DisplacementSize = displacementSize;
			instr.Displacement = displacementExpression;
		}
        /// <summary>
        /// Emits the immediate value as part of the instruction, if any.
        /// </summary>
        /// <param name="writer">The <see cref="BinaryWriter"/> to which the encoded instruction is written.</param>
        /// <param name="instructionOffset">The offset of the instruction in the stream underlying
        /// <paramref name="writer"/>.</param>
        /// <param name="context">The <see cref="Context"/> of the instruction.</param>
        /// <param name="expression">The <see cref="SimpleExpression"/> to emit.</param>
        /// <param name="size">The size of the value to emit.</param>
        private void EmitSimpleExpression(BinaryWriter writer, long instructionOffset, Context context, SimpleExpression expression, DataSize size)
        {
            #region Contract
            Contract.Requires <ArgumentNullException>(writer != null);
            Contract.Requires <ArgumentNullException>(context != null);
            Contract.Requires <InvalidEnumArgumentException>(Enum.IsDefined(typeof(DataSize), size));
            #endregion

            if (expression == null)
            {
                return;
            }

            // Number of bytes before the expression.
            ulong      relocationDiff = (ulong)(writer.BaseStream.Position - instructionOffset);
            Relocation relocation     = null;

            Int128 actualValue = expression.Evaluate(context);
            if (expression.Reference != null)
            {
                relocation = new Relocation(
                    expression.Reference.Symbol,
                    context.Section,
                    context.Address,
                    actualValue,
                    RelocationType.Default32);
            }

            // Emit the expression's value.
            EmitConstant(writer, size, actualValue);

            // Add the relocation to the context.
            if (relocation != null)
            {
                relocation.Offset += relocationDiff;
                context.RelocationTable.Add(relocation);
            }
        }
 private static bool ProcessSimple(XElement conditionXml, Exchange exchange)
 {
     return(SimpleExpression.Evaluate(exchange, conditionXml.Value));
 }