/// <summary> /// Constructs the operand's representation. /// </summary> /// <param name="context">The <see cref="X86Context"/> in which the /// operand is used.</param> /// <param name="instr">The <see cref="EncodedInstruction"/> encoding the /// operand.</param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="context"/> is <see langword="null"/>.</para> /// -or- /// <para><paramref name="instr"/> is <see langword="null"/>.</para> /// </exception> internal override void Construct(X86Context context, EncodedInstruction instr) { #region Contract if (context == null) { throw new ArgumentNullException("context"); } if (instr == null) { throw new ArgumentNullException("instr"); } #endregion // Let's evaluate the expression. ExpressionResult result = new BinaryExpression( expression, BinaryOperation.Subtract, new BinaryExpression( new CurrentPosition(), BinaryOperation.Add, new Constant((long)instr.GetLength()))).Evaluate(context); // Determine the size of the immediate operand. DataSize size = RequestedSize; if (size == DataSize.None) { // Does the result have a (resolved or not resolved) reference? if (result.HasReference) { // When the result has a reference, use the architecture's operand size. size = context.Representation.Architecture.OperandSize; } else { // Otherwise, use the most efficient word size. size = result.Constant.GetSize(); } } if (size >= DataSize.Bit64) { throw new AssemblerException(ExceptionStrings.OperandSizeNotEncodable); } else if (size == DataSize.None) { throw new AssemblerException(ExceptionStrings.OperandSizeNotSpecified); } // Set the parameters. instr.Immediate = result; instr.ImmediateSize = size; instr.SetOperandSize(context.Representation.Architecture.OperandSize, size); }
/// <summary> /// Constructs the operand's representation. /// </summary> /// <param name="context">The <see cref="X86Context"/> in which the /// operand is used.</param> /// <param name="instr">The <see cref="EncodedInstruction"/> encoding the /// operand.</param> /// <exception cref="ArgumentNullException"> /// <para><paramref name="context"/> is <see langword="null"/>.</para> /// -or- /// <para><paramref name="instr"/> is <see langword="null"/>.</para> /// </exception> internal override void Construct(X86Context context, EncodedInstruction instr) { #region Contract if (context == null) throw new ArgumentNullException("context"); if (instr == null) throw new ArgumentNullException("instr"); #endregion // Let's evaluate the expression. ExpressionResult result = new BinaryExpression( expression, BinaryOperation.Subtract, new BinaryExpression( new CurrentPosition(), BinaryOperation.Add, new Constant((long)instr.GetLength()))).Evaluate(context); // Determine the size of the immediate operand. DataSize size = RequestedSize; if (size == DataSize.None) { // Does the result have a (resolved or not resolved) reference? if (result.HasReference) // When the result has a reference, use the architecture's operand size. size = context.Representation.Architecture.OperandSize; else // Otherwise, use the most efficient word size. size = result.Constant.GetSize(); } if (size >= DataSize.Bit64) throw new AssemblerException(ExceptionStrings.OperandSizeNotEncodable); else if (size == DataSize.None) throw new AssemblerException(ExceptionStrings.OperandSizeNotSpecified); // Set the parameters. instr.Immediate = result; instr.ImmediateSize = size; instr.SetOperandSize(context.Representation.Architecture.OperandSize, size); }
/// <summary> /// Constructs the operand's representation. /// </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> internal override void Construct(Context context, EncodedInstruction instr) { // CONTRACT: Operand // Let's evaluate the expression. SimpleExpression result = expression(context); result = new SimpleExpression(result.Reference, result.Constant - (context.Address + instr.GetLength())); // Determine the size of the immediate operand. DataSize size = PreferredSize; if (size == DataSize.None) { // Does the result have a (resolved or not resolved) reference? if (result.Reference != null) { // When the result has a reference, use the architecture's operand size. size = context.Representation.Architecture.OperandSize; } else { // Otherwise, use the most efficient word size. size = MathExt.GetSizeOfValue(result.Constant); } } if (size >= DataSize.Bit64) { throw new AssemblerException(String.Format(CultureInfo.InvariantCulture, "{0}-bit operands cannot be encoded.", ((int)size) << 3)); } else if (size == DataSize.None) { throw new AssemblerException("The operand size is not specified."); } // Set the parameters. instr.Immediate = result; instr.ImmediateSize = size; instr.SetOperandSize(context.Representation.Architecture.OperandSize, size); }