/// <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); } }
/// <summary> /// Returns a <see cref="System.String"/> that represents this instance. /// </summary> /// <param name="context">The context.</param> /// <returns> /// A <see cref="System.String"/> that represents this instance. /// </returns> public override string ToString(Context context) { LiteralData data = (LiteralData)context.Other; return(String.Format("{0} ; {1} {2} {3}", ToString(context), data.Label, data.Type, data.Data)); }