private static bool CompileIntegerDivision(CodeGen codeGen, ILinkingInfo linkingInfo, Type type, Register leftReg, ExpressionResult rightExpr)
        {
            var rightReg = type.OtherVolatileIntRegister(leftReg, Register64.RAX, Register64.RDX);

            rightExpr.GenerateMoveTo(rightReg, type, codeGen, linkingInfo);

            if (!leftReg.IsSameRegister(Register64.RAX))
            {
                codeGen.Mov(Register64.RAX, leftReg.AsR64());
            }

            var typeIsByte   = type.SizeOf() == 1;
            var typeIsSigned = type.IsSignedInteger();

            if (typeIsByte)
            {
                if (typeIsSigned)
                {
                    codeGen.Movsx(Register64.RAX, Register8.AL);
                }
                else
                {
                    codeGen.Movzx(Register64.RAX, Register8.AL);
                }
            }
            else
            {
                codeGen.Xor(Register64.RDX, Register64.RDX);
                if (typeIsSigned)
                {
                    codeGen.Test(Register64.RAX, Register64.RAX);
                    codeGen.Jns(CodeGenExtensions.InstructionLength(gen => gen.Not(Register64.RDX)));
                    codeGen.Not(Register64.RDX);
                }
            }

            if (type.IsSignedInteger())
            {
                codeGen.Idiv(rightReg);
            }
            else
            {
                codeGen.Div(rightReg);
            }
            return(typeIsByte);
        }
示例#2
0
 public void DefineLocal(string identifier, Type type) => _definedLocalTypes[identifier] = type;