public override void ExitCast1(ssuplParser.Cast1Context context) { var lhstype = stringToType(context.TYPE().GetText()); var rhstype = type(context.expr()); typeAttr.Put(context, lhstype); if (lhstype == rhstype) { } //casting TO an int FROM a double else if (lhstype == VarType.INT && rhstype == VarType.DOUBLE) { code.Put(context, code.Get(context.expr()), "movq xmm0, [rsp]", //pop double from stack "add rsp,8", "cvttsd2si rax, xmm0", //convert double to int "push rax" ); } //casting TO a double FROM an int else if (lhstype == VarType.DOUBLE && rhstype == VarType.INT) { code.Put(context, code.Get(context.expr()), "pop rax", //Get the int "cvtsi2sd xmm0, rax", //convert int to double "sub rsp,8", //can't use push pop with doubles "movq [rsp], xmm0" //push back on to stack ); } else { throw new Exception("ICE"); } }
/// <summary> /// Exit a parse tree produced by the <c>cast1</c> /// labeled alternative in <see cref="ssuplParser.cast"/>. /// <para>The default implementation does nothing.</para> /// </summary> /// <param name="context">The parse tree.</param> public virtual void ExitCast1([NotNull] ssuplParser.Cast1Context context) { }