예제 #1
0
        /// <summary>
        /// </summary>
        /// <param name="opCode">
        /// </param>
        /// <param name="codes">
        /// </param>
        /// <returns>
        /// </returns>
        public static bool Any(this OpCodePart opCode, params Code[] codes)
        {
            if (opCode == null)
            {
                return(false);
            }

            var code = opCode.ToCode();

            return(codes.Any(item => item == code));
        }
예제 #2
0
        /// <summary>
        /// </summary>
        /// <param name="opCode">
        /// </param>
        /// <returns>
        /// </returns>
        public static int GetArgIndex(this OpCodePart opCode)
        {
            var asString = opCode.ToCode().ToString();
            var index    = -1;

            if (opCode.Any(Code.Ldarg_S, Code.Ldarg, Code.Ldarga_S, Code.Ldarga, Code.Starg_S, Code.Starg))
            {
                var opCodeInt32 = opCode as OpCodeInt32Part;
                index = opCodeInt32.Operand;
            }
            else
            {
                index = int.Parse(asString.Substring(asString.Length - 1));
            }

            return(index);
        }
예제 #3
0
        /// <summary>
        /// </summary>
        /// <param name="llvmWriter">
        /// </param>
        /// <param name="opCodePart">
        /// </param>
        /// <param name="methodBase">
        /// </param>
        public static void WriteCallConstructor(this LlvmWriter llvmWriter, OpCodePart opCodePart, IConstructor methodBase)
        {
            var writer = llvmWriter.Output;

            writer.WriteLine(string.Empty);
            writer.WriteLine("; Call Constructor");
            var resAlloc = opCodePart.Result;

            opCodePart.Result = null;
            llvmWriter.WriteCall(
                opCodePart,
                methodBase,
                opCodePart.ToCode() == Code.Callvirt,
                true,
                true,
                resAlloc,
                llvmWriter.tryScopes.Count > 0 ? llvmWriter.tryScopes.Peek() : null);
            opCodePart.Result = resAlloc;
        }
예제 #4
0
        /// <summary>
        /// </summary>
        /// <param name="opCode">
        /// </param>
        /// <param name="baseWriter">
        /// </param>
        /// <returns>
        /// </returns>
        public static IType GetLocalType(this OpCodePart opCode, BaseWriter baseWriter)
        {
            var asString = opCode.ToCode().ToString();
            var index    = -1;

            if (opCode.Any(Code.Ldloc_S, Code.Ldloc, Code.Ldloca_S, Code.Ldloca) || opCode.Any(Code.Stloc_S, Code.Stloc))
            {
                index = (opCode as OpCodeInt32Part).Operand;
            }
            else
            {
                index = int.Parse(asString.Substring(asString.Length - 1));
            }

            Debug.Assert(baseWriter.LocalInfo.Length > index);

            var localType = baseWriter.LocalInfo[index].LocalType;

            return(localType);
        }
예제 #5
0
        public void SaveBranchStackValue(OpCodePart opCode, BaseWriter baseWriter)
        {
            switch (opCode.ToCode())
            {
            case Code.Br:
            case Code.Br_S:
            case Code.Beq:
            case Code.Beq_S:
            case Code.Blt:
            case Code.Blt_S:
            case Code.Bgt:
            case Code.Bgt_S:
            case Code.Ble:
            case Code.Ble_S:
            case Code.Bge:
            case Code.Bge_S:
            case Code.Blt_Un:
            case Code.Blt_Un_S:
            case Code.Bgt_Un:
            case Code.Bgt_Un_S:
            case Code.Ble_Un:
            case Code.Ble_Un_S:
            case Code.Bge_Un:
            case Code.Bge_Un_S:
            case Code.Bne_Un:
            case Code.Bne_Un_S:
            case Code.Brtrue:
            case Code.Brtrue_S:
            case Code.Brfalse:
            case Code.Brfalse_S:
                if (opCode.IsJumpForward() && this.main.Any())
                {
                    // to clone whole stack
                    var clonedStack = this.main.ToList();
                    clonedStack.Reverse();
                    opCode.BranchStackValue = new Stack <OpCodePart>(clonedStack);
                }

                break;
            }
        }
