/// <summary>
 /// Gets the high condition.
 /// </summary>
 /// <param name="code">The code.</param>
 /// <returns></returns>
 private static IR.ConditionCode GetHighCondition(IR.ConditionCode code)
 {
     switch (code)
     {
         case IR.ConditionCode.Equal: return IR.ConditionCode.NotEqual;
         case IR.ConditionCode.GreaterOrEqual: return IR.ConditionCode.LessThan;
         case IR.ConditionCode.GreaterThan: return IR.ConditionCode.LessThan;
         case IR.ConditionCode.LessOrEqual: return IR.ConditionCode.GreaterThan;
         case IR.ConditionCode.LessThan: return IR.ConditionCode.GreaterThan;
         case IR.ConditionCode.NotEqual: return IR.ConditionCode.Equal;
         default: return code;
     }
 }
Exemple #2
0
        /// <summary>
        /// Emits a literal constant into the code stream.
        /// </summary>
        /// <param name="label">The label to apply to the data.</param>
        /// <param name="LiteralData"></param>
        // SigType type, object data)
        void ICodeEmitter.Literal(int label, IR.LiteralData LiteralData)
        {
            // Save the current position
            long currentPosition = _codeStream.Position;
            // Relative branch offset
            //int relOffset;
            // Flag, if we should really emit the literal (only if the literal is used!)
            bool emit = false;
            // Byte representation of the literal
            byte[] bytes;

            // Check if this label has forward references on it...
            emit = (0 != _literals.RemoveAll (delegate(Patch p)
            {
                if (p.label == label)
                {
                    _codeStream.Position = p.position;
                    // HACK: We can't do PIC right now
                    //relOffset = (int)currentPosition - ((int)p.position + 4);
                    bytes = LittleEndianBitConverter.GetBytes ((int)currentPosition);
                    _codeStream.Write (bytes, 0, bytes.Length);
                    return true;
                }

                return false;
            }));

            if (emit)
            {
                _codeStream.Position = currentPosition;
                switch (LiteralData.Type.Type) {
                    case CilElementType.I8:
                        bytes = LittleEndianBitConverter.GetBytes ((long)LiteralData.Data);
                        break;

                    case CilElementType.U8:
                        bytes = LittleEndianBitConverter.GetBytes ((ulong)LiteralData.Data);
                        break;

                    case CilElementType.R4:
                        bytes = LittleEndianBitConverter.GetBytes ((float)LiteralData.Data);
                        break;

                    case CilElementType.R8:
                        bytes = LittleEndianBitConverter.GetBytes ((double)LiteralData.Data);
                        break;
                    default:

                        throw new NotImplementedException ();
                }

                _codeStream.Write (bytes, 0, bytes.Length);
            }
        }