예제 #6
0
        public void SaveBranchStackValue(OpCodePart opCode, BaseWriter baseWriter)
        {
            switch (opCode.ToCode())
            {
            case Code.Br:
            case Code.Br_S:
            case Code.Beq:
            case Code.Beq_S:
            case Code.Blt:
            case Code.Blt_S:
            case Code.Bgt:
            case Code.Bgt_S:
            case Code.Ble:
            case Code.Ble_S:
            case Code.Bge:
            case Code.Bge_S:
            case Code.Blt_Un:
            case Code.Blt_Un_S:
            case Code.Bgt_Un:
            case Code.Bgt_Un_S:
            case Code.Ble_Un:
            case Code.Ble_Un_S:
            case Code.Bge_Un:
            case Code.Bge_Un_S:
            case Code.Bne_Un:
            case Code.Bne_Un_S:
            case Code.Brtrue:
            case Code.Brtrue_S:
            case Code.Brfalse:
            case Code.Brfalse_S:
                if (opCode.IsJumpForward() && this.main.Any())
                {
                    opCode.BranchStackValue = this.main.Peek();
                }

                break;
            }
        }
예제 #7
0
        public void SaveBranchStackValue(OpCodePart opCode, BaseWriter baseWriter)
        {
            switch (opCode.ToCode())
            {
                case Code.Br:
                case Code.Br_S:
                case Code.Beq:
                case Code.Beq_S:
                case Code.Blt:
                case Code.Blt_S:
                case Code.Bgt:
                case Code.Bgt_S:
                case Code.Ble:
                case Code.Ble_S:
                case Code.Bge:
                case Code.Bge_S:
                case Code.Blt_Un:
                case Code.Blt_Un_S:
                case Code.Bgt_Un:
                case Code.Bgt_Un_S:
                case Code.Ble_Un:
                case Code.Ble_Un_S:
                case Code.Bge_Un:
                case Code.Bge_Un_S:
                case Code.Bne_Un:
                case Code.Bne_Un_S:
                case Code.Brtrue:
                case Code.Brtrue_S:
                case Code.Brfalse:
                case Code.Brfalse_S:
                    if (opCode.IsJumpForward() && this.main.Any())
                    {
                        // to clone whole stack
                        var clonedStack = this.main.ToList();
                        clonedStack.Reverse();
                        opCode.BranchStackValue = new Stack<OpCodePart>(clonedStack);
                    }

                    break;
            }
        }
예제 #8
0
 /// <summary>
 /// </summary>
 /// <param name="opCodePart">
 /// </param>
 /// <returns>
 /// </returns>
 public static bool IsReturn(this OpCodePart opCodePart)
 {
     return(opCodePart.OpCode.FlowControl == FlowControl.Return && opCodePart.ToCode() != Code.Endfinally);
 }
예제 #9
0
 /// <summary>
 /// </summary>
 /// <param name="opCodePart">
 /// </param>
 /// <returns>
 /// </returns>
 public static bool IsCondBranch(this OpCodePart opCodePart)
 {
     return(opCodePart.OpCode.FlowControl == FlowControl.Cond_Branch && opCodePart.ToCode() != Code.Switch && opCodePart.ToCode() != Code.Leave &&
            opCodePart.ToCode() != Code.Leave_S);
 }
예제 #10
0
 /// <summary>
 /// </summary>
 /// <param name="opCodePart">
 /// </param>
 /// <returns>
 /// </returns>
 public static bool IsBranch(this OpCodePart opCodePart)
 {
     return(opCodePart.OpCode.FlowControl == FlowControl.Branch && opCodePart.ToCode() != Code.Switch);
 }